ReactOS 0.4.15-dev-7931-gfd331f1
tmrqueue.c
Go to the documentation of this file.
1#include <windows.h>
2#include <stdio.h>
3#include <tchar.h>
4
5#define N_TIMEOUT 3
6
7/*******************************************************************************/
8
9typedef struct _TEST *PTEST;
10
12
13typedef struct _TEST
14{
18 int id;
20
21static TEST Tests[3];
22
24{
25 int i, nTests;
26 static HANDLE hEvent;
27
29 if(hEvent == NULL)
30 {
31 _tprintf(_T("Unable to create event!"));
32 return;
33 }
34
35 nTests = sizeof(Tests) / sizeof(TEST);
36
37 for(i = 0; i < nTests; i++)
38 {
39 Tests[i].id = i + 1;
40
41 if(Tests[i].Routine == NULL)
42 {
43 continue;
44 }
45
46 _tprintf(_T("+++ TEST %d: %s\n"), Tests[i].id, Tests[i].description);
47
48 Tests[i].Routine(&Tests[i], hEvent);
49
51
52 _tprintf(_T("\n\n"));
53 }
54
56}
57
59{
60 int i, nTests, nsuccess = 0, nfailed = 0;
62
63 nTests = sizeof(Tests) / sizeof(TEST);
64
65 for(i = 0; i < nTests; i++)
66 {
67 if(Tests[i].Routine == NULL)
68 {
69 status = _T("SKIPPED");
70 }
71 else if(Tests[i].Result == TRUE)
72 {
73 status = _T("SUCCESS");
74 nsuccess++;
75 }
76 else
77 {
78 status = _T("FAILED ");
79 nfailed++;
80 }
81
82 _tprintf(_T("Test %d: %s %s\n"), i, status, Tests[i].description);
83 }
84
85 _tprintf(_T("\nTests succeeded: %d, failed: %d\n"), nsuccess, nfailed);
86 if(nfailed == 0)
87 {
88 _tprintf(_T(" ALL TESTS SUCCESSFUL!\n"));
89 }
90}
91
92/*******************************************************************************/
93
94typedef struct _TESTINFO
95{
100 /* additional stuff */
101 union
102 {
103 struct
104 {
107 struct
108 {
111 struct
112 {
116 };
118
120{
121 PTESTINFO Info = (PTESTINFO)Param;
122
123 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
124
125 if(Info->secsleft == 0)
126 {
127 BOOL stat;
128
129 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Info->Test->id);
131 if(stat)
132 _tprintf(_T("returned OK -> test FAILED!\n"));
133 else
134 {
135 int error = GetLastError();
136
137 switch(error)
138 {
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;
143 break;
144 default:
145 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
146 break;
147 }
148 }
149
150 /* set the event to continue tests */
151 SetEvent(Info->hEvent);
152 }
153}
154
156{
157 static TESTINFO Info;
158
159 Info.Test = Test;
160 Info.hEvent = hEvent;
161 Info.secsleft = N_TIMEOUT;
162
163 if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback1, &Info, 1000, 1000, 0))
164 {
165 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
166 /* we failed, set the event to continue tests */
168 return;
169 }
170
171 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Info.Test->id, (int)Info.hTimer, (int)Info.secsleft);
172}
173
174/*******************************************************************************/
175
177{
178 PTESTINFO Info = (PTESTINFO)Param;
179
180 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
181
182 if(Info->secsleft == 0)
183 {
184 /* set the event to continue tests */
185 SetEvent(Info->Test2.hWaitEvent);
186
187 /* sleep a bit */
188 Sleep(1500);
189 }
190}
191
193{
194 static TESTINFO Info;
195 BOOL stat;
196
197 Info.Test = Test;
198 Info.hEvent = hEvent;
199 Info.secsleft = N_TIMEOUT;
200
201 Info.Test2.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
202 if(Info.Test2.hWaitEvent == NULL)
203 {
204 _tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id);
205 return;
206 }
207
208 if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback2, &Info, 1000, 1000, 0))
209 {
210 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
211
212 CloseHandle(Info.Test2.hWaitEvent);
213 /* we failed, set the event to continue tests */
215 return;
216 }
217
218 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft);
219
220 WaitForSingleObject(Info.Test2.hWaitEvent, INFINITE);
221
222 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id);
224 if(stat)
225 {
226 _tprintf(_T("OK\n"));
227 /* this test is only successful in this case */
228 Test->Result = TRUE;
229 }
230 else
231 {
232 int error = GetLastError();
233
234 switch(error)
235 {
236 case ERROR_IO_PENDING:
237 _tprintf(_T("FAILED, Overlapped I/O operation in progress\n"));
238 break;
239 default:
240 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
241 break;
242 }
243 }
244
245 SetEvent(Info.hEvent);
246}
247
248/*******************************************************************************/
249
251{
252 PTESTINFO Info = (PTESTINFO)Param;
253
254 _tprintf(_T("[%d]TimerCallback(0x%x, %d) called (%d)\n"), (int)Info->Test->id, (int)Info->hTimer, (int)Fired, --Info->secsleft);
255
256 if(Info->secsleft == 0)
257 {
258 /* set the event to continue tests */
259 SetEvent(Info->Test3.hWaitEvent);
260
261 /* sleep a bit */
262 Sleep(1500);
263 }
264}
265
267{
268 static TESTINFO Info;
269 BOOL stat;
270
271 Info.Test = Test;
272 Info.hEvent = hEvent;
273 Info.secsleft = N_TIMEOUT;
274
275 Info.Test3.hWaitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
276 if(Info.Test3.hWaitEvent == NULL)
277 {
278 _tprintf(_T("[%d]Unable to create event!\n"), (int)Info.Test->id);
279 return;
280 }
281
282 Info.Test3.hNotification = CreateEvent(NULL, FALSE, FALSE, NULL);
283 if(Info.Test3.hNotification == NULL)
284 {
285 _tprintf(_T("[%d]Unable to create notification event!\n"), (int)Info.Test->id);
286 return;
287 }
288
289 if(!CreateTimerQueueTimer(&Info.hTimer, NULL, TimerCallback3, &Info, 1000, 1000, 0))
290 {
291 _tprintf(_T("[%d]CreateTimerQueueTimer() failed, LastError: %d!"), (int)Info.Test->id, (int)GetLastError());
292
293 CloseHandle(Info.Test3.hWaitEvent);
294 CloseHandle(Info.Test3.hNotification);
295 /* we failed, set the event to continue tests */
297 return;
298 }
299
300 _tprintf(_T("[%d]CreateTimerQueueTimer() created timer 0x%x, countdown (%d sec)...\n"), (int)Test->id, (int)Info.hTimer, (int)Info.secsleft);
301
302 WaitForSingleObject(Info.Test3.hWaitEvent, INFINITE);
303
304 _tprintf(_T("[%d]Timout finished, delete timer queue..."), (int)Test->id);
305 stat = DeleteTimerQueueTimer(NULL, Info.hTimer, Info.Test3.hNotification);
306 if(stat)
307 {
308 _tprintf(_T("returned OK -> test FAILED!\n"));
309 }
310 else
311 {
312 int error = GetLastError();
313
314 switch(error)
315 {
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 */
319 Test->Result = TRUE;
320 break;
321 default:
322 _tprintf(_T("Failed, LastError: %d\n"), (int)GetLastError());
323 break;
324 }
325 }
326
327 WaitForSingleObject(Info.Test3.hNotification, INFINITE);
328
329 CloseHandle(Info.Test3.hWaitEvent);
330 CloseHandle(Info.Test3.hNotification);
331
332 SetEvent(Info.hEvent);
333}
334
335/*******************************************************************************/
336
337VOID
339{
340 ZeroMemory(Tests, sizeof(Tests));
341
342 Tests[0].description = _T("non-blocking DeleteTimerQueueTimer() call from callback");
343 Tests[0].Routine = Test1;
344
345 Tests[1].description = _T("blocking DeleteTimerQueueTimer() call");
346 Tests[1].Routine = Test2;
347
348 Tests[2].description = _T("blocking DeleteTimerQueueTimer() call with specified event");
349 Tests[2].Routine = Test3;
350}
351
352int main(int argc, char* argv[])
353{
354 _tprintf(_T("+++ TimerQueue test running +++\n\n"));
355
356 InitTests();
357
358 RunTests();
359
360 _tprintf(_T("\n+++ RESULTS +++\n"));
361
363
364 return 0;
365}
unsigned char BOOLEAN
static int argc
Definition: ServiceArgs.c:12
#define VOID
Definition: acefi.h:82
#define stat
Definition: acwin.h:99
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI CreateTimerQueueTimer(OUT PHANDLE phNewTimer, IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN ULONG Flags)
Definition: timerqueue.c:138
BOOL WINAPI DeleteTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
Definition: timerqueue.c:240
int main()
Definition: test.c:6
#define INFINITE
Definition: serial.h:102
void RunTests()
Definition: ehframes.cpp:427
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void Test1(void)
Definition: himc.c:10
#define _tprintf
Definition: tchar.h:506
#define error(str)
Definition: mkdosfs.c:1605
void Test2(void)
Definition: terminate.cpp:76
static HANDLE hEvent
Definition: comm.c:54
#define argv
Definition: mplay32.c:18
Definition: comm.c:65
struct _TESTINFO::@1635::@1637 Test1
HANDLE hNotification
Definition: tmrqueue.c:114
PTEST Test
Definition: tmrqueue.c:96
struct _TESTINFO::@1635::@1639 Test3
struct _TESTINFO::@1635::@1638 Test2
HANDLE hWaitEvent
Definition: tmrqueue.c:109
HANDLE hTimer
Definition: tmrqueue.c:98
HANDLE hEvent
Definition: tmrqueue.c:99
int secsleft
Definition: tmrqueue.c:97
HANDLE Dummy
Definition: tmrqueue.c:105
Definition: tmrqueue.c:14
BOOL Result
Definition: tmrqueue.c:16
PFNTEST Routine
Definition: tmrqueue.c:17
TCHAR * description
Definition: tmrqueue.c:15
int id
Definition: tmrqueue.c:18
Definition: stat.h:55
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
VOID InitTests(VOID)
Definition: tmrqueue.c:338
VOID(* PFNTEST)(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:11
VOID PrintTestResults(VOID)
Definition: tmrqueue.c:58
static TEST Tests[3]
Definition: tmrqueue.c:21
VOID Test3(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:266
struct _TEST * PTEST
Definition: tmrqueue.c:9
struct _TESTINFO TESTINFO
struct _TESTINFO * PTESTINFO
VOID CALLBACK TimerCallback3(PVOID Param, BOOLEAN Fired)
Definition: tmrqueue.c:250
VOID CALLBACK TimerCallback1(PVOID Param, BOOLEAN Fired)
Definition: tmrqueue.c:119
struct _TEST TEST
VOID CALLBACK TimerCallback2(PVOID Param, BOOLEAN Fired)
Definition: tmrqueue.c:176
#define N_TIMEOUT
Definition: tmrqueue.c:5
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3748
const char * description
Definition: directx.c:2497
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
char TCHAR
Definition: xmlstorage.h:189