From 4f2afdd0ac5a49699f36fdc5808335cd73f6c8b1 Mon Sep 17 00:00:00 2001 From: Peter Oberndorfer Date: Wed, 22 Sep 2010 21:06:22 +0200 Subject: [PATCH] kernel32: Add test for WaitForSingleObject with lower 2 bits of handles set. --- dlls/kernel32/tests/sync.c | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/dlls/kernel32/tests/sync.c b/dlls/kernel32/tests/sync.c index ea36fc60847..095c9355fc9 100644 --- a/dlls/kernel32/tests/sync.c +++ b/dlls/kernel32/tests/sync.c @@ -939,6 +939,94 @@ static void test_timer_queue(void) GetLastError()); } +static HANDLE modify_handle(HANDLE handle, DWORD modify) +{ + DWORD tmp = HandleToULong(handle); + tmp |= modify; + return ULongToHandle(tmp); +} + +static void test_WaitForSingleObject(void) +{ + HANDLE signaled, nonsignaled, invalid; + DWORD ret; + + signaled = CreateEventW(NULL, TRUE, TRUE, NULL); + if(signaled == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + { + win_skip("Handles work differently on win9x\n"); + return; + } + nonsignaled = CreateEventW(NULL, TRUE, FALSE, NULL); + invalid = (HANDLE) 0xdeadbee0; + + /* invalid handle with different values for lower 2 bits */ + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(invalid, 0); + ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret); + ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(invalid, 1), 0); + ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret); + ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(invalid, 2), 0); + ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret); + ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(invalid, 3), 0); + todo_wine ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret); + ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); + + /* valid handle with different values for lower 2 bits */ + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(nonsignaled, 0); + ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(nonsignaled, 1), 0); + ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(nonsignaled, 2), 0); + ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(nonsignaled, 3), 0); + todo_wine ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret); + todo_wine ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + /* valid handle with different values for lower 2 bits */ + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(signaled, 0); + ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(signaled, 1), 0); + ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(signaled, 2), 0); + ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret); + ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WaitForSingleObject(modify_handle(signaled, 3), 0); + ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret); + todo_wine ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError()); + + CloseHandle(signaled); + CloseHandle(nonsignaled); +} + START_TEST(sync) { HMODULE hdll = GetModuleHandle("kernel32"); @@ -958,4 +1046,5 @@ START_TEST(sync) test_waitable_timer(); test_iocp_callback(); test_timer_queue(); + test_WaitForSingleObject(); }