2004-10-21 04:48:46 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
|
|
|
|
#define N_TIMEOUT 3
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
typedef struct _TEST *PTEST;
|
|
|
|
|
|
|
|
typedef VOID (*PFNTEST)(PTEST Test, HANDLE hEvent);
|
|
|
|
|
|
|
|
typedef struct _TEST
|
|
|
|
{
|
|
|
|
TCHAR *description;
|
|
|
|
BOOL Result;
|
|
|
|
PFNTEST Routine;
|
|
|
|
int id;
|
|
|
|
} TEST;
|
|
|
|
|
|
|
|
static TEST Tests[3];
|
|
|
|
|
|
|
|
VOID RunTests(VOID)
|
|
|
|
{
|
|
|
|
int i, nTests;
|
|
|
|
static HANDLE hEvent;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if(hEvent == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("Unable to create event!"));
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
nTests = sizeof(Tests) / sizeof(TEST);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
for(i = 0; i < nTests; i++)
|
|
|
|
{
|
|
|
|
Tests[i].id = i + 1;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(Tests[i].Routine == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("+++ TEST %d: %s\n"), Tests[i].id, Tests[i].description);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Tests[i].Routine(&Tests[i], hEvent);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
WaitForSingleObject(hEvent, INFINITE);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("\n\n"));
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
CloseHandle(hEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID PrintTestResults(VOID)
|
|
|
|
{
|
|
|
|
int i, nTests, nsuccess = 0, nfailed = 0;
|
|
|
|
TCHAR *status;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
nTests = sizeof(Tests) / sizeof(TEST);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
for(i = 0; i < nTests; i++)
|
|
|
|
{
|
|
|
|
if(Tests[i].Routine == NULL)
|
|
|
|
{
|
|
|
|
status = _T("SKIPPED");
|
|
|
|
}
|
|
|
|
else if(Tests[i].Result == TRUE)
|
|
|
|
{
|
|
|
|
status = _T("SUCCESS");
|
|
|
|
nsuccess++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = _T("FAILED ");
|
|
|
|
nfailed++;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("Test %d: %s %s\n"), i, status, Tests[i].description);
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("\nTests succeeded: %d, failed: %d\n"), nsuccess, nfailed);
|
|
|
|
if(nfailed == 0)
|
|
|
|
{
|
|
|
|
_tprintf(_T(" ALL TESTS SUCCESSFUL!\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
typedef struct _TESTINFO
|
|
|
|
{
|
|
|
|
PTEST Test;
|
|
|
|
int secsleft;
|
|
|
|
HANDLE hTimer;
|
|
|
|
HANDLE hEvent;
|
|
|
|
/* additional stuff */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
} Test1;
|
|
|
|
struct
|
|
|
|
{
|
2005-05-07 21:24:31 +00:00
|
|
|
HANDLE hWaitEvent;
|
2004-10-21 04:48:46 +00:00
|
|
|
} Test2;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
HANDLE hWaitEvent;
|
|
|
|
HANDLE hNotification;
|
|
|
|
} Test3;
|
|
|
|
};
|
|
|
|
} TESTINFO, *PTESTINFO;
|
|
|
|
|
|
|
|
VOID CALLBACK TimerCallback1(PVOID Param, BOOLEAN Fired)
|
|
|
|
{
|
|
|
|
PTESTINFO Info = (PTESTINFO)Param;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(Info->secsleft == 0)
|
|
|
|
{
|
|
|
|
BOOL stat;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Info->Test->id);
|
|
|
|
stat = DeleteTimerQueueTimer(NULL, Info->hTimer, NULL);
|
|
|
|
if(stat)
|
|
|
|
_tprintf(_T("returned OK -> test FAILED!\n"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int error = GetLastError();
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case ERROR_IO_PENDING:
|
|
|
|
_tprintf(_T("OK, Overlapped I/O operation in progress\n"));
|
|
|
|
/* this test is only successful in this case */
|
|
|
|
Info->Test->Result = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
/* set the event to continue tests */
|
|
|
|
SetEvent(Info->hEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID Test1(PTEST Test, HANDLE hEvent)
|
|
|
|
{
|
|
|
|
static TESTINFO Info;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test = Test;
|
|
|
|
Info.hEvent = hEvent;
|
|
|
|
Info.secsleft = N_TIMEOUT;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback1, &Info, 1000, 1000, 0))
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
|
|
|
|
/* we failed, set the event to continue tests */
|
|
|
|
SetEvent(hEvent);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Info.Test->id, (int)Info.hTimer, (int)Info.secsleft);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
VOID CALLBACK TimerCallback2(PVOID Param, BOOLEAN Fired)
|
|
|
|
{
|
|
|
|
PTESTINFO Info = (PTESTINFO)Param;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(Info->secsleft == 0)
|
|
|
|
{
|
|
|
|
/* set the event to continue tests */
|
|
|
|
SetEvent(Info->Test2.hWaitEvent);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
/* sleep a bit */
|
2005-05-07 21:24:31 +00:00
|
|
|
Sleep(1500);
|
2004-10-21 04:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID Test2(PTEST Test, HANDLE hEvent)
|
|
|
|
{
|
|
|
|
static TESTINFO Info;
|
|
|
|
BOOL stat;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test = Test;
|
|
|
|
Info.hEvent = hEvent;
|
|
|
|
Info.secsleft = N_TIMEOUT;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test2.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if(Info.Test2.hWaitEvent == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback2, &Info, 1000, 1000, 0))
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
CloseHandle(Info.Test2.hWaitEvent);
|
|
|
|
/* we failed, set the event to continue tests */
|
|
|
|
SetEvent(hEvent);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
WaitForSingleObject(Info.Test2.hWaitEvent, INFINITE);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id);
|
|
|
|
stat = DeleteTimerQueueTimer(NULL, Info.hTimer, INVALID_HANDLE_VALUE);
|
|
|
|
if(stat)
|
|
|
|
{
|
|
|
|
_tprintf(_T("OK\n"));
|
|
|
|
/* this test is only successful in this case */
|
|
|
|
Test->Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int error = GetLastError();
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case ERROR_IO_PENDING:
|
|
|
|
_tprintf(_T("FAILED, Overlapped I/O operation in progress\n"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
SetEvent(Info.hEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
VOID CALLBACK TimerCallback3(PVOID Param, BOOLEAN Fired)
|
|
|
|
{
|
|
|
|
PTESTINFO Info = (PTESTINFO)Param;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(Info->secsleft == 0)
|
|
|
|
{
|
|
|
|
/* set the event to continue tests */
|
|
|
|
SetEvent(Info->Test3.hWaitEvent);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
/* sleep a bit */
|
2005-05-07 21:24:31 +00:00
|
|
|
Sleep(1500);
|
2004-10-21 04:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID Test3(PTEST Test, HANDLE hEvent)
|
|
|
|
{
|
|
|
|
static TESTINFO Info;
|
|
|
|
BOOL stat;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test = Test;
|
|
|
|
Info.hEvent = hEvent;
|
|
|
|
Info.secsleft = N_TIMEOUT;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test3.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if(Info.Test3.hWaitEvent == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Info.Test3.hNotification = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if(Info.Test3.hNotification == NULL)
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]Unable to create notification event!\n"), (int)Info.Test->id);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback3, &Info, 1000, 1000, 0))
|
|
|
|
{
|
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
CloseHandle(Info.Test3.hWaitEvent);
|
|
|
|
CloseHandle(Info.Test3.hNotification);
|
|
|
|
/* we failed, set the event to continue tests */
|
|
|
|
SetEvent(hEvent);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
WaitForSingleObject(Info.Test3.hWaitEvent, INFINITE);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id);
|
|
|
|
stat = DeleteTimerQueueTimer(NULL, Info.hTimer, Info.Test3.hNotification);
|
|
|
|
if(stat)
|
|
|
|
{
|
|
|
|
_tprintf(_T("returned OK -> test FAILED!\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int error = GetLastError();
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case ERROR_IO_PENDING:
|
|
|
|
_tprintf(_T("OK, Overlapped I/O operation in progress\n"));
|
|
|
|
/* this test is only successful in this case */
|
|
|
|
Test->Result = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
WaitForSingleObject(Info.Test3.hNotification, INFINITE);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
CloseHandle(Info.Test3.hWaitEvent);
|
|
|
|
CloseHandle(Info.Test3.hNotification);
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
SetEvent(Info.hEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
InitTests(VOID)
|
|
|
|
{
|
|
|
|
ZeroMemory(Tests, sizeof(Tests));
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Tests[0].description = _T("non-blocking DeleteTimerQueueTimer() call from callback");
|
|
|
|
Tests[0].Routine = Test1;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Tests[1].description = _T("blocking DeleteTimerQueueTimer() call");
|
|
|
|
Tests[1].Routine = Test2;
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
Tests[2].description = _T("blocking DeleteTimerQueueTimer() call with specified event");
|
|
|
|
Tests[2].Routine = Test3;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
_tprintf(_T("+++ TimerQueue test running +++\n\n"));
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
InitTests();
|
2005-05-07 21:24:31 +00:00
|
|
|
|
|
|
|
RunTests();
|
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
_tprintf(_T("\n+++ RESULTS +++\n"));
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
PrintTestResults();
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2004-10-21 04:48:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|