ReactOS 0.4.16-dev-340-g0540c21
NtUserSetTimer.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for NtUserSetTimer
5 * COPYRIGHT: Copyright 2008 Timo Kreuzer <timo.kreuzer@reactos.org>
6 * Copyright 2024 Tomáš Veselý <turican0@gmail.com>
7 */
8
9#include "../win32nt.h"
10
11#define SLEEP_TIME 500
12#define MIN_MESSAGES_TIME 1
13#define MAX_MESSAGES_TIME 1000
14
15#define TEST1_COUNT 20
16#define TEST1_INTERVAL 10
17
18#define TEST2_COUNT 40000
19#define TEST2_INTERVAL 10
20
21#define TESTW1_COUNT 20
22#define TESTW1_INTERVAL 10
23
24#define TESTW2_COUNT 40000
25#define TESTW2_INTERVAL 10
26
28{
32
34
36{
39
41
42/* TIMERPROC for the test1,2,3() with messages without window */
43static void CALLBACK
45{
46 UINT i;
47 for (i = 0; i < TEST1_COUNT; i++)
48 {
49 if (timerId1[i].index == idEvent)
51 }
52}
53
54/* TIMERPROC for the testW1,2() with messages with window */
55static LRESULT CALLBACK
57{
58 switch (uMsg)
59 {
60 case WM_TIMER:
62 return 0;
63 }
64
65 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
66}
67
68// TEST WITH MESSAGES WITHOUT WINDOW - test count of sent messages
69static BOOL test1(void)
70{
71 UINT i, countErrors = 0;
73 MSG msg = { NULL };
74
76
77 for (i = 0; i < TEST1_COUNT; i++)
78 {
80 if (timerId1[i].index == 0)
81 countErrors++;
82 }
83
85
86 while (GetMessageW(&msg, NULL, 0, 0))
87 {
90
93 }
94
95 for (i = 0; i < TEST1_COUNT; i++)
96 {
98 countErrors++;
99 }
100
101 for (i = 0; i < TEST1_COUNT; i++)
102 {
103 if (KillTimer(NULL, timerId1[i].index) == 0)
104 countErrors++;
105 }
106
107 return (countErrors == 0);
108}
109
110// TEST WITH MESSAGES WITHOUT WINDOW - create many timers
111static BOOL test2(void)
112{
113 UINT i, countErrors = 0;
114 UINT_PTR locIndex;
115
116 for (i = 0; i < TEST2_COUNT; i++)
117 {
118 locIndex = SetTimer(NULL, 0, TEST2_INTERVAL, TimerProc);
119
120 if (locIndex == 0)
121 countErrors++;
122 if (KillTimer(NULL, locIndex) == 0)
123 countErrors++;
124 }
125
126 return (countErrors == 0);
127}
128
129// TEST WITH MESSAGES WITHOUT WINDOW - test different ids
130static BOOL test3(void)
131{
132 UINT countErrors = 0;
133 UINT_PTR locIndex1;
134 UINT_PTR locIndex2;
135
136 locIndex1 = SetTimer(NULL, 0, TEST1_INTERVAL, TimerProc);
137 if (locIndex1 == 0)
138 countErrors++;
139 if (KillTimer(NULL, locIndex1) == 0)
140 countErrors++;
141 locIndex2 = SetTimer(NULL, 0, TEST1_INTERVAL, TimerProc);
142 if (locIndex2 == 0)
143 countErrors++;
144 if (KillTimer(NULL, locIndex2) == 0)
145 countErrors++;
146 if (locIndex1 == locIndex2)
147 countErrors++;
148
149 return (countErrors == 0);
150}
151
152// TEST WITH MESSAGES WITH WINDOW - test count of sent messages
154{
155 UINT i, countErrors = 0;
156 UINT_PTR locIndex;
158 MSG msg = { NULL };
159
160 if (hwnd == NULL)
161 return FALSE;
162
164
165 for (i = 0; i < TESTW1_COUNT; i++)
166 {
167 locIndex = SetTimer(hwnd, i, TESTW1_INTERVAL, NULL);
168 if (locIndex == 0)
169 countErrors++;
170 }
171
173
174 while (GetMessageW(&msg, NULL, 0, 0))
175 {
178
181 }
182
183 for (i = 0; i < TESTW1_COUNT; i++)
184 {
186 countErrors++;
187 }
188
189 for (i = 0; i < TESTW1_COUNT; i++)
190 {
191 if (KillTimer(hwnd, i) == 0)
192 countErrors++;
193 }
194
195 return (countErrors == 0);
196}
197
198// TEST WITH MESSAGES WITH WINDOW - create many timers
200{
201 UINT i, countErrors = 0;
203
204 if (hwnd == NULL)
205 return FALSE;
206
207 for (i = 0; i < TESTW2_COUNT; i++)
208 {
210 if (result == 0)
211 countErrors++;
212 if (KillTimer(hwnd, 1) == 0)
213 countErrors++;
214 }
215
216 return (countErrors == 0);
217}
218
220{
221 WNDCLASSW wc = { 0 };
222 HWND hwnd;
223
224 // TEST WITH MESSAGES WITHOUT WINDOW - test count of sent messages
225 TEST(test1());
226
227 // TEST WITH MESSAGES WITHOUT WINDOW - create many timers
228 TEST(test2());
229
230 // TEST WITH MESSAGES WITHOUT WINDOW - test different ids
231 TEST(test3());
232
235 wc.lpszClassName = L"TimerWindowClass";
236 RegisterClassW(&wc);
237
238 hwnd = CreateWindowExW(0, L"TimerWindowClass", L"Timer Window", 0,
241
242 // TEST WITH MESSAGES WITH WINDOW - test count of sent messages
243 TEST(testW1(hwnd));
244
245 // TEST WITH MESSAGES WITH WINDOW - create many timers
246 TEST(testW2(hwnd));
247
248 if (hwnd != NULL)
250 UnregisterClassW(L"TimerWindowClass", NULL);
251}
#define TESTW2_INTERVAL
#define TESTW1_INTERVAL
#define TEST2_INTERVAL
TIMER_MESSAGE_STATEW1 timerIdW1[TESTW1_COUNT]
#define MIN_MESSAGES_TIME
#define TESTW1_COUNT
static BOOL testW1(HWND hwnd)
#define TEST1_INTERVAL
static BOOL test1(void)
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
TIMER_MESSAGE_STATE1 timerId1[TEST1_COUNT]
static void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
#define TEST2_COUNT
#define MAX_MESSAGES_TIME
static BOOL testW2(HWND hwnd)
#define TESTW2_COUNT
#define SLEEP_TIME
#define TEST1_COUNT
static BOOL test3(void)
static BOOL test2(void)
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
static ULONGLONG startTime
Definition: main.c:113
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint index
Definition: glext.h:6031
GLuint64EXT * result
Definition: glext.h:11304
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
UINT_PTR NTAPI NtUserSetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
Definition: timer.c:636
#define TEST(x)
Definition: precomp.h:20
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
DWORD dwTime
Definition: solitaire.cpp:27
LPCWSTR lpszClassName
Definition: winuser.h:3188
HINSTANCE hInstance
Definition: winuser.h:3183
WNDPROC lpfnWndProc
Definition: winuser.h:3180
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint64_t ULONGLONG
Definition: typedefs.h:67
#define ZeroMemory
Definition: winbase.h:1737
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define HWND_MESSAGE
Definition: winuser.h:1213
BOOL WINAPI TranslateMessage(_In_ const MSG *)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_TIMER
Definition: winuser.h:1745
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define CW_USEDEFAULT
Definition: winuser.h:225
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)