static void test_waitable_timer(void) { HANDLE handle, handle2; if (!pCreateWaitableTimerA || !pOpenWaitableTimerA) { skip("{Create,Open}WaitableTimerA() is not available\n"); return; } /* test case sensitivity */ SetLastError(0xdeadbeef); handle = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer"); ok(handle != NULL, "CreateWaitableTimer failed with error %u\n", GetLastError()); ok(GetLastError() == 0, "wrong error %u\n", GetLastError()); SetLastError(0xdeadbeef); handle2 = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer"); ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError()); ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError()); CloseHandle( handle2 ); SetLastError(0xdeadbeef); handle2 = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": TEST WAITABLETIMER"); ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError()); ok( GetLastError() == 0, "wrong error %u\n", GetLastError()); CloseHandle( handle2 ); SetLastError(0xdeadbeef); handle2 = pOpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": Test WaitableTimer"); ok( handle2 != NULL, "OpenWaitableTimer failed with error %d\n", GetLastError()); CloseHandle( handle2 ); SetLastError(0xdeadbeef); handle2 = pOpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": TEST WAITABLETIMER"); ok( !handle2, "OpenWaitableTimer succeeded\n"); ok( GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME, /* win98 */ "wrong error %u\n", GetLastError()); CloseHandle( handle ); }
static void test_timer(void) { HANDLE (WINAPI *pCreateWaitableTimerA)( SECURITY_ATTRIBUTES*, BOOL, LPSTR ); BOOL (WINAPI *pSetWaitableTimer)(HANDLE, LARGE_INTEGER*, LONG, PTIMERAPCROUTINE, LPVOID, BOOL); HMODULE hker = GetModuleHandleA("kernel32.dll"); HANDLE handle; BOOL r; LARGE_INTEGER due; pCreateWaitableTimerA = (void*)GetProcAddress( hker, "CreateWaitableTimerA"); if( !pCreateWaitableTimerA ) { win_skip("CreateWaitableTimerA is not available\n"); return; } pSetWaitableTimer = (void*)GetProcAddress( hker, "SetWaitableTimer"); if( !pSetWaitableTimer ) { win_skip("SetWaitableTimer is not available\n"); return; } /* try once with a positive number */ handle = pCreateWaitableTimerA( NULL, 0, NULL ); ok( handle != NULL, "failed to create waitable timer with no name\n" ); due.QuadPart = 10000; r = pSetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE ); ok( r, "failed to set timer\n"); CloseHandle( handle ); /* try once with a negative number */ handle = pCreateWaitableTimerA( NULL, 0, NULL ); ok( handle != NULL, "failed to create waitable timer with no name\n" ); due.QuadPart = -10000; r = pSetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE ); ok( r, "failed to set timer\n"); CloseHandle( handle ); }
static void test_name_collisions(void) { NTSTATUS status; UNICODE_STRING str; OBJECT_ATTRIBUTES attr; HANDLE dir, h, h1, h2; DWORD winerr; LARGE_INTEGER size; InitializeObjectAttributes(&attr, &str, 0, 0, NULL); pRtlCreateUnicodeStringFromAsciiz(&str, "\\"); DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_COLLISION) InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL); DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_EXISTS) pNtClose(h); status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE); ok(status == STATUS_OBJECT_TYPE_MISMATCH, "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status); pRtlFreeUnicodeString(&str); pRtlCreateUnicodeStringFromAsciiz(&str, "\\??\\PIPE\\om.c-mutant"); status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE); ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_OBJECT_PATH_NOT_FOUND, "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status); pRtlFreeUnicodeString(&str); if (!(dir = get_base_dir())) { win_skip( "couldn't find the BaseNamedObjects dir\n" ); return; } pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test"); InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL); h = CreateMutexA(NULL, FALSE, "om.c-test"); ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError()); status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE); ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status); h2 = CreateMutexA(NULL, FALSE, "om.c-test"); winerr = GetLastError(); ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS, "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr); pNtClose(h); pNtClose(h1); pNtClose(h2); h = CreateEventA(NULL, FALSE, FALSE, "om.c-test"); ok(h != 0, "CreateEventA failed got ret=%p (%d)\n", h, GetLastError()); status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE); ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status); h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test"); winerr = GetLastError(); ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS, "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr); pNtClose(h); pNtClose(h1); pNtClose(h2); h = CreateSemaphoreA(NULL, 1, 2, "om.c-test"); ok(h != 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h, GetLastError()); status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2); ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status); h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test"); winerr = GetLastError(); ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS, "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr); pNtClose(h); pNtClose(h1); pNtClose(h2); h = pCreateWaitableTimerA(NULL, TRUE, "om.c-test"); ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h, GetLastError()); status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer); ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status); h2 = pCreateWaitableTimerA(NULL, TRUE, "om.c-test"); winerr = GetLastError(); ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS, "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr); pNtClose(h); pNtClose(h1); pNtClose(h2); h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test"); ok(h != 0, "CreateFileMappingA failed got ret=%p (%d)\n", h, GetLastError()); size.u.LowPart = 256; size.u.HighPart = 0; status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0); ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL, "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status); h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test"); winerr = GetLastError(); ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS, "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr); pNtClose(h); pNtClose(h1); pNtClose(h2); pRtlFreeUnicodeString(&str); pNtClose(dir); }