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 does_not_exist
[] = "does_not_exists";
37 static CHAR empty
[] = "";
38 static CHAR env_x86
[] = "Windows NT x86";
39 static CHAR env_win9x_case
[] = "windowS 4.0";
40 static CHAR illegal_name
[] = "illegal,name";
41 static CHAR invalid_env
[] = "invalid_env";
42 static CHAR invalid_server
[] = "\\invalid_server";
43 static CHAR portname_com1
[] = "COM1:";
44 static CHAR portname_file
[] = "FILE:";
45 static CHAR portname_lpt1
[] = "LPT1:";
46 static CHAR version_dll
[] = "version.dll";
47 static CHAR winetest_monitor
[] = "winetest";
49 static HANDLE hwinspool
;
50 static FARPROC pGetDefaultPrinterA
;
51 static FARPROC pSetDefaultPrinterA
;
53 struct monitor_entry
{
58 /* report common behavior only once */
59 static DWORD report_deactivated_spooler
= 1;
60 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
61 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
63 if(report_deactivated_spooler > 0) { \
64 report_deactivated_spooler--; \
65 trace("The Service 'Spooler' is required for many test\n"); \
71 static LPSTR
find_default_printer(VOID
)
73 static LPSTR default_printer
= NULL
;
74 static char buffer
[DEFAULT_PRINTER_SIZE
];
79 if ((default_printer
== NULL
) && (pGetDefaultPrinterA
))
82 needed
= sizeof(buffer
);
83 res
= pGetDefaultPrinterA(buffer
, &needed
);
84 if(res
) default_printer
= buffer
;
85 trace("default_printer: '%s'\n", default_printer
);
87 if (default_printer
== NULL
)
91 /* NT 3.x and above */
92 if (RegOpenKeyEx(HKEY_CURRENT_USER
,
93 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
94 0, KEY_QUERY_VALUE
, &hwindows
) == NO_ERROR
) {
96 needed
= sizeof(buffer
);
97 if (RegQueryValueEx(hwindows
, "device", NULL
,
98 &type
, (LPBYTE
)buffer
, &needed
) == NO_ERROR
) {
100 ptr
= strchr(buffer
, ',');
103 default_printer
= buffer
;
106 RegCloseKey(hwindows
);
108 trace("default_printer: '%s'\n", default_printer
);
110 if (default_printer
== NULL
)
113 needed
= sizeof(buffer
);
114 res
= GetProfileStringA("windows", "device", "*", buffer
, needed
);
116 ptr
= strchr(buffer
, ',');
119 default_printer
= buffer
;
122 trace("default_printer: '%s'\n", default_printer
);
124 return default_printer
;
128 static struct monitor_entry
* find_installed_monitor(void)
130 MONITOR_INFO_2A mi2a
;
131 static struct monitor_entry
* entry
= NULL
;
135 static struct monitor_entry monitor_table
[] = {
136 {env_win9x_case
, "localspl.dll"},
137 {env_x86
, "localspl.dll"},
138 {env_win9x_case
, "localmon.dll"},
139 {env_x86
, "localmon.dll"},
140 {env_win9x_case
, "tcpmon.dll"},
141 {env_x86
, "tcpmon.dll"},
142 {env_win9x_case
, "usbmon.dll"},
143 {env_x86
, "usbmon.dll"},
144 {env_win9x_case
, "mspp32.dll"},
145 {env_x86
, "win32spl.dll"},
146 {env_x86
, "redmonnt.dll"},
147 {env_x86
, "redmon35.dll"},
148 {env_win9x_case
, "redmon95.dll"},
149 {env_x86
, "pdfcmnnt.dll"},
150 {env_win9x_case
, "pdfcmn95.dll"},
153 if (entry
) return entry
;
155 num_tests
= (sizeof(monitor_table
)/sizeof(struct monitor_entry
));
158 DeleteMonitorA(NULL
, env_x86
, winetest_monitor
);
159 DeleteMonitorA(NULL
, env_win9x_case
, winetest_monitor
);
161 /* find a usable monitor from the table */
162 mi2a
.pName
= winetest_monitor
;
163 while ((entry
== NULL
) && (i
< num_tests
)) {
164 entry
= &monitor_table
[i
];
166 mi2a
.pEnvironment
= entry
->env
;
167 mi2a
.pDLLName
= entry
->dllname
;
169 if (AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
)) {
171 trace("using '%s', '%s'\n", entry
->env
, entry
->dllname
);
172 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
182 /* ########################### */
185 static void test_AddMonitor(void)
187 MONITOR_INFO_2A mi2a
;
188 struct monitor_entry
* entry
= NULL
;
191 entry
= find_installed_monitor();
193 SetLastError(MAGIC_DEAD
);
194 res
= AddMonitorA(NULL
, 1, NULL
);
195 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
196 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
197 res
, GetLastError());
199 SetLastError(MAGIC_DEAD
);
200 res
= AddMonitorA(NULL
, 3, NULL
);
201 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
202 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
203 res
, GetLastError());
206 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
207 SetLastError(MAGIC_DEAD
);
208 res
= AddMonitorA(NULL
, 2, NULL
);
209 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
211 ((GetLastError() == MAGIC_DEAD
) ||
212 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
213 "returned %d with %d (expected '0' with: MAGIC_DEAD or " \
214 "ERROR_PRIVILEGE_NOT_HELD)\n", res
, GetLastError());
217 ZeroMemory(&mi2a
, sizeof(MONITOR_INFO_2A
));
218 SetLastError(MAGIC_DEAD
);
219 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
220 RETURN_ON_DEACTIVATED_SPOOLER(res
)
222 if (!res
&& (GetLastError() == ERROR_ACCESS_DENIED
)) {
223 trace("skip tests (ACCESS_DENIED)\n");
227 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
228 ok(!res
&& ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
229 (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
230 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or " \
231 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
234 trace("No usable Monitor found: Skip tests\n");
239 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
240 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
241 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
242 is created on win9x and we do not want to hit this bug here. */
244 mi2a
.pEnvironment
= entry
->env
;
245 SetLastError(MAGIC_DEAD
);
246 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
247 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
250 mi2a
.pEnvironment
= entry
->env
;
252 SetLastError(MAGIC_DEAD
);
253 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
254 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
256 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
257 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
258 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or " \
259 "ERROR_PRIVILEGE_NOT_HELD)\n",
260 res
, GetLastError());
262 mi2a
.pName
= winetest_monitor
;
263 SetLastError(MAGIC_DEAD
);
264 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
265 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
267 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
268 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
269 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or " \
270 "ERROR_PRIVILEGE_NOT_HELD)\n",
271 res
, GetLastError());
273 mi2a
.pDLLName
= empty
;
274 SetLastError(MAGIC_DEAD
);
275 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
276 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
277 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
278 res
, GetLastError());
280 mi2a
.pDLLName
= does_not_exist_dll
;
281 SetLastError(MAGIC_DEAD
);
282 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
283 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
285 ((GetLastError() == ERROR_MOD_NOT_FOUND
) ||
286 (GetLastError() == ERROR_INVALID_PARAMETER
)),
287 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or " \
288 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
290 mi2a
.pDLLName
= version_dll
;
291 SetLastError(MAGIC_DEAD
);
292 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
293 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
295 ((GetLastError() == ERROR_PROC_NOT_FOUND
) ||
296 (GetLastError() == ERROR_INVALID_PARAMETER
)),
297 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or " \
298 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
299 if (res
) DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
301 /* Test AddMonitor with real options */
302 mi2a
.pDLLName
= entry
->dllname
;
303 SetLastError(MAGIC_DEAD
);
304 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
305 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
307 /* add a monitor twice */
308 SetLastError(MAGIC_DEAD
);
309 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
310 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
312 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED
) ||
313 (GetLastError() == ERROR_ALREADY_EXISTS
)),
314 "returned %d with %d (expected '0' with: " \
315 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
316 res
, GetLastError());
318 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
319 SetLastError(MAGIC_DEAD
);
320 res
= AddMonitorA(empty
, 2, (LPBYTE
) &mi2a
);
321 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
324 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
328 /* ########################### */
330 static void test_AddPort(void)
334 SetLastError(0xdeadbeef);
335 res
= AddPortA(NULL
, 0, NULL
);
336 RETURN_ON_DEACTIVATED_SPOOLER(res
)
337 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
338 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
339 (GetLastError() == ERROR_INVALID_PARAMETER
)),
340 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
341 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
344 SetLastError(0xdeadbeef);
345 res
= AddPortA(NULL
, 0, empty
);
346 /* Allowed only for (Printer-)Administrators */
347 if (!res
&& (GetLastError() == ERROR_ACCESS_DENIED
)) {
348 trace("skip tests (ACCESS_DENIED)\n");
351 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
352 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
353 (GetLastError() == ERROR_INVALID_PARAMETER
)),
354 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
355 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
358 SetLastError(0xdeadbeef);
359 res
= AddPortA(NULL
, 0, does_not_exist
);
360 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
361 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
362 (GetLastError() == ERROR_INVALID_PARAMETER
)),
363 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
364 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
368 /* ########################### */
370 static void test_ConfigurePort(void)
375 SetLastError(0xdeadbeef);
376 res
= ConfigurePortA(NULL
, 0, NULL
);
377 RETURN_ON_DEACTIVATED_SPOOLER(res
)
378 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
379 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
380 (GetLastError() == ERROR_INVALID_PARAMETER
)),
381 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
382 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
384 SetLastError(0xdeadbeef);
385 res
= ConfigurePortA(NULL
, 0, empty
);
386 /* Allowed only for (Printer-)Administrators */
387 if (!res
&& (GetLastError() == ERROR_ACCESS_DENIED
)) {
388 trace(" skip tests (ACCESS_DENIED)\n");
391 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
392 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
393 (GetLastError() == ERROR_INVALID_PARAMETER
)),
394 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
395 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
398 SetLastError(0xdeadbeef);
399 res
= ConfigurePortA(NULL
, 0, does_not_exist
);
400 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
401 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
402 (GetLastError() == ERROR_INVALID_PARAMETER
)),
403 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
404 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
408 - Case of Portnames is ignored
409 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
410 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
412 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
413 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
414 - Cancel ("Local Port") => ERROR_CANCELED
415 - Cancel ("Redirected Port") => Success
417 if (winetest_interactive
> 0) {
418 SetLastError(0xdeadbeef);
419 res
= ConfigurePortA(NULL
, 0, portname_com1
);
420 trace("'%s' returned %d with %d\n", portname_com1
, res
, GetLastError());
422 SetLastError(0xdeadbeef);
423 res
= ConfigurePortA(NULL
, 0, portname_lpt1
);
424 trace("'%s' returned %d with %d\n", portname_lpt1
, res
, GetLastError());
426 SetLastError(0xdeadbeef);
427 res
= ConfigurePortA(NULL
, 0, portname_file
);
428 trace("'%s' returned %d with %d\n", portname_file
, res
, GetLastError());
432 /* ########################### */
434 static void test_DeleteMonitor(void)
436 MONITOR_INFO_2A mi2a
;
437 struct monitor_entry
* entry
= NULL
;
441 entry
= find_installed_monitor();
444 trace("No usable Monitor found: Skip tests\n");
448 mi2a
.pName
= winetest_monitor
;
449 mi2a
.pEnvironment
= entry
->env
;
450 mi2a
.pDLLName
= entry
->dllname
;
452 /* Testing DeleteMonitor with real options */
453 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
455 SetLastError(MAGIC_DEAD
);
456 res
= DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
457 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
459 /* Delete the Monitor twice */
460 SetLastError(MAGIC_DEAD
);
461 res
= DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
462 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
464 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR
) ||
465 (GetLastError() == ERROR_INVALID_PARAMETER
)),
466 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR" \
467 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
469 /* the environment */
470 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
471 SetLastError(MAGIC_DEAD
);
472 res
= DeleteMonitorA(NULL
, NULL
, winetest_monitor
);
473 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
475 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
476 SetLastError(MAGIC_DEAD
);
477 res
= DeleteMonitorA(NULL
, empty
, winetest_monitor
);
478 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
480 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
481 SetLastError(MAGIC_DEAD
);
482 res
= DeleteMonitorA(NULL
, invalid_env
, winetest_monitor
);
483 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
485 /* the monitor-name */
486 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
487 SetLastError(MAGIC_DEAD
);
488 res
= DeleteMonitorA(NULL
, entry
->env
, NULL
);
489 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
491 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
492 (GetLastError() == ERROR_INVALID_NAME
)),
493 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or " \
494 "ERROR_INVALID_NAME)\n", res
, GetLastError());
496 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
497 SetLastError(MAGIC_DEAD
);
498 res
= DeleteMonitorA(NULL
, entry
->env
, empty
);
499 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
501 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
502 (GetLastError() == ERROR_INVALID_NAME
)),
503 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or " \
504 "ERROR_INVALID_NAME)\n", res
, GetLastError());
506 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
507 SetLastError(MAGIC_DEAD
);
508 res
= DeleteMonitorA(empty
, entry
->env
, winetest_monitor
);
509 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
512 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
515 /* ########################### */
517 static void test_DeletePort(void)
521 SetLastError(0xdeadbeef);
522 res
= DeletePortA(NULL
, 0, NULL
);
523 RETURN_ON_DEACTIVATED_SPOOLER(res
)
525 SetLastError(0xdeadbeef);
526 res
= DeletePortA(NULL
, 0, empty
);
527 /* Allowed only for (Printer-)Administrators */
528 if (!res
&& (GetLastError() == ERROR_ACCESS_DENIED
)) {
529 trace("skip tests (ACCESS_DENIED)\n");
532 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
533 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
534 (GetLastError() == ERROR_INVALID_PARAMETER
)),
535 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
536 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
539 SetLastError(0xdeadbeef);
540 res
= DeletePortA(NULL
, 0, does_not_exist
);
541 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
542 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
543 (GetLastError() == ERROR_INVALID_PARAMETER
)),
544 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or " \
545 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
549 /* ########################### */
551 static void test_EnumForms(LPSTR pName
)
562 res
= OpenPrinter(pName
, &hprinter
, NULL
);
563 RETURN_ON_DEACTIVATED_SPOOLER(res
)
564 if (!res
|| !hprinter
)
566 /* Open the local Prinserver is not supported on win9x */
567 if (pName
) trace("Failed to open '%s', skiping the test\n", pName
);
571 /* valid levels are 1 and 2 */
572 for(level
= 0; level
< 4; level
++) {
574 pcReturned
= 0xdeadbeef;
575 SetLastError(0xdeadbeef);
576 res
= EnumFormsA(hprinter
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
578 /* EnumForms is not implemented in win9x */
579 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
581 /* EnumForms for the Server not implemented on all NT-Versions */
582 if (!res
&& (GetLastError() == ERROR_INVALID_HANDLE
) && !pName
) continue;
584 /* Level 2 for EnumForms is not supported on all systems */
585 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
) && (level
== 2)) continue;
587 /* use only a short test, when we test with an invalid level */
588 if(!level
|| (level
> 2)) {
589 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
590 (res
&& (pcReturned
== 0)),
591 "(%d) returned %d with %d and 0x%08x (expected '0' with " \
592 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
593 level
, res
, GetLastError(), pcReturned
);
597 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
598 "(%d) returned %d with %d (expected '0' with " \
599 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
601 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
602 if (buffer
== NULL
) continue;
604 SetLastError(0xdeadbeef);
605 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
606 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
607 level
, res
, GetLastError());
608 /* We can dump the returned Data here */
611 SetLastError(0xdeadbeef);
612 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
613 ok( res
, "(%d) returned %d with %d (expected '!=0')\n",
614 level
, res
, GetLastError());
616 SetLastError(0xdeadbeef);
617 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
618 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
619 "(%d) returned %d with %d (expected '0' with " \
620 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
623 SetLastError(0xdeadbeef);
624 res
= EnumFormsA(hprinter
, level
, NULL
, cbBuf
, &pcbNeeded
, &pcReturned
);
625 ok( !res
&& (GetLastError() == ERROR_INVALID_USER_BUFFER
) ,
626 "(%d) returned %d with %d (expected '0' with "\
627 "ERROR_INVALID_USER_BUFFER)\n", level
, res
, GetLastError());
630 SetLastError(0xdeadbeef);
631 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
632 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
633 "(%d) returned %d with %d (expected '0' with "\
634 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
636 SetLastError(0xdeadbeef);
637 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
638 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
639 "(%d) returned %d with %d (expected '0' with "\
640 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
642 SetLastError(0xdeadbeef);
643 res
= EnumFormsA(0, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
644 ok( !res
&& (GetLastError() == ERROR_INVALID_HANDLE
) ,
645 "(%d) returned %d with %d (expected '0' with "\
646 "ERROR_INVALID_HANDLE)\n", level
, res
, GetLastError());
648 HeapFree(GetProcessHeap(), 0, buffer
);
649 } /* for(level ... */
651 ClosePrinter(hprinter
);
654 /* ########################### */
656 static void test_EnumMonitors(void)
665 /* valid levels are 1 and 2 */
666 for(level
= 0; level
< 4; level
++) {
668 pcReturned
= MAGIC_DEAD
;
669 SetLastError(MAGIC_DEAD
);
670 res
= EnumMonitorsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
672 RETURN_ON_DEACTIVATED_SPOOLER(res
)
674 /* not implemented yet in wine */
675 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
678 /* use only a short test, when we test with an invalid level */
679 if(!level
|| (level
> 2)) {
680 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
681 (res
&& (pcReturned
== 0)),
682 "(%d) returned %d with %d and 0x%08x (expected '0' with " \
683 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
684 level
, res
, GetLastError(), pcReturned
);
688 /* Level 2 is not supported on win9x */
689 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
690 trace("Level %d not supported, skipping tests\n", level
);
694 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
695 "(%d) returned %d with %d (expected '0' with " \
696 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
699 trace("no valid buffer size returned, skipping tests\n");
703 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
704 if (buffer
== NULL
) continue;
706 SetLastError(MAGIC_DEAD
);
707 pcbNeeded
= MAGIC_DEAD
;
708 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
709 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
710 level
, res
, GetLastError());
711 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n",
712 level
, pcbNeeded
, cbBuf
);
713 /* We can validate the returned Data with the Registry here */
716 SetLastError(MAGIC_DEAD
);
717 pcReturned
= MAGIC_DEAD
;
718 pcbNeeded
= MAGIC_DEAD
;
719 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
720 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
,
721 res
, GetLastError());
722 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
725 SetLastError(MAGIC_DEAD
);
726 pcbNeeded
= MAGIC_DEAD
;
727 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
728 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
729 "(%d) returned %d with %d (expected '0' with " \
730 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
732 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
736 Do not add the next test:
737 w2k+: RPC_X_NULL_REF_POINTER
738 NT3.5: ERROR_INVALID_USER_BUFFER
739 win9x: crash in winspool.drv
741 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
744 SetLastError(MAGIC_DEAD
);
745 pcbNeeded
= MAGIC_DEAD
;
746 pcReturned
= MAGIC_DEAD
;
747 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
748 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
749 "(%d) returned %d with %d (expected '!=0' or '0' with "\
750 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
752 pcbNeeded
= MAGIC_DEAD
;
753 pcReturned
= MAGIC_DEAD
;
754 SetLastError(MAGIC_DEAD
);
755 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
756 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
757 "(%d) returned %d with %d (expected '!=0' or '0' with "\
758 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
760 HeapFree(GetProcessHeap(), 0, buffer
);
761 } /* for(level ... */
764 /* ########################### */
766 static void test_EnumPorts(void)
775 /* valid levels are 1 and 2 */
776 for(level
= 0; level
< 4; level
++) {
779 pcReturned
= 0xdeadbeef;
780 SetLastError(0xdeadbeef);
781 res
= EnumPortsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
782 RETURN_ON_DEACTIVATED_SPOOLER(res
)
784 /* use only a short test, when we test with an invalid level */
785 if(!level
|| (level
> 2)) {
786 /* NT: ERROR_INVALID_LEVEL, 9x: success */
787 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
788 (res
&& (pcReturned
== 0)),
789 "(%d) returned %d with %d and 0x%08x (expected '0' with " \
790 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
791 level
, res
, GetLastError(), pcReturned
);
796 /* Level 2 is not supported on NT 3.x */
797 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
798 trace("Level %d not supported, skipping tests\n", level
);
802 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
803 "(%d) returned %d with %d (expected '0' with " \
804 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
806 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
807 if (buffer
== NULL
) continue;
809 pcbNeeded
= 0xdeadbeef;
810 SetLastError(0xdeadbeef);
811 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
812 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
813 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
814 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
816 pcbNeeded
= 0xdeadbeef;
817 pcReturned
= 0xdeadbeef;
818 SetLastError(0xdeadbeef);
819 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
820 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
821 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
823 pcbNeeded
= 0xdeadbeef;
824 SetLastError(0xdeadbeef);
825 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
826 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
827 "(%d) returned %d with %d (expected '0' with " \
828 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
829 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
832 Do not add this test:
833 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
834 w2k+: RPC_X_NULL_REF_POINTER
835 NT3.5: ERROR_INVALID_USER_BUFFER
836 win9x: crash in winspool.drv
839 SetLastError(0xdeadbeef);
840 res
= EnumPorts(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
841 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
842 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
843 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
844 "(%d) returned %d with %d (expected '0' with " \
845 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
846 level
, res
, GetLastError());
849 SetLastError(0xdeadbeef);
850 res
= EnumPorts(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
851 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
852 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
853 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
854 "(%d) returned %d with %d (expected '0' with " \
855 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
856 level
, res
, GetLastError());
858 HeapFree(GetProcessHeap(), 0, buffer
);
862 /* ########################### */
864 static void test_GetDefaultPrinter(void)
867 DWORD exact
= DEFAULT_PRINTER_SIZE
;
869 char buffer
[DEFAULT_PRINTER_SIZE
];
871 if (!pGetDefaultPrinterA
) return;
872 /* only supported on NT like OSes starting with win2k */
874 SetLastError(ERROR_SUCCESS
);
875 retval
= pGetDefaultPrinterA(buffer
, &exact
);
876 if (!retval
|| !exact
|| !strlen(buffer
) ||
877 (ERROR_SUCCESS
!= GetLastError())) {
878 if ((ERROR_FILE_NOT_FOUND
== GetLastError()) ||
879 (ERROR_INVALID_NAME
== GetLastError()))
880 trace("this test requires a default printer to be set\n");
882 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
883 "function returned %s\n"
884 "last error 0x%08x\n"
885 "returned buffer size 0x%08x\n"
886 "returned buffer content %s\n",
887 retval
? "true" : "false", GetLastError(), exact
, buffer
);
891 SetLastError(ERROR_SUCCESS
);
892 retval
= pGetDefaultPrinterA(NULL
, NULL
);
893 ok( !retval
, "function result wrong! False expected\n");
894 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
895 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
898 SetLastError(ERROR_SUCCESS
);
899 retval
= pGetDefaultPrinterA(buffer
, NULL
);
900 ok( !retval
, "function result wrong! False expected\n");
901 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
902 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
905 SetLastError(ERROR_SUCCESS
);
907 retval
= pGetDefaultPrinterA(NULL
, &size
);
908 ok( !retval
, "function result wrong! False expected\n");
909 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
910 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
912 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
915 SetLastError(ERROR_SUCCESS
);
916 size
= DEFAULT_PRINTER_SIZE
;
917 retval
= pGetDefaultPrinterA(NULL
, &size
);
918 ok( !retval
, "function result wrong! False expected\n");
919 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
920 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
922 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
926 retval
= pGetDefaultPrinterA(buffer
, &size
);
927 ok( !retval
, "function result wrong! False expected\n");
928 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
929 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
931 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
935 retval
= pGetDefaultPrinterA(buffer
, &size
);
936 ok( retval
, "function result wrong! True expected\n");
937 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
941 static void test_GetPrinterDriverDirectory(void)
943 LPBYTE buffer
= NULL
;
944 DWORD cbBuf
= 0, pcbNeeded
= 0;
948 SetLastError(MAGIC_DEAD
);
949 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
950 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
951 res
, GetLastError(), cbBuf
);
953 RETURN_ON_DEACTIVATED_SPOOLER(res
)
954 ok((res
== 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
955 "returned %d with lasterror=%d (expected '0' with " \
956 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError());
959 trace("no valid buffer size returned, skipping tests\n");
963 buffer
= HeapAlloc( GetProcessHeap(), 0, cbBuf
*2);
964 if (buffer
== NULL
) return ;
966 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
967 ok( res
, "expected result != 0, got %d\n", res
);
968 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
971 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
972 ok( res
, "expected result != 0, got %d\n", res
);
973 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
976 SetLastError(MAGIC_DEAD
);
977 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
978 ok( !res
, "expected result == 0, got %d\n", res
);
979 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
982 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
983 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
987 Do not add the next test:
988 XPsp2: crash in this app, when the spooler is not running
989 NT3.5: ERROR_INVALID_USER_BUFFER
990 win9x: ERROR_INVALID_PARAMETER
992 pcbNeeded = MAGIC_DEAD;
993 SetLastError(MAGIC_DEAD);
994 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
997 SetLastError(MAGIC_DEAD
);
998 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
999 ok( (!res
&& RPC_X_NULL_REF_POINTER
== GetLastError()) || res
,
1000 "expected either result == 0 and "
1001 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1002 "got result %d and last error == %d\n", res
, GetLastError());
1004 SetLastError(MAGIC_DEAD
);
1005 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1006 ok(res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1007 "returned %d with %d (expected '!=0' or '0' with " \
1008 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1011 /* with a valid buffer, but level is too large */
1013 SetLastError(MAGIC_DEAD
);
1014 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1016 /* Level not checked in win9x and wine:*/
1017 if((res
!= FALSE
) && buffer
[0])
1019 trace("Level '2' not checked '%s'\n", buffer
);
1023 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1024 "returned %d with lasterror=%d (expected '0' with " \
1025 "ERROR_INVALID_LEVEL)\n", res
, GetLastError());
1028 /* printing environments are case insensitive */
1029 /* "Windows 4.0" is valid for win9x and NT */
1031 SetLastError(MAGIC_DEAD
);
1032 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1033 buffer
, cbBuf
*2, &pcbNeeded
);
1035 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1037 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1038 if (buffer
== NULL
) return ;
1040 SetLastError(MAGIC_DEAD
);
1041 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1042 buffer
, cbBuf
*2, &pcbNeeded
);
1045 ok(res
&& buffer
[0], "returned %d with " \
1046 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1047 res
, GetLastError(), lstrlenA((char *)buffer
));
1050 SetLastError(MAGIC_DEAD
);
1051 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1052 buffer
, cbBuf
*2, &pcbNeeded
);
1054 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1056 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1057 if (buffer
== NULL
) return ;
1060 SetLastError(MAGIC_DEAD
);
1061 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1062 buffer
, cbBuf
*2, &pcbNeeded
);
1065 /* "Windows NT x86" is invalid for win9x */
1066 ok( (res
&& buffer
[0]) ||
1067 (!res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
1068 "returned %d with lasterror=%d and len=%d (expected '!= 0' with " \
1069 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1070 res
, GetLastError(), lstrlenA((char *)buffer
));
1072 /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
1073 SetLastError(MAGIC_DEAD
);
1074 res
= GetPrinterDriverDirectoryA(empty
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1075 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1077 SetLastError(MAGIC_DEAD
);
1078 res
= GetPrinterDriverDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1079 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1081 SetLastError(MAGIC_DEAD
);
1082 res
= GetPrinterDriverDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1083 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1085 HeapFree( GetProcessHeap(), 0, buffer
);
1090 static void test_GetPrintProcessorDirectory(void)
1092 LPBYTE buffer
= NULL
;
1094 DWORD pcbNeeded
= 0;
1098 SetLastError(0xdeadbeef);
1099 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
1100 /* The deactivated Spooler is catched here on NT3.51 */
1101 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1102 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1103 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1104 res
, GetLastError());
1106 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
1107 if(buffer
== NULL
) return;
1110 SetLastError(0xdeadbeef);
1111 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
1112 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1114 SetLastError(0xdeadbeef);
1116 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1117 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1119 /* Buffer to small */
1121 SetLastError(0xdeadbeef);
1122 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
1123 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1124 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1125 res
, GetLastError());
1128 /* XPsp2: the programm will crash here, when the spooler is not running */
1129 /* GetPrinterDriverDirectory has the same bug */
1131 SetLastError(0xdeadbeef);
1132 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, &pcbNeeded
);
1136 SetLastError(0xdeadbeef);
1137 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
1138 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1139 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1140 "returned %d with %d (expected '!= 0' or '0' with " \
1141 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1145 SetLastError(0xdeadbeef);
1146 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1147 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1148 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1149 "returned %d with %d (expected '!= 0' or '0' with " \
1150 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1153 /* with a valid buffer, but level is invalid */
1155 SetLastError(0xdeadbeef);
1156 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1157 if (res
&& buffer
[0])
1159 /* Level is ignored in win9x*/
1160 trace("invalid level (2) was ignored\n");
1164 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1165 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1166 res
, GetLastError());
1169 /* Empty environment is the same as the default environment */
1171 SetLastError(0xdeadbeef);
1172 res
= GetPrintProcessorDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1173 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1175 /* "Windows 4.0" is valid for win9x and NT */
1177 SetLastError(0xdeadbeef);
1178 res
= GetPrintProcessorDirectoryA(NULL
, env_win9x_case
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1179 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1182 /* "Windows NT x86" is invalid for win9x */
1184 SetLastError(0xdeadbeef);
1185 res
= GetPrintProcessorDirectoryA(NULL
, env_x86
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1186 ok( res
|| (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1187 "returned %d with %d (expected '!= 0' or '0' with " \
1188 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
1190 /* invalid on all Systems */
1192 SetLastError(0xdeadbeef);
1193 res
= GetPrintProcessorDirectoryA(NULL
, invalid_env
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1194 ok( !res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1195 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1196 res
, GetLastError());
1198 /* Empty servername is the same as the local computer */
1200 SetLastError(0xdeadbeef);
1201 res
= GetPrintProcessorDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1202 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1204 /* invalid on all Systems */
1206 SetLastError(0xdeadbeef);
1207 res
= GetPrintProcessorDirectoryA(invalid_server
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1208 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1209 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1210 res
, GetLastError());
1212 HeapFree(GetProcessHeap(), 0, buffer
);
1217 static void test_OpenPrinter(void)
1219 PRINTER_DEFAULTSA defaults
;
1221 LPSTR default_printer
;
1224 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
1228 SetLastError(MAGIC_DEAD
);
1229 res
= OpenPrinter(NULL
, NULL
, NULL
);
1230 /* The deactivated Spooler is catched here on NT3.51 */
1231 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1232 ok(!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1233 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1234 res
, GetLastError());
1237 /* Get Handle for the local Printserver (NT only)*/
1238 hprinter
= (HANDLE
) MAGIC_DEAD
;
1239 SetLastError(MAGIC_DEAD
);
1240 res
= OpenPrinter(NULL
, &hprinter
, NULL
);
1241 /* The deactivated Spooler is catched here on XPsp2 */
1242 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1243 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1244 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1245 res
, GetLastError());
1247 ClosePrinter(hprinter
);
1249 defaults
.pDatatype
=NULL
;
1250 defaults
.pDevMode
=NULL
;
1252 defaults
.DesiredAccess
=0;
1253 hprinter
= (HANDLE
) MAGIC_DEAD
;
1254 SetLastError(MAGIC_DEAD
);
1255 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
1256 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1257 if (res
) ClosePrinter(hprinter
);
1259 defaults
.DesiredAccess
=-1;
1260 hprinter
= (HANDLE
) MAGIC_DEAD
;
1261 SetLastError(MAGIC_DEAD
);
1262 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
1264 ok(!res
&& GetLastError() == ERROR_ACCESS_DENIED
,
1265 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1266 res
, GetLastError());
1268 if (res
) ClosePrinter(hprinter
);
1272 size
= sizeof(buffer
) - 3 ;
1278 if (GetComputerNameA(ptr
, &size
)) {
1280 hprinter
= (HANDLE
) MAGIC_DEAD
;
1281 SetLastError(MAGIC_DEAD
);
1282 res
= OpenPrinter(buffer
, &hprinter
, NULL
);
1284 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1285 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1286 res
, GetLastError());
1288 if(res
) ClosePrinter(hprinter
);
1291 /* Invalid Printername */
1292 hprinter
= (HANDLE
) MAGIC_DEAD
;
1293 SetLastError(MAGIC_DEAD
);
1294 res
= OpenPrinter(illegal_name
, &hprinter
, NULL
);
1295 ok(!res
&& ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1296 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1297 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or" \
1298 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1299 if(res
) ClosePrinter(hprinter
);
1301 hprinter
= (HANDLE
) MAGIC_DEAD
;
1302 SetLastError(MAGIC_DEAD
);
1303 res
= OpenPrinter(empty
, &hprinter
, NULL
);
1304 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1306 ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1307 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1308 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME" \
1309 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1310 if(res
) ClosePrinter(hprinter
);
1313 /* Get Handle for the default Printer */
1314 if ((default_printer
= find_default_printer()))
1316 hprinter
= (HANDLE
) MAGIC_DEAD
;
1317 SetLastError(MAGIC_DEAD
);
1318 res
= OpenPrinter(default_printer
, &hprinter
, NULL
);
1319 if((!res
) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE
))
1321 trace("The Service 'Spooler' is required for '%s'\n", default_printer
);
1324 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1325 if(res
) ClosePrinter(hprinter
);
1327 SetLastError(MAGIC_DEAD
);
1328 res
= OpenPrinter(default_printer
, NULL
, NULL
);
1329 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1330 ok(res
|| (GetLastError() == ERROR_INVALID_PARAMETER
),
1331 "returned %d with %d (expected '!=0' or '0' with " \
1332 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1334 defaults
.pDatatype
=NULL
;
1335 defaults
.pDevMode
=NULL
;
1336 defaults
.DesiredAccess
=0;
1338 hprinter
= (HANDLE
) MAGIC_DEAD
;
1339 SetLastError(MAGIC_DEAD
);
1340 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1341 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1342 "returned %d with %d (expected '!=0' or '0' with " \
1343 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1344 if(res
) ClosePrinter(hprinter
);
1346 defaults
.pDatatype
= empty
;
1348 hprinter
= (HANDLE
) MAGIC_DEAD
;
1349 SetLastError(MAGIC_DEAD
);
1350 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1351 /* stop here, when a remote Printserver has no RPC-Service running */
1352 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1353 ok(res
|| ((GetLastError() == ERROR_INVALID_DATATYPE
) ||
1354 (GetLastError() == ERROR_ACCESS_DENIED
)),
1355 "returned %d with %d (expected '!=0' or '0' with: " \
1356 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1357 res
, GetLastError());
1358 if(res
) ClosePrinter(hprinter
);
1361 defaults
.pDatatype
=NULL
;
1362 defaults
.DesiredAccess
=PRINTER_ACCESS_USE
;
1364 hprinter
= (HANDLE
) MAGIC_DEAD
;
1365 SetLastError(MAGIC_DEAD
);
1366 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1367 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1368 "returned %d with %d (expected '!=0' or '0' with " \
1369 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1370 if(res
) ClosePrinter(hprinter
);
1373 defaults
.DesiredAccess
=PRINTER_ALL_ACCESS
;
1374 hprinter
= (HANDLE
) MAGIC_DEAD
;
1375 SetLastError(MAGIC_DEAD
);
1376 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1377 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1378 "returned %d with %d (expected '!=0' or '0' with " \
1379 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1380 if(res
) ClosePrinter(hprinter
);
1386 static void test_SetDefaultPrinter(void)
1389 LPSTR default_printer
;
1390 DWORD size
= DEFAULT_PRINTER_SIZE
;
1391 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
1392 CHAR org_value
[DEFAULT_PRINTER_SIZE
];
1395 if (!pSetDefaultPrinterA
) return;
1396 /* only supported on win2k and above */
1398 default_printer
= find_default_printer();
1400 /* backup the original value */
1401 org_value
[0] = '\0';
1402 SetLastError(MAGIC_DEAD
);
1403 res
= GetProfileStringA("windows", "device", NULL
, org_value
, size
);
1405 /* first part: with the default Printer */
1406 SetLastError(MAGIC_DEAD
);
1407 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1409 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1410 /* spooler is running or we have no spooler here*/
1412 /* Not implemented in wine */
1413 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
1414 trace("SetDefaultPrinterA() not implemented yet.\n");
1418 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1419 "returned %d with %d (expected '0' with " \
1420 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1422 WriteProfileStringA("windows", "device", org_value
);
1423 SetLastError(MAGIC_DEAD
);
1424 res
= pSetDefaultPrinterA("");
1425 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1426 "returned %d with %d (expected '!=0' or '0' with " \
1427 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1429 WriteProfileStringA("windows", "device", org_value
);
1430 SetLastError(MAGIC_DEAD
);
1431 res
= pSetDefaultPrinterA(NULL
);
1432 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1433 "returned %d with %d (expected '!=0' or '0' with " \
1434 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1436 WriteProfileStringA("windows", "device", org_value
);
1437 SetLastError(MAGIC_DEAD
);
1438 res
= pSetDefaultPrinterA(default_printer
);
1439 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1440 "returned %d with %d (expected '!=0' or '0' with " \
1441 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1444 /* second part: always without a default Printer */
1445 WriteProfileStringA("windows", "device", NULL
);
1446 SetLastError(MAGIC_DEAD
);
1447 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1449 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1450 "returned %d with %d (expected '0' with " \
1451 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1453 WriteProfileStringA("windows", "device", NULL
);
1454 SetLastError(MAGIC_DEAD
);
1455 res
= pSetDefaultPrinterA("");
1456 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1457 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1458 "returned %d with %d (expected '!=0' or '0' with " \
1459 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1461 WriteProfileStringA("windows", "device", NULL
);
1462 SetLastError(MAGIC_DEAD
);
1463 res
= pSetDefaultPrinterA(NULL
);
1464 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1465 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1466 "returned %d with %d (expected '!=0' or '0' with " \
1467 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1469 WriteProfileStringA("windows", "device", NULL
);
1470 SetLastError(MAGIC_DEAD
);
1471 res
= pSetDefaultPrinterA(default_printer
);
1472 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1473 "returned %d with %d (expected '!=0' or '0' with " \
1474 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1476 /* restore the original value */
1477 res
= pSetDefaultPrinterA(default_printer
); /* the nice way */
1478 WriteProfileStringA("windows", "device", org_value
); /* the old way */
1481 SetLastError(MAGIC_DEAD
);
1482 res
= GetProfileStringA("windows", "device", NULL
, buffer
, size
);
1483 ok(!lstrcmpA(org_value
, buffer
), "'%s' (expected '%s')\n", buffer
, org_value
);
1487 static void test_GetPrinterDriver(void)
1489 LPSTR default_printer
;
1494 DWORD needed
, filled
;
1496 default_printer
= find_default_printer();
1497 if (!default_printer
)
1499 trace("There is no default printer installed, skiping the test\n");
1504 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
1507 trace("There is no printers installed, skiping the test\n");
1510 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
1512 for (level
= -1; level
<= 7; level
++)
1514 SetLastError(0xdeadbeef);
1516 ret
= GetPrinterDriver(hprn
, NULL
, level
, NULL
, 0, &needed
);
1517 ok(!ret
, "level %d: GetPrinterDriver should fail\n", level
);
1518 if (level
>= 1 && level
<= 6)
1520 /* Not all levels are supported on all Windows-Versions */
1521 if(GetLastError() == ERROR_INVALID_LEVEL
) continue;
1522 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %d\n", GetLastError());
1523 ok(needed
> 0,"not expected needed buffer size %d\n", needed
);
1527 /* ERROR_OUTOFMEMORY found on win9x */
1528 ok( ((GetLastError() == ERROR_INVALID_LEVEL
) ||
1529 (GetLastError() == ERROR_OUTOFMEMORY
)),
1530 "%d: returned %d with %d (expected '0' with: " \
1531 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1532 level
, ret
, GetLastError());
1533 /* needed is modified in win9x. The modified Value depends on the
1534 default Printer. testing for "needed == (DWORD)-1" will fail */
1538 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1540 SetLastError(0xdeadbeef);
1542 ret
= GetPrinterDriver(hprn
, NULL
, level
, buf
, needed
, &filled
);
1543 ok(ret
, "level %d: GetPrinterDriver error %d\n", level
, GetLastError());
1544 ok(needed
== filled
, "needed %d != filled %d\n", needed
, filled
);
1548 DRIVER_INFO_2
*di_2
= (DRIVER_INFO_2
*)buf
;
1549 DWORD calculated
= sizeof(*di_2
);
1551 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1552 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1553 ok((di_2
->cVersion
>= 0 && di_2
->cVersion
<= 3) ||
1554 (di_2
->cVersion
== 0x0400), "di_2->cVersion = %d\n", di_2
->cVersion
);
1555 ok(di_2
->pName
!= NULL
, "not expected NULL ptr\n");
1556 ok(di_2
->pEnvironment
!= NULL
, "not expected NULL ptr\n");
1557 ok(di_2
->pDriverPath
!= NULL
, "not expected NULL ptr\n");
1558 ok(di_2
->pDataFile
!= NULL
, "not expected NULL ptr\n");
1559 ok(di_2
->pConfigFile
!= NULL
, "not expected NULL ptr\n");
1561 trace("cVersion %d\n", di_2
->cVersion
);
1562 trace("pName %s\n", di_2
->pName
);
1563 calculated
+= strlen(di_2
->pName
) + 1;
1564 trace("pEnvironment %s\n", di_2
->pEnvironment
);
1565 calculated
+= strlen(di_2
->pEnvironment
) + 1;
1566 trace("pDriverPath %s\n", di_2
->pDriverPath
);
1567 calculated
+= strlen(di_2
->pDriverPath
) + 1;
1568 trace("pDataFile %s\n", di_2
->pDataFile
);
1569 calculated
+= strlen(di_2
->pDataFile
) + 1;
1570 trace("pConfigFile %s\n", di_2
->pConfigFile
);
1571 calculated
+= strlen(di_2
->pConfigFile
) + 1;
1573 /* XP allocates memory for both ANSI and unicode names */
1574 ok(filled
>= calculated
,"calculated %d != filled %d\n", calculated
, filled
);
1577 HeapFree(GetProcessHeap(), 0, buf
);
1580 SetLastError(0xdeadbeef);
1581 ret
= ClosePrinter(hprn
);
1582 ok(ret
, "ClosePrinter error %d\n", GetLastError());
1585 static void test_DEVMODE(const DEVMODE
*dm
, LONG dmSize
, LPCSTR exp_prn_name
)
1587 /* On NT3.51, some fields in DEVMODE are empty/zero
1588 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1589 We skip the Tests on this Platform */
1590 if (dm
->dmSpecVersion
|| dm
->dmDriverVersion
|| dm
->dmDriverExtra
) {
1591 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1592 ok(!strncmp(exp_prn_name
, (LPCSTR
)dm
->dmDeviceName
, CCHDEVICENAME
-1),
1593 "expected '%s', got '%s'\n", exp_prn_name
, dm
->dmDeviceName
);
1594 ok(dm
->dmSize
+ dm
->dmDriverExtra
== dmSize
,
1595 "%u != %d\n", dm
->dmSize
+ dm
->dmDriverExtra
, dmSize
);
1597 trace("dmFields %08x\n", dm
->dmFields
);
1600 static void test_DocumentProperties(void)
1602 LPSTR default_printer
;
1607 default_printer
= find_default_printer();
1608 if (!default_printer
)
1610 trace("There is no default printer installed, skiping the test\n");
1615 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
1618 trace("There is no printers installed, skiping the test\n");
1621 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
1623 dm_size
= DocumentProperties(0, hprn
, NULL
, NULL
, NULL
, 0);
1624 trace("DEVMODE required size %d\n", dm_size
);
1625 ok(dm_size
>= sizeof(DEVMODE
), "unexpected DocumentProperties ret value %d\n", dm_size
);
1627 dm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dm_size
);
1629 ret
= DocumentProperties(0, hprn
, NULL
, dm
, dm
, DM_OUT_BUFFER
);
1630 ok(ret
== IDOK
, "DocumentProperties ret value %d != expected IDOK\n", ret
);
1632 test_DEVMODE(dm
, dm_size
, default_printer
);
1634 HeapFree(GetProcessHeap(), 0, dm
);
1636 SetLastError(0xdeadbeef);
1637 ret
= ClosePrinter(hprn
);
1638 ok(ret
, "ClosePrinter error %d\n", GetLastError());
1641 static void test_EnumPrinters(void)
1643 DWORD neededA
, neededW
, num
;
1646 SetLastError(0xdeadbeef);
1647 ret
= EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededA
, &num
);
1648 ok(ret
== 0, "ret %d\n", ret
);
1649 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
1650 ok(num
== 0, "num %d\n", num
);
1652 SetLastError(0xdeadbeef);
1653 ret
= EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededW
, &num
);
1654 ok(ret
== 0, "ret %d\n", ret
);
1655 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
1656 ok(num
== 0, "num %d\n", num
);
1658 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
1659 to hold the buffer returned by EnumPrintersW */
1660 ok(neededA
== neededW
, "neededA %d neededW %d\n", neededA
, neededW
);
1665 LPSTR default_printer
;
1667 hwinspool
= GetModuleHandleA("winspool.drv");
1668 pGetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "GetDefaultPrinterA");
1669 pSetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "SetDefaultPrinterA");
1671 default_printer
= find_default_printer();
1675 test_ConfigurePort();
1676 test_DeleteMonitor();
1678 test_DocumentProperties();
1679 test_EnumForms(NULL
);
1680 if (default_printer
) test_EnumForms(default_printer
);
1681 test_EnumMonitors();
1683 test_GetDefaultPrinter();
1684 test_GetPrinterDriverDirectory();
1685 test_GetPrintProcessorDirectory();
1687 test_GetPrinterDriver();
1688 test_SetDefaultPrinter();
1690 test_EnumPrinters();