[NTDLL_APITEST] Add test for invalid pointer
[reactos.git] / rostests / apitests / ntdll / RtlAllocateHeap.c
index 7202a7c..829983c 100644 (file)
@@ -23,7 +23,7 @@ START_TEST(RtlAllocateHeap)
     {
         Buffers[i] = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_CREATE_ALIGN_16, (i % 16 ) + 1);
         ASSERT(Buffers[i] != NULL);
-        if (!((ULONG_PTR)Buffers[i] & 0x2))
+        if (!((ULONG_PTR)Buffers[i] & 0xF))
         {
             Aligned = FALSE;
         }
@@ -34,7 +34,7 @@ START_TEST(RtlAllocateHeap)
         RtlFreeHeap(RtlGetProcessHeap(), 0, Buffers[i]);
     }
 
-    ok(Aligned  == FALSE, "No unaligned address returned\n");
+    ok(Aligned == FALSE, "No unaligned address returned\n");
 
     Aligned = TRUE;
     Parameters.Length = sizeof(Parameters);
@@ -46,9 +46,9 @@ START_TEST(RtlAllocateHeap)
 
     for (i = 0; i < 0x100; ++i)
     {
-        Buffers[i] = RtlAllocateHeap(RtlGetProcessHeap(), 0, (i % 16 ) + 1);
+        Buffers[i] = RtlAllocateHeap(hHeap, 0, (i % 16 ) + 1);
         ASSERT(Buffers[i] != NULL);
-        if (!((ULONG_PTR)Buffers[i] & 0x2))
+        if (!((ULONG_PTR)Buffers[i] & 0xF))
         {
             Aligned = FALSE;
         }
@@ -56,10 +56,22 @@ START_TEST(RtlAllocateHeap)
 
     for (i = 0; i < 0x100; ++i)
     {
-        RtlFreeHeap(RtlGetProcessHeap(), 0, Buffers[i]);
+        RtlFreeHeap(hHeap, 0, Buffers[i]);
     }
 
     RtlDestroyHeap(hHeap);
 
-    ok(Aligned  == FALSE, "No unaligned address returned\n");
+    ok(Aligned == TRUE, "Unaligned address returned\n");
+
+    _SEH2_TRY
+    {
+        hHeap = RtlCreateHeap(HEAP_CREATE_ALIGN_16, NULL, 0, 0, NULL, (PRTL_HEAP_PARAMETERS)0xdeadbeef);
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        hHeap = INVALID_HANDLE_VALUE;
+    }
+    _SEH2_END;
+
+    ok(hHeap == NULL, "Unexpected heap value: %p\n", hHeap);
 }