ReactOS 0.4.16-dev-2207-geb15453
timer.c
Go to the documentation of this file.
1/*
2 * Unit test suite for timer functions
3 *
4 * Copyright 2004 Mike McCormack
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "wine/test.h"
22#include "winbase.h"
23#include "winternl.h"
24#include "winuser.h"
25
26
27static void test_timer(void)
28{
30 BOOL r;
31 LARGE_INTEGER due;
32
33 /* try once with a positive number */
35 ok( handle != NULL, "failed to create waitable timer with no name\n" );
36
37 due.QuadPart = 10000;
38 r = SetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE );
39 ok( r, "failed to set timer\n");
40
42
43 /* try once with a negative number */
45 ok( handle != NULL, "failed to create waitable timer with no name\n" );
46
47 due.QuadPart = -10000;
48 r = SetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE );
49 ok( r, "failed to set timer\n");
50
52}
53
54#define TICKSPERSEC 10000000
55
56static BOOL adjust_system_time(int sec)
57{
59 SYSTEMTIME st;
60 FILETIME ft;
61
63 uli.u.LowPart = ft.dwLowDateTime;
64 uli.u.HighPart = ft.dwHighDateTime;
65 uli.QuadPart += (LONGLONG)sec * TICKSPERSEC;
66 ft.dwLowDateTime = uli.u.LowPart;
67 ft.dwHighDateTime = uli.u.HighPart;
68 if (!FileTimeToSystemTime(&ft, &st))
69 return FALSE;
70 return SetSystemTime(&st);
71}
72
74{
76 DWORD t, r;
77
78 event = CreateEventW(NULL, FALSE, FALSE, NULL);
79 ok(event != NULL, "CreateEvent failed\n");
80 t = GetTickCount();
82 ok(r == WAIT_TIMEOUT, "WiatForSingleObject returned %lx\n", r);
84 t = GetTickCount() - t;
85 ok(t > 2000, "t = %ld\n", t);
86 return 0;
87}
88
90{
92
93 Sleep(3000);
94 t = GetTickCount() - t;
95 ok(t > 2000, "t = %ld\n", t);
96 return 0;
97}
98
100{
101 DWORD t = GetTickCount();
102
103 SleepEx(3000, TRUE);
104 t = GetTickCount() - t;
105 ok(t > 2000, "t = %ld\n", t);
106 return 0;
107}
108
110{
112 HANDLE timer;
113 DWORD t, r;
114
115 li.QuadPart = -3 * TICKSPERSEC;
116
118 ok(timer != NULL, "CreateWaitableTimer failed\n");
119
120 t = GetTickCount();
121 r = SetWaitableTimer(timer, &li, 0, NULL, NULL, FALSE);
122 ok(r, "SetWaitableTimer failed\n");
123
125 ok(r == WAIT_OBJECT_0, "WaitForSingleObject returned %ld\n", r);
126 CloseHandle(timer);
127 t = GetTickCount() - t;
128 ok(t > 2000, "t = %ld\n", t);
129 return 0;
130}
131
133{
135 HANDLE timer;
136 FILETIME ft;
137 DWORD t, r;
138
140 li.u.LowPart = ft.dwLowDateTime;
141 li.u.HighPart = ft.dwHighDateTime;
142 li.QuadPart += 3 * TICKSPERSEC;
143
145 ok(timer != NULL, "CreateWaitableTimer failed\n");
146
147 t = GetTickCount();
148 r = SetWaitableTimer(timer, &li, 0, NULL, NULL, FALSE);
149 ok(r, "SetWaitableTimer failed\n");
150
152 ok(r == WAIT_OBJECT_0, "WaitForSingleObject returned %ld\n", r);
153 CloseHandle(timer);
154 t = GetTickCount() - t;
155 ok(t < 2000, "t = %ld\n", t);
156 return 0;
157}
158
160{
162 HANDLE timer;
163 DWORD t, r;
164
165 li.QuadPart = -1;
166
168 ok(timer != NULL, "CreateWaitableTimer failed\n");
169
170 t = GetTickCount();
171 r = SetWaitableTimer(timer, &li, 3000, NULL, NULL, FALSE);
172 ok(r, "SetWaitableTimer failed\n");
173
175 ok(r == WAIT_OBJECT_0, "WaitForSingleObject returned %ld\n", r);
176
178 ok(r == WAIT_OBJECT_0, "WaitForSingleObject returned %ld\n", r);
179 CloseHandle(timer);
180 t = GetTickCount() - t;
181 ok(t > 2000, "t = %ld\n", t);
182 return 0;
183}
184
186{
187 DWORD t = GetTickCount();
188 UINT_PTR timer;
189 MSG msg;
190
191 timer = SetTimer(NULL, 0, 3000, NULL);
192 ok(timer, "SetTimer failed (%ld)\n", GetLastError());
193
194 while (GetMessageW(&msg, NULL, 0, 0))
195 {
197 if (msg.message == WM_TIMER) break;
198 }
199
200 t = GetTickCount() - t;
201 ok(t > 2000, "t = %ld\n", t);
202 KillTimer(NULL, timer);
203 return 0;
204}
205
206static void test_timeouts(void)
207{
208 HANDLE threads[7];
209 DWORD i;
210
211 if (!adjust_system_time(1))
212 {
213 skip("can't adjust system clock (%ld)\n", GetLastError());
214 return;
215 }
216
217
225 for(i=0; i<ARRAY_SIZE(threads); i++)
226 ok(threads[i] != NULL, "CreateThread failed\n");
227
228 Sleep(500);
230
231 for (i=0; i<ARRAY_SIZE(threads); i++)
232 {
235 }
237}
238
240{
241 test_timer();
243}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
#define ARRAY_SIZE(A)
Definition: main.h:20
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI SetSystemTime(IN CONST SYSTEMTIME *lpSystemTime)
Definition: time.c:412
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
struct _cl_event * event
Definition: glext.h:7739
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 HANDLE ULONG_PTR DWORD threads
Definition: process.c:83
#define TICKSPERSEC
Definition: timer.c:54
static DWORD WINAPI thread_SleepEx(void *arg)
Definition: timer.c:99
static DWORD WINAPI thread_WaitableTimer_period(void *arg)
Definition: timer.c:159
static BOOL adjust_system_time(int sec)
Definition: timer.c:56
static DWORD WINAPI thread_WaitableTimer_rel(void *arg)
Definition: timer.c:109
static DWORD WINAPI thread_Sleep(void *arg)
Definition: timer.c:89
static DWORD WINAPI thread_SetTimer(void *arg)
Definition: timer.c:185
static DWORD WINAPI thread_WaitableTimer_abs(void *arg)
Definition: timer.c:132
static DWORD WINAPI thread_WaitForSingleObject(void *arg)
Definition: timer.c:73
static void test_timer(void)
Definition: timer.c:27
static void test_timeouts(void)
Definition: timer.c:206
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
struct _ULARGE_INTEGER::@4457 u
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:802
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
HANDLE WINAPI CreateWaitableTimerA(IN LPSECURITY_ATTRIBUTES lpTimerAttributes OPTIONAL, IN BOOL bManualReset, IN LPCSTR lpTimerName OPTIONAL)
Definition: synch.c:346
BOOL WINAPI SetWaitableTimer(IN HANDLE hTimer, IN const LARGE_INTEGER *pDueTime, IN LONG lPeriod, IN PTIMERAPCROUTINE pfnCompletionRoutine OPTIONAL, IN OPTIONAL LPVOID lpArgToCompletionRoutine, IN BOOL fResume)
Definition: synch.c:382
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int64_t LONGLONG
Definition: typedefs.h:68
LONGLONG QuadPart
Definition: typedefs.h:114
struct _LARGE_INTEGER::@2502 u
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:383
#define WINAPI
Definition: msvc.h:6
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_TIMER
Definition: winuser.h:1770
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)