Commit 38d0690a authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

kernel32/tests: Clean up interlocked SList tests.

parent a4be1ca6
......@@ -261,104 +261,91 @@ static void test_slist(void)
{
SLIST_ENTRY entry;
int value;
} item1, item2, item3, *pitem;
} item1, item2, item3, *item;
SLIST_HEADER slist_header;
PSLIST_ENTRY entry, next;
SLIST_ENTRY *entry;
USHORT size;
int i;
VOID (WINAPI *pInitializeSListHead)(PSLIST_HEADER);
USHORT (WINAPI *pQueryDepthSList)(PSLIST_HEADER);
PSLIST_ENTRY (WINAPI *pInterlockedFlushSList)(PSLIST_HEADER);
PSLIST_ENTRY (WINAPI *pInterlockedPopEntrySList)(PSLIST_HEADER);
PSLIST_ENTRY (WINAPI *pInterlockedPushEntrySList)(PSLIST_HEADER,PSLIST_ENTRY);
HMODULE kernel32;
kernel32 = GetModuleHandleA("KERNEL32.DLL");
pInitializeSListHead = (void*) GetProcAddress(kernel32, "InitializeSListHead");
pQueryDepthSList = (void*) GetProcAddress(kernel32, "QueryDepthSList");
pInterlockedFlushSList = (void*) GetProcAddress(kernel32, "InterlockedFlushSList");
pInterlockedPopEntrySList = (void*) GetProcAddress(kernel32, "InterlockedPopEntrySList");
pInterlockedPushEntrySList = (void*) GetProcAddress(kernel32, "InterlockedPushEntrySList");
if (pInitializeSListHead == NULL ||
pQueryDepthSList == NULL ||
pInterlockedFlushSList == NULL ||
pInterlockedPopEntrySList == NULL ||
pInterlockedPushEntrySList == NULL)
{
win_skip("some required slist entrypoints were not found, skipping tests\n");
return;
}
memset(&slist_header, 0xFF, sizeof(slist_header));
pInitializeSListHead(&slist_header);
size = pQueryDepthSList(&slist_header);
ok(size == 0, "initially created slist has size %d, expected 0\n", size);
item1.value = 1;
ok(pInterlockedPushEntrySList(&slist_header, &item1.entry) == NULL,
"previous entry in empty slist wasn't NULL\n");
size = pQueryDepthSList(&slist_header);
ok(size == 1, "slist with 1 item has size %d\n", size);
item2.value = 2;
entry = pInterlockedPushEntrySList(&slist_header, &item2.entry);
ok(entry != NULL, "previous entry in non-empty slist was NULL\n");
if (entry != NULL)
{
pitem = (struct item*) entry;
ok(pitem->value == 1, "previous entry in slist wasn't the one added\n");
}
size = pQueryDepthSList(&slist_header);
ok(size == 2, "slist with 2 items has size %d\n", size);
item3.value = 3;
entry = pInterlockedPushEntrySList(&slist_header, &item3.entry);
ok(entry != NULL, "previous entry in non-empty slist was NULL\n");
if (entry != NULL)
{
pitem = (struct item*) entry;
ok(pitem->value == 2, "previous entry in slist wasn't the one added\n");
}
size = pQueryDepthSList(&slist_header);
ok(size == 3, "slist with 3 items has size %d\n", size);
entry = pInterlockedPopEntrySList(&slist_header);
ok(entry != NULL, "entry shouldn't be NULL\n");
if (entry != NULL)
{
pitem = (struct item*) entry;
ok(pitem->value == 3, "unexpected entry removed\n");
}
size = pQueryDepthSList(&slist_header);
ok(size == 2, "slist with 2 items has size %d\n", size);
entry = pInterlockedFlushSList(&slist_header);
size = pQueryDepthSList(&slist_header);
ok(size == 0, "flushed slist should be empty, size is %d\n", size);
if (size == 0)
{
ok(pInterlockedPopEntrySList(&slist_header) == NULL,
"popping empty slist didn't return NULL\n");
}
ok(((struct item*)entry)->value == 2, "item 2 not in front of list\n");
ok(((struct item*)entry->Next)->value == 1, "item 1 not at the back of list\n");
memset(&slist_header, 0xff, sizeof(slist_header));
InitializeSListHead(&slist_header);
size = QueryDepthSList(&slist_header);
ok(size == 0, "Expected size == 0, got %u\n", size);
entry = InterlockedPushEntrySList(&slist_header, &item1.entry);
ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
size = QueryDepthSList(&slist_header);
ok(size == 1, "Expected size == 1, got %u\n", size);
entry = InterlockedPushEntrySList(&slist_header, &item2.entry);
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
size = QueryDepthSList(&slist_header);
ok(size == 2, "Expected size == 2, got %u\n", size);
entry = InterlockedPushEntrySList(&slist_header, &item3.entry);
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
size = QueryDepthSList(&slist_header);
ok(size == 3, "Expected size == 3, got %u\n", size);
entry = InterlockedPopEntrySList(&slist_header);
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
size = QueryDepthSList(&slist_header);
ok(size == 2, "Expected size == 2, got %u\n", size);
entry = InterlockedFlushSList(&slist_header);
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
item = CONTAINING_RECORD(item->entry.Next, struct item, entry);
ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
size = QueryDepthSList(&slist_header);
ok(size == 0, "Expected size == 0, got %u\n", size);
entry = InterlockedPopEntrySList(&slist_header);
ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
for (i = 0; i < 65536; i++)
{
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
pInterlockedPushEntrySList(&slist_header, entry);
item = HeapAlloc(GetProcessHeap(), 0, sizeof(*item));
item->value = i + 1;
entry = InterlockedPushEntrySList(&slist_header, &item->entry);
if (i)
{
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == i, "Expected item->value == %u, got %u\n", i, item->value);
}
else
{
ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
}
size = QueryDepthSList(&slist_header);
ok(size == ((i + 1) & 0xffff), "Expected size == %u, got %u\n", (i + 1) & 0xffff, size);
}
entry = pInterlockedFlushSList(&slist_header);
ok(entry != NULL, "not flushed\n");
while (entry)
entry = InterlockedFlushSList(&slist_header);
for (i = 65536; i > 0; i--)
{
next = entry->Next;
HeapFree(GetProcessHeap(), 0, entry);
entry = next;
ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
item = CONTAINING_RECORD(entry, struct item, entry);
ok(item->value == i, "Expected item->value == %u, got %u\n", i, item->value);
entry = item->entry.Next;
HeapFree(GetProcessHeap(), 0, item);
}
ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
size = QueryDepthSList(&slist_header);
ok(size == 0, "Expected size == 0, got %u\n", size);
entry = InterlockedPopEntrySList(&slist_header);
ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
}
static void test_event(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment