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
23 #include "wine/test.h"
33 #define MAGIC_DEAD 0xdeadbeef
34 #define DEFAULT_PRINTER_SIZE 1000
36 static CHAR does_not_exist_dll[]= "does_not_exist.dll";
37 static CHAR does_not_exist[] = "does_not_exist";
38 static CHAR empty[] = "";
39 static CHAR env_x86[] = "Windows NT x86";
40 static CHAR env_win9x_case[] = "windowS 4.0";
41 static CHAR illegal_name[] = "illegal,name";
42 static CHAR invalid_env[] = "invalid_env";
43 static CHAR portname_com1[] = "COM1:";
44 static CHAR portname_file[] = "FILE:";
45 static CHAR portname_lpt1[] = "LPT1:";
46 static CHAR server_does_not_exist[] = "\\does_not_exist";
47 static CHAR version_dll[] = "version.dll";
48 static CHAR winetest[] = "winetest";
49 static CHAR xcv_localport[] = ",XcvMonitor Local Port";
51 static WCHAR cmd_MonitorUIW[] = {'M','o','n','i','t','o','r','U','I',0};
52 static WCHAR cmd_PortIsValidW[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
53 static WCHAR emptyW[] = {0};
55 static WCHAR portname_com1W[] = {'C','O','M','1',':',0};
56 static WCHAR portname_com2W[] = {'C','O','M','2',':',0};
57 static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
58 static WCHAR portname_lpt1W[] = {'L','P','T','1',':',0};
59 static WCHAR portname_lpt2W[] = {'L','P','T','2',':',0};
61 static HANDLE hwinspool;
62 static FARPROC pGetDefaultPrinterA;
63 static FARPROC pSetDefaultPrinterA;
64 static DWORD (WINAPI * pXcvDataW)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD, PDWORD);
67 /* ################################ */
69 struct monitor_entry {
74 static LPSTR default_printer = NULL;
75 static LPSTR local_server = NULL;
76 static LPSTR tempdirA = NULL;
77 static LPSTR tempfileA = NULL;
78 static LPWSTR tempdirW = NULL;
79 static LPWSTR tempfileW = NULL;
81 /* ################################ */
82 /* report common behavior only once */
83 static DWORD report_deactivated_spooler = 1;
84 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
85 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
87 if(report_deactivated_spooler > 0) { \
88 report_deactivated_spooler--; \
89 skip("The Service 'Spooler' is required for many test\n"); \
95 static void find_default_printer(VOID)
97 static char buffer[DEFAULT_PRINTER_SIZE];
102 if ((default_printer == NULL) && (pGetDefaultPrinterA))
105 needed = sizeof(buffer);
106 res = pGetDefaultPrinterA(buffer, &needed);
107 if(res) default_printer = buffer;
108 trace("default_printer: '%s'\n", default_printer);
110 if (default_printer == NULL)
114 /* NT 3.x and above */
115 if (RegOpenKeyEx(HKEY_CURRENT_USER,
116 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
117 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
119 needed = sizeof(buffer);
120 if (RegQueryValueEx(hwindows, "device", NULL,
121 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
123 ptr = strchr(buffer, ',');
126 default_printer = buffer;
129 RegCloseKey(hwindows);
131 trace("default_printer: '%s'\n", default_printer);
133 if (default_printer == NULL)
136 needed = sizeof(buffer);
137 res = GetProfileStringA("windows", "device", "*", buffer, needed);
139 ptr = strchr(buffer, ',');
142 default_printer = buffer;
145 trace("default_printer: '%s'\n", default_printer);
150 static struct monitor_entry * find_installed_monitor(void)
152 MONITOR_INFO_2A mi2a;
153 static struct monitor_entry * entry = NULL;
157 static struct monitor_entry monitor_table[] = {
158 {env_win9x_case, "localspl.dll"},
159 {env_x86, "localspl.dll"},
160 {env_win9x_case, "localmon.dll"},
161 {env_x86, "localmon.dll"},
162 {env_win9x_case, "tcpmon.dll"},
163 {env_x86, "tcpmon.dll"},
164 {env_win9x_case, "usbmon.dll"},
165 {env_x86, "usbmon.dll"},
166 {env_win9x_case, "mspp32.dll"},
167 {env_x86, "win32spl.dll"},
168 {env_x86, "redmonnt.dll"},
169 {env_x86, "redmon35.dll"},
170 {env_win9x_case, "redmon95.dll"},
171 {env_x86, "pdfcmnnt.dll"},
172 {env_win9x_case, "pdfcmn95.dll"},
175 if (entry) return entry;
177 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
180 DeleteMonitorA(NULL, env_x86, winetest);
181 DeleteMonitorA(NULL, env_win9x_case, winetest);
183 /* find a usable monitor from the table */
184 mi2a.pName = winetest;
185 while ((entry == NULL) && (i < num_tests)) {
186 entry = &monitor_table[i];
188 mi2a.pEnvironment = entry->env;
189 mi2a.pDLLName = entry->dllname;
191 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
193 trace("using '%s', '%s'\n", entry->env, entry->dllname);
194 DeleteMonitorA(NULL, entry->env, winetest);
205 /* ########################### */
207 static void find_local_server(VOID)
209 static char buffer[MAX_PATH];
213 size = sizeof(buffer) - 3 ;
218 SetLastError(0xdeadbeef);
219 res = GetComputerNameA(&buffer[2], &size);
220 trace("returned %d with %d and %d: '%s'\n", res, GetLastError(), size, buffer);
222 ok( res != 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
223 res, GetLastError(), size, buffer);
225 if (res) local_server = buffer;
228 /* ########################### */
230 static void find_tempfile(VOID)
232 static CHAR buffer_dirA[MAX_PATH];
233 static CHAR buffer_fileA[MAX_PATH];
234 static WCHAR buffer_dirW[MAX_PATH];
235 static WCHAR buffer_fileW[MAX_PATH];
239 memset(buffer_dirA, 0, MAX_PATH - 1);
240 buffer_dirA[MAX_PATH - 1] = '\0';
241 SetLastError(0xdeadbeef);
242 res = GetTempPathA(MAX_PATH, buffer_dirA);
243 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
244 if (res == 0) return;
246 memset(buffer_fileA, 0, MAX_PATH - 1);
247 buffer_fileA[MAX_PATH - 1] = '\0';
248 SetLastError(0xdeadbeef);
249 res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
250 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
251 if (res == 0) return;
253 SetLastError(0xdeadbeef);
254 resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
255 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
256 if (resint == 0) return;
258 SetLastError(0xdeadbeef);
259 resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
260 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
261 if (resint == 0) return;
263 tempdirA = buffer_dirA;
264 tempfileA = buffer_fileA;
265 tempdirW = buffer_dirW;
266 tempfileW = buffer_fileW;
267 trace("tempfile: '%s'\n", tempfileA);
270 /* ########################### */
272 static void test_AddMonitor(void)
274 MONITOR_INFO_2A mi2a;
275 struct monitor_entry * entry = NULL;
278 entry = find_installed_monitor();
280 SetLastError(MAGIC_DEAD);
281 res = AddMonitorA(NULL, 1, NULL);
282 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
283 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
284 res, GetLastError());
286 SetLastError(MAGIC_DEAD);
287 res = AddMonitorA(NULL, 3, NULL);
288 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
289 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
290 res, GetLastError());
294 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
295 SetLastError(MAGIC_DEAD);
296 res = AddMonitorA(NULL, 2, NULL);
297 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
299 ((GetLastError() == MAGIC_DEAD) ||
300 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
301 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
302 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
305 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
306 SetLastError(MAGIC_DEAD);
307 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
308 RETURN_ON_DEACTIVATED_SPOOLER(res)
310 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
311 skip("(ACCESS_DENIED)\n");
315 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
316 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
317 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
318 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
319 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
322 skip("No usable Monitor found\n");
328 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
329 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
330 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
331 is created on win9x and we do not want to hit this bug here. */
333 mi2a.pEnvironment = entry->env;
334 SetLastError(MAGIC_DEAD);
335 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
336 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
339 mi2a.pEnvironment = entry->env;
341 SetLastError(MAGIC_DEAD);
342 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
343 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
345 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
346 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
347 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
348 "ERROR_PRIVILEGE_NOT_HELD)\n",
349 res, GetLastError());
351 mi2a.pName = winetest;
352 SetLastError(MAGIC_DEAD);
353 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
356 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
357 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
358 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
359 "ERROR_PRIVILEGE_NOT_HELD)\n",
360 res, GetLastError());
362 mi2a.pDLLName = empty;
363 SetLastError(MAGIC_DEAD);
364 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
365 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
366 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
367 res, GetLastError());
369 mi2a.pDLLName = does_not_exist_dll;
370 SetLastError(MAGIC_DEAD);
371 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
372 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
374 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
375 (GetLastError() == ERROR_INVALID_PARAMETER)),
376 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
377 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
379 mi2a.pDLLName = version_dll;
380 SetLastError(MAGIC_DEAD);
381 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
382 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
384 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
385 (GetLastError() == ERROR_INVALID_PARAMETER)),
386 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
387 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
388 if (res) DeleteMonitorA(NULL, entry->env, winetest);
390 /* Test AddMonitor with real options */
391 mi2a.pDLLName = entry->dllname;
392 SetLastError(MAGIC_DEAD);
393 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
394 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
396 /* add a monitor twice */
397 SetLastError(MAGIC_DEAD);
398 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
399 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
401 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
402 (GetLastError() == ERROR_ALREADY_EXISTS)),
403 "returned %d with %d (expected '0' with: "
404 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
405 res, GetLastError());
407 DeleteMonitorA(NULL, entry->env, winetest);
408 SetLastError(MAGIC_DEAD);
409 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
410 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
413 DeleteMonitorA(NULL, entry->env, winetest);
417 /* ########################### */
419 static void test_AddPort(void)
423 SetLastError(0xdeadbeef);
424 res = AddPortA(NULL, 0, NULL);
425 RETURN_ON_DEACTIVATED_SPOOLER(res)
426 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
427 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
428 (GetLastError() == ERROR_INVALID_PARAMETER)),
429 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
430 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
433 SetLastError(0xdeadbeef);
434 res = AddPortA(NULL, 0, empty);
435 /* Allowed only for (Printer-)Administrators */
436 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
437 skip("(ACCESS_DENIED)\n");
440 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
441 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
442 (GetLastError() == ERROR_INVALID_PARAMETER)),
443 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
444 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
447 SetLastError(0xdeadbeef);
448 res = AddPortA(NULL, 0, does_not_exist);
449 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
450 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
451 (GetLastError() == ERROR_INVALID_PARAMETER)),
452 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
453 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
457 /* ########################### */
459 static void test_ConfigurePort(void)
464 SetLastError(0xdeadbeef);
465 res = ConfigurePortA(NULL, 0, NULL);
466 RETURN_ON_DEACTIVATED_SPOOLER(res)
467 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
468 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
469 (GetLastError() == ERROR_INVALID_PARAMETER)),
470 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
471 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
473 SetLastError(0xdeadbeef);
474 res = ConfigurePortA(NULL, 0, empty);
475 /* Allowed only for (Printer-)Administrators */
476 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
477 skip("(ACCESS_DENIED)\n");
480 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
481 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
482 (GetLastError() == ERROR_INVALID_PARAMETER)),
483 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
484 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
487 SetLastError(0xdeadbeef);
488 res = ConfigurePortA(NULL, 0, does_not_exist);
489 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
490 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
491 (GetLastError() == ERROR_INVALID_PARAMETER)),
492 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
493 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
497 - Case of Portnames is ignored
498 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
499 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
501 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
502 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
503 - Cancel ("Local Port") => ERROR_CANCELED
504 - Cancel ("Redirected Port") => Success
506 if (winetest_interactive > 0) {
507 SetLastError(0xdeadbeef);
508 res = ConfigurePortA(NULL, 0, portname_com1);
509 trace("'%s' returned %d with %d\n", portname_com1, res, GetLastError());
511 SetLastError(0xdeadbeef);
512 res = ConfigurePortA(NULL, 0, portname_lpt1);
513 trace("'%s' returned %d with %d\n", portname_lpt1, res, GetLastError());
515 SetLastError(0xdeadbeef);
516 res = ConfigurePortA(NULL, 0, portname_file);
517 trace("'%s' returned %d with %d\n", portname_file, res, GetLastError());
521 /* ########################### */
523 static void test_DeleteMonitor(void)
525 MONITOR_INFO_2A mi2a;
526 struct monitor_entry * entry = NULL;
530 entry = find_installed_monitor();
533 skip("No usable Monitor found\n");
537 mi2a.pName = winetest;
538 mi2a.pEnvironment = entry->env;
539 mi2a.pDLLName = entry->dllname;
541 /* Testing DeleteMonitor with real options */
542 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
544 SetLastError(MAGIC_DEAD);
545 res = DeleteMonitorA(NULL, entry->env, winetest);
546 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
548 /* Delete the Monitor twice */
549 SetLastError(MAGIC_DEAD);
550 res = DeleteMonitorA(NULL, entry->env, winetest);
551 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
553 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
554 (GetLastError() == ERROR_INVALID_PARAMETER)),
555 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
556 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
558 /* the environment */
559 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
560 SetLastError(MAGIC_DEAD);
561 res = DeleteMonitorA(NULL, NULL, winetest);
562 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
564 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
565 SetLastError(MAGIC_DEAD);
566 res = DeleteMonitorA(NULL, empty, winetest);
567 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
569 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
570 SetLastError(MAGIC_DEAD);
571 res = DeleteMonitorA(NULL, invalid_env, winetest);
572 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
574 /* the monitor-name */
575 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
576 SetLastError(MAGIC_DEAD);
577 res = DeleteMonitorA(NULL, entry->env, NULL);
578 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
580 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
581 (GetLastError() == ERROR_INVALID_NAME)),
582 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
583 "ERROR_INVALID_NAME)\n", res, GetLastError());
585 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
586 SetLastError(MAGIC_DEAD);
587 res = DeleteMonitorA(NULL, entry->env, empty);
588 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
590 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
591 (GetLastError() == ERROR_INVALID_NAME)),
592 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
593 "ERROR_INVALID_NAME)\n", res, GetLastError());
595 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
596 SetLastError(MAGIC_DEAD);
597 res = DeleteMonitorA(empty, entry->env, winetest);
598 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
601 DeleteMonitorA(NULL, entry->env, winetest);
604 /* ########################### */
606 static void test_DeletePort(void)
610 SetLastError(0xdeadbeef);
611 res = DeletePortA(NULL, 0, NULL);
612 RETURN_ON_DEACTIVATED_SPOOLER(res)
614 SetLastError(0xdeadbeef);
615 res = DeletePortA(NULL, 0, empty);
616 /* Allowed only for (Printer-)Administrators */
617 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
618 skip("(ACCESS_DENIED)\n");
621 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
622 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
623 (GetLastError() == ERROR_INVALID_PARAMETER)),
624 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
625 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
628 SetLastError(0xdeadbeef);
629 res = DeletePortA(NULL, 0, does_not_exist);
630 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
631 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
632 (GetLastError() == ERROR_INVALID_PARAMETER)),
633 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
634 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
638 /* ########################### */
640 static void test_EnumForms(LPSTR pName)
651 res = OpenPrinter(pName, &hprinter, NULL);
652 RETURN_ON_DEACTIVATED_SPOOLER(res)
653 if (!res || !hprinter)
655 /* Open the local Prinserver is not supported on win9x */
656 if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
660 /* valid levels are 1 and 2 */
661 for(level = 0; level < 4; level++) {
663 pcReturned = 0xdeadbeef;
664 SetLastError(0xdeadbeef);
665 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
667 /* EnumForms is not implemented in win9x */
668 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
670 /* EnumForms for the Server not implemented on all NT-Versions */
671 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
673 /* Level 2 for EnumForms is not supported on all systems */
674 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
676 /* use only a short test, when we test with an invalid level */
677 if(!level || (level > 2)) {
678 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
679 (res && (pcReturned == 0)),
680 "(%d) returned %d with %d and 0x%08x (expected '0' with "
681 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
682 level, res, GetLastError(), pcReturned);
686 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
687 "(%d) returned %d with %d (expected '0' with "
688 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
690 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
691 if (buffer == NULL) continue;
693 SetLastError(0xdeadbeef);
694 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
695 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
696 level, res, GetLastError());
697 /* We can dump the returned Data here */
700 SetLastError(0xdeadbeef);
701 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
702 ok( res, "(%d) returned %d with %d (expected '!=0')\n",
703 level, res, GetLastError());
705 SetLastError(0xdeadbeef);
706 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
707 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
708 "(%d) returned %d with %d (expected '0' with "
709 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
712 SetLastError(0xdeadbeef);
713 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
714 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
715 "(%d) returned %d with %d (expected '0' with "
716 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
719 SetLastError(0xdeadbeef);
720 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
721 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
722 "(%d) returned %d with %d (expected '0' with "
723 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
725 SetLastError(0xdeadbeef);
726 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
727 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
728 "(%d) returned %d with %d (expected '0' with "
729 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
731 SetLastError(0xdeadbeef);
732 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
733 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
734 "(%d) returned %d with %d (expected '0' with "
735 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
737 HeapFree(GetProcessHeap(), 0, buffer);
738 } /* for(level ... */
740 ClosePrinter(hprinter);
743 /* ########################### */
745 static void test_EnumMonitors(void)
754 /* valid levels are 1 and 2 */
755 for(level = 0; level < 4; level++) {
757 pcReturned = MAGIC_DEAD;
758 SetLastError(MAGIC_DEAD);
759 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
761 RETURN_ON_DEACTIVATED_SPOOLER(res)
763 /* not implemented yet in wine */
764 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
767 /* use only a short test, when we test with an invalid level */
768 if(!level || (level > 2)) {
769 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
770 (res && (pcReturned == 0)),
771 "(%d) returned %d with %d and 0x%08x (expected '0' with "
772 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
773 level, res, GetLastError(), pcReturned);
777 /* Level 2 is not supported on win9x */
778 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
779 skip("Level %d not supported\n", level);
783 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
784 "(%d) returned %d with %d (expected '0' with "
785 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
788 skip("no valid buffer size returned\n");
792 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
793 if (buffer == NULL) continue;
795 SetLastError(MAGIC_DEAD);
796 pcbNeeded = MAGIC_DEAD;
797 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
798 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
799 level, res, GetLastError());
800 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n",
801 level, pcbNeeded, cbBuf);
802 /* We can validate the returned Data with the Registry here */
805 SetLastError(MAGIC_DEAD);
806 pcReturned = MAGIC_DEAD;
807 pcbNeeded = MAGIC_DEAD;
808 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
809 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level,
810 res, GetLastError());
811 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
814 SetLastError(MAGIC_DEAD);
815 pcbNeeded = MAGIC_DEAD;
816 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
817 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
818 "(%d) returned %d with %d (expected '0' with "
819 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
821 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
825 Do not add the next test:
826 w2k+: RPC_X_NULL_REF_POINTER
827 NT3.5: ERROR_INVALID_USER_BUFFER
828 win9x: crash in winspool.drv
830 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
833 SetLastError(MAGIC_DEAD);
834 pcbNeeded = MAGIC_DEAD;
835 pcReturned = MAGIC_DEAD;
836 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
837 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
838 "(%d) returned %d with %d (expected '!=0' or '0' with "
839 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
841 pcbNeeded = MAGIC_DEAD;
842 pcReturned = MAGIC_DEAD;
843 SetLastError(MAGIC_DEAD);
844 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
845 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
846 "(%d) returned %d with %d (expected '!=0' or '0' with "
847 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
849 HeapFree(GetProcessHeap(), 0, buffer);
850 } /* for(level ... */
853 /* ########################### */
855 static void test_EnumPorts(void)
864 /* valid levels are 1 and 2 */
865 for(level = 0; level < 4; level++) {
868 pcReturned = 0xdeadbeef;
869 SetLastError(0xdeadbeef);
870 res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
871 RETURN_ON_DEACTIVATED_SPOOLER(res)
873 /* use only a short test, when we test with an invalid level */
874 if(!level || (level > 2)) {
875 /* NT: ERROR_INVALID_LEVEL, 9x: success */
876 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
877 (res && (pcReturned == 0)),
878 "(%d) returned %d with %d and 0x%08x (expected '0' with "
879 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
880 level, res, GetLastError(), pcReturned);
885 /* Level 2 is not supported on NT 3.x */
886 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
887 skip("Level %d not supported\n", level);
891 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
892 "(%d) returned %d with %d (expected '0' with "
893 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
895 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
896 if (buffer == NULL) continue;
898 pcbNeeded = 0xdeadbeef;
899 SetLastError(0xdeadbeef);
900 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
901 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
902 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
903 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
905 pcbNeeded = 0xdeadbeef;
906 pcReturned = 0xdeadbeef;
907 SetLastError(0xdeadbeef);
908 res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
909 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
910 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
912 pcbNeeded = 0xdeadbeef;
913 SetLastError(0xdeadbeef);
914 res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
915 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
916 "(%d) returned %d with %d (expected '0' with "
917 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
918 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
921 Do not add this test:
922 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
923 w2k+: RPC_X_NULL_REF_POINTER
924 NT3.5: ERROR_INVALID_USER_BUFFER
925 win9x: crash in winspool.drv
928 SetLastError(0xdeadbeef);
929 res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
930 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
931 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
932 ( res && (GetLastError() == ERROR_SUCCESS) ),
933 "(%d) returned %d with %d (expected '0' with "
934 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
935 level, res, GetLastError());
938 SetLastError(0xdeadbeef);
939 res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
940 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
941 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
942 ( res && (GetLastError() == ERROR_SUCCESS) ),
943 "(%d) returned %d with %d (expected '0' with "
944 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
945 level, res, GetLastError());
947 HeapFree(GetProcessHeap(), 0, buffer);
951 /* ########################### */
953 static void test_GetDefaultPrinter(void)
956 DWORD exact = DEFAULT_PRINTER_SIZE;
958 char buffer[DEFAULT_PRINTER_SIZE];
960 if (!pGetDefaultPrinterA) return;
961 /* only supported on NT like OSes starting with win2k */
963 SetLastError(ERROR_SUCCESS);
964 retval = pGetDefaultPrinterA(buffer, &exact);
965 if (!retval || !exact || !strlen(buffer) ||
966 (ERROR_SUCCESS != GetLastError())) {
967 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
968 (ERROR_INVALID_NAME == GetLastError()))
969 trace("this test requires a default printer to be set\n");
971 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
972 "function returned %s\n"
973 "last error 0x%08x\n"
974 "returned buffer size 0x%08x\n"
975 "returned buffer content %s\n",
976 retval ? "true" : "false", GetLastError(), exact, buffer);
980 SetLastError(ERROR_SUCCESS);
981 retval = pGetDefaultPrinterA(NULL, NULL);
982 ok( !retval, "function result wrong! False expected\n");
983 ok( ERROR_INVALID_PARAMETER == GetLastError(),
984 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
987 SetLastError(ERROR_SUCCESS);
988 retval = pGetDefaultPrinterA(buffer, NULL);
989 ok( !retval, "function result wrong! False expected\n");
990 ok( ERROR_INVALID_PARAMETER == GetLastError(),
991 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
994 SetLastError(ERROR_SUCCESS);
996 retval = pGetDefaultPrinterA(NULL, &size);
997 ok( !retval, "function result wrong! False expected\n");
998 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
999 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1001 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1004 SetLastError(ERROR_SUCCESS);
1005 size = DEFAULT_PRINTER_SIZE;
1006 retval = pGetDefaultPrinterA(NULL, &size);
1007 ok( !retval, "function result wrong! False expected\n");
1008 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1009 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1011 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1015 retval = pGetDefaultPrinterA(buffer, &size);
1016 ok( !retval, "function result wrong! False expected\n");
1017 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1018 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1020 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1024 retval = pGetDefaultPrinterA(buffer, &size);
1025 ok( retval, "function result wrong! True expected\n");
1026 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1030 static void test_GetPrinterDriverDirectory(void)
1032 LPBYTE buffer = NULL;
1033 DWORD cbBuf = 0, pcbNeeded = 0;
1037 SetLastError(MAGIC_DEAD);
1038 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1039 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1040 res, GetLastError(), cbBuf);
1042 RETURN_ON_DEACTIVATED_SPOOLER(res)
1043 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1044 "returned %d with lasterror=%d (expected '0' with "
1045 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1048 skip("no valid buffer size returned\n");
1052 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1053 if (buffer == NULL) return ;
1055 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1056 ok( res, "expected result != 0, got %d\n", res);
1057 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1060 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1061 ok( res, "expected result != 0, got %d\n", res);
1062 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1065 SetLastError(MAGIC_DEAD);
1066 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1067 ok( !res , "expected result == 0, got %d\n", res);
1068 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1071 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1072 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1076 Do not add the next test:
1077 XPsp2: crash in this app, when the spooler is not running
1078 NT3.5: ERROR_INVALID_USER_BUFFER
1079 win9x: ERROR_INVALID_PARAMETER
1081 pcbNeeded = MAGIC_DEAD;
1082 SetLastError(MAGIC_DEAD);
1083 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1086 SetLastError(MAGIC_DEAD);
1087 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1088 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
1089 "expected either result == 0 and "
1090 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1091 "got result %d and last error == %d\n", res, GetLastError());
1093 SetLastError(MAGIC_DEAD);
1094 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1095 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1096 "returned %d with %d (expected '!=0' or '0' with "
1097 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1100 /* with a valid buffer, but level is too large */
1102 SetLastError(MAGIC_DEAD);
1103 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1105 /* Level not checked in win9x and wine:*/
1106 if((res != FALSE) && buffer[0])
1108 trace("Level '2' not checked '%s'\n", buffer);
1112 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1113 "returned %d with lasterror=%d (expected '0' with "
1114 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1117 /* printing environments are case insensitive */
1118 /* "Windows 4.0" is valid for win9x and NT */
1120 SetLastError(MAGIC_DEAD);
1121 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1122 buffer, cbBuf*2, &pcbNeeded);
1124 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1126 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1127 if (buffer == NULL) return ;
1129 SetLastError(MAGIC_DEAD);
1130 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1131 buffer, cbBuf*2, &pcbNeeded);
1134 ok(res && buffer[0], "returned %d with "
1135 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1136 res, GetLastError(), lstrlenA((char *)buffer));
1139 SetLastError(MAGIC_DEAD);
1140 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1141 buffer, cbBuf*2, &pcbNeeded);
1143 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1145 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1146 if (buffer == NULL) return ;
1149 SetLastError(MAGIC_DEAD);
1150 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1151 buffer, cbBuf*2, &pcbNeeded);
1154 /* "Windows NT x86" is invalid for win9x */
1155 ok( (res && buffer[0]) ||
1156 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
1157 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1158 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1159 res, GetLastError(), lstrlenA((char *)buffer));
1161 /* A setup program (PDFCreator_0.8.0) use empty strings */
1162 SetLastError(MAGIC_DEAD);
1163 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1164 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1166 SetLastError(MAGIC_DEAD);
1167 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1168 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1170 SetLastError(MAGIC_DEAD);
1171 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1172 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1174 HeapFree( GetProcessHeap(), 0, buffer);
1179 static void test_GetPrintProcessorDirectory(void)
1181 LPBYTE buffer = NULL;
1183 DWORD pcbNeeded = 0;
1187 SetLastError(0xdeadbeef);
1188 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1189 /* The deactivated Spooler is caught here on NT3.51 */
1190 RETURN_ON_DEACTIVATED_SPOOLER(res)
1191 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1192 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1193 res, GetLastError());
1195 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1196 if(buffer == NULL) return;
1199 SetLastError(0xdeadbeef);
1200 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1201 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1203 SetLastError(0xdeadbeef);
1205 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1206 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1208 /* Buffer to small */
1210 SetLastError(0xdeadbeef);
1211 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1212 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1213 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1214 res, GetLastError());
1218 /* XPsp2: the program will crash here, when the spooler is not running */
1219 /* GetPrinterDriverDirectory has the same bug */
1221 SetLastError(0xdeadbeef);
1222 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1226 SetLastError(0xdeadbeef);
1227 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1228 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1229 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1230 "returned %d with %d (expected '!= 0' or '0' with "
1231 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1235 SetLastError(0xdeadbeef);
1236 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1237 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1238 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1239 "returned %d with %d (expected '!= 0' or '0' with "
1240 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1243 /* with a valid buffer, but level is invalid */
1245 SetLastError(0xdeadbeef);
1246 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1247 if (res && buffer[0])
1249 /* Level is ignored in win9x*/
1250 trace("invalid level (2) was ignored\n");
1254 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1255 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1256 res, GetLastError());
1259 /* Empty environment is the same as the default environment */
1261 SetLastError(0xdeadbeef);
1262 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1263 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1265 /* "Windows 4.0" is valid for win9x and NT */
1267 SetLastError(0xdeadbeef);
1268 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1269 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1272 /* "Windows NT x86" is invalid for win9x */
1274 SetLastError(0xdeadbeef);
1275 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1276 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1277 "returned %d with %d (expected '!= 0' or '0' with "
1278 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1280 /* invalid on all Systems */
1282 SetLastError(0xdeadbeef);
1283 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1284 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1285 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1286 res, GetLastError());
1288 /* Empty servername is the same as the local computer */
1290 SetLastError(0xdeadbeef);
1291 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1292 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1294 /* invalid on all Systems */
1296 SetLastError(0xdeadbeef);
1297 res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1298 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
1299 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1300 res, GetLastError());
1302 HeapFree(GetProcessHeap(), 0, buffer);
1307 static void test_OpenPrinter(void)
1309 PRINTER_DEFAULTSA defaults;
1313 SetLastError(MAGIC_DEAD);
1314 res = OpenPrinter(NULL, NULL, NULL);
1315 /* The deactivated Spooler is caught here on NT3.51 */
1316 RETURN_ON_DEACTIVATED_SPOOLER(res)
1317 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1318 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1319 res, GetLastError());
1322 /* Get Handle for the local Printserver (NT only)*/
1323 hprinter = (HANDLE) MAGIC_DEAD;
1324 SetLastError(MAGIC_DEAD);
1325 res = OpenPrinter(NULL, &hprinter, NULL);
1326 /* The deactivated Spooler is caught here on XPsp2 */
1327 RETURN_ON_DEACTIVATED_SPOOLER(res)
1328 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1329 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1330 res, GetLastError());
1332 ClosePrinter(hprinter);
1334 defaults.pDatatype=NULL;
1335 defaults.pDevMode=NULL;
1337 defaults.DesiredAccess=0;
1338 hprinter = (HANDLE) MAGIC_DEAD;
1339 SetLastError(MAGIC_DEAD);
1340 res = OpenPrinter(NULL, &hprinter, &defaults);
1341 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1342 if (res) ClosePrinter(hprinter);
1344 defaults.DesiredAccess=-1;
1345 hprinter = (HANDLE) MAGIC_DEAD;
1346 SetLastError(MAGIC_DEAD);
1347 res = OpenPrinter(NULL, &hprinter, &defaults);
1349 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1350 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1351 res, GetLastError());
1353 if (res) ClosePrinter(hprinter);
1358 if (local_server != NULL) {
1359 hprinter = (HANDLE) 0xdeadbeef;
1360 SetLastError(0xdeadbeef);
1361 res = OpenPrinter(local_server, &hprinter, NULL);
1362 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1363 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1364 res, GetLastError());
1365 if(res) ClosePrinter(hprinter);
1368 /* Invalid Printername */
1369 hprinter = (HANDLE) MAGIC_DEAD;
1370 SetLastError(MAGIC_DEAD);
1371 res = OpenPrinter(illegal_name, &hprinter, NULL);
1372 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1373 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1374 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1375 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1376 if(res) ClosePrinter(hprinter);
1378 hprinter = (HANDLE) MAGIC_DEAD;
1379 SetLastError(MAGIC_DEAD);
1380 res = OpenPrinter(empty, &hprinter, NULL);
1381 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1383 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1384 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1385 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1386 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1387 if(res) ClosePrinter(hprinter);
1390 /* Get Handle for the default Printer */
1391 if (default_printer)
1393 hprinter = (HANDLE) MAGIC_DEAD;
1394 SetLastError(MAGIC_DEAD);
1395 res = OpenPrinter(default_printer, &hprinter, NULL);
1396 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1398 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1401 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1402 if(res) ClosePrinter(hprinter);
1404 SetLastError(MAGIC_DEAD);
1405 res = OpenPrinter(default_printer, NULL, NULL);
1406 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1407 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1408 "returned %d with %d (expected '!=0' or '0' with "
1409 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1411 defaults.pDatatype=NULL;
1412 defaults.pDevMode=NULL;
1413 defaults.DesiredAccess=0;
1415 hprinter = (HANDLE) MAGIC_DEAD;
1416 SetLastError(MAGIC_DEAD);
1417 res = OpenPrinter(default_printer, &hprinter, &defaults);
1418 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1419 "returned %d with %d (expected '!=0' or '0' with "
1420 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1421 if(res) ClosePrinter(hprinter);
1423 defaults.pDatatype = empty;
1425 hprinter = (HANDLE) MAGIC_DEAD;
1426 SetLastError(MAGIC_DEAD);
1427 res = OpenPrinter(default_printer, &hprinter, &defaults);
1428 /* stop here, when a remote Printserver has no RPC-Service running */
1429 RETURN_ON_DEACTIVATED_SPOOLER(res)
1430 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1431 (GetLastError() == ERROR_ACCESS_DENIED)),
1432 "returned %d with %d (expected '!=0' or '0' with: "
1433 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1434 res, GetLastError());
1435 if(res) ClosePrinter(hprinter);
1438 defaults.pDatatype=NULL;
1439 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1441 hprinter = (HANDLE) MAGIC_DEAD;
1442 SetLastError(MAGIC_DEAD);
1443 res = OpenPrinter(default_printer, &hprinter, &defaults);
1444 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1445 "returned %d with %d (expected '!=0' or '0' with "
1446 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1447 if(res) ClosePrinter(hprinter);
1450 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1451 hprinter = (HANDLE) MAGIC_DEAD;
1452 SetLastError(MAGIC_DEAD);
1453 res = OpenPrinter(default_printer, &hprinter, &defaults);
1454 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1455 "returned %d with %d (expected '!=0' or '0' with "
1456 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1457 if(res) ClosePrinter(hprinter);
1463 static void test_SetDefaultPrinter(void)
1466 DWORD size = DEFAULT_PRINTER_SIZE;
1467 CHAR buffer[DEFAULT_PRINTER_SIZE];
1468 CHAR org_value[DEFAULT_PRINTER_SIZE];
1471 if (!pSetDefaultPrinterA) return;
1472 /* only supported on win2k and above */
1474 /* backup the original value */
1475 org_value[0] = '\0';
1476 SetLastError(MAGIC_DEAD);
1477 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1479 /* first part: with the default Printer */
1480 SetLastError(MAGIC_DEAD);
1481 res = pSetDefaultPrinterA("no_printer_with_this_name");
1483 RETURN_ON_DEACTIVATED_SPOOLER(res)
1484 /* spooler is running or we have no spooler here*/
1486 /* Not implemented in wine */
1487 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1488 trace("SetDefaultPrinterA() not implemented yet.\n");
1492 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1493 "returned %d with %d (expected '0' with "
1494 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1496 WriteProfileStringA("windows", "device", org_value);
1497 SetLastError(MAGIC_DEAD);
1498 res = pSetDefaultPrinterA("");
1499 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1500 "returned %d with %d (expected '!=0' or '0' with "
1501 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1503 WriteProfileStringA("windows", "device", org_value);
1504 SetLastError(MAGIC_DEAD);
1505 res = pSetDefaultPrinterA(NULL);
1506 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1507 "returned %d with %d (expected '!=0' or '0' with "
1508 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1510 WriteProfileStringA("windows", "device", org_value);
1511 SetLastError(MAGIC_DEAD);
1512 res = pSetDefaultPrinterA(default_printer);
1513 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1514 "returned %d with %d (expected '!=0' or '0' with "
1515 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1518 /* second part: always without a default Printer */
1519 WriteProfileStringA("windows", "device", NULL);
1520 SetLastError(MAGIC_DEAD);
1521 res = pSetDefaultPrinterA("no_printer_with_this_name");
1523 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1524 "returned %d with %d (expected '0' with "
1525 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1527 WriteProfileStringA("windows", "device", NULL);
1528 SetLastError(MAGIC_DEAD);
1529 res = pSetDefaultPrinterA("");
1530 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1531 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1532 "returned %d with %d (expected '!=0' or '0' with "
1533 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1535 WriteProfileStringA("windows", "device", NULL);
1536 SetLastError(MAGIC_DEAD);
1537 res = pSetDefaultPrinterA(NULL);
1538 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1539 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1540 "returned %d with %d (expected '!=0' or '0' with "
1541 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1543 WriteProfileStringA("windows", "device", NULL);
1544 SetLastError(MAGIC_DEAD);
1545 res = pSetDefaultPrinterA(default_printer);
1546 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1547 "returned %d with %d (expected '!=0' or '0' with "
1548 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1550 /* restore the original value */
1551 res = pSetDefaultPrinterA(default_printer); /* the nice way */
1552 WriteProfileStringA("windows", "device", org_value); /* the old way */
1555 SetLastError(MAGIC_DEAD);
1556 res = GetProfileStringA("windows", "device", NULL, buffer, size);
1557 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1561 /* ########################### */
1563 static void test_XcvDataW_MonitorUI(void)
1567 BYTE buffer[MAX_PATH + 4];
1571 PRINTER_DEFAULTSA pd;
1573 /* api is not present before w2k */
1574 if (pXcvDataW == NULL) return;
1576 pd.pDatatype = NULL;
1578 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
1581 SetLastError(0xdeadbeef);
1582 res = OpenPrinter(xcv_localport, &hXcv, &pd);
1583 RETURN_ON_DEACTIVATED_SPOOLER(res)
1584 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
1587 /* ask for needed size */
1588 needed = (DWORD) 0xdeadbeef;
1589 status = (DWORD) 0xdeadbeef;
1590 SetLastError(0xdeadbeef);
1591 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed, &status);
1592 ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
1593 "returned %d with %u and %u for status %u (expected '!= 0' and "
1594 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
1595 res, GetLastError(), needed, status);
1597 if (needed > MAX_PATH) {
1599 skip("buffer overflow (%u)\n", needed);
1602 len = needed; /* Size is in bytes */
1604 /* the command is required */
1605 needed = (DWORD) 0xdeadbeef;
1606 status = (DWORD) 0xdeadbeef;
1607 SetLastError(0xdeadbeef);
1608 res = pXcvDataW(hXcv, emptyW, NULL, 0, NULL, 0, &needed, &status);
1609 ok( res && (status == ERROR_INVALID_PARAMETER),
1610 "returned %d with %u and %u for status %u (expected '!= 0' with "
1611 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
1613 needed = (DWORD) 0xdeadbeef;
1614 status = (DWORD) 0xdeadbeef;
1615 SetLastError(0xdeadbeef);
1616 res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
1617 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1618 "returned %d with %u and %u for status %u (expected '0' with "
1619 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1621 /* "PDWORD needed" is checked before RPC-Errors */
1622 needed = (DWORD) 0xdeadbeef;
1623 status = (DWORD) 0xdeadbeef;
1624 SetLastError(0xdeadbeef);
1625 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, NULL, &status);
1626 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
1627 "returned %d with %u and %u for status %u (expected '0' with "
1628 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
1630 needed = (DWORD) 0xdeadbeef;
1631 status = (DWORD) 0xdeadbeef;
1632 SetLastError(0xdeadbeef);
1633 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, len, &needed, &status);
1634 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1635 "returned %d with %u and %u for status %u (expected '0' with "
1636 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1638 needed = (DWORD) 0xdeadbeef;
1639 status = (DWORD) 0xdeadbeef;
1640 SetLastError(0xdeadbeef);
1641 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, NULL);
1642 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
1643 "returned %d with %u and %u for status %u (expected '0' with "
1644 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
1646 /* off by one: larger */
1647 needed = (DWORD) 0xdeadbeef;
1648 status = (DWORD) 0xdeadbeef;
1649 SetLastError(0xdeadbeef);
1650 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len+1, &needed, &status);
1651 ok( res && (status == ERROR_SUCCESS),
1652 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1653 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
1655 /* off by one: smaller */
1656 /* the buffer is not modified for NT4, w2k, XP */
1657 needed = (DWORD) 0xdeadbeef;
1658 status = (DWORD) 0xdeadbeef;
1659 SetLastError(0xdeadbeef);
1660 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len-1, &needed, &status);
1661 ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
1662 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1663 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
1666 /* Normal use. The DLL-Name without a Path is returned */
1667 memset(buffer, 0, len);
1668 needed = (DWORD) 0xdeadbeef;
1669 status = (DWORD) 0xdeadbeef;
1670 SetLastError(0xdeadbeef);
1671 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, &status);
1672 ok( res && (status == ERROR_SUCCESS),
1673 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1674 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
1679 /* ########################### */
1681 static void test_XcvDataW_PortIsValid(void)
1687 PRINTER_DEFAULTSA pd;
1689 /* api is not present before w2k */
1690 if (pXcvDataW == NULL) return;
1692 pd.pDatatype = NULL;
1694 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
1697 SetLastError(0xdeadbeef);
1698 res = OpenPrinter(xcv_localport, &hXcv, &pd);
1700 RETURN_ON_DEACTIVATED_SPOOLER(res)
1701 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
1705 /* "PDWORD needed" is always required */
1706 needed = (DWORD) 0xdeadbeef;
1707 status = (DWORD) 0xdeadbeef;
1708 SetLastError(0xdeadbeef);
1709 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, NULL, &status);
1710 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
1711 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
1712 res, GetLastError(), needed, status);
1714 /* an empty name is not allowed */
1715 needed = (DWORD) 0xdeadbeef;
1716 status = (DWORD) 0xdeadbeef;
1717 SetLastError(0xdeadbeef);
1718 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) emptyW, sizeof(emptyW), NULL, 0, &needed, &status);
1719 ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
1720 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
1721 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
1722 res, GetLastError(), needed, status);
1724 /* a directory is not allowed */
1725 needed = (DWORD) 0xdeadbeef;
1726 status = (DWORD) 0xdeadbeef;
1727 SetLastError(0xdeadbeef);
1728 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
1729 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
1730 ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
1731 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
1732 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
1733 res, GetLastError(), needed, status);
1735 /* more valid well known Ports */
1736 needed = (DWORD) 0xdeadbeef;
1737 status = (DWORD) 0xdeadbeef;
1738 SetLastError(0xdeadbeef);
1739 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed, &status);
1740 ok( res && (status == ERROR_SUCCESS),
1741 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
1742 res, GetLastError(), needed, status);
1744 needed = (DWORD) 0xdeadbeef;
1745 status = (DWORD) 0xdeadbeef;
1746 SetLastError(0xdeadbeef);
1747 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt2W, sizeof(portname_lpt2W), NULL, 0, &needed, &status);
1748 ok( res && (status == ERROR_SUCCESS),
1749 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
1750 res, GetLastError(), needed, status);
1752 needed = (DWORD) 0xdeadbeef;
1753 status = (DWORD) 0xdeadbeef;
1754 SetLastError(0xdeadbeef);
1755 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com1W, sizeof(portname_com1W), NULL, 0, &needed, &status);
1756 ok( res && (status == ERROR_SUCCESS),
1757 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
1758 res, GetLastError(), needed, status);
1760 needed = (DWORD) 0xdeadbeef;
1761 status = (DWORD) 0xdeadbeef;
1762 SetLastError(0xdeadbeef);
1763 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com2W, sizeof(portname_com2W), NULL, 0, &needed, &status);
1764 ok( res && (status == ERROR_SUCCESS),
1765 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
1766 res, GetLastError(), needed, status);
1768 needed = (DWORD) 0xdeadbeef;
1769 status = (DWORD) 0xdeadbeef;
1770 SetLastError(0xdeadbeef);
1771 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_fileW, sizeof(portname_fileW), NULL, 0, &needed, &status);
1772 ok( res && (status == ERROR_SUCCESS),
1773 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
1774 res, GetLastError(), needed, status);
1777 /* a normal, writable file is allowed */
1778 needed = (DWORD) 0xdeadbeef;
1779 status = (DWORD) 0xdeadbeef;
1780 SetLastError(0xdeadbeef);
1781 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
1782 ok( res && (status == ERROR_SUCCESS),
1783 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
1784 res, GetLastError(), needed, status);
1789 /* ########################### */
1791 static void test_GetPrinterDriver(void)
1797 DWORD needed, filled;
1799 if (!default_printer)
1801 skip("There is no default printer installed\n");
1806 ret = OpenPrinter(default_printer, &hprn, NULL);
1809 skip("Unable to open the default printer (%s)\n", default_printer);
1812 ok(hprn != 0, "wrong hprn %p\n", hprn);
1814 for (level = -1; level <= 7; level++)
1816 SetLastError(0xdeadbeef);
1818 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
1819 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
1820 if (level >= 1 && level <= 6)
1822 /* Not all levels are supported on all Windows-Versions */
1823 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
1824 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
1825 ok(needed > 0,"not expected needed buffer size %d\n", needed);
1829 /* ERROR_OUTOFMEMORY found on win9x */
1830 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
1831 (GetLastError() == ERROR_OUTOFMEMORY)),
1832 "%d: returned %d with %d (expected '0' with: "
1833 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1834 level, ret, GetLastError());
1835 /* needed is modified in win9x. The modified Value depends on the
1836 default Printer. testing for "needed == (DWORD)-1" will fail */
1840 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1842 SetLastError(0xdeadbeef);
1844 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
1845 ok(ret, "level %d: GetPrinterDriver error %d\n", level, GetLastError());
1846 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
1850 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
1851 DWORD calculated = sizeof(*di_2);
1853 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1854 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1855 ok((di_2->cVersion >= 0 && di_2->cVersion <= 3) ||
1856 (di_2->cVersion == 0x0400), "di_2->cVersion = %d\n", di_2->cVersion);
1857 ok(di_2->pName != NULL, "not expected NULL ptr\n");
1858 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
1859 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
1860 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
1861 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
1863 trace("cVersion %d\n", di_2->cVersion);
1864 trace("pName %s\n", di_2->pName);
1865 calculated += strlen(di_2->pName) + 1;
1866 trace("pEnvironment %s\n", di_2->pEnvironment);
1867 calculated += strlen(di_2->pEnvironment) + 1;
1868 trace("pDriverPath %s\n", di_2->pDriverPath);
1869 calculated += strlen(di_2->pDriverPath) + 1;
1870 trace("pDataFile %s\n", di_2->pDataFile);
1871 calculated += strlen(di_2->pDataFile) + 1;
1872 trace("pConfigFile %s\n", di_2->pConfigFile);
1873 calculated += strlen(di_2->pConfigFile) + 1;
1875 /* XP allocates memory for both ANSI and unicode names */
1876 ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
1879 HeapFree(GetProcessHeap(), 0, buf);
1882 SetLastError(0xdeadbeef);
1883 ret = ClosePrinter(hprn);
1884 ok(ret, "ClosePrinter error %d\n", GetLastError());
1887 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
1889 /* On NT3.51, some fields in DEVMODE are empty/zero
1890 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1891 We skip the Tests on this Platform */
1892 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
1893 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1894 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
1895 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
1896 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
1897 "%u != %d\n", dm->dmSize + dm->dmDriverExtra, dmSize);
1899 trace("dmFields %08x\n", dm->dmFields);
1902 static void test_DocumentProperties(void)
1908 if (!default_printer)
1910 skip("There is no default printer installed\n");
1915 ret = OpenPrinter(default_printer, &hprn, NULL);
1918 skip("Unable to open the default printer (%s)\n", default_printer);
1921 ok(hprn != 0, "wrong hprn %p\n", hprn);
1923 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
1924 trace("DEVMODE required size %d\n", dm_size);
1925 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %d\n", dm_size);
1927 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
1929 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
1930 ok(ret == IDOK, "DocumentProperties ret value %d != expected IDOK\n", ret);
1932 test_DEVMODE(dm, dm_size, default_printer);
1934 HeapFree(GetProcessHeap(), 0, dm);
1936 SetLastError(0xdeadbeef);
1937 ret = ClosePrinter(hprn);
1938 ok(ret, "ClosePrinter error %d\n", GetLastError());
1941 static void test_EnumPrinters(void)
1943 DWORD neededA, neededW, num;
1946 SetLastError(0xdeadbeef);
1948 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
1949 RETURN_ON_DEACTIVATED_SPOOLER(ret)
1952 /* We have 1 or more printers */
1953 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
1954 ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
1958 /* We don't have any printers defined */
1959 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
1960 ok(neededA == 0, "Expected neededA to be zero\n");
1962 ok(num == 0, "num %d\n", num);
1964 SetLastError(0xdeadbeef);
1966 ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
1967 /* EnumPrintersW is not supported on all platforms */
1968 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
1970 skip("EnumPrintersW is not implemented\n");
1976 /* We have 1 or more printers */
1977 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
1978 ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
1982 /* We don't have any printers defined */
1983 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
1984 ok(neededW == 0, "Expected neededW to be zero\n");
1986 ok(num == 0, "num %d\n", num);
1988 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
1989 to hold the buffer returned by EnumPrintersW */
1990 ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
1995 hwinspool = GetModuleHandleA("winspool.drv");
1996 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
1997 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
1998 pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
2000 find_default_printer();
2001 find_local_server();
2006 test_ConfigurePort();
2007 test_DeleteMonitor();
2009 test_DocumentProperties();
2010 test_EnumForms(NULL);
2011 if (default_printer) test_EnumForms(default_printer);
2012 test_EnumMonitors();
2014 test_EnumPrinters();
2015 test_GetDefaultPrinter();
2016 test_GetPrinterDriverDirectory();
2017 test_GetPrintProcessorDirectory();
2019 test_GetPrinterDriver();
2020 test_SetDefaultPrinter();
2021 test_XcvDataW_MonitorUI();
2022 test_XcvDataW_PortIsValid();