2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite RtlGenericTable
8 #define KMT_EMULATE_KERNEL
14 static LIST_ENTRY Allocations
;
16 static RTL_GENERIC_COMPARE_RESULTS NTAPI
17 CompareCharTable(PRTL_GENERIC_TABLE Table
, PVOID A
, PVOID B
)
19 RTL_GENERIC_COMPARE_RESULTS Result
= (*((PCHAR
)A
) < *((PCHAR
)B
)) ? GenericLessThan
:
20 (*((PCHAR
)A
) > *((PCHAR
)B
)) ? GenericGreaterThan
:
26 AllocRoutine(PRTL_GENERIC_TABLE Table
, CLONG ByteSize
)
28 PLIST_ENTRY Entry
= ExAllocatePool
29 (NonPagedPool
, sizeof(LIST_ENTRY
) + ByteSize
);
30 InsertTailList(&Allocations
, Entry
);
35 FreeRoutine(PRTL_GENERIC_TABLE Table
, PVOID Buffer
)
37 PLIST_ENTRY Entry
= (PLIST_ENTRY
)(((PCHAR
)Buffer
) - sizeof(LIST_ENTRY
));
38 RemoveEntryList(Entry
);
42 static void RtlSplayTreeTest()
46 CHAR Text
[] = "the quick_brown!fOx-jUmp3d/0vER+THe^lazy.D@g";
47 CHAR NewE
[] = "11111111111111111111111111111111110111111111";
48 RTL_GENERIC_TABLE Table
;
49 RtlInitializeGenericTable
55 for (i
= 0; Text
[i
]; i
++) {
57 Ch
= (PCHAR
)RtlInsertElementGenericTable
62 ok(Ch
&& *Ch
== Text
[i
], "Copy character into node\n");
63 ok(WasNew
== (NewE
[i
] == '1'), "Character newness didn't match\n");
65 for (Ch
= (PCHAR
)RtlEnumerateGenericTable(&Table
, TRUE
), i
= 0;
67 Ch
= (PCHAR
)RtlEnumerateGenericTable(&Table
, FALSE
), i
++) {
68 ok(strchr(Text
, *Ch
) != NULL
, "Nonexistent character\n");
70 ok(RtlNumberGenericTableElements(&Table
) == strlen(Text
) - 1, "Not the right number of elements\n");
71 ok(RtlLookupElementGenericTable(&Table
, "q") != NULL
, "Could not lookup q\n");
72 ok(!RtlLookupElementGenericTable(&Table
, "#"), "Found a character that shouldn't appear\n");
73 ok(strlen(Text
) == i
+ 1, "Didn't enumerate enough characters\n");
75 for (i
= 0; Text
[i
]; i
++) {
78 WasDeleted
= RtlDeleteElementGenericTable(&Table
, &Text
[i
]);
82 ok(!RtlNumberGenericTableElements(&Table
), "Not zero elements\n");
83 ok(!RtlGetElementGenericTable(&Table
, 0), "Elements left when we removed them all\n");
84 ok(strlen(Text
) == del
+ 1, "Deleted too many times\n");
85 ok(IsListEmpty(&Allocations
), "Didn't free all memory\n");
88 START_TEST(RtlSplayTree
)
90 InitializeListHead(&Allocations
);