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
33 #include "ddk/winsplp.h"
35 #include "wine/test.h"
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
)
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");
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
);
77 pi
= (PORT_INFO_2W
*) pi_buffer
;
79 while (pi_numports
> res
) {
80 if (lstrcmpiW(pi
->pPortName
, pPort
) == 0) {
91 /* ########################### */
93 static LPCSTR
load_functions(void)
98 hdll
= LoadLibraryA(ptr
);
99 if (!hdll
) return ptr
;
101 ptr
= "InitializePrintMonitorUI";
102 pInitializePrintMonitorUI
= (VOID
*) GetProcAddress(hdll
, ptr
);
103 if (!pInitializePrintMonitorUI
) return ptr
;
108 /* ###########################
112 static LPWSTR
strdupW(LPCWSTR strW
)
116 ptr
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(strW
) + 1) * sizeof(WCHAR
));
123 /* ########################### */
125 static void test_AddPortUI(void)
130 /* not present before w2k */
132 skip("AddPortUI not found\n");
136 SetLastError(0xdeadbeef);
137 res
= pAddPortUI(NULL
, NULL
, NULL
, NULL
);
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
);
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
);
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);
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
);
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)
187 /* not present before w2k */
188 if (!pConfigurePortUI
) {
189 skip("ConfigurePortUI not found\n");
193 SetLastError(0xdeadbeef);
194 res
= pConfigurePortUI(NULL
, NULL
, NULL
);
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
"");
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");
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
);
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());
225 SetLastError(0xdeadbeef);
226 res
= pConfigurePortUI(NULL
, NULL
, lpt_absent
);
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
);
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());
243 SetLastError(0xdeadbeef);
244 res
= pConfigurePortUI(NULL
, NULL
, com_absent
);
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:");
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 /* ########################### */
273 /* localui.dll does not exist before w2k */
274 ptr
= load_functions();
276 skip("%s not found\n", ptr
);
280 pui
= pInitializePrintMonitorUI();
282 numentries
= (pui
->dwMonitorUISize
- sizeof(DWORD
)) / sizeof(VOID
*);
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 */
296 file_present
= find_portinfo2(L
"FILE:");
298 if (!pi_numports
) /* Nothing to test without a port */
302 /* "LPT1:" - "LPT9:" */
303 while (((lpt_present
== NULL
) || (lpt_absent
== NULL
)) && id
< 9) {
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
);
313 /* "COM1:" - "COM9:" */
314 while (((com_present
== NULL
) || (com_absent
== NULL
)) && id
< 9) {
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
);
324 test_ConfigurePortUI();
327 HeapFree(GetProcessHeap(), 0, lpt_absent
);
328 HeapFree(GetProcessHeap(), 0, com_absent
);
329 HeapFree(GetProcessHeap(), 0, pi_buffer
);