ReactOS 0.4.15-dev-5672-gf73ac17
SendMessageTimeout.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for SendMessageTimeout
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "precomp.h"
9
16
17static
18void
22{
25
27 ok(ret == 0, "ret = %Id\n", ret);
28
29 result = 0x55555555;
31 ok(ret == 0, "ret = %Id\n", ret);
32 ok(result == 0, "result = %Iu\n", result);
33
35 ok(ret == 0, "ret = %Id\n", ret);
36
37 result = 0x55555555;
39 ok(ret == 0, "ret = %Id\n", ret);
40 ok(result == 0, "result = %Iu\n", result);
41}
42
43#define WM_SENDTOOTHERTHREAD (WM_USER + 14)
44
45#define KILL_THREAD1_FLAG 0x40000000
46#define KILL_THREAD2_FLAG 0x20000000
47#define KILL_THREAD_FLAGS (KILL_THREAD1_FLAG | KILL_THREAD2_FLAG)
48
49static
57{
60
61 if (hWnd == hWndThread1)
62 {
64 }
65 else if (hWnd == hWndThread2)
66 {
68 }
69 else
70 {
72 }
73
74 switch (message)
75 {
78 {
79 if ((wParam & KILL_THREAD2_FLAG) &&
80 (wParam & ~KILL_THREAD_FLAGS) > 10)
81 {
83 }
84 if ((wParam & KILL_THREAD1_FLAG) &&
85 (wParam & ~KILL_THREAD_FLAGS) > 10)
86 {
88 }
89 ok(lParam == dwThread2, "lParam = %Iu, expected %lu\n", lParam, dwThread2);
91 }
92 else
93 {
94 ok(lParam == dwThread1, "lParam = %Iu, expected %lu\n", lParam, dwThread1);
96 }
97 }
98
100}
101
102static
103DWORD
104WINAPI
107{
108 MSG msg;
109
110 hWndThread1 = CreateWindowExW(0, L"SendTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL);
111 ok(hWndThread1 != NULL, "CreateWindow failed\n");
112
113 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
114 {
115 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
116 RECORD_MESSAGE(1, msg.message, POST, 0, 0);
118 }
119
121
123 {
124 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
125 {
126 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
127 RECORD_MESSAGE(1, msg.message, POST, 0, 0);
129 }
130 }
131
133 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
134 {
135 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
136 RECORD_MESSAGE(1, msg.message, POST, 0, 0);
138 }
139
140 return 6;
141}
142
143static
144DWORD
145WINAPI
148{
149 MSG msg;
150 LRESULT ret;
152
153 hWndThread2 = CreateWindowExW(0, L"SendTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL);
154 ok(hWndThread2 != NULL, "CreateWindow failed\n");
155
156 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
157 {
158 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
159 RECORD_MESSAGE(2, msg.message, POST, 0, 0);
161 }
162
165 ok(ret == 0, "ret = %lu\n", ret);
166
167 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
168 {
169 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
170 RECORD_MESSAGE(2, msg.message, POST, 0, 0);
172 }
173
175 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
176 {
177 if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
178 RECORD_MESSAGE(2, msg.message, POST, 0, 0);
180 }
181
182 return 7;
183}
184
185static
186void
188 _In_ BOOL KillThread1,
189 _In_ BOOL KillThread2)
190{
192 HANDLE Handles[2];
193 BOOL Ret;
194 DWORD ExitCode;
195
196 Parameter = UlongToPtr((KillThread1 ? KILL_THREAD1_FLAG : 0) |
197 (KillThread2 ? KILL_THREAD2_FLAG : 0));
200
202
203 Handles[0] = hThread1;
204 Handles[1] = hThread2;
206
207 Ret = GetExitCodeThread(hThread1, &ExitCode);
208 ok(Ret == TRUE, "GetExitCodeThread failed with %lu\n", GetLastError());
209 if (KillThread1)
210 ok(ExitCode == 456, "Thread1 exit code is %lu\n", ExitCode);
211 else
212 ok(ExitCode == 6, "Thread1 exit code is %lu\n", ExitCode);
213
214 Ret = GetExitCodeThread(hThread2, &ExitCode);
215 ok(Ret == TRUE, "GetExitCodeThread failed with %lu\n", GetLastError());
216 if (KillThread2)
217 ok(ExitCode == 123, "Thread2 exit code is %lu\n", ExitCode);
218 else
219 ok(ExitCode == 7, "Thread2 exit code is %lu\n", ExitCode);
220
223
224 //TRACE_CACHE();
225}
226
228{
231 TestSendMessageTimeout(NULL, WM_GETICON);
232
233 RegisterSimpleClass(WndProc, L"SendTest");
234
239}
static HANDLE hThread2
static HWND hWndThread1
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
static DWORD WINAPI Thread2(_Inout_opt_ PVOID Parameter)
static void TestSendMessageTimeout(_In_ HWND hWnd, _In_ UINT Msg)
static DWORD dwThread2
#define KILL_THREAD2_FLAG
static void TestRecursiveInterThreadMessages(_In_ BOOL KillThread1, _In_ BOOL KillThread2)
static HWND hWndThread2
static DWORD WINAPI Thread1(_Inout_opt_ PVOID Parameter)
static DWORD dwThread1
#define KILL_THREAD1_FLAG
#define WM_SENDTOOTHERTHREAD
#define KILL_THREAD_FLAGS
static HANDLE hThread1
#define ok(value,...)
Definition: atltest.h:57
#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
struct @1609 Msg[]
LPARAM lParam
Definition: combotst.c:139
#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 CALLBACK
Definition: compat.h:35
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:567
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
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:587
BOOL WINAPI GetExitCodeThread(IN HANDLE hThread, OUT LPDWORD lpExitCode)
Definition: thread.c:541
#define INFINITE
Definition: serial.h:102
#define UlongToPtr(u)
Definition: config.h:106
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint64EXT * result
Definition: glext.h:11304
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define _Inout_opt_
Definition: ms_sal.h:379
#define _In_
Definition: ms_sal.h:308
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
@ POST
Definition: msgtrace.h:7
@ SENT
Definition: msgtrace.h:6
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
Definition: tftpd.h:60
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint32_t DWORD_PTR
Definition: typedefs.h:65
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define CREATE_SUSPENDED
Definition: winbase.h:178
#define WAIT_OBJECT_0
Definition: winbase.h:406
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define WM_PAINT
Definition: winuser.h:1610
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define SendMessageTimeout
Definition: winuser.h:5835
#define MWMO_ALERTABLE
Definition: winuser.h:903
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define QS_ALLEVENTS
Definition: winuser.h:896
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
DWORD WINAPI MsgWaitForMultipleObjectsEx(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask, _In_ DWORD dwFlags)
LRESULT WINAPI SendMessageTimeoutA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
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 PM_REMOVE
Definition: winuser.h:1186
#define SendMessage
Definition: winuser.h:5833
#define PeekMessage
Definition: winuser.h:5820
#define WM_USER
Definition: winuser.h:1885
BOOL WINAPI DestroyWindow(_In_ HWND)
#define SMTO_NORMAL
Definition: winuser.h:1215