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