From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/ntdll/tests/rtl.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c index fa887421233..2acca39e519 100644 --- a/dlls/ntdll/tests/rtl.c +++ b/dlls/ntdll/tests/rtl.c @@ -108,6 +108,9 @@ static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExW)(PCWSTR, struct in6_addr *, static BOOL (WINAPI *pRtlIsCriticalSectionLocked)(CRITICAL_SECTION *); static BOOL (WINAPI *pRtlIsCriticalSectionLockedByThread)(CRITICAL_SECTION *); static NTSTATUS (WINAPI *pRtlInitializeCriticalSectionEx)(CRITICAL_SECTION *, ULONG, ULONG); +static void (WINAPI *pRtlInitializeGenericTable)(RTL_GENERIC_TABLE *, PRTL_GENERIC_COMPARE_ROUTINE, + PRTL_GENERIC_ALLOCATE_ROUTINE, PRTL_GENERIC_FREE_ROUTINE, + void *); static void * (WINAPI *pRtlFindExportedRoutineByName)(HMODULE,const char *); static NTSTATUS (WINAPI *pLdrEnumerateLoadedModules)(void *, void *, void *); static NTSTATUS (WINAPI *pLdrRegisterDllNotification)(ULONG, PLDR_DLL_NOTIFICATION_FUNCTION, void *, void **); @@ -169,6 +172,7 @@ static void InitFunctionPtrs(void) pRtlIsCriticalSectionLocked = (void *)GetProcAddress(hntdll, "RtlIsCriticalSectionLocked"); pRtlIsCriticalSectionLockedByThread = (void *)GetProcAddress(hntdll, "RtlIsCriticalSectionLockedByThread"); pRtlInitializeCriticalSectionEx = (void *)GetProcAddress(hntdll, "RtlInitializeCriticalSectionEx"); + pRtlInitializeGenericTable = (void *)GetProcAddress(hntdll, "RtlInitializeGenericTable"); pRtlFindExportedRoutineByName = (void *)GetProcAddress(hntdll, "RtlFindExportedRoutineByName"); pLdrEnumerateLoadedModules = (void *)GetProcAddress(hntdll, "LdrEnumerateLoadedModules"); pLdrRegisterDllNotification = (void *)GetProcAddress(hntdll, "LdrRegisterDllNotification"); @@ -4846,6 +4850,53 @@ static void test_RtlDelete(void) ok(root == NULL, "Got unexpected root.\n"); }
+static RTL_GENERIC_COMPARE_RESULTS WINAPI generic_compare_proc(RTL_GENERIC_TABLE *table, void *p1, void *p2) +{ + int *value1 = p1, *value2 = p2; + + if (*value1 < *value2) + return GenericLessThan; + else if (*value1 > *value2) + return GenericGreaterThan; + else + return GenericEqual; +} + +static void * WINAPI generic_allocate_proc(RTL_GENERIC_TABLE *table, CLONG size) +{ + return malloc(size); +} + +static void WINAPI generic_free_proc(RTL_GENERIC_TABLE *table, void *ptr) +{ + free(ptr); +} + +static void test_RtlInitializeGenericTable(void) +{ + RTL_GENERIC_TABLE table; + + if (!pRtlInitializeGenericTable) + { + win_skip("RtlInitializeGenericTable is unavailable.\n"); + return; + } + + memset(&table, 0xff, sizeof(table)); + pRtlInitializeGenericTable(&table, generic_compare_proc, generic_allocate_proc, + generic_free_proc, (void *)0xdeadbeef); + ok(!table.TableRoot, "Got unexpected TableRoot.\n"); + ok(table.InsertOrderList.Flink == &table.InsertOrderList, "Got unexpected InsertOrderList.Flink.\n"); + ok(table.InsertOrderList.Blink == &table.InsertOrderList, "Got unexpected InsertOrderList.Blink.\n"); + ok(table.OrderedPointer == &table.InsertOrderList, "Got unexpected OrderedPointer.\n"); + ok(!table.NumberGenericTableElements, "Got unexpected NumberGenericTableElements.\n"); + ok(!table.WhichOrderedElement, "Got unexpected WhichOrderedElement.\n"); + ok(table.CompareRoutine == generic_compare_proc, "Got unexpected CompareRoutine.\n"); + ok(table.AllocateRoutine == generic_allocate_proc, "Got unexpected AllocateRoutine.\n"); + ok(table.FreeRoutine == generic_free_proc, "Got unexpected FreeRoutine.\n"); + ok(table.TableContext == (void *)0xdeadbeef, "Got unexpected TableContext.\n"); +} + START_TEST(rtl) { InitFunctionPtrs(); @@ -4905,4 +4956,5 @@ START_TEST(rtl) test_RtlSplay(); test_RtlDeleteNoSplay(); test_RtlDelete(); + test_RtlInitializeGenericTable(); }