40ade2d2d527d2c834b9db36e190e5c7fba6cbea
[reactos.git] / rostests / apitests / ntdll / RtlAllocateHeap.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlAllocateHeap
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12
13 PVOID Buffers[0x100];
14
15 START_TEST(RtlAllocateHeap)
16 {
17 USHORT i;
18 HANDLE hHeap;
19 BOOLEAN Aligned = TRUE;
20 RTL_HEAP_PARAMETERS Parameters = {0};
21
22 for (i = 0; i < 0x100; ++i)
23 {
24 Buffers[i] = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_CREATE_ALIGN_16, (i % 16 ) + 1);
25 ASSERT(Buffers[i] != NULL);
26 if (!((ULONG_PTR)Buffers[i] & 0xF))
27 {
28 Aligned = FALSE;
29 }
30 }
31
32 for (i = 0; i < 0x100; ++i)
33 {
34 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffers[i]);
35 }
36
37 ok(Aligned == FALSE, "No unaligned address returned\n");
38
39 Aligned = TRUE;
40 Parameters.Length = sizeof(Parameters);
41 hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, &Parameters);
42 if (hHeap == NULL)
43 {
44 return;
45 }
46
47 for (i = 0; i < 0x100; ++i)
48 {
49 Buffers[i] = RtlAllocateHeap(hHeap, 0, (i % 16 ) + 1);
50 ASSERT(Buffers[i] != NULL);
51 if (!((ULONG_PTR)Buffers[i] & 0xF))
52 {
53 Aligned = FALSE;
54 }
55 }
56
57 for (i = 0; i < 0x100; ++i)
58 {
59 RtlFreeHeap(hHeap, 0, Buffers[i]);
60 }
61
62 RtlDestroyHeap(hHeap);
63
64 ok(Aligned == TRUE, "Unaligned address returned\n");
65 }