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 does_not_exist_dll[]= "does_not_exists.dll";
36 static CHAR empty[] = "";
37 static CHAR env_x86[] = "Windows NT x86";
38 static CHAR env_win9x_case[] = "windowS 4.0";
39 static CHAR illegal_name[] = "illegal,name";
40 static CHAR invalid_env[] = "invalid_env";
41 static CHAR invalid_server[] = "\\invalid_server";
42 static CHAR version_dll[] = "version.dll";
43 static CHAR winetest_monitor[] = "winetest";
45 static HANDLE hwinspool;
46 static FARPROC pGetDefaultPrinterA;
47 static FARPROC pSetDefaultPrinterA;
49 struct monitor_entry {
54 /* report common behavior only once */
55 static DWORD report_deactivated_spooler = 1;
56 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
57 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
59 if(report_deactivated_spooler > 0) { \
60 report_deactivated_spooler--; \
61 trace("The Service 'Spooler' is required for many test\n"); \
67 static LPSTR find_default_printer(VOID)
69 static LPSTR default_printer = NULL;
70 static char buffer[DEFAULT_PRINTER_SIZE];
75 if ((default_printer == NULL) && (pGetDefaultPrinterA))
78 needed = sizeof(buffer);
79 res = pGetDefaultPrinterA(buffer, &needed);
80 if(res) default_printer = buffer;
81 trace("default_printer: '%s'\n", default_printer);
83 if (default_printer == NULL)
87 /* NT 3.x and above */
88 if (RegOpenKeyEx(HKEY_CURRENT_USER,
89 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
90 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
92 needed = sizeof(buffer);
93 if (RegQueryValueEx(hwindows, "device", NULL,
94 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
96 ptr = strchr(buffer, ',');
99 default_printer = buffer;
102 RegCloseKey(hwindows);
104 trace("default_printer: '%s'\n", default_printer);
106 if (default_printer == NULL)
109 needed = sizeof(buffer);
110 res = GetProfileStringA("windows", "device", "*", buffer, needed);
112 ptr = strchr(buffer, ',');
115 default_printer = buffer;
118 trace("default_printer: '%s'\n", default_printer);
120 return default_printer;
124 static struct monitor_entry * find_installed_monitor(void)
126 MONITOR_INFO_2A mi2a;
127 static struct monitor_entry * entry = NULL;
131 static struct monitor_entry monitor_table[] = {
132 {env_win9x_case, "localspl.dll"},
133 {env_x86, "localspl.dll"},
134 {env_win9x_case, "localmon.dll"},
135 {env_x86, "localmon.dll"},
136 {env_win9x_case, "tcpmon.dll"},
137 {env_x86, "tcpmon.dll"},
138 {env_win9x_case, "usbmon.dll"},
139 {env_x86, "usbmon.dll"},
140 {env_win9x_case, "mspp32.dll"},
141 {env_x86, "win32spl.dll"},
142 {env_x86, "redmonnt.dll"},
143 {env_x86, "redmon35.dll"},
144 {env_win9x_case, "redmon95.dll"},
145 {env_x86, "pdfcmnnt.dll"},
146 {env_win9x_case, "pdfcmn95.dll"},
149 if (entry) return entry;
151 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
154 DeleteMonitorA(NULL, env_x86, winetest_monitor);
155 DeleteMonitorA(NULL, env_win9x_case, winetest_monitor);
157 /* find a usable monitor from the table */
158 mi2a.pName = winetest_monitor;
159 while ((entry == NULL) && (i < num_tests)) {
160 entry = &monitor_table[i];
162 mi2a.pEnvironment = entry->env;
163 mi2a.pDLLName = entry->dllname;
165 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
167 trace("using '%s', '%s'\n", entry->env, entry->dllname);
168 DeleteMonitorA(NULL, entry->env, winetest_monitor);
178 /* ########################### */
181 static void test_AddMonitor(void)
183 MONITOR_INFO_2A mi2a;
184 struct monitor_entry * entry = NULL;
187 entry = find_installed_monitor();
189 SetLastError(MAGIC_DEAD);
190 res = AddMonitorA(NULL, 1, NULL);
191 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
192 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
193 res, GetLastError());
195 SetLastError(MAGIC_DEAD);
196 res = AddMonitorA(NULL, 3, NULL);
197 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
198 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
199 res, GetLastError());
202 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
203 SetLastError(MAGIC_DEAD);
204 res = AddMonitorA(NULL, 2, NULL);
205 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
207 ((GetLastError() == MAGIC_DEAD) ||
208 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
209 "returned %ld with %ld (expected '0' with: MAGIC_DEAD or " \
210 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
213 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
214 SetLastError(MAGIC_DEAD);
215 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
216 RETURN_ON_DEACTIVATED_SPOOLER(res)
218 if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
219 trace("skip tests (ACCESS_DENIED)\n");
223 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
224 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
225 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
226 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
227 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
230 trace("No usable Monitor found: Skip tests\n");
235 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
236 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
237 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
238 is created on win9x and we do not want to hit this bug here. */
240 mi2a.pEnvironment = entry->env;
241 SetLastError(MAGIC_DEAD);
242 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
243 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
246 mi2a.pEnvironment = entry->env;
248 SetLastError(MAGIC_DEAD);
249 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
250 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
252 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
253 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
254 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
255 "ERROR_PRIVILEGE_NOT_HELD)\n",
256 res, GetLastError());
258 mi2a.pName = winetest_monitor;
259 SetLastError(MAGIC_DEAD);
260 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
261 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
263 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
264 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
265 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
266 "ERROR_PRIVILEGE_NOT_HELD)\n",
267 res, GetLastError());
269 mi2a.pDLLName = empty;
270 SetLastError(MAGIC_DEAD);
271 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
272 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
273 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
274 res, GetLastError());
276 mi2a.pDLLName = does_not_exist_dll;
277 SetLastError(MAGIC_DEAD);
278 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
279 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
281 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
282 (GetLastError() == ERROR_INVALID_PARAMETER)),
283 "returned %ld with %ld (expected '0' with: ERROR_MOD_NOT_FOUND or " \
284 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
286 mi2a.pDLLName = version_dll;
287 SetLastError(MAGIC_DEAD);
288 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
289 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
291 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
292 (GetLastError() == ERROR_INVALID_PARAMETER)),
293 "returned %ld with %ld (expected '0' with: ERROR_PROC_NOT_FOUND or " \
294 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
295 if (res) DeleteMonitorA(NULL, entry->env, winetest_monitor);
297 /* Test AddMonitor with real options */
298 mi2a.pDLLName = entry->dllname;
299 SetLastError(MAGIC_DEAD);
300 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
301 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
303 /* add a monitor twice */
304 SetLastError(MAGIC_DEAD);
305 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
306 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
308 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
309 (GetLastError() == ERROR_ALREADY_EXISTS)),
310 "returned %ld with %ld (expected '0' with: " \
311 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
312 res, GetLastError());
314 DeleteMonitorA(NULL, entry->env, winetest_monitor);
315 SetLastError(MAGIC_DEAD);
316 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
317 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
320 DeleteMonitorA(NULL, entry->env, winetest_monitor);
324 /* ########################### */
326 static void test_DeleteMonitor(void)
328 MONITOR_INFO_2A mi2a;
329 struct monitor_entry * entry = NULL;
333 entry = find_installed_monitor();
336 trace("No usable Monitor found: Skip tests\n");
340 mi2a.pName = winetest_monitor;
341 mi2a.pEnvironment = entry->env;
342 mi2a.pDLLName = entry->dllname;
344 /* Testing DeleteMonitor with real options */
345 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
347 SetLastError(MAGIC_DEAD);
348 res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
349 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
351 /* Delete the Monitor twice */
352 SetLastError(MAGIC_DEAD);
353 res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
354 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
356 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
357 (GetLastError() == ERROR_INVALID_PARAMETER)),
358 "returned %ld with %ld (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR" \
359 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
361 /* the environment */
362 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
363 SetLastError(MAGIC_DEAD);
364 res = DeleteMonitorA(NULL, NULL, winetest_monitor);
365 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
367 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
368 SetLastError(MAGIC_DEAD);
369 res = DeleteMonitorA(NULL, empty, winetest_monitor);
370 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
372 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
373 SetLastError(MAGIC_DEAD);
374 res = DeleteMonitorA(NULL, invalid_env, winetest_monitor);
375 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
377 /* the monitor-name */
378 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
379 SetLastError(MAGIC_DEAD);
380 res = DeleteMonitorA(NULL, entry->env, NULL);
381 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
383 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
384 (GetLastError() == ERROR_INVALID_NAME)),
385 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
386 "ERROR_INVALID_NAME)\n", res, GetLastError());
388 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
389 SetLastError(MAGIC_DEAD);
390 res = DeleteMonitorA(NULL, entry->env, empty);
391 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
393 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
394 (GetLastError() == ERROR_INVALID_NAME)),
395 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
396 "ERROR_INVALID_NAME)\n", res, GetLastError());
398 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
399 SetLastError(MAGIC_DEAD);
400 res = DeleteMonitorA(empty, entry->env, winetest_monitor);
401 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
404 DeleteMonitorA(NULL, entry->env, winetest_monitor);
409 static void test_EnumForms(LPSTR pName)
420 res = OpenPrinter(pName, &hprinter, NULL);
421 RETURN_ON_DEACTIVATED_SPOOLER(res)
422 if (!res || !hprinter)
424 /* Open the local Prinserver is not supported on win9x */
425 if (pName) trace("Failed to open '%s', skiping the test\n", pName);
429 /* valid levels are 1 and 2 */
430 for(level = 0; level < 4; level++) {
432 pcReturned = 0xdeadbeef;
433 SetLastError(0xdeadbeef);
434 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
436 /* EnumForms is not implemented in win9x */
437 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
439 /* EnumForms for the Server not implemented on all NT-Versions */
440 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
442 /* Level 2 for EnumForms is not supported on all systems */
443 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
445 /* use only a short test, when we test with an invalid level */
446 if(!level || (level > 2)) {
447 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
448 (res && (pcReturned == 0)),
449 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
450 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
451 level, res, GetLastError(), pcReturned);
455 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
456 "(%ld) returned %ld with %ld (expected '0' with " \
457 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
459 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
460 if (buffer == NULL) continue;
462 SetLastError(0xdeadbeef);
463 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
464 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
465 level, res, GetLastError());
466 /* We can dump the returned Data here */
469 SetLastError(0xdeadbeef);
470 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
471 ok( res, "(%ld) returned %ld with %ld (expected '!=0')\n",
472 level, res, GetLastError());
474 SetLastError(0xdeadbeef);
475 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
476 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
477 "(%ld) returned %ld with %ld (expected '0' with " \
478 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
481 SetLastError(0xdeadbeef);
482 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
483 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
484 "(%ld) returned %ld with %ld (expected '0' with "\
485 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
488 SetLastError(0xdeadbeef);
489 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
490 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
491 "(%ld) returned %ld with %ld (expected '0' with "\
492 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
494 SetLastError(0xdeadbeef);
495 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
496 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
497 "(%ld) returned %ld with %ld (expected '0' with "\
498 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
500 SetLastError(0xdeadbeef);
501 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
502 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
503 "(%ld) returned %ld with %ld (expected '0' with "\
504 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
506 HeapFree(GetProcessHeap(), 0, buffer);
507 } /* for(level ... */
509 ClosePrinter(hprinter);
512 /* ########################### */
514 static void test_EnumMonitors(void)
523 /* valid levels are 1 and 2 */
524 for(level = 0; level < 4; level++) {
526 pcReturned = MAGIC_DEAD;
527 SetLastError(MAGIC_DEAD);
528 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
530 RETURN_ON_DEACTIVATED_SPOOLER(res)
532 /* not implemented yet in wine */
533 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
536 /* use only a short test, when we test with an invalid level */
537 if(!level || (level > 2)) {
538 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
539 (res && (pcReturned == 0)),
540 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
541 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
542 level, res, GetLastError(), pcReturned);
546 /* Level 2 is not supported on win9x */
547 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
548 trace("Level %ld not supported, skipping tests\n", level);
552 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
553 "(%ld) returned %ld with %ld (expected '0' with " \
554 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
557 trace("no valid buffer size returned, skipping tests\n");
561 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
562 if (buffer == NULL) continue;
564 SetLastError(MAGIC_DEAD);
565 pcbNeeded = MAGIC_DEAD;
566 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
567 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
568 level, res, GetLastError());
569 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n",
570 level, pcbNeeded, cbBuf);
571 /* We can validate the returned Data with the Registry here */
574 SetLastError(MAGIC_DEAD);
575 pcReturned = MAGIC_DEAD;
576 pcbNeeded = MAGIC_DEAD;
577 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
578 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level,
579 res, GetLastError());
580 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
583 SetLastError(MAGIC_DEAD);
584 pcbNeeded = MAGIC_DEAD;
585 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
586 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
587 "(%ld) returned %ld with %ld (expected '0' with " \
588 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
590 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
594 Do not add the next test:
595 w2k+: RPC_X_NULL_REF_POINTER
596 NT3.5: ERROR_INVALID_USER_BUFFER
597 win9x: crash in winspool.drv
599 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
602 SetLastError(MAGIC_DEAD);
603 pcbNeeded = MAGIC_DEAD;
604 pcReturned = MAGIC_DEAD;
605 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
606 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
607 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
608 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
610 pcbNeeded = MAGIC_DEAD;
611 pcReturned = MAGIC_DEAD;
612 SetLastError(MAGIC_DEAD);
613 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
614 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
615 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
616 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
618 HeapFree(GetProcessHeap(), 0, buffer);
619 } /* for(level ... */
623 static void test_GetDefaultPrinter(void)
626 DWORD exact = DEFAULT_PRINTER_SIZE;
628 char buffer[DEFAULT_PRINTER_SIZE];
630 if (!pGetDefaultPrinterA) return;
631 /* only supported on NT like OSes starting with win2k */
633 SetLastError(ERROR_SUCCESS);
634 retval = pGetDefaultPrinterA(buffer, &exact);
635 if (!retval || !exact || !strlen(buffer) ||
636 (ERROR_SUCCESS != GetLastError())) {
637 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
638 (ERROR_INVALID_NAME == GetLastError()))
639 trace("this test requires a default printer to be set\n");
641 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
642 "function returned %s\n"
643 "last error 0x%08lx\n"
644 "returned buffer size 0x%08lx\n"
645 "returned buffer content %s\n",
646 retval ? "true" : "false", GetLastError(), exact, buffer);
650 SetLastError(ERROR_SUCCESS);
651 retval = pGetDefaultPrinterA(NULL, NULL);
652 ok( !retval, "function result wrong! False expected\n");
653 ok( ERROR_INVALID_PARAMETER == GetLastError(),
654 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
657 SetLastError(ERROR_SUCCESS);
658 retval = pGetDefaultPrinterA(buffer, NULL);
659 ok( !retval, "function result wrong! False expected\n");
660 ok( ERROR_INVALID_PARAMETER == GetLastError(),
661 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
664 SetLastError(ERROR_SUCCESS);
666 retval = pGetDefaultPrinterA(NULL, &size);
667 ok( !retval, "function result wrong! False expected\n");
668 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
669 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
671 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
674 SetLastError(ERROR_SUCCESS);
675 size = DEFAULT_PRINTER_SIZE;
676 retval = pGetDefaultPrinterA(NULL, &size);
677 ok( !retval, "function result wrong! False expected\n");
678 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
679 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
681 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
685 retval = pGetDefaultPrinterA(buffer, &size);
686 ok( !retval, "function result wrong! False expected\n");
687 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
688 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
690 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
694 retval = pGetDefaultPrinterA(buffer, &size);
695 ok( retval, "function result wrong! True expected\n");
696 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
700 static void test_GetPrinterDriverDirectory(void)
702 LPBYTE buffer = NULL;
703 DWORD cbBuf = 0, pcbNeeded = 0;
707 SetLastError(MAGIC_DEAD);
708 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
709 trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
710 res, GetLastError(), cbBuf);
712 RETURN_ON_DEACTIVATED_SPOOLER(res)
713 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
714 "returned %d with lasterror=%ld (expected '0' with " \
715 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
718 trace("no valid buffer size returned, skipping tests\n");
722 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
723 if (buffer == NULL) return ;
725 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
726 ok( res, "expected result != 0, got %d\n", res);
727 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
730 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
731 ok( res, "expected result != 0, got %d\n", res);
732 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
735 SetLastError(MAGIC_DEAD);
736 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
737 ok( !res , "expected result == 0, got %d\n", res);
738 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
741 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
742 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
746 Do not add the next test:
747 XPsp2: crash in this app, when the spooler is not running
748 NT3.5: ERROR_INVALID_USER_BUFFER
749 win9x: ERROR_INVALID_PARAMETER
751 pcbNeeded = MAGIC_DEAD;
752 SetLastError(MAGIC_DEAD);
753 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
756 SetLastError(MAGIC_DEAD);
757 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
758 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
759 "expected either result == 0 and "
760 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
761 "got result %d and last error == %ld\n", res, GetLastError());
763 SetLastError(MAGIC_DEAD);
764 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
765 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
766 "returned %d with %ld (expected '!=0' or '0' with " \
767 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
770 /* with a valid buffer, but level is too large */
772 SetLastError(MAGIC_DEAD);
773 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
775 /* Level not checked in win9x and wine:*/
776 if((res != FALSE) && buffer[0])
778 trace("Level '2' not checked '%s'\n", buffer);
782 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
783 "returned %d with lasterror=%ld (expected '0' with " \
784 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
787 /* printing environments are case insensitive */
788 /* "Windows 4.0" is valid for win9x and NT */
790 SetLastError(MAGIC_DEAD);
791 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
792 buffer, cbBuf*2, &pcbNeeded);
794 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
796 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
797 if (buffer == NULL) return ;
799 SetLastError(MAGIC_DEAD);
800 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
801 buffer, cbBuf*2, &pcbNeeded);
804 ok(res && buffer[0], "returned %d with " \
805 "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n",
806 res, GetLastError(), lstrlenA((char *)buffer));
809 SetLastError(MAGIC_DEAD);
810 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
811 buffer, cbBuf*2, &pcbNeeded);
813 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
815 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
816 if (buffer == NULL) return ;
819 SetLastError(MAGIC_DEAD);
820 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
821 buffer, cbBuf*2, &pcbNeeded);
824 /* "Windows NT x86" is invalid for win9x */
825 ok( (res && buffer[0]) ||
826 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
827 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
828 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
829 res, GetLastError(), lstrlenA((char *)buffer));
831 /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
832 SetLastError(MAGIC_DEAD);
833 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
834 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
836 SetLastError(MAGIC_DEAD);
837 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
838 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
840 SetLastError(MAGIC_DEAD);
841 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
842 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
844 HeapFree( GetProcessHeap(), 0, buffer);
849 static void test_GetPrintProcessorDirectory(void)
851 LPBYTE buffer = NULL;
857 SetLastError(0xdeadbeef);
858 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
859 /* The deactivated Spooler is catched here on NT3.51 */
860 RETURN_ON_DEACTIVATED_SPOOLER(res)
861 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
862 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
863 res, GetLastError());
865 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
866 if(buffer == NULL) return;
869 SetLastError(0xdeadbeef);
870 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
871 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
873 SetLastError(0xdeadbeef);
875 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
876 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
878 /* Buffer to small */
880 SetLastError(0xdeadbeef);
881 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
882 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
883 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
884 res, GetLastError());
887 /* XPsp2: the programm will crash here, when the spooler is not running */
888 /* GetPrinterDriverDirectory has the same bug */
890 SetLastError(0xdeadbeef);
891 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
895 SetLastError(0xdeadbeef);
896 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
897 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
898 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
899 "returned %d with %ld (expected '!= 0' or '0' with " \
900 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
904 SetLastError(0xdeadbeef);
905 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
906 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
907 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
908 "returned %d with %ld (expected '!= 0' or '0' with " \
909 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
912 /* with a valid buffer, but level is invalid */
914 SetLastError(0xdeadbeef);
915 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
916 if (res && buffer[0])
918 /* Level is ignored in win9x*/
919 trace("invalid level (2) was ignored\n");
923 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
924 "returned %d with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
925 res, GetLastError());
928 /* Empty environment is the same as the default environment */
930 SetLastError(0xdeadbeef);
931 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
932 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
934 /* "Windows 4.0" is valid for win9x and NT */
936 SetLastError(0xdeadbeef);
937 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
938 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
941 /* "Windows NT x86" is invalid for win9x */
943 SetLastError(0xdeadbeef);
944 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
945 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
946 "returned %d with %ld (expected '!= 0' or '0' with " \
947 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
949 /* invalid on all Systems */
951 SetLastError(0xdeadbeef);
952 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
953 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
954 "returned %d with %ld (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
955 res, GetLastError());
957 /* Empty servername is the same as the local computer */
959 SetLastError(0xdeadbeef);
960 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
961 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
963 /* invalid on all Systems */
965 SetLastError(0xdeadbeef);
966 res = GetPrintProcessorDirectoryA(invalid_server, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
967 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
968 "returned %d with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
969 res, GetLastError());
971 HeapFree(GetProcessHeap(), 0, buffer);
976 static void test_OpenPrinter(void)
978 PRINTER_DEFAULTSA defaults;
980 LPSTR default_printer;
983 CHAR buffer[DEFAULT_PRINTER_SIZE];
987 SetLastError(MAGIC_DEAD);
988 res = OpenPrinter(NULL, NULL, NULL);
989 /* The deactivated Spooler is catched here on NT3.51 */
990 RETURN_ON_DEACTIVATED_SPOOLER(res)
991 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
992 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
993 res, GetLastError());
996 /* Get Handle for the local Printserver (NT only)*/
997 hprinter = (HANDLE) MAGIC_DEAD;
998 SetLastError(MAGIC_DEAD);
999 res = OpenPrinter(NULL, &hprinter, NULL);
1000 /* The deactivated Spooler is catched here on XPsp2 */
1001 RETURN_ON_DEACTIVATED_SPOOLER(res)
1002 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1003 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1004 res, GetLastError());
1006 ClosePrinter(hprinter);
1008 defaults.pDatatype=NULL;
1009 defaults.pDevMode=NULL;
1011 defaults.DesiredAccess=0;
1012 hprinter = (HANDLE) MAGIC_DEAD;
1013 SetLastError(MAGIC_DEAD);
1014 res = OpenPrinter(NULL, &hprinter, &defaults);
1015 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1016 if (res) ClosePrinter(hprinter);
1018 defaults.DesiredAccess=-1;
1019 hprinter = (HANDLE) MAGIC_DEAD;
1020 SetLastError(MAGIC_DEAD);
1021 res = OpenPrinter(NULL, &hprinter, &defaults);
1023 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1024 "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n",
1025 res, GetLastError());
1027 if (res) ClosePrinter(hprinter);
1031 size = sizeof(buffer) - 3 ;
1037 if (GetComputerNameA(ptr, &size)) {
1039 hprinter = (HANDLE) MAGIC_DEAD;
1040 SetLastError(MAGIC_DEAD);
1041 res = OpenPrinter(buffer, &hprinter, NULL);
1043 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1044 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1045 res, GetLastError());
1047 if(res) ClosePrinter(hprinter);
1050 /* Invalid Printername */
1051 hprinter = (HANDLE) MAGIC_DEAD;
1052 SetLastError(MAGIC_DEAD);
1053 res = OpenPrinter(illegal_name, &hprinter, NULL);
1054 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1055 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1056 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or" \
1057 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1058 if(res) ClosePrinter(hprinter);
1060 hprinter = (HANDLE) MAGIC_DEAD;
1061 SetLastError(MAGIC_DEAD);
1062 res = OpenPrinter(empty, &hprinter, NULL);
1063 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1065 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1066 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1067 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PRINTER_NAME" \
1068 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1069 if(res) ClosePrinter(hprinter);
1072 /* Get Handle for the default Printer */
1073 if ((default_printer = find_default_printer()))
1075 hprinter = (HANDLE) MAGIC_DEAD;
1076 SetLastError(MAGIC_DEAD);
1077 res = OpenPrinter(default_printer, &hprinter, NULL);
1078 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1080 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1083 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1084 if(res) ClosePrinter(hprinter);
1086 SetLastError(MAGIC_DEAD);
1087 res = OpenPrinter(default_printer, NULL, NULL);
1088 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1089 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1090 "returned %ld with %ld (expected '!=0' or '0' with " \
1091 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1093 defaults.pDatatype=NULL;
1094 defaults.pDevMode=NULL;
1095 defaults.DesiredAccess=0;
1097 hprinter = (HANDLE) MAGIC_DEAD;
1098 SetLastError(MAGIC_DEAD);
1099 res = OpenPrinter(default_printer, &hprinter, &defaults);
1100 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1101 "returned %ld with %ld (expected '!=0' or '0' with " \
1102 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1103 if(res) ClosePrinter(hprinter);
1105 defaults.pDatatype = empty;
1107 hprinter = (HANDLE) MAGIC_DEAD;
1108 SetLastError(MAGIC_DEAD);
1109 res = OpenPrinter(default_printer, &hprinter, &defaults);
1110 /* stop here, when a remote Printserver has no RPC-Service running */
1111 RETURN_ON_DEACTIVATED_SPOOLER(res)
1112 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1113 (GetLastError() == ERROR_ACCESS_DENIED)),
1114 "returned %ld with %ld (expected '!=0' or '0' with: " \
1115 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1116 res, GetLastError());
1117 if(res) ClosePrinter(hprinter);
1120 defaults.pDatatype=NULL;
1121 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1123 hprinter = (HANDLE) MAGIC_DEAD;
1124 SetLastError(MAGIC_DEAD);
1125 res = OpenPrinter(default_printer, &hprinter, &defaults);
1126 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1127 "returned %ld with %ld (expected '!=0' or '0' with " \
1128 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1129 if(res) ClosePrinter(hprinter);
1132 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1133 hprinter = (HANDLE) MAGIC_DEAD;
1134 SetLastError(MAGIC_DEAD);
1135 res = OpenPrinter(default_printer, &hprinter, &defaults);
1136 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1137 "returned %ld with %ld (expected '!=0' or '0' with " \
1138 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1139 if(res) ClosePrinter(hprinter);
1145 static void test_SetDefaultPrinter(void)
1148 LPSTR default_printer;
1149 DWORD size = DEFAULT_PRINTER_SIZE;
1150 CHAR buffer[DEFAULT_PRINTER_SIZE];
1151 CHAR org_value[DEFAULT_PRINTER_SIZE];
1154 if (!pSetDefaultPrinterA) return;
1155 /* only supported on win2k and above */
1157 default_printer = find_default_printer();
1159 /* backup the original value */
1160 org_value[0] = '\0';
1161 SetLastError(MAGIC_DEAD);
1162 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1164 /* first part: with the default Printer */
1165 SetLastError(MAGIC_DEAD);
1166 res = pSetDefaultPrinterA("no_printer_with_this_name");
1168 RETURN_ON_DEACTIVATED_SPOOLER(res)
1169 /* spooler is running or we have no spooler here*/
1171 /* Not implemented in wine */
1172 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1173 trace("SetDefaultPrinterA() not implemented yet.\n");
1177 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1178 "returned %ld with %ld (expected '0' with " \
1179 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1181 WriteProfileStringA("windows", "device", org_value);
1182 SetLastError(MAGIC_DEAD);
1183 res = pSetDefaultPrinterA("");
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(NULL);
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());
1195 WriteProfileStringA("windows", "device", org_value);
1196 SetLastError(MAGIC_DEAD);
1197 res = pSetDefaultPrinterA(default_printer);
1198 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1199 "returned %ld with %ld (expected '!=0' or '0' with " \
1200 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1203 /* second part: always without a default Printer */
1204 WriteProfileStringA("windows", "device", NULL);
1205 SetLastError(MAGIC_DEAD);
1206 res = pSetDefaultPrinterA("no_printer_with_this_name");
1208 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1209 "returned %ld with %ld (expected '0' with " \
1210 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1212 WriteProfileStringA("windows", "device", NULL);
1213 SetLastError(MAGIC_DEAD);
1214 res = pSetDefaultPrinterA("");
1215 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1216 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1217 "returned %ld with %ld (expected '!=0' or '0' with " \
1218 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1220 WriteProfileStringA("windows", "device", NULL);
1221 SetLastError(MAGIC_DEAD);
1222 res = pSetDefaultPrinterA(NULL);
1223 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
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 WriteProfileStringA("windows", "device", NULL);
1229 SetLastError(MAGIC_DEAD);
1230 res = pSetDefaultPrinterA(default_printer);
1231 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1232 "returned %ld with %ld (expected '!=0' or '0' with " \
1233 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1235 /* restore the original value */
1236 res = pSetDefaultPrinterA(default_printer); /* the nice way */
1237 WriteProfileStringA("windows", "device", org_value); /* the old way */
1240 SetLastError(MAGIC_DEAD);
1241 res = GetProfileStringA("windows", "device", NULL, buffer, size);
1242 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1246 static void test_GetPrinterDriver(void)
1248 LPSTR default_printer;
1253 DWORD needed, filled;
1255 default_printer = find_default_printer();
1256 if (!default_printer)
1258 trace("There is no default printer installed, skiping the test\n");
1263 ret = OpenPrinter(default_printer, &hprn, NULL);
1266 trace("There is no printers installed, skiping the test\n");
1269 ok(hprn != 0, "wrong hprn %p\n", hprn);
1271 for (level = -1; level <= 7; level++)
1273 SetLastError(0xdeadbeef);
1275 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
1276 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
1277 if (level >= 1 && level <= 6)
1279 /* Not all levels are supported on all Windows-Versions */
1280 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
1281 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
1282 ok(needed > 0,"not expected needed buffer size %ld\n", needed);
1286 /* ERROR_OUTOFMEMORY found on win9x */
1287 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
1288 (GetLastError() == ERROR_OUTOFMEMORY)),
1289 "%d: returned %d with %ld (expected '0' with: " \
1290 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1291 level, ret, GetLastError());
1292 /* needed is modified in win9x. The modified Value depends on the
1293 default Printer. testing for "needed == (DWORD)-1" will fail */
1297 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1299 SetLastError(0xdeadbeef);
1301 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
1302 ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
1303 ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
1307 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
1308 DWORD calculated = sizeof(*di_2);
1310 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1311 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1312 ok((di_2->cVersion >= 0 && di_2->cVersion <= 3) ||
1313 (di_2->cVersion == 0x0400), "di_2->cVersion = %ld\n", di_2->cVersion);
1314 ok(di_2->pName != NULL, "not expected NULL ptr\n");
1315 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
1316 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
1317 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
1318 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
1320 trace("cVersion %ld\n", di_2->cVersion);
1321 trace("pName %s\n", di_2->pName);
1322 calculated += strlen(di_2->pName) + 1;
1323 trace("pEnvironment %s\n", di_2->pEnvironment);
1324 calculated += strlen(di_2->pEnvironment) + 1;
1325 trace("pDriverPath %s\n", di_2->pDriverPath);
1326 calculated += strlen(di_2->pDriverPath) + 1;
1327 trace("pDataFile %s\n", di_2->pDataFile);
1328 calculated += strlen(di_2->pDataFile) + 1;
1329 trace("pConfigFile %s\n", di_2->pConfigFile);
1330 calculated += strlen(di_2->pConfigFile) + 1;
1332 /* XP allocates memory for both ANSI and unicode names */
1333 ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
1336 HeapFree(GetProcessHeap(), 0, buf);
1339 SetLastError(0xdeadbeef);
1340 ret = ClosePrinter(hprn);
1341 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1344 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
1346 /* On NT3.51, some fields in DEVMODE are empty/zero
1347 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1348 We skip the Tests on this Platform */
1349 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
1350 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1351 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
1352 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
1353 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
1354 "%u != %ld\n", dm->dmSize + dm->dmDriverExtra, dmSize);
1356 trace("dmFields %08lx\n", dm->dmFields);
1359 static void test_DocumentProperties(void)
1361 LPSTR default_printer;
1366 default_printer = find_default_printer();
1367 if (!default_printer)
1369 trace("There is no default printer installed, skiping the test\n");
1374 ret = OpenPrinter(default_printer, &hprn, NULL);
1377 trace("There is no printers installed, skiping the test\n");
1380 ok(hprn != 0, "wrong hprn %p\n", hprn);
1382 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
1383 trace("DEVMODE required size %ld\n", dm_size);
1384 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %ld\n", dm_size);
1386 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
1388 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
1389 ok(ret == IDOK, "DocumentProperties ret value %ld != expected IDOK\n", ret);
1391 test_DEVMODE(dm, dm_size, default_printer);
1393 HeapFree(GetProcessHeap(), 0, dm);
1395 SetLastError(0xdeadbeef);
1396 ret = ClosePrinter(hprn);
1397 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1402 LPSTR default_printer;
1404 hwinspool = GetModuleHandleA("winspool.drv");
1405 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
1406 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
1408 default_printer = find_default_printer();
1411 test_DeleteMonitor();
1412 test_DocumentProperties();
1413 test_EnumForms(NULL);
1414 if (default_printer) test_EnumForms(default_printer);
1415 test_EnumMonitors();
1416 test_GetDefaultPrinter();
1417 test_GetPrinterDriverDirectory();
1418 test_GetPrintProcessorDirectory();
1420 test_GetPrinterDriver();
1421 test_SetDefaultPrinter();