ReactOS  0.4.14-dev-317-g96040ec
SendMessageTimeout.c File Reference
#include "precomp.h"
Include dependency graph for SendMessageTimeout.c:

Go to the source code of this file.

Macros

#define WM_SENDTOOTHERTHREAD   (WM_USER + 14)
 
#define KILL_THREAD1_FLAG   0x40000000
 
#define KILL_THREAD2_FLAG   0x20000000
 
#define KILL_THREAD_FLAGS   (KILL_THREAD1_FLAG | KILL_THREAD2_FLAG)
 

Functions

static void TestSendMessageTimeout (_In_ HWND hWnd, _In_ UINT Msg)
 
static LRESULT CALLBACK WndProc (_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
 
static DWORD WINAPI Thread1 (_Inout_opt_ PVOID Parameter)
 
static DWORD WINAPI Thread2 (_Inout_opt_ PVOID Parameter)
 
static void TestRecursiveInterThreadMessages (_In_ BOOL KillThread1, _In_ BOOL KillThread2)
 
 START_TEST (SendMessageTimeout)
 

Variables

static DWORD dwThread1
 
static DWORD dwThread2
 
static HANDLE hThread1
 
static HANDLE hThread2
 
static HWND hWndThread1
 
static HWND hWndThread2
 

Macro Definition Documentation

◆ KILL_THREAD1_FLAG

#define KILL_THREAD1_FLAG   0x40000000

Definition at line 45 of file SendMessageTimeout.c.

◆ KILL_THREAD2_FLAG

#define KILL_THREAD2_FLAG   0x20000000

Definition at line 46 of file SendMessageTimeout.c.

◆ KILL_THREAD_FLAGS

#define KILL_THREAD_FLAGS   (KILL_THREAD1_FLAG | KILL_THREAD2_FLAG)

Definition at line 47 of file SendMessageTimeout.c.

◆ WM_SENDTOOTHERTHREAD

#define WM_SENDTOOTHERTHREAD   (WM_USER + 14)

Definition at line 43 of file SendMessageTimeout.c.

Function Documentation

◆ START_TEST()

START_TEST ( SendMessageTimeout  )

Definition at line 227 of file SendMessageTimeout.c.

228 {
231  TestSendMessageTimeout(NULL, WM_GETICON);
232 
233  RegisterSimpleClass(WndProc, L"SendTest");
234 
239 }
#define TRUE
Definition: types.h:120
static void TestRecursiveInterThreadMessages(_In_ BOOL KillThread1, _In_ BOOL KillThread2)
static void TestSendMessageTimeout(_In_ HWND hWnd, _In_ UINT Msg)
smooth NULL
Definition: ftsmooth.c:416
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define WM_PAINT
Definition: winuser.h:1602
static const WCHAR L[]
Definition: oid.c:1250
#define WM_USER
Definition: winuser.h:1877
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)

◆ TestRecursiveInterThreadMessages()

static void TestRecursiveInterThreadMessages ( _In_ BOOL  KillThread1,
_In_ BOOL  KillThread2 
)
static

Definition at line 187 of file SendMessageTimeout.c.

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 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
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
#define KILL_THREAD1_FLAG
static DWORD WINAPI Thread1(_Inout_opt_ PVOID Parameter)
#define KILL_THREAD2_FLAG
BOOL WINAPI GetExitCodeThread(IN HANDLE hThread, OUT LPDWORD lpExitCode)
Definition: thread.c:540
#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 UlongToPtr(u)
Definition: config.h:106
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE hThread2
#define ok(value,...)
Definition: atltest.h:57
static DWORD dwThread2
static DWORD WINAPI Thread2(_Inout_opt_ PVOID Parameter)
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:566
#define INFINITE
Definition: serial.h:102
static HANDLE hThread1

Referenced by START_TEST().

◆ TestSendMessageTimeout()

static void TestSendMessageTimeout ( _In_ HWND  hWnd,
_In_ UINT  Msg 
)
static

Definition at line 19 of file SendMessageTimeout.c.

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 }
HWND hWnd
Definition: settings.c:17
#define SMTO_NORMAL
Definition: winuser.h:1211
smooth NULL
Definition: ftsmooth.c:416
struct @1593 Msg[]
LRESULT WINAPI SendMessageTimeoutA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
int ret
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define ok(value,...)
Definition: atltest.h:57
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
LONG_PTR LRESULT
Definition: windef.h:209
GLuint64EXT * result
Definition: glext.h:11304

Referenced by START_TEST().

◆ Thread1()

static DWORD WINAPI Thread1 ( _Inout_opt_ PVOID  Parameter)
static

Definition at line 105 of file SendMessageTimeout.c.

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 }
static HWND hWndThread1
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5731
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI DestroyWindow(_In_ HWND)
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
smooth NULL
Definition: ftsmooth.c:416
#define QS_ALLEVENTS
Definition: winuser.h:873
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define MWMO_ALERTABLE
Definition: winuser.h:899
static HANDLE hThread2
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)
#define WM_USER
Definition: winuser.h:1877
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define ok(value,...)
Definition: atltest.h:57
#define msg(x)
Definition: auth_time.c:54
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:566
#define PM_REMOVE
Definition: winuser.h:1182

Referenced by SystemProcessTest(), and TestRecursiveInterThreadMessages().

◆ Thread2()

static DWORD WINAPI Thread2 ( _Inout_opt_ PVOID  Parameter)
static

Definition at line 146 of file SendMessageTimeout.c.

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 }
static HWND hWndThread1
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5731
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
UINT_PTR WPARAM
Definition: windef.h:207
_In_ PVOID Parameter
Definition: ldrtypes.h:241
BOOL WINAPI DestroyWindow(_In_ HWND)
WPARAM wParam
Definition: combotst.c:138
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
smooth NULL
Definition: ftsmooth.c:416
static HWND hWndThread2
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)
#define WM_USER
Definition: winuser.h:1877
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define WM_SENDTOOTHERTHREAD
#define ok(value,...)
Definition: atltest.h:57
static DWORD dwThread2
#define msg(x)
Definition: auth_time.c:54
#define SendMessage
Definition: winuser.h:5744
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define PM_REMOVE
Definition: winuser.h:1182
LONG_PTR LRESULT
Definition: windef.h:209

Referenced by SystemProcessTest(), and TestRecursiveInterThreadMessages().

◆ WndProc()

static LRESULT CALLBACK WndProc ( _In_ HWND  hWnd,
_In_ UINT  message,
_In_ WPARAM  wParam,
_In_ LPARAM  lParam 
)
static

Definition at line 52 of file SendMessageTimeout.c.

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 }
static HWND hWndThread1
#define KILL_THREAD_FLAGS
Definition: tftpd.h:59
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:586
HWND hWnd
Definition: settings.c:17
static DWORD dwThread1
#define KILL_THREAD1_FLAG
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define KILL_THREAD2_FLAG
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
static HWND hWndThread2
static HANDLE hThread2
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define WM_SENDTOOTHERTHREAD
#define ok(value,...)
Definition: atltest.h:57
static DWORD dwThread2
Definition: msgtrace.h:6
#define SendMessage
Definition: winuser.h:5744
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
LPARAM lParam
Definition: combotst.c:139
static HANDLE hThread1

Referenced by START_TEST().

Variable Documentation

◆ dwThread1

DWORD dwThread1
static

Definition at line 10 of file SendMessageTimeout.c.

Referenced by TestRecursiveInterThreadMessages(), and WndProc().

◆ dwThread2

DWORD dwThread2
static

Definition at line 11 of file SendMessageTimeout.c.

Referenced by TestRecursiveInterThreadMessages(), Thread2(), and WndProc().

◆ hThread1

HANDLE hThread1
static

Definition at line 12 of file SendMessageTimeout.c.

Referenced by TestRecursiveInterThreadMessages(), and WndProc().

◆ hThread2

HANDLE hThread2
static

Definition at line 13 of file SendMessageTimeout.c.

Referenced by TestRecursiveInterThreadMessages(), Thread1(), and WndProc().

◆ hWndThread1

HWND hWndThread1
static

Definition at line 14 of file SendMessageTimeout.c.

Referenced by Thread1(), Thread2(), and WndProc().

◆ hWndThread2

HWND hWndThread2
static

Definition at line 15 of file SendMessageTimeout.c.

Referenced by Thread2(), and WndProc().