1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS api tests
3c2c66affSColin Finck * LICENSE: GPLv2+ - See COPYING in the top level directory
4c2c66affSColin Finck * PURPOSE: Test for RtlAllocateHeap
5c2c66affSColin Finck * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6c2c66affSColin Finck */
7c2c66affSColin Finck
8283bbe73SAmine Khaldi #include "precomp.h"
9c2c66affSColin Finck
10*e470b583SJérôme Gardou #include <pseh/pseh2.h>
11*e470b583SJérôme Gardou
12c2c66affSColin Finck PVOID Buffers[0x100];
13c2c66affSColin Finck
START_TEST(RtlAllocateHeap)14c2c66affSColin Finck START_TEST(RtlAllocateHeap)
15c2c66affSColin Finck {
16c2c66affSColin Finck USHORT i;
17c2c66affSColin Finck HANDLE hHeap;
18c2c66affSColin Finck BOOLEAN Aligned = TRUE;
19c2c66affSColin Finck RTL_HEAP_PARAMETERS Parameters = {0};
20c2c66affSColin Finck
21c2c66affSColin Finck for (i = 0; i < 0x100; ++i)
22c2c66affSColin Finck {
23c2c66affSColin Finck Buffers[i] = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_CREATE_ALIGN_16, (i % 16 ) + 1);
24c2c66affSColin Finck ASSERT(Buffers[i] != NULL);
25c2c66affSColin Finck if (!((ULONG_PTR)Buffers[i] & 0xF))
26c2c66affSColin Finck {
27c2c66affSColin Finck Aligned = FALSE;
28c2c66affSColin Finck }
29c2c66affSColin Finck }
30c2c66affSColin Finck
31c2c66affSColin Finck for (i = 0; i < 0x100; ++i)
32c2c66affSColin Finck {
33c2c66affSColin Finck RtlFreeHeap(RtlGetProcessHeap(), 0, Buffers[i]);
34c2c66affSColin Finck }
35c2c66affSColin Finck
36c2c66affSColin Finck ok(Aligned == FALSE, "No unaligned address returned\n");
37c2c66affSColin Finck
38c2c66affSColin Finck Aligned = TRUE;
39c2c66affSColin Finck Parameters.Length = sizeof(Parameters);
40c2c66affSColin Finck hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, &Parameters);
41c2c66affSColin Finck if (hHeap == NULL)
42c2c66affSColin Finck {
43c2c66affSColin Finck return;
44c2c66affSColin Finck }
45c2c66affSColin Finck
46c2c66affSColin Finck for (i = 0; i < 0x100; ++i)
47c2c66affSColin Finck {
48c2c66affSColin Finck Buffers[i] = RtlAllocateHeap(hHeap, 0, (i % 16 ) + 1);
49c2c66affSColin Finck ASSERT(Buffers[i] != NULL);
50c2c66affSColin Finck if (!((ULONG_PTR)Buffers[i] & 0xF))
51c2c66affSColin Finck {
52c2c66affSColin Finck Aligned = FALSE;
53c2c66affSColin Finck }
54c2c66affSColin Finck }
55c2c66affSColin Finck
56c2c66affSColin Finck for (i = 0; i < 0x100; ++i)
57c2c66affSColin Finck {
58c2c66affSColin Finck RtlFreeHeap(hHeap, 0, Buffers[i]);
59c2c66affSColin Finck }
60c2c66affSColin Finck
61c2c66affSColin Finck RtlDestroyHeap(hHeap);
62c2c66affSColin Finck
63c2c66affSColin Finck ok(Aligned == TRUE, "Unaligned address returned\n");
64c2c66affSColin Finck
65c2c66affSColin Finck _SEH2_TRY
66c2c66affSColin Finck {
676b1ca758STimo Kreuzer hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, (PRTL_HEAP_PARAMETERS)(ULONG_PTR)0xdeadbeefdeadbeefULL);
68c2c66affSColin Finck }
69c2c66affSColin Finck _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
70c2c66affSColin Finck {
71c2c66affSColin Finck hHeap = INVALID_HANDLE_VALUE;
72c2c66affSColin Finck }
73c2c66affSColin Finck _SEH2_END;
74c2c66affSColin Finck
75c2c66affSColin Finck ok(hHeap == NULL, "Unexpected heap value: %p\n", hHeap);
76c2c66affSColin Finck }
77