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
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
36 #include "wine/test.h"
38 #define MAGIC_DEAD 0xdeadbeef
39 #define DEFAULT_PRINTER_SIZE 1000
41 static CHAR does_not_exist_dll
[]= "does_not_exist.dll";
42 static CHAR does_not_exist
[] = "does_not_exist";
43 static CHAR empty
[] = "";
44 static CHAR env_x64
[] = "Windows x64";
45 static CHAR env_x86
[] = "Windows NT x86";
46 static CHAR env_win9x_case
[] = "windowS 4.0";
47 static CHAR illegal_name
[] = "illegal,name";
48 static CHAR invalid_env
[] = "invalid_env";
49 static CHAR LocalPortA
[] = "Local Port";
50 static CHAR portname_com1
[] = "COM1:";
51 static CHAR portname_file
[] = "FILE:";
52 static CHAR portname_lpt1
[] = "LPT1:";
53 static CHAR server_does_not_exist
[] = "\\does_not_exist";
54 static CHAR version_dll
[] = "version.dll";
55 static CHAR winetest
[] = "winetest";
56 static CHAR xcv_localport
[] = ",XcvMonitor Local Port";
58 static WCHAR cmd_MonitorUIW
[] = {'M','o','n','i','t','o','r','U','I',0};
59 static WCHAR cmd_PortIsValidW
[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
60 static WCHAR emptyW
[] = {0};
62 static WCHAR portname_com1W
[] = {'C','O','M','1',':',0};
63 static WCHAR portname_com2W
[] = {'C','O','M','2',':',0};
64 static WCHAR portname_fileW
[] = {'F','I','L','E',':',0};
65 static WCHAR portname_lpt1W
[] = {'L','P','T','1',':',0};
66 static WCHAR portname_lpt2W
[] = {'L','P','T','2',':',0};
68 static HANDLE hwinspool
;
69 static BOOL (WINAPI
* pGetDefaultPrinterA
)(LPSTR
, LPDWORD
);
70 static BOOL (WINAPI
* pSetDefaultPrinterA
)(LPCSTR
);
71 static DWORD (WINAPI
* pXcvDataW
)(HANDLE
, LPCWSTR
, PBYTE
, DWORD
, PBYTE
, DWORD
, PDWORD
, PDWORD
);
72 static BOOL (WINAPI
* pAddPortExA
)(LPSTR
, DWORD
, LPBYTE
, LPSTR
);
75 /* ################################ */
77 struct monitor_entry
{
82 static LPSTR default_printer
= NULL
;
83 static LPSTR local_server
= NULL
;
84 static LPSTR tempdirA
= NULL
;
85 static LPSTR tempfileA
= NULL
;
86 static LPWSTR tempdirW
= NULL
;
87 static LPWSTR tempfileW
= NULL
;
89 /* ################################ */
90 /* report common behavior only once */
91 static DWORD deactivated_spooler_reported
= 0;
92 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
93 if ((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
95 if (!deactivated_spooler_reported) { \
96 deactivated_spooler_reported++; \
97 skip("The Service 'Spooler' is required for many test\n"); \
102 static DWORD access_denied_reported
= 0;
103 #define RETURN_ON_ACCESS_DENIED(res) \
104 if ((res == 0) && (GetLastError() == ERROR_ACCESS_DENIED)) \
106 if (!access_denied_reported) { \
107 access_denied_reported++; \
108 skip("More Access-Rights are required for many test\n"); \
113 /* ################################ */
115 static void find_default_printer(VOID
)
117 static char buffer
[DEFAULT_PRINTER_SIZE
];
122 if ((default_printer
== NULL
) && (pGetDefaultPrinterA
))
125 needed
= sizeof(buffer
);
126 res
= pGetDefaultPrinterA(buffer
, &needed
);
127 if(res
) default_printer
= buffer
;
128 trace("default_printer: '%s'\n", default_printer
);
130 if (default_printer
== NULL
)
134 /* NT 3.x and above */
135 if (RegOpenKeyEx(HKEY_CURRENT_USER
,
136 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
137 0, KEY_QUERY_VALUE
, &hwindows
) == NO_ERROR
) {
139 needed
= sizeof(buffer
);
140 if (RegQueryValueEx(hwindows
, "device", NULL
,
141 &type
, (LPBYTE
)buffer
, &needed
) == NO_ERROR
) {
143 ptr
= strchr(buffer
, ',');
146 default_printer
= buffer
;
149 RegCloseKey(hwindows
);
151 trace("default_printer: '%s'\n", default_printer
);
153 if (default_printer
== NULL
)
156 needed
= sizeof(buffer
);
157 res
= GetProfileStringA("windows", "device", "*", buffer
, needed
);
159 ptr
= strchr(buffer
, ',');
162 default_printer
= buffer
;
165 trace("default_printer: '%s'\n", default_printer
);
170 static struct monitor_entry
* find_installed_monitor(void)
172 MONITOR_INFO_2A mi2a
;
173 static struct monitor_entry
* entry
= NULL
;
177 static struct monitor_entry monitor_table
[] = {
178 {env_win9x_case
, "localspl.dll"},
179 {env_x86
, "localspl.dll"},
180 {env_x64
, "localspl.dll"},
181 {env_win9x_case
, "localmon.dll"},
182 {env_x86
, "localmon.dll"},
183 {env_win9x_case
, "tcpmon.dll"},
184 {env_x86
, "tcpmon.dll"},
185 {env_win9x_case
, "usbmon.dll"},
186 {env_x86
, "usbmon.dll"},
187 {env_win9x_case
, "mspp32.dll"},
188 {env_x86
, "win32spl.dll"},
189 {env_x86
, "redmonnt.dll"},
190 {env_x86
, "redmon35.dll"},
191 {env_win9x_case
, "redmon95.dll"},
192 {env_x86
, "pdfcmnnt.dll"},
193 {env_win9x_case
, "pdfcmn95.dll"},
196 if (entry
) return entry
;
198 num_tests
= (sizeof(monitor_table
)/sizeof(struct monitor_entry
));
201 DeleteMonitorA(NULL
, env_x64
, winetest
);
202 DeleteMonitorA(NULL
, env_x86
, winetest
);
203 DeleteMonitorA(NULL
, env_win9x_case
, winetest
);
205 /* find a usable monitor from the table */
206 mi2a
.pName
= winetest
;
207 while ((entry
== NULL
) && (i
< num_tests
)) {
208 entry
= &monitor_table
[i
];
210 mi2a
.pEnvironment
= entry
->env
;
211 mi2a
.pDLLName
= entry
->dllname
;
213 if (AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
)) {
215 trace("using '%s', '%s'\n", entry
->env
, entry
->dllname
);
216 DeleteMonitorA(NULL
, entry
->env
, winetest
);
227 /* ########################### */
229 static void find_local_server(VOID
)
231 static char buffer
[MAX_PATH
];
235 size
= sizeof(buffer
) - 3 ;
240 SetLastError(0xdeadbeef);
241 res
= GetComputerNameA(&buffer
[2], &size
);
242 trace("returned %d with %d and %d: '%s'\n", res
, GetLastError(), size
, buffer
);
244 ok( res
!= 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
245 res
, GetLastError(), size
, buffer
);
247 if (res
) local_server
= buffer
;
250 /* ########################### */
252 static void find_tempfile(VOID
)
254 static CHAR buffer_dirA
[MAX_PATH
];
255 static CHAR buffer_fileA
[MAX_PATH
];
256 static WCHAR buffer_dirW
[MAX_PATH
];
257 static WCHAR buffer_fileW
[MAX_PATH
];
261 memset(buffer_dirA
, 0, MAX_PATH
- 1);
262 buffer_dirA
[MAX_PATH
- 1] = '\0';
263 SetLastError(0xdeadbeef);
264 res
= GetTempPathA(MAX_PATH
, buffer_dirA
);
265 ok(res
, "returned %u with %u and '%s' (expected '!= 0')\n", res
, GetLastError(), buffer_dirA
);
266 if (res
== 0) return;
268 memset(buffer_fileA
, 0, MAX_PATH
- 1);
269 buffer_fileA
[MAX_PATH
- 1] = '\0';
270 SetLastError(0xdeadbeef);
271 res
= GetTempFileNameA(buffer_dirA
, winetest
, 0, buffer_fileA
);
272 ok(res
, "returned %u with %u and '%s' (expected '!= 0')\n", res
, GetLastError(), buffer_fileA
);
273 if (res
== 0) return;
275 SetLastError(0xdeadbeef);
276 resint
= MultiByteToWideChar(CP_ACP
, 0, buffer_dirA
, -1, buffer_dirW
, MAX_PATH
);
277 ok(res
, "returned %u with %u (expected '!= 0')\n", resint
, GetLastError());
278 if (resint
== 0) return;
280 SetLastError(0xdeadbeef);
281 resint
= MultiByteToWideChar(CP_ACP
, 0, buffer_fileA
, -1, buffer_fileW
, MAX_PATH
);
282 ok(res
, "returned %u with %u (expected '!= 0')\n", resint
, GetLastError());
283 if (resint
== 0) return;
285 tempdirA
= buffer_dirA
;
286 tempfileA
= buffer_fileA
;
287 tempdirW
= buffer_dirW
;
288 tempfileW
= buffer_fileW
;
289 trace("tempfile: '%s'\n", tempfileA
);
292 /* ########################### */
294 static void test_AddMonitor(void)
296 MONITOR_INFO_2A mi2a
;
297 struct monitor_entry
* entry
= NULL
;
300 entry
= find_installed_monitor();
302 SetLastError(MAGIC_DEAD
);
303 res
= AddMonitorA(NULL
, 1, NULL
);
304 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
305 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
306 res
, GetLastError());
308 SetLastError(MAGIC_DEAD
);
309 res
= AddMonitorA(NULL
, 3, NULL
);
310 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
311 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
312 res
, GetLastError());
316 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
317 SetLastError(MAGIC_DEAD
);
318 res
= AddMonitorA(NULL
, 2, NULL
);
319 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
321 ((GetLastError() == MAGIC_DEAD
) ||
322 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
323 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
324 "ERROR_PRIVILEGE_NOT_HELD)\n", res
, GetLastError());
327 ZeroMemory(&mi2a
, sizeof(MONITOR_INFO_2A
));
328 SetLastError(MAGIC_DEAD
);
329 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
330 RETURN_ON_DEACTIVATED_SPOOLER(res
)
331 RETURN_ON_ACCESS_DENIED(res
)
333 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
334 ok(!res
&& ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
335 (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
336 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
337 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
340 skip("No usable Monitor found\n");
346 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
347 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
348 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
349 is created on win9x and we do not want to hit this bug here. */
351 mi2a
.pEnvironment
= entry
->env
;
352 SetLastError(MAGIC_DEAD
);
353 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
357 mi2a
.pEnvironment
= entry
->env
;
359 SetLastError(MAGIC_DEAD
);
360 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
361 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
363 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
364 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
365 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
366 "ERROR_PRIVILEGE_NOT_HELD)\n",
367 res
, GetLastError());
369 mi2a
.pName
= winetest
;
370 SetLastError(MAGIC_DEAD
);
371 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
372 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
374 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
375 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
376 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
377 "ERROR_PRIVILEGE_NOT_HELD)\n",
378 res
, GetLastError());
380 mi2a
.pDLLName
= empty
;
381 SetLastError(MAGIC_DEAD
);
382 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
383 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
384 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
385 res
, GetLastError());
387 mi2a
.pDLLName
= does_not_exist_dll
;
388 SetLastError(MAGIC_DEAD
);
389 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
390 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
392 ((GetLastError() == ERROR_MOD_NOT_FOUND
) ||
393 (GetLastError() == ERROR_INVALID_PARAMETER
)),
394 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
395 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
397 mi2a
.pDLLName
= version_dll
;
398 SetLastError(MAGIC_DEAD
);
399 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
400 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
402 ((GetLastError() == ERROR_PROC_NOT_FOUND
) ||
403 (GetLastError() == ERROR_INVALID_PARAMETER
)),
404 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
405 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
406 if (res
) DeleteMonitorA(NULL
, entry
->env
, winetest
);
408 /* Test AddMonitor with real options */
409 mi2a
.pDLLName
= entry
->dllname
;
410 SetLastError(MAGIC_DEAD
);
411 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
412 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
414 /* add a monitor twice */
415 SetLastError(MAGIC_DEAD
);
416 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
417 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
419 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED
) ||
420 (GetLastError() == ERROR_ALREADY_EXISTS
)),
421 "returned %d with %d (expected '0' with: "
422 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
423 res
, GetLastError());
425 DeleteMonitorA(NULL
, entry
->env
, winetest
);
426 SetLastError(MAGIC_DEAD
);
427 res
= AddMonitorA(empty
, 2, (LPBYTE
) &mi2a
);
428 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
431 DeleteMonitorA(NULL
, entry
->env
, winetest
);
435 /* ########################### */
437 static void test_AddPort(void)
441 SetLastError(0xdeadbeef);
442 res
= AddPortA(NULL
, 0, NULL
);
443 RETURN_ON_DEACTIVATED_SPOOLER(res
)
444 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
445 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
446 (GetLastError() == ERROR_INVALID_PARAMETER
)),
447 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
448 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
451 SetLastError(0xdeadbeef);
452 res
= AddPortA(NULL
, 0, empty
);
453 /* Allowed only for (Printer-)Administrators */
454 RETURN_ON_ACCESS_DENIED(res
)
456 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
457 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
458 (GetLastError() == ERROR_INVALID_PARAMETER
)),
459 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
460 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
463 SetLastError(0xdeadbeef);
464 res
= AddPortA(NULL
, 0, does_not_exist
);
465 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
466 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
467 (GetLastError() == ERROR_INVALID_PARAMETER
)),
468 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
469 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
473 /* ########################### */
475 static void test_AddPortEx(void)
482 win_skip("AddPortEx not supported\n");
486 /* start test with a clean system */
487 DeletePortA(NULL
, 0, tempfileA
);
489 pi
.pPortName
= tempfileA
;
490 SetLastError(0xdeadbeef);
491 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
492 RETURN_ON_DEACTIVATED_SPOOLER(res
)
494 /* Allowed only for (Printer-)Administrators.
495 W2K+XP: ERROR_INVALID_PARAMETER */
496 if (!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
)) {
497 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
500 ok( res
, "got %u with %u (expected '!= 0')\n", res
, GetLastError());
502 /* Add a port, that already exist */
503 SetLastError(0xdeadbeef);
504 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
505 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
506 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
507 res
, GetLastError());
508 DeletePortA(NULL
, 0, tempfileA
);
511 /* the Monitorname must match */
512 SetLastError(0xdeadbeef);
513 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, NULL
);
514 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
515 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
516 res
, GetLastError());
517 if (res
) DeletePortA(NULL
, 0, tempfileA
);
519 SetLastError(0xdeadbeef);
520 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, empty
);
521 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
522 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
523 res
, GetLastError());
524 if (res
) DeletePortA(NULL
, 0, tempfileA
);
526 SetLastError(0xdeadbeef);
527 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, does_not_exist
);
528 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
529 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
530 res
, GetLastError());
531 if (res
) DeletePortA(NULL
, 0, tempfileA
);
534 /* We need a Portname */
535 SetLastError(0xdeadbeef);
536 res
= pAddPortExA(NULL
, 1, NULL
, LocalPortA
);
537 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
538 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
539 res
, GetLastError());
542 SetLastError(0xdeadbeef);
543 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
544 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
545 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
546 res
, GetLastError());
547 if (res
) DeletePortA(NULL
, 0, tempfileA
);
550 /* level 2 is documented as supported for Printmonitors,
551 but that is not supported for "Local Port" (localspl.dll) and
552 AddPortEx fails with ERROR_INVALID_LEVEL */
554 pi
.pPortName
= tempfileA
;
555 pi
.pMonitorName
= LocalPortA
;
556 pi
.pDescription
= winetest
;
557 pi
.fPortType
= PORT_TYPE_WRITE
;
559 SetLastError(0xdeadbeef);
560 res
= pAddPortExA(NULL
, 2, (LPBYTE
) &pi
, LocalPortA
);
561 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
562 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
563 res
, GetLastError());
564 if (res
) DeletePortA(NULL
, 0, tempfileA
);
568 SetLastError(0xdeadbeef);
569 res
= pAddPortExA(NULL
, 0, (LPBYTE
) &pi
, LocalPortA
);
570 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
571 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
572 res
, GetLastError());
574 SetLastError(0xdeadbeef);
575 res
= pAddPortExA(NULL
, 3, (LPBYTE
) &pi
, LocalPortA
);
576 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
577 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
578 res
, GetLastError());
582 DeletePortA(NULL
, 0, tempfileA
);
586 /* ########################### */
588 static void test_ConfigurePort(void)
593 SetLastError(0xdeadbeef);
594 res
= ConfigurePortA(NULL
, 0, NULL
);
595 RETURN_ON_DEACTIVATED_SPOOLER(res
)
596 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
597 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
598 (GetLastError() == ERROR_INVALID_PARAMETER
)),
599 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
600 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
602 SetLastError(0xdeadbeef);
603 res
= ConfigurePortA(NULL
, 0, empty
);
604 /* Allowed only for (Printer-)Administrators */
605 RETURN_ON_ACCESS_DENIED(res
)
607 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
608 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
609 (GetLastError() == ERROR_INVALID_PARAMETER
)),
610 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
611 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
614 SetLastError(0xdeadbeef);
615 res
= ConfigurePortA(NULL
, 0, does_not_exist
);
616 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
617 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
618 (GetLastError() == ERROR_INVALID_PARAMETER
)),
619 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
620 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
624 - Case of Portnames is ignored
625 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
626 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
628 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
629 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
630 - Cancel ("Local Port") => ERROR_CANCELED
631 - Cancel ("Redirected Port") => Success
633 if (winetest_interactive
> 0) {
634 SetLastError(0xdeadbeef);
635 res
= ConfigurePortA(NULL
, 0, portname_com1
);
636 trace("'%s' returned %d with %d\n", portname_com1
, res
, GetLastError());
638 SetLastError(0xdeadbeef);
639 res
= ConfigurePortA(NULL
, 0, portname_lpt1
);
640 trace("'%s' returned %d with %d\n", portname_lpt1
, res
, GetLastError());
642 SetLastError(0xdeadbeef);
643 res
= ConfigurePortA(NULL
, 0, portname_file
);
644 trace("'%s' returned %d with %d\n", portname_file
, res
, GetLastError());
648 /* ########################### */
650 static void test_DeleteMonitor(void)
652 MONITOR_INFO_2A mi2a
;
653 struct monitor_entry
* entry
= NULL
;
657 entry
= find_installed_monitor();
660 skip("No usable Monitor found\n");
664 mi2a
.pName
= winetest
;
665 mi2a
.pEnvironment
= entry
->env
;
666 mi2a
.pDLLName
= entry
->dllname
;
668 /* Testing DeleteMonitor with real options */
669 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
671 SetLastError(MAGIC_DEAD
);
672 res
= DeleteMonitorA(NULL
, entry
->env
, winetest
);
673 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
675 /* Delete the Monitor twice */
676 SetLastError(MAGIC_DEAD
);
677 res
= DeleteMonitorA(NULL
, entry
->env
, winetest
);
678 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
680 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR
) ||
681 (GetLastError() == ERROR_INVALID_PARAMETER
)),
682 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
683 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
685 /* the environment */
686 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
687 SetLastError(MAGIC_DEAD
);
688 res
= DeleteMonitorA(NULL
, NULL
, winetest
);
689 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
691 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
692 SetLastError(MAGIC_DEAD
);
693 res
= DeleteMonitorA(NULL
, empty
, winetest
);
694 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
696 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
697 SetLastError(MAGIC_DEAD
);
698 res
= DeleteMonitorA(NULL
, invalid_env
, winetest
);
700 (!res
&& GetLastError() == ERROR_INVALID_ENVIRONMENT
) /* Vista/W2K8 */,
701 "returned %d with %d\n", res
, GetLastError());
703 /* the monitor-name */
704 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
705 SetLastError(MAGIC_DEAD
);
706 res
= DeleteMonitorA(NULL
, entry
->env
, NULL
);
707 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
709 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
710 (GetLastError() == ERROR_INVALID_NAME
)),
711 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
712 "ERROR_INVALID_NAME)\n", res
, GetLastError());
714 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
715 SetLastError(MAGIC_DEAD
);
716 res
= DeleteMonitorA(NULL
, entry
->env
, empty
);
717 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
719 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
720 (GetLastError() == ERROR_INVALID_NAME
)),
721 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
722 "ERROR_INVALID_NAME)\n", res
, GetLastError());
724 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
725 SetLastError(MAGIC_DEAD
);
726 res
= DeleteMonitorA(empty
, entry
->env
, winetest
);
727 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
730 DeleteMonitorA(NULL
, entry
->env
, winetest
);
733 /* ########################### */
735 static void test_DeletePort(void)
739 SetLastError(0xdeadbeef);
740 res
= DeletePortA(NULL
, 0, NULL
);
741 RETURN_ON_DEACTIVATED_SPOOLER(res
)
743 SetLastError(0xdeadbeef);
744 res
= DeletePortA(NULL
, 0, empty
);
745 /* Allowed only for (Printer-)Administrators */
746 RETURN_ON_ACCESS_DENIED(res
)
748 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
749 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
750 (GetLastError() == ERROR_INVALID_PARAMETER
)),
751 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
752 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
755 SetLastError(0xdeadbeef);
756 res
= DeletePortA(NULL
, 0, does_not_exist
);
757 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
758 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
759 (GetLastError() == ERROR_INVALID_PARAMETER
)),
760 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
761 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
765 /* ########################### */
767 static void test_EnumForms(LPSTR pName
)
777 const char *formtype
;
778 static const char * const formtypes
[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
779 #define FORMTYPE_MAX 2
780 PFORM_INFO_1A pFI_1a
;
781 PFORM_INFO_2A pFI_2a
;
783 res
= OpenPrinter(pName
, &hprinter
, NULL
);
784 RETURN_ON_DEACTIVATED_SPOOLER(res
)
785 if (!res
|| !hprinter
)
787 /* Open the local Prinserver is not supported on win9x */
788 if (pName
) skip("Failed to open '%s' (not supported on win9x)\n", pName
);
792 /* valid levels are 1 and 2 */
793 for(level
= 0; level
< 4; level
++) {
795 pcReturned
= 0xdeadbeef;
796 SetLastError(0xdeadbeef);
797 res
= EnumFormsA(hprinter
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
799 /* EnumForms is not implemented in win9x */
800 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
802 /* EnumForms for the Server not implemented on all NT-Versions */
803 if (!res
&& (GetLastError() == ERROR_INVALID_HANDLE
) && !pName
) continue;
805 /* Level 2 for EnumForms is not supported on all systems */
806 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
) && (level
== 2)) continue;
808 /* use only a short test, when we test with an invalid level */
809 if(!level
|| (level
> 2)) {
810 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
811 (res
&& (pcReturned
== 0)),
812 "(%d) returned %d with %d and 0x%08x (expected '0' with "
813 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
814 level
, res
, GetLastError(), pcReturned
);
818 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
819 "(%d) returned %d with %d (expected '0' with "
820 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
822 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
823 if (buffer
== NULL
) continue;
825 SetLastError(0xdeadbeef);
826 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
827 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
828 level
, res
, GetLastError());
830 if (winetest_debug
> 1) {
831 trace("dumping %d forms level %d\n", pcReturned
, level
);
832 pFI_1a
= (PFORM_INFO_1A
)buffer
;
833 pFI_2a
= (PFORM_INFO_2A
)buffer
;
834 for (i
= 0; i
< pcReturned
; i
++)
836 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
837 formtype
= (pFI_1a
->Flags
<= FORMTYPE_MAX
) ? formtypes
[pFI_1a
->Flags
] : formtypes
[3];
838 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i
, pFI_1a
->pName
,
839 (float)pFI_1a
->Size
.cx
/1000, (float)pFI_1a
->Size
.cy
/1000, formtype
);
841 if (level
== 1) pFI_1a
++;
843 /* output additional FORM_INFO_2 fields */
844 trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
845 pFI_2a
->pKeyword
, pFI_2a
->StringType
, pFI_2a
->pMuiDll
,
846 pFI_2a
->dwResourceId
, pFI_2a
->pDisplayName
, pFI_2a
->wLangId
);
848 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
850 pFI_1a
= (PFORM_INFO_1A
)pFI_2a
;
855 SetLastError(0xdeadbeef);
856 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
857 ok( res
, "(%d) returned %d with %d (expected '!=0')\n",
858 level
, res
, GetLastError());
860 SetLastError(0xdeadbeef);
861 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
862 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
863 "(%d) returned %d with %d (expected '0' with "
864 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
867 SetLastError(0xdeadbeef);
868 res
= EnumFormsA(hprinter
, level
, NULL
, cbBuf
, &pcbNeeded
, &pcReturned
);
869 ok( !res
&& (GetLastError() == ERROR_INVALID_USER_BUFFER
) ,
870 "(%d) returned %d with %d (expected '0' with "
871 "ERROR_INVALID_USER_BUFFER)\n", level
, res
, GetLastError());
874 SetLastError(0xdeadbeef);
875 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
876 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
877 "(%d) returned %d with %d (expected '0' with "
878 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
880 SetLastError(0xdeadbeef);
881 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
882 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
883 "(%d) returned %d with %d (expected '0' with "
884 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
886 SetLastError(0xdeadbeef);
887 res
= EnumFormsA(0, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
888 ok( !res
&& (GetLastError() == ERROR_INVALID_HANDLE
) ,
889 "(%d) returned %d with %d (expected '0' with "
890 "ERROR_INVALID_HANDLE)\n", level
, res
, GetLastError());
892 HeapFree(GetProcessHeap(), 0, buffer
);
893 } /* for(level ... */
895 ClosePrinter(hprinter
);
898 /* ########################### */
900 static void test_EnumMonitors(void)
909 /* valid levels are 1 and 2 */
910 for(level
= 0; level
< 4; level
++) {
912 pcReturned
= MAGIC_DEAD
;
913 SetLastError(MAGIC_DEAD
);
914 res
= EnumMonitorsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
916 RETURN_ON_DEACTIVATED_SPOOLER(res
)
918 /* not implemented yet in wine */
919 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
922 /* use only a short test, when we test with an invalid level */
923 if(!level
|| (level
> 2)) {
924 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
925 (res
&& (pcReturned
== 0)),
926 "(%d) returned %d with %d and 0x%08x (expected '0' with "
927 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
928 level
, res
, GetLastError(), pcReturned
);
932 /* Level 2 is not supported on win9x */
933 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
934 skip("Level %d not supported\n", level
);
938 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
939 "(%d) returned %d with %d (expected '0' with "
940 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
943 skip("no valid buffer size returned\n");
947 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
948 if (buffer
== NULL
) continue;
950 SetLastError(MAGIC_DEAD
);
951 pcbNeeded
= MAGIC_DEAD
;
952 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
953 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
954 level
, res
, GetLastError());
955 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n",
956 level
, pcbNeeded
, cbBuf
);
957 /* We can validate the returned Data with the Registry here */
960 SetLastError(MAGIC_DEAD
);
961 pcReturned
= MAGIC_DEAD
;
962 pcbNeeded
= MAGIC_DEAD
;
963 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
964 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
,
965 res
, GetLastError());
966 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
969 SetLastError(MAGIC_DEAD
);
970 pcbNeeded
= MAGIC_DEAD
;
971 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
972 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
973 "(%d) returned %d with %d (expected '0' with "
974 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
976 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
980 Do not add the next test:
981 w2k+: RPC_X_NULL_REF_POINTER
982 NT3.5: ERROR_INVALID_USER_BUFFER
983 win9x: crash in winspool.drv
985 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
988 SetLastError(MAGIC_DEAD
);
989 pcbNeeded
= MAGIC_DEAD
;
990 pcReturned
= MAGIC_DEAD
;
991 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
992 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
993 "(%d) returned %d with %d (expected '!=0' or '0' with "
994 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
996 pcbNeeded
= MAGIC_DEAD
;
997 pcReturned
= MAGIC_DEAD
;
998 SetLastError(MAGIC_DEAD
);
999 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1000 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
1001 "(%d) returned %d with %d (expected '!=0' or '0' with "
1002 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1004 HeapFree(GetProcessHeap(), 0, buffer
);
1005 } /* for(level ... */
1008 /* ########################### */
1010 static void test_EnumPorts(void)
1019 /* valid levels are 1 and 2 */
1020 for(level
= 0; level
< 4; level
++) {
1023 pcReturned
= 0xdeadbeef;
1024 SetLastError(0xdeadbeef);
1025 res
= EnumPortsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
1026 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1028 /* use only a short test, when we test with an invalid level */
1029 if(!level
|| (level
> 2)) {
1030 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1031 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1032 (res
&& (pcReturned
== 0)),
1033 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1034 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1035 level
, res
, GetLastError(), pcReturned
);
1040 /* Level 2 is not supported on NT 3.x */
1041 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
1042 skip("Level %d not supported\n", level
);
1046 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1047 "(%d) returned %d with %d (expected '0' with "
1048 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
1050 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
1051 if (buffer
== NULL
) continue;
1053 pcbNeeded
= 0xdeadbeef;
1054 SetLastError(0xdeadbeef);
1055 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1056 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
1057 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1058 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1060 pcbNeeded
= 0xdeadbeef;
1061 pcReturned
= 0xdeadbeef;
1062 SetLastError(0xdeadbeef);
1063 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
1064 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
1065 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1067 pcbNeeded
= 0xdeadbeef;
1068 SetLastError(0xdeadbeef);
1069 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
1070 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1071 "(%d) returned %d with %d (expected '0' with "
1072 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
1073 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1076 Do not add this test:
1077 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1078 w2k+: RPC_X_NULL_REF_POINTER
1079 NT3.5: ERROR_INVALID_USER_BUFFER
1080 win9x: crash in winspool.drv
1083 SetLastError(0xdeadbeef);
1084 res
= EnumPorts(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
1085 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1086 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
1087 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
1088 "(%d) returned %d with %d (expected '0' with "
1089 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1090 level
, res
, GetLastError());
1093 SetLastError(0xdeadbeef);
1094 res
= EnumPorts(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1095 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1096 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
1097 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
1098 "(%d) returned %d with %d (expected '0' with "
1099 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1100 level
, res
, GetLastError());
1102 HeapFree(GetProcessHeap(), 0, buffer
);
1106 /* ########################### */
1108 static void test_EnumPrinterDrivers(void)
1117 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1118 for(level
= 0; level
< 10; level
++) {
1120 pcReturned
= 0xdeadbeef;
1121 SetLastError(0xdeadbeef);
1122 res
= EnumPrinterDriversA(NULL
, NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
1123 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1125 /* use only a short test, when we test with an invalid level */
1126 if(!level
|| (level
== 7) || (level
> 8)) {
1128 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1129 (res
&& (pcReturned
== 0)),
1130 "(%d) got %u with %u and 0x%x "
1131 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1132 level
, res
, GetLastError(), pcReturned
);
1136 /* some level are not supported in all windows versions */
1137 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
1138 skip("Level %d not supported\n", level
);
1142 ok( ((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) ||
1143 (res
&& (default_printer
== NULL
)),
1144 "(%u) got %u with %u for %s (expected '0' with "
1145 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1146 level
, res
, GetLastError(), default_printer
);
1149 skip("no valid buffer size returned\n");
1153 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
+ 4);
1154 if (buffer
== NULL
) continue;
1156 SetLastError(0xdeadbeef);
1157 pcbNeeded
= 0xdeadbeef;
1158 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1159 ok(res
, "(%u) got %u with %u (expected '!=0')\n", level
, res
, GetLastError());
1160 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1162 /* validate the returned Data here */
1164 LPDRIVER_INFO_2A di
= (LPDRIVER_INFO_2A
) buffer
;
1166 ok( strrchr(di
->pDriverPath
, '\\') != NULL
,
1167 "(%u) got %s for %s (expected a full path)\n",
1168 level
, di
->pDriverPath
, di
->pName
);
1172 SetLastError(0xdeadbeef);
1173 pcReturned
= 0xdeadbeef;
1174 pcbNeeded
= 0xdeadbeef;
1175 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
1176 ok(res
, "(%u) got %u with %u (expected '!=0')\n", level
, res
, GetLastError());
1177 ok(pcbNeeded
== cbBuf
, "(%u) returned %u (expected %u)\n", level
, pcbNeeded
, cbBuf
);
1179 SetLastError(0xdeadbeef);
1180 pcbNeeded
= 0xdeadbeef;
1181 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
1182 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1183 "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1184 level
, res
, GetLastError());
1185 ok(pcbNeeded
== cbBuf
, "(%u) returned %u (expected %u)\n", level
, pcbNeeded
, cbBuf
);
1188 Do not add the next test:
1189 NT: ERROR_INVALID_USER_BUFFER
1190 win9x: crash or 100% CPU
1192 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1195 SetLastError(0xdeadbeef);
1196 pcbNeeded
= 0xdeadbeef;
1197 pcReturned
= 0xdeadbeef;
1198 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
1199 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
1200 "(%u) got %u with %u (expected '!=0' or '0' with "
1201 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1203 pcbNeeded
= 0xdeadbeef;
1204 pcReturned
= 0xdeadbeef;
1205 SetLastError(0xdeadbeef);
1206 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1207 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
1208 "(%u) got %u with %u (expected '!=0' or '0' with "
1209 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1211 HeapFree(GetProcessHeap(), 0, buffer
);
1212 } /* for(level ... */
1215 /* ########################### */
1217 static void test_GetDefaultPrinter(void)
1220 DWORD exact
= DEFAULT_PRINTER_SIZE
;
1222 char buffer
[DEFAULT_PRINTER_SIZE
];
1224 if (!pGetDefaultPrinterA
) return;
1225 /* only supported on NT like OSes starting with win2k */
1227 SetLastError(ERROR_SUCCESS
);
1228 retval
= pGetDefaultPrinterA(buffer
, &exact
);
1229 if (!retval
|| !exact
|| !strlen(buffer
) ||
1230 (ERROR_SUCCESS
!= GetLastError())) {
1231 if ((ERROR_FILE_NOT_FOUND
== GetLastError()) ||
1232 (ERROR_INVALID_NAME
== GetLastError()))
1233 trace("this test requires a default printer to be set\n");
1235 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1236 "function returned %s\n"
1237 "last error 0x%08x\n"
1238 "returned buffer size 0x%08x\n"
1239 "returned buffer content %s\n",
1240 retval
? "true" : "false", GetLastError(), exact
, buffer
);
1244 SetLastError(ERROR_SUCCESS
);
1245 retval
= pGetDefaultPrinterA(NULL
, NULL
);
1246 ok( !retval
, "function result wrong! False expected\n");
1247 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
1248 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1251 SetLastError(ERROR_SUCCESS
);
1252 retval
= pGetDefaultPrinterA(buffer
, NULL
);
1253 ok( !retval
, "function result wrong! False expected\n");
1254 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
1255 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1258 SetLastError(ERROR_SUCCESS
);
1260 retval
= pGetDefaultPrinterA(NULL
, &size
);
1261 ok( !retval
, "function result wrong! False expected\n");
1262 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1263 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1265 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1268 SetLastError(ERROR_SUCCESS
);
1269 size
= DEFAULT_PRINTER_SIZE
;
1270 retval
= pGetDefaultPrinterA(NULL
, &size
);
1271 ok( !retval
, "function result wrong! False expected\n");
1272 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1273 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1275 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1279 retval
= pGetDefaultPrinterA(buffer
, &size
);
1280 ok( !retval
, "function result wrong! False expected\n");
1281 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1282 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1284 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1288 retval
= pGetDefaultPrinterA(buffer
, &size
);
1289 ok( retval
, "function result wrong! True expected\n");
1290 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1294 static void test_GetPrinterDriverDirectory(void)
1296 LPBYTE buffer
= NULL
;
1297 DWORD cbBuf
= 0, pcbNeeded
= 0;
1301 SetLastError(MAGIC_DEAD
);
1302 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
1303 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1304 res
, GetLastError(), cbBuf
);
1306 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1307 ok((res
== 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1308 "returned %d with lasterror=%d (expected '0' with "
1309 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError());
1312 skip("no valid buffer size returned\n");
1316 buffer
= HeapAlloc( GetProcessHeap(), 0, cbBuf
*2);
1317 if (buffer
== NULL
) return ;
1319 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
1320 ok( res
, "expected result != 0, got %d\n", res
);
1321 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1324 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1325 ok( res
, "expected result != 0, got %d\n", res
);
1326 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1329 SetLastError(MAGIC_DEAD
);
1330 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
1331 ok( !res
, "expected result == 0, got %d\n", res
);
1332 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1335 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1336 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1340 Do not add the next test:
1341 XPsp2: crash in this app, when the spooler is not running
1342 NT3.5: ERROR_INVALID_USER_BUFFER
1343 win9x: ERROR_INVALID_PARAMETER
1345 pcbNeeded = MAGIC_DEAD;
1346 SetLastError(MAGIC_DEAD);
1347 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1350 SetLastError(MAGIC_DEAD
);
1351 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
1352 ok( (!res
&& RPC_X_NULL_REF_POINTER
== GetLastError()) || res
,
1353 "expected either result == 0 and "
1354 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1355 "got result %d and last error == %d\n", res
, GetLastError());
1357 SetLastError(MAGIC_DEAD
);
1358 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1359 ok(res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1360 "returned %d with %d (expected '!=0' or '0' with "
1361 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1364 /* with a valid buffer, but level is too large */
1366 SetLastError(MAGIC_DEAD
);
1367 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1369 /* Level not checked in win9x and wine:*/
1370 if((res
!= FALSE
) && buffer
[0])
1372 trace("Level '2' not checked '%s'\n", buffer
);
1376 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1377 "returned %d with lasterror=%d (expected '0' with "
1378 "ERROR_INVALID_LEVEL)\n", res
, GetLastError());
1381 /* printing environments are case insensitive */
1382 /* "Windows 4.0" is valid for win9x and NT */
1384 SetLastError(MAGIC_DEAD
);
1385 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1386 buffer
, cbBuf
*2, &pcbNeeded
);
1388 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1390 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1391 if (buffer
== NULL
) return ;
1393 SetLastError(MAGIC_DEAD
);
1394 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1395 buffer
, cbBuf
*2, &pcbNeeded
);
1398 ok(res
&& buffer
[0], "returned %d with "
1399 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1400 res
, GetLastError(), lstrlenA((char *)buffer
));
1403 SetLastError(MAGIC_DEAD
);
1404 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1405 buffer
, cbBuf
*2, &pcbNeeded
);
1407 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1409 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1410 if (buffer
== NULL
) return ;
1413 SetLastError(MAGIC_DEAD
);
1414 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1415 buffer
, cbBuf
*2, &pcbNeeded
);
1418 /* "Windows NT x86" is invalid for win9x */
1419 ok( (res
&& buffer
[0]) ||
1420 (!res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
1421 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1422 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1423 res
, GetLastError(), lstrlenA((char *)buffer
));
1425 /* A setup program (PDFCreator_0.8.0) use empty strings */
1426 SetLastError(MAGIC_DEAD
);
1427 res
= GetPrinterDriverDirectoryA(empty
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1428 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1430 SetLastError(MAGIC_DEAD
);
1431 res
= GetPrinterDriverDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1432 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1434 SetLastError(MAGIC_DEAD
);
1435 res
= GetPrinterDriverDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1436 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1438 HeapFree( GetProcessHeap(), 0, buffer
);
1443 static void test_GetPrintProcessorDirectory(void)
1445 LPBYTE buffer
= NULL
;
1447 DWORD pcbNeeded
= 0;
1451 SetLastError(0xdeadbeef);
1452 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
1453 /* The deactivated Spooler is caught here on NT3.51 */
1454 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1455 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1456 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1457 res
, GetLastError());
1459 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
1460 if(buffer
== NULL
) return;
1463 SetLastError(0xdeadbeef);
1464 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
1465 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1467 SetLastError(0xdeadbeef);
1469 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1470 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1472 /* Buffer to small */
1474 SetLastError(0xdeadbeef);
1475 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
1476 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1477 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1478 res
, GetLastError());
1482 /* XPsp2: the program will crash here, when the spooler is not running */
1483 /* GetPrinterDriverDirectory has the same bug */
1485 SetLastError(0xdeadbeef);
1486 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, &pcbNeeded
);
1490 SetLastError(0xdeadbeef);
1491 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
1492 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1493 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1494 "returned %d with %d (expected '!= 0' or '0' with "
1495 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1499 SetLastError(0xdeadbeef);
1500 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1501 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1502 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
1503 "returned %d with %d (expected '!= 0' or '0' with "
1504 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
1507 /* with a valid buffer, but level is invalid */
1509 SetLastError(0xdeadbeef);
1510 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1511 if (res
&& buffer
[0])
1513 /* Level is ignored in win9x*/
1514 trace("invalid level (2) was ignored\n");
1518 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1519 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1520 res
, GetLastError());
1523 /* Empty environment is the same as the default environment */
1525 SetLastError(0xdeadbeef);
1526 res
= GetPrintProcessorDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1527 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1529 /* "Windows 4.0" is valid for win9x and NT */
1531 SetLastError(0xdeadbeef);
1532 res
= GetPrintProcessorDirectoryA(NULL
, env_win9x_case
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1533 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1536 /* "Windows NT x86" is invalid for win9x */
1538 SetLastError(0xdeadbeef);
1539 res
= GetPrintProcessorDirectoryA(NULL
, env_x86
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1540 ok( res
|| (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1541 "returned %d with %d (expected '!= 0' or '0' with "
1542 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
1544 /* invalid on all Systems */
1546 SetLastError(0xdeadbeef);
1547 res
= GetPrintProcessorDirectoryA(NULL
, invalid_env
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1548 ok( !res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1549 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1550 res
, GetLastError());
1552 /* Empty servername is the same as the local computer */
1554 SetLastError(0xdeadbeef);
1555 res
= GetPrintProcessorDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1556 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1558 /* invalid on all Systems */
1560 SetLastError(0xdeadbeef);
1561 res
= GetPrintProcessorDirectoryA(server_does_not_exist
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1562 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1563 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1564 res
, GetLastError());
1566 HeapFree(GetProcessHeap(), 0, buffer
);
1571 static void test_OpenPrinter(void)
1573 PRINTER_DEFAULTSA defaults
;
1577 SetLastError(MAGIC_DEAD
);
1578 res
= OpenPrinter(NULL
, NULL
, NULL
);
1579 /* The deactivated Spooler is caught here on NT3.51 */
1580 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1581 ok(!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1582 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1583 res
, GetLastError());
1586 /* Get Handle for the local Printserver (NT only)*/
1587 hprinter
= (HANDLE
) MAGIC_DEAD
;
1588 SetLastError(MAGIC_DEAD
);
1589 res
= OpenPrinter(NULL
, &hprinter
, NULL
);
1590 /* The deactivated Spooler is caught here on XPsp2 */
1591 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1592 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1593 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1594 res
, GetLastError());
1596 ClosePrinter(hprinter
);
1598 defaults
.pDatatype
=NULL
;
1599 defaults
.pDevMode
=NULL
;
1601 defaults
.DesiredAccess
=0;
1602 hprinter
= (HANDLE
) MAGIC_DEAD
;
1603 SetLastError(MAGIC_DEAD
);
1604 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
1605 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1606 if (res
) ClosePrinter(hprinter
);
1608 defaults
.DesiredAccess
=-1;
1609 hprinter
= (HANDLE
) MAGIC_DEAD
;
1610 SetLastError(MAGIC_DEAD
);
1611 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
1613 ok(!res
&& GetLastError() == ERROR_ACCESS_DENIED
,
1614 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1615 res
, GetLastError());
1617 if (res
) ClosePrinter(hprinter
);
1622 if (local_server
!= NULL
) {
1623 hprinter
= (HANDLE
) 0xdeadbeef;
1624 SetLastError(0xdeadbeef);
1625 res
= OpenPrinter(local_server
, &hprinter
, NULL
);
1626 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
1627 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1628 res
, GetLastError());
1629 if(res
) ClosePrinter(hprinter
);
1632 /* Invalid Printername */
1633 hprinter
= (HANDLE
) MAGIC_DEAD
;
1634 SetLastError(MAGIC_DEAD
);
1635 res
= OpenPrinter(illegal_name
, &hprinter
, NULL
);
1636 ok(!res
&& ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1637 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1638 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1639 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1640 if(res
) ClosePrinter(hprinter
);
1642 hprinter
= (HANDLE
) MAGIC_DEAD
;
1643 SetLastError(MAGIC_DEAD
);
1644 res
= OpenPrinter(empty
, &hprinter
, NULL
);
1645 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1647 ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1648 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1649 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1650 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1651 if(res
) ClosePrinter(hprinter
);
1654 /* Get Handle for the default Printer */
1655 if (default_printer
)
1657 hprinter
= (HANDLE
) MAGIC_DEAD
;
1658 SetLastError(MAGIC_DEAD
);
1659 res
= OpenPrinter(default_printer
, &hprinter
, NULL
);
1660 if((!res
) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE
))
1662 trace("The Service 'Spooler' is required for '%s'\n", default_printer
);
1665 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1666 if(res
) ClosePrinter(hprinter
);
1668 SetLastError(MAGIC_DEAD
);
1669 res
= OpenPrinter(default_printer
, NULL
, NULL
);
1670 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1671 ok(res
|| (GetLastError() == ERROR_INVALID_PARAMETER
),
1672 "returned %d with %d (expected '!=0' or '0' with "
1673 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1675 defaults
.pDatatype
=NULL
;
1676 defaults
.pDevMode
=NULL
;
1677 defaults
.DesiredAccess
=0;
1679 hprinter
= (HANDLE
) MAGIC_DEAD
;
1680 SetLastError(MAGIC_DEAD
);
1681 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1682 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1683 "returned %d with %d (expected '!=0' or '0' with "
1684 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1685 if(res
) ClosePrinter(hprinter
);
1687 defaults
.pDatatype
= empty
;
1689 hprinter
= (HANDLE
) MAGIC_DEAD
;
1690 SetLastError(MAGIC_DEAD
);
1691 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1692 /* stop here, when a remote Printserver has no RPC-Service running */
1693 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1694 ok(res
|| ((GetLastError() == ERROR_INVALID_DATATYPE
) ||
1695 (GetLastError() == ERROR_ACCESS_DENIED
)),
1696 "returned %d with %d (expected '!=0' or '0' with: "
1697 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1698 res
, GetLastError());
1699 if(res
) ClosePrinter(hprinter
);
1702 defaults
.pDatatype
=NULL
;
1703 defaults
.DesiredAccess
=PRINTER_ACCESS_USE
;
1705 hprinter
= (HANDLE
) MAGIC_DEAD
;
1706 SetLastError(MAGIC_DEAD
);
1707 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1708 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1709 "returned %d with %d (expected '!=0' or '0' with "
1710 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1711 if(res
) ClosePrinter(hprinter
);
1714 defaults
.DesiredAccess
=PRINTER_ALL_ACCESS
;
1715 hprinter
= (HANDLE
) MAGIC_DEAD
;
1716 SetLastError(MAGIC_DEAD
);
1717 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
1718 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1719 "returned %d with %d (expected '!=0' or '0' with "
1720 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1721 if(res
) ClosePrinter(hprinter
);
1727 static void test_SetDefaultPrinter(void)
1730 DWORD size
= DEFAULT_PRINTER_SIZE
;
1731 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
1732 CHAR org_value
[DEFAULT_PRINTER_SIZE
];
1735 if (!pSetDefaultPrinterA
) return;
1736 /* only supported on win2k and above */
1738 /* backup the original value */
1739 org_value
[0] = '\0';
1740 SetLastError(MAGIC_DEAD
);
1741 res
= GetProfileStringA("windows", "device", NULL
, org_value
, size
);
1743 /* first part: with the default Printer */
1744 SetLastError(MAGIC_DEAD
);
1745 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1747 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1748 /* spooler is running or we have no spooler here*/
1750 /* Not implemented in wine */
1751 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
1752 trace("SetDefaultPrinterA() not implemented yet.\n");
1756 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1757 "returned %d with %d (expected '0' with "
1758 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1760 WriteProfileStringA("windows", "device", org_value
);
1761 SetLastError(MAGIC_DEAD
);
1762 res
= pSetDefaultPrinterA("");
1763 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1764 "returned %d with %d (expected '!=0' or '0' with "
1765 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1767 WriteProfileStringA("windows", "device", org_value
);
1768 SetLastError(MAGIC_DEAD
);
1769 res
= pSetDefaultPrinterA(NULL
);
1770 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1771 "returned %d with %d (expected '!=0' or '0' with "
1772 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1774 WriteProfileStringA("windows", "device", org_value
);
1775 SetLastError(MAGIC_DEAD
);
1776 res
= pSetDefaultPrinterA(default_printer
);
1777 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1778 "returned %d with %d (expected '!=0' or '0' with "
1779 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1782 /* second part: always without a default Printer */
1783 WriteProfileStringA("windows", "device", NULL
);
1784 SetLastError(MAGIC_DEAD
);
1785 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1787 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1788 "returned %d with %d (expected '0' with "
1789 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1791 WriteProfileStringA("windows", "device", NULL
);
1792 SetLastError(MAGIC_DEAD
);
1793 res
= pSetDefaultPrinterA("");
1794 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1795 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1796 "returned %d with %d (expected '!=0' or '0' with "
1797 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1799 WriteProfileStringA("windows", "device", NULL
);
1800 SetLastError(MAGIC_DEAD
);
1801 res
= pSetDefaultPrinterA(NULL
);
1802 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1803 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1804 "returned %d with %d (expected '!=0' or '0' with "
1805 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1807 WriteProfileStringA("windows", "device", NULL
);
1808 SetLastError(MAGIC_DEAD
);
1809 res
= pSetDefaultPrinterA(default_printer
);
1810 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
1811 "returned %d with %d (expected '!=0' or '0' with "
1812 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1814 /* restore the original value */
1815 res
= pSetDefaultPrinterA(default_printer
); /* the nice way */
1816 WriteProfileStringA("windows", "device", org_value
); /* the old way */
1819 SetLastError(MAGIC_DEAD
);
1820 res
= GetProfileStringA("windows", "device", NULL
, buffer
, size
);
1821 ok(!lstrcmpA(org_value
, buffer
), "'%s' (expected '%s')\n", buffer
, org_value
);
1825 /* ########################### */
1827 static void test_XcvDataW_MonitorUI(void)
1831 BYTE buffer
[MAX_PATH
+ 4];
1835 PRINTER_DEFAULTSA pd
;
1837 /* api is not present before w2k */
1838 if (pXcvDataW
== NULL
) return;
1840 pd
.pDatatype
= NULL
;
1842 pd
.DesiredAccess
= SERVER_ACCESS_ADMINISTER
;
1845 SetLastError(0xdeadbeef);
1846 res
= OpenPrinter(xcv_localport
, &hXcv
, &pd
);
1847 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1848 RETURN_ON_ACCESS_DENIED(res
)
1850 ok(res
, "returned %d with %u and handle %p (expected '!= 0')\n", res
, GetLastError(), hXcv
);
1853 /* ask for needed size */
1854 needed
= (DWORD
) 0xdeadbeef;
1855 status
= (DWORD
) 0xdeadbeef;
1856 SetLastError(0xdeadbeef);
1857 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, NULL
, 0, &needed
, &status
);
1858 ok( res
&& (status
== ERROR_INSUFFICIENT_BUFFER
) && (needed
<= MAX_PATH
),
1859 "returned %d with %u and %u for status %u (expected '!= 0' and "
1860 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
1861 res
, GetLastError(), needed
, status
);
1863 if (needed
> MAX_PATH
) {
1865 skip("buffer overflow (%u)\n", needed
);
1868 len
= needed
; /* Size is in bytes */
1870 /* the command is required */
1871 needed
= (DWORD
) 0xdeadbeef;
1872 status
= (DWORD
) 0xdeadbeef;
1873 SetLastError(0xdeadbeef);
1874 res
= pXcvDataW(hXcv
, emptyW
, NULL
, 0, NULL
, 0, &needed
, &status
);
1875 ok( res
&& (status
== ERROR_INVALID_PARAMETER
),
1876 "returned %d with %u and %u for status %u (expected '!= 0' with "
1877 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError(), needed
, status
);
1879 needed
= (DWORD
) 0xdeadbeef;
1880 status
= (DWORD
) 0xdeadbeef;
1881 SetLastError(0xdeadbeef);
1882 res
= pXcvDataW(hXcv
, NULL
, NULL
, 0, buffer
, MAX_PATH
, &needed
, &status
);
1883 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
1884 "returned %d with %u and %u for status %u (expected '0' with "
1885 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
1887 /* "PDWORD needed" is checked before RPC-Errors */
1888 needed
= (DWORD
) 0xdeadbeef;
1889 status
= (DWORD
) 0xdeadbeef;
1890 SetLastError(0xdeadbeef);
1891 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, NULL
, &status
);
1892 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1893 "returned %d with %u and %u for status %u (expected '0' with "
1894 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError(), needed
, status
);
1896 needed
= (DWORD
) 0xdeadbeef;
1897 status
= (DWORD
) 0xdeadbeef;
1898 SetLastError(0xdeadbeef);
1899 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, NULL
, len
, &needed
, &status
);
1900 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
1901 "returned %d with %u and %u for status %u (expected '0' with "
1902 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
1904 needed
= (DWORD
) 0xdeadbeef;
1905 status
= (DWORD
) 0xdeadbeef;
1906 SetLastError(0xdeadbeef);
1907 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, &needed
, NULL
);
1908 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
1909 "returned %d with %u and %u for status %u (expected '0' with "
1910 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
1912 /* off by one: larger */
1913 needed
= (DWORD
) 0xdeadbeef;
1914 status
= (DWORD
) 0xdeadbeef;
1915 SetLastError(0xdeadbeef);
1916 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
+1, &needed
, &status
);
1917 ok( res
&& (status
== ERROR_SUCCESS
),
1918 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1919 "ERROR_SUCCESS)\n", res
, GetLastError(), needed
, status
);
1921 /* off by one: smaller */
1922 /* the buffer is not modified for NT4, w2k, XP */
1923 needed
= (DWORD
) 0xdeadbeef;
1924 status
= (DWORD
) 0xdeadbeef;
1925 SetLastError(0xdeadbeef);
1926 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
-1, &needed
, &status
);
1927 ok( res
&& (status
== ERROR_INSUFFICIENT_BUFFER
),
1928 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1929 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError(), needed
, status
);
1932 /* Normal use. The DLL-Name without a Path is returned */
1933 memset(buffer
, 0, len
);
1934 needed
= (DWORD
) 0xdeadbeef;
1935 status
= (DWORD
) 0xdeadbeef;
1936 SetLastError(0xdeadbeef);
1937 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, &needed
, &status
);
1938 ok( res
&& (status
== ERROR_SUCCESS
),
1939 "returned %d with %u and %u for status %u (expected '!= 0' for status "
1940 "ERROR_SUCCESS)\n", res
, GetLastError(), needed
, status
);
1945 /* ########################### */
1947 static void test_XcvDataW_PortIsValid(void)
1953 PRINTER_DEFAULTSA pd
;
1955 /* api is not present before w2k */
1956 if (pXcvDataW
== NULL
) return;
1958 pd
.pDatatype
= NULL
;
1960 pd
.DesiredAccess
= SERVER_ACCESS_ADMINISTER
;
1963 SetLastError(0xdeadbeef);
1964 res
= OpenPrinter(xcv_localport
, &hXcv
, &pd
);
1966 RETURN_ON_DEACTIVATED_SPOOLER(res
)
1967 RETURN_ON_ACCESS_DENIED(res
)
1969 ok(res
, "returned %d with %u and handle %p (expected '!= 0')\n", res
, GetLastError(), hXcv
);
1973 /* "PDWORD needed" is always required */
1974 needed
= (DWORD
) 0xdeadbeef;
1975 status
= (DWORD
) 0xdeadbeef;
1976 SetLastError(0xdeadbeef);
1977 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt1W
, sizeof(portname_lpt1W
), NULL
, 0, NULL
, &status
);
1978 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1979 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
1980 res
, GetLastError(), needed
, status
);
1982 /* an empty name is not allowed */
1983 needed
= (DWORD
) 0xdeadbeef;
1984 status
= (DWORD
) 0xdeadbeef;
1985 SetLastError(0xdeadbeef);
1986 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) emptyW
, sizeof(emptyW
), NULL
, 0, &needed
, &status
);
1987 ok( res
&& ((status
== ERROR_FILE_NOT_FOUND
) || (status
== ERROR_PATH_NOT_FOUND
)),
1988 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
1989 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
1990 res
, GetLastError(), needed
, status
);
1992 /* a directory is not allowed */
1993 needed
= (DWORD
) 0xdeadbeef;
1994 status
= (DWORD
) 0xdeadbeef;
1995 SetLastError(0xdeadbeef);
1996 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) tempdirW
, (lstrlenW(tempdirW
) + 1) * sizeof(WCHAR
), NULL
, 0, &needed
, &status
);
1997 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
1998 ok( res
&& ((status
== ERROR_PATH_NOT_FOUND
) || (status
== ERROR_ACCESS_DENIED
)),
1999 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2000 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2001 res
, GetLastError(), needed
, status
);
2003 /* more valid well known Ports */
2004 needed
= (DWORD
) 0xdeadbeef;
2005 status
= (DWORD
) 0xdeadbeef;
2006 SetLastError(0xdeadbeef);
2007 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt1W
, sizeof(portname_lpt1W
), NULL
, 0, &needed
, &status
);
2008 ok( res
&& (status
== ERROR_SUCCESS
),
2009 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2010 res
, GetLastError(), needed
, status
);
2012 needed
= (DWORD
) 0xdeadbeef;
2013 status
= (DWORD
) 0xdeadbeef;
2014 SetLastError(0xdeadbeef);
2015 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt2W
, sizeof(portname_lpt2W
), NULL
, 0, &needed
, &status
);
2016 ok( res
&& (status
== ERROR_SUCCESS
),
2017 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2018 res
, GetLastError(), needed
, status
);
2020 needed
= (DWORD
) 0xdeadbeef;
2021 status
= (DWORD
) 0xdeadbeef;
2022 SetLastError(0xdeadbeef);
2023 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_com1W
, sizeof(portname_com1W
), NULL
, 0, &needed
, &status
);
2024 ok( res
&& (status
== ERROR_SUCCESS
),
2025 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2026 res
, GetLastError(), needed
, status
);
2028 needed
= (DWORD
) 0xdeadbeef;
2029 status
= (DWORD
) 0xdeadbeef;
2030 SetLastError(0xdeadbeef);
2031 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_com2W
, sizeof(portname_com2W
), NULL
, 0, &needed
, &status
);
2032 ok( res
&& (status
== ERROR_SUCCESS
),
2033 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2034 res
, GetLastError(), needed
, status
);
2036 needed
= (DWORD
) 0xdeadbeef;
2037 status
= (DWORD
) 0xdeadbeef;
2038 SetLastError(0xdeadbeef);
2039 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_fileW
, sizeof(portname_fileW
), NULL
, 0, &needed
, &status
);
2040 ok( res
&& (status
== ERROR_SUCCESS
),
2041 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2042 res
, GetLastError(), needed
, status
);
2045 /* a normal, writable file is allowed */
2046 needed
= (DWORD
) 0xdeadbeef;
2047 status
= (DWORD
) 0xdeadbeef;
2048 SetLastError(0xdeadbeef);
2049 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) tempfileW
, (lstrlenW(tempfileW
) + 1) * sizeof(WCHAR
), NULL
, 0, &needed
, &status
);
2050 ok( res
&& (status
== ERROR_SUCCESS
),
2051 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2052 res
, GetLastError(), needed
, status
);
2057 /* ########################### */
2059 static void test_GetPrinterDriver(void)
2065 DWORD needed
, filled
;
2067 if (!default_printer
)
2069 skip("There is no default printer installed\n");
2074 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
2077 skip("Unable to open the default printer (%s)\n", default_printer
);
2080 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
2082 for (level
= -1; level
<= 7; level
++)
2084 SetLastError(0xdeadbeef);
2086 ret
= GetPrinterDriver(hprn
, NULL
, level
, NULL
, 0, &needed
);
2087 ok(!ret
, "level %d: GetPrinterDriver should fail\n", level
);
2088 if (level
>= 1 && level
<= 6)
2090 /* Not all levels are supported on all Windows-Versions */
2091 if(GetLastError() == ERROR_INVALID_LEVEL
) continue;
2092 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %d\n", GetLastError());
2093 ok(needed
> 0,"not expected needed buffer size %d\n", needed
);
2097 /* ERROR_OUTOFMEMORY found on win9x */
2098 ok( ((GetLastError() == ERROR_INVALID_LEVEL
) ||
2099 (GetLastError() == ERROR_OUTOFMEMORY
)),
2100 "%d: returned %d with %d (expected '0' with: "
2101 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2102 level
, ret
, GetLastError());
2103 /* needed is modified in win9x. The modified Value depends on the
2104 default Printer. testing for "needed == (DWORD)-1" will fail */
2108 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2110 SetLastError(0xdeadbeef);
2112 ret
= GetPrinterDriver(hprn
, NULL
, level
, buf
, needed
, &filled
);
2113 ok(ret
, "level %d: GetPrinterDriver error %d\n", level
, GetLastError());
2114 ok(needed
== filled
, "needed %d != filled %d\n", needed
, filled
);
2118 DRIVER_INFO_2
*di_2
= (DRIVER_INFO_2
*)buf
;
2119 DWORD calculated
= sizeof(*di_2
);
2121 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2122 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
2123 ok( (di_2
->cVersion
<= 3) ||
2124 (di_2
->cVersion
== 0x0400), "di_2->cVersion = %d\n", di_2
->cVersion
);
2125 ok(di_2
->pName
!= NULL
, "not expected NULL ptr\n");
2126 ok(di_2
->pEnvironment
!= NULL
, "not expected NULL ptr\n");
2127 ok(di_2
->pDriverPath
!= NULL
, "not expected NULL ptr\n");
2128 ok(di_2
->pDataFile
!= NULL
, "not expected NULL ptr\n");
2129 ok(di_2
->pConfigFile
!= NULL
, "not expected NULL ptr\n");
2131 trace("cVersion %d\n", di_2
->cVersion
);
2132 trace("pName %s\n", di_2
->pName
);
2133 calculated
+= strlen(di_2
->pName
) + 1;
2134 trace("pEnvironment %s\n", di_2
->pEnvironment
);
2135 calculated
+= strlen(di_2
->pEnvironment
) + 1;
2136 trace("pDriverPath %s\n", di_2
->pDriverPath
);
2137 calculated
+= strlen(di_2
->pDriverPath
) + 1;
2138 trace("pDataFile %s\n", di_2
->pDataFile
);
2139 calculated
+= strlen(di_2
->pDataFile
) + 1;
2140 trace("pConfigFile %s\n", di_2
->pConfigFile
);
2141 calculated
+= strlen(di_2
->pConfigFile
) + 1;
2143 /* XP allocates memory for both ANSI and unicode names */
2144 ok(filled
>= calculated
,"calculated %d != filled %d\n", calculated
, filled
);
2147 HeapFree(GetProcessHeap(), 0, buf
);
2150 SetLastError(0xdeadbeef);
2151 ret
= ClosePrinter(hprn
);
2152 ok(ret
, "ClosePrinter error %d\n", GetLastError());
2155 static void test_DEVMODE(const DEVMODE
*dm
, LONG dmSize
, LPCSTR exp_prn_name
)
2157 /* On NT3.51, some fields in DEVMODE are empty/zero
2158 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2159 We skip the Tests on this Platform */
2160 if (dm
->dmSpecVersion
|| dm
->dmDriverVersion
|| dm
->dmDriverExtra
) {
2161 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2162 ok(!strncmp(exp_prn_name
, (LPCSTR
)dm
->dmDeviceName
, CCHDEVICENAME
-1),
2163 "expected '%s', got '%s'\n", exp_prn_name
, dm
->dmDeviceName
);
2164 ok(dm
->dmSize
+ dm
->dmDriverExtra
== dmSize
,
2165 "%u != %d\n", dm
->dmSize
+ dm
->dmDriverExtra
, dmSize
);
2167 trace("dmFields %08x\n", dm
->dmFields
);
2170 static void test_DocumentProperties(void)
2176 if (!default_printer
)
2178 skip("There is no default printer installed\n");
2183 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
2186 skip("Unable to open the default printer (%s)\n", default_printer
);
2189 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
2191 dm_size
= DocumentProperties(0, hprn
, NULL
, NULL
, NULL
, 0);
2192 trace("DEVMODE required size %d\n", dm_size
);
2193 ok(dm_size
>= sizeof(DEVMODE
), "unexpected DocumentProperties ret value %d\n", dm_size
);
2195 dm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dm_size
);
2197 ret
= DocumentProperties(0, hprn
, NULL
, dm
, dm
, DM_OUT_BUFFER
);
2198 ok(ret
== IDOK
, "DocumentProperties ret value %d != expected IDOK\n", ret
);
2200 test_DEVMODE(dm
, dm_size
, default_printer
);
2202 HeapFree(GetProcessHeap(), 0, dm
);
2204 SetLastError(0xdeadbeef);
2205 ret
= ClosePrinter(hprn
);
2206 ok(ret
, "ClosePrinter error %d\n", GetLastError());
2209 static void test_EnumPrinters(void)
2211 DWORD neededA
, neededW
, num
;
2214 SetLastError(0xdeadbeef);
2216 ret
= EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededA
, &num
);
2217 RETURN_ON_DEACTIVATED_SPOOLER(ret
)
2220 /* We have 1 or more printers */
2221 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
2222 ok(neededA
> 0, "Expected neededA to show the number of needed bytes\n");
2226 /* We don't have any printers defined */
2227 ok(GetLastError() == S_OK
, "gle %d\n", GetLastError());
2228 ok(neededA
== 0, "Expected neededA to be zero\n");
2230 ok(num
== 0, "num %d\n", num
);
2232 SetLastError(0xdeadbeef);
2234 ret
= EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededW
, &num
);
2235 /* EnumPrintersW is not supported on all platforms */
2236 if (!ret
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
2238 win_skip("EnumPrintersW is not implemented\n");
2244 /* We have 1 or more printers */
2245 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
2246 ok(neededW
> 0, "Expected neededW to show the number of needed bytes\n");
2250 /* We don't have any printers defined */
2251 ok(GetLastError() == S_OK
, "gle %d\n", GetLastError());
2252 ok(neededW
== 0, "Expected neededW to be zero\n");
2254 ok(num
== 0, "num %d\n", num
);
2256 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2257 to hold the buffer returned by EnumPrintersW */
2258 ok(neededA
== neededW
, "neededA %d neededW %d\n", neededA
, neededW
);
2261 static void test_DeviceCapabilities(void)
2264 BOOL (WINAPI
*pPrintDlgA
)(PRINTDLGA
*);
2268 const char *driver
, *device
, *port
;
2276 INT n_papers
, n_paper_size
, n_paper_names
, n_copies
, ret
;
2279 hComdlg32
= LoadLibrary("comdlg32.dll");
2281 pPrintDlgA
= (void *)GetProcAddress(hComdlg32
, "PrintDlgA");
2284 memset(&prn_dlg
, 0, sizeof(prn_dlg
));
2285 prn_dlg
.lStructSize
= sizeof(prn_dlg
);
2286 prn_dlg
.Flags
= PD_RETURNDEFAULT
;
2287 ret
= pPrintDlgA(&prn_dlg
);
2288 FreeLibrary(hComdlg32
);
2291 skip("PrintDlg returned no default printer\n");
2294 ok(prn_dlg
.hDevMode
!= 0, "PrintDlg returned hDevMode == NULL\n");
2295 ok(prn_dlg
.hDevNames
!= 0, "PrintDlg returned hDevNames == NULL\n");
2297 dm
= GlobalLock(prn_dlg
.hDevMode
);
2298 ok(dm
!= NULL
, "GlobalLock(prn_dlg.hDevMode) failed\n");
2299 trace("dmDeviceName \"%s\"\n", dm
->dmDeviceName
);
2301 dn
= GlobalLock(prn_dlg
.hDevNames
);
2302 ok(dn
!= NULL
, "GlobalLock(prn_dlg.hDevNames) failed\n");
2303 ok(dn
->wDriverOffset
, "expected not 0 wDriverOffset\n");
2304 ok(dn
->wDeviceOffset
, "expected not 0 wDeviceOffset\n");
2305 ok(dn
->wOutputOffset
, "expected not 0 wOutputOffset\n");
2306 ok(dn
->wDefault
== DN_DEFAULTPRN
, "expected DN_DEFAULTPRN got %x\n", dn
->wDefault
);
2307 driver
= (const char *)dn
+ dn
->wDriverOffset
;
2308 device
= (const char *)dn
+ dn
->wDeviceOffset
;
2309 port
= (const char *)dn
+ dn
->wOutputOffset
;
2310 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver
, device
, port
);
2312 test_DEVMODE(dm
, dm
->dmSize
+ dm
->dmDriverExtra
, device
);
2314 n_papers
= DeviceCapabilities(device
, port
, DC_PAPERS
, NULL
, NULL
);
2315 ok(n_papers
> 0, "DeviceCapabilities DC_PAPERS failed\n");
2316 papers
= HeapAlloc(GetProcessHeap(), 0, sizeof(*papers
) * n_papers
);
2317 ret
= DeviceCapabilities(device
, port
, DC_PAPERS
, (LPSTR
)papers
, NULL
);
2318 ok(ret
== n_papers
, "expected %d, got %d\n", n_papers
, ret
);
2320 for (ret
= 0; ret
< n_papers
; ret
++)
2321 trace("papers[%d] = %d\n", ret
, papers
[ret
]);
2323 HeapFree(GetProcessHeap(), 0, papers
);
2325 n_paper_size
= DeviceCapabilities(device
, port
, DC_PAPERSIZE
, NULL
, NULL
);
2326 ok(n_paper_size
> 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
2327 ok(n_paper_size
== n_papers
, "n_paper_size %d != n_papers %d\n", n_paper_size
, n_papers
);
2328 paper_size
= HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size
) * n_paper_size
);
2329 ret
= DeviceCapabilities(device
, port
, DC_PAPERSIZE
, (LPSTR
)paper_size
, NULL
);
2330 ok(ret
== n_paper_size
, "expected %d, got %d\n", n_paper_size
, ret
);
2332 for (ret
= 0; ret
< n_paper_size
; ret
++)
2333 trace("paper_size[%d] = %d x %d\n", ret
, paper_size
[ret
].x
, paper_size
[ret
].y
);
2335 HeapFree(GetProcessHeap(), 0, paper_size
);
2337 n_paper_names
= DeviceCapabilities(device
, port
, DC_PAPERNAMES
, NULL
, NULL
);
2338 ok(n_paper_names
> 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
2339 ok(n_paper_names
== n_papers
, "n_paper_names %d != n_papers %d\n", n_paper_names
, n_papers
);
2340 paper_name
= HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name
) * n_paper_names
);
2341 ret
= DeviceCapabilities(device
, port
, DC_PAPERNAMES
, (LPSTR
)paper_name
, NULL
);
2342 ok(ret
== n_paper_names
, "expected %d, got %d\n", n_paper_names
, ret
);
2344 for (ret
= 0; ret
< n_paper_names
; ret
++)
2345 trace("paper_name[%u] = %s\n", ret
, paper_name
[ret
].name
);
2347 HeapFree(GetProcessHeap(), 0, paper_name
);
2349 n_copies
= DeviceCapabilities(device
, port
, DC_COPIES
, NULL
, dm
);
2350 ok(n_copies
> 0, "DeviceCapabilities DC_COPIES failed\n");
2351 trace("n_copies = %d\n", n_copies
);
2353 /* these capabilities not available on all printer drivers */
2356 ret
= DeviceCapabilities(device
, port
, DC_MAXEXTENT
, NULL
, NULL
);
2357 ok(ret
!= -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
2358 ext
= MAKEPOINTS(ret
);
2359 trace("max ext = %d x %d\n", ext
.x
, ext
.y
);
2361 ret
= DeviceCapabilities(device
, port
, DC_MINEXTENT
, NULL
, NULL
);
2362 ok(ret
!= -1, "DeviceCapabilities DC_MINEXTENT failed\n");
2363 ext
= MAKEPOINTS(ret
);
2364 trace("min ext = %d x %d\n", ext
.x
, ext
.y
);
2367 fields
= DeviceCapabilities(device
, port
, DC_FIELDS
, NULL
, NULL
);
2368 ok(fields
!= (DWORD
)-1, "DeviceCapabilities DC_FIELDS failed\n");
2370 ok(fields
== (dm
->dmFields
| DM_FORMNAME
),
2371 "fields %x != (dm->dmFields | DM_FORMNAME) %x\n", fields
, dm
->dmFields
);
2373 GlobalUnlock(prn_dlg
.hDevMode
);
2374 GlobalFree(prn_dlg
.hDevMode
);
2375 GlobalUnlock(prn_dlg
.hDevNames
);
2376 GlobalFree(prn_dlg
.hDevNames
);
2381 hwinspool
= GetModuleHandleA("winspool.drv");
2382 pGetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "GetDefaultPrinterA");
2383 pSetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "SetDefaultPrinterA");
2384 pXcvDataW
= (void *) GetProcAddress(hwinspool
, "XcvDataW");
2385 pAddPortExA
= (void *) GetProcAddress(hwinspool
, "AddPortExA");
2387 find_default_printer();
2388 find_local_server();
2394 test_ConfigurePort();
2395 test_DeleteMonitor();
2397 test_DeviceCapabilities();
2398 test_DocumentProperties();
2399 test_EnumForms(NULL
);
2400 if (default_printer
) test_EnumForms(default_printer
);
2401 test_EnumMonitors();
2403 test_EnumPrinterDrivers();
2404 test_EnumPrinters();
2405 test_GetDefaultPrinter();
2406 test_GetPrinterDriverDirectory();
2407 test_GetPrintProcessorDirectory();
2409 test_GetPrinterDriver();
2410 test_SetDefaultPrinter();
2411 test_XcvDataW_MonitorUI();
2412 test_XcvDataW_PortIsValid();
2414 /* Cleanup our temporary file */
2415 DeleteFileA(tempfileA
);