ReactOS 0.4.15-dev-7842-g558ab78
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#include <stdarg.h>
22#include <stdio.h>
23
24#include "windef.h"
25#include "winbase.h"
26#include "wingdi.h"
27#include "winuser.h"
28#include "winnls.h"
29
30#include "wine/test.h"
31
35
37{
38 if (msg == WM_NULL)
39 {
40 trace("main_window_procA: Sleeping for %lu ms\n", wparam);
41 if (wparam)
42 {
45 }
46 trace("main_window_procA: Returning WM_NULL with parameter %08lx\n", lparam);
47 return lparam;
48 }
49
51}
52
53static BOOL init_procs(void)
54{
55 WNDCLASSA cls;
56
57 hevent = CreateEventA(NULL, TRUE, FALSE, "Asynchronous checking event");
58
59 cls.style = CS_DBLCLKS;
61 cls.cbClsExtra = 0;
62 cls.cbWndExtra = 0;
64 cls.hIcon = 0;
67 cls.lpszMenuName = NULL;
68 cls.lpszClassName = "MainWindowClass";
69
70 if (!RegisterClassA(&cls))
71 return FALSE;
72
73 if (!CreateWindowExA(0, "MainWindowClass", "Main window", WS_CAPTION | WS_SYSMENU |
74 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP, 100, 100, 200,
75 200, 0, 0, GetModuleHandleA(NULL), NULL))
76 return FALSE;
77 return TRUE;
78}
79
80static void test_parameters(PBROADCAST broadcast, const char *functionname)
81{
82 LONG ret;
83 DWORD recips;
84
85 SetLastError(0xcafebabe);
86 recips = BSM_APPLICATIONS;
87 ret = broadcast( 0x80000000, &recips, WM_NULL, 0, 0 );
89 {
90 win_skip("%s is not implemented\n", functionname);
91 return;
92 }
93 ok(!ret || broken(ret), "Returned: %d\n", ret);
94 if (!ret) ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
95
96 SetLastError(0xcafebabe);
97 recips = BSM_APPLICATIONS;
98 ret = broadcast( 0x80000000, &recips, WM_NULL, 0, 0 );
99 ok(!ret || broken(ret), "Returned: %d\n", ret);
100 if (!ret) ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
101
102if (0) /* TODO: Check the hang flags */
103{
104 SetLastError(0xcafebabe);
105 recips = BSM_APPLICATIONS;
106 ret = broadcast( BSF_QUERY|(BSF_NOHANG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
107 ok(0, "Last error: %08x\n", GetLastError());
108 ok(0, "Returned: %d\n", ret);
109
110 SetLastError(0xcafebabe);
111 recips = BSM_APPLICATIONS;
112 ret = broadcast( BSF_QUERY|(BSF_NOHANG|BSF_NOTIMEOUTIFNOTHUNG), &recips, WM_NULL, 30000, 0 );
113 ok(0, "Last error: %08x\n", GetLastError());
114 ok(0, "Returned: %d\n", ret);
115
116 SetLastError(0xcafebabe);
117 recips = BSM_APPLICATIONS;
118 ret = broadcast( BSF_QUERY|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
119 ok(0, "Last error: %08x\n", GetLastError());
120 ok(0, "Returned: %d\n", ret);
121
122 SetLastError(0xcafebabe);
123 recips = BSM_APPLICATIONS;
124 ret = broadcast( BSF_POSTMESSAGE|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0 );
125 ok(0, "Last error: %08x\n", GetLastError());
126 ok(0, "Returned: %d\n", ret);
127}
128
129 SetLastError( 0xdeadbeef );
130 recips = BSM_APPLICATIONS;
131 ret = broadcast( BSF_POSTMESSAGE|BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, 0 );
132 ok(ret==1, "Returned: %d\n", ret);
133 ok(WaitForSingleObject(hevent, 0) != WAIT_OBJECT_0, "Synchronous message sent instead\n");
135
136 recips = BSM_APPLICATIONS;
137 ret = broadcast( BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, BROADCAST_QUERY_DENY );
138 ok(ret==1, "Returned: %d\n", ret);
139 ok(WaitForSingleObject(hevent, 0) != WAIT_TIMEOUT, "Asynchronous message sent instead\n");
141}
142
143/* BSF_SENDNOTIFYMESSAGE and BSF_QUERY are both synchronous within the same process
144 * However you should be able to distinguish them by sending the BROADCAST_QUERY_DENY flag
145 */
146
147static void test_parametersEx(PBROADCASTEX broadcastex)
148{
149 LONG ret;
150 DWORD recips;
151
152 SetLastError(0xcafebabe);
153 recips = BSM_APPLICATIONS;
154 ret = broadcastex( 0x80000000, &recips, WM_NULL, 0, 0, NULL );
155 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
156 ok(!ret, "Returned: %d\n", ret);
157
158 SetLastError(0xcafebabe);
159 recips = BSM_APPLICATIONS;
160 ret = broadcastex( 0x80000000, &recips, WM_NULL, 0, 0, NULL );
161 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error: %08x\n", GetLastError());
162 ok(!ret, "Returned: %d\n", ret);
163
164if (0) /* TODO: Check the hang flags */
165{
166 SetLastError(0xcafebabe);
167 recips = BSM_APPLICATIONS;
168 ret = broadcastex( BSF_QUERY|(BSF_NOHANG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
169 ok(0, "Last error: %08x\n", GetLastError());
170 ok(0, "Returned: %d\n", ret);
171
172 SetLastError(0xcafebabe);
173 recips = BSM_APPLICATIONS;
174 ret = broadcastex( BSF_QUERY|(BSF_NOHANG|BSF_NOTIMEOUTIFNOTHUNG), &recips, WM_NULL, 30000, 0, NULL );
175 ok(0, "Last error: %08x\n", GetLastError());
176 ok(0, "Returned: %d\n", ret);
177
178 SetLastError(0xcafebabe);
179 recips = BSM_APPLICATIONS;
180 ret = broadcastex( BSF_QUERY|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
181 ok(0, "Last error: %08x\n", GetLastError());
182 ok(0, "Returned: %d\n", ret);
183
184 SetLastError(0xcafebabe);
185 recips = BSM_APPLICATIONS;
186 ret = broadcastex( BSF_POSTMESSAGE|(BSF_NOTIMEOUTIFNOTHUNG|BSF_FORCEIFHUNG), &recips, WM_NULL, 30000, 0, NULL );
187 ok(0, "Last error: %08x\n", GetLastError());
188 ok(0, "Returned: %d\n", ret);
189}
190
191 recips = BSM_APPLICATIONS;
192 ret = broadcastex( BSF_POSTMESSAGE|BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, 0, NULL );
193 ok(ret==1, "Returned: %d\n", ret);
194 ok(WaitForSingleObject(hevent, 0) != WAIT_OBJECT_0, "Synchronous message sent instead\n");
196
197 recips = BSM_APPLICATIONS;
198 ret = broadcastex( BSF_SENDNOTIFYMESSAGE, &recips, WM_NULL, 100, BROADCAST_QUERY_DENY, NULL );
199 ok(ret==1, "Returned: %d\n", ret);
200 ok(WaitForSingleObject(hevent, 0) != WAIT_TIMEOUT, "Asynchronous message sent instead\n");
202}
203
204START_TEST(broadcast)
205{
206 if (!init_procs())
207 return;
208
209 trace("Running BroadcastSystemMessageA tests\n");
210 test_parameters(BroadcastSystemMessageA, "BroadcastSystemMessageA");
211
212 trace("Running BroadcastSystemMessageW tests\n");
213 test_parameters(BroadcastSystemMessageW, "BroadcastSystemMessageW");
214
215 trace("Running BroadcastSystemMessageExA tests\n");
217
218 trace("Running BroadcastSystemMessageExW tests\n");
220}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
#define broken(x)
Definition: _sntprintf.h:21
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
LONG(WINAPI * PBROADCAST)(DWORD, LPDWORD, UINT, WPARAM, LPARAM)
Definition: broadcast.c:32
static BOOL init_procs(void)
Definition: broadcast.c:53
LONG(WINAPI * PBROADCASTEX)(DWORD, LPDWORD, UINT, WPARAM, LPARAM, PBSMINFO)
Definition: broadcast.c:33
static void test_parametersEx(PBROADCASTEX broadcastex)
Definition: broadcast.c:147
static HANDLE hevent
Definition: broadcast.c:34
static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: broadcast.c:36
#define BSF_POSTMESSAGE
Definition: dbt.h:58
#define BSF_NOTIMEOUTIFNOTHUNG
Definition: dbt.h:57
#define BSF_NOHANG
Definition: dbt.h:56
#define BSF_QUERY
Definition: dbt.h:59
#define BSM_APPLICATIONS
Definition: dbt.h:48
#define BSF_FORCEIFHUNG
Definition: dbt.h:54
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static void test_parameters(void)
Definition: shellpath.c:1313
unsigned int UINT
Definition: ndis.h:50
#define LPDWORD
Definition: nt_native.h:46
#define DWORD
Definition: nt_native.h:44
#define WS_CAPTION
Definition: pedump.c:624
#define WS_MAXIMIZEBOX
Definition: pedump.c:632
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_POPUP
Definition: pedump.c:616
long LONG
Definition: pedump.c:60
#define WS_MINIMIZEBOX
Definition: pedump.c:631
#define win_skip
Definition: test.h:160
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
PBSMINFO
Definition: dosdev.c:30
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent(IN HANDLE hEvent)
Definition: synch.c:695
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
int ret
LONG WINAPI BroadcastSystemMessageExW(DWORD dwflags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam, PBSMINFO pBSMInfo)
Definition: message.c:3439
LONG WINAPI BroadcastSystemMessageA(DWORD dwFlags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam)
Definition: message.c:3393
LONG WINAPI BroadcastSystemMessageExA(DWORD dwflags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam, PBSMINFO pBSMInfo)
Definition: message.c:3423
LONG WINAPI BroadcastSystemMessageW(DWORD dwFlags, LPDWORD lpdwRecipients, UINT uiMessage, WPARAM wParam, LPARAM lParam)
Definition: message.c:3408
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
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
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define WHITE_BRUSH
Definition: wingdi.h:902
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)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_ARROW
Definition: winuser.h:687
#define CS_DBLCLKS
Definition: winuser.h:651
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
#define WM_NULL
Definition: winuser.h:1607
#define BROADCAST_QUERY_DENY
Definition: winuser.h:178
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2090
const char * LPCSTR
Definition: xmlstorage.h:183