user32/listbox: Make SetCount fail if LBS_NODATA is not set.
[wine.git] / dlls / user32 / tests / broadcast.c
blob1a216955bba11cbe82df42cadebbc5d601b1d4ca
1 /*
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
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winnls.h"
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 );
36 static HANDLE hevent;
38 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
40 if (msg == WM_NULL)
42 trace("main_window_procA: Sleeping for %lu ms\n", wparam);
43 if (wparam)
45 if (WaitForSingleObject(hevent, wparam) == WAIT_TIMEOUT)
46 SetEvent(hevent);
48 trace("main_window_procA: Returning WM_NULL with parameter %08lx\n", lparam);
49 return lparam;
52 return DefWindowProcA(hwnd, msg, wparam, lparam);
55 static BOOL init_procs(void)
57 WNDCLASSA cls;
59 hevent = CreateEventA(NULL, TRUE, FALSE, "Asynchronous checking event");
61 cls.style = CS_DBLCLKS;
62 cls.lpfnWndProc = main_window_procA;
63 cls.cbClsExtra = 0;
64 cls.cbWndExtra = 0;
65 cls.hInstance = GetModuleHandleA(0);
66 cls.hIcon = 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))
73 return FALSE;
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))
78 return FALSE;
79 return TRUE;
82 static void test_parameters(PBROADCAST broadcast, const char *functionname)
84 LONG ret;
85 DWORD recips;
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);
93 return;
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");
136 PulseEvent(hevent);
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");
142 PulseEvent(hevent);
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)
151 LONG ret;
152 DWORD recips;
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");
197 PulseEvent(hevent);
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");
203 PulseEvent(hevent);
206 START_TEST(broadcast)
208 if (!init_procs())
209 return;
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);