ReactOS 0.4.16-dev-2224-g3637fd8
timer.c File Reference
#include "wine/test.h"
#include "winbase.h"
#include "winternl.h"
#include "winuser.h"
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define TICKSPERSEC   10000000
 

Functions

static void test_timer (void)
 
static BOOL adjust_system_time (int sec)
 
static DWORD WINAPI thread_WaitForSingleObject (void *arg)
 
static DWORD WINAPI thread_Sleep (void *arg)
 
static DWORD WINAPI thread_SleepEx (void *arg)
 
static DWORD WINAPI thread_WaitableTimer_rel (void *arg)
 
static DWORD WINAPI thread_WaitableTimer_abs (void *arg)
 
static DWORD WINAPI thread_WaitableTimer_period (void *arg)
 
static DWORD WINAPI thread_SetTimer (void *arg)
 
static void test_timeouts (void)
 
 START_TEST (timer)
 

Macro Definition Documentation

◆ TICKSPERSEC

#define TICKSPERSEC   10000000

Definition at line 54 of file timer.c.

Function Documentation

◆ adjust_system_time()

static BOOL adjust_system_time ( int  sec)
static

Definition at line 56 of file timer.c.

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}
#define FALSE
Definition: types.h:117
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
#define TICKSPERSEC
Definition: timer.c:54
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
struct _ULARGE_INTEGER::@4457 u
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by test_timeouts().

◆ START_TEST()

START_TEST ( timer  )

Definition at line 239 of file timer.c.

240{
241 test_timer();
243}
static void test_timer(void)
Definition: timer.c:27
static void test_timeouts(void)
Definition: timer.c:206

◆ test_timeouts()

static void test_timeouts ( void  )
static

Definition at line 206 of file timer.c.

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}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
#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
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
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
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
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
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ test_timer()

static void test_timer ( void  )
static

Definition at line 27 of file timer.c.

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}
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
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
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by START_TEST().

◆ thread_SetTimer()

static DWORD WINAPI thread_SetTimer ( void arg)
static

Definition at line 185 of file timer.c.

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}
#define msg(x)
Definition: auth_time.c:54
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
GLdouble GLdouble t
Definition: gl.h:2047
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
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)

Referenced by test_timeouts().

◆ thread_Sleep()

static DWORD WINAPI thread_Sleep ( void arg)
static

Definition at line 89 of file timer.c.

90{
92
93 Sleep(3000);
94 t = GetTickCount() - t;
95 ok(t > 2000, "t = %ld\n", t);
96 return 0;
97}

Referenced by test_timeouts().

◆ thread_SleepEx()

static DWORD WINAPI thread_SleepEx ( void arg)
static

Definition at line 99 of file timer.c.

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}
#define TRUE
Definition: types.h:120
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:802

Referenced by test_timeouts().

◆ thread_WaitableTimer_abs()

static DWORD WINAPI thread_WaitableTimer_abs ( void arg)
static

Definition at line 132 of file timer.c.

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}
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
struct _LARGE_INTEGER::@2502 u
#define WAIT_OBJECT_0
Definition: winbase.h:383

Referenced by test_timeouts().

◆ thread_WaitableTimer_period()

static DWORD WINAPI thread_WaitableTimer_period ( void arg)
static

Definition at line 159 of file timer.c.

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}

Referenced by test_timeouts().

◆ thread_WaitableTimer_rel()

static DWORD WINAPI thread_WaitableTimer_rel ( void arg)
static

Definition at line 109 of file timer.c.

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}

Referenced by test_timeouts().

◆ thread_WaitForSingleObject()

static DWORD WINAPI thread_WaitForSingleObject ( void arg)
static

Definition at line 73 of file timer.c.

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}
#define WAIT_TIMEOUT
Definition: dderror.h:14
struct _cl_event * event
Definition: glext.h:7739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651

Referenced by test_timeouts().