ReactOS  0.4.14-dev-828-g8dc90a4
broadcast.c
Go to the documentation of this file.
1 /*
2  * Unit tests for BroadcastSystemMessage
3  *
4  * Copyright 2008 Maarten Lankhorst
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #ifndef __REACTOS__
22 #define _WIN32_WINNT 0x0501
23 #endif
24 
25 #include <stdarg.h>
26 #include <stdio.h>
27 
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 
34 #include "wine/test.h"
35 
38 static HANDLE hevent;
39 
41 {
42  if (msg == WM_NULL)
43  {
44  trace("main_window_procA: Sleeping for %lu ms\n", wparam);
45  if (wparam)
46  {
49  }
50  trace("main_window_procA: Returning WM_NULL with parameter %08lx\n", lparam);
51  return lparam;
52  }
53 
54  return DefWindowProcA(hwnd, msg, wparam, lparam);
55 }
56 
57 static BOOL init_procs(void)
58 {
59  WNDCLASSA cls;
60 
61  hevent = CreateEventA(NULL, TRUE, FALSE, "Asynchronous checking event");
62 
63  cls.style = CS_DBLCLKS;
65  cls.cbClsExtra = 0;
66  cls.cbWndExtra = 0;
67  cls.hInstance = GetModuleHandleA(0);
68  cls.hIcon = 0;
71  cls.lpszMenuName = NULL;
72  cls.lpszClassName = "MainWindowClass";
73 
74  if (!RegisterClassA(&cls))
75  return FALSE;
76 
77  if (!CreateWindowExA(0, "MainWindowClass", "Main window", WS_CAPTION | WS_SYSMENU |
78  WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP, 100, 100, 200,
79  200, 0, 0, GetModuleHandleA(NULL), NULL))
80  return FALSE;
81  return TRUE;
82 }
83 
84 static void test_parameters(PBROADCAST broadcast, const char *functionname)
85 {
86  LONG ret;
87  DWORD recips;
88 
89  SetLastError(0xcafebabe);
90  recips = BSM_APPLICATIONS;
91  ret = broadcast( 0x80000000, &recips, WM_NULL, 0, 0 );
93  {
94  win_skip("%s is not implemented\n", functionname);
95  return;
96  }
97  ok(!ret || broken(ret), "Returned: %d\n", ret);
98  if (!ret) ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
99 
100  SetLastError(0xcafebabe);
101  recips = BSM_APPLICATIONS;
102  ret = broadcast( 0x80000000, &recips, WM_NULL, 0, 0 );
103  ok(!ret || broken(ret), "Returned: %d\n", ret);
104  if (!ret) ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
105 
106 if (0) /* TODO: Check the hang flags */
107 {
108  SetLastError(0xcafebabe);
109  recips = BSM_APPLICATIONS;
110  ret = broadcast( BSF_QUERY|(BSF_NOHANG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
111  ok(0, "Last error: %08x\n", GetLastError());
112  ok(0, "Returned: %d\n", ret);
113 
114  SetLastError(0xcafebabe);
115  recips = BSM_APPLICATIONS;
116  ret = broadcast( BSF_QUERY|(BSF_NOHANG|BSF_NOTIMEOUTIFNOTHUNG), &recips, WM_NULL, 30000, 0 );
117  ok(0, "Last error: %08x\n", GetLastError());
118  ok(0, "Returned: %d\n", ret);
119 
120  SetLastError(0xcafebabe);
121  recips = BSM_APPLICATIONS;
122  ret = broadcast( BSF_QUERY|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
123  ok(0, "Last error: %08x\n", GetLastError());
124  ok(0, "Returned: %d\n", ret);
125 
126  SetLastError(0xcafebabe);
127  recips = BSM_APPLICATIONS;
128  ret = broadcast( BSF_POSTMESSAGE|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
129  ok(0, "Last error: %08x\n", GetLastError());
130  ok(0, "Returned: %d\n", ret);
131 }
132 
133  SetLastError( 0xdeadbeef );
134  recips = BSM_APPLICATIONS;
135  ret = broadcast( BSF_POSTMESSAGE|BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, 0 );
136  ok(ret==1, "Returned: %d\n", ret);
137  ok(WaitForSingleObject(hevent, 0) != WAIT_OBJECT_0, "Synchronous message sent instead\n");
139 
140  recips = BSM_APPLICATIONS;
141  ret = broadcast( BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, BROADCAST_QUERY_DENY );
142  ok(ret==1, "Returned: %d\n", ret);
143  ok(WaitForSingleObject(hevent, 0) != WAIT_TIMEOUT, "Asynchronous message sent instead\n");
145 }
146 
147 /* BSF_SENDNOTIFYMESSAGE and BSF_QUERY are both synchronous within the same process
148  * However you should be able to distinguish them by sending the BROADCAST_QUERY_DENY flag
149  */
150 
151 static void test_parametersEx(PBROADCASTEX broadcastex)
152 {
153  LONG ret;
154  DWORD recips;
155 
156  SetLastError(0xcafebabe);
157  recips = BSM_APPLICATIONS;
158  ret = broadcastex( 0x80000000, &recips, WM_NULL, 0, 0, NULL );
159  ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
160  ok(!ret, "Returned: %d\n", ret);
161 
162  SetLastError(0xcafebabe);
163  recips = BSM_APPLICATIONS;
164  ret = broadcastex( 0x80000000, &recips, WM_NULL, 0, 0, NULL );
165  ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
166  ok(!ret, "Returned: %d\n", ret);
167 
168 if (0) /* TODO: Check the hang flags */
169 {
170  SetLastError(0xcafebabe);
171  recips = BSM_APPLICATIONS;
172  ret = broadcastex( BSF_QUERY|(BSF_NOHANG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
173  ok(0, "Last error: %08x\n", GetLastError());
174  ok(0, "Returned: %d\n", ret);
175 
176  SetLastError(0xcafebabe);
177  recips = BSM_APPLICATIONS;
178  ret = broadcastex( BSF_QUERY|(BSF_NOHANG|BSF_NOTIMEOUTIFNOTHUNG), &recips, WM_NULL, 30000, 0, NULL );
179  ok(0, "Last error: %08x\n", GetLastError());
180  ok(0, "Returned: %d\n", ret);
181 
182  SetLastError(0xcafebabe);
183  recips = BSM_APPLICATIONS;
184  ret = broadcastex( BSF_QUERY|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
185  ok(0, "Last error: %08x\n", GetLastError());
186  ok(0, "Returned: %d\n", ret);
187 
188  SetLastError(0xcafebabe);
189  recips = BSM_APPLICATIONS;
190  ret = broadcastex( BSF_POSTMESSAGE|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
191  ok(0, "Last error: %08x\n", GetLastError());
192  ok(0, "Returned: %d\n", ret);
193 }
194 
195  recips = BSM_APPLICATIONS;
196  ret = broadcastex( BSF_POSTMESSAGE|BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, 0, NULL );
197  ok(ret==1, "Returned: %d\n", ret);
198  ok(WaitForSingleObject(hevent, 0) != WAIT_OBJECT_0, "Synchronous message sent instead\n");
200 
201  recips = BSM_APPLICATIONS;
202  ret = broadcastex( BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, BROADCAST_QUERY_DENY, NULL );
203  ok(ret==1, "Returned: %d\n", ret);
204  ok(WaitForSingleObject(hevent, 0) != WAIT_TIMEOUT, "Asynchronous message sent instead\n");
206 }
207 
208 START_TEST(broadcast)
209 {
210  if (!init_procs())
211  return;
212 
213  trace("Running BroadcastSystemMessageA tests\n");
214  test_parameters(BroadcastSystemMessageA, "BroadcastSystemMessageA");
215 
216  trace("Running BroadcastSystemMessageW tests\n");
217  test_parameters(BroadcastSystemMessageW, "BroadcastSystemMessageW");
218 
219  trace("Running BroadcastSystemMessageExA tests\n");
221 
222  trace("Running BroadcastSystemMessageExW tests\n");
224 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define WM_NULL
Definition: winuser.h:1589
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define BSF_FORCEIFHUNG
Definition: dbt.h:54
#define TRUE
Definition: types.h:120
static void test_parametersEx(PBROADCASTEX broadcastex)
Definition: broadcast.c:151
#define BROADCAST_QUERY_DENY
Definition: winuser.h:178
LONG WINAPI BroadcastSystemMessageW(DWORD dwFlags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam)
Definition: message.c:3397
#define BSF_NOTIMEOUTIFNOTHUNG
Definition: dbt.h:57
#define BSF_QUERY
Definition: dbt.h:59
int cbClsExtra
Definition: winuser.h:3140
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPCSTR lpszMenuName
Definition: winuser.h:3146
#define WHITE_BRUSH
Definition: wingdi.h:901
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3145
LONG(WINAPI * PBROADCAST)(DWORD, LPDWORD, UINT, WPARAM, LPARAM)
Definition: broadcast.c:36
#define BSF_NOHANG
Definition: dbt.h:56
#define BSF_POSTMESSAGE
Definition: dbt.h:58
#define DWORD
Definition: nt_native.h:44
LONG WINAPI BroadcastSystemMessageExW(DWORD dwflags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam, PBSMINFO pBSMInfo)
Definition: message.c:3428
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static HANDLE hevent
Definition: broadcast.c:38
int cbWndExtra
Definition: winuser.h:3141
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent(IN HANDLE hEvent)
Definition: synch.c:695
HCURSOR hCursor
Definition: winuser.h:3144
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
const char * LPCSTR
Definition: xmlstorage.h:183
#define WS_MAXIMIZEBOX
Definition: pedump.c:632
LONG(WINAPI * PBROADCASTEX)(DWORD, LPDWORD, UINT, WPARAM, LPARAM, PBSMINFO)
Definition: broadcast.c:37
#define WS_CAPTION
Definition: pedump.c:624
static void test_parameters(PBROADCAST broadcast, const char *functionname)
Definition: broadcast.c:84
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define trace
Definition: atltest.h:70
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define WAIT_TIMEOUT
Definition: dderror.h:14
int ret
START_TEST(broadcast)
Definition: broadcast.c:208
static BOOL init_procs(void)
Definition: broadcast.c:57
#define LPDWORD
Definition: nt_native.h:46
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define CS_DBLCLKS
Definition: winuser.h:646
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: broadcast.c:40
LPCSTR lpszClassName
Definition: winuser.h:3147
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2059
#define broken(x)
Definition: _sntprintf.h:21
UINT style
Definition: winuser.h:3138
#define WS_MINIMIZEBOX
Definition: pedump.c:631
HINSTANCE hInstance
Definition: winuser.h:3142
#define ok(value,...)
Definition: atltest.h:57
#define WS_POPUP
Definition: pedump.c:616
unsigned int UINT
Definition: ndis.h:50
WNDPROC lpfnWndProc
Definition: winuser.h:3139
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR 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 ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
PBSMINFO
Definition: dosdev.c:30
LONG WINAPI BroadcastSystemMessageExA(DWORD dwflags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam, PBSMINFO pBSMInfo)
Definition: message.c:3412
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_SYSMENU
Definition: pedump.c:629
#define win_skip
Definition: test.h:149
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
#define BSM_APPLICATIONS
Definition: dbt.h:48
LONG WINAPI BroadcastSystemMessageA(DWORD dwFlags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam)
Definition: message.c:3382
static UINT WPARAM wparam
Definition: combo.c:716
HICON hIcon
Definition: winuser.h:3143