2005-04-24 19:37:52 +02:00
|
|
|
/*
|
|
|
|
* Synchronization tests
|
|
|
|
*
|
|
|
|
* Copyright 2005 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-04-24 19:37:52 +02:00
|
|
|
*/
|
|
|
|
|
2008-12-04 12:10:16 +01:00
|
|
|
#define _WIN32_WINNT 0x500
|
2005-04-24 19:37:52 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2008-07-22 02:43:28 +02:00
|
|
|
static BOOL (WINAPI *pChangeTimerQueueTimer)(HANDLE, HANDLE, ULONG, ULONG);
|
2008-07-22 02:42:41 +02:00
|
|
|
static HANDLE (WINAPI *pCreateTimerQueue)(void);
|
|
|
|
static BOOL (WINAPI *pCreateTimerQueueTimer)(PHANDLE, HANDLE, WAITORTIMERCALLBACK,
|
|
|
|
PVOID, DWORD, DWORD, ULONG);
|
2008-05-25 13:51:21 +02:00
|
|
|
static HANDLE (WINAPI *pCreateWaitableTimerA)(SECURITY_ATTRIBUTES*,BOOL,LPCSTR);
|
2008-07-22 02:42:41 +02:00
|
|
|
static BOOL (WINAPI *pDeleteTimerQueueEx)(HANDLE, HANDLE);
|
2008-07-22 02:43:28 +02:00
|
|
|
static BOOL (WINAPI *pDeleteTimerQueueTimer)(HANDLE, HANDLE, HANDLE);
|
2008-05-25 13:51:21 +02:00
|
|
|
static HANDLE (WINAPI *pOpenWaitableTimerA)(DWORD,BOOL,LPCSTR);
|
2012-03-12 10:33:32 +01:00
|
|
|
static HANDLE (WINAPI *pCreateMemoryResourceNotification)(MEMORY_RESOURCE_NOTIFICATION_TYPE);
|
|
|
|
static BOOL (WINAPI *pQueryMemoryResourceNotification)(HANDLE, PBOOL);
|
2008-05-25 13:51:21 +02:00
|
|
|
|
2005-04-24 19:37:52 +02:00
|
|
|
static void test_signalandwait(void)
|
|
|
|
{
|
|
|
|
DWORD (WINAPI *pSignalObjectAndWait)(HANDLE, HANDLE, DWORD, BOOL);
|
|
|
|
HMODULE kernel32;
|
|
|
|
DWORD r;
|
2011-07-23 22:02:19 +02:00
|
|
|
HANDLE event[2], semaphore[2], file;
|
2005-04-24 19:37:52 +02:00
|
|
|
|
|
|
|
kernel32 = GetModuleHandle("kernel32");
|
|
|
|
pSignalObjectAndWait = (void*) GetProcAddress(kernel32, "SignalObjectAndWait");
|
|
|
|
|
|
|
|
if (!pSignalObjectAndWait)
|
|
|
|
return;
|
|
|
|
|
2005-08-01 12:57:13 +02:00
|
|
|
/* invalid parameters */
|
|
|
|
r = pSignalObjectAndWait(NULL, NULL, 0, 0);
|
|
|
|
if (r == ERROR_INVALID_FUNCTION)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("SignalObjectAndWait is not implemented\n");
|
2005-08-01 12:57:13 +02:00
|
|
|
return; /* Win98/ME */
|
|
|
|
}
|
|
|
|
ok( r == WAIT_FAILED, "should fail\n");
|
|
|
|
|
2005-04-24 19:37:52 +02:00
|
|
|
event[0] = CreateEvent(NULL, 0, 0, NULL);
|
|
|
|
event[1] = CreateEvent(NULL, 1, 1, NULL);
|
|
|
|
|
|
|
|
ok( event[0] && event[1], "failed to create event flags\n");
|
|
|
|
|
|
|
|
r = pSignalObjectAndWait(event[0], NULL, 0, FALSE);
|
|
|
|
ok( r == WAIT_FAILED, "should fail\n");
|
|
|
|
|
|
|
|
r = pSignalObjectAndWait(NULL, event[0], 0, FALSE);
|
|
|
|
ok( r == WAIT_FAILED, "should fail\n");
|
|
|
|
|
|
|
|
|
|
|
|
/* valid parameters */
|
|
|
|
r = pSignalObjectAndWait(event[0], event[1], 0, FALSE);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should succeed\n");
|
|
|
|
|
|
|
|
/* event[0] is now signalled */
|
|
|
|
r = pSignalObjectAndWait(event[0], event[0], 0, FALSE);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should succeed\n");
|
|
|
|
|
|
|
|
/* event[0] is not signalled */
|
|
|
|
r = WaitForSingleObject(event[0], 0);
|
|
|
|
ok( r == WAIT_TIMEOUT, "event was signalled\n");
|
|
|
|
|
|
|
|
r = pSignalObjectAndWait(event[0], event[0], 0, FALSE);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should succeed\n");
|
|
|
|
|
|
|
|
/* clear event[1] and check for a timeout */
|
|
|
|
ok(ResetEvent(event[1]), "failed to clear event[1]\n");
|
|
|
|
r = pSignalObjectAndWait(event[0], event[1], 0, FALSE);
|
|
|
|
ok( r == WAIT_TIMEOUT, "should timeout\n");
|
|
|
|
|
|
|
|
CloseHandle(event[0]);
|
|
|
|
CloseHandle(event[1]);
|
|
|
|
|
|
|
|
/* semaphores */
|
|
|
|
semaphore[0] = CreateSemaphore( NULL, 0, 1, NULL );
|
|
|
|
semaphore[1] = CreateSemaphore( NULL, 1, 1, NULL );
|
|
|
|
ok( semaphore[0] && semaphore[1], "failed to create semaphore\n");
|
|
|
|
|
|
|
|
r = pSignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should succeed\n");
|
|
|
|
|
|
|
|
r = pSignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
|
|
|
|
ok( r == WAIT_FAILED, "should fail\n");
|
|
|
|
|
|
|
|
r = ReleaseSemaphore(semaphore[0],1,NULL);
|
|
|
|
ok( r == FALSE, "should fail\n");
|
|
|
|
|
|
|
|
r = ReleaseSemaphore(semaphore[1],1,NULL);
|
|
|
|
ok( r == TRUE, "should succeed\n");
|
|
|
|
|
|
|
|
CloseHandle(semaphore[0]);
|
|
|
|
CloseHandle(semaphore[1]);
|
|
|
|
|
|
|
|
/* try a registry key */
|
|
|
|
file = CreateFile("x", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
|
|
|
r = pSignalObjectAndWait(file, file, 0, FALSE);
|
|
|
|
ok( r == WAIT_FAILED, "should fail\n");
|
|
|
|
ok( ERROR_INVALID_HANDLE == GetLastError(), "should return invalid handle error\n");
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
|
2006-06-14 14:20:31 +02:00
|
|
|
static void test_mutex(void)
|
|
|
|
{
|
|
|
|
DWORD wait_ret;
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE hCreated;
|
|
|
|
HANDLE hOpened;
|
2011-09-14 14:48:56 +02:00
|
|
|
int i;
|
|
|
|
DWORD failed = 0;
|
2006-06-14 14:20:31 +02:00
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hOpened = OpenMutex(0, FALSE, "WineTestMutex");
|
|
|
|
ok(hOpened == NULL, "OpenMutex succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-06-14 14:20:31 +02:00
|
|
|
hCreated = CreateMutex(NULL, FALSE, "WineTestMutex");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(hCreated != NULL, "CreateMutex failed with error %d\n", GetLastError());
|
2006-06-14 14:20:31 +02:00
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-09-14 14:48:56 +02:00
|
|
|
hOpened = OpenMutex(0, FALSE, "WineTestMutex");
|
2012-03-12 06:40:43 +01:00
|
|
|
todo_wine
|
2011-09-27 00:14:10 +02:00
|
|
|
ok(hOpened == NULL, "OpenMutex succeeded\n");
|
2012-03-12 06:40:43 +01:00
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError());
|
2011-09-14 14:48:56 +02:00
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-09-14 14:48:56 +02:00
|
|
|
hOpened = OpenMutex(GENERIC_EXECUTE, FALSE, "WineTestMutex");
|
|
|
|
ok(hOpened != NULL, "OpenMutex failed with error %d\n", GetLastError());
|
|
|
|
wait_ret = WaitForSingleObject(hOpened, INFINITE);
|
2011-09-14 14:49:09 +02:00
|
|
|
ok(wait_ret == WAIT_OBJECT_0, "WaitForSingleObject failed with error %d\n", GetLastError());
|
2011-09-14 14:48:56 +02:00
|
|
|
CloseHandle(hOpened);
|
|
|
|
|
|
|
|
for(i=0; i < 31; i++)
|
|
|
|
{
|
|
|
|
wait_ret = WaitForSingleObject(hCreated, INFINITE);
|
|
|
|
ok(wait_ret == WAIT_OBJECT_0, "WaitForSingleObject failed with error 0x%08x\n", wait_ret);
|
|
|
|
}
|
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-09-14 14:48:56 +02:00
|
|
|
hOpened = OpenMutex(GENERIC_READ | GENERIC_WRITE, FALSE, "WineTestMutex");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(hOpened != NULL, "OpenMutex failed with error %d\n", GetLastError());
|
2011-09-14 14:48:56 +02:00
|
|
|
wait_ret = WaitForSingleObject(hOpened, INFINITE);
|
2011-09-14 14:49:09 +02:00
|
|
|
ok(wait_ret == WAIT_FAILED, "WaitForSingleObject succeeded\n");
|
2011-09-14 14:48:56 +02:00
|
|
|
CloseHandle(hOpened);
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-09-14 14:48:56 +02:00
|
|
|
hOpened = OpenMutex(0x1 << i, FALSE, "WineTestMutex");
|
|
|
|
if(hOpened != NULL)
|
|
|
|
{
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-09-14 14:49:03 +02:00
|
|
|
ret = ReleaseMutex(hOpened);
|
|
|
|
ok(ret, "ReleaseMutex failed with error %d, access %x\n", GetLastError(), 1 << i);
|
2011-09-14 14:48:56 +02:00
|
|
|
CloseHandle(hOpened);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-12 06:40:43 +01:00
|
|
|
if ((1 << i) == ACCESS_SYSTEM_SECURITY)
|
|
|
|
todo_wine ok(GetLastError() == ERROR_PRIVILEGE_NOT_HELD, "wrong error %u, access %x\n", GetLastError(), 1 << i);
|
|
|
|
else
|
|
|
|
todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u, , access %x\n", GetLastError(), 1 << i);
|
2011-09-14 14:49:03 +02:00
|
|
|
ReleaseMutex(hCreated);
|
2011-09-14 14:48:56 +02:00
|
|
|
failed |=0x1 << i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
todo_wine
|
2011-09-27 00:14:10 +02:00
|
|
|
ok( failed == 0x0de0fffe, "open succeeded when it shouldn't: %x\n", failed);
|
2011-09-14 14:48:56 +02:00
|
|
|
|
2012-03-12 06:40:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2006-06-14 14:20:31 +02:00
|
|
|
ret = ReleaseMutex(hCreated);
|
2011-09-14 14:48:56 +02:00
|
|
|
ok(!ret && (GetLastError() == ERROR_NOT_OWNER),
|
2006-10-10 01:06:48 +02:00
|
|
|
"ReleaseMutex should have failed with ERROR_NOT_OWNER instead of %d\n", GetLastError());
|
2006-06-14 14:20:31 +02:00
|
|
|
|
2008-05-21 20:41:45 +02:00
|
|
|
/* test case sensitivity */
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hOpened = OpenMutex(READ_CONTROL, FALSE, "WINETESTMUTEX");
|
|
|
|
ok(!hOpened, "OpenMutex succeeded\n");
|
2011-08-09 22:06:26 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
2008-05-21 20:41:45 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hOpened = OpenMutex(READ_CONTROL, FALSE, "winetestmutex");
|
|
|
|
ok(!hOpened, "OpenMutex succeeded\n");
|
2011-08-09 22:06:26 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
2008-05-21 20:41:45 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hOpened = CreateMutex(NULL, FALSE, "WineTestMutex");
|
|
|
|
ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError());
|
|
|
|
ok(GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
|
2006-06-14 14:20:31 +02:00
|
|
|
CloseHandle(hOpened);
|
2008-05-21 20:41:45 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hOpened = CreateMutex(NULL, FALSE, "WINETESTMUTEX");
|
|
|
|
ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError());
|
|
|
|
ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle(hOpened);
|
|
|
|
|
2006-06-14 14:20:31 +02:00
|
|
|
CloseHandle(hCreated);
|
|
|
|
}
|
|
|
|
|
2007-02-02 15:41:15 +01:00
|
|
|
static void test_slist(void)
|
|
|
|
{
|
|
|
|
struct item
|
|
|
|
{
|
|
|
|
SLIST_ENTRY entry;
|
|
|
|
int value;
|
|
|
|
} item1, item2, item3, *pitem;
|
|
|
|
|
2009-01-29 22:08:07 +01:00
|
|
|
SLIST_HEADER slist_header;
|
2007-02-02 15:41:15 +01:00
|
|
|
PSLIST_ENTRY entry;
|
|
|
|
USHORT size;
|
|
|
|
|
|
|
|
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 = GetModuleHandle("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)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("some required slist entrypoints were not found, skipping tests\n");
|
2007-02-02 15:41:15 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2008-05-21 20:42:54 +02:00
|
|
|
static void test_event(void)
|
2007-10-24 17:07:15 +02:00
|
|
|
{
|
2008-05-21 20:42:54 +02:00
|
|
|
HANDLE handle, handle2;
|
2007-10-24 17:07:15 +02:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
|
|
|
SECURITY_DESCRIPTOR sd;
|
|
|
|
ACL acl;
|
2012-03-12 10:33:32 +01:00
|
|
|
DWORD ret;
|
|
|
|
BOOL val;
|
2007-10-24 17:07:15 +02:00
|
|
|
|
|
|
|
/* no sd */
|
|
|
|
handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle(handle);
|
|
|
|
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = &sd;
|
|
|
|
sa.bInheritHandle = FALSE;
|
|
|
|
|
|
|
|
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
|
|
|
|
/* blank sd */
|
|
|
|
handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle(handle);
|
|
|
|
|
|
|
|
/* sd with NULL dacl */
|
|
|
|
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
|
|
|
|
handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle(handle);
|
|
|
|
|
|
|
|
/* sd with empty dacl */
|
|
|
|
InitializeAcl(&acl, sizeof(acl), ACL_REVISION);
|
|
|
|
SetSecurityDescriptorDacl(&sd, TRUE, &acl, FALSE);
|
|
|
|
handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle(handle);
|
2008-05-21 20:42:54 +02:00
|
|
|
|
|
|
|
/* test case sensitivity */
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok( handle != NULL, "CreateEvent failed with error %u\n", GetLastError());
|
|
|
|
ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok( handle2 != NULL, "CreateEvent failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": TEST EVENT");
|
|
|
|
ok( handle2 != NULL, "CreateEvent failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, __FILE__ ": Test Event");
|
|
|
|
ok( handle2 != NULL, "OpenEvent failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, __FILE__ ": TEST EVENT");
|
|
|
|
ok( !handle2, "OpenEvent succeeded\n");
|
2011-08-09 22:06:26 +02:00
|
|
|
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
2008-05-21 20:42:54 +02:00
|
|
|
|
|
|
|
CloseHandle( handle );
|
2012-03-12 10:33:32 +01:00
|
|
|
|
|
|
|
/* resource notifications are events too */
|
|
|
|
|
|
|
|
if (!pCreateMemoryResourceNotification || !pQueryMemoryResourceNotification)
|
|
|
|
{
|
|
|
|
trace( "memory resource notifications not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handle = pCreateMemoryResourceNotification( HighMemoryResourceNotification + 1 );
|
|
|
|
ok( !handle, "CreateMemoryResourceNotification succeeded\n" );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
|
|
|
|
ret = pQueryMemoryResourceNotification( handle, &val );
|
|
|
|
ok( !ret, "QueryMemoryResourceNotification succeeded\n" );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
|
|
|
|
|
|
|
|
handle = pCreateMemoryResourceNotification( LowMemoryResourceNotification );
|
|
|
|
ok( handle != 0, "CreateMemoryResourceNotification failed err %u\n", GetLastError() );
|
|
|
|
ret = WaitForSingleObject( handle, 10 );
|
|
|
|
ok( ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT, "WaitForSingleObject wrong ret %u\n", ret );
|
|
|
|
|
|
|
|
val = ~0;
|
|
|
|
ret = pQueryMemoryResourceNotification( handle, &val );
|
|
|
|
ok( ret, "QueryMemoryResourceNotification failed err %u\n", GetLastError() );
|
|
|
|
ok( val == FALSE || val == TRUE, "wrong value %u\n", val );
|
|
|
|
ret = CloseHandle( handle );
|
|
|
|
ok( ret, "CloseHandle failed err %u\n", GetLastError() );
|
|
|
|
|
|
|
|
handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
|
|
|
|
val = ~0;
|
|
|
|
ret = pQueryMemoryResourceNotification( handle, &val );
|
|
|
|
ok( ret, "QueryMemoryResourceNotification failed err %u\n", GetLastError() );
|
|
|
|
ok( val == FALSE || val == TRUE, "wrong value %u\n", val );
|
|
|
|
CloseHandle( handle );
|
2007-10-24 17:07:15 +02:00
|
|
|
}
|
|
|
|
|
2008-05-21 20:43:43 +02:00
|
|
|
static void test_semaphore(void)
|
|
|
|
{
|
|
|
|
HANDLE handle, handle2;
|
|
|
|
|
|
|
|
/* test case sensitivity */
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": Test Semaphore");
|
|
|
|
ok(handle != NULL, "CreateSemaphore failed with error %u\n", GetLastError());
|
|
|
|
ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": Test Semaphore");
|
|
|
|
ok( handle2 != NULL, "CreateSemaphore failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": TEST SEMAPHORE");
|
|
|
|
ok( handle2 != NULL, "CreateSemaphore failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = OpenSemaphoreA( SEMAPHORE_ALL_ACCESS, FALSE, __FILE__ ": Test Semaphore");
|
|
|
|
ok( handle2 != NULL, "OpenSemaphore failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle2 = OpenSemaphoreA( SEMAPHORE_ALL_ACCESS, FALSE, __FILE__ ": TEST SEMAPHORE");
|
|
|
|
ok( !handle2, "OpenSemaphore succeeded\n");
|
2011-08-09 22:06:26 +02:00
|
|
|
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
|
2008-05-21 20:43:43 +02:00
|
|
|
|
|
|
|
CloseHandle( handle );
|
|
|
|
}
|
|
|
|
|
2008-05-21 20:44:36 +02:00
|
|
|
static void test_waitable_timer(void)
|
|
|
|
{
|
|
|
|
HANDLE handle, handle2;
|
|
|
|
|
2008-05-25 13:51:21 +02:00
|
|
|
if (!pCreateWaitableTimerA || !pOpenWaitableTimerA)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("{Create,Open}WaitableTimerA() is not available\n");
|
2008-05-25 13:51:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-21 20:44:36 +02:00
|
|
|
/* test case sensitivity */
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-25 13:51:21 +02:00
|
|
|
handle = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer");
|
2008-05-21 20:44:36 +02:00
|
|
|
ok(handle != NULL, "CreateWaitableTimer failed with error %u\n", GetLastError());
|
|
|
|
ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-25 13:51:21 +02:00
|
|
|
handle2 = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer");
|
2008-05-21 20:44:36 +02:00
|
|
|
ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-25 13:51:21 +02:00
|
|
|
handle2 = pCreateWaitableTimerA(NULL, FALSE, __FILE__ ": TEST WAITABLETIMER");
|
2008-05-21 20:44:36 +02:00
|
|
|
ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError());
|
|
|
|
ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-25 13:51:21 +02:00
|
|
|
handle2 = pOpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": Test WaitableTimer");
|
2008-05-21 20:44:36 +02:00
|
|
|
ok( handle2 != NULL, "OpenWaitableTimer failed with error %d\n", GetLastError());
|
|
|
|
CloseHandle( handle2 );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-05-25 13:51:21 +02:00
|
|
|
handle2 = pOpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": TEST WAITABLETIMER");
|
2008-05-21 20:44:36 +02:00
|
|
|
ok( !handle2, "OpenWaitableTimer succeeded\n");
|
2008-08-04 17:29:49 +02:00
|
|
|
ok( GetLastError() == ERROR_FILE_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_INVALID_NAME, /* win98 */
|
|
|
|
"wrong error %u\n", GetLastError());
|
2008-05-21 20:44:36 +02:00
|
|
|
|
|
|
|
CloseHandle( handle );
|
|
|
|
}
|
|
|
|
|
2007-12-17 18:16:49 +01:00
|
|
|
static HANDLE sem = 0;
|
|
|
|
|
2008-01-16 12:19:21 +01:00
|
|
|
static void CALLBACK iocp_callback(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
|
2007-12-17 18:16:49 +01:00
|
|
|
{
|
|
|
|
ReleaseSemaphore(sem, 1, NULL);
|
|
|
|
}
|
|
|
|
|
2008-07-16 02:49:57 +02:00
|
|
|
static BOOL (WINAPI *p_BindIoCompletionCallback)( HANDLE FileHandle, LPOVERLAPPED_COMPLETION_ROUTINE Function, ULONG Flags) = NULL;
|
2007-12-17 18:16:49 +01:00
|
|
|
|
|
|
|
static void test_iocp_callback(void)
|
|
|
|
{
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
DWORD ret;
|
|
|
|
BOOL retb;
|
|
|
|
static const char prefix[] = "pfx";
|
|
|
|
HANDLE hFile;
|
|
|
|
HMODULE hmod = GetModuleHandleA("kernel32.dll");
|
|
|
|
DWORD bytesWritten;
|
|
|
|
const char *buffer = "12345678123456781234567812345678";
|
|
|
|
OVERLAPPED overlapped;
|
|
|
|
|
|
|
|
p_BindIoCompletionCallback = (void*)GetProcAddress(hmod, "BindIoCompletionCallback");
|
|
|
|
if(!p_BindIoCompletionCallback) {
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("BindIoCompletionCallback not found in this DLL\n");
|
2007-12-17 18:16:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sem = CreateSemaphore(NULL, 0, 1, NULL);
|
|
|
|
ok(sem != INVALID_HANDLE_VALUE, "Creating a semaphore failed\n");
|
|
|
|
|
|
|
|
ret = GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
|
|
|
|
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
|
|
|
|
|
|
|
|
ret = GetTempFileNameA(temp_path, prefix, 0, filename);
|
|
|
|
ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
|
|
|
|
|
|
|
|
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS, 0);
|
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
|
|
|
|
|
|
|
|
retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
|
|
|
|
ok(retb == FALSE, "BindIoCompletionCallback succeeded on a file that wasn't created with FILE_FLAG_OVERLAPPED\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CloseHandle(hFile);
|
|
|
|
ok( ret, "CloseHandle: error %d\n", GetLastError());
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok( ret, "DeleteFileA: error %d\n", GetLastError());
|
|
|
|
|
|
|
|
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED, 0);
|
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
|
|
|
|
|
|
|
|
retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
|
|
|
|
ok(retb == TRUE, "BindIoCompletionCallback failed\n");
|
|
|
|
|
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
2009-03-11 09:39:16 +01:00
|
|
|
retb = WriteFile(hFile, buffer, 4, &bytesWritten, &overlapped);
|
2007-12-17 18:16:49 +01:00
|
|
|
ok(retb == TRUE || GetLastError() == ERROR_IO_PENDING, "WriteFile failed, lastError = %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(sem, 5000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "Wait for the IO completion callback failed\n");
|
|
|
|
CloseHandle(sem);
|
|
|
|
|
|
|
|
retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
|
|
|
|
ok(retb == FALSE, "BindIoCompletionCallback succeeded when setting the same callback on the file again\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
|
|
|
|
retb = p_BindIoCompletionCallback(hFile, NULL, 0);
|
|
|
|
ok(retb == FALSE, "BindIoCompletionCallback succeeded when setting the callback to NULL\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CloseHandle(hFile);
|
|
|
|
ok( ret, "CloseHandle: error %d\n", GetLastError());
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok( ret, "DeleteFileA: error %d\n", GetLastError());
|
|
|
|
|
2008-04-25 05:50:45 +02:00
|
|
|
/* win2k3 requires the Flags parameter to be zero */
|
|
|
|
SetLastError(0xdeadbeef);
|
2007-12-17 18:16:49 +01:00
|
|
|
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED, 0);
|
|
|
|
ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
|
|
|
|
retb = p_BindIoCompletionCallback(hFile, iocp_callback, 12345);
|
2008-04-25 05:50:45 +02:00
|
|
|
if (!retb)
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
else
|
|
|
|
ok(retb == TRUE, "BindIoCompletionCallback failed with Flags != 0\n");
|
2007-12-17 18:16:49 +01:00
|
|
|
ret = CloseHandle(hFile);
|
|
|
|
ok( ret, "CloseHandle: error %d\n", GetLastError());
|
|
|
|
ret = DeleteFileA(filename);
|
|
|
|
ok( ret, "DeleteFileA: error %d\n", GetLastError());
|
|
|
|
|
|
|
|
retb = p_BindIoCompletionCallback(NULL, iocp_callback, 0);
|
|
|
|
ok(retb == FALSE, "BindIoCompletionCallback succeeded on a NULL file\n");
|
2008-09-11 14:07:54 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE ||
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER, /* vista */
|
|
|
|
"Last error is %d\n", GetLastError());
|
2007-12-17 18:16:49 +01:00
|
|
|
}
|
|
|
|
|
2008-07-17 02:42:32 +02:00
|
|
|
static void CALLBACK timer_queue_cb1(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
int *pn = p;
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
++*pn;
|
|
|
|
}
|
|
|
|
|
2008-07-22 02:43:28 +02:00
|
|
|
struct timer_queue_data1
|
|
|
|
{
|
|
|
|
int num_calls;
|
|
|
|
int max_calls;
|
|
|
|
HANDLE q, t;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK timer_queue_cb2(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
|
|
|
struct timer_queue_data1 *d = p;
|
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
if (d->t && ++d->num_calls == d->max_calls)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
/* Note, XP SP2 does *not* do any deadlock checking, so passing
|
|
|
|
INVALID_HANDLE_VALUE here will just hang. */
|
|
|
|
ret = pDeleteTimerQueueTimer(d->q, d->t, NULL);
|
|
|
|
ok(!ret, "DeleteTimerQueueTimer\n");
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "DeleteTimerQueueTimer\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK timer_queue_cb3(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
|
|
|
struct timer_queue_data1 *d = p;
|
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
if (d->t && ++d->num_calls == d->max_calls)
|
|
|
|
{
|
|
|
|
/* Basically kill the timer since it won't have time to run
|
|
|
|
again. */
|
|
|
|
BOOL ret = pChangeTimerQueueTimer(d->q, d->t, 10000, 0);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 01:26:32 +02:00
|
|
|
static void CALLBACK timer_queue_cb4(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
|
|
|
struct timer_queue_data1 *d = p;
|
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
if (d->t)
|
|
|
|
{
|
|
|
|
/* This tests whether a timer gets flagged for deletion before
|
|
|
|
or after the callback runs. If we start this timer with a
|
|
|
|
period of zero (run once), then ChangeTimerQueueTimer will
|
|
|
|
fail if the timer is already flagged. Hence we really run
|
|
|
|
only once. Otherwise we will run multiple times. */
|
|
|
|
BOOL ret = pChangeTimerQueueTimer(d->q, d->t, 50, 50);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer\n");
|
|
|
|
++d->num_calls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 01:27:54 +02:00
|
|
|
static void CALLBACK timer_queue_cb5(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
2009-01-03 20:17:31 +01:00
|
|
|
DWORD_PTR delay = (DWORD_PTR) p;
|
2008-07-25 01:27:54 +02:00
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
if (delay)
|
|
|
|
Sleep(delay);
|
|
|
|
}
|
|
|
|
|
2008-07-25 23:50:10 +02:00
|
|
|
static void CALLBACK timer_queue_cb6(PVOID p, BOOLEAN timedOut)
|
|
|
|
{
|
|
|
|
struct timer_queue_data1 *d = p;
|
|
|
|
ok(timedOut, "Timer callbacks should always time out\n");
|
|
|
|
/* This tests an original implementation bug where a deleted timer may get
|
|
|
|
to run, but it is tricky to set up. */
|
|
|
|
if (d->q && d->num_calls++ == 0)
|
|
|
|
{
|
|
|
|
/* First run: delete ourselves, then insert and remove a timer
|
|
|
|
that goes in front of us in the sorted timeout list. Once
|
|
|
|
removed, we will still timeout at the faster timer's due time,
|
|
|
|
but this should be a no-op if we are bug-free. There should
|
|
|
|
not be a second run. We can test the value of num_calls later. */
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE t;
|
|
|
|
|
|
|
|
/* The delete will pend while we are in this callback. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueTimer(d->q, d->t, NULL);
|
|
|
|
ok(!ret, "DeleteTimerQueueTimer\n");
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING, "DeleteTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pCreateTimerQueueTimer(&t, d->q, timer_queue_cb1, NULL, 100, 0, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pDeleteTimerQueueTimer(d->q, t, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Now we stay alive by hanging around in the callback. */
|
|
|
|
Sleep(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-17 02:42:32 +02:00
|
|
|
static void test_timer_queue(void)
|
|
|
|
{
|
2012-07-03 10:03:07 +02:00
|
|
|
HANDLE q, t0, t1, t2, t3, t4, t5;
|
|
|
|
int n0, n1, n2, n3, n4, n5;
|
2008-07-25 23:50:10 +02:00
|
|
|
struct timer_queue_data1 d1, d2, d3, d4;
|
2008-07-25 01:27:54 +02:00
|
|
|
HANDLE e, et1, et2;
|
2012-07-03 10:03:07 +02:00
|
|
|
BOOL ret, ret0;
|
2008-07-17 02:42:32 +02:00
|
|
|
|
2008-07-22 02:43:28 +02:00
|
|
|
if (!pChangeTimerQueueTimer || !pCreateTimerQueue || !pCreateTimerQueueTimer
|
|
|
|
|| !pDeleteTimerQueueEx || !pDeleteTimerQueueTimer)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("TimerQueue API not present\n");
|
2008-07-22 02:42:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-20 23:51:31 +02:00
|
|
|
/* Test asynchronous deletion of the queue. */
|
2008-07-22 02:42:41 +02:00
|
|
|
q = pCreateTimerQueue();
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pDeleteTimerQueueEx(q, NULL);
|
2008-11-17 23:01:21 +01:00
|
|
|
ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
|
2008-09-28 21:09:21 +02:00
|
|
|
"DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-17 02:42:32 +02:00
|
|
|
|
2008-07-20 23:51:31 +02:00
|
|
|
/* Test synchronous deletion of the queue and running timers. */
|
2008-07-22 02:42:41 +02:00
|
|
|
q = pCreateTimerQueue();
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
2012-07-03 10:03:07 +02:00
|
|
|
/* Not called. */
|
|
|
|
t0 = NULL;
|
|
|
|
n0 = 0;
|
|
|
|
ret = pCreateTimerQueueTimer(&t0, q, timer_queue_cb1, &n0, 0,
|
|
|
|
300, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t0 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
ret0 = pDeleteTimerQueueTimer(q, t0, NULL);
|
|
|
|
ok((!ret0 && GetLastError() == ERROR_IO_PENDING) ||
|
|
|
|
broken(ret0), /* Win 2000 & XP & 2003 */
|
|
|
|
"DeleteTimerQueueTimer ret=%d le=%u\n", ret0, GetLastError());
|
|
|
|
|
2008-07-17 02:42:32 +02:00
|
|
|
/* Called once. */
|
|
|
|
t1 = NULL;
|
|
|
|
n1 = 0;
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pCreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 0,
|
|
|
|
0, 0);
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
|
|
|
|
/* A slow one. */
|
|
|
|
t2 = NULL;
|
|
|
|
n2 = 0;
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pCreateTimerQueueTimer(&t2, q, timer_queue_cb1, &n2, 0,
|
|
|
|
100, 0);
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t2 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
|
|
|
|
/* A fast one. */
|
|
|
|
t3 = NULL;
|
|
|
|
n3 = 0;
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pCreateTimerQueueTimer(&t3, q, timer_queue_cb1, &n3, 0,
|
|
|
|
10, 0);
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t3 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
|
|
|
|
/* Start really late (it won't start). */
|
|
|
|
t4 = NULL;
|
|
|
|
n4 = 0;
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pCreateTimerQueueTimer(&t4, q, timer_queue_cb1, &n4, 10000,
|
|
|
|
10, 0);
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t4 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
|
|
|
|
/* Start soon, but delay so long it won't run again. */
|
|
|
|
t5 = NULL;
|
|
|
|
n5 = 0;
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pCreateTimerQueueTimer(&t5, q, timer_queue_cb1, &n5, 0,
|
|
|
|
10000, 0);
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t5 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
|
|
|
|
/* Give them a chance to do some work. */
|
|
|
|
Sleep(500);
|
|
|
|
|
2008-07-25 01:27:54 +02:00
|
|
|
/* Test deleting a once-only timer. */
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* A periodic timer. */
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t2, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer\n");
|
|
|
|
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pDeleteTimerQueueEx(q, INVALID_HANDLE_VALUE);
|
2008-07-22 02:46:30 +02:00
|
|
|
ok(ret, "DeleteTimerQueueEx\n");
|
2012-07-03 10:03:07 +02:00
|
|
|
todo_wine
|
|
|
|
ok(n0 == 1 || broken(ret0 && n0 == 0), "Timer callback 0 expected 1 got %d\n", n0);
|
2012-07-03 10:02:51 +02:00
|
|
|
ok(n1 == 1, "Timer callback 1 expected 1 got %d\n", n1);
|
|
|
|
ok(n2 < n3, "Timer callback 2 & 3 expected %d < %d\n", n2, n3);
|
|
|
|
ok(n4 == 0, "Timer callback 4 expected 0 got %d\n", n4);
|
|
|
|
ok(n5 == 1, "Timer callback 5 expected 1 got %d\n", n5);
|
2008-07-17 02:42:32 +02:00
|
|
|
|
2008-07-25 01:27:54 +02:00
|
|
|
/* Test synchronous deletion of the timer/queue with event trigger. */
|
2008-07-17 02:42:32 +02:00
|
|
|
e = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2008-07-25 01:27:54 +02:00
|
|
|
et1 = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
et2 = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
if (!e || !et1 || !et2)
|
2008-07-17 02:42:32 +02:00
|
|
|
{
|
|
|
|
skip("Failed to create timer queue descruction event\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-22 02:42:41 +02:00
|
|
|
q = pCreateTimerQueue();
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
2008-07-25 01:27:54 +02:00
|
|
|
/* Run once and finish quickly (should be done when we delete it). */
|
|
|
|
t1 = NULL;
|
2008-11-03 22:35:08 +01:00
|
|
|
ret = pCreateTimerQueueTimer(&t1, q, timer_queue_cb5, NULL, 0, 0, 0);
|
2008-07-25 01:27:54 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Run once and finish slowly (shouldn't be done when we delete it). */
|
|
|
|
t2 = NULL;
|
|
|
|
ret = pCreateTimerQueueTimer(&t2, q, timer_queue_cb5, (PVOID) 1000, 0,
|
|
|
|
0, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t2 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Run once and finish quickly (should be done when we delete it). */
|
|
|
|
t3 = NULL;
|
2008-11-03 22:35:08 +01:00
|
|
|
ret = pCreateTimerQueueTimer(&t3, q, timer_queue_cb5, NULL, 0, 0, 0);
|
2008-07-25 01:27:54 +02:00
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t3 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Run once and finish slowly (shouldn't be done when we delete it). */
|
|
|
|
t4 = NULL;
|
|
|
|
ret = pCreateTimerQueueTimer(&t4, q, timer_queue_cb5, (PVOID) 1000, 0,
|
|
|
|
0, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t4 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Give them a chance to start. */
|
|
|
|
Sleep(400);
|
|
|
|
|
|
|
|
/* DeleteTimerQueueTimer always returns PENDING with a NULL event,
|
|
|
|
even if the timer is finished. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t1, NULL);
|
2008-11-17 23:01:21 +01:00
|
|
|
ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
|
2008-09-28 21:09:21 +02:00
|
|
|
"DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-25 01:27:54 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t2, NULL);
|
2008-09-28 21:09:21 +02:00
|
|
|
ok(!ret, "DeleteTimerQueueTimer call was expected to fail\n");
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING,
|
|
|
|
"DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-25 01:27:54 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t3, et1);
|
2008-09-28 21:09:21 +02:00
|
|
|
ok(ret, "DeleteTimerQueueTimer call was expected to fail\n");
|
|
|
|
ok(GetLastError() == 0xdeadbeef,
|
|
|
|
"DeleteTimerQueueTimer, GetLastError: expected 0xdeadbeef, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-25 01:27:54 +02:00
|
|
|
ok(WaitForSingleObject(et1, 250) == WAIT_OBJECT_0,
|
|
|
|
"Timer destruction event not triggered\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t4, et2);
|
2008-09-28 21:09:21 +02:00
|
|
|
ok(!ret, "DeleteTimerQueueTimer call was expected to fail\n");
|
|
|
|
ok(GetLastError() == ERROR_IO_PENDING,
|
|
|
|
"DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-25 01:27:54 +02:00
|
|
|
ok(WaitForSingleObject(et2, 1000) == WAIT_OBJECT_0,
|
|
|
|
"Timer destruction event not triggered\n");
|
|
|
|
|
2008-07-17 02:42:32 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2008-07-22 02:42:41 +02:00
|
|
|
ret = pDeleteTimerQueueEx(q, e);
|
2008-11-17 23:01:21 +01:00
|
|
|
ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
|
2008-09-28 21:09:21 +02:00
|
|
|
"DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-17 02:42:32 +02:00
|
|
|
ok(WaitForSingleObject(e, 250) == WAIT_OBJECT_0,
|
2008-07-25 01:27:54 +02:00
|
|
|
"Queue destruction event not triggered\n");
|
2008-07-17 02:42:32 +02:00
|
|
|
CloseHandle(e);
|
2008-07-22 02:43:28 +02:00
|
|
|
|
|
|
|
/* Test deleting/changing a timer in execution. */
|
|
|
|
q = pCreateTimerQueue();
|
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
2008-07-25 01:27:03 +02:00
|
|
|
/* Test changing a once-only timer before it fires (this is allowed,
|
|
|
|
whereas after it fires you cannot). */
|
|
|
|
n1 = 0;
|
|
|
|
ret = pCreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 10000,
|
|
|
|
0, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
ret = pChangeTimerQueueTimer(q, t1, 0, 0);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer\n");
|
|
|
|
|
2008-07-22 02:43:28 +02:00
|
|
|
d2.t = t2 = NULL;
|
|
|
|
d2.num_calls = 0;
|
|
|
|
d2.max_calls = 3;
|
|
|
|
d2.q = q;
|
|
|
|
ret = pCreateTimerQueueTimer(&t2, q, timer_queue_cb2, &d2, 10,
|
|
|
|
10, 0);
|
|
|
|
d2.t = t2;
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t2 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-22 02:43:28 +02:00
|
|
|
|
|
|
|
d3.t = t3 = NULL;
|
|
|
|
d3.num_calls = 0;
|
|
|
|
d3.max_calls = 4;
|
|
|
|
d3.q = q;
|
|
|
|
ret = pCreateTimerQueueTimer(&t3, q, timer_queue_cb3, &d3, 10,
|
|
|
|
10, 0);
|
|
|
|
d3.t = t3;
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
2008-07-22 02:44:05 +02:00
|
|
|
ok(t3 != NULL, "CreateTimerQueueTimer\n");
|
2008-07-22 02:43:28 +02:00
|
|
|
|
2008-07-25 01:26:32 +02:00
|
|
|
d4.t = t4 = NULL;
|
|
|
|
d4.num_calls = 0;
|
|
|
|
d4.q = q;
|
|
|
|
ret = pCreateTimerQueueTimer(&t4, q, timer_queue_cb4, &d4, 10,
|
|
|
|
0, 0);
|
|
|
|
d4.t = t4;
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t4 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
2008-11-17 23:01:21 +01:00
|
|
|
Sleep(500);
|
2008-07-22 02:43:28 +02:00
|
|
|
|
|
|
|
ret = pDeleteTimerQueueEx(q, INVALID_HANDLE_VALUE);
|
2008-07-22 02:46:30 +02:00
|
|
|
ok(ret, "DeleteTimerQueueEx\n");
|
2008-07-25 01:27:03 +02:00
|
|
|
ok(n1 == 1, "ChangeTimerQueueTimer\n");
|
2008-07-22 02:43:28 +02:00
|
|
|
ok(d2.num_calls == d2.max_calls, "DeleteTimerQueueTimer\n");
|
2008-07-25 01:27:03 +02:00
|
|
|
ok(d3.num_calls == d3.max_calls, "ChangeTimerQueueTimer\n");
|
2008-07-25 01:26:32 +02:00
|
|
|
ok(d4.num_calls == 1, "Timer flagged for deletion incorrectly\n");
|
2008-07-25 23:50:10 +02:00
|
|
|
|
|
|
|
/* Test an obscure bug that was in the original implementation. */
|
|
|
|
q = pCreateTimerQueue();
|
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
|
|
|
/* All the work is done in the callback. */
|
|
|
|
d1.t = t1 = NULL;
|
|
|
|
d1.num_calls = 0;
|
|
|
|
d1.q = q;
|
|
|
|
ret = pCreateTimerQueueTimer(&t1, q, timer_queue_cb6, &d1, 100,
|
|
|
|
100, WT_EXECUTELONGFUNCTION);
|
|
|
|
d1.t = t1;
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
Sleep(750);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueEx(q, NULL);
|
2008-11-17 23:01:21 +01:00
|
|
|
ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
|
2008-09-28 21:09:21 +02:00
|
|
|
"DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-25 23:50:10 +02:00
|
|
|
ok(d1.num_calls == 1, "DeleteTimerQueueTimer\n");
|
2008-07-29 23:36:41 +02:00
|
|
|
|
|
|
|
/* Test functions on the default timer queue. */
|
|
|
|
t1 = NULL;
|
|
|
|
n1 = 0;
|
|
|
|
ret = pCreateTimerQueueTimer(&t1, NULL, timer_queue_cb1, &n1, 1000,
|
|
|
|
1000, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer, default queue\n");
|
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer, default queue\n");
|
|
|
|
|
|
|
|
ret = pChangeTimerQueueTimer(NULL, t1, 2000, 2000);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer, default queue\n");
|
|
|
|
|
|
|
|
ret = pDeleteTimerQueueTimer(NULL, t1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer, default queue\n");
|
2008-07-29 23:38:23 +02:00
|
|
|
|
|
|
|
/* Try mixing default and non-default queues. Apparently this works. */
|
|
|
|
q = pCreateTimerQueue();
|
|
|
|
ok(q != NULL, "CreateTimerQueue\n");
|
|
|
|
|
|
|
|
t1 = NULL;
|
|
|
|
n1 = 0;
|
|
|
|
ret = pCreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 1000,
|
|
|
|
1000, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t1 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
t2 = NULL;
|
|
|
|
n2 = 0;
|
|
|
|
ret = pCreateTimerQueueTimer(&t2, NULL, timer_queue_cb1, &n2, 1000,
|
|
|
|
1000, 0);
|
|
|
|
ok(ret, "CreateTimerQueueTimer\n");
|
|
|
|
ok(t2 != NULL, "CreateTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pChangeTimerQueueTimer(NULL, t1, 2000, 2000);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pChangeTimerQueueTimer(q, t2, 2000, 2000);
|
|
|
|
ok(ret, "ChangeTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pDeleteTimerQueueTimer(NULL, t1, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer\n");
|
|
|
|
|
|
|
|
ret = pDeleteTimerQueueTimer(q, t2, INVALID_HANDLE_VALUE);
|
|
|
|
ok(ret, "DeleteTimerQueueTimer\n");
|
|
|
|
|
|
|
|
/* Try to delete the default queue? In any case: not allowed. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueEx(NULL, NULL);
|
2008-09-28 21:09:21 +02:00
|
|
|
ok(!ret, "DeleteTimerQueueEx call was expected to fail\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
|
|
|
"DeleteTimerQueueEx, GetLastError: expected ERROR_INVALID_HANDLE, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-29 23:38:23 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pDeleteTimerQueueEx(q, NULL);
|
2008-11-17 23:01:21 +01:00
|
|
|
ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
|
2008-09-28 21:09:21 +02:00
|
|
|
"DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
|
|
|
|
GetLastError());
|
2008-07-17 02:42:32 +02:00
|
|
|
}
|
|
|
|
|
2010-09-22 21:06:22 +02:00
|
|
|
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);
|
|
|
|
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);
|
2010-09-22 19:53:16 +02:00
|
|
|
ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret);
|
2010-09-22 21:06:22 +02:00
|
|
|
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);
|
2010-09-22 19:53:16 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret);
|
2010-09-22 19:54:36 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
|
2010-09-22 21:06:22 +02:00
|
|
|
|
|
|
|
/* 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);
|
2010-09-22 19:54:36 +02:00
|
|
|
ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
|
2010-09-22 21:06:22 +02:00
|
|
|
|
|
|
|
CloseHandle(signaled);
|
|
|
|
CloseHandle(nonsignaled);
|
|
|
|
}
|
|
|
|
|
2011-07-23 22:02:19 +02:00
|
|
|
static void test_WaitForMultipleObjects(void)
|
|
|
|
{
|
|
|
|
DWORD r;
|
|
|
|
int i;
|
|
|
|
HANDLE maxevents[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
|
|
|
|
/* create the maximum number of events and make sure
|
|
|
|
* we can wait on that many */
|
|
|
|
for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
|
|
|
|
{
|
|
|
|
maxevents[i] = CreateEvent(NULL, i==0, TRUE, NULL);
|
|
|
|
ok( maxevents[i] != 0, "should create enough events\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* a manual-reset event remains signaled, an auto-reset event is cleared */
|
|
|
|
r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should signal lowest handle first, got %d\n", r);
|
|
|
|
r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0);
|
|
|
|
ok( r == WAIT_OBJECT_0, "should signal handle #0 first, got %d\n", r);
|
|
|
|
ok(ResetEvent(maxevents[0]), "ResetEvent\n");
|
|
|
|
for (i=1; i<MAXIMUM_WAIT_OBJECTS; i++)
|
|
|
|
{
|
|
|
|
/* the lowest index is checked first and remaining events are untouched */
|
|
|
|
r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0);
|
|
|
|
ok( r == WAIT_OBJECT_0+i, "should signal handle #%d first, got %d\n", i, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
|
|
|
|
if (maxevents[i]) CloseHandle(maxevents[i]);
|
|
|
|
}
|
|
|
|
|
2005-04-24 19:37:52 +02:00
|
|
|
START_TEST(sync)
|
|
|
|
{
|
2008-05-25 13:51:21 +02:00
|
|
|
HMODULE hdll = GetModuleHandle("kernel32");
|
2008-07-22 02:43:28 +02:00
|
|
|
pChangeTimerQueueTimer = (void*)GetProcAddress(hdll, "ChangeTimerQueueTimer");
|
2008-07-22 02:42:41 +02:00
|
|
|
pCreateTimerQueue = (void*)GetProcAddress(hdll, "CreateTimerQueue");
|
|
|
|
pCreateTimerQueueTimer = (void*)GetProcAddress(hdll, "CreateTimerQueueTimer");
|
2008-05-25 13:51:21 +02:00
|
|
|
pCreateWaitableTimerA = (void*)GetProcAddress(hdll, "CreateWaitableTimerA");
|
2008-07-22 02:42:41 +02:00
|
|
|
pDeleteTimerQueueEx = (void*)GetProcAddress(hdll, "DeleteTimerQueueEx");
|
2008-07-22 02:43:28 +02:00
|
|
|
pDeleteTimerQueueTimer = (void*)GetProcAddress(hdll, "DeleteTimerQueueTimer");
|
2008-05-25 13:51:21 +02:00
|
|
|
pOpenWaitableTimerA = (void*)GetProcAddress(hdll, "OpenWaitableTimerA");
|
2012-03-12 10:33:32 +01:00
|
|
|
pCreateMemoryResourceNotification = (void *)GetProcAddress(hdll, "CreateMemoryResourceNotification");
|
|
|
|
pQueryMemoryResourceNotification = (void *)GetProcAddress(hdll, "QueryMemoryResourceNotification");
|
2008-05-25 13:51:21 +02:00
|
|
|
|
2005-04-24 19:37:52 +02:00
|
|
|
test_signalandwait();
|
2006-06-14 14:20:31 +02:00
|
|
|
test_mutex();
|
2007-02-02 15:41:15 +01:00
|
|
|
test_slist();
|
2008-05-21 20:42:54 +02:00
|
|
|
test_event();
|
2008-05-21 20:43:43 +02:00
|
|
|
test_semaphore();
|
2008-05-21 20:44:36 +02:00
|
|
|
test_waitable_timer();
|
2007-12-17 18:16:49 +01:00
|
|
|
test_iocp_callback();
|
2008-07-17 02:42:32 +02:00
|
|
|
test_timer_queue();
|
2010-09-22 21:06:22 +02:00
|
|
|
test_WaitForSingleObject();
|
2011-07-23 22:02:19 +02:00
|
|
|
test_WaitForMultipleObjects();
|
2005-04-24 19:37:52 +02:00
|
|
|
}
|