winspool/tests: Tests for GetPrintProcessorDirectory.
[wine/multimedia.git] / dlls / winspool.drv / tests / info.c
blobca65021f46ccaba3e308fb8656a1e308f794eb7e
1 /*
2 * Copyright (C) 2003, 2004 Stefan Leichter
3 * Copyright (C) 2005, 2006 Detlef Riekenberg
4 * Copyright (C) 2006 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winspool.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 {
44 LPSTR env;
45 LPSTR dllname;
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)) \
52 { \
53 if(report_deactivated_spooler > 0) { \
54 report_deactivated_spooler--; \
55 trace("The Service 'Spooler' is required for many test\n"); \
56 } \
57 return; \
61 static LPSTR find_default_printer(VOID)
63 static LPSTR default_printer = NULL;
64 static char buffer[DEFAULT_PRINTER_SIZE];
65 DWORD needed;
66 DWORD res;
67 LPSTR ptr;
69 if ((default_printer == NULL) && (pGetDefaultPrinterA))
71 /* w2k and above */
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)
79 HKEY hwindows;
80 DWORD type;
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, ',');
91 if (ptr) {
92 ptr[0] = '\0';
93 default_printer = buffer;
96 RegCloseKey(hwindows);
98 trace("default_printer: '%s'\n", default_printer);
100 if (default_printer == NULL)
102 /* win9x */
103 needed = sizeof(buffer);
104 res = GetProfileStringA("windows", "device", "*", buffer, needed);
105 if(res) {
106 ptr = strchr(buffer, ',');
107 if (ptr) {
108 ptr[0] = '\0';
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;
122 DWORD num_tests;
123 DWORD i = 0;
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));
147 /* cleanup */
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];
155 i++;
156 mi2a.pEnvironment = entry->env;
157 mi2a.pDLLName = entry->dllname;
159 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
160 /* we got one */
161 trace("using '%s', '%s'\n", entry->env, entry->dllname);
162 DeleteMonitorA(NULL, entry->env, winetest_monitor);
164 else
166 entry = NULL;
169 return entry;
172 /* ########################### */
175 static void test_AddMonitor(void)
177 MONITOR_INFO_2A mi2a;
178 struct monitor_entry * entry = NULL;
179 DWORD res;
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());
195 #if 0
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 */
200 ok(!res &&
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());
205 #endif
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");
214 return;
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());
223 if (!entry) {
224 trace("No usable Monitor found: Skip tests\n");
225 return;
228 #if 0
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 */
238 #endif
240 mi2a.pEnvironment = entry->env;
241 mi2a.pName = "";
242 SetLastError(MAGIC_DEAD);
243 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
244 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
245 ok( !res &&
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 */
256 ok( !res &&
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());
263 mi2a.pDLLName = "";
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 */
275 ok( !res &&
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 */
285 todo_wine {
286 ok( !res &&
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) */
304 ok( !res &&
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());
316 /* cleanup */
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;
327 DWORD res;
329 entry = find_installed_monitor();
331 if (!entry) {
332 trace("No usable Monitor found: Skip tests\n");
333 return;
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) */
351 ok( !res &&
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)*/
378 ok( !res &&
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)*/
388 ok( !res &&
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());
399 /* cleanup */
400 DeleteMonitorA(NULL, entry->env, winetest_monitor);
404 /* ########################### */
406 static void test_EnumMonitors(void)
408 DWORD res;
409 LPBYTE buffer;
410 DWORD cbBuf;
411 DWORD pcbNeeded;
412 DWORD pcReturned;
413 DWORD level;
415 /* valid levels are 1 and 2 */
416 for(level = 0; level < 4; level++) {
417 cbBuf = MAGIC_DEAD;
418 pcReturned = MAGIC_DEAD;
419 SetLastError(MAGIC_DEAD);
420 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
422 RETURN_ON_DEACTIVATED_SPOOLER(res)
424 /* not implemented yet in wine */
425 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
428 /* use only a short test, when we test with an invalid level */
429 if(!level || (level > 2)) {
430 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
431 (res && (pcReturned == 0)),
432 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
433 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
434 level, res, GetLastError(), pcReturned);
435 continue;
438 /* Level 2 is not supported on win9x */
439 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
440 trace("Level %ld not supported, skipping tests\n", level);
441 continue;
444 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
445 "(%ld) returned %ld with %ld (expected '0' with " \
446 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
448 if (!cbBuf) {
449 trace("no valid buffer size returned, skipping tests\n");
450 continue;
453 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
454 if (buffer == NULL) continue;
456 SetLastError(MAGIC_DEAD);
457 pcbNeeded = MAGIC_DEAD;
458 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
459 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
460 level, res, GetLastError());
461 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n",
462 level, pcbNeeded, cbBuf);
463 /* We can validate the returned Data with the Registry here */
466 SetLastError(MAGIC_DEAD);
467 pcReturned = MAGIC_DEAD;
468 pcbNeeded = MAGIC_DEAD;
469 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
470 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level,
471 res, GetLastError());
472 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
473 pcbNeeded, cbBuf);
475 SetLastError(MAGIC_DEAD);
476 pcbNeeded = MAGIC_DEAD;
477 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
478 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
479 "(%ld) returned %ld with %ld (expected '0' with " \
480 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
482 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
483 pcbNeeded, cbBuf);
486 Do not add the next test:
487 w2k+: RPC_X_NULL_REF_POINTER
488 NT3.5: ERROR_INVALID_USER_BUFFER
489 win9x: crash in winspool.drv
491 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
494 SetLastError(MAGIC_DEAD);
495 pcbNeeded = MAGIC_DEAD;
496 pcReturned = MAGIC_DEAD;
497 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
498 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
499 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
500 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
502 pcbNeeded = MAGIC_DEAD;
503 pcReturned = MAGIC_DEAD;
504 SetLastError(MAGIC_DEAD);
505 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
506 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
507 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
508 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
510 HeapFree(GetProcessHeap(), 0, buffer);
511 } /* for(level ... */
515 static void test_GetDefaultPrinter(void)
517 BOOL retval;
518 DWORD exact = DEFAULT_PRINTER_SIZE;
519 DWORD size;
520 char buffer[DEFAULT_PRINTER_SIZE];
522 if (!pGetDefaultPrinterA) return;
523 /* only supported on NT like OSes starting with win2k */
525 SetLastError(ERROR_SUCCESS);
526 retval = pGetDefaultPrinterA(buffer, &exact);
527 if (!retval || !exact || !strlen(buffer) ||
528 (ERROR_SUCCESS != GetLastError())) {
529 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
530 (ERROR_INVALID_NAME == GetLastError()))
531 trace("this test requires a default printer to be set\n");
532 else {
533 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
534 "function returned %s\n"
535 "last error 0x%08lx\n"
536 "returned buffer size 0x%08lx\n"
537 "returned buffer content %s\n",
538 retval ? "true" : "false", GetLastError(), exact, buffer);
540 return;
542 SetLastError(ERROR_SUCCESS);
543 retval = pGetDefaultPrinterA(NULL, NULL);
544 ok( !retval, "function result wrong! False expected\n");
545 ok( ERROR_INVALID_PARAMETER == GetLastError(),
546 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
547 GetLastError());
549 SetLastError(ERROR_SUCCESS);
550 retval = pGetDefaultPrinterA(buffer, NULL);
551 ok( !retval, "function result wrong! False expected\n");
552 ok( ERROR_INVALID_PARAMETER == GetLastError(),
553 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
554 GetLastError());
556 SetLastError(ERROR_SUCCESS);
557 size = 0;
558 retval = pGetDefaultPrinterA(NULL, &size);
559 ok( !retval, "function result wrong! False expected\n");
560 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
561 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
562 GetLastError());
563 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
564 exact, size);
566 SetLastError(ERROR_SUCCESS);
567 size = DEFAULT_PRINTER_SIZE;
568 retval = pGetDefaultPrinterA(NULL, &size);
569 ok( !retval, "function result wrong! False expected\n");
570 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
571 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
572 GetLastError());
573 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
574 exact, size);
576 size = 0;
577 retval = pGetDefaultPrinterA(buffer, &size);
578 ok( !retval, "function result wrong! False expected\n");
579 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
580 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
581 GetLastError());
582 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
583 exact, size);
585 size = exact;
586 retval = pGetDefaultPrinterA(buffer, &size);
587 ok( retval, "function result wrong! True expected\n");
588 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
589 exact, size);
592 static void test_GetPrinterDriverDirectory(void)
594 LPBYTE buffer = NULL;
595 DWORD cbBuf = 0, pcbNeeded = 0;
596 BOOL res;
598 SetLastError(MAGIC_DEAD);
599 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
600 trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
601 res, GetLastError(), cbBuf);
603 RETURN_ON_DEACTIVATED_SPOOLER(res)
604 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
605 "returned %d with lasterror=%ld (expected '0' with " \
606 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
608 if (!cbBuf) {
609 trace("no valid buffer size returned, skipping tests\n");
610 return;
613 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
614 if (buffer == NULL) return ;
616 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
617 ok( res, "expected result != 0, got %d\n", res);
618 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
619 pcbNeeded, cbBuf);
621 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
622 ok( res, "expected result != 0, got %d\n", res);
623 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
624 pcbNeeded, cbBuf);
626 SetLastError(MAGIC_DEAD);
627 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
628 ok( !res , "expected result == 0, got %d\n", res);
629 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
630 pcbNeeded, cbBuf);
632 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
633 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
634 GetLastError());
637 Do not add the next test:
638 XPsp2: crash in this app, when the spooler is not running
639 NT3.5: ERROR_INVALID_USER_BUFFER
640 win9x: ERROR_INVALID_PARAMETER
642 pcbNeeded = MAGIC_DEAD;
643 SetLastError(MAGIC_DEAD);
644 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
647 SetLastError(MAGIC_DEAD);
648 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
649 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
650 "expected either result == 0 and "
651 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
652 "got result %d and last error == %ld\n", res, GetLastError());
654 SetLastError(MAGIC_DEAD);
655 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
656 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
657 "returned %d with %ld (expected '!=0' or '0' with " \
658 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
661 /* with a valid buffer, but level is too large */
662 buffer[0] = '\0';
663 SetLastError(MAGIC_DEAD);
664 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
666 /* Level not checked in win9x and wine:*/
667 if((res != FALSE) && buffer[0])
669 trace("Level '2' not checked '%s'\n", buffer);
671 else
673 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
674 "returned %d with lasterror=%ld (expected '0' with " \
675 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
678 /* printing environments are case insensitive */
679 /* "Windows 4.0" is valid for win9x and NT */
680 buffer[0] = '\0';
681 SetLastError(MAGIC_DEAD);
682 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
683 buffer, cbBuf*2, &pcbNeeded);
685 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
686 cbBuf = pcbNeeded;
687 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
688 if (buffer == NULL) return ;
690 SetLastError(MAGIC_DEAD);
691 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
692 buffer, cbBuf*2, &pcbNeeded);
695 ok(res && buffer[0], "returned %d with " \
696 "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n",
697 res, GetLastError(), lstrlenA((char *)buffer));
699 buffer[0] = '\0';
700 SetLastError(MAGIC_DEAD);
701 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
702 buffer, cbBuf*2, &pcbNeeded);
704 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
705 cbBuf = pcbNeeded;
706 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
707 if (buffer == NULL) return ;
709 buffer[0] = '\0';
710 SetLastError(MAGIC_DEAD);
711 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
712 buffer, cbBuf*2, &pcbNeeded);
715 /* "Windows NT x86" is invalid for win9x */
716 ok( (res && buffer[0]) ||
717 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
718 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
719 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
720 res, GetLastError(), lstrlenA((char *)buffer));
722 /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
723 SetLastError(MAGIC_DEAD);
724 res = GetPrinterDriverDirectoryA("", "", 1, buffer, cbBuf*2, &pcbNeeded);
725 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
727 SetLastError(MAGIC_DEAD);
728 res = GetPrinterDriverDirectoryA(NULL, "", 1, buffer, cbBuf*2, &pcbNeeded);
729 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
731 SetLastError(MAGIC_DEAD);
732 res = GetPrinterDriverDirectoryA("", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
733 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
735 HeapFree( GetProcessHeap(), 0, buffer);
738 /* ##### */
740 static void test_GetPrintProcessorDirectory(void)
742 LPBYTE buffer = NULL;
743 DWORD cbBuf = 0;
744 DWORD pcbNeeded = 0;
745 BOOL res;
747 SetLastError(0xdeadbeef);
748 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
749 /* The deactivated Spooler is catched here on NT3.51 */
750 RETURN_ON_DEACTIVATED_SPOOLER(res)
751 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
752 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
753 res, GetLastError());
755 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
756 if(buffer == NULL) return;
758 buffer[0] = '\0';
759 SetLastError(0xdeadbeef);
760 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
761 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
763 SetLastError(0xdeadbeef);
764 buffer[0] = '\0';
765 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
766 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
768 /* Buffer to small */
769 buffer[0] = '\0';
770 SetLastError(0xdeadbeef);
771 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
772 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
773 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
774 res, GetLastError());
776 #if 0
777 /* XPsp2: the programm will crash here, when the spooler is not running */
778 /* GetPrinterDriverDirectory has the same bug */
779 pcbNeeded = 0;
780 SetLastError(0xdeadbeef);
781 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
782 #endif
784 buffer[0] = '\0';
785 SetLastError(0xdeadbeef);
786 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
787 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
788 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
789 "returned %d with %ld (expected '!= 0' or '0' with " \
790 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
793 buffer[0] = '\0';
794 SetLastError(0xdeadbeef);
795 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
796 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
797 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
798 "returned %d with %ld (expected '!= 0' or '0' with " \
799 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
802 /* with a valid buffer, but level is invalid */
803 buffer[0] = '\0';
804 SetLastError(0xdeadbeef);
805 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
806 if (res && buffer[0])
808 /* Level is ignored in win9x*/
809 trace("invalid level (2) was ignored\n");
811 else
813 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
814 "returned %d with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
815 res, GetLastError());
818 /* Empty environment is the same as the default environment */
819 buffer[0] = '\0';
820 SetLastError(0xdeadbeef);
821 res = GetPrintProcessorDirectoryA(NULL, "", 1, buffer, cbBuf*2, &pcbNeeded);
822 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
824 /* "Windows 4.0" is valid for win9x and NT */
825 buffer[0] = '\0';
826 SetLastError(0xdeadbeef);
827 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
828 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
831 /* "Windows NT x86" is invalid for win9x */
832 buffer[0] = '\0';
833 SetLastError(0xdeadbeef);
834 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
835 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
836 "returned %d with %ld (expected '!= 0' or '0' with " \
837 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
839 /* invalid on all Systems */
840 buffer[0] = '\0';
841 SetLastError(0xdeadbeef);
842 res = GetPrintProcessorDirectoryA(NULL, "invalid_env", 1, buffer, cbBuf*2, &pcbNeeded);
843 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
844 "returned %d with %ld (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
845 res, GetLastError());
847 /* Empty servername is the same as the local computer */
848 buffer[0] = '\0';
849 SetLastError(0xdeadbeef);
850 res = GetPrintProcessorDirectoryA("", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
851 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
853 /* invalid on all Systems */
854 buffer[0] = '\0';
855 SetLastError(0xdeadbeef);
856 res = GetPrintProcessorDirectoryA("\\invalid_server", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
857 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
858 "returned %d with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
859 res, GetLastError());
861 HeapFree(GetProcessHeap(), 0, buffer);
864 /* ##### */
866 static void test_OpenPrinter(void)
868 PRINTER_DEFAULTSA defaults;
869 HANDLE hprinter;
870 LPSTR default_printer;
871 DWORD res;
872 DWORD size;
873 CHAR buffer[DEFAULT_PRINTER_SIZE];
874 LPSTR ptr;
876 SetLastError(MAGIC_DEAD);
877 res = OpenPrinter(NULL, NULL, NULL);
878 /* The deactivated Spooler is catched here on NT3.51 */
879 RETURN_ON_DEACTIVATED_SPOOLER(res)
880 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
881 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
882 res, GetLastError());
885 /* Get Handle for the local Printserver (NT only)*/
886 hprinter = (HANDLE) MAGIC_DEAD;
887 SetLastError(MAGIC_DEAD);
888 res = OpenPrinter(NULL, &hprinter, NULL);
889 /* The deactivated Spooler is catched here on XPsp2 */
890 RETURN_ON_DEACTIVATED_SPOOLER(res)
891 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
892 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
893 res, GetLastError());
894 if(res) {
895 ClosePrinter(hprinter);
897 defaults.pDatatype=NULL;
898 defaults.pDevMode=NULL;
900 defaults.DesiredAccess=0;
901 hprinter = (HANDLE) MAGIC_DEAD;
902 SetLastError(MAGIC_DEAD);
903 res = OpenPrinter(NULL, &hprinter, &defaults);
904 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
905 if (res) ClosePrinter(hprinter);
907 defaults.DesiredAccess=-1;
908 hprinter = (HANDLE) MAGIC_DEAD;
909 SetLastError(MAGIC_DEAD);
910 res = OpenPrinter(NULL, &hprinter, &defaults);
911 todo_wine {
912 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
913 "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n",
914 res, GetLastError());
916 if (res) ClosePrinter(hprinter);
920 size = sizeof(buffer) - 3 ;
921 ptr = buffer;
922 ptr[0] = '\\';
923 ptr++;
924 ptr[0] = '\\';
925 ptr++;
926 if (GetComputerNameA(ptr, &size)) {
928 hprinter = (HANDLE) MAGIC_DEAD;
929 SetLastError(MAGIC_DEAD);
930 res = OpenPrinter(buffer, &hprinter, NULL);
931 todo_wine {
932 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
933 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
934 res, GetLastError());
936 if(res) ClosePrinter(hprinter);
939 /* Invalid Printername */
940 hprinter = (HANDLE) MAGIC_DEAD;
941 SetLastError(MAGIC_DEAD);
942 res = OpenPrinter("illegal,name", &hprinter, NULL);
943 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
944 (GetLastError() == ERROR_INVALID_PARAMETER) ),
945 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or" \
946 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
947 if(res) ClosePrinter(hprinter);
949 hprinter = (HANDLE) MAGIC_DEAD;
950 SetLastError(MAGIC_DEAD);
951 res = OpenPrinter("", &hprinter, NULL);
952 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
953 ok( !res &&
954 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
955 (GetLastError() == ERROR_INVALID_PARAMETER) ),
956 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PRINTER_NAME" \
957 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
958 if(res) ClosePrinter(hprinter);
961 /* Get Handle for the default Printer */
962 if ((default_printer = find_default_printer()))
964 hprinter = (HANDLE) MAGIC_DEAD;
965 SetLastError(MAGIC_DEAD);
966 res = OpenPrinter(default_printer, &hprinter, NULL);
967 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
969 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
970 return;
972 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
973 if(res) ClosePrinter(hprinter);
975 SetLastError(MAGIC_DEAD);
976 res = OpenPrinter(default_printer, NULL, NULL);
977 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
978 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
979 "returned %ld with %ld (expected '!=0' or '0' with " \
980 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
982 defaults.pDatatype=NULL;
983 defaults.pDevMode=NULL;
984 defaults.DesiredAccess=0;
986 hprinter = (HANDLE) MAGIC_DEAD;
987 SetLastError(MAGIC_DEAD);
988 res = OpenPrinter(default_printer, &hprinter, &defaults);
989 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
990 "returned %ld with %ld (expected '!=0' or '0' with " \
991 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
992 if(res) ClosePrinter(hprinter);
994 defaults.pDatatype="";
996 hprinter = (HANDLE) MAGIC_DEAD;
997 SetLastError(MAGIC_DEAD);
998 res = OpenPrinter(default_printer, &hprinter, &defaults);
999 /* stop here, when a remote Printserver has no RPC-Service running */
1000 RETURN_ON_DEACTIVATED_SPOOLER(res)
1001 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1002 (GetLastError() == ERROR_ACCESS_DENIED)),
1003 "returned %ld with %ld (expected '!=0' or '0' with: " \
1004 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1005 res, GetLastError());
1006 if(res) ClosePrinter(hprinter);
1009 defaults.pDatatype=NULL;
1010 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1012 hprinter = (HANDLE) MAGIC_DEAD;
1013 SetLastError(MAGIC_DEAD);
1014 res = OpenPrinter(default_printer, &hprinter, &defaults);
1015 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1016 "returned %ld with %ld (expected '!=0' or '0' with " \
1017 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1018 if(res) ClosePrinter(hprinter);
1021 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1022 hprinter = (HANDLE) MAGIC_DEAD;
1023 SetLastError(MAGIC_DEAD);
1024 res = OpenPrinter(default_printer, &hprinter, &defaults);
1025 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1026 "returned %ld with %ld (expected '!=0' or '0' with " \
1027 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1028 if(res) ClosePrinter(hprinter);
1034 static void test_SetDefaultPrinter(void)
1036 DWORD res;
1037 LPSTR default_printer;
1038 DWORD size = DEFAULT_PRINTER_SIZE;
1039 CHAR buffer[DEFAULT_PRINTER_SIZE];
1040 CHAR org_value[DEFAULT_PRINTER_SIZE];
1043 if (!pSetDefaultPrinterA) return;
1044 /* only supported on win2k and above */
1046 default_printer = find_default_printer();
1048 /* backup the original value */
1049 org_value[0] = '\0';
1050 SetLastError(MAGIC_DEAD);
1051 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1053 /* first part: with the default Printer */
1054 SetLastError(MAGIC_DEAD);
1055 res = pSetDefaultPrinterA("no_printer_with_this_name");
1057 RETURN_ON_DEACTIVATED_SPOOLER(res)
1058 /* spooler is running or we have no spooler here*/
1060 /* Not implemented in wine */
1061 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1062 trace("SetDefaultPrinterA() not implemented yet.\n");
1063 return;
1066 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1067 "returned %ld with %ld (expected '0' with " \
1068 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1070 WriteProfileStringA("windows", "device", org_value);
1071 SetLastError(MAGIC_DEAD);
1072 res = pSetDefaultPrinterA("");
1073 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1074 "returned %ld with %ld (expected '!=0' or '0' with " \
1075 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1077 WriteProfileStringA("windows", "device", org_value);
1078 SetLastError(MAGIC_DEAD);
1079 res = pSetDefaultPrinterA(NULL);
1080 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1081 "returned %ld with %ld (expected '!=0' or '0' with " \
1082 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1084 WriteProfileStringA("windows", "device", org_value);
1085 SetLastError(MAGIC_DEAD);
1086 res = pSetDefaultPrinterA(default_printer);
1087 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1088 "returned %ld with %ld (expected '!=0' or '0' with " \
1089 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1092 /* second part: always without a default Printer */
1093 WriteProfileStringA("windows", "device", NULL);
1094 SetLastError(MAGIC_DEAD);
1095 res = pSetDefaultPrinterA("no_printer_with_this_name");
1097 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1098 "returned %ld with %ld (expected '0' with " \
1099 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1101 WriteProfileStringA("windows", "device", NULL);
1102 SetLastError(MAGIC_DEAD);
1103 res = pSetDefaultPrinterA("");
1104 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1105 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1106 "returned %ld with %ld (expected '!=0' or '0' with " \
1107 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1109 WriteProfileStringA("windows", "device", NULL);
1110 SetLastError(MAGIC_DEAD);
1111 res = pSetDefaultPrinterA(NULL);
1112 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1113 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1114 "returned %ld with %ld (expected '!=0' or '0' with " \
1115 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1117 WriteProfileStringA("windows", "device", NULL);
1118 SetLastError(MAGIC_DEAD);
1119 res = pSetDefaultPrinterA(default_printer);
1120 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1121 "returned %ld with %ld (expected '!=0' or '0' with " \
1122 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1124 /* restore the original value */
1125 res = pSetDefaultPrinterA(default_printer); /* the nice way */
1126 WriteProfileStringA("windows", "device", org_value); /* the old way */
1128 buffer[0] = '\0';
1129 SetLastError(MAGIC_DEAD);
1130 res = GetProfileStringA("windows", "device", NULL, buffer, size);
1131 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1135 static void test_GetPrinterDriver(void)
1137 LPSTR default_printer;
1138 HANDLE hprn;
1139 BOOL ret;
1140 BYTE *buf;
1141 INT level;
1142 DWORD needed, filled;
1144 default_printer = find_default_printer();
1145 if (!default_printer)
1147 trace("There is no default printer installed, skiping the test\n");
1148 return;
1151 hprn = 0;
1152 ret = OpenPrinter(default_printer, &hprn, NULL);
1153 if (!ret)
1155 trace("There is no printers installed, skiping the test\n");
1156 return;
1158 ok(hprn != 0, "wrong hprn %p\n", hprn);
1160 for (level = -1; level <= 7; level++)
1162 SetLastError(0xdeadbeef);
1163 needed = (DWORD)-1;
1164 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
1165 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
1166 if (level >= 1 && level <= 6)
1168 /* Not all levels are supported on all Windows-Versions */
1169 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
1170 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
1171 ok(needed > 0,"not expected needed buffer size %ld\n", needed);
1173 else
1175 /* ERROR_OUTOFMEMORY found on win9x */
1176 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
1177 (GetLastError() == ERROR_OUTOFMEMORY)),
1178 "%d: returned %d with %ld (expected '0' with: " \
1179 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1180 level, ret, GetLastError());
1181 /* needed is modified in win9x. The modified Value depends on the
1182 default Printer. testing for "needed == (DWORD)-1" will fail */
1183 continue;
1186 buf = HeapAlloc(GetProcessHeap(), 0, needed);
1188 SetLastError(0xdeadbeef);
1189 filled = -1;
1190 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
1191 ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
1192 ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
1194 if (level == 2)
1196 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
1197 DWORD calculated = sizeof(*di_2);
1199 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1200 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1201 ok((di_2->cVersion >= 0 && di_2->cVersion <= 3) ||
1202 (di_2->cVersion == 0x0400), "di_2->cVersion = %ld\n", di_2->cVersion);
1203 ok(di_2->pName != NULL, "not expected NULL ptr\n");
1204 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
1205 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
1206 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
1207 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
1209 trace("cVersion %ld\n", di_2->cVersion);
1210 trace("pName %s\n", di_2->pName);
1211 calculated += strlen(di_2->pName) + 1;
1212 trace("pEnvironment %s\n", di_2->pEnvironment);
1213 calculated += strlen(di_2->pEnvironment) + 1;
1214 trace("pDriverPath %s\n", di_2->pDriverPath);
1215 calculated += strlen(di_2->pDriverPath) + 1;
1216 trace("pDataFile %s\n", di_2->pDataFile);
1217 calculated += strlen(di_2->pDataFile) + 1;
1218 trace("pConfigFile %s\n", di_2->pConfigFile);
1219 calculated += strlen(di_2->pConfigFile) + 1;
1221 /* XP allocates memory for both ANSI and unicode names */
1222 ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
1225 HeapFree(GetProcessHeap(), 0, buf);
1228 SetLastError(0xdeadbeef);
1229 ret = ClosePrinter(hprn);
1230 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1233 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
1235 /* On NT3.51, some fields in DEVMODE are empty/zero
1236 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1237 We skip the Tests on this Platform */
1238 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
1239 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1240 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
1241 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
1242 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
1243 "%u != %ld\n", dm->dmSize + dm->dmDriverExtra, dmSize);
1245 trace("dmFields %08lx\n", dm->dmFields);
1248 static void test_DocumentProperties(void)
1250 LPSTR default_printer;
1251 HANDLE hprn;
1252 LONG dm_size, ret;
1253 DEVMODE *dm;
1255 default_printer = find_default_printer();
1256 if (!default_printer)
1258 trace("There is no default printer installed, skiping the test\n");
1259 return;
1262 hprn = 0;
1263 ret = OpenPrinter(default_printer, &hprn, NULL);
1264 if (!ret)
1266 trace("There is no printers installed, skiping the test\n");
1267 return;
1269 ok(hprn != 0, "wrong hprn %p\n", hprn);
1271 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
1272 trace("DEVMODE required size %ld\n", dm_size);
1273 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %ld\n", dm_size);
1275 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
1277 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
1278 ok(ret == IDOK, "DocumentProperties ret value %ld != expected IDOK\n", ret);
1280 test_DEVMODE(dm, dm_size, default_printer);
1282 HeapFree(GetProcessHeap(), 0, dm);
1284 SetLastError(0xdeadbeef);
1285 ret = ClosePrinter(hprn);
1286 ok(ret, "ClosePrinter error %ld\n", GetLastError());
1289 START_TEST(info)
1291 hwinspool = GetModuleHandleA("winspool.drv");
1292 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
1293 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
1295 find_default_printer();
1297 test_AddMonitor();
1298 test_DeleteMonitor();
1299 test_DocumentProperties();
1300 test_EnumMonitors();
1301 test_GetDefaultPrinter();
1302 test_GetPrinterDriverDirectory();
1303 test_GetPrintProcessorDirectory();
1304 test_OpenPrinter();
1305 test_GetPrinterDriver();
1306 test_SetDefaultPrinter();