7 /*******************************************************************************/
9 typedef struct _TEST
*PTEST
;
11 typedef VOID (*PFNTEST
)(PTEST Test
, HANDLE hEvent
);
28 hEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
31 _tprintf(_T("Unable to create event!"));
35 nTests
= sizeof(Tests
) / sizeof(TEST
);
37 for(i
= 0; i
< nTests
; i
++)
41 if(Tests
[i
].Routine
== NULL
)
46 _tprintf(_T("+++ TEST %d: %s\n"), Tests
[i
].id
, Tests
[i
].description
);
48 Tests
[i
].Routine(&Tests
[i
], hEvent
);
50 WaitForSingleObject(hEvent
, INFINITE
);
58 VOID
PrintTestResults(VOID
)
60 int i
, nTests
, nsuccess
= 0, nfailed
= 0;
63 nTests
= sizeof(Tests
) / sizeof(TEST
);
65 for(i
= 0; i
< nTests
; i
++)
67 if(Tests
[i
].Routine
== NULL
)
69 status
= _T("SKIPPED");
71 else if(Tests
[i
].Result
== TRUE
)
73 status
= _T("SUCCESS");
78 status
= _T("FAILED ");
82 _tprintf(_T("Test %d: %s %s\n"), i
, status
, Tests
[i
].description
);
85 _tprintf(_T("\nTests succeeded: %d, failed: %d\n"), nsuccess
, nfailed
);
88 _tprintf(_T(" ALL TESTS SUCCESSFUL!\n"));
92 /*******************************************************************************/
94 typedef struct _TESTINFO
100 /* additional stuff */
114 HANDLE hNotification
;
117 } TESTINFO
, *PTESTINFO
;
119 VOID CALLBACK
TimerCallback1(PVOID Param
, BOOLEAN Fired
)
121 PTESTINFO Info
= (PTESTINFO
)Param
;
123 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info
->Test
->id
, (int)Info
->hTimer
, (int)Fired
, --Info
->secsleft
);
125 if(Info
->secsleft
== 0)
129 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Info
->Test
->id
);
130 stat
= DeleteTimerQueueTimer(NULL
, Info
->hTimer
, NULL
);
132 _tprintf(_T("returned OK -> test FAILED!\n"));
135 int error
= GetLastError();
139 case ERROR_IO_PENDING
:
140 _tprintf(_T("OK, Overlapped I/O operation in progress\n"));
141 /* this test is only successful in this case */
142 Info
->Test
->Result
= TRUE
;
145 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
150 /* set the event to continue tests */
151 SetEvent(Info
->hEvent
);
155 VOID
Test1(PTEST Test
, HANDLE hEvent
)
157 static TESTINFO Info
;
160 Info
.hEvent
= hEvent
;
161 Info
.secsleft
= N_TIMEOUT
;
163 if(!CreateTimerQueueTimer(&Info
.hTimer
, NULL
, TimerCallback1
, &Info
, 1000, 1000, 0))
165 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info
.Test
->id
, (int)GetLastError());
166 /* we failed, set the event to continue tests */
171 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Info
.Test
->id
, (int)Info
.hTimer
, (int)Info
.secsleft
);
174 /*******************************************************************************/
176 VOID CALLBACK
TimerCallback2(PVOID Param
, BOOLEAN Fired
)
178 PTESTINFO Info
= (PTESTINFO
)Param
;
180 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info
->Test
->id
, (int)Info
->hTimer
, (int)Fired
, --Info
->secsleft
);
182 if(Info
->secsleft
== 0)
184 /* set the event to continue tests */
185 SetEvent(Info
->Test2
.hWaitEvent
);
192 VOID
Test2(PTEST Test
, HANDLE hEvent
)
194 static TESTINFO Info
;
198 Info
.hEvent
= hEvent
;
199 Info
.secsleft
= N_TIMEOUT
;
201 Info
.Test2
.hWaitEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
202 if(Info
.Test2
.hWaitEvent
== NULL
)
204 _tprintf(_T("[%d]Unable to create event!\n"), (int)Info
.Test
->id
);
208 if(!CreateTimerQueueTimer(&Info
.hTimer
, NULL
, TimerCallback2
, &Info
, 1000, 1000, 0))
210 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info
.Test
->id
, (int)GetLastError());
212 CloseHandle(Info
.Test2
.hWaitEvent
);
213 /* we failed, set the event to continue tests */
218 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test
->id
, (int)Info
.hTimer
, (int)Info
.secsleft
);
220 WaitForSingleObject(Info
.Test2
.hWaitEvent
, INFINITE
);
222 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test
->id
);
223 stat
= DeleteTimerQueueTimer(NULL
, Info
.hTimer
, INVALID_HANDLE_VALUE
);
226 _tprintf(_T("OK\n"));
227 /* this test is only successful in this case */
232 int error
= GetLastError();
236 case ERROR_IO_PENDING
:
237 _tprintf(_T("FAILED, Overlapped I/O operation in progress\n"));
240 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
245 SetEvent(Info
.hEvent
);
248 /*******************************************************************************/
250 VOID CALLBACK
TimerCallback3(PVOID Param
, BOOLEAN Fired
)
252 PTESTINFO Info
= (PTESTINFO
)Param
;
254 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info
->Test
->id
, (int)Info
->hTimer
, (int)Fired
, --Info
->secsleft
);
256 if(Info
->secsleft
== 0)
258 /* set the event to continue tests */
259 SetEvent(Info
->Test3
.hWaitEvent
);
266 VOID
Test3(PTEST Test
, HANDLE hEvent
)
268 static TESTINFO Info
;
272 Info
.hEvent
= hEvent
;
273 Info
.secsleft
= N_TIMEOUT
;
275 Info
.Test3
.hWaitEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
276 if(Info
.Test3
.hWaitEvent
== NULL
)
278 _tprintf(_T("[%d]Unable to create event!\n"), (int)Info
.Test
->id
);
282 Info
.Test3
.hNotification
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
283 if(Info
.Test3
.hNotification
== NULL
)
285 _tprintf(_T("[%d]Unable to create notification event!\n"), (int)Info
.Test
->id
);
289 if(!CreateTimerQueueTimer(&Info
.hTimer
, NULL
, TimerCallback3
, &Info
, 1000, 1000, 0))
291 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info
.Test
->id
, (int)GetLastError());
293 CloseHandle(Info
.Test3
.hWaitEvent
);
294 CloseHandle(Info
.Test3
.hNotification
);
295 /* we failed, set the event to continue tests */
300 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test
->id
, (int)Info
.hTimer
, (int)Info
.secsleft
);
302 WaitForSingleObject(Info
.Test3
.hWaitEvent
, INFINITE
);
304 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test
->id
);
305 stat
= DeleteTimerQueueTimer(NULL
, Info
.hTimer
, Info
.Test3
.hNotification
);
308 _tprintf(_T("returned OK -> test FAILED!\n"));
312 int error
= GetLastError();
316 case ERROR_IO_PENDING
:
317 _tprintf(_T("OK, Overlapped I/O operation in progress\n"));
318 /* this test is only successful in this case */
322 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
327 WaitForSingleObject(Info
.Test3
.hNotification
, INFINITE
);
329 CloseHandle(Info
.Test3
.hWaitEvent
);
330 CloseHandle(Info
.Test3
.hNotification
);
332 SetEvent(Info
.hEvent
);
335 /*******************************************************************************/
340 ZeroMemory(Tests
, sizeof(Tests
));
342 Tests
[0].description
= _T("non-blocking DeleteTimerQueueTimer() call from callback");
343 Tests
[0].Routine
= Test1
;
345 Tests
[1].description
= _T("blocking DeleteTimerQueueTimer() call");
346 Tests
[1].Routine
= Test2
;
348 Tests
[2].description
= _T("blocking DeleteTimerQueueTimer() call with specified event");
349 Tests
[2].Routine
= Test3
;
352 int main(int argc
, char* argv
[])
354 _tprintf(_T("+++ TimerQueue test running +++\n\n"));
360 _tprintf(_T("\n+++ RESULTS +++\n"));