2 * Unit tests for BroadcastSystemMessage
4 * Copyright 2008 Maarten Lankhorst
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.
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.
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
21 #define _WIN32_WINNT 0x0501
32 #include "wine/test.h"
34 typedef LONG (WINAPI
*PBROADCAST
)( DWORD
,LPDWORD
,UINT
,WPARAM
,LPARAM
);
35 typedef LONG (WINAPI
*PBROADCASTEX
)( DWORD
,LPDWORD
,UINT
,WPARAM
,LPARAM
,PBSMINFO
);
38 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
42 trace("main_window_procA: Sleeping for %lu ms\n", wparam
);
45 if (WaitForSingleObject(hevent
, wparam
) == WAIT_TIMEOUT
)
48 trace("main_window_procA: Returning WM_NULL with parameter %08lx\n", lparam
);
52 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
55 static BOOL
init_procs(void)
59 hevent
= CreateEventA(NULL
, TRUE
, FALSE
, "Asynchronous checking event");
61 cls
.style
= CS_DBLCLKS
;
62 cls
.lpfnWndProc
= main_window_procA
;
65 cls
.hInstance
= GetModuleHandleA(0);
67 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
68 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
69 cls
.lpszMenuName
= NULL
;
70 cls
.lpszClassName
= "MainWindowClass";
72 if (!RegisterClassA(&cls
))
75 if (!CreateWindowExA(0, "MainWindowClass", "Main window", WS_CAPTION
| WS_SYSMENU
|
76 WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
, 100, 100, 200,
77 200, 0, 0, GetModuleHandleA(NULL
), NULL
))
82 static void test_parameters(PBROADCAST broadcast
, const char *functionname
)
87 SetLastError(0xcafebabe);
88 recips
= BSM_APPLICATIONS
;
89 ret
= broadcast( 0x80000000, &recips
, WM_NULL
, 0, 0 );
90 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
92 win_skip("%s is not implemented\n", functionname
);
95 ok(!ret
|| broken(ret
), "Returned: %d\n", ret
);
96 if (!ret
) ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Last error: %08x\n", GetLastError());
98 SetLastError(0xcafebabe);
99 recips
= BSM_APPLICATIONS
;
100 ret
= broadcast( 0x80000000, &recips
, WM_NULL
, 0, 0 );
101 ok(!ret
|| broken(ret
), "Returned: %d\n", ret
);
102 if (!ret
) ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Last error: %08x\n", GetLastError());
104 if (0) /* TODO: Check the hang flags */
106 SetLastError(0xcafebabe);
107 recips
= BSM_APPLICATIONS
;
108 ret
= broadcast( BSF_QUERY
|(BSF_NOHANG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0 );
109 ok(0, "Last error: %08x\n", GetLastError());
110 ok(0, "Returned: %d\n", ret
);
112 SetLastError(0xcafebabe);
113 recips
= BSM_APPLICATIONS
;
114 ret
= broadcast( BSF_QUERY
|(BSF_NOHANG
|BSF_NOTIMEOUTIFNOTHUNG
), &recips
, WM_NULL
, 30000, 0 );
115 ok(0, "Last error: %08x\n", GetLastError());
116 ok(0, "Returned: %d\n", ret
);
118 SetLastError(0xcafebabe);
119 recips
= BSM_APPLICATIONS
;
120 ret
= broadcast( BSF_QUERY
|(BSF_NOTIMEOUTIFNOTHUNG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0 );
121 ok(0, "Last error: %08x\n", GetLastError());
122 ok(0, "Returned: %d\n", ret
);
124 SetLastError(0xcafebabe);
125 recips
= BSM_APPLICATIONS
;
126 ret
= broadcast( BSF_POSTMESSAGE
|(BSF_NOTIMEOUTIFNOTHUNG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0 );
127 ok(0, "Last error: %08x\n", GetLastError());
128 ok(0, "Returned: %d\n", ret
);
131 SetLastError( 0xdeadbeef );
132 recips
= BSM_APPLICATIONS
;
133 ret
= broadcast( BSF_POSTMESSAGE
|BSF_SENDNOTIFYMESSAGE
, &recips
, WM_NULL
, 100, 0 );
134 ok(ret
==1, "Returned: %d\n", ret
);
135 ok(WaitForSingleObject(hevent
, 0) != WAIT_OBJECT_0
, "Synchronous message sent instead\n");
138 recips
= BSM_APPLICATIONS
;
139 ret
= broadcast( BSF_SENDNOTIFYMESSAGE
, &recips
, WM_NULL
, 100, BROADCAST_QUERY_DENY
);
140 ok(ret
==1, "Returned: %d\n", ret
);
141 ok(WaitForSingleObject(hevent
, 0) != WAIT_TIMEOUT
, "Asynchronous message sent instead\n");
145 /* BSF_SENDNOTIFYMESSAGE and BSF_QUERY are both synchronous within the same process
146 * However you should be able to distinguish them by sending the BROADCAST_QUERY_DENY flag
149 static void test_parametersEx(PBROADCASTEX broadcastex
)
154 SetLastError(0xcafebabe);
155 recips
= BSM_APPLICATIONS
;
156 ret
= broadcastex( 0x80000000, &recips
, WM_NULL
, 0, 0, NULL
);
157 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Last error: %08x\n", GetLastError());
158 ok(!ret
, "Returned: %d\n", ret
);
160 SetLastError(0xcafebabe);
161 recips
= BSM_APPLICATIONS
;
162 ret
= broadcastex( 0x80000000, &recips
, WM_NULL
, 0, 0, NULL
);
163 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Last error: %08x\n", GetLastError());
164 ok(!ret
, "Returned: %d\n", ret
);
166 if (0) /* TODO: Check the hang flags */
168 SetLastError(0xcafebabe);
169 recips
= BSM_APPLICATIONS
;
170 ret
= broadcastex( BSF_QUERY
|(BSF_NOHANG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0, NULL
);
171 ok(0, "Last error: %08x\n", GetLastError());
172 ok(0, "Returned: %d\n", ret
);
174 SetLastError(0xcafebabe);
175 recips
= BSM_APPLICATIONS
;
176 ret
= broadcastex( BSF_QUERY
|(BSF_NOHANG
|BSF_NOTIMEOUTIFNOTHUNG
), &recips
, WM_NULL
, 30000, 0, NULL
);
177 ok(0, "Last error: %08x\n", GetLastError());
178 ok(0, "Returned: %d\n", ret
);
180 SetLastError(0xcafebabe);
181 recips
= BSM_APPLICATIONS
;
182 ret
= broadcastex( BSF_QUERY
|(BSF_NOTIMEOUTIFNOTHUNG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0, NULL
);
183 ok(0, "Last error: %08x\n", GetLastError());
184 ok(0, "Returned: %d\n", ret
);
186 SetLastError(0xcafebabe);
187 recips
= BSM_APPLICATIONS
;
188 ret
= broadcastex( BSF_POSTMESSAGE
|(BSF_NOTIMEOUTIFNOTHUNG
|BSF_FORCEIFHUNG
), &recips
, WM_NULL
, 30000, 0, NULL
);
189 ok(0, "Last error: %08x\n", GetLastError());
190 ok(0, "Returned: %d\n", ret
);
193 recips
= BSM_APPLICATIONS
;
194 ret
= broadcastex( BSF_POSTMESSAGE
|BSF_SENDNOTIFYMESSAGE
, &recips
, WM_NULL
, 100, 0, NULL
);
195 ok(ret
==1, "Returned: %d\n", ret
);
196 ok(WaitForSingleObject(hevent
, 0) != WAIT_OBJECT_0
, "Synchronous message sent instead\n");
199 recips
= BSM_APPLICATIONS
;
200 ret
= broadcastex( BSF_SENDNOTIFYMESSAGE
, &recips
, WM_NULL
, 100, BROADCAST_QUERY_DENY
, NULL
);
201 ok(ret
==1, "Returned: %d\n", ret
);
202 ok(WaitForSingleObject(hevent
, 0) != WAIT_TIMEOUT
, "Asynchronous message sent instead\n");
206 START_TEST(broadcast
)
211 trace("Running BroadcastSystemMessageA tests\n");
212 test_parameters(BroadcastSystemMessageA
, "BroadcastSystemMessageA");
214 trace("Running BroadcastSystemMessageW tests\n");
215 test_parameters(BroadcastSystemMessageW
, "BroadcastSystemMessageW");
217 trace("Running BroadcastSystemMessageExA tests\n");
218 test_parametersEx(BroadcastSystemMessageExA
);
220 trace("Running BroadcastSystemMessageExW tests\n");
221 test_parametersEx(BroadcastSystemMessageExW
);