[REACTOS] Fix 64 bit build (#465)
[reactos.git] / modules / 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 "precomp.h"
9
10 PVOID Buffers[0x100];
11
12 START_TEST(RtlAllocateHeap)
13 {
14 USHORT i;
15 HANDLE hHeap;
16 BOOLEAN Aligned = TRUE;
17 RTL_HEAP_PARAMETERS Parameters = {0};
18
19 for (i = 0; i < 0x100; ++i)
20 {
21 Buffers[i] = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_CREATE_ALIGN_16, (i % 16 ) + 1);
22 ASSERT(Buffers[i] != NULL);
23 if (!((ULONG_PTR)Buffers[i] & 0xF))
24 {
25 Aligned = FALSE;
26 }
27 }
28
29 for (i = 0; i < 0x100; ++i)
30 {
31 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffers[i]);
32 }
33
34 ok(Aligned == FALSE, "No unaligned address returned\n");
35
36 Aligned = TRUE;
37 Parameters.Length = sizeof(Parameters);
38 hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, &Parameters);
39 if (hHeap == NULL)
40 {
41 return;
42 }
43
44 for (i = 0; i < 0x100; ++i)
45 {
46 Buffers[i] = RtlAllocateHeap(hHeap, 0, (i % 16 ) + 1);
47 ASSERT(Buffers[i] != NULL);
48 if (!((ULONG_PTR)Buffers[i] & 0xF))
49 {
50 Aligned = FALSE;
51 }
52 }
53
54 for (i = 0; i < 0x100; ++i)
55 {
56 RtlFreeHeap(hHeap, 0, Buffers[i]);
57 }
58
59 RtlDestroyHeap(hHeap);
60
61 ok(Aligned == TRUE, "Unaligned address returned\n");
62
63 _SEH2_TRY
64 {
65 hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, (PRTL_HEAP_PARAMETERS)(ULONG_PTR)0xdeadbeefdeadbeefULL);
66 }
67 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
68 {
69 hHeap = INVALID_HANDLE_VALUE;
70 }
71 _SEH2_END;
72
73 ok(hHeap == NULL, "Unexpected heap value: %p\n", hHeap);
74 }