ReactOS  0.4.14-dev-98-gb0d4763
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 
17 static
18 void
20  _In_ HWND hWnd,
21  _In_ UINT Msg)
22 {
23  LRESULT ret;
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 
49 static
50 LRESULT
53  _In_ HWND hWnd,
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 
102 static
103 DWORD
104 WINAPI
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 
143 static
144 DWORD
145 WINAPI
148 {
149  MSG msg;
150  LRESULT ret;
151  WPARAM wParam;
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 
185 static
186 void
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;
205  WaitForMultipleObjects(2, Handles, TRUE, INFINITE);
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 HWND hWndThread1
#define KILL_THREAD_FLAGS
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
Definition: tftpd.h:59
#define PeekMessage
Definition: winuser.h:5731
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:586
static void TestRecursiveInterThreadMessages(_In_ BOOL KillThread1, _In_ BOOL KillThread2)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
UINT_PTR WPARAM
Definition: windef.h:207
static DWORD dwThread1
_In_ PVOID Parameter
Definition: ldrtypes.h:241
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
BOOL WINAPI DestroyWindow(_In_ HWND)
#define KILL_THREAD1_FLAG
static DWORD WINAPI Thread1(_Inout_opt_ PVOID Parameter)
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
START_TEST(SendMessageTimeout)
#define SMTO_NORMAL
Definition: winuser.h:1211
static void TestSendMessageTimeout(_In_ HWND hWnd, _In_ UINT Msg)
#define KILL_THREAD2_FLAG
BOOL WINAPI GetExitCodeThread(IN HANDLE hThread, OUT LPDWORD lpExitCode)
Definition: thread.c:540
DWORD WINAPI MsgWaitForMultipleObjectsEx(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask, _In_ DWORD dwFlags)
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
#define CREATE_SUSPENDED
Definition: winbase.h:178
unsigned int BOOL
Definition: ntddk_ex.h:94
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:136
smooth NULL
Definition: ftsmooth.c:416
#define QS_ALLEVENTS
Definition: winuser.h:873
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
#define UlongToPtr(u)
Definition: config.h:106
static HWND hWndThread2
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define WAIT_OBJECT_0
Definition: winbase.h:387
LRESULT WINAPI SendMessageTimeoutA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
#define SendMessageTimeout
Definition: winuser.h:5746
#define MWMO_ALERTABLE
Definition: winuser.h:899
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE hThread2
#define WM_PAINT
Definition: winuser.h:1602
int ret
Definition: msgtrace.h:7
static const WCHAR L[]
Definition: oid.c:1250
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)
struct @1580 Msg[]
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define WM_USER
Definition: winuser.h:1877
#define _In_
Definition: no_sal2.h:204
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define WM_SENDTOOTHERTHREAD
#define ok(value,...)
Definition: atltest.h:57
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
static DWORD dwThread2
static DWORD WINAPI Thread2(_Inout_opt_ PVOID Parameter)
unsigned int UINT
Definition: ndis.h:50
Definition: msgtrace.h:6
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
#define msg(x)
Definition: auth_time.c:54
#define SendMessage
Definition: winuser.h:5744
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:566
#define PM_REMOVE
Definition: winuser.h:1182
LONG_PTR LRESULT
Definition: windef.h:209
#define INFINITE
Definition: serial.h:102
GLuint64EXT * result
Definition: glext.h:11304
LPARAM lParam
Definition: combotst.c:139
#define _Inout_opt_
Definition: no_sal2.h:258
static HANDLE hThread1