ReactOS 0.4.16-dev-334-g4d9f67c
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}
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
static void TestSendMessageTimeout(_In_ HWND hWnd, _In_ UINT Msg)
static void TestRecursiveInterThreadMessages(_In_ BOOL KillThread1, _In_ BOOL KillThread2)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define L(x)
Definition: ntvdm.h:50
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define WM_PAINT
Definition: winuser.h:1623
#define WM_USER
Definition: winuser.h:1898

◆ 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;
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}
static HANDLE hThread2
static DWORD WINAPI Thread2(_Inout_opt_ PVOID Parameter)
static DWORD dwThread2
#define KILL_THREAD2_FLAG
static DWORD WINAPI Thread1(_Inout_opt_ PVOID Parameter)
static DWORD dwThread1
#define KILL_THREAD1_FLAG
static HANDLE hThread1
#define ok(value,...)
Definition: atltest.h:57
#define CloseHandle
Definition: compat.h:739
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 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
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CREATE_SUSPENDED
Definition: winbase.h:181
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by START_TEST().

◆ TestSendMessageTimeout()

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

Definition at line 19 of file SendMessageTimeout.c.

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}
HWND hWnd
Definition: settings.c:17
struct @1642 Msg[]
GLuint64EXT * result
Definition: glext.h:11304
uint32_t DWORD_PTR
Definition: typedefs.h:65
int ret
LONG_PTR LRESULT
Definition: windef.h:209
LRESULT WINAPI SendMessageTimeoutW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
LRESULT WINAPI SendMessageTimeoutA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM, _In_ UINT, _In_ UINT, _Out_opt_ PDWORD_PTR)
#define SMTO_NORMAL
Definition: winuser.h:1228

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
#define msg(x)
Definition: auth_time.c:54
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
@ POST
Definition: msgtrace.h:7
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define WAIT_OBJECT_0
Definition: winbase.h:432
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
#define MWMO_ALERTABLE
Definition: winuser.h:912
#define QS_ALLEVENTS
Definition: winuser.h:905
DWORD WINAPI MsgWaitForMultipleObjectsEx(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask, _In_ DWORD dwFlags)
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:1199
#define PeekMessage
Definition: winuser.h:5842
BOOL WINAPI DestroyWindow(_In_ HWND)

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;
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 hWndThread2
#define WM_SENDTOOTHERTHREAD
WPARAM wParam
Definition: combotst.c:138
UINT_PTR WPARAM
Definition: windef.h:207
#define SendMessage
Definition: winuser.h:5855

Referenced by SepOpenThreadToken(), 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}
#define KILL_THREAD_FLAGS
LPARAM lParam
Definition: combotst.c:139
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:587
@ SENT
Definition: msgtrace.h:6
Definition: tftpd.h:60
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

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 Test_Acquire(), TestRecursiveInterThreadMessages(), and WndProc().

◆ hThread2

HANDLE hThread2
static

◆ 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().