diff --git a/modules/rostests/apitests/ntdll/CMakeLists.txt b/modules/rostests/apitests/ntdll/CMakeLists.txt index f48d4e53dec..abda236e613 100644 --- a/modules/rostests/apitests/ntdll/CMakeLists.txt +++ b/modules/rostests/apitests/ntdll/CMakeLists.txt @@ -79,6 +79,7 @@ list(APPEND SOURCE RtlGetLengthWithoutTrailingPathSeperators.c RtlGetLongestNtPathLength.c RtlGetNtProductType.c + RtlGetProcessHeaps.c RtlGetUnloadEventTrace.c RtlHandle.c RtlImageDirectoryEntryToData.c diff --git a/modules/rostests/apitests/ntdll/RtlGetProcessHeaps.c b/modules/rostests/apitests/ntdll/RtlGetProcessHeaps.c new file mode 100644 index 00000000000..25b1959a41d --- /dev/null +++ b/modules/rostests/apitests/ntdll/RtlGetProcessHeaps.c @@ -0,0 +1,48 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: Test for RtlGetProcessHeaps + * COPYRIGHT: Copyright 2023 Mark Jansen + */ + +#include "precomp.h" + +START_TEST(RtlGetProcessHeaps) +{ + HANDLE HeapArray[40] = {0}; + ULONG MaxHeapArraySize = _countof(HeapArray); + + // Can call it with NULL + ULONG InitialNumHeaps = RtlGetProcessHeaps(0, NULL); + ok(InitialNumHeaps > 0, "Expected at least one heap\n"); + ok(InitialNumHeaps < MaxHeapArraySize, "Expected less heaps, got %lu\n", InitialNumHeaps); + + // Grab all heaps + ULONG NumHeaps = RtlGetProcessHeaps(MaxHeapArraySize, HeapArray); + ok_eq_ulong(NumHeaps, InitialNumHeaps); + for (ULONG n = 0; n < min(NumHeaps, MaxHeapArraySize); ++n) + { + ok(HeapArray[n] != NULL, "Heap[%lu] == NULL\n", n); + } + + PVOID HeapPtr = RtlCreateHeap(HEAP_GROWABLE, NULL, 0, 0x10000, NULL, NULL); + + memset(HeapArray, 0, sizeof(HeapArray)); + NumHeaps = RtlGetProcessHeaps(MaxHeapArraySize, HeapArray); + ok_eq_ulong(InitialNumHeaps + 1, NumHeaps); + if (NumHeaps > 0 && NumHeaps <= MaxHeapArraySize) + { + // A new heap is added at the end + ok_ptr(HeapArray[NumHeaps - 1], HeapPtr); + } + + RtlDestroyHeap(HeapPtr); + + // Just ask for one heap, the number of heaps available is returned, but only one heap ptr filled! + memset(HeapArray, 0xff, sizeof(HeapArray)); + NumHeaps = RtlGetProcessHeaps(1, HeapArray); + ok_eq_ulong(NumHeaps, InitialNumHeaps); + + ok_ptr(HeapArray[0], RtlGetProcessHeap()); // First item is the process heap + ok_ptr(HeapArray[1], INVALID_HANDLE_VALUE); // Next item is not touched! +} diff --git a/modules/rostests/apitests/ntdll/testlist.c b/modules/rostests/apitests/ntdll/testlist.c index 6d22f349692..a34b06f12d7 100644 --- a/modules/rostests/apitests/ntdll/testlist.c +++ b/modules/rostests/apitests/ntdll/testlist.c @@ -76,6 +76,7 @@ extern void func_RtlGetLengthWithoutLastFullDosOrNtPathElement(void); extern void func_RtlGetLengthWithoutTrailingPathSeperators(void); extern void func_RtlGetLongestNtPathLength(void); extern void func_RtlGetNtProductType(void); +extern void func_RtlGetProcessHeaps(void); extern void func_RtlGetUnloadEventTrace(void); extern void func_RtlHandle(void); extern void func_RtlImageDirectoryEntryToData(void); @@ -175,6 +176,7 @@ const struct test winetest_testlist[] = { "RtlGetLengthWithoutTrailingPathSeperators", func_RtlGetLengthWithoutTrailingPathSeperators }, { "RtlGetLongestNtPathLength", func_RtlGetLongestNtPathLength }, { "RtlGetNtProductType", func_RtlGetNtProductType }, + { "RtlGetProcessHeaps", func_RtlGetProcessHeaps }, { "RtlGetUnloadEventTrace", func_RtlGetUnloadEventTrace }, { "RtlHandle", func_RtlHandle }, { "RtlImageDirectoryEntryToData", func_RtlImageDirectoryEntryToData },