Index: rostests/apitests/kernel32/CMakeLists.txt =================================================================== --- rostests/apitests/kernel32/CMakeLists.txt (revision 74019) +++ rostests/apitests/kernel32/CMakeLists.txt (working copy) @@ -10,6 +10,7 @@ GetCurrentDirectory.c GetDriveType.c GetModuleFileName.c + HeapWalk.c interlck.c LoadLibraryExW.c lstrcpynW.c Index: rostests/apitests/kernel32/HeapWalk.c =================================================================== --- rostests/apitests/kernel32/HeapWalk.c (nonexistent) +++ rostests/apitests/kernel32/HeapWalk.c (working copy) @@ -0,0 +1,96 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Tests for HeapWalk + * PROGRAMMER: Mark Jansen + */ + +#include + +#include + + +static void test_data(HANDLE hHeap, PVOID Ptrs[], SIZE_T Sizes[], SIZE_T Count, const char* scope) +{ + PROCESS_HEAP_ENTRY Entry; + SIZE_T Index; + + Entry.lpData = NULL; + Index = 0; + while (HeapWalk(hHeap, &Entry)) + { + if (Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) + { + if (Index < Count) + { + ok(Entry.lpData == Ptrs[Index], "lpData(0x%x) != Ptrs[%i](0x%x) %s\n", Entry.lpData, Ptrs[Index], Index, scope); + ok(Entry.cbData == Sizes[Index], "cbData(0x%x) != cbData[%i](0x%x) %s\n", Entry.cbData, Sizes[Index], Index, scope); + Index++; + } + else + { + ok(0, "Index %d out of range %s\n", Index, scope); + } + } + } + ok(Index == Count, "Index(%i) != Count(%i) %s\n", Index, Count, scope); +} + + + +static void test_heap(HANDLE hHeap) +{ + PROCESS_HEAP_ENTRY Entry; + PVOID Ptrs[4] = { 0 }; + SIZE_T Sizes[4] = { 4, 9, 12312, 4 }; + SIZE_T Count; + + Entry.lpData = NULL; + while (HeapWalk(hHeap, &Entry)) + { + ok_int(Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY, 0); + } + + for (Count = 0; Count < _countof(Ptrs); ++Count) + { + test_data(hHeap, Ptrs, Sizes, Count, "before alloc"); + Ptrs[Count] = HeapAlloc(hHeap, 0, Sizes[Count]); + test_data(hHeap, Ptrs, Sizes, Count + 1, "after alloc"); + } + + for (Count = 0; Count < _countof(Ptrs); ++Count) + { + test_data(hHeap, Ptrs, Sizes, _countof(Ptrs) - Count, "before free"); + HeapFree(hHeap, 0, Ptrs[_countof(Ptrs) - 1 - Count]); + test_data(hHeap, Ptrs, Sizes, _countof(Ptrs) - 1 - Count, "after free"); + } + +} + +START_TEST(HeapWalk) +{ + HANDLE hHeap = HeapCreate(0, 0, 0); + test_heap(hHeap); + HeapDestroy(hHeap); + + //PROCESS_HEAP_ENTRY Entry; + //BOOL ret = FALSE; + //if (!HeapLock(hHeap)) + //{ + // skip("Unable to lock heap\n"); + // return FALSE; + //} + + //Entry.lpData = NULL; + //while (!ret && HeapWalk(hHeap, &Entry)) + //{ + // if ((Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) && + // (Entry.lpData == ptr)) + // { + // ret = TRUE; + // } + //} + + //HeapUnlock(hHeap); + //return ret; +} Index: rostests/apitests/kernel32/testlist.c =================================================================== --- rostests/apitests/kernel32/testlist.c (revision 74019) +++ rostests/apitests/kernel32/testlist.c (working copy) @@ -1,6 +1,7 @@ #define __ROS_LONG64__ #define STANDALONE +#include #include extern void func_DefaultActCtx(void); @@ -11,6 +12,7 @@ extern void func_GetCurrentDirectory(void); extern void func_GetDriveType(void); extern void func_GetModuleFileName(void); +extern void func_HeapWalk(void); extern void func_interlck(void); extern void func_LoadLibraryExW(void); extern void func_lstrcpynW(void); @@ -34,6 +36,7 @@ { "GetCurrentDirectory", func_GetCurrentDirectory }, { "GetDriveType", func_GetDriveType }, { "GetModuleFileName", func_GetModuleFileName }, + { "HeapWalk", func_HeapWalk }, { "interlck", func_interlck }, { "LoadLibraryExW", func_LoadLibraryExW }, { "lstrcpynW", func_lstrcpynW },