gdi32: PATH_ExtTextOut remove incorrect shift to DC origin.
[wine/hacks.git] / dlls / winspool.drv / tests / info.c
blob9a7acf66b48ff3f766c542c8bbe45e639a74a1db
1 /*
2 * Copyright (C) 2003, 2004 Stefan Leichter
3 * Copyright (C) 2005, 2006 Detlef Riekenberg
4 * Copyright (C) 2006 Dmitry Timoshkov
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 #include <stdarg.h>
22 #include <assert.h>
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "winuser.h"
33 #include "winreg.h"
34 #include "winspool.h"
35 #include "commdlg.h"
36 #include "wine/test.h"
38 #define MAGIC_DEAD 0xdeadbeef
39 #define DEFAULT_PRINTER_SIZE 1000
41 static CHAR does_not_exist_dll[]= "does_not_exist.dll";
42 static CHAR does_not_exist[] = "does_not_exist";
43 static CHAR empty[] = "";
44 static CHAR env_x64[] = "Windows x64";
45 static CHAR env_x86[] = "Windows NT x86";
46 static CHAR env_win9x_case[] = "windowS 4.0";
47 static CHAR illegal_name[] = "illegal,name";
48 static CHAR invalid_env[] = "invalid_env";
49 static CHAR LocalPortA[] = "Local Port";
50 static CHAR portname_com1[] = "COM1:";
51 static CHAR portname_file[] = "FILE:";
52 static CHAR portname_lpt1[] = "LPT1:";
53 static CHAR server_does_not_exist[] = "\\does_not_exist";
54 static CHAR version_dll[] = "version.dll";
55 static CHAR winetest[] = "winetest";
56 static CHAR xcv_localport[] = ",XcvMonitor Local Port";
58 static WCHAR cmd_MonitorUIW[] = {'M','o','n','i','t','o','r','U','I',0};
59 static WCHAR cmd_PortIsValidW[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
60 static WCHAR emptyW[] = {0};
62 static WCHAR portname_com1W[] = {'C','O','M','1',':',0};
63 static WCHAR portname_com2W[] = {'C','O','M','2',':',0};
64 static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
65 static WCHAR portname_lpt1W[] = {'L','P','T','1',':',0};
66 static WCHAR portname_lpt2W[] = {'L','P','T','2',':',0};
68 static HANDLE hwinspool;
69 static BOOL (WINAPI * pGetDefaultPrinterA)(LPSTR, LPDWORD);
70 static BOOL (WINAPI * pSetDefaultPrinterA)(LPCSTR);
71 static DWORD (WINAPI * pXcvDataW)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD, PDWORD);
72 static BOOL (WINAPI * pAddPortExA)(LPSTR, DWORD, LPBYTE, LPSTR);
75 /* ################################ */
77 struct monitor_entry {
78 LPSTR env;
79 CHAR dllname[32];
82 static LPSTR default_printer = NULL;
83 static LPSTR local_server = NULL;
84 static LPSTR tempdirA = NULL;
85 static LPSTR tempfileA = NULL;
86 static LPWSTR tempdirW = NULL;
87 static LPWSTR tempfileW = NULL;
89 /* ################################ */
90 /* report common behavior only once */
91 static DWORD deactivated_spooler_reported = 0;
92 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
93 if ((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
94 { \
95 if (!deactivated_spooler_reported) { \
96 deactivated_spooler_reported++; \
97 skip("The Service 'Spooler' is required for many test\n"); \
98 } \
99 return; \
102 static DWORD access_denied_reported = 0;
103 #define RETURN_ON_ACCESS_DENIED(res) \
104 if ((res == 0) && (GetLastError() == ERROR_ACCESS_DENIED)) \
106 if (!access_denied_reported) { \
107 access_denied_reported++; \
108 skip("More Access-Rights are required for many test\n"); \
110 return; \
113 /* ################################ */
115 static void find_default_printer(VOID)
117 static char buffer[DEFAULT_PRINTER_SIZE];
118 DWORD needed;
119 DWORD res;
120 LPSTR ptr;
122 if ((default_printer == NULL) && (pGetDefaultPrinterA))
124 /* w2k and above */
125 needed = sizeof(buffer);
126 res = pGetDefaultPrinterA(buffer, &needed);
127 if(res) default_printer = buffer;
128 trace("default_printer: '%s'\n", default_printer);
130 if (default_printer == NULL)
132 HKEY hwindows;
133 DWORD type;
134 /* NT 3.x and above */
135 if (RegOpenKeyEx(HKEY_CURRENT_USER,
136 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
137 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
139 needed = sizeof(buffer);
140 if (RegQueryValueEx(hwindows, "device", NULL,
141 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
143 ptr = strchr(buffer, ',');
144 if (ptr) {
145 ptr[0] = '\0';
146 default_printer = buffer;
149 RegCloseKey(hwindows);
151 trace("default_printer: '%s'\n", default_printer);
153 if (default_printer == NULL)
155 /* win9x */
156 needed = sizeof(buffer);
157 res = GetProfileStringA("windows", "device", "*", buffer, needed);
158 if(res) {
159 ptr = strchr(buffer, ',');
160 if (ptr) {
161 ptr[0] = '\0';
162 default_printer = buffer;
165 trace("default_printer: '%s'\n", default_printer);
170 static struct monitor_entry * find_installed_monitor(void)
172 MONITOR_INFO_2A mi2a;
173 static struct monitor_entry * entry = NULL;
174 DWORD num_tests;
175 DWORD i = 0;
177 static struct monitor_entry monitor_table[] = {
178 {env_win9x_case, "localspl.dll"},
179 {env_x86, "localspl.dll"},
180 {env_x64, "localspl.dll"},
181 {env_win9x_case, "localmon.dll"},
182 {env_x86, "localmon.dll"},
183 {env_win9x_case, "tcpmon.dll"},
184 {env_x86, "tcpmon.dll"},
185 {env_win9x_case, "usbmon.dll"},
186 {env_x86, "usbmon.dll"},
187 {env_win9x_case, "mspp32.dll"},
188 {env_x86, "win32spl.dll"},
189 {env_x86, "redmonnt.dll"},
190 {env_x86, "redmon35.dll"},
191 {env_win9x_case, "redmon95.dll"},
192 {env_x86, "pdfcmnnt.dll"},
193 {env_win9x_case, "pdfcmn95.dll"},
196 if (entry) return entry;
198 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
200 /* cleanup */
201 DeleteMonitorA(NULL, env_x64, winetest);
202 DeleteMonitorA(NULL, env_x86, winetest);
203 DeleteMonitorA(NULL, env_win9x_case, winetest);
205 /* find a usable monitor from the table */
206 mi2a.pName = winetest;
207 while ((entry == NULL) && (i < num_tests)) {
208 entry = &monitor_table[i];
209 i++;
210 mi2a.pEnvironment = entry->env;
211 mi2a.pDLLName = entry->dllname;
213 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
214 /* we got one */
215 trace("using '%s', '%s'\n", entry->env, entry->dllname);
216 DeleteMonitorA(NULL, entry->env, winetest);
218 else
220 entry = NULL;
223 return entry;
227 /* ########################### */
229 static void find_local_server(VOID)
231 static char buffer[MAX_PATH];
232 DWORD res;
233 DWORD size;
235 size = sizeof(buffer) - 3 ;
236 buffer[0] = '\\';
237 buffer[1] = '\\';
238 buffer[2] = '\0';
240 SetLastError(0xdeadbeef);
241 res = GetComputerNameA(&buffer[2], &size);
242 trace("returned %d with %d and %d: '%s'\n", res, GetLastError(), size, buffer);
244 ok( res != 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
245 res, GetLastError(), size, buffer);
247 if (res) local_server = buffer;
250 /* ########################### */
252 static void find_tempfile(VOID)
254 static CHAR buffer_dirA[MAX_PATH];
255 static CHAR buffer_fileA[MAX_PATH];
256 static WCHAR buffer_dirW[MAX_PATH];
257 static WCHAR buffer_fileW[MAX_PATH];
258 DWORD res;
259 int resint;
261 memset(buffer_dirA, 0, MAX_PATH - 1);
262 buffer_dirA[MAX_PATH - 1] = '\0';
263 SetLastError(0xdeadbeef);
264 res = GetTempPathA(MAX_PATH, buffer_dirA);
265 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
266 if (res == 0) return;
268 memset(buffer_fileA, 0, MAX_PATH - 1);
269 buffer_fileA[MAX_PATH - 1] = '\0';
270 SetLastError(0xdeadbeef);
271 res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
272 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
273 if (res == 0) return;
275 SetLastError(0xdeadbeef);
276 resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
277 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
278 if (resint == 0) return;
280 SetLastError(0xdeadbeef);
281 resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
282 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
283 if (resint == 0) return;
285 tempdirA = buffer_dirA;
286 tempfileA = buffer_fileA;
287 tempdirW = buffer_dirW;
288 tempfileW = buffer_fileW;
289 trace("tempfile: '%s'\n", tempfileA);
292 /* ########################### */
294 static void test_AddMonitor(void)
296 MONITOR_INFO_2A mi2a;
297 struct monitor_entry * entry = NULL;
298 DWORD res;
300 entry = find_installed_monitor();
302 SetLastError(MAGIC_DEAD);
303 res = AddMonitorA(NULL, 1, NULL);
304 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
305 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
306 res, GetLastError());
308 SetLastError(MAGIC_DEAD);
309 res = AddMonitorA(NULL, 3, NULL);
310 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
311 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
312 res, GetLastError());
314 if (0)
316 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
317 SetLastError(MAGIC_DEAD);
318 res = AddMonitorA(NULL, 2, NULL);
319 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
320 ok(!res &&
321 ((GetLastError() == MAGIC_DEAD) ||
322 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
323 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
324 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
327 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
328 SetLastError(MAGIC_DEAD);
329 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
330 RETURN_ON_DEACTIVATED_SPOOLER(res)
331 RETURN_ON_ACCESS_DENIED(res)
333 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
334 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
335 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
336 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
337 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
339 if (!entry) {
340 skip("No usable Monitor found\n");
341 return;
344 if (0)
346 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
347 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
348 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
349 is created on win9x and we do not want to hit this bug here. */
351 mi2a.pEnvironment = entry->env;
352 SetLastError(MAGIC_DEAD);
353 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
357 mi2a.pEnvironment = entry->env;
358 mi2a.pName = empty;
359 SetLastError(MAGIC_DEAD);
360 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
361 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
362 ok( !res &&
363 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
364 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
365 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
366 "ERROR_PRIVILEGE_NOT_HELD)\n",
367 res, GetLastError());
369 mi2a.pName = winetest;
370 SetLastError(MAGIC_DEAD);
371 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
372 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
373 ok( !res &&
374 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
375 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
376 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
377 "ERROR_PRIVILEGE_NOT_HELD)\n",
378 res, GetLastError());
380 mi2a.pDLLName = empty;
381 SetLastError(MAGIC_DEAD);
382 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
383 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
384 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
385 res, GetLastError());
387 mi2a.pDLLName = does_not_exist_dll;
388 SetLastError(MAGIC_DEAD);
389 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
390 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
391 ok( !res &&
392 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
393 (GetLastError() == ERROR_INVALID_PARAMETER)),
394 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
395 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
397 mi2a.pDLLName = version_dll;
398 SetLastError(MAGIC_DEAD);
399 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
400 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
401 ok( !res &&
402 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
403 (GetLastError() == ERROR_INVALID_PARAMETER)),
404 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
405 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
406 if (res) DeleteMonitorA(NULL, entry->env, winetest);
408 /* Test AddMonitor with real options */
409 mi2a.pDLLName = entry->dllname;
410 SetLastError(MAGIC_DEAD);
411 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
412 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
414 /* add a monitor twice */
415 SetLastError(MAGIC_DEAD);
416 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
417 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
418 ok( !res &&
419 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
420 (GetLastError() == ERROR_ALREADY_EXISTS)),
421 "returned %d with %d (expected '0' with: "
422 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
423 res, GetLastError());
425 DeleteMonitorA(NULL, entry->env, winetest);
426 SetLastError(MAGIC_DEAD);
427 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
428 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
430 /* cleanup */
431 DeleteMonitorA(NULL, entry->env, winetest);
435 /* ########################### */
437 static void test_AddPort(void)
439 DWORD res;
441 SetLastError(0xdeadbeef);
442 res = AddPortA(NULL, 0, NULL);
443 RETURN_ON_DEACTIVATED_SPOOLER(res)
444 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
445 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
446 (GetLastError() == ERROR_INVALID_PARAMETER)),
447 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
448 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
451 SetLastError(0xdeadbeef);
452 res = AddPortA(NULL, 0, empty);
453 /* Allowed only for (Printer-)Administrators */
454 RETURN_ON_ACCESS_DENIED(res)
456 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
457 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
458 (GetLastError() == ERROR_INVALID_PARAMETER)),
459 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
460 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
463 SetLastError(0xdeadbeef);
464 res = AddPortA(NULL, 0, does_not_exist);
465 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
466 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
467 (GetLastError() == ERROR_INVALID_PARAMETER)),
468 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
469 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
473 /* ########################### */
475 static void test_AddPortEx(void)
477 PORT_INFO_2A pi;
478 DWORD res;
481 if (!pAddPortExA) {
482 win_skip("AddPortEx not supported\n");
483 return;
486 /* start test with a clean system */
487 DeletePortA(NULL, 0, tempfileA);
489 pi.pPortName = tempfileA;
490 SetLastError(0xdeadbeef);
491 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
492 RETURN_ON_DEACTIVATED_SPOOLER(res)
494 /* Allowed only for (Printer-)Administrators.
495 W2K+XP: ERROR_INVALID_PARAMETER */
496 if (!res && (GetLastError() == ERROR_INVALID_PARAMETER)) {
497 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
498 return;
500 ok( res, "got %u with %u (expected '!= 0')\n", res, GetLastError());
502 /* Add a port, that already exist */
503 SetLastError(0xdeadbeef);
504 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
505 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
506 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
507 res, GetLastError());
508 DeletePortA(NULL, 0, tempfileA);
511 /* the Monitorname must match */
512 SetLastError(0xdeadbeef);
513 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, NULL);
514 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
515 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
516 res, GetLastError());
517 if (res) DeletePortA(NULL, 0, tempfileA);
519 SetLastError(0xdeadbeef);
520 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, empty);
521 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
522 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
523 res, GetLastError());
524 if (res) DeletePortA(NULL, 0, tempfileA);
526 SetLastError(0xdeadbeef);
527 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, does_not_exist);
528 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
529 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
530 res, GetLastError());
531 if (res) DeletePortA(NULL, 0, tempfileA);
534 /* We need a Portname */
535 SetLastError(0xdeadbeef);
536 res = pAddPortExA(NULL, 1, NULL, LocalPortA);
537 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
538 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
539 res, GetLastError());
541 pi.pPortName = NULL;
542 SetLastError(0xdeadbeef);
543 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
544 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
545 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
546 res, GetLastError());
547 if (res) DeletePortA(NULL, 0, tempfileA);
550 /* level 2 is documented as supported for Printmonitors,
551 but that is not supported for "Local Port" (localspl.dll) and
552 AddPortEx fails with ERROR_INVALID_LEVEL */
554 pi.pPortName = tempfileA;
555 pi.pMonitorName = LocalPortA;
556 pi.pDescription = winetest;
557 pi.fPortType = PORT_TYPE_WRITE;
559 SetLastError(0xdeadbeef);
560 res = pAddPortExA(NULL, 2, (LPBYTE) &pi, LocalPortA);
561 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
562 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
563 res, GetLastError());
564 if (res) DeletePortA(NULL, 0, tempfileA);
567 /* invalid levels */
568 SetLastError(0xdeadbeef);
569 res = pAddPortExA(NULL, 0, (LPBYTE) &pi, LocalPortA);
570 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
571 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
572 res, GetLastError());
574 SetLastError(0xdeadbeef);
575 res = pAddPortExA(NULL, 3, (LPBYTE) &pi, LocalPortA);
576 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
577 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
578 res, GetLastError());
581 /* cleanup */
582 DeletePortA(NULL, 0, tempfileA);
586 /* ########################### */
588 static void test_ConfigurePort(void)
590 DWORD res;
593 SetLastError(0xdeadbeef);
594 res = ConfigurePortA(NULL, 0, NULL);
595 RETURN_ON_DEACTIVATED_SPOOLER(res)
596 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
597 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
598 (GetLastError() == ERROR_INVALID_PARAMETER)),
599 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
600 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
602 SetLastError(0xdeadbeef);
603 res = ConfigurePortA(NULL, 0, empty);
604 /* Allowed only for (Printer-)Administrators */
605 RETURN_ON_ACCESS_DENIED(res)
607 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
608 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
609 (GetLastError() == ERROR_INVALID_PARAMETER)),
610 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
611 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
614 SetLastError(0xdeadbeef);
615 res = ConfigurePortA(NULL, 0, does_not_exist);
616 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
617 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
618 (GetLastError() == ERROR_INVALID_PARAMETER)),
619 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
620 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
623 /* Testing-Results:
624 - Case of Portnames is ignored
625 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
626 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
628 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
629 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
630 - Cancel ("Local Port") => ERROR_CANCELED
631 - Cancel ("Redirected Port") => Success
633 if (winetest_interactive > 0) {
634 SetLastError(0xdeadbeef);
635 res = ConfigurePortA(NULL, 0, portname_com1);
636 trace("'%s' returned %d with %d\n", portname_com1, res, GetLastError());
638 SetLastError(0xdeadbeef);
639 res = ConfigurePortA(NULL, 0, portname_lpt1);
640 trace("'%s' returned %d with %d\n", portname_lpt1, res, GetLastError());
642 SetLastError(0xdeadbeef);
643 res = ConfigurePortA(NULL, 0, portname_file);
644 trace("'%s' returned %d with %d\n", portname_file, res, GetLastError());
648 /* ########################### */
650 static void test_DeleteMonitor(void)
652 MONITOR_INFO_2A mi2a;
653 struct monitor_entry * entry = NULL;
654 DWORD res;
657 entry = find_installed_monitor();
659 if (!entry) {
660 skip("No usable Monitor found\n");
661 return;
664 mi2a.pName = winetest;
665 mi2a.pEnvironment = entry->env;
666 mi2a.pDLLName = entry->dllname;
668 /* Testing DeleteMonitor with real options */
669 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
671 SetLastError(MAGIC_DEAD);
672 res = DeleteMonitorA(NULL, entry->env, winetest);
673 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
675 /* Delete the Monitor twice */
676 SetLastError(MAGIC_DEAD);
677 res = DeleteMonitorA(NULL, entry->env, winetest);
678 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
679 ok( !res &&
680 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
681 (GetLastError() == ERROR_INVALID_PARAMETER)),
682 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
683 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
685 /* the environment */
686 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
687 SetLastError(MAGIC_DEAD);
688 res = DeleteMonitorA(NULL, NULL, winetest);
689 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
691 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
692 SetLastError(MAGIC_DEAD);
693 res = DeleteMonitorA(NULL, empty, winetest);
694 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
696 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
697 SetLastError(MAGIC_DEAD);
698 res = DeleteMonitorA(NULL, invalid_env, winetest);
699 ok( res ||
700 (!res && GetLastError() == ERROR_INVALID_ENVIRONMENT) /* Vista/W2K8 */,
701 "returned %d with %d\n", res, GetLastError());
703 /* the monitor-name */
704 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
705 SetLastError(MAGIC_DEAD);
706 res = DeleteMonitorA(NULL, entry->env, NULL);
707 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
708 ok( !res &&
709 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
710 (GetLastError() == ERROR_INVALID_NAME)),
711 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
712 "ERROR_INVALID_NAME)\n", res, GetLastError());
714 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
715 SetLastError(MAGIC_DEAD);
716 res = DeleteMonitorA(NULL, entry->env, empty);
717 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
718 ok( !res &&
719 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
720 (GetLastError() == ERROR_INVALID_NAME)),
721 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
722 "ERROR_INVALID_NAME)\n", res, GetLastError());
724 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
725 SetLastError(MAGIC_DEAD);
726 res = DeleteMonitorA(empty, entry->env, winetest);
727 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
729 /* cleanup */
730 DeleteMonitorA(NULL, entry->env, winetest);
733 /* ########################### */
735 static void test_DeletePort(void)
737 DWORD res;
739 SetLastError(0xdeadbeef);
740 res = DeletePortA(NULL, 0, NULL);
741 RETURN_ON_DEACTIVATED_SPOOLER(res)
743 SetLastError(0xdeadbeef);
744 res = DeletePortA(NULL, 0, empty);
745 /* Allowed only for (Printer-)Administrators */
746 RETURN_ON_ACCESS_DENIED(res)
748 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
749 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
750 (GetLastError() == ERROR_INVALID_PARAMETER)),
751 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
752 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
755 SetLastError(0xdeadbeef);
756 res = DeletePortA(NULL, 0, does_not_exist);
757 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
758 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
759 (GetLastError() == ERROR_INVALID_PARAMETER)),
760 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
761 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
765 /* ########################### */
767 static void test_EnumForms(LPSTR pName)
769 DWORD res;
770 HANDLE hprinter = 0;
771 LPBYTE buffer;
772 DWORD cbBuf;
773 DWORD pcbNeeded;
774 DWORD pcReturned;
775 DWORD level;
776 UINT i;
777 const char *formtype;
778 static const char * const formtypes[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
779 #define FORMTYPE_MAX 2
780 PFORM_INFO_1A pFI_1a;
781 PFORM_INFO_2A pFI_2a;
783 res = OpenPrinter(pName, &hprinter, NULL);
784 RETURN_ON_DEACTIVATED_SPOOLER(res)
785 if (!res || !hprinter)
787 /* Open the local Prinserver is not supported on win9x */
788 if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
789 return;
792 /* valid levels are 1 and 2 */
793 for(level = 0; level < 4; level++) {
794 cbBuf = 0xdeadbeef;
795 pcReturned = 0xdeadbeef;
796 SetLastError(0xdeadbeef);
797 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
799 /* EnumForms is not implemented in win9x */
800 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
802 /* EnumForms for the Server not implemented on all NT-Versions */
803 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
805 /* Level 2 for EnumForms is not supported on all systems */
806 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
808 /* use only a short test, when we test with an invalid level */
809 if(!level || (level > 2)) {
810 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
811 (res && (pcReturned == 0)),
812 "(%d) returned %d with %d and 0x%08x (expected '0' with "
813 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
814 level, res, GetLastError(), pcReturned);
815 continue;
818 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
819 "(%d) returned %d with %d (expected '0' with "
820 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
822 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
823 if (buffer == NULL) continue;
825 SetLastError(0xdeadbeef);
826 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
827 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
828 level, res, GetLastError());
830 if (winetest_debug > 1) {
831 trace("dumping %d forms level %d\n", pcReturned, level);
832 pFI_1a = (PFORM_INFO_1A)buffer;
833 pFI_2a = (PFORM_INFO_2A)buffer;
834 for (i = 0; i < pcReturned; i++)
836 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
837 formtype = (pFI_1a->Flags <= FORMTYPE_MAX) ? formtypes[pFI_1a->Flags] : formtypes[3];
838 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i, pFI_1a->pName,
839 (float)pFI_1a->Size.cx/1000, (float)pFI_1a->Size.cy/1000, formtype);
841 if (level == 1) pFI_1a ++;
842 else {
843 /* output additional FORM_INFO_2 fields */
844 trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
845 pFI_2a->pKeyword, pFI_2a->StringType, pFI_2a->pMuiDll,
846 pFI_2a->dwResourceId, pFI_2a->pDisplayName, pFI_2a->wLangId);
848 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
849 pFI_2a ++;
850 pFI_1a = (PFORM_INFO_1A)pFI_2a;
855 SetLastError(0xdeadbeef);
856 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
857 ok( res, "(%d) returned %d with %d (expected '!=0')\n",
858 level, res, GetLastError());
860 SetLastError(0xdeadbeef);
861 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
862 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
863 "(%d) returned %d with %d (expected '0' with "
864 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
867 SetLastError(0xdeadbeef);
868 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
869 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
870 "(%d) returned %d with %d (expected '0' with "
871 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
874 SetLastError(0xdeadbeef);
875 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
876 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
877 "(%d) returned %d with %d (expected '0' with "
878 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
880 SetLastError(0xdeadbeef);
881 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
882 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
883 "(%d) returned %d with %d (expected '0' with "
884 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
886 SetLastError(0xdeadbeef);
887 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
888 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
889 "(%d) returned %d with %d (expected '0' with "
890 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
892 HeapFree(GetProcessHeap(), 0, buffer);
893 } /* for(level ... */
895 ClosePrinter(hprinter);
898 /* ########################### */
900 static void test_EnumMonitors(void)
902 DWORD res;
903 LPBYTE buffer;
904 DWORD cbBuf;
905 DWORD pcbNeeded;
906 DWORD pcReturned;
907 DWORD level;
909 /* valid levels are 1 and 2 */
910 for(level = 0; level < 4; level++) {
911 cbBuf = MAGIC_DEAD;
912 pcReturned = MAGIC_DEAD;
913 SetLastError(MAGIC_DEAD);
914 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
916 RETURN_ON_DEACTIVATED_SPOOLER(res)
918 /* not implemented yet in wine */
919 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
922 /* use only a short test, when we test with an invalid level */
923 if(!level || (level > 2)) {
924 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
925 (res && (pcReturned == 0)),
926 "(%d) returned %d with %d and 0x%08x (expected '0' with "
927 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
928 level, res, GetLastError(), pcReturned);
929 continue;
932 /* Level 2 is not supported on win9x */
933 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
934 skip("Level %d not supported\n", level);
935 continue;
938 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
939 "(%d) returned %d with %d (expected '0' with "
940 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
942 if (!cbBuf) {
943 skip("no valid buffer size returned\n");
944 continue;
947 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
948 if (buffer == NULL) continue;
950 SetLastError(MAGIC_DEAD);
951 pcbNeeded = MAGIC_DEAD;
952 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
953 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
954 level, res, GetLastError());
955 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n",
956 level, pcbNeeded, cbBuf);
957 /* We can validate the returned Data with the Registry here */
960 SetLastError(MAGIC_DEAD);
961 pcReturned = MAGIC_DEAD;
962 pcbNeeded = MAGIC_DEAD;
963 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
964 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level,
965 res, GetLastError());
966 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
967 pcbNeeded, cbBuf);
969 SetLastError(MAGIC_DEAD);
970 pcbNeeded = MAGIC_DEAD;
971 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
972 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
973 "(%d) returned %d with %d (expected '0' with "
974 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
976 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
977 pcbNeeded, cbBuf);
980 Do not add the next test:
981 w2k+: RPC_X_NULL_REF_POINTER
982 NT3.5: ERROR_INVALID_USER_BUFFER
983 win9x: crash in winspool.drv
985 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
988 SetLastError(MAGIC_DEAD);
989 pcbNeeded = MAGIC_DEAD;
990 pcReturned = MAGIC_DEAD;
991 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
992 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
993 "(%d) returned %d with %d (expected '!=0' or '0' with "
994 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
996 pcbNeeded = MAGIC_DEAD;
997 pcReturned = MAGIC_DEAD;
998 SetLastError(MAGIC_DEAD);
999 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1000 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1001 "(%d) returned %d with %d (expected '!=0' or '0' with "
1002 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1004 HeapFree(GetProcessHeap(), 0, buffer);
1005 } /* for(level ... */
1008 /* ########################### */
1010 static void test_EnumPorts(void)
1012 DWORD res;
1013 DWORD level;
1014 LPBYTE buffer;
1015 DWORD cbBuf;
1016 DWORD pcbNeeded;
1017 DWORD pcReturned;
1019 /* valid levels are 1 and 2 */
1020 for(level = 0; level < 4; level++) {
1022 cbBuf = 0xdeadbeef;
1023 pcReturned = 0xdeadbeef;
1024 SetLastError(0xdeadbeef);
1025 res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
1026 RETURN_ON_DEACTIVATED_SPOOLER(res)
1028 /* use only a short test, when we test with an invalid level */
1029 if(!level || (level > 2)) {
1030 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1031 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1032 (res && (pcReturned == 0)),
1033 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1034 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1035 level, res, GetLastError(), pcReturned);
1036 continue;
1040 /* Level 2 is not supported on NT 3.x */
1041 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1042 skip("Level %d not supported\n", level);
1043 continue;
1046 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1047 "(%d) returned %d with %d (expected '0' with "
1048 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1050 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1051 if (buffer == NULL) continue;
1053 pcbNeeded = 0xdeadbeef;
1054 SetLastError(0xdeadbeef);
1055 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1056 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1057 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1058 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1060 pcbNeeded = 0xdeadbeef;
1061 pcReturned = 0xdeadbeef;
1062 SetLastError(0xdeadbeef);
1063 res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1064 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1065 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1067 pcbNeeded = 0xdeadbeef;
1068 SetLastError(0xdeadbeef);
1069 res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1070 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1071 "(%d) returned %d with %d (expected '0' with "
1072 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1073 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1076 Do not add this test:
1077 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1078 w2k+: RPC_X_NULL_REF_POINTER
1079 NT3.5: ERROR_INVALID_USER_BUFFER
1080 win9x: crash in winspool.drv
1083 SetLastError(0xdeadbeef);
1084 res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1085 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1086 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1087 ( res && (GetLastError() == ERROR_SUCCESS) ),
1088 "(%d) returned %d with %d (expected '0' with "
1089 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1090 level, res, GetLastError());
1093 SetLastError(0xdeadbeef);
1094 res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1095 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1096 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1097 ( res && (GetLastError() == ERROR_SUCCESS) ),
1098 "(%d) returned %d with %d (expected '0' with "
1099 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1100 level, res, GetLastError());
1102 HeapFree(GetProcessHeap(), 0, buffer);
1106 /* ########################### */
1108 static void test_EnumPrinterDrivers(void)
1110 static char env_all[] = "all";
1112 DWORD res;
1113 LPBYTE buffer;
1114 DWORD cbBuf;
1115 DWORD pcbNeeded;
1116 DWORD pcReturned;
1117 DWORD level;
1119 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1120 for(level = 0; level < 10; level++) {
1121 cbBuf = 0xdeadbeef;
1122 pcReturned = 0xdeadbeef;
1123 SetLastError(0xdeadbeef);
1124 res = EnumPrinterDriversA(NULL, NULL, level, NULL, 0, &cbBuf, &pcReturned);
1125 RETURN_ON_DEACTIVATED_SPOOLER(res)
1127 /* use only a short test, when we test with an invalid level */
1128 if(!level || (level == 7) || (level > 8)) {
1130 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1131 (res && (pcReturned == 0)),
1132 "(%d) got %u with %u and 0x%x "
1133 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1134 level, res, GetLastError(), pcReturned);
1135 continue;
1138 /* some level are not supported in all windows versions */
1139 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1140 skip("Level %d not supported\n", level);
1141 continue;
1144 ok( ((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ||
1145 (res && (default_printer == NULL)),
1146 "(%u) got %u with %u for %s (expected '0' with "
1147 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1148 level, res, GetLastError(), default_printer);
1150 if (!cbBuf) {
1151 skip("no valid buffer size returned\n");
1152 continue;
1155 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1156 if (buffer == NULL) continue;
1158 SetLastError(0xdeadbeef);
1159 pcbNeeded = 0xdeadbeef;
1160 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1161 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1162 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1164 /* validate the returned Data here */
1165 if (level > 1) {
1166 LPDRIVER_INFO_2A di = (LPDRIVER_INFO_2A) buffer;
1168 ok( strrchr(di->pDriverPath, '\\') != NULL,
1169 "(%u) got %s for %s (expected a full path)\n",
1170 level, di->pDriverPath, di->pName);
1174 SetLastError(0xdeadbeef);
1175 pcReturned = 0xdeadbeef;
1176 pcbNeeded = 0xdeadbeef;
1177 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1178 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1179 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1181 SetLastError(0xdeadbeef);
1182 pcbNeeded = 0xdeadbeef;
1183 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1184 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1185 "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1186 level, res, GetLastError());
1187 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1190 Do not add the next test:
1191 NT: ERROR_INVALID_USER_BUFFER
1192 win9x: crash or 100% CPU
1194 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1197 SetLastError(0xdeadbeef);
1198 pcbNeeded = 0xdeadbeef;
1199 pcReturned = 0xdeadbeef;
1200 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, NULL, &pcReturned);
1201 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1202 "(%u) got %u with %u (expected '!=0' or '0' with "
1203 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1205 pcbNeeded = 0xdeadbeef;
1206 pcReturned = 0xdeadbeef;
1207 SetLastError(0xdeadbeef);
1208 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1209 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1210 "(%u) got %u with %u (expected '!=0' or '0' with "
1211 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1213 HeapFree(GetProcessHeap(), 0, buffer);
1214 } /* for(level ... */
1216 pcbNeeded = 0;
1217 pcReturned = 0;
1218 SetLastError(0xdeadbeef);
1219 res = EnumPrinterDriversA(NULL, env_all, 1, NULL, 0, &pcbNeeded, &pcReturned);
1220 if (res)
1222 skip("no printer drivers found\n");
1223 return;
1225 if (GetLastError() == ERROR_INVALID_ENVIRONMENT)
1227 win_skip("NT4 and below don't support the 'all' environment value\n");
1228 return;
1230 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "unexpected error %u\n", GetLastError());
1232 buffer = HeapAlloc(GetProcessHeap(), 0, pcbNeeded);
1233 res = EnumPrinterDriversA(NULL, env_all, 1, buffer, pcbNeeded, &pcbNeeded, &pcReturned);
1234 ok(res, "EnumPrinterDriversA failed %u\n", GetLastError());
1236 HeapFree(GetProcessHeap(), 0, buffer);
1239 /* ########################### */
1241 static void test_GetDefaultPrinter(void)
1243 BOOL retval;
1244 DWORD exact = DEFAULT_PRINTER_SIZE;
1245 DWORD size;
1246 char buffer[DEFAULT_PRINTER_SIZE];
1248 if (!pGetDefaultPrinterA) return;
1249 /* only supported on NT like OSes starting with win2k */
1251 SetLastError(ERROR_SUCCESS);
1252 retval = pGetDefaultPrinterA(buffer, &exact);
1253 if (!retval || !exact || !strlen(buffer) ||
1254 (ERROR_SUCCESS != GetLastError())) {
1255 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
1256 (ERROR_INVALID_NAME == GetLastError()))
1257 trace("this test requires a default printer to be set\n");
1258 else {
1259 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1260 "function returned %s\n"
1261 "last error 0x%08x\n"
1262 "returned buffer size 0x%08x\n"
1263 "returned buffer content %s\n",
1264 retval ? "true" : "false", GetLastError(), exact, buffer);
1266 return;
1268 SetLastError(ERROR_SUCCESS);
1269 retval = pGetDefaultPrinterA(NULL, NULL);
1270 ok( !retval, "function result wrong! False expected\n");
1271 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1272 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1273 GetLastError());
1275 SetLastError(ERROR_SUCCESS);
1276 retval = pGetDefaultPrinterA(buffer, NULL);
1277 ok( !retval, "function result wrong! False expected\n");
1278 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1279 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1280 GetLastError());
1282 SetLastError(ERROR_SUCCESS);
1283 size = 0;
1284 retval = pGetDefaultPrinterA(NULL, &size);
1285 ok( !retval, "function result wrong! False expected\n");
1286 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1287 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1288 GetLastError());
1289 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1290 exact, size);
1292 SetLastError(ERROR_SUCCESS);
1293 size = DEFAULT_PRINTER_SIZE;
1294 retval = pGetDefaultPrinterA(NULL, &size);
1295 ok( !retval, "function result wrong! False expected\n");
1296 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1297 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1298 GetLastError());
1299 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1300 exact, size);
1302 size = 0;
1303 retval = pGetDefaultPrinterA(buffer, &size);
1304 ok( !retval, "function result wrong! False expected\n");
1305 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1306 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1307 GetLastError());
1308 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1309 exact, size);
1311 size = exact;
1312 retval = pGetDefaultPrinterA(buffer, &size);
1313 ok( retval, "function result wrong! True expected\n");
1314 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1315 exact, size);
1318 static void test_GetPrinterDriverDirectory(void)
1320 LPBYTE buffer = NULL;
1321 DWORD cbBuf = 0, pcbNeeded = 0;
1322 BOOL res;
1325 SetLastError(MAGIC_DEAD);
1326 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1327 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1328 res, GetLastError(), cbBuf);
1330 RETURN_ON_DEACTIVATED_SPOOLER(res)
1331 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1332 "returned %d with lasterror=%d (expected '0' with "
1333 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1335 if (!cbBuf) {
1336 skip("no valid buffer size returned\n");
1337 return;
1340 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1341 if (buffer == NULL) return ;
1343 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1344 ok( res, "expected result != 0, got %d\n", res);
1345 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1346 pcbNeeded, cbBuf);
1348 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1349 ok( res, "expected result != 0, got %d\n", res);
1350 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1351 pcbNeeded, cbBuf);
1353 SetLastError(MAGIC_DEAD);
1354 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1355 ok( !res , "expected result == 0, got %d\n", res);
1356 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1357 pcbNeeded, cbBuf);
1359 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1360 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1361 GetLastError());
1364 Do not add the next test:
1365 XPsp2: crash in this app, when the spooler is not running
1366 NT3.5: ERROR_INVALID_USER_BUFFER
1367 win9x: ERROR_INVALID_PARAMETER
1369 pcbNeeded = MAGIC_DEAD;
1370 SetLastError(MAGIC_DEAD);
1371 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1374 SetLastError(MAGIC_DEAD);
1375 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1376 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
1377 "expected either result == 0 and "
1378 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1379 "got result %d and last error == %d\n", res, GetLastError());
1381 SetLastError(MAGIC_DEAD);
1382 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1383 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1384 "returned %d with %d (expected '!=0' or '0' with "
1385 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1388 /* with a valid buffer, but level is too large */
1389 buffer[0] = '\0';
1390 SetLastError(MAGIC_DEAD);
1391 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1393 /* Level not checked in win9x and wine:*/
1394 if((res != FALSE) && buffer[0])
1396 trace("Level '2' not checked '%s'\n", buffer);
1398 else
1400 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1401 "returned %d with lasterror=%d (expected '0' with "
1402 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1405 /* printing environments are case insensitive */
1406 /* "Windows 4.0" is valid for win9x and NT */
1407 buffer[0] = '\0';
1408 SetLastError(MAGIC_DEAD);
1409 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1410 buffer, cbBuf*2, &pcbNeeded);
1412 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1413 cbBuf = pcbNeeded;
1414 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1415 if (buffer == NULL) return ;
1417 SetLastError(MAGIC_DEAD);
1418 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1419 buffer, cbBuf*2, &pcbNeeded);
1422 ok(res && buffer[0], "returned %d with "
1423 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1424 res, GetLastError(), lstrlenA((char *)buffer));
1426 buffer[0] = '\0';
1427 SetLastError(MAGIC_DEAD);
1428 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1429 buffer, cbBuf*2, &pcbNeeded);
1431 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1432 cbBuf = pcbNeeded;
1433 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1434 if (buffer == NULL) return ;
1436 buffer[0] = '\0';
1437 SetLastError(MAGIC_DEAD);
1438 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1439 buffer, cbBuf*2, &pcbNeeded);
1442 /* "Windows NT x86" is invalid for win9x */
1443 ok( (res && buffer[0]) ||
1444 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
1445 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1446 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1447 res, GetLastError(), lstrlenA((char *)buffer));
1449 /* A setup program (PDFCreator_0.8.0) use empty strings */
1450 SetLastError(MAGIC_DEAD);
1451 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1452 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1454 SetLastError(MAGIC_DEAD);
1455 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1456 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1458 SetLastError(MAGIC_DEAD);
1459 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1460 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1462 HeapFree( GetProcessHeap(), 0, buffer);
1465 /* ##### */
1467 static void test_GetPrintProcessorDirectory(void)
1469 LPBYTE buffer = NULL;
1470 DWORD cbBuf = 0;
1471 DWORD pcbNeeded = 0;
1472 BOOL res;
1475 SetLastError(0xdeadbeef);
1476 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1477 /* The deactivated Spooler is caught here on NT3.51 */
1478 RETURN_ON_DEACTIVATED_SPOOLER(res)
1479 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1480 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1481 res, GetLastError());
1483 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1484 if(buffer == NULL) return;
1486 buffer[0] = '\0';
1487 SetLastError(0xdeadbeef);
1488 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1489 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1491 SetLastError(0xdeadbeef);
1492 buffer[0] = '\0';
1493 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1494 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1496 /* Buffer to small */
1497 buffer[0] = '\0';
1498 SetLastError(0xdeadbeef);
1499 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1500 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1501 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1502 res, GetLastError());
1504 if (0)
1506 /* XPsp2: the program will crash here, when the spooler is not running */
1507 /* GetPrinterDriverDirectory has the same bug */
1508 pcbNeeded = 0;
1509 SetLastError(0xdeadbeef);
1510 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1513 buffer[0] = '\0';
1514 SetLastError(0xdeadbeef);
1515 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1516 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1517 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1518 "returned %d with %d (expected '!= 0' or '0' with "
1519 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1522 buffer[0] = '\0';
1523 SetLastError(0xdeadbeef);
1524 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1525 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1526 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1527 "returned %d with %d (expected '!= 0' or '0' with "
1528 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1531 /* with a valid buffer, but level is invalid */
1532 buffer[0] = '\0';
1533 SetLastError(0xdeadbeef);
1534 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1535 if (res && buffer[0])
1537 /* Level is ignored in win9x*/
1538 trace("invalid level (2) was ignored\n");
1540 else
1542 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1543 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1544 res, GetLastError());
1547 /* Empty environment is the same as the default environment */
1548 buffer[0] = '\0';
1549 SetLastError(0xdeadbeef);
1550 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1551 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1553 /* "Windows 4.0" is valid for win9x and NT */
1554 buffer[0] = '\0';
1555 SetLastError(0xdeadbeef);
1556 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1557 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1560 /* "Windows NT x86" is invalid for win9x */
1561 buffer[0] = '\0';
1562 SetLastError(0xdeadbeef);
1563 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1564 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1565 "returned %d with %d (expected '!= 0' or '0' with "
1566 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1568 /* invalid on all Systems */
1569 buffer[0] = '\0';
1570 SetLastError(0xdeadbeef);
1571 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1572 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1573 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1574 res, GetLastError());
1576 /* Empty servername is the same as the local computer */
1577 buffer[0] = '\0';
1578 SetLastError(0xdeadbeef);
1579 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1580 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1582 /* invalid on all Systems */
1583 buffer[0] = '\0';
1584 SetLastError(0xdeadbeef);
1585 res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1586 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
1587 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1588 res, GetLastError());
1590 HeapFree(GetProcessHeap(), 0, buffer);
1593 /* ##### */
1595 static void test_OpenPrinter(void)
1597 PRINTER_DEFAULTSA defaults;
1598 HANDLE hprinter;
1599 DWORD res;
1601 SetLastError(MAGIC_DEAD);
1602 res = OpenPrinter(NULL, NULL, NULL);
1603 /* The deactivated Spooler is caught here on NT3.51 */
1604 RETURN_ON_DEACTIVATED_SPOOLER(res)
1605 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1606 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1607 res, GetLastError());
1610 /* Get Handle for the local Printserver (NT only)*/
1611 hprinter = (HANDLE) MAGIC_DEAD;
1612 SetLastError(MAGIC_DEAD);
1613 res = OpenPrinter(NULL, &hprinter, NULL);
1614 /* The deactivated Spooler is caught here on XPsp2 */
1615 RETURN_ON_DEACTIVATED_SPOOLER(res)
1616 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1617 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1618 res, GetLastError());
1619 if(res) {
1620 ClosePrinter(hprinter);
1622 defaults.pDatatype=NULL;
1623 defaults.pDevMode=NULL;
1625 defaults.DesiredAccess=0;
1626 hprinter = (HANDLE) MAGIC_DEAD;
1627 SetLastError(MAGIC_DEAD);
1628 res = OpenPrinter(NULL, &hprinter, &defaults);
1629 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1630 if (res) ClosePrinter(hprinter);
1632 defaults.DesiredAccess=-1;
1633 hprinter = (HANDLE) MAGIC_DEAD;
1634 SetLastError(MAGIC_DEAD);
1635 res = OpenPrinter(NULL, &hprinter, &defaults);
1636 todo_wine {
1637 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1638 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1639 res, GetLastError());
1641 if (res) ClosePrinter(hprinter);
1646 if (local_server != NULL) {
1647 hprinter = (HANDLE) 0xdeadbeef;
1648 SetLastError(0xdeadbeef);
1649 res = OpenPrinter(local_server, &hprinter, NULL);
1650 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1651 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1652 res, GetLastError());
1653 if(res) ClosePrinter(hprinter);
1656 /* Invalid Printername */
1657 hprinter = (HANDLE) MAGIC_DEAD;
1658 SetLastError(MAGIC_DEAD);
1659 res = OpenPrinter(illegal_name, &hprinter, NULL);
1660 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1661 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1662 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1663 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1664 if(res) ClosePrinter(hprinter);
1666 hprinter = (HANDLE) MAGIC_DEAD;
1667 SetLastError(MAGIC_DEAD);
1668 res = OpenPrinter(empty, &hprinter, NULL);
1669 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1670 ok( !res &&
1671 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1672 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1673 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1674 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1675 if(res) ClosePrinter(hprinter);
1678 /* Get Handle for the default Printer */
1679 if (default_printer)
1681 hprinter = (HANDLE) MAGIC_DEAD;
1682 SetLastError(MAGIC_DEAD);
1683 res = OpenPrinter(default_printer, &hprinter, NULL);
1684 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1686 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1687 return;
1689 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1690 if(res) ClosePrinter(hprinter);
1692 SetLastError(MAGIC_DEAD);
1693 res = OpenPrinter(default_printer, NULL, NULL);
1694 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1695 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1696 "returned %d with %d (expected '!=0' or '0' with "
1697 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1699 defaults.pDatatype=NULL;
1700 defaults.pDevMode=NULL;
1701 defaults.DesiredAccess=0;
1703 hprinter = (HANDLE) MAGIC_DEAD;
1704 SetLastError(MAGIC_DEAD);
1705 res = OpenPrinter(default_printer, &hprinter, &defaults);
1706 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1707 "returned %d with %d (expected '!=0' or '0' with "
1708 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1709 if(res) ClosePrinter(hprinter);
1711 defaults.pDatatype = empty;
1713 hprinter = (HANDLE) MAGIC_DEAD;
1714 SetLastError(MAGIC_DEAD);
1715 res = OpenPrinter(default_printer, &hprinter, &defaults);
1716 /* stop here, when a remote Printserver has no RPC-Service running */
1717 RETURN_ON_DEACTIVATED_SPOOLER(res)
1718 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1719 (GetLastError() == ERROR_ACCESS_DENIED)),
1720 "returned %d with %d (expected '!=0' or '0' with: "
1721 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1722 res, GetLastError());
1723 if(res) ClosePrinter(hprinter);
1726 defaults.pDatatype=NULL;
1727 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1729 hprinter = (HANDLE) MAGIC_DEAD;
1730 SetLastError(MAGIC_DEAD);
1731 res = OpenPrinter(default_printer, &hprinter, &defaults);
1732 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1733 "returned %d with %d (expected '!=0' or '0' with "
1734 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1735 if(res) ClosePrinter(hprinter);
1738 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1739 hprinter = (HANDLE) MAGIC_DEAD;
1740 SetLastError(MAGIC_DEAD);
1741 res = OpenPrinter(default_printer, &hprinter, &defaults);
1742 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1743 "returned %d with %d (expected '!=0' or '0' with "
1744 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1745 if(res) ClosePrinter(hprinter);
1751 static void test_SetDefaultPrinter(void)
1753 DWORD res;
1754 DWORD size = DEFAULT_PRINTER_SIZE;
1755 CHAR buffer[DEFAULT_PRINTER_SIZE];
1756 CHAR org_value[DEFAULT_PRINTER_SIZE];
1759 if (!pSetDefaultPrinterA) return;
1760 /* only supported on win2k and above */
1762 /* backup the original value */
1763 org_value[0] = '\0';
1764 SetLastError(MAGIC_DEAD);
1765 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1767 /* first part: with the default Printer */
1768 SetLastError(MAGIC_DEAD);
1769 res = pSetDefaultPrinterA("no_printer_with_this_name");
1771 RETURN_ON_DEACTIVATED_SPOOLER(res)
1772 /* spooler is running or we have no spooler here*/
1774 /* Not implemented in wine */
1775 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1776 trace("SetDefaultPrinterA() not implemented yet.\n");
1777 return;
1780 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1781 "returned %d with %d (expected '0' with "
1782 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1784 WriteProfileStringA("windows", "device", org_value);
1785 SetLastError(MAGIC_DEAD);
1786 res = pSetDefaultPrinterA("");
1787 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1788 "returned %d with %d (expected '!=0' or '0' with "
1789 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1791 WriteProfileStringA("windows", "device", org_value);
1792 SetLastError(MAGIC_DEAD);
1793 res = pSetDefaultPrinterA(NULL);
1794 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1795 "returned %d with %d (expected '!=0' or '0' with "
1796 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1798 WriteProfileStringA("windows", "device", org_value);
1799 SetLastError(MAGIC_DEAD);
1800 res = pSetDefaultPrinterA(default_printer);
1801 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1802 "returned %d with %d (expected '!=0' or '0' with "
1803 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1806 /* second part: always without a default Printer */
1807 WriteProfileStringA("windows", "device", NULL);
1808 SetLastError(MAGIC_DEAD);
1809 res = pSetDefaultPrinterA("no_printer_with_this_name");
1811 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1812 "returned %d with %d (expected '0' with "
1813 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1815 WriteProfileStringA("windows", "device", NULL);
1816 SetLastError(MAGIC_DEAD);
1817 res = pSetDefaultPrinterA("");
1818 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1819 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1820 "returned %d with %d (expected '!=0' or '0' with "
1821 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1823 WriteProfileStringA("windows", "device", NULL);
1824 SetLastError(MAGIC_DEAD);
1825 res = pSetDefaultPrinterA(NULL);
1826 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1827 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1828 "returned %d with %d (expected '!=0' or '0' with "
1829 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1831 WriteProfileStringA("windows", "device", NULL);
1832 SetLastError(MAGIC_DEAD);
1833 res = pSetDefaultPrinterA(default_printer);
1834 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1835 "returned %d with %d (expected '!=0' or '0' with "
1836 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1838 /* restore the original value */
1839 res = pSetDefaultPrinterA(default_printer); /* the nice way */
1840 WriteProfileStringA("windows", "device", org_value); /* the old way */
1842 buffer[0] = '\0';
1843 SetLastError(MAGIC_DEAD);
1844 res = GetProfileStringA("windows", "device", NULL, buffer, size);
1845 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1849 /* ########################### */
1851 static void test_XcvDataW_MonitorUI(void)
1853 DWORD res;
1854 HANDLE hXcv;
1855 BYTE buffer[MAX_PATH + 4];
1856 DWORD needed;
1857 DWORD status;
1858 DWORD len;
1859 PRINTER_DEFAULTSA pd;
1861 /* api is not present before w2k */
1862 if (pXcvDataW == NULL) return;
1864 pd.pDatatype = NULL;
1865 pd.pDevMode = NULL;
1866 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
1868 hXcv = NULL;
1869 SetLastError(0xdeadbeef);
1870 res = OpenPrinter(xcv_localport, &hXcv, &pd);
1871 RETURN_ON_DEACTIVATED_SPOOLER(res)
1872 RETURN_ON_ACCESS_DENIED(res)
1874 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
1875 if (!res) return;
1877 /* ask for needed size */
1878 needed = (DWORD) 0xdeadbeef;
1879 status = (DWORD) 0xdeadbeef;
1880 SetLastError(0xdeadbeef);
1881 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed, &status);
1882 ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
1883 "returned %d with %u and %u for status %u (expected '!= 0' and "
1884 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
1885 res, GetLastError(), needed, status);
1887 if (needed > MAX_PATH) {
1888 ClosePrinter(hXcv);
1889 skip("buffer overflow (%u)\n", needed);
1890 return;
1892 len = needed; /* Size is in bytes */
1894 /* the command is required */
1895 needed = (DWORD) 0xdeadbeef;
1896 status = (DWORD) 0xdeadbeef;
1897 SetLastError(0xdeadbeef);
1898 res = pXcvDataW(hXcv, emptyW, NULL, 0, NULL, 0, &needed, &status);
1899 ok( res && (status == ERROR_INVALID_PARAMETER),
1900 "returned %d with %u and %u for status %u (expected '!= 0' with "
1901 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
1903 needed = (DWORD) 0xdeadbeef;
1904 status = (DWORD) 0xdeadbeef;
1905 SetLastError(0xdeadbeef);
1906 res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
1907 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1908 "returned %d with %u and %u for status %u (expected '0' with "
1909 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1911 /* "PDWORD needed" is checked before RPC-Errors */
1912 needed = (DWORD) 0xdeadbeef;
1913 status = (DWORD) 0xdeadbeef;
1914 SetLastError(0xdeadbeef);
1915 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, NULL, &status);
1916 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
1917 "returned %d with %u and %u for status %u (expected '0' with "
1918 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
1920 needed = (DWORD) 0xdeadbeef;
1921 status = (DWORD) 0xdeadbeef;
1922 SetLastError(0xdeadbeef);
1923 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, len, &needed, &status);
1924 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1925 "returned %d with %u and %u for status %u (expected '0' with "
1926 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1928 needed = (DWORD) 0xdeadbeef;
1929 status = (DWORD) 0xdeadbeef;
1930 SetLastError(0xdeadbeef);
1931 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, NULL);
1932 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1933 "returned %d with %u and %u for status %u (expected '0' with "
1934 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1936 /* off by one: larger */
1937 needed = (DWORD) 0xdeadbeef;
1938 status = (DWORD) 0xdeadbeef;
1939 SetLastError(0xdeadbeef);
1940 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len+1, &needed, &status);
1941 ok( res && (status == ERROR_SUCCESS),
1942 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1943 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
1945 /* off by one: smaller */
1946 /* the buffer is not modified for NT4, w2k, XP */
1947 needed = (DWORD) 0xdeadbeef;
1948 status = (DWORD) 0xdeadbeef;
1949 SetLastError(0xdeadbeef);
1950 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len-1, &needed, &status);
1951 ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
1952 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1953 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
1956 /* Normal use. The DLL-Name without a Path is returned */
1957 memset(buffer, 0, len);
1958 needed = (DWORD) 0xdeadbeef;
1959 status = (DWORD) 0xdeadbeef;
1960 SetLastError(0xdeadbeef);
1961 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, &status);
1962 ok( res && (status == ERROR_SUCCESS),
1963 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1964 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
1966 ClosePrinter(hXcv);
1969 /* ########################### */
1971 static void test_XcvDataW_PortIsValid(void)
1973 DWORD res;
1974 HANDLE hXcv;
1975 DWORD needed;
1976 DWORD status;
1977 PRINTER_DEFAULTSA pd;
1979 /* api is not present before w2k */
1980 if (pXcvDataW == NULL) return;
1982 pd.pDatatype = NULL;
1983 pd.pDevMode = NULL;
1984 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
1986 hXcv = NULL;
1987 SetLastError(0xdeadbeef);
1988 res = OpenPrinter(xcv_localport, &hXcv, &pd);
1990 RETURN_ON_DEACTIVATED_SPOOLER(res)
1991 RETURN_ON_ACCESS_DENIED(res)
1993 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
1994 if (!res) return;
1997 /* "PDWORD needed" is always required */
1998 needed = (DWORD) 0xdeadbeef;
1999 status = (DWORD) 0xdeadbeef;
2000 SetLastError(0xdeadbeef);
2001 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, NULL, &status);
2002 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2003 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2004 res, GetLastError(), needed, status);
2006 /* an empty name is not allowed */
2007 needed = (DWORD) 0xdeadbeef;
2008 status = (DWORD) 0xdeadbeef;
2009 SetLastError(0xdeadbeef);
2010 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) emptyW, sizeof(emptyW), NULL, 0, &needed, &status);
2011 ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
2012 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2013 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2014 res, GetLastError(), needed, status);
2016 /* a directory is not allowed */
2017 needed = (DWORD) 0xdeadbeef;
2018 status = (DWORD) 0xdeadbeef;
2019 SetLastError(0xdeadbeef);
2020 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2021 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2022 ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
2023 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2024 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2025 res, GetLastError(), needed, status);
2027 /* more valid well known Ports */
2028 needed = (DWORD) 0xdeadbeef;
2029 status = (DWORD) 0xdeadbeef;
2030 SetLastError(0xdeadbeef);
2031 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed, &status);
2032 ok( res && (status == ERROR_SUCCESS),
2033 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2034 res, GetLastError(), needed, status);
2036 needed = (DWORD) 0xdeadbeef;
2037 status = (DWORD) 0xdeadbeef;
2038 SetLastError(0xdeadbeef);
2039 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt2W, sizeof(portname_lpt2W), NULL, 0, &needed, &status);
2040 ok( res && (status == ERROR_SUCCESS),
2041 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2042 res, GetLastError(), needed, status);
2044 needed = (DWORD) 0xdeadbeef;
2045 status = (DWORD) 0xdeadbeef;
2046 SetLastError(0xdeadbeef);
2047 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com1W, sizeof(portname_com1W), NULL, 0, &needed, &status);
2048 ok( res && (status == ERROR_SUCCESS),
2049 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2050 res, GetLastError(), needed, status);
2052 needed = (DWORD) 0xdeadbeef;
2053 status = (DWORD) 0xdeadbeef;
2054 SetLastError(0xdeadbeef);
2055 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com2W, sizeof(portname_com2W), NULL, 0, &needed, &status);
2056 ok( res && (status == ERROR_SUCCESS),
2057 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2058 res, GetLastError(), needed, status);
2060 needed = (DWORD) 0xdeadbeef;
2061 status = (DWORD) 0xdeadbeef;
2062 SetLastError(0xdeadbeef);
2063 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_fileW, sizeof(portname_fileW), NULL, 0, &needed, &status);
2064 ok( res && (status == ERROR_SUCCESS),
2065 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2066 res, GetLastError(), needed, status);
2069 /* a normal, writable file is allowed */
2070 needed = (DWORD) 0xdeadbeef;
2071 status = (DWORD) 0xdeadbeef;
2072 SetLastError(0xdeadbeef);
2073 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2074 ok( res && (status == ERROR_SUCCESS),
2075 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2076 res, GetLastError(), needed, status);
2078 ClosePrinter(hXcv);
2081 /* ########################### */
2083 static void test_GetPrinterDriver(void)
2085 HANDLE hprn;
2086 BOOL ret;
2087 BYTE *buf;
2088 INT level;
2089 DWORD needed, filled;
2091 if (!default_printer)
2093 skip("There is no default printer installed\n");
2094 return;
2097 hprn = 0;
2098 ret = OpenPrinter(default_printer, &hprn, NULL);
2099 if (!ret)
2101 skip("Unable to open the default printer (%s)\n", default_printer);
2102 return;
2104 ok(hprn != 0, "wrong hprn %p\n", hprn);
2106 for (level = -1; level <= 7; level++)
2108 SetLastError(0xdeadbeef);
2109 needed = (DWORD)-1;
2110 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
2111 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
2112 if (level >= 1 && level <= 6)
2114 /* Not all levels are supported on all Windows-Versions */
2115 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
2116 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2117 ok(needed > 0,"not expected needed buffer size %d\n", needed);
2119 else
2121 /* ERROR_OUTOFMEMORY found on win9x */
2122 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
2123 (GetLastError() == ERROR_OUTOFMEMORY)),
2124 "%d: returned %d with %d (expected '0' with: "
2125 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2126 level, ret, GetLastError());
2127 /* needed is modified in win9x. The modified Value depends on the
2128 default Printer. testing for "needed == (DWORD)-1" will fail */
2129 continue;
2132 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2134 SetLastError(0xdeadbeef);
2135 filled = -1;
2136 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
2137 ok(ret, "level %d: GetPrinterDriver error %d\n", level, GetLastError());
2138 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2140 if (level == 2)
2142 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
2143 DWORD calculated = sizeof(*di_2);
2145 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2146 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
2147 ok( (di_2->cVersion <= 3) ||
2148 (di_2->cVersion == 0x0400), "di_2->cVersion = %d\n", di_2->cVersion);
2149 ok(di_2->pName != NULL, "not expected NULL ptr\n");
2150 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
2151 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
2152 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
2153 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
2155 trace("cVersion %d\n", di_2->cVersion);
2156 trace("pName %s\n", di_2->pName);
2157 calculated += strlen(di_2->pName) + 1;
2158 trace("pEnvironment %s\n", di_2->pEnvironment);
2159 calculated += strlen(di_2->pEnvironment) + 1;
2160 trace("pDriverPath %s\n", di_2->pDriverPath);
2161 calculated += strlen(di_2->pDriverPath) + 1;
2162 trace("pDataFile %s\n", di_2->pDataFile);
2163 calculated += strlen(di_2->pDataFile) + 1;
2164 trace("pConfigFile %s\n", di_2->pConfigFile);
2165 calculated += strlen(di_2->pConfigFile) + 1;
2167 /* XP allocates memory for both ANSI and unicode names */
2168 ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
2171 HeapFree(GetProcessHeap(), 0, buf);
2174 SetLastError(0xdeadbeef);
2175 ret = ClosePrinter(hprn);
2176 ok(ret, "ClosePrinter error %d\n", GetLastError());
2179 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
2181 /* On NT3.51, some fields in DEVMODE are empty/zero
2182 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2183 We skip the Tests on this Platform */
2184 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
2185 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2186 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
2187 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
2188 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
2189 "%u != %d\n", dm->dmSize + dm->dmDriverExtra, dmSize);
2191 trace("dmFields %08x\n", dm->dmFields);
2194 static void test_DocumentProperties(void)
2196 HANDLE hprn;
2197 LONG dm_size, ret;
2198 DEVMODE *dm;
2200 if (!default_printer)
2202 skip("There is no default printer installed\n");
2203 return;
2206 hprn = 0;
2207 ret = OpenPrinter(default_printer, &hprn, NULL);
2208 if (!ret)
2210 skip("Unable to open the default printer (%s)\n", default_printer);
2211 return;
2213 ok(hprn != 0, "wrong hprn %p\n", hprn);
2215 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
2216 trace("DEVMODE required size %d\n", dm_size);
2217 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %d\n", dm_size);
2219 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
2221 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
2222 ok(ret == IDOK, "DocumentProperties ret value %d != expected IDOK\n", ret);
2224 test_DEVMODE(dm, dm_size, default_printer);
2226 HeapFree(GetProcessHeap(), 0, dm);
2228 SetLastError(0xdeadbeef);
2229 ret = ClosePrinter(hprn);
2230 ok(ret, "ClosePrinter error %d\n", GetLastError());
2233 static void test_EnumPrinters(void)
2235 DWORD neededA, neededW, num;
2236 DWORD ret;
2238 SetLastError(0xdeadbeef);
2239 neededA = -1;
2240 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
2241 RETURN_ON_DEACTIVATED_SPOOLER(ret)
2242 if (!ret)
2244 /* We have 1 or more printers */
2245 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2246 ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
2248 else
2250 /* We don't have any printers defined */
2251 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2252 ok(neededA == 0, "Expected neededA to be zero\n");
2254 ok(num == 0, "num %d\n", num);
2256 SetLastError(0xdeadbeef);
2257 neededW = -1;
2258 ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
2259 /* EnumPrintersW is not supported on all platforms */
2260 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
2262 win_skip("EnumPrintersW is not implemented\n");
2263 return;
2266 if (!ret)
2268 /* We have 1 or more printers */
2269 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2270 ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
2272 else
2274 /* We don't have any printers defined */
2275 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2276 ok(neededW == 0, "Expected neededW to be zero\n");
2278 ok(num == 0, "num %d\n", num);
2280 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2281 to hold the buffer returned by EnumPrintersW */
2282 ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
2285 static void test_DeviceCapabilities(void)
2287 HANDLE hComdlg32;
2288 BOOL (WINAPI *pPrintDlgA)(PRINTDLGA *);
2289 PRINTDLGA prn_dlg;
2290 DEVMODE *dm;
2291 DEVNAMES *dn;
2292 const char *driver, *device, *port;
2293 WORD *papers;
2294 POINT *paper_size;
2295 POINTS ext;
2296 struct
2298 char name[64];
2299 } *paper_name;
2300 INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
2301 DWORD fields;
2303 hComdlg32 = LoadLibrary("comdlg32.dll");
2304 assert(hComdlg32);
2305 pPrintDlgA = (void *)GetProcAddress(hComdlg32, "PrintDlgA");
2306 assert(pPrintDlgA);
2308 memset(&prn_dlg, 0, sizeof(prn_dlg));
2309 prn_dlg.lStructSize = sizeof(prn_dlg);
2310 prn_dlg.Flags = PD_RETURNDEFAULT;
2311 ret = pPrintDlgA(&prn_dlg);
2312 FreeLibrary(hComdlg32);
2313 if (!ret)
2315 skip("PrintDlg returned no default printer\n");
2316 return;
2318 ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
2319 ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
2321 dm = GlobalLock(prn_dlg.hDevMode);
2322 ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
2323 trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
2325 dn = GlobalLock(prn_dlg.hDevNames);
2326 ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
2327 ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
2328 ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
2329 ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
2330 ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
2331 driver = (const char *)dn + dn->wDriverOffset;
2332 device = (const char *)dn + dn->wDeviceOffset;
2333 port = (const char *)dn + dn->wOutputOffset;
2334 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
2336 test_DEVMODE(dm, dm->dmSize + dm->dmDriverExtra, device);
2338 n_papers = DeviceCapabilities(device, port, DC_PAPERS, NULL, NULL);
2339 ok(n_papers > 0, "DeviceCapabilities DC_PAPERS failed\n");
2340 papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
2341 ret = DeviceCapabilities(device, port, DC_PAPERS, (LPSTR)papers, NULL);
2342 ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
2343 #if VERBOSE
2344 for (ret = 0; ret < n_papers; ret++)
2345 trace("papers[%d] = %d\n", ret, papers[ret]);
2346 #endif
2347 HeapFree(GetProcessHeap(), 0, papers);
2349 n_paper_size = DeviceCapabilities(device, port, DC_PAPERSIZE, NULL, NULL);
2350 ok(n_paper_size > 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
2351 ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
2352 paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
2353 ret = DeviceCapabilities(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
2354 ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
2355 #if VERBOSE
2356 for (ret = 0; ret < n_paper_size; ret++)
2357 trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
2358 #endif
2359 HeapFree(GetProcessHeap(), 0, paper_size);
2361 n_paper_names = DeviceCapabilities(device, port, DC_PAPERNAMES, NULL, NULL);
2362 ok(n_paper_names > 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
2363 ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
2364 paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
2365 ret = DeviceCapabilities(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
2366 ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
2367 #if VERBOSE
2368 for (ret = 0; ret < n_paper_names; ret++)
2369 trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
2370 #endif
2371 HeapFree(GetProcessHeap(), 0, paper_name);
2373 n_copies = DeviceCapabilities(device, port, DC_COPIES, NULL, dm);
2374 ok(n_copies > 0, "DeviceCapabilities DC_COPIES failed\n");
2375 trace("n_copies = %d\n", n_copies);
2377 /* these capabilities not available on all printer drivers */
2378 if (0)
2380 ret = DeviceCapabilities(device, port, DC_MAXEXTENT, NULL, NULL);
2381 ok(ret != -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
2382 ext = MAKEPOINTS(ret);
2383 trace("max ext = %d x %d\n", ext.x, ext.y);
2385 ret = DeviceCapabilities(device, port, DC_MINEXTENT, NULL, NULL);
2386 ok(ret != -1, "DeviceCapabilities DC_MINEXTENT failed\n");
2387 ext = MAKEPOINTS(ret);
2388 trace("min ext = %d x %d\n", ext.x, ext.y);
2391 fields = DeviceCapabilities(device, port, DC_FIELDS, NULL, NULL);
2392 ok(fields != (DWORD)-1, "DeviceCapabilities DC_FIELDS failed\n");
2393 todo_wine
2394 ok(fields == (dm->dmFields | DM_FORMNAME),
2395 "fields %x != (dm->dmFields | DM_FORMNAME) %x\n", fields, dm->dmFields);
2397 GlobalUnlock(prn_dlg.hDevMode);
2398 GlobalFree(prn_dlg.hDevMode);
2399 GlobalUnlock(prn_dlg.hDevNames);
2400 GlobalFree(prn_dlg.hDevNames);
2403 START_TEST(info)
2405 hwinspool = GetModuleHandleA("winspool.drv");
2406 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
2407 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
2408 pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
2409 pAddPortExA = (void *) GetProcAddress(hwinspool, "AddPortExA");
2411 find_default_printer();
2412 find_local_server();
2413 find_tempfile();
2415 test_AddMonitor();
2416 test_AddPort();
2417 test_AddPortEx();
2418 test_ConfigurePort();
2419 test_DeleteMonitor();
2420 test_DeletePort();
2421 test_DeviceCapabilities();
2422 test_DocumentProperties();
2423 test_EnumForms(NULL);
2424 if (default_printer) test_EnumForms(default_printer);
2425 test_EnumMonitors();
2426 test_EnumPorts();
2427 test_EnumPrinterDrivers();
2428 test_EnumPrinters();
2429 test_GetDefaultPrinter();
2430 test_GetPrinterDriverDirectory();
2431 test_GetPrintProcessorDirectory();
2432 test_OpenPrinter();
2433 test_GetPrinterDriver();
2434 test_SetDefaultPrinter();
2435 test_XcvDataW_MonitorUI();
2436 test_XcvDataW_PortIsValid();
2438 /* Cleanup our temporary file */
2439 DeleteFileA(tempfileA);