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"
32 #define MAGIC_DEAD 0xdeadbeef
33 #define DEFAULT_PRINTER_SIZE 1000
35 static char env_x86[] = "Windows NT x86";
36 static char env_win9x_case[] = "windowS 4.0";
37 static char winetest_monitor[] = "winetest";
39 static HANDLE hwinspool;
40 static FARPROC pGetDefaultPrinterA;
41 static FARPROC pSetDefaultPrinterA;
43 struct monitor_entry {
48 /* report common behavior only once */
49 static DWORD report_deactivated_spooler = 1;
50 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
51 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
53 if(report_deactivated_spooler > 0) { \
54 report_deactivated_spooler--; \
55 trace("The Service 'Spooler' is required for many test\n"); \
61 static LPSTR find_default_printer(VOID)
63 static LPSTR default_printer = NULL;
64 static char buffer[DEFAULT_PRINTER_SIZE];
69 if ((default_printer == NULL) && (pGetDefaultPrinterA))
72 needed = sizeof(buffer);
73 res = pGetDefaultPrinterA(buffer, &needed);
74 if(res) default_printer = buffer;
75 trace("default_printer: '%s'\n", default_printer);
77 if (default_printer == NULL)
81 /* NT 3.x and above */
82 if (RegOpenKeyEx(HKEY_CURRENT_USER,
83 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
84 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
86 needed = sizeof(buffer);
87 if (RegQueryValueEx(hwindows, "device", NULL,
88 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
90 ptr = strchr(buffer, ',');
93 default_printer = buffer;
96 RegCloseKey(hwindows);
98 trace("default_printer: '%s'\n", default_printer);
100 if (default_printer == NULL)
103 needed = sizeof(buffer);
104 res = GetProfileStringA("windows", "device", "*", buffer, needed);
106 ptr = strchr(buffer, ',');
109 default_printer = buffer;
112 trace("default_printer: '%s'\n", default_printer);
114 return default_printer;
118 static struct monitor_entry * find_installed_monitor(void)
120 MONITOR_INFO_2A mi2a;
121 static struct monitor_entry * entry = NULL;
125 static struct monitor_entry monitor_table[] = {
126 {env_win9x_case, "localspl.dll"},
127 {env_x86, "localspl.dll"},
128 {env_win9x_case, "localmon.dll"},
129 {env_x86, "localmon.dll"},
130 {env_win9x_case, "tcpmon.dll"},
131 {env_x86, "tcpmon.dll"},
132 {env_win9x_case, "usbmon.dll"},
133 {env_x86, "usbmon.dll"},
134 {env_win9x_case, "mspp32.dll"},
135 {env_x86, "win32spl.dll"},
136 {env_x86, "redmonnt.dll"},
137 {env_x86, "redmon35.dll"},
138 {env_win9x_case, "redmon95.dll"},
139 {env_x86, "pdfcmnnt.dll"},
140 {env_win9x_case, "pdfcmn95.dll"},
143 if (entry) return entry;
145 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
148 DeleteMonitorA(NULL, env_x86, winetest_monitor);
149 DeleteMonitorA(NULL, env_win9x_case, winetest_monitor);
151 /* find a usable monitor from the table */
152 mi2a.pName = winetest_monitor;
153 while ((entry == NULL) && (i < num_tests)) {
154 entry = &monitor_table[i];
156 mi2a.pEnvironment = entry->env;
157 mi2a.pDLLName = entry->dllname;
159 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
161 trace("using '%s', '%s'\n", entry->env, entry->dllname);
162 DeleteMonitorA(NULL, entry->env, winetest_monitor);
172 /* ########################### */
175 static void test_AddMonitor(void)
177 MONITOR_INFO_2A mi2a;
178 struct monitor_entry * entry = NULL;
181 entry = find_installed_monitor();
183 SetLastError(MAGIC_DEAD);
184 res = AddMonitorA(NULL, 1, NULL);
185 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
186 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
187 res, GetLastError());
189 SetLastError(MAGIC_DEAD);
190 res = AddMonitorA(NULL, 3, NULL);
191 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
192 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
193 res, GetLastError());
196 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
197 SetLastError(MAGIC_DEAD);
198 res = AddMonitorA(NULL, 2, NULL);
199 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
201 ((GetLastError() == MAGIC_DEAD) ||
202 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
203 "returned %ld with %ld (expected '0' with: MAGIC_DEAD or " \
204 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
207 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
208 SetLastError(MAGIC_DEAD);
209 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
210 RETURN_ON_DEACTIVATED_SPOOLER(res)
212 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
213 trace("skip tests (ACCESS_DENIED)\n");
217 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
218 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
219 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
220 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
221 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
224 trace("No usable Monitor found: Skip tests\n");
229 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
230 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
231 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
232 is created on win9x and we do not want to hit this bug here. */
234 mi2a.pEnvironment = entry->env;
235 SetLastError(MAGIC_DEAD);
236 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
237 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
240 mi2a.pEnvironment = entry->env;
242 SetLastError(MAGIC_DEAD);
243 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
244 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
246 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
247 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
248 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
249 "ERROR_PRIVILEGE_NOT_HELD)\n",
250 res, GetLastError());
252 mi2a.pName = winetest_monitor;
253 SetLastError(MAGIC_DEAD);
254 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
255 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
257 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
258 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
259 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
260 "ERROR_PRIVILEGE_NOT_HELD)\n",
261 res, GetLastError());
264 SetLastError(MAGIC_DEAD);
265 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
266 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
267 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
268 res, GetLastError());
271 mi2a.pDLLName = "does_not_exists.dll";
272 SetLastError(MAGIC_DEAD);
273 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
274 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
276 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
277 (GetLastError() == ERROR_INVALID_PARAMETER)),
278 "returned %ld with %ld (expected '0' with: ERROR_MOD_NOT_FOUND or " \
279 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
281 mi2a.pDLLName = "version.dll";
282 SetLastError(MAGIC_DEAD);
283 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
284 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
287 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
288 (GetLastError() == ERROR_INVALID_PARAMETER)),
289 "returned %ld with %ld (expected '0' with: ERROR_PROC_NOT_FOUND or " \
290 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
291 if (res) DeleteMonitorA(NULL, entry->env, winetest_monitor);
294 /* Test AddMonitor with real options */
295 mi2a.pDLLName = entry->dllname;
296 SetLastError(MAGIC_DEAD);
297 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
298 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
300 /* add a monitor twice */
301 SetLastError(MAGIC_DEAD);
302 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
303 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
305 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
306 (GetLastError() == ERROR_ALREADY_EXISTS)),
307 "returned %ld with %ld (expected '0' with: " \
308 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
309 res, GetLastError());
311 DeleteMonitorA(NULL, entry->env, winetest_monitor);
312 SetLastError(MAGIC_DEAD);
313 res = AddMonitorA("", 2, (LPBYTE) &mi2a);
314 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
317 DeleteMonitorA(NULL, entry->env, winetest_monitor);
321 /* ########################### */
323 static void test_DeleteMonitor(void)
325 MONITOR_INFO_2A mi2a;
326 struct monitor_entry * entry = NULL;
329 entry = find_installed_monitor();
332 trace("No usable Monitor found: Skip tests\n");
336 mi2a.pName = winetest_monitor;
337 mi2a.pEnvironment = entry->env;
338 mi2a.pDLLName = entry->dllname;
340 /* Testing DeleteMonitor with real options */
341 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
343 SetLastError(MAGIC_DEAD);
344 res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
345 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
347 /* Delete the Monitor twice */
348 SetLastError(MAGIC_DEAD);
349 res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
350 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
352 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
353 (GetLastError() == ERROR_INVALID_PARAMETER)),
354 "returned %ld with %ld (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR" \
355 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
357 /* the environment */
358 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
359 SetLastError(MAGIC_DEAD);
360 res = DeleteMonitorA(NULL, NULL, winetest_monitor);
361 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
363 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
364 SetLastError(MAGIC_DEAD);
365 res = DeleteMonitorA(NULL, "", winetest_monitor);
366 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
368 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
369 SetLastError(MAGIC_DEAD);
370 res = DeleteMonitorA(NULL, "bad_env", winetest_monitor);
371 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
373 /* the monitor-name */
374 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
375 SetLastError(MAGIC_DEAD);
376 res = DeleteMonitorA(NULL, entry->env, NULL);
377 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
379 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
380 (GetLastError() == ERROR_INVALID_NAME)),
381 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
382 "ERROR_INVALID_NAME)\n", res, GetLastError());
384 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
385 SetLastError(MAGIC_DEAD);
386 res = DeleteMonitorA(NULL, entry->env, "");
387 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
389 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
390 (GetLastError() == ERROR_INVALID_NAME)),
391 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
392 "ERROR_INVALID_NAME)\n", res, GetLastError());
394 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
395 SetLastError(MAGIC_DEAD);
396 res = DeleteMonitorA("", entry->env, winetest_monitor);
397 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
400 DeleteMonitorA(NULL, entry->env, winetest_monitor);
405 static void test_EnumForms(LPSTR pName)
416 res = OpenPrinter(pName, &hprinter, NULL);
417 RETURN_ON_DEACTIVATED_SPOOLER(res)
418 if (!res || !hprinter)
420 /* Open the local Prinserver is not supported on win9x */
421 if (pName) trace("Failed to open '%s', skiping the test\n", pName);
425 /* valid levels are 1 and 2 */
426 for(level = 0; level < 4; level++) {
428 pcReturned = 0xdeadbeef;
429 SetLastError(0xdeadbeef);
430 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
432 /* EnumForms is not implemented in win9x */
433 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
435 /* EnumForms for the Server not implemented on all NT-Versions */
436 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
438 /* Level 2 for EnumForms is not supported on all systems */
439 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
441 /* use only a short test, when we test with an invalid level */
442 if(!level || (level > 2)) {
443 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
444 (res && (pcReturned == 0)),
445 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
446 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
447 level, res, GetLastError(), pcReturned);
451 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
452 "(%ld) returned %ld with %ld (expected '0' with " \
453 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
455 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
456 if (buffer == NULL) continue;
458 SetLastError(0xdeadbeef);
459 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
460 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
461 level, res, GetLastError());
462 /* We can dump the returned Data here */
465 SetLastError(0xdeadbeef);
466 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
467 ok( res, "(%ld) returned %ld with %ld (expected '!=0')\n",
468 level, res, GetLastError());
470 SetLastError(0xdeadbeef);
471 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
472 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
473 "(%ld) returned %ld with %ld (expected '0' with " \
474 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
477 SetLastError(0xdeadbeef);
478 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
479 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
480 "(%ld) returned %ld with %ld (expected '0' with "\
481 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
484 SetLastError(0xdeadbeef);
485 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
486 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
487 "(%ld) returned %ld with %ld (expected '0' with "\
488 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
490 SetLastError(0xdeadbeef);
491 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
492 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
493 "(%ld) returned %ld with %ld (expected '0' with "\
494 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
496 SetLastError(0xdeadbeef);
497 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
498 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
499 "(%ld) returned %ld with %ld (expected '0' with "\
500 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
502 HeapFree(GetProcessHeap(), 0, buffer);
503 } /* for(level ... */
505 ClosePrinter(hprinter);
508 /* ########################### */
510 static void test_EnumMonitors(void)
519 /* valid levels are 1 and 2 */
520 for(level = 0; level < 4; level++) {
522 pcReturned = MAGIC_DEAD;
523 SetLastError(MAGIC_DEAD);
524 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
526 RETURN_ON_DEACTIVATED_SPOOLER(res)
528 /* not implemented yet in wine */
529 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
532 /* use only a short test, when we test with an invalid level */
533 if(!level || (level > 2)) {
534 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
535 (res && (pcReturned == 0)),
536 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
537 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
538 level, res, GetLastError(), pcReturned);
542 /* Level 2 is not supported on win9x */
543 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
544 trace("Level %ld not supported, skipping tests\n", level);
548 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
549 "(%ld) returned %ld with %ld (expected '0' with " \
550 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
553 trace("no valid buffer size returned, skipping tests\n");
557 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
558 if (buffer == NULL) continue;
560 SetLastError(MAGIC_DEAD);
561 pcbNeeded = MAGIC_DEAD;
562 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
563 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
564 level, res, GetLastError());
565 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n",
566 level, pcbNeeded, cbBuf);
567 /* We can validate the returned Data with the Registry here */
570 SetLastError(MAGIC_DEAD);
571 pcReturned = MAGIC_DEAD;
572 pcbNeeded = MAGIC_DEAD;
573 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
574 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level,
575 res, GetLastError());
576 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
579 SetLastError(MAGIC_DEAD);
580 pcbNeeded = MAGIC_DEAD;
581 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
582 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
583 "(%ld) returned %ld with %ld (expected '0' with " \
584 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
586 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
590 Do not add the next test:
591 w2k+: RPC_X_NULL_REF_POINTER
592 NT3.5: ERROR_INVALID_USER_BUFFER
593 win9x: crash in winspool.drv
595 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
598 SetLastError(MAGIC_DEAD);
599 pcbNeeded = MAGIC_DEAD;
600 pcReturned = MAGIC_DEAD;
601 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
602 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
603 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
604 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
606 pcbNeeded = MAGIC_DEAD;
607 pcReturned = MAGIC_DEAD;
608 SetLastError(MAGIC_DEAD);
609 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
610 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
611 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
612 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
614 HeapFree(GetProcessHeap(), 0, buffer);
615 } /* for(level ... */
619 static void test_GetDefaultPrinter(void)
622 DWORD exact = DEFAULT_PRINTER_SIZE;
624 char buffer[DEFAULT_PRINTER_SIZE];
626 if (!pGetDefaultPrinterA) return;
627 /* only supported on NT like OSes starting with win2k */
629 SetLastError(ERROR_SUCCESS);
630 retval = pGetDefaultPrinterA(buffer, &exact);
631 if (!retval || !exact || !strlen(buffer) ||
632 (ERROR_SUCCESS != GetLastError())) {
633 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
634 (ERROR_INVALID_NAME == GetLastError()))
635 trace("this test requires a default printer to be set\n");
637 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
638 "function returned %s\n"
639 "last error 0x%08lx\n"
640 "returned buffer size 0x%08lx\n"
641 "returned buffer content %s\n",
642 retval ? "true" : "false", GetLastError(), exact, buffer);
646 SetLastError(ERROR_SUCCESS);
647 retval = pGetDefaultPrinterA(NULL, NULL);
648 ok( !retval, "function result wrong! False expected\n");
649 ok( ERROR_INVALID_PARAMETER == GetLastError(),
650 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
653 SetLastError(ERROR_SUCCESS);
654 retval = pGetDefaultPrinterA(buffer, NULL);
655 ok( !retval, "function result wrong! False expected\n");
656 ok( ERROR_INVALID_PARAMETER == GetLastError(),
657 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
660 SetLastError(ERROR_SUCCESS);
662 retval = pGetDefaultPrinterA(NULL, &size);
663 ok( !retval, "function result wrong! False expected\n");
664 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
665 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
667 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
670 SetLastError(ERROR_SUCCESS);
671 size = DEFAULT_PRINTER_SIZE;
672 retval = pGetDefaultPrinterA(NULL, &size);
673 ok( !retval, "function result wrong! False expected\n");
674 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
675 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
677 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
681 retval = pGetDefaultPrinterA(buffer, &size);
682 ok( !retval, "function result wrong! False expected\n");
683 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
684 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
686 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
690 retval = pGetDefaultPrinterA(buffer, &size);
691 ok( retval, "function result wrong! True expected\n");
692 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
696 static void test_GetPrinterDriverDirectory(void)
698 LPBYTE buffer = NULL;
699 DWORD cbBuf = 0, pcbNeeded = 0;
702 SetLastError(MAGIC_DEAD);
703 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
704 trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
705 res, GetLastError(), cbBuf);
707 RETURN_ON_DEACTIVATED_SPOOLER(res)
708 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
709 "returned %d with lasterror=%ld (expected '0' with " \
710 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
713 trace("no valid buffer size returned, skipping tests\n");
717 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
718 if (buffer == NULL) return ;
720 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
721 ok( res, "expected result != 0, got %d\n", res);
722 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
725 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
726 ok( res, "expected result != 0, got %d\n", res);
727 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
730 SetLastError(MAGIC_DEAD);
731 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
732 ok( !res , "expected result == 0, got %d\n", res);
733 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
736 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
737 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
741 Do not add the next test:
742 XPsp2: crash in this app, when the spooler is not running
743 NT3.5: ERROR_INVALID_USER_BUFFER
744 win9x: ERROR_INVALID_PARAMETER
746 pcbNeeded = MAGIC_DEAD;
747 SetLastError(MAGIC_DEAD);
748 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
751 SetLastError(MAGIC_DEAD);
752 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
753 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
754 "expected either result == 0 and "
755 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
756 "got result %d and last error == %ld\n", res, GetLastError());
758 SetLastError(MAGIC_DEAD);
759 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
760 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
761 "returned %d with %ld (expected '!=0' or '0' with " \
762 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
765 /* with a valid buffer, but level is too large */
767 SetLastError(MAGIC_DEAD);
768 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
770 /* Level not checked in win9x and wine:*/
771 if((res != FALSE) && buffer[0])
773 trace("Level '2' not checked '%s'\n", buffer);
777 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
778 "returned %d with lasterror=%ld (expected '0' with " \
779 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
782 /* printing environments are case insensitive */
783 /* "Windows 4.0" is valid for win9x and NT */
785 SetLastError(MAGIC_DEAD);
786 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
787 buffer, cbBuf*2, &pcbNeeded);
789 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
791 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
792 if (buffer == NULL) return ;
794 SetLastError(MAGIC_DEAD);
795 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
796 buffer, cbBuf*2, &pcbNeeded);
799 ok(res && buffer[0], "returned %d with " \
800 "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n",
801 res, GetLastError(), lstrlenA((char *)buffer));
804 SetLastError(MAGIC_DEAD);
805 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
806 buffer, cbBuf*2, &pcbNeeded);
808 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
810 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
811 if (buffer == NULL) return ;
814 SetLastError(MAGIC_DEAD);
815 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
816 buffer, cbBuf*2, &pcbNeeded);
819 /* "Windows NT x86" is invalid for win9x */
820 ok( (res && buffer[0]) ||
821 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
822 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
823 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
824 res, GetLastError(), lstrlenA((char *)buffer));
826 /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
827 SetLastError(MAGIC_DEAD);
828 res = GetPrinterDriverDirectoryA("", "", 1, buffer, cbBuf*2, &pcbNeeded);
829 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
831 SetLastError(MAGIC_DEAD);
832 res = GetPrinterDriverDirectoryA(NULL, "", 1, buffer, cbBuf*2, &pcbNeeded);
833 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
835 SetLastError(MAGIC_DEAD);
836 res = GetPrinterDriverDirectoryA("", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
837 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
839 HeapFree( GetProcessHeap(), 0, buffer);
844 static void test_GetPrintProcessorDirectory(void)
846 LPBYTE buffer = NULL;
851 SetLastError(0xdeadbeef);
852 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
853 /* The deactivated Spooler is catched here on NT3.51 */
854 RETURN_ON_DEACTIVATED_SPOOLER(res)
855 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
856 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
857 res, GetLastError());
859 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
860 if(buffer == NULL) return;
863 SetLastError(0xdeadbeef);
864 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
865 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
867 SetLastError(0xdeadbeef);
869 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
870 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
872 /* Buffer to small */
874 SetLastError(0xdeadbeef);
875 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
876 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
877 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
878 res, GetLastError());
881 /* XPsp2: the programm will crash here, when the spooler is not running */
882 /* GetPrinterDriverDirectory has the same bug */
884 SetLastError(0xdeadbeef);
885 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
889 SetLastError(0xdeadbeef);
890 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
891 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
892 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
893 "returned %d with %ld (expected '!= 0' or '0' with " \
894 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
898 SetLastError(0xdeadbeef);
899 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
900 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
901 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
902 "returned %d with %ld (expected '!= 0' or '0' with " \
903 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
906 /* with a valid buffer, but level is invalid */
908 SetLastError(0xdeadbeef);
909 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
910 if (res && buffer[0])
912 /* Level is ignored in win9x*/
913 trace("invalid level (2) was ignored\n");
917 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
918 "returned %d with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
919 res, GetLastError());
922 /* Empty environment is the same as the default environment */
924 SetLastError(0xdeadbeef);
925 res = GetPrintProcessorDirectoryA(NULL, "", 1, buffer, cbBuf*2, &pcbNeeded);
926 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
928 /* "Windows 4.0" is valid for win9x and NT */
930 SetLastError(0xdeadbeef);
931 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
932 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
935 /* "Windows NT x86" is invalid for win9x */
937 SetLastError(0xdeadbeef);
938 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
939 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
940 "returned %d with %ld (expected '!= 0' or '0' with " \
941 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
943 /* invalid on all Systems */
945 SetLastError(0xdeadbeef);
946 res = GetPrintProcessorDirectoryA(NULL, "invalid_env", 1, buffer, cbBuf*2, &pcbNeeded);
947 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
948 "returned %d with %ld (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
949 res, GetLastError());
951 /* Empty servername is the same as the local computer */
953 SetLastError(0xdeadbeef);
954 res = GetPrintProcessorDirectoryA("", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
955 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
957 /* invalid on all Systems */
959 SetLastError(0xdeadbeef);
960 res = GetPrintProcessorDirectoryA("\\invalid_server", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
961 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
962 "returned %d with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
963 res, GetLastError());
965 HeapFree(GetProcessHeap(), 0, buffer);
970 static void test_OpenPrinter(void)
972 PRINTER_DEFAULTSA defaults;
974 LPSTR default_printer;
977 CHAR buffer[DEFAULT_PRINTER_SIZE];
980 SetLastError(MAGIC_DEAD);
981 res = OpenPrinter(NULL, NULL, NULL);
982 /* The deactivated Spooler is catched here on NT3.51 */
983 RETURN_ON_DEACTIVATED_SPOOLER(res)
984 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
985 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
986 res, GetLastError());
989 /* Get Handle for the local Printserver (NT only)*/
990 hprinter = (HANDLE) MAGIC_DEAD;
991 SetLastError(MAGIC_DEAD);
992 res = OpenPrinter(NULL, &hprinter, NULL);
993 /* The deactivated Spooler is catched here on XPsp2 */
994 RETURN_ON_DEACTIVATED_SPOOLER(res)
995 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
996 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
997 res, GetLastError());
999 ClosePrinter(hprinter);
1001 defaults.pDatatype=NULL;
1002 defaults.pDevMode=NULL;
1004 defaults.DesiredAccess=0;
1005 hprinter = (HANDLE) MAGIC_DEAD;
1006 SetLastError(MAGIC_DEAD);
1007 res = OpenPrinter(NULL, &hprinter, &defaults);
1008 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1009 if (res) ClosePrinter(hprinter);
1011 defaults.DesiredAccess=-1;
1012 hprinter = (HANDLE) MAGIC_DEAD;
1013 SetLastError(MAGIC_DEAD);
1014 res = OpenPrinter(NULL, &hprinter, &defaults);
1016 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1017 "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n",
1018 res, GetLastError());
1020 if (res) ClosePrinter(hprinter);
1024 size = sizeof(buffer) - 3 ;
1030 if (GetComputerNameA(ptr, &size)) {
1032 hprinter = (HANDLE) MAGIC_DEAD;
1033 SetLastError(MAGIC_DEAD);
1034 res = OpenPrinter(buffer, &hprinter, NULL);
1036 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1037 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1038 res, GetLastError());
1040 if(res) ClosePrinter(hprinter);
1043 /* Invalid Printername */
1044 hprinter = (HANDLE) MAGIC_DEAD;
1045 SetLastError(MAGIC_DEAD);
1046 res = OpenPrinter("illegal,name", &hprinter, NULL);
1047 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1048 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1049 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or" \
1050 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1051 if(res) ClosePrinter(hprinter);
1053 hprinter = (HANDLE) MAGIC_DEAD;
1054 SetLastError(MAGIC_DEAD);
1055 res = OpenPrinter("", &hprinter, NULL);
1056 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1058 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1059 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1060 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PRINTER_NAME" \
1061 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1062 if(res) ClosePrinter(hprinter);
1065 /* Get Handle for the default Printer */
1066 if ((default_printer = find_default_printer()))
1068 hprinter = (HANDLE) MAGIC_DEAD;
1069 SetLastError(MAGIC_DEAD);
1070 res = OpenPrinter(default_printer, &hprinter, NULL);
1071 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1073 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1076 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1077 if(res) ClosePrinter(hprinter);
1079 SetLastError(MAGIC_DEAD);
1080 res = OpenPrinter(default_printer, NULL, NULL);
1081 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1082 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1083 "returned %ld with %ld (expected '!=0' or '0' with " \
1084 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1086 defaults.pDatatype=NULL;
1087 defaults.pDevMode=NULL;
1088 defaults.DesiredAccess=0;
1090 hprinter = (HANDLE) MAGIC_DEAD;
1091 SetLastError(MAGIC_DEAD);
1092 res = OpenPrinter(default_printer, &hprinter, &defaults);
1093 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1094 "returned %ld with %ld (expected '!=0' or '0' with " \
1095 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1096 if(res) ClosePrinter(hprinter);
1098 defaults.pDatatype="";
1100 hprinter = (HANDLE) MAGIC_DEAD;
1101 SetLastError(MAGIC_DEAD);
1102 res = OpenPrinter(default_printer, &hprinter, &defaults);
1103 /* stop here, when a remote Printserver has no RPC-Service running */
1104 RETURN_ON_DEACTIVATED_SPOOLER(res)
1105 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1106 (GetLastError() == ERROR_ACCESS_DENIED)),
1107 "returned %ld with %ld (expected '!=0' or '0' with: " \
1108 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1109 res, GetLastError());
1110 if(res) ClosePrinter(hprinter);
1113 defaults.pDatatype=NULL;
1114 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1116 hprinter = (HANDLE) MAGIC_DEAD;
1117 SetLastError(MAGIC_DEAD);
1118 res = OpenPrinter(default_printer, &hprinter, &defaults);
1119 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1120 "returned %ld with %ld (expected '!=0' or '0' with " \
1121 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1122 if(res) ClosePrinter(hprinter);
1125 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1126 hprinter = (HANDLE) MAGIC_DEAD;
1127 SetLastError(MAGIC_DEAD);
1128 res = OpenPrinter(default_printer, &hprinter, &defaults);
1129 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1130 "returned %ld with %ld (expected '!=0' or '0' with " \
1131 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1132 if(res) ClosePrinter(hprinter);
1138 static void test_SetDefaultPrinter(void)
1141 LPSTR default_printer;
1142 DWORD size = DEFAULT_PRINTER_SIZE;
1143 CHAR buffer[DEFAULT_PRINTER_SIZE];
1144 CHAR org_value[DEFAULT_PRINTER_SIZE];
1147 if (!pSetDefaultPrinterA) return;
1148 /* only supported on win2k and above */
1150 default_printer = find_default_printer();
1152 /* backup the original value */
1153 org_value[0] = '\0';
1154 SetLastError(MAGIC_DEAD);
1155 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1157 /* first part: with the default Printer */
1158 SetLastError(MAGIC_DEAD);
1159 res = pSetDefaultPrinterA("no_printer_with_this_name");
1161 RETURN_ON_DEACTIVATED_SPOOLER(res)
1162 /* spooler is running or we have no spooler here*/
1164 /* Not implemented in wine */
1165 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1166 trace("SetDefaultPrinterA() not implemented yet.\n");
1170 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1171 "returned %ld with %ld (expected '0' with " \
1172 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1174 WriteProfileStringA("windows", "device", org_value);
1175 SetLastError(MAGIC_DEAD);
1176 res = pSetDefaultPrinterA("");
1177 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1178 "returned %ld with %ld (expected '!=0' or '0' with " \
1179 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1181 WriteProfileStringA("windows", "device", org_value);
1182 SetLastError(MAGIC_DEAD);
1183 res = pSetDefaultPrinterA(NULL);
1184 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1185 "returned %ld with %ld (expected '!=0' or '0' with " \
1186 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1188 WriteProfileStringA("windows", "device", org_value);
1189 SetLastError(MAGIC_DEAD);
1190 res = pSetDefaultPrinterA(default_printer);
1191 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1192 "returned %ld with %ld (expected '!=0' or '0' with " \
1193 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1196 /* second part: always without a default Printer */
1197 WriteProfileStringA("windows", "device", NULL);
1198 SetLastError(MAGIC_DEAD);
1199 res = pSetDefaultPrinterA("no_printer_with_this_name");
1201 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1202 "returned %ld with %ld (expected '0' with " \
1203 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1205 WriteProfileStringA("windows", "device", NULL);
1206 SetLastError(MAGIC_DEAD);
1207 res = pSetDefaultPrinterA("");
1208 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1209 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1210 "returned %ld with %ld (expected '!=0' or '0' with " \
1211 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1213 WriteProfileStringA("windows", "device", NULL);
1214 SetLastError(MAGIC_DEAD);
1215 res = pSetDefaultPrinterA(NULL);
1216 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1217 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1218 "returned %ld with %ld (expected '!=0' or '0' with " \
1219 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1221 WriteProfileStringA("windows", "device", NULL);
1222 SetLastError(MAGIC_DEAD);
1223 res = pSetDefaultPrinterA(default_printer);
1224 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1225 "returned %ld with %ld (expected '!=0' or '0' with " \
1226 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1228 /* restore the original value */
1229 res = pSetDefaultPrinterA(default_printer); /* the nice way */
1230 WriteProfileStringA("windows", "device", org_value); /* the old way */
1233 SetLastError(MAGIC_DEAD);
1234 res = GetProfileStringA("windows", "device", NULL, buffer, size);
1235 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1239 static void test_GetPrinterDriver(void)
1241 LPSTR default_printer;
1246 DWORD needed, filled;
1248 default_printer = find_default_printer();
1249 if (!default_printer)
1251 trace("There is no default printer installed, skiping the test\n");
1256 ret = OpenPrinter(default_printer, &hprn, NULL);
1259 trace("There is no printers installed, skiping the test\n");
1262 ok(hprn != 0, "wrong hprn %p\n", hprn);
1264 for (level = -1; level <= 7; level++)
1266 SetLastError(0xdeadbeef);
1268 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
1269 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
1270 if (level >= 1 && level <= 6)
1272 /* Not all levels are supported on all Windows-Versions */
1273 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
1274 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
1275 ok(needed > 0,"not expected needed buffer size %ld\n", needed);
1279 /* ERROR_OUTOFMEMORY found on win9x */
1280 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
1281 (GetLastError() == ERROR_OUTOFMEMORY)),
1282 "%d: returned %d with %ld (expected '0' with: " \
1283 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1284 level, ret, GetLastError());
1285 /* needed is modified in win9x. The modified Value depends on the
1286 default Printer. testing for "needed == (DWORD)-1" will fail */
1290 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1292 SetLastError(0xdeadbeef);
1294 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
1295 ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
1296 ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
1300 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
1301 DWORD calculated = sizeof(*di_2);
1303 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1304 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1305 ok((di_2->cVersion >= 0 && di_2->cVersion <= 3) ||
1306 (di_2->cVersion == 0x0400), "di_2->cVersion = %ld\n", di_2->cVersion);
1307 ok(di_2->pName != NULL, "not expected NULL ptr\n");
1308 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
1309 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
1310 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
1311 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
1313 trace("cVersion %ld\n", di_2->cVersion);
1314 trace("pName %s\n", di_2->pName);
1315 calculated += strlen(di_2->pName) + 1;
1316 trace("pEnvironment %s\n", di_2->pEnvironment);
1317 calculated += strlen(di_2->pEnvironment) + 1;
1318 trace("pDriverPath %s\n", di_2->pDriverPath);
1319 calculated += strlen(di_2->pDriverPath) + 1;
1320 trace("pDataFile %s\n", di_2->pDataFile);
1321 calculated += strlen(di_2->pDataFile) + 1;
1322 trace("pConfigFile %s\n", di_2->pConfigFile);
1323 calculated += strlen(di_2->pConfigFile) + 1;
1325 /* XP allocates memory for both ANSI and unicode names */
1326 ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
1329 HeapFree(GetProcessHeap(), 0, buf);
1332 SetLastError(0xdeadbeef);
1333 ret = ClosePrinter(hprn);
1334 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1337 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
1339 /* On NT3.51, some fields in DEVMODE are empty/zero
1340 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1341 We skip the Tests on this Platform */
1342 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
1343 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1344 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
1345 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
1346 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
1347 "%u != %ld\n", dm->dmSize + dm->dmDriverExtra, dmSize);
1349 trace("dmFields %08lx\n", dm->dmFields);
1352 static void test_DocumentProperties(void)
1354 LPSTR default_printer;
1359 default_printer = find_default_printer();
1360 if (!default_printer)
1362 trace("There is no default printer installed, skiping the test\n");
1367 ret = OpenPrinter(default_printer, &hprn, NULL);
1370 trace("There is no printers installed, skiping the test\n");
1373 ok(hprn != 0, "wrong hprn %p\n", hprn);
1375 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
1376 trace("DEVMODE required size %ld\n", dm_size);
1377 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %ld\n", dm_size);
1379 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
1381 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
1382 ok(ret == IDOK, "DocumentProperties ret value %ld != expected IDOK\n", ret);
1384 test_DEVMODE(dm, dm_size, default_printer);
1386 HeapFree(GetProcessHeap(), 0, dm);
1388 SetLastError(0xdeadbeef);
1389 ret = ClosePrinter(hprn);
1390 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1395 LPSTR default_printer;
1397 hwinspool = GetModuleHandleA("winspool.drv");
1398 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
1399 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
1401 default_printer = find_default_printer();
1404 test_DeleteMonitor();
1405 test_DocumentProperties();
1406 test_EnumForms(NULL);
1407 if (default_printer) test_EnumForms(default_printer);
1408 test_EnumMonitors();
1409 test_GetDefaultPrinter();
1410 test_GetPrinterDriverDirectory();
1411 test_GetPrintProcessorDirectory();
1413 test_GetPrinterDriver();
1414 test_SetDefaultPrinter();