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
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
36 #include "wine/test.h"
38 #define MAGIC_DEAD 0xdeadbeef
39 #define DEFAULT_PRINTER_SIZE 1000
41 static CHAR defaultspooldirectory[] = "DefaultSpoolDirectory";
42 static CHAR does_not_exist_dll[]= "does_not_exist.dll";
43 static CHAR does_not_exist[] = "does_not_exist";
44 static CHAR empty[] = "";
45 static CHAR env_x64[] = "Windows x64";
46 static CHAR env_x86[] = "Windows NT x86";
47 static CHAR env_win9x_case[] = "windowS 4.0";
48 static CHAR illegal_name[] = "illegal,name";
49 static CHAR invalid_env[] = "invalid_env";
50 static CHAR LocalPortA[] = "Local Port";
51 static CHAR portname_com1[] = "COM1:";
52 static CHAR portname_file[] = "FILE:";
53 static CHAR portname_lpt1[] = "LPT1:";
54 static CHAR server_does_not_exist[] = "\\\\does_not_exist";
55 static CHAR version_dll[] = "version.dll";
56 static CHAR winetest[] = "winetest";
57 static CHAR xcv_localport[] = ",XcvMonitor Local Port";
59 static WCHAR cmd_MonitorUIW[] = {'M','o','n','i','t','o','r','U','I',0};
60 static WCHAR cmd_PortIsValidW[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
61 static WCHAR emptyW[] = {0};
63 static WCHAR portname_com1W[] = {'C','O','M','1',':',0};
64 static WCHAR portname_com2W[] = {'C','O','M','2',':',0};
65 static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
66 static WCHAR portname_lpt1W[] = {'L','P','T','1',':',0};
67 static WCHAR portname_lpt2W[] = {'L','P','T','2',':',0};
69 static HANDLE hwinspool;
70 static BOOL (WINAPI * pAddPortExA)(LPSTR, DWORD, LPBYTE, LPSTR);
71 static BOOL (WINAPI * pEnumPrinterDriversW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
72 static BOOL (WINAPI * pGetDefaultPrinterA)(LPSTR, LPDWORD);
73 static DWORD (WINAPI * pGetPrinterDataExA)(HANDLE, LPCSTR, LPCSTR, LPDWORD, LPBYTE, DWORD, LPDWORD);
74 static BOOL (WINAPI * pGetPrinterDriverW)(HANDLE, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD);
75 static BOOL (WINAPI * pGetPrinterW)(HANDLE, DWORD, LPBYTE, DWORD, LPDWORD);
76 static BOOL (WINAPI * pSetDefaultPrinterA)(LPCSTR);
77 static DWORD (WINAPI * pXcvDataW)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD, PDWORD);
80 /* ################################ */
82 struct monitor_entry {
87 static LPSTR default_printer = NULL;
88 static LPSTR local_server = NULL;
89 static LPSTR tempdirA = NULL;
90 static LPSTR tempfileA = NULL;
91 static LPWSTR tempdirW = NULL;
92 static LPWSTR tempfileW = NULL;
94 /* ################################ */
95 /* report common behavior only once */
96 static DWORD deactivated_spooler_reported = 0;
97 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
98 if ((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
100 if (!deactivated_spooler_reported) { \
101 deactivated_spooler_reported++; \
102 skip("The Service 'Spooler' is required for many test\n"); \
107 static DWORD access_denied_reported = 0;
108 #define RETURN_ON_ACCESS_DENIED(res) \
109 if ((res == 0) && (GetLastError() == ERROR_ACCESS_DENIED)) \
111 if (!access_denied_reported) { \
112 access_denied_reported++; \
113 skip("More Access-Rights are required for many test\n"); \
118 /* ################################ */
120 static BOOL on_win9x = FALSE;
122 static BOOL check_win9x(void)
126 SetLastError(0xdeadbeef);
127 pGetPrinterW(NULL, 0, NULL, 0, NULL);
128 return (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
136 static void find_default_printer(VOID)
138 static char buffer[DEFAULT_PRINTER_SIZE];
143 if ((default_printer == NULL) && (pGetDefaultPrinterA))
146 needed = sizeof(buffer);
147 res = pGetDefaultPrinterA(buffer, &needed);
148 if(res) default_printer = buffer;
149 trace("default_printer: '%s'\n", default_printer);
151 if (default_printer == NULL)
155 /* NT 3.x and above */
156 if (RegOpenKeyEx(HKEY_CURRENT_USER,
157 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
158 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
160 needed = sizeof(buffer);
161 if (RegQueryValueEx(hwindows, "device", NULL,
162 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
164 ptr = strchr(buffer, ',');
167 default_printer = buffer;
170 RegCloseKey(hwindows);
172 trace("default_printer: '%s'\n", default_printer);
174 if (default_printer == NULL)
177 needed = sizeof(buffer);
178 res = GetProfileStringA("windows", "device", "*", buffer, needed);
180 ptr = strchr(buffer, ',');
183 default_printer = buffer;
186 trace("default_printer: '%s'\n", default_printer);
191 static struct monitor_entry * find_installed_monitor(void)
193 MONITOR_INFO_2A mi2a;
194 static struct monitor_entry * entry = NULL;
198 static struct monitor_entry monitor_table[] = {
199 {env_win9x_case, "localspl.dll"},
200 {env_x86, "localspl.dll"},
201 {env_x64, "localspl.dll"},
202 {env_win9x_case, "localmon.dll"},
203 {env_x86, "localmon.dll"},
204 {env_win9x_case, "tcpmon.dll"},
205 {env_x86, "tcpmon.dll"},
206 {env_win9x_case, "usbmon.dll"},
207 {env_x86, "usbmon.dll"},
208 {env_win9x_case, "mspp32.dll"},
209 {env_x86, "win32spl.dll"},
210 {env_x86, "redmonnt.dll"},
211 {env_x86, "redmon35.dll"},
212 {env_win9x_case, "redmon95.dll"},
213 {env_x86, "pdfcmnnt.dll"},
214 {env_win9x_case, "pdfcmn95.dll"},
217 if (entry) return entry;
219 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
222 DeleteMonitorA(NULL, env_x64, winetest);
223 DeleteMonitorA(NULL, env_x86, winetest);
224 DeleteMonitorA(NULL, env_win9x_case, winetest);
226 /* find a usable monitor from the table */
227 mi2a.pName = winetest;
228 while ((entry == NULL) && (i < num_tests)) {
229 entry = &monitor_table[i];
231 mi2a.pEnvironment = entry->env;
232 mi2a.pDLLName = entry->dllname;
234 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
236 trace("using '%s', '%s'\n", entry->env, entry->dllname);
237 DeleteMonitorA(NULL, entry->env, winetest);
248 /* ########################### */
250 static void find_local_server(VOID)
252 static char buffer[MAX_PATH];
256 size = sizeof(buffer) - 3 ;
261 SetLastError(0xdeadbeef);
262 res = GetComputerNameA(&buffer[2], &size);
263 trace("returned %d with %d and %d: '%s'\n", res, GetLastError(), size, buffer);
265 ok( res != 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
266 res, GetLastError(), size, buffer);
268 if (res) local_server = buffer;
271 /* ########################### */
273 static void find_tempfile(VOID)
275 static CHAR buffer_dirA[MAX_PATH];
276 static CHAR buffer_fileA[MAX_PATH];
277 static WCHAR buffer_dirW[MAX_PATH];
278 static WCHAR buffer_fileW[MAX_PATH];
282 memset(buffer_dirA, 0, MAX_PATH - 1);
283 buffer_dirA[MAX_PATH - 1] = '\0';
284 SetLastError(0xdeadbeef);
285 res = GetTempPathA(MAX_PATH, buffer_dirA);
286 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
287 if (res == 0) return;
289 memset(buffer_fileA, 0, MAX_PATH - 1);
290 buffer_fileA[MAX_PATH - 1] = '\0';
291 SetLastError(0xdeadbeef);
292 res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
293 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
294 if (res == 0) return;
296 SetLastError(0xdeadbeef);
297 resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
298 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
299 if (resint == 0) return;
301 SetLastError(0xdeadbeef);
302 resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
303 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
304 if (resint == 0) return;
306 tempdirA = buffer_dirA;
307 tempfileA = buffer_fileA;
308 tempdirW = buffer_dirW;
309 tempfileW = buffer_fileW;
310 trace("tempfile: '%s'\n", tempfileA);
313 /* ########################### */
315 static void test_AddMonitor(void)
317 MONITOR_INFO_2A mi2a;
318 struct monitor_entry * entry = NULL;
321 entry = find_installed_monitor();
323 SetLastError(MAGIC_DEAD);
324 res = AddMonitorA(NULL, 1, NULL);
325 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
326 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
327 res, GetLastError());
329 SetLastError(MAGIC_DEAD);
330 res = AddMonitorA(NULL, 3, NULL);
331 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
332 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
333 res, GetLastError());
337 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
338 SetLastError(MAGIC_DEAD);
339 res = AddMonitorA(NULL, 2, NULL);
340 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
342 ((GetLastError() == MAGIC_DEAD) ||
343 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
344 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
345 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
348 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
349 SetLastError(MAGIC_DEAD);
350 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
351 RETURN_ON_DEACTIVATED_SPOOLER(res)
352 RETURN_ON_ACCESS_DENIED(res)
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
355 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
356 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
357 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
358 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
361 skip("No usable Monitor found\n");
367 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
368 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
369 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
370 is created on win9x and we do not want to hit this bug here. */
372 mi2a.pEnvironment = entry->env;
373 SetLastError(MAGIC_DEAD);
374 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
375 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
378 mi2a.pEnvironment = entry->env;
380 SetLastError(MAGIC_DEAD);
381 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
382 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
384 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
385 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
386 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
387 "ERROR_PRIVILEGE_NOT_HELD)\n",
388 res, GetLastError());
390 mi2a.pName = winetest;
391 SetLastError(MAGIC_DEAD);
392 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
393 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
395 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
396 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
397 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
398 "ERROR_PRIVILEGE_NOT_HELD)\n",
399 res, GetLastError());
401 mi2a.pDLLName = empty;
402 SetLastError(MAGIC_DEAD);
403 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
404 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
405 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
406 res, GetLastError());
408 mi2a.pDLLName = does_not_exist_dll;
409 SetLastError(MAGIC_DEAD);
410 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
411 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
413 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
414 (GetLastError() == ERROR_INVALID_PARAMETER)),
415 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
416 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
418 mi2a.pDLLName = version_dll;
419 SetLastError(MAGIC_DEAD);
420 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
421 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
423 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
424 (GetLastError() == ERROR_INVALID_PARAMETER)),
425 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
426 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
427 if (res) DeleteMonitorA(NULL, entry->env, winetest);
429 /* Test AddMonitor with real options */
430 mi2a.pDLLName = entry->dllname;
431 SetLastError(MAGIC_DEAD);
432 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
433 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
435 /* add a monitor twice */
436 SetLastError(MAGIC_DEAD);
437 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
438 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
440 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
441 (GetLastError() == ERROR_ALREADY_EXISTS)),
442 "returned %d with %d (expected '0' with: "
443 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
444 res, GetLastError());
446 DeleteMonitorA(NULL, entry->env, winetest);
447 SetLastError(MAGIC_DEAD);
448 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
449 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
452 DeleteMonitorA(NULL, entry->env, winetest);
456 /* ########################### */
458 static void test_AddPort(void)
462 SetLastError(0xdeadbeef);
463 res = AddPortA(NULL, 0, NULL);
464 RETURN_ON_DEACTIVATED_SPOOLER(res)
465 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
466 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
467 (GetLastError() == ERROR_INVALID_PARAMETER)),
468 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
469 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
472 SetLastError(0xdeadbeef);
473 res = AddPortA(NULL, 0, empty);
474 /* Allowed only for (Printer-)Administrators */
475 RETURN_ON_ACCESS_DENIED(res)
477 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
478 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
479 (GetLastError() == ERROR_INVALID_PARAMETER)),
480 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
481 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
484 SetLastError(0xdeadbeef);
485 res = AddPortA(NULL, 0, does_not_exist);
486 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
487 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
488 (GetLastError() == ERROR_INVALID_PARAMETER)),
489 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
490 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
494 /* ########################### */
496 static void test_AddPortEx(void)
503 win_skip("AddPortEx not supported\n");
507 /* start test with a clean system */
508 DeletePortA(NULL, 0, tempfileA);
510 pi.pPortName = tempfileA;
511 SetLastError(0xdeadbeef);
512 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
513 RETURN_ON_DEACTIVATED_SPOOLER(res)
515 /* Allowed only for (Printer-)Administrators.
516 W2K+XP: ERROR_INVALID_PARAMETER */
517 if (!res && (GetLastError() == ERROR_INVALID_PARAMETER)) {
518 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
521 ok( res, "got %u with %u (expected '!= 0')\n", res, GetLastError());
523 /* Add a port, that already exist */
524 SetLastError(0xdeadbeef);
525 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
526 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
527 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
528 res, GetLastError());
529 DeletePortA(NULL, 0, tempfileA);
532 /* the Monitorname must match */
533 SetLastError(0xdeadbeef);
534 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, NULL);
535 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
536 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
537 res, GetLastError());
538 if (res) DeletePortA(NULL, 0, tempfileA);
540 SetLastError(0xdeadbeef);
541 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, empty);
542 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
543 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
544 res, GetLastError());
545 if (res) DeletePortA(NULL, 0, tempfileA);
547 SetLastError(0xdeadbeef);
548 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, does_not_exist);
549 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
550 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
551 res, GetLastError());
552 if (res) DeletePortA(NULL, 0, tempfileA);
555 /* We need a Portname */
556 SetLastError(0xdeadbeef);
557 res = pAddPortExA(NULL, 1, NULL, LocalPortA);
558 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
559 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
560 res, GetLastError());
563 SetLastError(0xdeadbeef);
564 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
565 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
566 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
567 res, GetLastError());
568 if (res) DeletePortA(NULL, 0, tempfileA);
571 /* level 2 is documented as supported for Printmonitors,
572 but that is not supported for "Local Port" (localspl.dll) and
573 AddPortEx fails with ERROR_INVALID_LEVEL */
575 pi.pPortName = tempfileA;
576 pi.pMonitorName = LocalPortA;
577 pi.pDescription = winetest;
578 pi.fPortType = PORT_TYPE_WRITE;
580 SetLastError(0xdeadbeef);
581 res = pAddPortExA(NULL, 2, (LPBYTE) &pi, LocalPortA);
582 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
583 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
584 res, GetLastError());
585 if (res) DeletePortA(NULL, 0, tempfileA);
589 SetLastError(0xdeadbeef);
590 res = pAddPortExA(NULL, 0, (LPBYTE) &pi, LocalPortA);
591 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
592 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
593 res, GetLastError());
595 SetLastError(0xdeadbeef);
596 res = pAddPortExA(NULL, 3, (LPBYTE) &pi, LocalPortA);
597 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
598 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
599 res, GetLastError());
603 DeletePortA(NULL, 0, tempfileA);
607 /* ########################### */
609 static void test_ConfigurePort(void)
614 SetLastError(0xdeadbeef);
615 res = ConfigurePortA(NULL, 0, NULL);
616 RETURN_ON_DEACTIVATED_SPOOLER(res)
617 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
618 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
619 (GetLastError() == ERROR_INVALID_PARAMETER)),
620 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
621 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
623 SetLastError(0xdeadbeef);
624 res = ConfigurePortA(NULL, 0, empty);
625 /* Allowed only for (Printer-)Administrators */
626 RETURN_ON_ACCESS_DENIED(res)
628 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
629 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
630 (GetLastError() == ERROR_INVALID_PARAMETER)),
631 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
632 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
635 SetLastError(0xdeadbeef);
636 res = ConfigurePortA(NULL, 0, does_not_exist);
637 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
638 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
639 (GetLastError() == ERROR_INVALID_PARAMETER)),
640 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
641 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
645 - Case of Portnames is ignored
646 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
647 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
649 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
650 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
651 - Cancel ("Local Port") => ERROR_CANCELED
652 - Cancel ("Redirected Port") => Success
654 if (winetest_interactive > 0) {
655 SetLastError(0xdeadbeef);
656 res = ConfigurePortA(NULL, 0, portname_com1);
657 trace("'%s' returned %d with %d\n", portname_com1, res, GetLastError());
659 SetLastError(0xdeadbeef);
660 res = ConfigurePortA(NULL, 0, portname_lpt1);
661 trace("'%s' returned %d with %d\n", portname_lpt1, res, GetLastError());
663 SetLastError(0xdeadbeef);
664 res = ConfigurePortA(NULL, 0, portname_file);
665 trace("'%s' returned %d with %d\n", portname_file, res, GetLastError());
669 /* ########################### */
671 static void test_DeleteMonitor(void)
673 MONITOR_INFO_2A mi2a;
674 struct monitor_entry * entry = NULL;
678 entry = find_installed_monitor();
681 skip("No usable Monitor found\n");
685 mi2a.pName = winetest;
686 mi2a.pEnvironment = entry->env;
687 mi2a.pDLLName = entry->dllname;
689 /* Testing DeleteMonitor with real options */
690 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
692 SetLastError(MAGIC_DEAD);
693 res = DeleteMonitorA(NULL, entry->env, winetest);
694 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
696 /* Delete the Monitor twice */
697 SetLastError(MAGIC_DEAD);
698 res = DeleteMonitorA(NULL, entry->env, winetest);
699 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
701 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
702 (GetLastError() == ERROR_INVALID_PARAMETER)),
703 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
704 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
706 /* the environment */
707 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
708 SetLastError(MAGIC_DEAD);
709 res = DeleteMonitorA(NULL, NULL, winetest);
710 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
712 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
713 SetLastError(MAGIC_DEAD);
714 res = DeleteMonitorA(NULL, empty, winetest);
715 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
717 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
718 SetLastError(MAGIC_DEAD);
719 res = DeleteMonitorA(NULL, invalid_env, winetest);
721 (!res && GetLastError() == ERROR_INVALID_ENVIRONMENT) /* Vista/W2K8 */,
722 "returned %d with %d\n", res, GetLastError());
724 /* the monitor-name */
725 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
726 SetLastError(MAGIC_DEAD);
727 res = DeleteMonitorA(NULL, entry->env, NULL);
728 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
730 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
731 (GetLastError() == ERROR_INVALID_NAME)),
732 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
733 "ERROR_INVALID_NAME)\n", res, GetLastError());
735 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
736 SetLastError(MAGIC_DEAD);
737 res = DeleteMonitorA(NULL, entry->env, empty);
738 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
740 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
741 (GetLastError() == ERROR_INVALID_NAME)),
742 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
743 "ERROR_INVALID_NAME)\n", res, GetLastError());
745 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
746 SetLastError(MAGIC_DEAD);
747 res = DeleteMonitorA(empty, entry->env, winetest);
748 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
751 DeleteMonitorA(NULL, entry->env, winetest);
754 /* ########################### */
756 static void test_DeletePort(void)
760 SetLastError(0xdeadbeef);
761 res = DeletePortA(NULL, 0, NULL);
762 RETURN_ON_DEACTIVATED_SPOOLER(res)
764 SetLastError(0xdeadbeef);
765 res = DeletePortA(NULL, 0, empty);
766 /* Allowed only for (Printer-)Administrators */
767 RETURN_ON_ACCESS_DENIED(res)
769 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
770 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
771 (GetLastError() == ERROR_INVALID_PARAMETER)),
772 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
773 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
776 SetLastError(0xdeadbeef);
777 res = DeletePortA(NULL, 0, does_not_exist);
778 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
779 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
780 (GetLastError() == ERROR_INVALID_PARAMETER)),
781 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
782 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
786 /* ########################### */
788 static void test_EnumForms(LPSTR pName)
798 const char *formtype;
799 static const char * const formtypes[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
800 #define FORMTYPE_MAX 2
801 PFORM_INFO_1A pFI_1a;
802 PFORM_INFO_2A pFI_2a;
804 res = OpenPrinter(pName, &hprinter, NULL);
805 RETURN_ON_DEACTIVATED_SPOOLER(res)
806 if (!res || !hprinter)
808 /* Open the local Prinserver is not supported on win9x */
809 if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
813 /* valid levels are 1 and 2 */
814 for(level = 0; level < 4; level++) {
816 pcReturned = 0xdeadbeef;
817 SetLastError(0xdeadbeef);
818 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
820 /* EnumForms is not implemented in win9x */
821 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
823 /* EnumForms for the Server not implemented on all NT-Versions */
824 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
826 /* Level 2 for EnumForms is not supported on all systems */
827 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
829 /* use only a short test, when we test with an invalid level */
830 if(!level || (level > 2)) {
831 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
832 (res && (pcReturned == 0)),
833 "(%d) returned %d with %d and 0x%08x (expected '0' with "
834 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
835 level, res, GetLastError(), pcReturned);
839 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
840 "(%d) returned %d with %d (expected '0' with "
841 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
843 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
844 if (buffer == NULL) continue;
846 SetLastError(0xdeadbeef);
847 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
848 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
849 level, res, GetLastError());
851 if (winetest_debug > 1) {
852 trace("dumping %d forms level %d\n", pcReturned, level);
853 pFI_1a = (PFORM_INFO_1A)buffer;
854 pFI_2a = (PFORM_INFO_2A)buffer;
855 for (i = 0; i < pcReturned; i++)
857 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
858 formtype = (pFI_1a->Flags <= FORMTYPE_MAX) ? formtypes[pFI_1a->Flags] : formtypes[3];
859 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i, pFI_1a->pName,
860 (float)pFI_1a->Size.cx/1000, (float)pFI_1a->Size.cy/1000, formtype);
862 if (level == 1) pFI_1a ++;
864 /* output additional FORM_INFO_2 fields */
865 trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
866 pFI_2a->pKeyword, pFI_2a->StringType, pFI_2a->pMuiDll,
867 pFI_2a->dwResourceId, pFI_2a->pDisplayName, pFI_2a->wLangId);
869 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
871 pFI_1a = (PFORM_INFO_1A)pFI_2a;
876 SetLastError(0xdeadbeef);
877 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
878 ok( res, "(%d) returned %d with %d (expected '!=0')\n",
879 level, res, GetLastError());
881 SetLastError(0xdeadbeef);
882 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
883 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
884 "(%d) returned %d with %d (expected '0' with "
885 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
888 SetLastError(0xdeadbeef);
889 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
890 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
891 "(%d) returned %d with %d (expected '0' with "
892 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
895 SetLastError(0xdeadbeef);
896 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
897 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
898 "(%d) returned %d with %d (expected '0' with "
899 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
901 SetLastError(0xdeadbeef);
902 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
903 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
904 "(%d) returned %d with %d (expected '0' with "
905 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
907 SetLastError(0xdeadbeef);
908 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
909 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
910 "(%d) returned %d with %d (expected '0' with "
911 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
913 HeapFree(GetProcessHeap(), 0, buffer);
914 } /* for(level ... */
916 ClosePrinter(hprinter);
919 /* ########################### */
921 static void test_EnumMonitors(void)
930 /* valid levels are 1 and 2 */
931 for(level = 0; level < 4; level++) {
933 pcReturned = MAGIC_DEAD;
934 SetLastError(MAGIC_DEAD);
935 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
937 RETURN_ON_DEACTIVATED_SPOOLER(res)
939 /* not implemented yet in wine */
940 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
943 /* use only a short test, when we test with an invalid level */
944 if(!level || (level > 2)) {
945 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
946 (res && (pcReturned == 0)),
947 "(%d) returned %d with %d and 0x%08x (expected '0' with "
948 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
949 level, res, GetLastError(), pcReturned);
953 /* Level 2 is not supported on win9x */
954 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
955 skip("Level %d not supported\n", level);
959 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
960 "(%d) returned %d with %d (expected '0' with "
961 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
964 skip("no valid buffer size returned\n");
968 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
969 if (buffer == NULL) continue;
971 SetLastError(MAGIC_DEAD);
972 pcbNeeded = MAGIC_DEAD;
973 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
974 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
975 level, res, GetLastError());
976 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n",
977 level, pcbNeeded, cbBuf);
978 /* We can validate the returned Data with the Registry here */
981 SetLastError(MAGIC_DEAD);
982 pcReturned = MAGIC_DEAD;
983 pcbNeeded = MAGIC_DEAD;
984 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
985 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level,
986 res, GetLastError());
987 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
990 SetLastError(MAGIC_DEAD);
991 pcbNeeded = MAGIC_DEAD;
992 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
993 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
994 "(%d) returned %d with %d (expected '0' with "
995 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
997 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
1001 Do not add the next test:
1002 w2k+: RPC_X_NULL_REF_POINTER
1003 NT3.5: ERROR_INVALID_USER_BUFFER
1004 win9x: crash in winspool.drv
1006 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1009 SetLastError(MAGIC_DEAD);
1010 pcbNeeded = MAGIC_DEAD;
1011 pcReturned = MAGIC_DEAD;
1012 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1013 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1014 "(%d) returned %d with %d (expected '!=0' or '0' with "
1015 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1017 pcbNeeded = MAGIC_DEAD;
1018 pcReturned = MAGIC_DEAD;
1019 SetLastError(MAGIC_DEAD);
1020 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1021 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1022 "(%d) returned %d with %d (expected '!=0' or '0' with "
1023 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1025 HeapFree(GetProcessHeap(), 0, buffer);
1026 } /* for(level ... */
1029 /* ########################### */
1031 static void test_EnumPorts(void)
1040 /* valid levels are 1 and 2 */
1041 for(level = 0; level < 4; level++) {
1044 pcReturned = 0xdeadbeef;
1045 SetLastError(0xdeadbeef);
1046 res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
1047 RETURN_ON_DEACTIVATED_SPOOLER(res)
1049 /* use only a short test, when we test with an invalid level */
1050 if(!level || (level > 2)) {
1051 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1052 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1053 (res && (pcReturned == 0)),
1054 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1055 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1056 level, res, GetLastError(), pcReturned);
1061 /* Level 2 is not supported on NT 3.x */
1062 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1063 skip("Level %d not supported\n", level);
1067 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1068 "(%d) returned %d with %d (expected '0' with "
1069 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1071 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1072 if (buffer == NULL) continue;
1074 pcbNeeded = 0xdeadbeef;
1075 SetLastError(0xdeadbeef);
1076 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1077 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1078 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1079 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1081 pcbNeeded = 0xdeadbeef;
1082 pcReturned = 0xdeadbeef;
1083 SetLastError(0xdeadbeef);
1084 res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1085 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1086 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1088 pcbNeeded = 0xdeadbeef;
1089 SetLastError(0xdeadbeef);
1090 res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1091 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1092 "(%d) returned %d with %d (expected '0' with "
1093 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1094 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1097 Do not add this test:
1098 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1099 w2k+: RPC_X_NULL_REF_POINTER
1100 NT3.5: ERROR_INVALID_USER_BUFFER
1101 win9x: crash in winspool.drv
1104 SetLastError(0xdeadbeef);
1105 res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1106 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1107 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1108 ( res && (GetLastError() == ERROR_SUCCESS) ),
1109 "(%d) returned %d with %d (expected '0' with "
1110 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1111 level, res, GetLastError());
1114 SetLastError(0xdeadbeef);
1115 res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1116 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1117 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1118 ( res && (GetLastError() == ERROR_SUCCESS) ),
1119 "(%d) returned %d with %d (expected '0' with "
1120 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1121 level, res, GetLastError());
1123 HeapFree(GetProcessHeap(), 0, buffer);
1127 /* ########################### */
1129 static void test_EnumPrinterDrivers(void)
1131 static char env_all[] = "all";
1140 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1141 for(level = 0; level < 10; level++) {
1143 pcReturned = 0xdeadbeef;
1144 SetLastError(0xdeadbeef);
1145 res = EnumPrinterDriversA(NULL, NULL, level, NULL, 0, &cbBuf, &pcReturned);
1146 RETURN_ON_DEACTIVATED_SPOOLER(res)
1148 /* use only a short test, when we test with an invalid level */
1149 if(!level || (level == 7) || (level > 8)) {
1151 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1152 (res && (pcReturned == 0)),
1153 "(%d) got %u with %u and 0x%x "
1154 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1155 level, res, GetLastError(), pcReturned);
1159 /* some level are not supported in all windows versions */
1160 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1161 skip("Level %d not supported\n", level);
1165 ok( ((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ||
1166 (res && (default_printer == NULL)),
1167 "(%u) got %u with %u for %s (expected '0' with "
1168 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1169 level, res, GetLastError(), default_printer);
1172 skip("no valid buffer size returned\n");
1176 /* EnumPrinterDriversA returns the same number of bytes as EnumPrinterDriversW */
1177 if (!on_win9x && pEnumPrinterDriversW)
1179 DWORD double_needed;
1180 DWORD double_returned;
1181 pEnumPrinterDriversW(NULL, NULL, level, NULL, 0, &double_needed, &double_returned);
1182 ok(double_needed == cbBuf, "level %d: EnumPrinterDriversA returned different size %d than EnumPrinterDriversW (%d)\n", level, cbBuf, double_needed);
1185 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1186 if (buffer == NULL) continue;
1188 SetLastError(0xdeadbeef);
1189 pcbNeeded = 0xdeadbeef;
1190 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1191 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1192 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1194 /* validate the returned Data here */
1196 LPDRIVER_INFO_2A di = (LPDRIVER_INFO_2A) buffer;
1198 ok( strrchr(di->pDriverPath, '\\') != NULL,
1199 "(%u) got %s for %s (expected a full path)\n",
1200 level, di->pDriverPath, di->pName);
1204 SetLastError(0xdeadbeef);
1205 pcReturned = 0xdeadbeef;
1206 pcbNeeded = 0xdeadbeef;
1207 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1208 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1209 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1211 SetLastError(0xdeadbeef);
1212 pcbNeeded = 0xdeadbeef;
1213 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1214 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1215 "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1216 level, res, GetLastError());
1217 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1220 Do not add the next test:
1221 NT: ERROR_INVALID_USER_BUFFER
1222 win9x: crash or 100% CPU
1224 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1227 SetLastError(0xdeadbeef);
1228 pcbNeeded = 0xdeadbeef;
1229 pcReturned = 0xdeadbeef;
1230 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, NULL, &pcReturned);
1231 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1232 "(%u) got %u with %u (expected '!=0' or '0' with "
1233 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1235 pcbNeeded = 0xdeadbeef;
1236 pcReturned = 0xdeadbeef;
1237 SetLastError(0xdeadbeef);
1238 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1239 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1240 "(%u) got %u with %u (expected '!=0' or '0' with "
1241 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1243 HeapFree(GetProcessHeap(), 0, buffer);
1244 } /* for(level ... */
1248 SetLastError(0xdeadbeef);
1249 res = EnumPrinterDriversA(NULL, env_all, 1, NULL, 0, &pcbNeeded, &pcReturned);
1252 skip("no printer drivers found\n");
1255 if (GetLastError() == ERROR_INVALID_ENVIRONMENT)
1257 win_skip("NT4 and below don't support the 'all' environment value\n");
1260 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "unexpected error %u\n", GetLastError());
1262 buffer = HeapAlloc(GetProcessHeap(), 0, pcbNeeded);
1263 res = EnumPrinterDriversA(NULL, env_all, 1, buffer, pcbNeeded, &pcbNeeded, &pcReturned);
1264 ok(res, "EnumPrinterDriversA failed %u\n", GetLastError());
1265 if (res && pcReturned > 0)
1267 DRIVER_INFO_1 *di_1 = (DRIVER_INFO_1 *)buffer;
1268 ok((LPBYTE) di_1->pName == NULL || (LPBYTE) di_1->pName < buffer ||
1269 (LPBYTE) di_1->pName >= (LPBYTE)(di_1 + pcReturned),
1270 "Driver Information not in sequence; pName %p, top of data %p\n",
1271 di_1->pName, di_1 + pcReturned);
1274 HeapFree(GetProcessHeap(), 0, buffer);
1277 /* ########################### */
1279 static void test_EnumPrintProcessors(void)
1289 pcReturned = 0xdeadbeef;
1290 SetLastError(0xdeadbeef);
1291 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, 0, &cbBuf, &pcReturned);
1292 RETURN_ON_DEACTIVATED_SPOOLER(res)
1294 if (res && !cbBuf) {
1295 skip("No Printprocessor installed\n");
1299 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1300 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1301 res, GetLastError());
1303 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1307 SetLastError(0xdeadbeef);
1308 pcbNeeded = 0xdeadbeef;
1309 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1310 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1311 /* validate the returned Data here. */
1314 SetLastError(0xdeadbeef);
1315 pcReturned = 0xdeadbeef;
1316 pcbNeeded = 0xdeadbeef;
1317 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1318 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1320 SetLastError(0xdeadbeef);
1321 pcbNeeded = 0xdeadbeef;
1322 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1323 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1324 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1325 res, GetLastError());
1327 /* only level 1 is valid */
1329 /* both tests crash on win98se */
1330 SetLastError(0xdeadbeef);
1331 pcbNeeded = 0xdeadbeef;
1332 pcReturned = 0xdeadbeef;
1333 res = EnumPrintProcessorsA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded, &pcReturned);
1334 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1335 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1336 res, GetLastError());
1338 SetLastError(0xdeadbeef);
1339 pcbNeeded = 0xdeadbeef;
1340 res = EnumPrintProcessorsA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded, &pcReturned);
1341 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1342 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1343 res, GetLastError());
1346 /* an empty environment is ignored */
1347 SetLastError(0xdeadbeef);
1348 pcbNeeded = 0xdeadbeef;
1349 res = EnumPrintProcessorsA(NULL, empty, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1350 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1352 /* the environment is checked */
1353 SetLastError(0xdeadbeef);
1354 pcbNeeded = 0xdeadbeef;
1355 res = EnumPrintProcessorsA(NULL, invalid_env, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1356 /* NT5: ERROR_INVALID_ENVIRONMENT, NT4: res != 0, 9x: ERROR_INVALID_PARAMETER */
1357 ok( broken(res) || /* NT4 */
1358 (GetLastError() == ERROR_INVALID_ENVIRONMENT) ||
1359 (GetLastError() == ERROR_INVALID_PARAMETER),
1360 "got %u with %u (expected '0' with ERROR_INVALID_ENVIRONMENT or "
1361 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1364 /* failure-Codes for NULL */
1366 /* this test crash on win98se */
1367 SetLastError(0xdeadbeef);
1368 pcbNeeded = 0xdeadbeef;
1369 pcReturned = 0xdeadbeef;
1370 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, cbBuf, &pcbNeeded, &pcReturned);
1371 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
1372 "got %u with %u (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1373 res, GetLastError());
1376 SetLastError(0xdeadbeef);
1377 pcbNeeded = 0xdeadbeef;
1378 pcReturned = 0xdeadbeef;
1379 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, NULL, &pcReturned);
1380 /* the NULL is ignored on win9x */
1381 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1382 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1383 res, GetLastError());
1385 pcbNeeded = 0xdeadbeef;
1386 pcReturned = 0xdeadbeef;
1387 SetLastError(0xdeadbeef);
1388 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, NULL);
1389 /* the NULL is ignored on win9x */
1390 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1391 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1392 res, GetLastError());
1394 HeapFree(GetProcessHeap(), 0, buffer);
1398 /* ########################### */
1400 static void test_GetDefaultPrinter(void)
1403 DWORD exact = DEFAULT_PRINTER_SIZE;
1405 char buffer[DEFAULT_PRINTER_SIZE];
1407 if (!pGetDefaultPrinterA) return;
1408 /* only supported on NT like OSes starting with win2k */
1410 SetLastError(ERROR_SUCCESS);
1411 retval = pGetDefaultPrinterA(buffer, &exact);
1412 if (!retval || !exact || !strlen(buffer) ||
1413 (ERROR_SUCCESS != GetLastError())) {
1414 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
1415 (ERROR_INVALID_NAME == GetLastError()))
1416 trace("this test requires a default printer to be set\n");
1418 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1419 "function returned %s\n"
1420 "last error 0x%08x\n"
1421 "returned buffer size 0x%08x\n"
1422 "returned buffer content %s\n",
1423 retval ? "true" : "false", GetLastError(), exact, buffer);
1427 SetLastError(ERROR_SUCCESS);
1428 retval = pGetDefaultPrinterA(NULL, NULL);
1429 ok( !retval, "function result wrong! False expected\n");
1430 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1431 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1434 SetLastError(ERROR_SUCCESS);
1435 retval = pGetDefaultPrinterA(buffer, NULL);
1436 ok( !retval, "function result wrong! False expected\n");
1437 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1438 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1441 SetLastError(ERROR_SUCCESS);
1443 retval = pGetDefaultPrinterA(NULL, &size);
1444 ok( !retval, "function result wrong! False expected\n");
1445 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1446 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1448 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1451 SetLastError(ERROR_SUCCESS);
1452 size = DEFAULT_PRINTER_SIZE;
1453 retval = pGetDefaultPrinterA(NULL, &size);
1454 ok( !retval, "function result wrong! False expected\n");
1455 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1456 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1458 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1462 retval = pGetDefaultPrinterA(buffer, &size);
1463 ok( !retval, "function result wrong! False expected\n");
1464 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1465 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1467 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1471 retval = pGetDefaultPrinterA(buffer, &size);
1472 ok( retval, "function result wrong! True expected\n");
1473 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1477 static void test_GetPrinterDriverDirectory(void)
1479 LPBYTE buffer = NULL;
1480 DWORD cbBuf = 0, pcbNeeded = 0;
1484 SetLastError(MAGIC_DEAD);
1485 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1486 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1487 res, GetLastError(), cbBuf);
1489 RETURN_ON_DEACTIVATED_SPOOLER(res)
1490 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1491 "returned %d with lasterror=%d (expected '0' with "
1492 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1495 skip("no valid buffer size returned\n");
1499 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1500 if (buffer == NULL) return ;
1502 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1503 ok( res, "expected result != 0, got %d\n", res);
1504 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1507 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1508 ok( res, "expected result != 0, got %d\n", res);
1509 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1512 SetLastError(MAGIC_DEAD);
1513 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1514 ok( !res , "expected result == 0, got %d\n", res);
1515 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1518 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1519 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1523 Do not add the next test:
1524 XPsp2: crash in this app, when the spooler is not running
1525 NT3.5: ERROR_INVALID_USER_BUFFER
1526 win9x: ERROR_INVALID_PARAMETER
1528 pcbNeeded = MAGIC_DEAD;
1529 SetLastError(MAGIC_DEAD);
1530 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1533 SetLastError(MAGIC_DEAD);
1534 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1535 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
1536 "expected either result == 0 and "
1537 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1538 "got result %d and last error == %d\n", res, GetLastError());
1540 SetLastError(MAGIC_DEAD);
1541 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1542 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1543 "returned %d with %d (expected '!=0' or '0' with "
1544 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1547 /* with a valid buffer, but level is too large */
1549 SetLastError(MAGIC_DEAD);
1550 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1552 /* Level not checked in win9x and wine:*/
1553 if((res != FALSE) && buffer[0])
1555 trace("Level '2' not checked '%s'\n", buffer);
1559 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1560 "returned %d with lasterror=%d (expected '0' with "
1561 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1564 /* printing environments are case insensitive */
1565 /* "Windows 4.0" is valid for win9x and NT */
1567 SetLastError(MAGIC_DEAD);
1568 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1569 buffer, cbBuf*2, &pcbNeeded);
1571 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1573 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1574 if (buffer == NULL) return ;
1576 SetLastError(MAGIC_DEAD);
1577 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1578 buffer, cbBuf*2, &pcbNeeded);
1581 ok(res && buffer[0], "returned %d with "
1582 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1583 res, GetLastError(), lstrlenA((char *)buffer));
1586 SetLastError(MAGIC_DEAD);
1587 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1588 buffer, cbBuf*2, &pcbNeeded);
1590 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1592 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1593 if (buffer == NULL) return ;
1596 SetLastError(MAGIC_DEAD);
1597 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1598 buffer, cbBuf*2, &pcbNeeded);
1601 /* "Windows NT x86" is invalid for win9x */
1602 ok( (res && buffer[0]) ||
1603 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
1604 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1605 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1606 res, GetLastError(), lstrlenA((char *)buffer));
1608 /* A setup program (PDFCreator_0.8.0) use empty strings */
1609 SetLastError(MAGIC_DEAD);
1610 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1611 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1613 SetLastError(MAGIC_DEAD);
1614 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1615 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1617 SetLastError(MAGIC_DEAD);
1618 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1619 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1621 HeapFree( GetProcessHeap(), 0, buffer);
1626 static void test_GetPrintProcessorDirectory(void)
1628 LPBYTE buffer = NULL;
1630 DWORD pcbNeeded = 0;
1634 SetLastError(0xdeadbeef);
1635 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1636 /* The deactivated Spooler is caught here on NT3.51 */
1637 RETURN_ON_DEACTIVATED_SPOOLER(res)
1638 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1639 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1640 res, GetLastError());
1642 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1643 if(buffer == NULL) return;
1646 SetLastError(0xdeadbeef);
1647 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1648 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1650 SetLastError(0xdeadbeef);
1652 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1653 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1655 /* Buffer to small */
1657 SetLastError(0xdeadbeef);
1658 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1659 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1660 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1661 res, GetLastError());
1665 /* XPsp2: the program will crash here, when the spooler is not running */
1666 /* GetPrinterDriverDirectory has the same bug */
1668 SetLastError(0xdeadbeef);
1669 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1670 /* NT: ERROR_INVALID_USER_BUFFER, 9x: res != 0 */
1671 ok( (!res && (GetLastError() == ERROR_INVALID_USER_BUFFER)) ||
1673 "returned %d with %d (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1674 res, GetLastError());
1678 SetLastError(0xdeadbeef);
1679 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1680 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1681 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ||
1683 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1684 res, GetLastError());
1687 SetLastError(0xdeadbeef);
1688 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1689 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1690 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ||
1692 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1693 res, GetLastError());
1695 /* with a valid buffer, but level is invalid */
1697 SetLastError(0xdeadbeef);
1698 res = GetPrintProcessorDirectoryA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded);
1699 /* Level is ignored in win9x*/
1700 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1701 broken(res && buffer[0]),
1702 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1703 res, GetLastError());
1706 SetLastError(0xdeadbeef);
1707 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1708 /* Level is ignored in win9x*/
1709 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1710 broken(res && buffer[0]),
1711 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1712 res, GetLastError());
1714 /* Empty environment is the same as the default environment */
1716 SetLastError(0xdeadbeef);
1717 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1718 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1720 /* "Windows 4.0" is valid for win9x and NT */
1722 SetLastError(0xdeadbeef);
1723 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1724 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1727 /* "Windows NT x86" is invalid for win9x */
1729 SetLastError(0xdeadbeef);
1730 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1731 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1732 "returned %d with %d (expected '!= 0' or '0' with "
1733 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1735 /* invalid on all Systems */
1737 SetLastError(0xdeadbeef);
1738 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1739 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1740 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1741 res, GetLastError());
1743 /* Empty servername is the same as the local computer */
1745 SetLastError(0xdeadbeef);
1746 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1747 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1749 /* invalid on all Systems */
1751 SetLastError(0xdeadbeef);
1752 res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1753 ok( !res, "expected failure\n");
1754 ok( GetLastError() == RPC_S_SERVER_UNAVAILABLE || /* NT */
1755 GetLastError() == ERROR_INVALID_PARAMETER || /* 9x */
1756 GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista */
1757 "unexpected last error %d\n", GetLastError());
1759 HeapFree(GetProcessHeap(), 0, buffer);
1764 static void test_OpenPrinter(void)
1766 PRINTER_DEFAULTSA defaults;
1770 SetLastError(MAGIC_DEAD);
1771 res = OpenPrinter(NULL, NULL, NULL);
1772 /* The deactivated Spooler is caught here on NT3.51 */
1773 RETURN_ON_DEACTIVATED_SPOOLER(res)
1774 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1775 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1776 res, GetLastError());
1779 /* Get Handle for the local Printserver (NT only)*/
1780 hprinter = (HANDLE) MAGIC_DEAD;
1781 SetLastError(MAGIC_DEAD);
1782 res = OpenPrinter(NULL, &hprinter, NULL);
1783 /* The deactivated Spooler is caught here on XPsp2 */
1784 RETURN_ON_DEACTIVATED_SPOOLER(res)
1785 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1786 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1787 res, GetLastError());
1789 ClosePrinter(hprinter);
1791 defaults.pDatatype=NULL;
1792 defaults.pDevMode=NULL;
1794 defaults.DesiredAccess=0;
1795 hprinter = (HANDLE) MAGIC_DEAD;
1796 SetLastError(MAGIC_DEAD);
1797 res = OpenPrinter(NULL, &hprinter, &defaults);
1798 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1799 if (res) ClosePrinter(hprinter);
1801 defaults.DesiredAccess=-1;
1802 hprinter = (HANDLE) MAGIC_DEAD;
1803 SetLastError(MAGIC_DEAD);
1804 res = OpenPrinter(NULL, &hprinter, &defaults);
1806 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1807 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1808 res, GetLastError());
1810 if (res) ClosePrinter(hprinter);
1815 if (local_server != NULL) {
1816 hprinter = (HANDLE) 0xdeadbeef;
1817 SetLastError(0xdeadbeef);
1818 res = OpenPrinter(local_server, &hprinter, NULL);
1819 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1820 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1821 res, GetLastError());
1822 if(res) ClosePrinter(hprinter);
1825 /* Invalid Printername */
1826 hprinter = (HANDLE) MAGIC_DEAD;
1827 SetLastError(MAGIC_DEAD);
1828 res = OpenPrinter(illegal_name, &hprinter, NULL);
1829 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1830 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1831 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1832 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1833 if(res) ClosePrinter(hprinter);
1835 hprinter = (HANDLE) MAGIC_DEAD;
1836 SetLastError(MAGIC_DEAD);
1837 res = OpenPrinter(empty, &hprinter, NULL);
1838 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1840 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1841 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1842 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1843 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1844 if(res) ClosePrinter(hprinter);
1847 /* Get Handle for the default Printer */
1848 if (default_printer)
1850 hprinter = (HANDLE) MAGIC_DEAD;
1851 SetLastError(MAGIC_DEAD);
1852 res = OpenPrinter(default_printer, &hprinter, NULL);
1853 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1855 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1858 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1859 if(res) ClosePrinter(hprinter);
1861 SetLastError(MAGIC_DEAD);
1862 res = OpenPrinter(default_printer, NULL, NULL);
1863 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1864 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1865 "returned %d with %d (expected '!=0' or '0' with "
1866 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1868 defaults.pDatatype=NULL;
1869 defaults.pDevMode=NULL;
1870 defaults.DesiredAccess=0;
1872 hprinter = (HANDLE) MAGIC_DEAD;
1873 SetLastError(MAGIC_DEAD);
1874 res = OpenPrinter(default_printer, &hprinter, &defaults);
1875 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1876 "returned %d with %d (expected '!=0' or '0' with "
1877 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1878 if(res) ClosePrinter(hprinter);
1880 defaults.pDatatype = empty;
1882 hprinter = (HANDLE) MAGIC_DEAD;
1883 SetLastError(MAGIC_DEAD);
1884 res = OpenPrinter(default_printer, &hprinter, &defaults);
1885 /* stop here, when a remote Printserver has no RPC-Service running */
1886 RETURN_ON_DEACTIVATED_SPOOLER(res)
1887 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1888 (GetLastError() == ERROR_ACCESS_DENIED)),
1889 "returned %d with %d (expected '!=0' or '0' with: "
1890 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1891 res, GetLastError());
1892 if(res) ClosePrinter(hprinter);
1895 defaults.pDatatype=NULL;
1896 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1898 hprinter = (HANDLE) MAGIC_DEAD;
1899 SetLastError(MAGIC_DEAD);
1900 res = OpenPrinter(default_printer, &hprinter, &defaults);
1901 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1902 "returned %d with %d (expected '!=0' or '0' with "
1903 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1904 if(res) ClosePrinter(hprinter);
1907 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1908 hprinter = (HANDLE) MAGIC_DEAD;
1909 SetLastError(MAGIC_DEAD);
1910 res = OpenPrinter(default_printer, &hprinter, &defaults);
1911 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1912 "returned %d with %d (expected '!=0' or '0' with "
1913 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1914 if(res) ClosePrinter(hprinter);
1920 static void test_SetDefaultPrinter(void)
1923 DWORD size = DEFAULT_PRINTER_SIZE;
1924 CHAR buffer[DEFAULT_PRINTER_SIZE];
1925 CHAR org_value[DEFAULT_PRINTER_SIZE];
1927 if (!default_printer)
1929 skip("There is no default printer installed\n");
1933 if (!pSetDefaultPrinterA) return;
1934 /* only supported on win2k and above */
1936 /* backup the original value */
1937 org_value[0] = '\0';
1938 SetLastError(MAGIC_DEAD);
1939 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1941 /* first part: with the default Printer */
1942 SetLastError(MAGIC_DEAD);
1943 res = pSetDefaultPrinterA("no_printer_with_this_name");
1945 RETURN_ON_DEACTIVATED_SPOOLER(res)
1946 /* spooler is running or we have no spooler here*/
1948 /* Not implemented in wine */
1949 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1950 trace("SetDefaultPrinterA() not implemented yet.\n");
1954 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1955 "returned %d with %d (expected '0' with "
1956 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1958 WriteProfileStringA("windows", "device", org_value);
1959 SetLastError(MAGIC_DEAD);
1960 res = pSetDefaultPrinterA("");
1961 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1962 "returned %d with %d (expected '!=0' or '0' with "
1963 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1965 WriteProfileStringA("windows", "device", org_value);
1966 SetLastError(MAGIC_DEAD);
1967 res = pSetDefaultPrinterA(NULL);
1968 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1969 "returned %d with %d (expected '!=0' or '0' with "
1970 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1972 WriteProfileStringA("windows", "device", org_value);
1973 SetLastError(MAGIC_DEAD);
1974 res = pSetDefaultPrinterA(default_printer);
1975 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1976 "returned %d with %d (expected '!=0' or '0' with "
1977 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1980 /* second part: always without a default Printer */
1981 WriteProfileStringA("windows", "device", NULL);
1982 SetLastError(MAGIC_DEAD);
1983 res = pSetDefaultPrinterA("no_printer_with_this_name");
1985 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1986 "returned %d with %d (expected '0' with "
1987 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1989 WriteProfileStringA("windows", "device", NULL);
1990 SetLastError(MAGIC_DEAD);
1991 res = pSetDefaultPrinterA("");
1992 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1993 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1994 "returned %d with %d (expected '!=0' or '0' with "
1995 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1997 WriteProfileStringA("windows", "device", NULL);
1998 SetLastError(MAGIC_DEAD);
1999 res = pSetDefaultPrinterA(NULL);
2000 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
2001 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
2002 "returned %d with %d (expected '!=0' or '0' with "
2003 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2005 WriteProfileStringA("windows", "device", NULL);
2006 SetLastError(MAGIC_DEAD);
2007 res = pSetDefaultPrinterA(default_printer);
2008 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
2009 "returned %d with %d (expected '!=0' or '0' with "
2010 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2012 /* restore the original value */
2013 res = pSetDefaultPrinterA(default_printer); /* the nice way */
2014 WriteProfileStringA("windows", "device", org_value); /* the old way */
2017 SetLastError(MAGIC_DEAD);
2018 res = GetProfileStringA("windows", "device", NULL, buffer, size);
2019 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
2023 /* ########################### */
2025 static void test_XcvDataW_MonitorUI(void)
2029 BYTE buffer[MAX_PATH + 4];
2033 PRINTER_DEFAULTSA pd;
2035 /* api is not present before w2k */
2036 if (pXcvDataW == NULL) return;
2038 pd.pDatatype = NULL;
2040 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2043 SetLastError(0xdeadbeef);
2044 res = OpenPrinter(xcv_localport, &hXcv, &pd);
2045 RETURN_ON_DEACTIVATED_SPOOLER(res)
2046 RETURN_ON_ACCESS_DENIED(res)
2048 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2051 /* ask for needed size */
2052 needed = (DWORD) 0xdeadbeef;
2053 status = (DWORD) 0xdeadbeef;
2054 SetLastError(0xdeadbeef);
2055 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed, &status);
2056 ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
2057 "returned %d with %u and %u for status %u (expected '!= 0' and "
2058 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
2059 res, GetLastError(), needed, status);
2061 if (needed > MAX_PATH) {
2063 skip("buffer overflow (%u)\n", needed);
2066 len = needed; /* Size is in bytes */
2068 /* the command is required */
2069 needed = (DWORD) 0xdeadbeef;
2070 status = (DWORD) 0xdeadbeef;
2071 SetLastError(0xdeadbeef);
2072 res = pXcvDataW(hXcv, emptyW, NULL, 0, NULL, 0, &needed, &status);
2073 ok( res && (status == ERROR_INVALID_PARAMETER),
2074 "returned %d with %u and %u for status %u (expected '!= 0' with "
2075 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2077 needed = (DWORD) 0xdeadbeef;
2078 status = (DWORD) 0xdeadbeef;
2079 SetLastError(0xdeadbeef);
2080 res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
2081 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2082 "returned %d with %u and %u for status %u (expected '0' with "
2083 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2085 /* "PDWORD needed" is checked before RPC-Errors */
2086 needed = (DWORD) 0xdeadbeef;
2087 status = (DWORD) 0xdeadbeef;
2088 SetLastError(0xdeadbeef);
2089 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, NULL, &status);
2090 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2091 "returned %d with %u and %u for status %u (expected '0' with "
2092 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2094 needed = (DWORD) 0xdeadbeef;
2095 status = (DWORD) 0xdeadbeef;
2096 SetLastError(0xdeadbeef);
2097 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, len, &needed, &status);
2098 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2099 "returned %d with %u and %u for status %u (expected '0' with "
2100 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2102 needed = (DWORD) 0xdeadbeef;
2103 status = (DWORD) 0xdeadbeef;
2104 SetLastError(0xdeadbeef);
2105 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, NULL);
2106 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2107 "returned %d with %u and %u for status %u (expected '0' with "
2108 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2110 /* off by one: larger */
2111 needed = (DWORD) 0xdeadbeef;
2112 status = (DWORD) 0xdeadbeef;
2113 SetLastError(0xdeadbeef);
2114 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len+1, &needed, &status);
2115 ok( res && (status == ERROR_SUCCESS),
2116 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2117 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2119 /* off by one: smaller */
2120 /* the buffer is not modified for NT4, w2k, XP */
2121 needed = (DWORD) 0xdeadbeef;
2122 status = (DWORD) 0xdeadbeef;
2123 SetLastError(0xdeadbeef);
2124 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len-1, &needed, &status);
2125 ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
2126 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2127 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
2130 /* Normal use. The DLL-Name without a Path is returned */
2131 memset(buffer, 0, len);
2132 needed = (DWORD) 0xdeadbeef;
2133 status = (DWORD) 0xdeadbeef;
2134 SetLastError(0xdeadbeef);
2135 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, &status);
2136 ok( res && (status == ERROR_SUCCESS),
2137 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2138 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2143 /* ########################### */
2145 static void test_XcvDataW_PortIsValid(void)
2151 PRINTER_DEFAULTSA pd;
2153 /* api is not present before w2k */
2154 if (pXcvDataW == NULL) return;
2156 pd.pDatatype = NULL;
2158 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2161 SetLastError(0xdeadbeef);
2162 res = OpenPrinter(xcv_localport, &hXcv, &pd);
2164 RETURN_ON_DEACTIVATED_SPOOLER(res)
2165 RETURN_ON_ACCESS_DENIED(res)
2167 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2171 /* "PDWORD needed" is always required */
2172 needed = (DWORD) 0xdeadbeef;
2173 status = (DWORD) 0xdeadbeef;
2174 SetLastError(0xdeadbeef);
2175 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, NULL, &status);
2176 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2177 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2178 res, GetLastError(), needed, status);
2180 /* an empty name is not allowed */
2181 needed = (DWORD) 0xdeadbeef;
2182 status = (DWORD) 0xdeadbeef;
2183 SetLastError(0xdeadbeef);
2184 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) emptyW, sizeof(emptyW), NULL, 0, &needed, &status);
2185 ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
2186 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2187 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2188 res, GetLastError(), needed, status);
2190 /* a directory is not allowed */
2191 needed = (DWORD) 0xdeadbeef;
2192 status = (DWORD) 0xdeadbeef;
2193 SetLastError(0xdeadbeef);
2194 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2195 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2196 ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
2197 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2198 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2199 res, GetLastError(), needed, status);
2201 /* more valid well known Ports */
2202 needed = (DWORD) 0xdeadbeef;
2203 status = (DWORD) 0xdeadbeef;
2204 SetLastError(0xdeadbeef);
2205 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed, &status);
2206 ok( res && (status == ERROR_SUCCESS),
2207 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2208 res, GetLastError(), needed, status);
2210 needed = (DWORD) 0xdeadbeef;
2211 status = (DWORD) 0xdeadbeef;
2212 SetLastError(0xdeadbeef);
2213 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt2W, sizeof(portname_lpt2W), NULL, 0, &needed, &status);
2214 ok( res && (status == ERROR_SUCCESS),
2215 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2216 res, GetLastError(), needed, status);
2218 needed = (DWORD) 0xdeadbeef;
2219 status = (DWORD) 0xdeadbeef;
2220 SetLastError(0xdeadbeef);
2221 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com1W, sizeof(portname_com1W), NULL, 0, &needed, &status);
2222 ok( res && (status == ERROR_SUCCESS),
2223 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2224 res, GetLastError(), needed, status);
2226 needed = (DWORD) 0xdeadbeef;
2227 status = (DWORD) 0xdeadbeef;
2228 SetLastError(0xdeadbeef);
2229 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com2W, sizeof(portname_com2W), NULL, 0, &needed, &status);
2230 ok( res && (status == ERROR_SUCCESS),
2231 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2232 res, GetLastError(), needed, status);
2234 needed = (DWORD) 0xdeadbeef;
2235 status = (DWORD) 0xdeadbeef;
2236 SetLastError(0xdeadbeef);
2237 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_fileW, sizeof(portname_fileW), NULL, 0, &needed, &status);
2238 ok( res && (status == ERROR_SUCCESS),
2239 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2240 res, GetLastError(), needed, status);
2243 /* a normal, writable file is allowed */
2244 needed = (DWORD) 0xdeadbeef;
2245 status = (DWORD) 0xdeadbeef;
2246 SetLastError(0xdeadbeef);
2247 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2248 ok( res && (status == ERROR_SUCCESS),
2249 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2250 res, GetLastError(), needed, status);
2255 /* ########################### */
2257 static void test_GetPrinter(void)
2263 DWORD needed, filled;
2265 if (!default_printer)
2267 skip("There is no default printer installed\n");
2272 ret = OpenPrinter(default_printer, &hprn, NULL);
2275 skip("Unable to open the default printer (%s)\n", default_printer);
2278 ok(hprn != 0, "wrong hprn %p\n", hprn);
2280 for (level = 1; level <= 9; level++)
2282 SetLastError(0xdeadbeef);
2284 ret = GetPrinter(hprn, level, NULL, 0, &needed);
2287 win_skip("Level %d is not supported on Win9x/WinMe\n", level);
2288 ok(GetLastError() == ERROR_SUCCESS, "wrong error %d\n", GetLastError());
2289 ok(needed == 0,"Expected 0, got %d\n", needed);
2292 ok(!ret, "level %d: GetPrinter should fail\n", level);
2293 /* Not all levels are supported on all Windows-Versions */
2294 if (GetLastError() == ERROR_INVALID_LEVEL ||
2295 GetLastError() == ERROR_NOT_SUPPORTED /* Win9x/WinMe */)
2297 skip("Level %d not supported\n", level);
2300 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2301 ok(needed > 0,"not expected needed buffer size %d\n", needed);
2303 /* GetPrinterA returns the same number of bytes as GetPrinterW */
2304 if (!on_win9x && !ret && pGetPrinterW && level != 6 && level != 7)
2306 DWORD double_needed;
2307 ret = pGetPrinterW(hprn, level, NULL, 0, &double_needed);
2308 ok(double_needed == needed, "level %d: GetPrinterA returned different size %d than GetPrinterW (%d)\n", level, needed, double_needed);
2311 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2313 SetLastError(0xdeadbeef);
2315 ret = GetPrinter(hprn, level, buf, needed, &filled);
2316 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2320 PRINTER_INFO_2 *pi_2 = (PRINTER_INFO_2 *)buf;
2322 ok(pi_2->pPrinterName!= NULL, "not expected NULL ptr\n");
2323 ok(pi_2->pDriverName!= NULL, "not expected NULL ptr\n");
2325 trace("pPrinterName %s\n", pi_2->pPrinterName);
2326 trace("pDriverName %s\n", pi_2->pDriverName);
2329 HeapFree(GetProcessHeap(), 0, buf);
2332 SetLastError(0xdeadbeef);
2333 ret = ClosePrinter(hprn);
2334 ok(ret, "ClosePrinter error %d\n", GetLastError());
2337 /* ########################### */
2339 static void test_GetPrinterData(void)
2344 CHAR buffer[MAX_PATH + 1];
2348 /* ToDo: test parameter validation, test with the default printer */
2350 SetLastError(0xdeadbeef);
2351 res = OpenPrinter(NULL, &hprn, NULL);
2354 /* printserver not available on win9x */
2356 win_skip("Unable to open the printserver: %d\n", GetLastError());
2360 memset(buffer, '#', sizeof(buffer));
2361 buffer[MAX_PATH] = 0;
2363 needed = 0xdeadbeef;
2364 SetLastError(0xdeadbeef);
2365 res = GetPrinterDataA(hprn, defaultspooldirectory, &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2367 len = lstrlenA(buffer) + sizeof(CHAR);
2368 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2369 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2370 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2371 res, type, needed, buffer, len);
2373 needed = 0xdeadbeef;
2374 SetLastError(0xdeadbeef);
2375 res = GetPrinterDataA(hprn, defaultspooldirectory, NULL, NULL, 0, &needed);
2376 ok( (res == ERROR_MORE_DATA) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2377 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res, needed, len);
2379 /* ToDo: test SPLREG_* */
2381 SetLastError(0xdeadbeef);
2382 res = ClosePrinter(hprn);
2383 ok(res, "ClosePrinter error %d\n", GetLastError());
2386 /* ########################### */
2388 static void test_GetPrinterDataEx(void)
2393 CHAR buffer[MAX_PATH + 1];
2397 /* not present before w2k */
2398 if (!pGetPrinterDataExA) {
2399 win_skip("GetPrinterDataEx not found\n");
2403 /* ToDo: test parameter validation, test with the default printer */
2405 SetLastError(0xdeadbeef);
2406 res = OpenPrinter(NULL, &hprn, NULL);
2409 win_skip("Unable to open the printserver: %d\n", GetLastError());
2413 /* keyname is ignored, when hprn is a HANDLE for a printserver */
2414 memset(buffer, '#', sizeof(buffer));
2415 buffer[MAX_PATH] = 0;
2417 needed = 0xdeadbeef;
2418 SetLastError(0xdeadbeef);
2419 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, &type,
2420 (LPBYTE) buffer, sizeof(buffer), &needed);
2422 len = lstrlenA(buffer) + sizeof(CHAR);
2423 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2424 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2425 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2426 res, type, needed, buffer, len);
2428 memset(buffer, '#', sizeof(buffer));
2429 buffer[MAX_PATH] = 0;
2431 needed = 0xdeadbeef;
2432 SetLastError(0xdeadbeef);
2433 res = pGetPrinterDataExA(hprn, "", defaultspooldirectory, &type,
2434 (LPBYTE) buffer, sizeof(buffer), &needed);
2435 len = lstrlenA(buffer) + sizeof(CHAR);
2436 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2437 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2438 res, type, needed, buffer, len);
2440 memset(buffer, '#', sizeof(buffer));
2441 buffer[MAX_PATH] = 0;
2443 needed = 0xdeadbeef;
2444 SetLastError(0xdeadbeef);
2445 /* Wine uses GetPrinterDataEx with "PrinterDriverData" to implement GetPrinterData */
2446 res = pGetPrinterDataExA(hprn, "PrinterDriverData", defaultspooldirectory,
2447 &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2448 len = lstrlenA(buffer) + sizeof(CHAR);
2449 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2450 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2451 res, type, needed, buffer, len);
2454 memset(buffer, '#', sizeof(buffer));
2455 buffer[MAX_PATH] = 0;
2457 needed = 0xdeadbeef;
2458 SetLastError(0xdeadbeef);
2459 res = pGetPrinterDataExA(hprn, does_not_exist, defaultspooldirectory, &type,
2460 (LPBYTE) buffer, sizeof(buffer), &needed);
2461 len = lstrlenA(buffer) + sizeof(CHAR);
2462 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2463 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2464 res, type, needed, buffer, len);
2466 needed = 0xdeadbeef;
2467 SetLastError(0xdeadbeef);
2468 /* vista and w2k8 have a bug in GetPrinterDataEx:
2469 the current LastError value is returned as result */
2470 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2471 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeadbeef)) &&
2472 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2473 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res, needed, len);
2475 needed = 0xdeadbeef;
2476 SetLastError(0xdeaddead);
2477 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2478 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeaddead)) &&
2479 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2480 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res, needed, len);
2482 SetLastError(0xdeadbeef);
2483 res = ClosePrinter(hprn);
2484 ok(res, "ClosePrinter error %d\n", GetLastError());
2487 /* ########################### */
2489 static void test_GetPrinterDriver(void)
2495 DWORD needed, filled;
2497 if (!default_printer)
2499 skip("There is no default printer installed\n");
2504 ret = OpenPrinter(default_printer, &hprn, NULL);
2507 skip("Unable to open the default printer (%s)\n", default_printer);
2510 ok(hprn != 0, "wrong hprn %p\n", hprn);
2512 for (level = -1; level <= 7; level++)
2514 SetLastError(0xdeadbeef);
2516 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
2517 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
2518 if (level >= 1 && level <= 6)
2520 /* Not all levels are supported on all Windows-Versions */
2521 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
2522 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2523 ok(needed > 0,"not expected needed buffer size %d\n", needed);
2527 /* ERROR_OUTOFMEMORY found on win9x */
2528 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
2529 (GetLastError() == ERROR_OUTOFMEMORY)),
2530 "%d: returned %d with %d (expected '0' with: "
2531 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2532 level, ret, GetLastError());
2533 /* needed is modified in win9x. The modified Value depends on the
2534 default Printer. testing for "needed == (DWORD)-1" will fail */
2538 /* GetPrinterDriverA returns the same number of bytes as GetPrinterDriverW */
2539 if (!on_win9x && !ret && pGetPrinterDriverW)
2541 DWORD double_needed;
2542 ret = pGetPrinterDriverW(hprn, NULL, level, NULL, 0, &double_needed);
2543 ok(double_needed == needed, "GetPrinterDriverA returned different size %d than GetPrinterDriverW (%d)\n", needed, double_needed);
2546 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2548 SetLastError(0xdeadbeef);
2550 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
2551 ok(ret, "level %d: GetPrinterDriver error %d\n", level, GetLastError());
2552 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2556 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
2557 DWORD calculated = sizeof(*di_2);
2560 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2561 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
2562 ok( (di_2->cVersion <= 3) ||
2563 (di_2->cVersion == 0x0400), "di_2->cVersion = %d\n", di_2->cVersion);
2564 ok(di_2->pName != NULL, "not expected NULL ptr\n");
2565 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
2566 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
2567 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
2568 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
2570 trace("cVersion %d\n", di_2->cVersion);
2571 trace("pName %s\n", di_2->pName);
2572 calculated += strlen(di_2->pName) + 1;
2573 trace("pEnvironment %s\n", di_2->pEnvironment);
2574 calculated += strlen(di_2->pEnvironment) + 1;
2575 trace("pDriverPath %s\n", di_2->pDriverPath);
2576 calculated += strlen(di_2->pDriverPath) + 1;
2577 trace("pDataFile %s\n", di_2->pDataFile);
2578 calculated += strlen(di_2->pDataFile) + 1;
2579 trace("pConfigFile %s\n", di_2->pConfigFile);
2580 calculated += strlen(di_2->pConfigFile) + 1;
2582 hf = CreateFileA(di_2->pDriverPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2583 if(hf != INVALID_HANDLE_VALUE)
2586 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDriverPath);
2588 hf = CreateFileA(di_2->pDataFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2589 if(hf != INVALID_HANDLE_VALUE)
2592 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDataFile);
2594 hf = CreateFileA(di_2->pConfigFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2595 if(hf != INVALID_HANDLE_VALUE)
2598 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pConfigFile);
2600 /* XP allocates memory for both ANSI and unicode names */
2601 ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
2603 /* Obscure test - demonstrate that Windows zero fills the buffer, even on failure */
2604 if (di_2->pDataFile)
2606 ret = GetPrinterDriver(hprn, NULL, level, buf, needed - 2, &filled);
2607 ok(!ret, "level %d: GetPrinterDriver succeeded with less buffer than it should\n", level);
2608 ok(di_2->pDataFile == NULL ||
2609 broken(di_2->pDataFile != NULL), /* Win9x/WinMe */
2610 "Even on failure, GetPrinterDriver clears the buffer to zeros\n");
2614 HeapFree(GetProcessHeap(), 0, buf);
2617 SetLastError(0xdeadbeef);
2618 ret = ClosePrinter(hprn);
2619 ok(ret, "ClosePrinter error %d\n", GetLastError());
2622 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
2624 /* On NT3.51, some fields in DEVMODE are empty/zero
2625 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2626 We skip the Tests on this Platform */
2627 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
2628 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2629 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1) ||
2630 !strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -2), /* XP+ */
2631 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
2632 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
2633 "%u != %d\n", dm->dmSize + dm->dmDriverExtra, dmSize);
2635 trace("dmFields %08x\n", dm->dmFields);
2638 static void test_DocumentProperties(void)
2644 if (!default_printer)
2646 skip("There is no default printer installed\n");
2651 ret = OpenPrinter(default_printer, &hprn, NULL);
2654 skip("Unable to open the default printer (%s)\n", default_printer);
2657 ok(hprn != 0, "wrong hprn %p\n", hprn);
2659 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
2660 trace("DEVMODE required size %d\n", dm_size);
2661 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %d\n", dm_size);
2663 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
2665 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
2666 ok(ret == IDOK, "DocumentProperties ret value %d != expected IDOK\n", ret);
2668 test_DEVMODE(dm, dm_size, default_printer);
2670 HeapFree(GetProcessHeap(), 0, dm);
2672 SetLastError(0xdeadbeef);
2673 ret = ClosePrinter(hprn);
2674 ok(ret, "ClosePrinter error %d\n", GetLastError());
2677 static void test_EnumPrinters(void)
2679 DWORD neededA, neededW, num;
2682 SetLastError(0xdeadbeef);
2684 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
2685 RETURN_ON_DEACTIVATED_SPOOLER(ret)
2688 /* We have 1 or more printers */
2689 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2690 ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
2694 /* We don't have any printers defined */
2695 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2696 ok(neededA == 0, "Expected neededA to be zero\n");
2698 ok(num == 0, "num %d\n", num);
2700 SetLastError(0xdeadbeef);
2702 ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
2703 /* EnumPrintersW is not supported on all platforms */
2704 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
2706 win_skip("EnumPrintersW is not implemented\n");
2712 /* We have 1 or more printers */
2713 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2714 ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
2718 /* We don't have any printers defined */
2719 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2720 ok(neededW == 0, "Expected neededW to be zero\n");
2722 ok(num == 0, "num %d\n", num);
2724 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2725 to hold the buffer returned by EnumPrintersW */
2726 ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
2729 static void test_DeviceCapabilities(void)
2732 BOOL (WINAPI *pPrintDlgA)(PRINTDLGA *);
2736 const char *driver, *device, *port;
2744 INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
2747 hComdlg32 = LoadLibrary("comdlg32.dll");
2749 pPrintDlgA = (void *)GetProcAddress(hComdlg32, "PrintDlgA");
2752 memset(&prn_dlg, 0, sizeof(prn_dlg));
2753 prn_dlg.lStructSize = sizeof(prn_dlg);
2754 prn_dlg.Flags = PD_RETURNDEFAULT;
2755 ret = pPrintDlgA(&prn_dlg);
2756 FreeLibrary(hComdlg32);
2759 skip("PrintDlg returned no default printer\n");
2762 ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
2763 ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
2765 dm = GlobalLock(prn_dlg.hDevMode);
2766 ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
2767 trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
2769 dn = GlobalLock(prn_dlg.hDevNames);
2770 ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
2771 ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
2772 ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
2773 ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
2774 ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
2775 driver = (const char *)dn + dn->wDriverOffset;
2776 device = (const char *)dn + dn->wDeviceOffset;
2777 port = (const char *)dn + dn->wOutputOffset;
2778 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
2780 test_DEVMODE(dm, dm->dmSize + dm->dmDriverExtra, device);
2782 n_papers = DeviceCapabilities(device, port, DC_PAPERS, NULL, NULL);
2783 ok(n_papers > 0, "DeviceCapabilities DC_PAPERS failed\n");
2784 papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
2785 ret = DeviceCapabilities(device, port, DC_PAPERS, (LPSTR)papers, NULL);
2786 ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
2788 for (ret = 0; ret < n_papers; ret++)
2789 trace("papers[%d] = %d\n", ret, papers[ret]);
2791 HeapFree(GetProcessHeap(), 0, papers);
2793 n_paper_size = DeviceCapabilities(device, port, DC_PAPERSIZE, NULL, NULL);
2794 ok(n_paper_size > 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
2795 ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
2796 paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
2797 ret = DeviceCapabilities(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
2798 ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
2800 for (ret = 0; ret < n_paper_size; ret++)
2801 trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
2803 HeapFree(GetProcessHeap(), 0, paper_size);
2805 n_paper_names = DeviceCapabilities(device, port, DC_PAPERNAMES, NULL, NULL);
2806 ok(n_paper_names > 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
2807 ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
2808 paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
2809 ret = DeviceCapabilities(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
2810 ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
2812 for (ret = 0; ret < n_paper_names; ret++)
2813 trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
2815 HeapFree(GetProcessHeap(), 0, paper_name);
2817 n_copies = DeviceCapabilities(device, port, DC_COPIES, NULL, dm);
2818 ok(n_copies > 0, "DeviceCapabilities DC_COPIES failed\n");
2819 trace("n_copies = %d\n", n_copies);
2821 /* these capabilities not available on all printer drivers */
2824 ret = DeviceCapabilities(device, port, DC_MAXEXTENT, NULL, NULL);
2825 ok(ret != -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
2826 ext = MAKEPOINTS(ret);
2827 trace("max ext = %d x %d\n", ext.x, ext.y);
2829 ret = DeviceCapabilities(device, port, DC_MINEXTENT, NULL, NULL);
2830 ok(ret != -1, "DeviceCapabilities DC_MINEXTENT failed\n");
2831 ext = MAKEPOINTS(ret);
2832 trace("min ext = %d x %d\n", ext.x, ext.y);
2835 fields = DeviceCapabilities(device, port, DC_FIELDS, NULL, NULL);
2836 ok(fields != (DWORD)-1, "DeviceCapabilities DC_FIELDS failed\n");
2838 ok(fields == (dm->dmFields | DM_FORMNAME) ||
2839 broken(fields == dm->dmFields), /* Win9x/WinMe */
2840 "fields %x != (dm->dmFields | DM_FORMNAME) %lx\n", fields, (dm->dmFields | DM_FORMNAME));
2842 GlobalUnlock(prn_dlg.hDevMode);
2843 GlobalFree(prn_dlg.hDevMode);
2844 GlobalUnlock(prn_dlg.hDevNames);
2845 GlobalFree(prn_dlg.hDevNames);
2850 hwinspool = GetModuleHandleA("winspool.drv");
2851 pAddPortExA = (void *) GetProcAddress(hwinspool, "AddPortExA");
2852 pEnumPrinterDriversW = (void *) GetProcAddress(hwinspool, "EnumPrinterDriversW");
2853 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
2854 pGetPrinterDataExA = (void *) GetProcAddress(hwinspool, "GetPrinterDataExA");
2855 pGetPrinterDriverW = (void *) GetProcAddress(hwinspool, "GetPrinterDriverW");
2856 pGetPrinterW = (void *) GetProcAddress(hwinspool, "GetPrinterW");
2857 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
2858 pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
2860 on_win9x = check_win9x();
2862 win_skip("Several W-functions are not available on Win9x/WinMe\n");
2864 find_default_printer();
2865 find_local_server();
2871 test_ConfigurePort();
2872 test_DeleteMonitor();
2874 test_DeviceCapabilities();
2875 test_DocumentProperties();
2876 test_EnumForms(NULL);
2877 if (default_printer) test_EnumForms(default_printer);
2878 test_EnumMonitors();
2880 test_EnumPrinterDrivers();
2881 test_EnumPrinters();
2882 test_EnumPrintProcessors();
2883 test_GetDefaultPrinter();
2884 test_GetPrinterDriverDirectory();
2885 test_GetPrintProcessorDirectory();
2888 test_GetPrinterData();
2889 test_GetPrinterDataEx();
2890 test_GetPrinterDriver();
2891 test_SetDefaultPrinter();
2892 test_XcvDataW_MonitorUI();
2893 test_XcvDataW_PortIsValid();
2895 /* Cleanup our temporary file */
2896 DeleteFileA(tempfileA);