mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / localui / tests / localui.c
blob23be8c779d16178ce0d08310d042f3a12c7b8fe2
1 /*
2 * Unit test suite for the Local Printmonitor User Interface
4 * Copyright 2007 Detlef Riekenberg
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wingdi.h"
29 #include "winnls.h"
30 #include "winreg.h"
32 #include "winspool.h"
33 #include "ddk/winsplp.h"
35 #include "wine/test.h"
38 /* ##### */
40 static HMODULE hdll;
41 static PMONITORUI (WINAPI *pInitializePrintMonitorUI)(VOID);
42 static PMONITORUI pui;
43 static BOOL (WINAPI *pAddPortUI)(PCWSTR, HWND, PCWSTR, PWSTR *);
44 static BOOL (WINAPI *pConfigurePortUI)(PCWSTR, HWND, PCWSTR);
45 static BOOL (WINAPI *pDeletePortUI)(PCWSTR, HWND, PCWSTR);
47 static LPBYTE pi_buffer;
48 static DWORD pi_numports;
49 static DWORD pi_needed;
51 static PORT_INFO_2W * lpt_present;
52 static PORT_INFO_2W * com_present;
53 static PORT_INFO_2W * file_present;
55 static LPWSTR lpt_absent;
56 static LPWSTR com_absent;
58 /* ########################### */
60 static PORT_INFO_2W * find_portinfo2(LPCWSTR pPort)
62 PORT_INFO_2W * pi;
63 DWORD res;
65 if (!pi_buffer) {
66 res = EnumPortsW(NULL, 2, NULL, 0, &pi_needed, &pi_numports);
67 if (!res && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) {
68 win_skip("The service 'Spooler' is required for many tests\n");
69 return NULL;
71 ok(!res, "EnumPorts succeeded: got %d\n", res);
72 pi_buffer = HeapAlloc(GetProcessHeap(), 0, pi_needed);
73 res = EnumPortsW(NULL, 2, pi_buffer, pi_needed, &pi_needed, &pi_numports);
74 ok(res == 1, "EnumPorts failed: got %d\n", res);
76 if (pi_buffer) {
77 pi = (PORT_INFO_2W *) pi_buffer;
78 res = 0;
79 while (pi_numports > res) {
80 if (lstrcmpiW(pi->pPortName, pPort) == 0) {
81 return pi;
83 pi++;
84 res++;
87 return NULL;
91 /* ########################### */
93 static LPCSTR load_functions(void)
95 LPCSTR ptr;
97 ptr = "localui.dll";
98 hdll = LoadLibraryA(ptr);
99 if (!hdll) return ptr;
101 ptr = "InitializePrintMonitorUI";
102 pInitializePrintMonitorUI = (VOID *) GetProcAddress(hdll, ptr);
103 if (!pInitializePrintMonitorUI) return ptr;
105 return NULL;
108 /* ###########################
109 * strdupW [internal]
112 static LPWSTR strdupW(LPCWSTR strW)
114 LPWSTR ptr;
116 ptr = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(strW) + 1) * sizeof(WCHAR));
117 if (ptr) {
118 lstrcpyW(ptr, strW);
120 return ptr;
123 /* ########################### */
125 static void test_AddPortUI(void)
127 DWORD res;
128 LPWSTR new_portname;
130 /* not present before w2k */
131 if (!pAddPortUI) {
132 skip("AddPortUI not found\n");
133 return;
136 SetLastError(0xdeadbeef);
137 res = pAddPortUI(NULL, NULL, NULL, NULL);
138 ok( !res &&
139 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
140 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
141 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
143 SetLastError(0xdeadbeef);
144 res = pAddPortUI(NULL, NULL, L"", NULL);
145 ok( !res &&
146 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
147 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
148 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
150 SetLastError(0xdeadbeef);
151 res = pAddPortUI(NULL, NULL, L"does_not_exist", NULL);
152 ok( !res &&
153 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
154 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
155 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
157 if (winetest_interactive) {
158 SetLastError(0xdeadbeef);
159 new_portname = NULL;
161 * - On MSDN, you can read that no dialog should be displayed when hWnd
162 * is NULL, but native localui does not care
163 * - When the new port already exists,
164 * TRUE is returned, but new_portname is NULL
165 * - When the new port starts with "COM" or "LPT",
166 * FALSE is returned with ERROR_NOT_SUPPORTED on windows
168 res = pAddPortUI(NULL, NULL, L"Local Port", &new_portname);
169 ok( res ||
170 (GetLastError() == ERROR_CANCELLED) ||
171 (GetLastError() == ERROR_ACCESS_DENIED) ||
172 (GetLastError() == ERROR_NOT_SUPPORTED),
173 "got %d with %u and %p (expected '!= 0' or '0' with: "
174 "ERROR_CANCELLED, ERROR_ACCESS_DENIED or ERROR_NOT_SUPPORTED)\n",
175 res, GetLastError(), new_portname);
177 GlobalFree(new_portname);
181 /* ########################### */
183 static void test_ConfigurePortUI(void)
185 DWORD res;
187 /* not present before w2k */
188 if (!pConfigurePortUI) {
189 skip("ConfigurePortUI not found\n");
190 return;
193 SetLastError(0xdeadbeef);
194 res = pConfigurePortUI(NULL, NULL, NULL);
195 ok( !res &&
196 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
197 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
198 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
200 SetLastError(0xdeadbeef);
201 res = pConfigurePortUI(NULL, NULL, L"");
202 ok( !res &&
203 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
204 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
205 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
208 SetLastError(0xdeadbeef);
209 res = pConfigurePortUI(NULL, NULL, L"does_not_exist");
210 ok( !res &&
211 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
212 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
213 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
215 if (winetest_interactive && lpt_present) {
216 SetLastError(0xdeadbeef);
217 res = pConfigurePortUI(NULL, NULL, lpt_present->pPortName);
218 ok( res ||
219 (GetLastError() == ERROR_CANCELLED) || (GetLastError() == ERROR_ACCESS_DENIED),
220 "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
221 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
224 if (lpt_absent) {
225 SetLastError(0xdeadbeef);
226 res = pConfigurePortUI(NULL, NULL, lpt_absent);
227 ok( !res &&
228 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
229 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
230 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
233 if (winetest_interactive && com_present) {
234 SetLastError(0xdeadbeef);
235 res = pConfigurePortUI(NULL, NULL, com_present->pPortName);
236 ok( res ||
237 (GetLastError() == ERROR_CANCELLED) || (GetLastError() == ERROR_ACCESS_DENIED),
238 "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
239 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
242 if (com_absent) {
243 SetLastError(0xdeadbeef);
244 res = pConfigurePortUI(NULL, NULL, com_absent);
245 ok( !res &&
246 ((GetLastError() == ERROR_UNKNOWN_PORT) || (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
247 "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
248 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
252 if (winetest_interactive && file_present) {
253 SetLastError(0xdeadbeef);
254 res = pConfigurePortUI(NULL, NULL, L"FILE:");
255 ok( !res &&
256 ((GetLastError() == ERROR_CANCELLED) || (GetLastError() == ERROR_ACCESS_DENIED)),
257 "got %d with %u (expected '0' with: ERROR_CANCELLED or "
258 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
262 /* ########################### */
264 START_TEST(localui)
266 LPCSTR ptr;
267 DWORD numentries;
268 PORT_INFO_2W * pi2;
269 WCHAR bufferW[16];
270 CHAR bufferA[16];
271 DWORD id;
273 /* localui.dll does not exist before w2k */
274 ptr = load_functions();
275 if (ptr) {
276 skip("%s not found\n", ptr);
277 return;
280 pui = pInitializePrintMonitorUI();
281 if (pui) {
282 numentries = (pui->dwMonitorUISize - sizeof(DWORD)) / sizeof(VOID *);
283 ok( numentries == 3,
284 "dwMonitorUISize (%d) => %d Functions\n", pui->dwMonitorUISize, numentries);
286 if (numentries > 2) {
287 pAddPortUI = pui->pfnAddPortUI;
288 pConfigurePortUI = pui->pfnConfigurePortUI;
289 pDeletePortUI = pui->pfnDeletePortUI;
293 /* find installed ports */
295 /* "FILE:" */
296 file_present = find_portinfo2(L"FILE:");
298 if (!pi_numports) /* Nothing to test without a port */
299 return;
301 id = 0;
302 /* "LPT1:" - "LPT9:" */
303 while (((lpt_present == NULL) || (lpt_absent == NULL)) && id < 9) {
304 id++;
305 sprintf(bufferA, "LPT%u:", id);
306 MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, ARRAY_SIZE(bufferW));
307 pi2 = find_portinfo2(bufferW);
308 if (pi2 && (lpt_present == NULL)) lpt_present = pi2;
309 if (!pi2 && (lpt_absent == NULL)) lpt_absent = strdupW(bufferW);
312 id = 0;
313 /* "COM1:" - "COM9:" */
314 while (((com_present == NULL) || (com_absent == NULL)) && id < 9) {
315 id++;
316 sprintf(bufferA, "COM%u:", id);
317 MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, ARRAY_SIZE(bufferW));
318 pi2 = find_portinfo2(bufferW);
319 if (pi2 && (com_present == NULL)) com_present = pi2;
320 if (!pi2 && (com_absent == NULL)) com_absent = strdupW(bufferW);
323 test_AddPortUI();
324 test_ConfigurePortUI();
326 /* cleanup */
327 HeapFree(GetProcessHeap(), 0, lpt_absent);
328 HeapFree(GetProcessHeap(), 0, com_absent);
329 HeapFree(GetProcessHeap(), 0, pi_buffer);