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 defaultspooldirectory
[] = "DefaultSpoolDirectory";
42 static CHAR does_not_exist_dll
[]= "does_not_exist.dll";
43 static CHAR does_not_exist
[] = "does_not_exist";
44 static CHAR empty
[] = "";
45 static CHAR env_x64
[] = "Windows x64";
46 static CHAR env_x86
[] = "Windows NT x86";
47 static CHAR env_win9x_case
[] = "windowS 4.0";
48 static CHAR illegal_name
[] = "illegal,name";
49 static CHAR invalid_env
[] = "invalid_env";
50 static CHAR LocalPortA
[] = "Local Port";
51 static CHAR portname_com1
[] = "COM1:";
52 static CHAR portname_file
[] = "FILE:";
53 static CHAR portname_lpt1
[] = "LPT1:";
54 static CHAR server_does_not_exist
[] = "\\\\does_not_exist";
55 static CHAR version_dll
[] = "version.dll";
56 static CHAR winetest
[] = "winetest";
57 static CHAR xcv_localport
[] = ",XcvMonitor Local Port";
59 static const WCHAR cmd_MonitorUIW
[] = {'M','o','n','i','t','o','r','U','I',0};
60 static const WCHAR cmd_PortIsValidW
[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
61 static WCHAR emptyW
[] = {0};
63 static WCHAR portname_com1W
[] = {'C','O','M','1',':',0};
64 static WCHAR portname_com2W
[] = {'C','O','M','2',':',0};
65 static WCHAR portname_fileW
[] = {'F','I','L','E',':',0};
66 static WCHAR portname_lpt1W
[] = {'L','P','T','1',':',0};
67 static WCHAR portname_lpt2W
[] = {'L','P','T','2',':',0};
69 static HANDLE hwinspool
;
70 static BOOL (WINAPI
* pAddPortExA
)(LPSTR
, DWORD
, LPBYTE
, LPSTR
);
71 static BOOL (WINAPI
* pEnumPrinterDriversW
)(LPWSTR
, LPWSTR
, DWORD
, LPBYTE
, DWORD
, LPDWORD
, LPDWORD
);
72 static BOOL (WINAPI
* pGetDefaultPrinterA
)(LPSTR
, LPDWORD
);
73 static DWORD (WINAPI
* pGetPrinterDataExA
)(HANDLE
, LPCSTR
, LPCSTR
, LPDWORD
, LPBYTE
, DWORD
, LPDWORD
);
74 static BOOL (WINAPI
* pGetPrinterDriverW
)(HANDLE
, LPWSTR
, DWORD
, LPBYTE
, DWORD
, LPDWORD
);
75 static BOOL (WINAPI
* pGetPrinterW
)(HANDLE
, DWORD
, LPBYTE
, DWORD
, LPDWORD
);
76 static BOOL (WINAPI
* pSetDefaultPrinterA
)(LPCSTR
);
77 static DWORD (WINAPI
* pXcvDataW
)(HANDLE
, LPCWSTR
, PBYTE
, DWORD
, PBYTE
, DWORD
, PDWORD
, PDWORD
);
78 static BOOL (WINAPI
* pIsValidDevmodeW
)(PDEVMODEW
, SIZE_T
);
81 /* ################################ */
83 struct monitor_entry
{
88 static LPSTR default_printer
= NULL
;
89 static LPSTR local_server
= NULL
;
90 static LPSTR tempdirA
= NULL
;
91 static LPSTR tempfileA
= NULL
;
92 static LPWSTR tempdirW
= NULL
;
93 static LPWSTR tempfileW
= NULL
;
95 static BOOL
is_spooler_deactivated(DWORD res
, DWORD lasterror
)
97 if (!res
&& lasterror
== RPC_S_SERVER_UNAVAILABLE
)
99 static int deactivated_spooler_reported
= 0;
100 if (!deactivated_spooler_reported
)
102 deactivated_spooler_reported
= 1;
103 skip("The service 'Spooler' is required for many tests\n");
110 static BOOL
is_access_denied(DWORD res
, DWORD lasterror
)
112 if (!res
&& lasterror
== ERROR_ACCESS_DENIED
)
114 static int access_denied_reported
= 0;
115 if (!access_denied_reported
)
117 access_denied_reported
= 1;
118 skip("More access rights are required for many tests\n");
125 static BOOL on_win9x
= FALSE
;
127 static BOOL
check_win9x(void)
131 SetLastError(0xdeadbeef);
132 pGetPrinterW(NULL
, 0, NULL
, 0, NULL
);
133 return (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
);
141 static void find_default_printer(VOID
)
143 static char buffer
[DEFAULT_PRINTER_SIZE
];
148 if ((default_printer
== NULL
) && (pGetDefaultPrinterA
))
151 needed
= sizeof(buffer
);
152 res
= pGetDefaultPrinterA(buffer
, &needed
);
153 if(res
) default_printer
= buffer
;
154 trace("default_printer: '%s'\n", default_printer
? default_printer
: "(null)");
156 if (default_printer
== NULL
)
160 /* NT 3.x and above */
161 if (RegOpenKeyExA(HKEY_CURRENT_USER
,
162 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
163 0, KEY_QUERY_VALUE
, &hwindows
) == NO_ERROR
) {
165 needed
= sizeof(buffer
);
166 if (RegQueryValueExA(hwindows
, "device", NULL
, &type
, (LPBYTE
)buffer
, &needed
) == NO_ERROR
) {
167 ptr
= strchr(buffer
, ',');
170 default_printer
= buffer
;
173 RegCloseKey(hwindows
);
175 trace("default_printer: '%s'\n", default_printer
? default_printer
: "(null)");
177 if (default_printer
== NULL
)
180 needed
= sizeof(buffer
);
181 res
= GetProfileStringA("windows", "device", "*", buffer
, needed
);
183 ptr
= strchr(buffer
, ',');
186 default_printer
= buffer
;
189 trace("default_printer: '%s'\n", default_printer
? default_printer
: "(null)");
194 static struct monitor_entry
* find_installed_monitor(void)
196 MONITOR_INFO_2A mi2a
;
197 static struct monitor_entry
* entry
= NULL
;
201 static struct monitor_entry monitor_table
[] = {
202 {env_win9x_case
, "localspl.dll"},
203 {env_x86
, "localspl.dll"},
204 {env_x64
, "localspl.dll"},
205 {env_win9x_case
, "localmon.dll"},
206 {env_x86
, "localmon.dll"},
207 {env_win9x_case
, "tcpmon.dll"},
208 {env_x86
, "tcpmon.dll"},
209 {env_win9x_case
, "usbmon.dll"},
210 {env_x86
, "usbmon.dll"},
211 {env_win9x_case
, "mspp32.dll"},
212 {env_x86
, "win32spl.dll"},
213 {env_x86
, "redmonnt.dll"},
214 {env_x86
, "redmon35.dll"},
215 {env_win9x_case
, "redmon95.dll"},
216 {env_x86
, "pdfcmnnt.dll"},
217 {env_win9x_case
, "pdfcmn95.dll"},
220 if (entry
) return entry
;
222 num_tests
= (sizeof(monitor_table
)/sizeof(struct monitor_entry
));
225 DeleteMonitorA(NULL
, env_x64
, winetest
);
226 DeleteMonitorA(NULL
, env_x86
, winetest
);
227 DeleteMonitorA(NULL
, env_win9x_case
, winetest
);
229 /* find a usable monitor from the table */
230 mi2a
.pName
= winetest
;
231 while ((entry
== NULL
) && (i
< num_tests
)) {
232 entry
= &monitor_table
[i
];
234 mi2a
.pEnvironment
= entry
->env
;
235 mi2a
.pDLLName
= entry
->dllname
;
237 if (AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
)) {
239 trace("using '%s', '%s'\n", entry
->env
, entry
->dllname
);
240 DeleteMonitorA(NULL
, entry
->env
, winetest
);
251 /* ########################### */
253 static void find_local_server(VOID
)
255 static char buffer
[MAX_PATH
];
259 size
= sizeof(buffer
) - 3 ;
264 SetLastError(0xdeadbeef);
265 res
= GetComputerNameA(&buffer
[2], &size
);
266 trace("returned %d with %d and %d: '%s'\n", res
, GetLastError(), size
, buffer
);
268 ok( res
!= 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
269 res
, GetLastError(), size
, buffer
);
271 if (res
) local_server
= buffer
;
274 /* ########################### */
276 static void find_tempfile(VOID
)
278 static CHAR buffer_dirA
[MAX_PATH
];
279 static CHAR buffer_fileA
[MAX_PATH
];
280 static WCHAR buffer_dirW
[MAX_PATH
];
281 static WCHAR buffer_fileW
[MAX_PATH
];
285 memset(buffer_dirA
, 0, MAX_PATH
- 1);
286 buffer_dirA
[MAX_PATH
- 1] = '\0';
287 SetLastError(0xdeadbeef);
288 res
= GetTempPathA(MAX_PATH
, buffer_dirA
);
289 ok(res
, "returned %u with %u and '%s' (expected '!= 0')\n", res
, GetLastError(), buffer_dirA
);
290 if (res
== 0) return;
292 memset(buffer_fileA
, 0, MAX_PATH
- 1);
293 buffer_fileA
[MAX_PATH
- 1] = '\0';
294 SetLastError(0xdeadbeef);
295 res
= GetTempFileNameA(buffer_dirA
, winetest
, 0, buffer_fileA
);
296 ok(res
, "returned %u with %u and '%s' (expected '!= 0')\n", res
, GetLastError(), buffer_fileA
);
297 if (res
== 0) return;
299 SetLastError(0xdeadbeef);
300 resint
= MultiByteToWideChar(CP_ACP
, 0, buffer_dirA
, -1, buffer_dirW
, MAX_PATH
);
301 ok(res
, "returned %u with %u (expected '!= 0')\n", resint
, GetLastError());
302 if (resint
== 0) return;
304 SetLastError(0xdeadbeef);
305 resint
= MultiByteToWideChar(CP_ACP
, 0, buffer_fileA
, -1, buffer_fileW
, MAX_PATH
);
306 ok(res
, "returned %u with %u (expected '!= 0')\n", resint
, GetLastError());
307 if (resint
== 0) return;
309 tempdirA
= buffer_dirA
;
310 tempfileA
= buffer_fileA
;
311 tempdirW
= buffer_dirW
;
312 tempfileW
= buffer_fileW
;
313 trace("tempfile: '%s'\n", tempfileA
);
316 /* ########################### */
318 static void test_AddMonitor(void)
320 MONITOR_INFO_2A mi2a
;
321 struct monitor_entry
* entry
= NULL
;
324 entry
= find_installed_monitor();
326 SetLastError(MAGIC_DEAD
);
327 res
= AddMonitorA(NULL
, 1, NULL
);
328 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
329 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
330 res
, GetLastError());
332 SetLastError(MAGIC_DEAD
);
333 res
= AddMonitorA(NULL
, 3, NULL
);
334 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
335 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
336 res
, GetLastError());
340 /* This test crashes win9x on vmware (works with win9x on qemu 0.8.1) */
341 SetLastError(MAGIC_DEAD
);
342 res
= AddMonitorA(NULL
, 2, NULL
);
343 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
345 ((GetLastError() == MAGIC_DEAD
) ||
346 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
347 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
348 "ERROR_PRIVILEGE_NOT_HELD)\n", res
, GetLastError());
351 ZeroMemory(&mi2a
, sizeof(MONITOR_INFO_2A
));
352 SetLastError(MAGIC_DEAD
);
353 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
354 if (is_spooler_deactivated(res
, GetLastError())) return;
355 if (is_access_denied(res
, GetLastError())) return;
357 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
358 ok(!res
&& ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
359 (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
360 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
361 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
364 skip("No usable Monitor found\n");
370 /* The test is deactivated, because when mi2a.pName is NULL, the subkey
371 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
372 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
373 is created on win9x and we do not want to hit this bug here. */
375 mi2a
.pEnvironment
= entry
->env
;
376 SetLastError(MAGIC_DEAD
);
377 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
378 ok(res
, "AddMonitor error %d\n", GetLastError());
379 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
382 mi2a
.pEnvironment
= entry
->env
;
384 SetLastError(MAGIC_DEAD
);
385 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
386 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
388 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
389 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
390 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
391 "ERROR_PRIVILEGE_NOT_HELD)\n",
392 res
, GetLastError());
394 mi2a
.pName
= winetest
;
395 SetLastError(MAGIC_DEAD
);
396 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
397 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
399 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
400 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
401 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
402 "ERROR_PRIVILEGE_NOT_HELD)\n",
403 res
, GetLastError());
405 mi2a
.pDLLName
= empty
;
406 SetLastError(MAGIC_DEAD
);
407 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
408 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
409 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
410 res
, GetLastError());
412 mi2a
.pDLLName
= does_not_exist_dll
;
413 SetLastError(MAGIC_DEAD
);
414 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
415 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
417 ((GetLastError() == ERROR_MOD_NOT_FOUND
) ||
418 (GetLastError() == ERROR_INVALID_PARAMETER
)),
419 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
420 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
422 mi2a
.pDLLName
= version_dll
;
423 SetLastError(MAGIC_DEAD
);
424 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
425 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
427 ((GetLastError() == ERROR_PROC_NOT_FOUND
) ||
428 (GetLastError() == ERROR_INVALID_PARAMETER
)),
429 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
430 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
431 if (res
) DeleteMonitorA(NULL
, entry
->env
, winetest
);
433 /* Test AddMonitor with real options */
434 mi2a
.pDLLName
= entry
->dllname
;
435 SetLastError(MAGIC_DEAD
);
436 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
437 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
439 /* add a monitor twice */
440 SetLastError(MAGIC_DEAD
);
441 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
442 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
444 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED
) ||
445 (GetLastError() == ERROR_ALREADY_EXISTS
)),
446 "returned %d with %d (expected '0' with: "
447 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
448 res
, GetLastError());
450 DeleteMonitorA(NULL
, entry
->env
, winetest
);
451 SetLastError(MAGIC_DEAD
);
452 res
= AddMonitorA(empty
, 2, (LPBYTE
) &mi2a
);
453 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
456 DeleteMonitorA(NULL
, entry
->env
, winetest
);
460 /* ########################### */
462 static void test_AddPort(void)
466 SetLastError(0xdeadbeef);
467 res
= AddPortA(NULL
, 0, NULL
);
468 if (is_spooler_deactivated(res
, GetLastError())) return;
469 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
470 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
471 (GetLastError() == ERROR_INVALID_PARAMETER
)),
472 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
473 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
476 SetLastError(0xdeadbeef);
477 res
= AddPortA(NULL
, 0, empty
);
478 /* Allowed only for (Printer-)Administrators */
479 if (is_access_denied(res
, GetLastError())) return;
481 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
482 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
483 (GetLastError() == ERROR_INVALID_PARAMETER
)),
484 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
485 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
488 SetLastError(0xdeadbeef);
489 res
= AddPortA(NULL
, 0, does_not_exist
);
490 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
491 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
492 (GetLastError() == ERROR_INVALID_PARAMETER
)),
493 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
494 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
498 /* ########################### */
500 static void test_AddPortEx(void)
507 win_skip("AddPortEx not supported\n");
511 /* start test with a clean system */
512 DeletePortA(NULL
, 0, tempfileA
);
514 pi
.pPortName
= tempfileA
;
515 SetLastError(0xdeadbeef);
516 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
517 if (is_spooler_deactivated(res
, GetLastError())) return;
519 /* Allowed only for (Printer-)Administrators.
520 W2K+XP: ERROR_INVALID_PARAMETER */
521 if (!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
)) {
522 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
525 ok( res
, "got %u with %u (expected '!= 0')\n", res
, GetLastError());
527 /* add a port that already exists */
528 SetLastError(0xdeadbeef);
529 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
530 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
531 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
532 res
, GetLastError());
533 DeletePortA(NULL
, 0, tempfileA
);
536 /* the Monitorname must match */
537 SetLastError(0xdeadbeef);
538 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, NULL
);
539 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
540 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
541 res
, GetLastError());
542 if (res
) DeletePortA(NULL
, 0, tempfileA
);
544 SetLastError(0xdeadbeef);
545 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, empty
);
546 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
547 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
548 res
, GetLastError());
549 if (res
) DeletePortA(NULL
, 0, tempfileA
);
551 SetLastError(0xdeadbeef);
552 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, does_not_exist
);
553 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
554 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
555 res
, GetLastError());
556 if (res
) DeletePortA(NULL
, 0, tempfileA
);
559 /* We need a Portname */
560 SetLastError(0xdeadbeef);
561 res
= pAddPortExA(NULL
, 1, NULL
, LocalPortA
);
562 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
563 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
564 res
, GetLastError());
567 SetLastError(0xdeadbeef);
568 res
= pAddPortExA(NULL
, 1, (LPBYTE
) &pi
, LocalPortA
);
569 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
570 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
571 res
, GetLastError());
572 if (res
) DeletePortA(NULL
, 0, tempfileA
);
575 /* level 2 is documented as supported for Printmonitors,
576 but that is not supported for "Local Port" (localspl.dll) and
577 AddPortEx fails with ERROR_INVALID_LEVEL */
579 pi
.pPortName
= tempfileA
;
580 pi
.pMonitorName
= LocalPortA
;
581 pi
.pDescription
= winetest
;
582 pi
.fPortType
= PORT_TYPE_WRITE
;
584 SetLastError(0xdeadbeef);
585 res
= pAddPortExA(NULL
, 2, (LPBYTE
) &pi
, LocalPortA
);
586 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
587 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
588 res
, GetLastError());
589 if (res
) DeletePortA(NULL
, 0, tempfileA
);
593 SetLastError(0xdeadbeef);
594 res
= pAddPortExA(NULL
, 0, (LPBYTE
) &pi
, LocalPortA
);
595 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
596 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
597 res
, GetLastError());
599 SetLastError(0xdeadbeef);
600 res
= pAddPortExA(NULL
, 3, (LPBYTE
) &pi
, LocalPortA
);
601 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
602 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
603 res
, GetLastError());
607 DeletePortA(NULL
, 0, tempfileA
);
611 /* ########################### */
613 static void test_ConfigurePort(void)
618 SetLastError(0xdeadbeef);
619 res
= ConfigurePortA(NULL
, 0, NULL
);
620 if (is_spooler_deactivated(res
, GetLastError())) return;
621 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
622 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
623 (GetLastError() == ERROR_INVALID_PARAMETER
)),
624 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
625 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
627 SetLastError(0xdeadbeef);
628 res
= ConfigurePortA(NULL
, 0, empty
);
629 /* Allowed only for (Printer-)Administrators */
630 if (is_access_denied(res
, GetLastError())) return;
632 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
633 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
634 (GetLastError() == ERROR_INVALID_PARAMETER
)),
635 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
636 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
639 SetLastError(0xdeadbeef);
640 res
= ConfigurePortA(NULL
, 0, does_not_exist
);
641 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
642 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
643 (GetLastError() == ERROR_INVALID_PARAMETER
)),
644 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
645 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
649 - Case of Portnames is ignored
650 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
651 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
653 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
654 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
655 - Cancel ("Local Port") => ERROR_CANCELED
656 - Cancel ("Redirected Port") => Success
658 if (winetest_interactive
> 0) {
659 SetLastError(0xdeadbeef);
660 res
= ConfigurePortA(NULL
, 0, portname_com1
);
661 trace("'%s' returned %d with %d\n", portname_com1
, res
, GetLastError());
663 SetLastError(0xdeadbeef);
664 res
= ConfigurePortA(NULL
, 0, portname_lpt1
);
665 trace("'%s' returned %d with %d\n", portname_lpt1
, res
, GetLastError());
667 SetLastError(0xdeadbeef);
668 res
= ConfigurePortA(NULL
, 0, portname_file
);
669 trace("'%s' returned %d with %d\n", portname_file
, res
, GetLastError());
673 /* ########################### */
675 static void test_DeleteMonitor(void)
677 MONITOR_INFO_2A mi2a
;
678 struct monitor_entry
* entry
= NULL
;
682 entry
= find_installed_monitor();
685 skip("No usable Monitor found\n");
689 mi2a
.pName
= winetest
;
690 mi2a
.pEnvironment
= entry
->env
;
691 mi2a
.pDLLName
= entry
->dllname
;
693 /* Testing DeleteMonitor with real options */
694 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
696 SetLastError(MAGIC_DEAD
);
697 res
= DeleteMonitorA(NULL
, entry
->env
, winetest
);
698 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
700 /* Delete the Monitor twice */
701 SetLastError(MAGIC_DEAD
);
702 res
= DeleteMonitorA(NULL
, entry
->env
, winetest
);
703 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
705 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR
) ||
706 (GetLastError() == ERROR_INVALID_PARAMETER
)),
707 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
708 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
710 /* the environment */
711 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
712 SetLastError(MAGIC_DEAD
);
713 res
= DeleteMonitorA(NULL
, NULL
, winetest
);
714 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
716 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
717 SetLastError(MAGIC_DEAD
);
718 res
= DeleteMonitorA(NULL
, empty
, winetest
);
719 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
721 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
722 SetLastError(MAGIC_DEAD
);
723 res
= DeleteMonitorA(NULL
, invalid_env
, winetest
);
724 ok( res
|| GetLastError() == ERROR_INVALID_ENVIRONMENT
/* Vista/W2K8 */,
725 "returned %d with %d\n", res
, GetLastError());
727 /* the monitor-name */
728 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
729 SetLastError(MAGIC_DEAD
);
730 res
= DeleteMonitorA(NULL
, entry
->env
, NULL
);
731 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
733 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
734 (GetLastError() == ERROR_INVALID_NAME
)),
735 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
736 "ERROR_INVALID_NAME)\n", res
, GetLastError());
738 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
739 SetLastError(MAGIC_DEAD
);
740 res
= DeleteMonitorA(NULL
, entry
->env
, empty
);
741 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
743 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
744 (GetLastError() == ERROR_INVALID_NAME
)),
745 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
746 "ERROR_INVALID_NAME)\n", res
, GetLastError());
748 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
749 SetLastError(MAGIC_DEAD
);
750 res
= DeleteMonitorA(empty
, entry
->env
, winetest
);
751 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
754 DeleteMonitorA(NULL
, entry
->env
, winetest
);
757 /* ########################### */
759 static void test_DeletePort(void)
763 SetLastError(0xdeadbeef);
764 res
= DeletePortA(NULL
, 0, NULL
);
765 if (is_spooler_deactivated(res
, GetLastError())) return;
767 SetLastError(0xdeadbeef);
768 res
= DeletePortA(NULL
, 0, empty
);
769 /* Allowed only for (Printer-)Administrators */
770 if (is_access_denied(res
, GetLastError())) return;
772 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
773 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
774 (GetLastError() == ERROR_INVALID_PARAMETER
)),
775 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
776 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
779 SetLastError(0xdeadbeef);
780 res
= DeletePortA(NULL
, 0, does_not_exist
);
781 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
782 ok( !res
&& ((GetLastError() == ERROR_NOT_SUPPORTED
) ||
783 (GetLastError() == ERROR_INVALID_PARAMETER
)),
784 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
785 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
789 /* ########################### */
791 static void test_EnumForms(LPSTR pName
)
801 const char *formtype
;
802 static const char * const formtypes
[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
803 #define FORMTYPE_MAX 2
804 PFORM_INFO_1A pFI_1a
;
805 PFORM_INFO_2A pFI_2a
;
807 res
= OpenPrinterA(pName
, &hprinter
, NULL
);
808 if (is_spooler_deactivated(res
, GetLastError())) return;
809 if (!res
|| !hprinter
)
811 /* opening the local Printserver is not supported on win9x */
812 if (pName
) skip("Failed to open '%s' (not supported on win9x)\n", pName
);
816 /* valid levels are 1 and 2 */
817 for(level
= 0; level
< 4; level
++) {
819 pcReturned
= 0xdeadbeef;
820 SetLastError(0xdeadbeef);
821 res
= EnumFormsA(hprinter
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
823 /* EnumForms is not implemented on win9x */
824 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
826 /* EnumForms for the server is not implemented on all NT-versions */
827 if (!res
&& (GetLastError() == ERROR_INVALID_HANDLE
) && !pName
) continue;
829 /* Level 2 for EnumForms is not supported on all systems */
830 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
) && (level
== 2)) continue;
832 /* use only a short test when testing an invalid level */
833 if(!level
|| (level
> 2)) {
834 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
835 (res
&& (pcReturned
== 0)),
836 "(%d) returned %d with %d and 0x%08x (expected '0' with "
837 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
838 level
, res
, GetLastError(), pcReturned
);
842 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
843 "(%d) returned %d with %d (expected '0' with "
844 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
846 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
847 if (buffer
== NULL
) continue;
849 SetLastError(0xdeadbeef);
850 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
851 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
852 level
, res
, GetLastError());
854 if (winetest_debug
> 1) {
855 trace("dumping %d forms level %d\n", pcReturned
, level
);
856 pFI_1a
= (PFORM_INFO_1A
)buffer
;
857 pFI_2a
= (PFORM_INFO_2A
)buffer
;
858 for (i
= 0; i
< pcReturned
; i
++)
860 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
861 formtype
= (pFI_1a
->Flags
<= FORMTYPE_MAX
) ? formtypes
[pFI_1a
->Flags
] : formtypes
[3];
862 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i
, pFI_1a
->pName
,
863 (float)pFI_1a
->Size
.cx
/1000, (float)pFI_1a
->Size
.cy
/1000, formtype
);
865 if (level
== 1) pFI_1a
++;
867 /* output additional FORM_INFO_2 fields */
868 trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
869 pFI_2a
->pKeyword
, pFI_2a
->StringType
, pFI_2a
->pMuiDll
,
870 pFI_2a
->dwResourceId
, pFI_2a
->pDisplayName
, pFI_2a
->wLangId
);
872 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
874 pFI_1a
= (PFORM_INFO_1A
)pFI_2a
;
879 SetLastError(0xdeadbeef);
880 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
881 ok( res
, "(%d) returned %d with %d (expected '!=0')\n",
882 level
, res
, GetLastError());
884 SetLastError(0xdeadbeef);
885 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
886 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
887 "(%d) returned %d with %d (expected '0' with "
888 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
891 SetLastError(0xdeadbeef);
892 res
= EnumFormsA(hprinter
, level
, NULL
, cbBuf
, &pcbNeeded
, &pcReturned
);
893 ok( !res
&& (GetLastError() == ERROR_INVALID_USER_BUFFER
) ,
894 "(%d) returned %d with %d (expected '0' with "
895 "ERROR_INVALID_USER_BUFFER)\n", level
, res
, GetLastError());
898 SetLastError(0xdeadbeef);
899 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
900 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
901 "(%d) returned %d with %d (expected '0' with "
902 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
904 SetLastError(0xdeadbeef);
905 res
= EnumFormsA(hprinter
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
906 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ,
907 "(%d) returned %d with %d (expected '0' with "
908 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
910 SetLastError(0xdeadbeef);
911 res
= EnumFormsA(0, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
912 ok( !res
&& (GetLastError() == ERROR_INVALID_HANDLE
) ,
913 "(%d) returned %d with %d (expected '0' with "
914 "ERROR_INVALID_HANDLE)\n", level
, res
, GetLastError());
916 HeapFree(GetProcessHeap(), 0, buffer
);
917 } /* for(level ... */
919 ClosePrinter(hprinter
);
922 /* ########################### */
924 static void test_EnumMonitors(void)
933 /* valid levels are 1 and 2 */
934 for(level
= 0; level
< 4; level
++) {
936 pcReturned
= MAGIC_DEAD
;
937 SetLastError(MAGIC_DEAD
);
938 res
= EnumMonitorsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
939 if (is_spooler_deactivated(res
, GetLastError())) return;
940 /* not implemented yet in wine */
941 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
944 /* use only a short test when testing an invalid level */
945 if(!level
|| (level
> 2)) {
946 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
947 (res
&& (pcReturned
== 0)),
948 "(%d) returned %d with %d and 0x%08x (expected '0' with "
949 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
950 level
, res
, GetLastError(), pcReturned
);
954 /* Level 2 is not supported on win9x */
955 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
956 skip("Level %d not supported\n", level
);
960 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
961 "(%d) returned %d with %d (expected '0' with "
962 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
965 skip("no valid buffer size returned\n");
969 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
970 if (buffer
== NULL
) continue;
972 SetLastError(MAGIC_DEAD
);
973 pcbNeeded
= MAGIC_DEAD
;
974 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
975 ok(res
, "(%d) returned %d with %d (expected '!=0')\n",
976 level
, res
, GetLastError());
977 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n",
978 level
, pcbNeeded
, cbBuf
);
979 /* We can validate the returned Data with the Registry here */
982 SetLastError(MAGIC_DEAD
);
983 pcReturned
= MAGIC_DEAD
;
984 pcbNeeded
= MAGIC_DEAD
;
985 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
986 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
,
987 res
, GetLastError());
988 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
991 SetLastError(MAGIC_DEAD
);
992 pcbNeeded
= MAGIC_DEAD
;
993 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
994 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
995 "(%d) returned %d with %d (expected '0' with "
996 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
998 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
,
1002 Do not add the next test:
1003 w2k+: RPC_X_NULL_REF_POINTER
1004 NT3.5: ERROR_INVALID_USER_BUFFER
1005 win9x: crash in winspool.drv
1007 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1010 SetLastError(MAGIC_DEAD
);
1011 pcbNeeded
= MAGIC_DEAD
;
1012 pcReturned
= MAGIC_DEAD
;
1013 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
1014 ok( res
|| GetLastError() == RPC_X_NULL_REF_POINTER
,
1015 "(%d) returned %d with %d (expected '!=0' or '0' with "
1016 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1018 pcbNeeded
= MAGIC_DEAD
;
1019 pcReturned
= MAGIC_DEAD
;
1020 SetLastError(MAGIC_DEAD
);
1021 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1022 ok( res
|| GetLastError() == RPC_X_NULL_REF_POINTER
,
1023 "(%d) returned %d with %d (expected '!=0' or '0' with "
1024 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1026 HeapFree(GetProcessHeap(), 0, buffer
);
1027 } /* for(level ... */
1030 /* ########################### */
1032 static void test_EnumPorts(void)
1041 /* valid levels are 1 and 2 */
1042 for(level
= 0; level
< 4; level
++) {
1045 pcReturned
= 0xdeadbeef;
1046 SetLastError(0xdeadbeef);
1047 res
= EnumPortsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
1048 if (is_spooler_deactivated(res
, GetLastError())) return;
1050 /* use only a short test when testing an invalid level */
1051 if(!level
|| (level
> 2)) {
1052 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1053 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1054 (res
&& (pcReturned
== 0)),
1055 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1056 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1057 level
, res
, GetLastError(), pcReturned
);
1062 /* Level 2 is not supported on NT 3.x */
1063 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
1064 skip("Level %d not supported\n", level
);
1068 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1069 "(%d) returned %d with %d (expected '0' with "
1070 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
1072 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
1073 if (buffer
== NULL
) continue;
1075 pcbNeeded
= 0xdeadbeef;
1076 SetLastError(0xdeadbeef);
1077 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1078 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
1079 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1080 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1082 pcbNeeded
= 0xdeadbeef;
1083 pcReturned
= 0xdeadbeef;
1084 SetLastError(0xdeadbeef);
1085 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
1086 ok(res
, "(%d) returned %d with %d (expected '!=0')\n", level
, res
, GetLastError());
1087 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1089 pcbNeeded
= 0xdeadbeef;
1090 SetLastError(0xdeadbeef);
1091 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
1092 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1093 "(%d) returned %d with %d (expected '0' with "
1094 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
1095 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1098 Do not add this test:
1099 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1100 w2k+: RPC_X_NULL_REF_POINTER
1101 NT3.5: ERROR_INVALID_USER_BUFFER
1102 win9x: crash in winspool.drv
1105 SetLastError(0xdeadbeef);
1106 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
1107 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1108 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
1109 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
1110 "(%d) returned %d with %d (expected '0' with "
1111 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1112 level
, res
, GetLastError());
1115 SetLastError(0xdeadbeef);
1116 res
= EnumPortsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1117 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1118 ok( (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
) ) ||
1119 ( res
&& (GetLastError() == ERROR_SUCCESS
) ),
1120 "(%d) returned %d with %d (expected '0' with "
1121 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1122 level
, res
, GetLastError());
1124 HeapFree(GetProcessHeap(), 0, buffer
);
1128 /* ########################### */
1130 static void test_EnumPrinterDrivers(void)
1132 static char env_all
[] = "all";
1141 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1142 for(level
= 0; level
< 10; level
++) {
1144 pcReturned
= 0xdeadbeef;
1145 SetLastError(0xdeadbeef);
1146 res
= EnumPrinterDriversA(NULL
, NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
1147 if (is_spooler_deactivated(res
, GetLastError())) return;
1149 /* use only a short test when testing an invalid level */
1150 if(!level
|| (level
== 7) || (level
> 8)) {
1152 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1153 (res
&& (pcReturned
== 0)),
1154 "(%d) got %u with %u and 0x%x "
1155 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1156 level
, res
, GetLastError(), pcReturned
);
1160 /* some levels are not supported on all windows versions */
1161 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
1162 skip("Level %d not supported\n", level
);
1166 ok( ((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) ||
1167 (res
&& (default_printer
== NULL
)),
1168 "(%u) got %u with %u for %s (expected '0' with "
1169 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1170 level
, res
, GetLastError(), default_printer
);
1173 skip("no valid buffer size returned\n");
1177 /* EnumPrinterDriversA returns the same number of bytes as EnumPrinterDriversW */
1178 if (!on_win9x
&& pEnumPrinterDriversW
)
1180 DWORD double_needed
;
1181 DWORD double_returned
;
1182 pEnumPrinterDriversW(NULL
, NULL
, level
, NULL
, 0, &double_needed
, &double_returned
);
1183 ok(double_needed
== cbBuf
, "level %d: EnumPrinterDriversA returned different size %d than EnumPrinterDriversW (%d)\n", level
, cbBuf
, double_needed
);
1186 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
+ 4);
1187 if (buffer
== NULL
) continue;
1189 SetLastError(0xdeadbeef);
1190 pcbNeeded
= 0xdeadbeef;
1191 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1192 ok(res
, "(%u) got %u with %u (expected '!=0')\n", level
, res
, GetLastError());
1193 ok(pcbNeeded
== cbBuf
, "(%d) returned %d (expected %d)\n", level
, pcbNeeded
, cbBuf
);
1195 /* validate the returned data here */
1197 LPDRIVER_INFO_2A di
= (LPDRIVER_INFO_2A
) buffer
;
1199 ok( strrchr(di
->pDriverPath
, '\\') != NULL
,
1200 "(%u) got %s for %s (expected a full path)\n",
1201 level
, di
->pDriverPath
, di
->pName
);
1205 SetLastError(0xdeadbeef);
1206 pcReturned
= 0xdeadbeef;
1207 pcbNeeded
= 0xdeadbeef;
1208 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
1209 ok(res
, "(%u) got %u with %u (expected '!=0')\n", level
, res
, GetLastError());
1210 ok(pcbNeeded
== cbBuf
, "(%u) returned %u (expected %u)\n", level
, pcbNeeded
, cbBuf
);
1212 SetLastError(0xdeadbeef);
1213 pcbNeeded
= 0xdeadbeef;
1214 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
1215 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1216 "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1217 level
, res
, GetLastError());
1218 ok(pcbNeeded
== cbBuf
, "(%u) returned %u (expected %u)\n", level
, pcbNeeded
, cbBuf
);
1221 Do not add the next test:
1222 NT: ERROR_INVALID_USER_BUFFER
1223 win9x: crash or 100% CPU
1225 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1228 SetLastError(0xdeadbeef);
1229 pcbNeeded
= 0xdeadbeef;
1230 pcReturned
= 0xdeadbeef;
1231 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
1232 ok( res
|| GetLastError() == RPC_X_NULL_REF_POINTER
,
1233 "(%u) got %u with %u (expected '!=0' or '0' with "
1234 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1236 pcbNeeded
= 0xdeadbeef;
1237 pcReturned
= 0xdeadbeef;
1238 SetLastError(0xdeadbeef);
1239 res
= EnumPrinterDriversA(NULL
, NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1240 ok( res
|| GetLastError() == RPC_X_NULL_REF_POINTER
,
1241 "(%u) got %u with %u (expected '!=0' or '0' with "
1242 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
1244 HeapFree(GetProcessHeap(), 0, buffer
);
1245 } /* for(level ... */
1249 SetLastError(0xdeadbeef);
1250 res
= EnumPrinterDriversA(NULL
, env_all
, 1, NULL
, 0, &pcbNeeded
, &pcReturned
);
1253 skip("no printer drivers found\n");
1256 if (GetLastError() == ERROR_INVALID_ENVIRONMENT
)
1258 win_skip("NT4 and below don't support the 'all' environment value\n");
1261 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "unexpected error %u\n", GetLastError());
1263 buffer
= HeapAlloc(GetProcessHeap(), 0, pcbNeeded
);
1264 res
= EnumPrinterDriversA(NULL
, env_all
, 1, buffer
, pcbNeeded
, &pcbNeeded
, &pcReturned
);
1265 ok(res
, "EnumPrinterDriversA failed %u\n", GetLastError());
1266 if (res
&& pcReturned
> 0)
1268 DRIVER_INFO_1A
*di_1
= (DRIVER_INFO_1A
*)buffer
;
1269 ok((LPBYTE
) di_1
->pName
== NULL
|| (LPBYTE
) di_1
->pName
< buffer
||
1270 (LPBYTE
) di_1
->pName
>= (LPBYTE
)(di_1
+ pcReturned
),
1271 "Driver Information not in sequence; pName %p, top of data %p\n",
1272 di_1
->pName
, di_1
+ pcReturned
);
1275 HeapFree(GetProcessHeap(), 0, buffer
);
1278 /* ########################### */
1280 static void test_EnumPrintProcessors(void)
1290 pcReturned
= 0xdeadbeef;
1291 SetLastError(0xdeadbeef);
1292 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, NULL
, 0, &cbBuf
, &pcReturned
);
1293 if (is_spooler_deactivated(res
, GetLastError())) return;
1295 if (res
&& !cbBuf
) {
1296 skip("No Printprocessor installed\n");
1300 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1301 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1302 res
, GetLastError());
1304 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
+ 4);
1308 SetLastError(0xdeadbeef);
1309 pcbNeeded
= 0xdeadbeef;
1310 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1311 ok(res
, "got %u with %u (expected '!=0')\n", res
, GetLastError());
1312 /* validate the returned data here. */
1315 SetLastError(0xdeadbeef);
1316 pcReturned
= 0xdeadbeef;
1317 pcbNeeded
= 0xdeadbeef;
1318 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
1319 ok(res
, "got %u with %u (expected '!=0')\n", res
, GetLastError());
1321 SetLastError(0xdeadbeef);
1322 pcbNeeded
= 0xdeadbeef;
1323 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
1324 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1325 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1326 res
, GetLastError());
1328 /* only level 1 is valid */
1330 /* both tests crash on win98se */
1331 SetLastError(0xdeadbeef);
1332 pcbNeeded
= 0xdeadbeef;
1333 pcReturned
= 0xdeadbeef;
1334 res
= EnumPrintProcessorsA(NULL
, NULL
, 0, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1335 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1336 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1337 res
, GetLastError());
1339 SetLastError(0xdeadbeef);
1340 pcbNeeded
= 0xdeadbeef;
1341 res
= EnumPrintProcessorsA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1342 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1343 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1344 res
, GetLastError());
1347 /* an empty environment is ignored */
1348 SetLastError(0xdeadbeef);
1349 pcbNeeded
= 0xdeadbeef;
1350 res
= EnumPrintProcessorsA(NULL
, empty
, 1, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1351 ok(res
, "got %u with %u (expected '!=0')\n", res
, GetLastError());
1353 /* the environment is checked */
1354 SetLastError(0xdeadbeef);
1355 pcbNeeded
= 0xdeadbeef;
1356 res
= EnumPrintProcessorsA(NULL
, invalid_env
, 1, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
1357 /* NT5: ERROR_INVALID_ENVIRONMENT, NT4: res != 0, 9x: ERROR_INVALID_PARAMETER */
1358 ok( broken(res
) || /* NT4 */
1359 (GetLastError() == ERROR_INVALID_ENVIRONMENT
) ||
1360 (GetLastError() == ERROR_INVALID_PARAMETER
),
1361 "got %u with %u (expected '0' with ERROR_INVALID_ENVIRONMENT or "
1362 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1365 /* failure-Codes for NULL */
1367 /* this test crashes on win98se */
1368 SetLastError(0xdeadbeef);
1369 pcbNeeded
= 0xdeadbeef;
1370 pcReturned
= 0xdeadbeef;
1371 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, NULL
, cbBuf
, &pcbNeeded
, &pcReturned
);
1372 ok( !res
&& (GetLastError() == ERROR_INVALID_USER_BUFFER
) ,
1373 "got %u with %u (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1374 res
, GetLastError());
1377 SetLastError(0xdeadbeef);
1378 pcbNeeded
= 0xdeadbeef;
1379 pcReturned
= 0xdeadbeef;
1380 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, buffer
, cbBuf
, NULL
, &pcReturned
);
1381 /* the NULL is ignored on win9x */
1382 ok( broken(res
) || (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)),
1383 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1384 res
, GetLastError());
1386 pcbNeeded
= 0xdeadbeef;
1387 pcReturned
= 0xdeadbeef;
1388 SetLastError(0xdeadbeef);
1389 res
= EnumPrintProcessorsA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
, NULL
);
1390 /* the NULL is ignored on win9x */
1391 ok( broken(res
) || (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)),
1392 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1393 res
, GetLastError());
1395 HeapFree(GetProcessHeap(), 0, buffer
);
1399 /* ########################### */
1401 static void test_GetDefaultPrinter(void)
1404 DWORD exact
= DEFAULT_PRINTER_SIZE
;
1406 char buffer
[DEFAULT_PRINTER_SIZE
];
1408 if (!pGetDefaultPrinterA
) return;
1409 /* only supported on NT like OSes starting with win2k */
1411 SetLastError(ERROR_SUCCESS
);
1412 retval
= pGetDefaultPrinterA(buffer
, &exact
);
1413 if (!retval
|| !exact
|| !strlen(buffer
) ||
1414 (ERROR_SUCCESS
!= GetLastError())) {
1415 if ((ERROR_FILE_NOT_FOUND
== GetLastError()) ||
1416 (ERROR_INVALID_NAME
== GetLastError()))
1417 trace("this test requires a default printer to be set\n");
1419 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1420 "function returned %s\n"
1421 "last error 0x%08x\n"
1422 "returned buffer size 0x%08x\n"
1423 "returned buffer content %s\n",
1424 retval
? "true" : "false", GetLastError(), exact
, buffer
);
1428 SetLastError(ERROR_SUCCESS
);
1429 retval
= pGetDefaultPrinterA(NULL
, NULL
);
1430 ok( !retval
, "function result wrong! False expected\n");
1431 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
1432 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1435 SetLastError(ERROR_SUCCESS
);
1436 retval
= pGetDefaultPrinterA(buffer
, NULL
);
1437 ok( !retval
, "function result wrong! False expected\n");
1438 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
1439 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1442 SetLastError(ERROR_SUCCESS
);
1444 retval
= pGetDefaultPrinterA(NULL
, &size
);
1445 ok( !retval
, "function result wrong! False expected\n");
1446 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1447 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1449 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1452 SetLastError(ERROR_SUCCESS
);
1453 size
= DEFAULT_PRINTER_SIZE
;
1454 retval
= pGetDefaultPrinterA(NULL
, &size
);
1455 ok( !retval
, "function result wrong! False expected\n");
1456 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1457 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1459 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1463 retval
= pGetDefaultPrinterA(buffer
, &size
);
1464 ok( !retval
, "function result wrong! False expected\n");
1465 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1466 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1468 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1472 retval
= pGetDefaultPrinterA(buffer
, &size
);
1473 ok( retval
, "function result wrong! True expected\n");
1474 ok( size
== exact
, "Parameter size wrong! %d expected got %d\n",
1478 static void test_GetPrinterDriverDirectory(void)
1480 LPBYTE buffer
= NULL
;
1481 DWORD cbBuf
= 0, pcbNeeded
= 0;
1485 SetLastError(MAGIC_DEAD
);
1486 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
1487 if (is_spooler_deactivated(res
, GetLastError())) return;
1489 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1490 res
, GetLastError(), cbBuf
);
1492 ok((res
== 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1493 "returned %d with lasterror=%d (expected '0' with "
1494 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError());
1497 skip("no valid buffer size returned\n");
1501 buffer
= HeapAlloc( GetProcessHeap(), 0, cbBuf
*2);
1502 if (buffer
== NULL
) return ;
1504 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
1505 ok( res
, "expected result != 0, got %d\n", res
);
1506 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1509 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1510 ok( res
, "expected result != 0, got %d\n", res
);
1511 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1514 SetLastError(MAGIC_DEAD
);
1515 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
1516 ok( !res
, "expected result == 0, got %d\n", res
);
1517 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %d instead of %d\n",
1520 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
1521 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1525 Do not add the next test:
1526 XPsp2: crash in this app, when the spooler is not running
1527 NT3.5: ERROR_INVALID_USER_BUFFER
1528 win9x: ERROR_INVALID_PARAMETER
1530 pcbNeeded = MAGIC_DEAD;
1531 SetLastError(MAGIC_DEAD);
1532 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1535 SetLastError(MAGIC_DEAD
);
1536 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
1537 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1538 NT: RPC_X_NULL_REF_POINTER */
1539 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
) ||
1540 (GetLastError() == ERROR_INVALID_PARAMETER
),
1541 "returned %d with %d (expected '!=0' or '0' with RPC_X_NULL_REF_POINTER "
1542 "or '0' with ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1544 SetLastError(MAGIC_DEAD
);
1545 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1546 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1547 NT: RPC_X_NULL_REF_POINTER */
1548 ok( res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
) ||
1549 (GetLastError() == ERROR_INVALID_PARAMETER
),
1550 "returned %d with %d (expected '!=0' or '0' with RPC_X_NULL_REF_POINTER "
1551 "or '0' with ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1553 /* with a valid buffer, but level is too large */
1555 SetLastError(MAGIC_DEAD
);
1556 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1558 /* Level not checked in win9x and wine:*/
1559 if((res
!= FALSE
) && buffer
[0])
1561 trace("Level '2' not checked '%s'\n", buffer
);
1565 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
1566 "returned %d with lasterror=%d (expected '0' with "
1567 "ERROR_INVALID_LEVEL)\n", res
, GetLastError());
1570 /* printing environments are case insensitive */
1571 /* "Windows 4.0" is valid for win9x and NT */
1573 SetLastError(MAGIC_DEAD
);
1574 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1575 buffer
, cbBuf
*2, &pcbNeeded
);
1577 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1579 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1580 if (buffer
== NULL
) return ;
1582 SetLastError(MAGIC_DEAD
);
1583 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
1584 buffer
, cbBuf
*2, &pcbNeeded
);
1587 ok(res
&& buffer
[0], "returned %d with "
1588 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1589 res
, GetLastError(), lstrlenA((char *)buffer
));
1592 SetLastError(MAGIC_DEAD
);
1593 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1594 buffer
, cbBuf
*2, &pcbNeeded
);
1596 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
1598 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
1599 if (buffer
== NULL
) return ;
1602 SetLastError(MAGIC_DEAD
);
1603 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
1604 buffer
, cbBuf
*2, &pcbNeeded
);
1607 /* "Windows NT x86" is invalid for win9x */
1608 ok( (res
&& buffer
[0]) ||
1609 (!res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
1610 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1611 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1612 res
, GetLastError(), lstrlenA((char *)buffer
));
1614 /* A setup program (PDFCreator_0.8.0) use empty strings */
1615 SetLastError(MAGIC_DEAD
);
1616 res
= GetPrinterDriverDirectoryA(empty
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1617 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1619 SetLastError(MAGIC_DEAD
);
1620 res
= GetPrinterDriverDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1621 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1623 SetLastError(MAGIC_DEAD
);
1624 res
= GetPrinterDriverDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1625 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError() );
1627 HeapFree( GetProcessHeap(), 0, buffer
);
1632 static void test_GetPrintProcessorDirectory(void)
1634 LPBYTE buffer
= NULL
;
1636 DWORD pcbNeeded
= 0;
1640 SetLastError(0xdeadbeef);
1641 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
1642 if (is_spooler_deactivated(res
, GetLastError())) return;
1644 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1645 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1646 res
, GetLastError());
1648 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
1649 if(buffer
== NULL
) return;
1652 SetLastError(0xdeadbeef);
1653 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
1654 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1656 SetLastError(0xdeadbeef);
1658 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1659 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1661 /* Buffer too small */
1663 SetLastError(0xdeadbeef);
1664 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
1665 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
1666 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1667 res
, GetLastError());
1671 /* XPsp2: the program will crash here, when the spooler is not running */
1672 /* GetPrinterDriverDirectory has the same bug */
1674 SetLastError(0xdeadbeef);
1675 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, &pcbNeeded
);
1676 /* NT: ERROR_INVALID_USER_BUFFER, 9x: res != 0 */
1677 ok( (!res
&& (GetLastError() == ERROR_INVALID_USER_BUFFER
)) ||
1679 "returned %d with %d (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1680 res
, GetLastError());
1684 SetLastError(0xdeadbeef);
1685 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
1686 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1687 NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1688 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
1689 (GetLastError() == ERROR_INVALID_PARAMETER
)),
1690 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER "
1691 "or with ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1694 SetLastError(0xdeadbeef);
1695 res
= GetPrintProcessorDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
1696 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1697 NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1698 ok( !res
&& ((GetLastError() == RPC_X_NULL_REF_POINTER
) ||
1699 (GetLastError() == ERROR_INVALID_PARAMETER
)),
1700 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER "
1701 "or with ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1703 /* with a valid buffer, but level is invalid */
1705 SetLastError(0xdeadbeef);
1706 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 0, buffer
, cbBuf
, &pcbNeeded
);
1707 /* Level is ignored in win9x*/
1708 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1709 broken(res
&& buffer
[0]),
1710 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1711 res
, GetLastError());
1714 SetLastError(0xdeadbeef);
1715 res
= GetPrintProcessorDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
1716 /* Level is ignored on win9x*/
1717 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
1718 broken(res
&& buffer
[0]),
1719 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1720 res
, GetLastError());
1722 /* Empty environment is the same as the default environment */
1724 SetLastError(0xdeadbeef);
1725 res
= GetPrintProcessorDirectoryA(NULL
, empty
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1726 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1728 /* "Windows 4.0" is valid for win9x and NT */
1730 SetLastError(0xdeadbeef);
1731 res
= GetPrintProcessorDirectoryA(NULL
, env_win9x_case
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1732 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1735 /* "Windows NT x86" is invalid for win9x */
1737 SetLastError(0xdeadbeef);
1738 res
= GetPrintProcessorDirectoryA(NULL
, env_x86
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1739 ok( res
|| (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1740 "returned %d with %d (expected '!= 0' or '0' with "
1741 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
1743 /* invalid on all systems */
1745 SetLastError(0xdeadbeef);
1746 res
= GetPrintProcessorDirectoryA(NULL
, invalid_env
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1747 ok( !res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
),
1748 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1749 res
, GetLastError());
1751 /* Empty servername is the same as the local computer */
1753 SetLastError(0xdeadbeef);
1754 res
= GetPrintProcessorDirectoryA(empty
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1755 ok(res
, "returned %d with %d (expected '!= 0')\n", res
, GetLastError());
1757 /* invalid on all systems */
1759 SetLastError(0xdeadbeef);
1760 res
= GetPrintProcessorDirectoryA(server_does_not_exist
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
1761 ok( !res
, "expected failure\n");
1762 ok( GetLastError() == RPC_S_SERVER_UNAVAILABLE
|| /* NT */
1763 GetLastError() == ERROR_INVALID_PARAMETER
|| /* 9x */
1764 GetLastError() == RPC_S_INVALID_NET_ADDR
, /* Some Vista */
1765 "unexpected last error %d\n", GetLastError());
1767 HeapFree(GetProcessHeap(), 0, buffer
);
1772 static void test_OpenPrinter(void)
1774 PRINTER_DEFAULTSA defaults
;
1778 SetLastError(MAGIC_DEAD
);
1779 res
= OpenPrinterA(NULL
, NULL
, NULL
);
1780 if (is_spooler_deactivated(res
, GetLastError())) return;
1782 ok(!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1783 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1784 res
, GetLastError());
1787 /* Get Handle for the local Printserver (NT only)*/
1788 hprinter
= (HANDLE
) MAGIC_DEAD
;
1789 SetLastError(MAGIC_DEAD
);
1790 res
= OpenPrinterA(NULL
, &hprinter
, NULL
);
1791 if (is_spooler_deactivated(res
, GetLastError())) return;
1792 ok(res
|| GetLastError() == ERROR_INVALID_PARAMETER
,
1793 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1794 res
, GetLastError());
1796 ClosePrinter(hprinter
);
1798 defaults
.pDatatype
=NULL
;
1799 defaults
.pDevMode
=NULL
;
1801 defaults
.DesiredAccess
=0;
1802 hprinter
= (HANDLE
) MAGIC_DEAD
;
1803 SetLastError(MAGIC_DEAD
);
1804 res
= OpenPrinterA(NULL
, &hprinter
, &defaults
);
1805 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1806 if (res
) ClosePrinter(hprinter
);
1808 defaults
.DesiredAccess
=-1;
1809 hprinter
= (HANDLE
) MAGIC_DEAD
;
1810 SetLastError(MAGIC_DEAD
);
1811 res
= OpenPrinterA(NULL
, &hprinter
, &defaults
);
1813 ok(!res
&& GetLastError() == ERROR_ACCESS_DENIED
,
1814 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1815 res
, GetLastError());
1817 if (res
) ClosePrinter(hprinter
);
1822 if (local_server
!= NULL
) {
1823 hprinter
= (HANDLE
) 0xdeadbeef;
1824 SetLastError(0xdeadbeef);
1825 res
= OpenPrinterA(local_server
, &hprinter
, NULL
);
1826 ok(res
|| GetLastError() == ERROR_INVALID_PARAMETER
,
1827 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1828 res
, GetLastError());
1829 if(res
) ClosePrinter(hprinter
);
1832 /* Invalid Printername */
1833 hprinter
= (HANDLE
) MAGIC_DEAD
;
1834 SetLastError(MAGIC_DEAD
);
1835 res
= OpenPrinterA(illegal_name
, &hprinter
, NULL
);
1836 ok(!res
&& ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1837 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1838 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1839 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1840 if(res
) ClosePrinter(hprinter
);
1842 hprinter
= (HANDLE
) MAGIC_DEAD
;
1843 SetLastError(MAGIC_DEAD
);
1844 res
= OpenPrinterA(empty
, &hprinter
, NULL
);
1845 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1847 ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
1848 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
1849 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1850 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1851 if(res
) ClosePrinter(hprinter
);
1854 /* get handle for the default printer */
1855 if (default_printer
)
1857 hprinter
= (HANDLE
) MAGIC_DEAD
;
1858 SetLastError(MAGIC_DEAD
);
1859 res
= OpenPrinterA(default_printer
, &hprinter
, NULL
);
1860 if((!res
) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE
))
1862 trace("The service 'Spooler' is required for '%s'\n", default_printer
);
1865 ok(res
, "returned %d with %d (expected '!=0')\n", res
, GetLastError());
1866 if(res
) ClosePrinter(hprinter
);
1868 SetLastError(MAGIC_DEAD
);
1869 res
= OpenPrinterA(default_printer
, NULL
, NULL
);
1870 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1871 ok(res
|| (GetLastError() == ERROR_INVALID_PARAMETER
),
1872 "returned %d with %d (expected '!=0' or '0' with "
1873 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
1875 defaults
.pDatatype
=NULL
;
1876 defaults
.pDevMode
=NULL
;
1877 defaults
.DesiredAccess
=0;
1879 hprinter
= (HANDLE
) MAGIC_DEAD
;
1880 SetLastError(MAGIC_DEAD
);
1881 res
= OpenPrinterA(default_printer
, &hprinter
, &defaults
);
1882 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1883 "returned %d with %d (expected '!=0' or '0' with "
1884 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1885 if(res
) ClosePrinter(hprinter
);
1887 defaults
.pDatatype
= empty
;
1889 hprinter
= (HANDLE
) MAGIC_DEAD
;
1890 SetLastError(MAGIC_DEAD
);
1891 res
= OpenPrinterA(default_printer
, &hprinter
, &defaults
);
1892 /* stop here, when a remote Printserver has no RPC-Service running */
1893 if (is_spooler_deactivated(res
, GetLastError())) return;
1894 ok(res
|| ((GetLastError() == ERROR_INVALID_DATATYPE
) ||
1895 (GetLastError() == ERROR_ACCESS_DENIED
)),
1896 "returned %d with %d (expected '!=0' or '0' with: "
1897 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1898 res
, GetLastError());
1899 if(res
) ClosePrinter(hprinter
);
1902 defaults
.pDatatype
=NULL
;
1903 defaults
.DesiredAccess
=PRINTER_ACCESS_USE
;
1905 hprinter
= (HANDLE
) MAGIC_DEAD
;
1906 SetLastError(MAGIC_DEAD
);
1907 res
= OpenPrinterA(default_printer
, &hprinter
, &defaults
);
1908 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1909 "returned %d with %d (expected '!=0' or '0' with "
1910 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1911 if(res
) ClosePrinter(hprinter
);
1914 defaults
.DesiredAccess
=PRINTER_ALL_ACCESS
;
1915 hprinter
= (HANDLE
) MAGIC_DEAD
;
1916 SetLastError(MAGIC_DEAD
);
1917 res
= OpenPrinterA(default_printer
, &hprinter
, &defaults
);
1918 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
1919 "returned %d with %d (expected '!=0' or '0' with "
1920 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
1921 if(res
) ClosePrinter(hprinter
);
1927 static void test_SetDefaultPrinter(void)
1930 DWORD size
= DEFAULT_PRINTER_SIZE
;
1931 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
1932 CHAR org_value
[DEFAULT_PRINTER_SIZE
];
1934 if (!default_printer
)
1936 skip("There is no default printer installed\n");
1940 if (!pSetDefaultPrinterA
) return;
1941 /* only supported on win2k and above */
1943 /* backup the original value */
1944 org_value
[0] = '\0';
1945 SetLastError(MAGIC_DEAD
);
1946 res
= GetProfileStringA("windows", "device", NULL
, org_value
, size
);
1947 ok(res
, "GetProfileString error %d\n", GetLastError());
1949 /* first part: with the default Printer */
1950 SetLastError(MAGIC_DEAD
);
1951 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1952 if (is_spooler_deactivated(res
, GetLastError())) return;
1954 /* Not implemented in wine */
1955 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
1956 trace("SetDefaultPrinterA() not implemented yet.\n");
1960 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1961 "returned %d with %d (expected '0' with "
1962 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1964 WriteProfileStringA("windows", "device", org_value
);
1965 SetLastError(MAGIC_DEAD
);
1966 res
= pSetDefaultPrinterA("");
1967 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
1968 "returned %d with %d (expected '!=0' or '0' with "
1969 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1971 WriteProfileStringA("windows", "device", org_value
);
1972 SetLastError(MAGIC_DEAD
);
1973 res
= pSetDefaultPrinterA(NULL
);
1974 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
1975 "returned %d with %d (expected '!=0' or '0' with "
1976 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1978 WriteProfileStringA("windows", "device", org_value
);
1979 SetLastError(MAGIC_DEAD
);
1980 res
= pSetDefaultPrinterA(default_printer
);
1981 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
1982 "returned %d with %d (expected '!=0' or '0' with "
1983 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1986 /* second part: always without a default Printer */
1987 WriteProfileStringA("windows", "device", NULL
);
1988 SetLastError(MAGIC_DEAD
);
1989 res
= pSetDefaultPrinterA("no_printer_with_this_name");
1991 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
1992 "returned %d with %d (expected '0' with "
1993 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
1995 WriteProfileStringA("windows", "device", NULL
);
1996 SetLastError(MAGIC_DEAD
);
1997 res
= pSetDefaultPrinterA("");
1998 if (is_spooler_deactivated(res
, GetLastError()))
1999 goto restore_old_printer
;
2001 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
2002 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
2003 "returned %d with %d (expected '!=0' or '0' with "
2004 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
2006 WriteProfileStringA("windows", "device", NULL
);
2007 SetLastError(MAGIC_DEAD
);
2008 res
= pSetDefaultPrinterA(NULL
);
2009 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
2010 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
2011 "returned %d with %d (expected '!=0' or '0' with "
2012 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
2014 WriteProfileStringA("windows", "device", NULL
);
2015 SetLastError(MAGIC_DEAD
);
2016 res
= pSetDefaultPrinterA(default_printer
);
2017 ok(res
|| GetLastError() == ERROR_INVALID_PRINTER_NAME
,
2018 "returned %d with %d (expected '!=0' or '0' with "
2019 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
2021 /* restore the original value */
2022 restore_old_printer
:
2023 res
= pSetDefaultPrinterA(default_printer
); /* the nice way */
2024 ok(res
, "SetDefaultPrinter error %d\n", GetLastError());
2025 WriteProfileStringA("windows", "device", org_value
); /* the old way */
2028 SetLastError(MAGIC_DEAD
);
2029 res
= GetProfileStringA("windows", "device", NULL
, buffer
, size
);
2030 ok(res
, "GetProfileString error %d\n", GetLastError());
2031 ok(!lstrcmpA(org_value
, buffer
), "'%s' (expected '%s')\n", buffer
, org_value
);
2035 /* ########################### */
2037 static void test_XcvDataW_MonitorUI(void)
2041 BYTE buffer
[MAX_PATH
+ 4];
2045 PRINTER_DEFAULTSA pd
;
2047 /* api is not present before w2k */
2048 if (pXcvDataW
== NULL
) return;
2050 pd
.pDatatype
= NULL
;
2052 pd
.DesiredAccess
= SERVER_ACCESS_ADMINISTER
;
2055 SetLastError(0xdeadbeef);
2056 res
= OpenPrinterA(xcv_localport
, &hXcv
, &pd
);
2057 if (is_spooler_deactivated(res
, GetLastError())) return;
2058 if (is_access_denied(res
, GetLastError())) return;
2060 ok(res
, "returned %d with %u and handle %p (expected '!= 0')\n", res
, GetLastError(), hXcv
);
2063 /* ask for needed size */
2064 needed
= (DWORD
) 0xdeadbeef;
2065 status
= (DWORD
) 0xdeadbeef;
2066 SetLastError(0xdeadbeef);
2067 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, NULL
, 0, &needed
, &status
);
2068 ok( res
&& (status
== ERROR_INSUFFICIENT_BUFFER
) && (needed
<= MAX_PATH
),
2069 "returned %d with %u and %u for status %u (expected '!= 0' and "
2070 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
2071 res
, GetLastError(), needed
, status
);
2073 if (needed
> MAX_PATH
) {
2075 skip("buffer overflow (%u)\n", needed
);
2078 len
= needed
; /* Size is in bytes */
2080 /* the command is required */
2081 needed
= (DWORD
) 0xdeadbeef;
2082 status
= (DWORD
) 0xdeadbeef;
2083 SetLastError(0xdeadbeef);
2084 res
= pXcvDataW(hXcv
, emptyW
, NULL
, 0, NULL
, 0, &needed
, &status
);
2085 ok( res
&& (status
== ERROR_INVALID_PARAMETER
),
2086 "returned %d with %u and %u for status %u (expected '!= 0' with "
2087 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError(), needed
, status
);
2089 needed
= (DWORD
) 0xdeadbeef;
2090 status
= (DWORD
) 0xdeadbeef;
2091 SetLastError(0xdeadbeef);
2092 res
= pXcvDataW(hXcv
, NULL
, NULL
, 0, buffer
, MAX_PATH
, &needed
, &status
);
2093 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
2094 "returned %d with %u and %u for status %u (expected '0' with "
2095 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
2097 /* "PDWORD needed" is checked before RPC-Errors */
2098 needed
= (DWORD
) 0xdeadbeef;
2099 status
= (DWORD
) 0xdeadbeef;
2100 SetLastError(0xdeadbeef);
2101 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, NULL
, &status
);
2102 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
2103 "returned %d with %u and %u for status %u (expected '0' with "
2104 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError(), needed
, status
);
2106 needed
= (DWORD
) 0xdeadbeef;
2107 status
= (DWORD
) 0xdeadbeef;
2108 SetLastError(0xdeadbeef);
2109 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, NULL
, len
, &needed
, &status
);
2110 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
2111 "returned %d with %u and %u for status %u (expected '0' with "
2112 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
2114 needed
= (DWORD
) 0xdeadbeef;
2115 status
= (DWORD
) 0xdeadbeef;
2116 SetLastError(0xdeadbeef);
2117 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, &needed
, NULL
);
2118 ok( !res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
),
2119 "returned %d with %u and %u for status %u (expected '0' with "
2120 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError(), needed
, status
);
2122 /* off by one: larger */
2123 needed
= (DWORD
) 0xdeadbeef;
2124 status
= (DWORD
) 0xdeadbeef;
2125 SetLastError(0xdeadbeef);
2126 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
+1, &needed
, &status
);
2127 ok( res
&& (status
== ERROR_SUCCESS
),
2128 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2129 "ERROR_SUCCESS)\n", res
, GetLastError(), needed
, status
);
2131 /* off by one: smaller */
2132 /* the buffer is not modified for NT4, w2k, XP */
2133 needed
= (DWORD
) 0xdeadbeef;
2134 status
= (DWORD
) 0xdeadbeef;
2135 SetLastError(0xdeadbeef);
2136 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
-1, &needed
, &status
);
2137 ok( res
&& (status
== ERROR_INSUFFICIENT_BUFFER
),
2138 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2139 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError(), needed
, status
);
2142 /* Normal use. The DLL-Name without a Path is returned */
2143 memset(buffer
, 0, len
);
2144 needed
= (DWORD
) 0xdeadbeef;
2145 status
= (DWORD
) 0xdeadbeef;
2146 SetLastError(0xdeadbeef);
2147 res
= pXcvDataW(hXcv
, cmd_MonitorUIW
, NULL
, 0, buffer
, len
, &needed
, &status
);
2148 ok( res
&& (status
== ERROR_SUCCESS
),
2149 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2150 "ERROR_SUCCESS)\n", res
, GetLastError(), needed
, status
);
2155 /* ########################### */
2157 static void test_XcvDataW_PortIsValid(void)
2163 PRINTER_DEFAULTSA pd
;
2165 /* api is not present before w2k */
2166 if (pXcvDataW
== NULL
) return;
2168 pd
.pDatatype
= NULL
;
2170 pd
.DesiredAccess
= SERVER_ACCESS_ADMINISTER
;
2173 SetLastError(0xdeadbeef);
2174 res
= OpenPrinterA(xcv_localport
, &hXcv
, &pd
);
2175 if (is_spooler_deactivated(res
, GetLastError())) return;
2176 if (is_access_denied(res
, GetLastError())) return;
2178 ok(res
, "returned %d with %u and handle %p (expected '!= 0')\n", res
, GetLastError(), hXcv
);
2182 /* "PDWORD needed" is always required */
2183 needed
= (DWORD
) 0xdeadbeef;
2184 status
= (DWORD
) 0xdeadbeef;
2185 SetLastError(0xdeadbeef);
2186 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt1W
, sizeof(portname_lpt1W
), NULL
, 0, NULL
, &status
);
2187 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
2188 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2189 res
, GetLastError(), needed
, status
);
2191 /* an empty name is not allowed */
2192 needed
= (DWORD
) 0xdeadbeef;
2193 status
= (DWORD
) 0xdeadbeef;
2194 SetLastError(0xdeadbeef);
2195 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) emptyW
, sizeof(emptyW
), NULL
, 0, &needed
, &status
);
2196 ok( res
&& ((status
== ERROR_FILE_NOT_FOUND
) || (status
== ERROR_PATH_NOT_FOUND
)),
2197 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2198 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2199 res
, GetLastError(), needed
, status
);
2201 /* a directory is not allowed */
2202 needed
= (DWORD
) 0xdeadbeef;
2203 status
= (DWORD
) 0xdeadbeef;
2204 SetLastError(0xdeadbeef);
2205 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) tempdirW
, (lstrlenW(tempdirW
) + 1) * sizeof(WCHAR
), NULL
, 0, &needed
, &status
);
2206 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2207 ok( res
&& ((status
== ERROR_PATH_NOT_FOUND
) || (status
== ERROR_ACCESS_DENIED
)),
2208 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2209 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2210 res
, GetLastError(), needed
, status
);
2212 /* more valid well known ports */
2213 needed
= (DWORD
) 0xdeadbeef;
2214 status
= (DWORD
) 0xdeadbeef;
2215 SetLastError(0xdeadbeef);
2216 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt1W
, sizeof(portname_lpt1W
), NULL
, 0, &needed
, &status
);
2217 ok( res
&& (status
== ERROR_SUCCESS
),
2218 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2219 res
, GetLastError(), needed
, status
);
2221 needed
= (DWORD
) 0xdeadbeef;
2222 status
= (DWORD
) 0xdeadbeef;
2223 SetLastError(0xdeadbeef);
2224 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_lpt2W
, sizeof(portname_lpt2W
), NULL
, 0, &needed
, &status
);
2225 ok( res
&& (status
== ERROR_SUCCESS
),
2226 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2227 res
, GetLastError(), needed
, status
);
2229 needed
= (DWORD
) 0xdeadbeef;
2230 status
= (DWORD
) 0xdeadbeef;
2231 SetLastError(0xdeadbeef);
2232 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_com1W
, sizeof(portname_com1W
), NULL
, 0, &needed
, &status
);
2233 ok( res
&& (status
== ERROR_SUCCESS
),
2234 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2235 res
, GetLastError(), needed
, status
);
2237 needed
= (DWORD
) 0xdeadbeef;
2238 status
= (DWORD
) 0xdeadbeef;
2239 SetLastError(0xdeadbeef);
2240 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_com2W
, sizeof(portname_com2W
), NULL
, 0, &needed
, &status
);
2241 ok( res
&& (status
== ERROR_SUCCESS
),
2242 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2243 res
, GetLastError(), needed
, status
);
2245 needed
= (DWORD
) 0xdeadbeef;
2246 status
= (DWORD
) 0xdeadbeef;
2247 SetLastError(0xdeadbeef);
2248 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) portname_fileW
, sizeof(portname_fileW
), NULL
, 0, &needed
, &status
);
2249 ok( res
&& (status
== ERROR_SUCCESS
),
2250 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2251 res
, GetLastError(), needed
, status
);
2254 /* a normal, writable file is allowed */
2255 needed
= (DWORD
) 0xdeadbeef;
2256 status
= (DWORD
) 0xdeadbeef;
2257 SetLastError(0xdeadbeef);
2258 res
= pXcvDataW(hXcv
, cmd_PortIsValidW
, (PBYTE
) tempfileW
, (lstrlenW(tempfileW
) + 1) * sizeof(WCHAR
), NULL
, 0, &needed
, &status
);
2259 ok( res
&& (status
== ERROR_SUCCESS
),
2260 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2261 res
, GetLastError(), needed
, status
);
2266 /* ########################### */
2268 static void test_GetPrinter(void)
2274 DWORD needed
, filled
;
2276 if (!default_printer
)
2278 skip("There is no default printer installed\n");
2283 ret
= OpenPrinterA(default_printer
, &hprn
, NULL
);
2286 skip("Unable to open the default printer (%s)\n", default_printer
);
2289 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
2291 for (level
= 1; level
<= 9; level
++)
2293 SetLastError(0xdeadbeef);
2295 ret
= GetPrinterA(hprn
, level
, NULL
, 0, &needed
);
2298 win_skip("Level %d is not supported on Win9x/WinMe\n", level
);
2299 ok(GetLastError() == ERROR_SUCCESS
, "wrong error %d\n", GetLastError());
2300 ok(needed
== 0,"Expected 0, got %d\n", needed
);
2303 ok(!ret
, "level %d: GetPrinter should fail\n", level
);
2304 /* Not all levels are supported on all Windows-Versions */
2305 if (GetLastError() == ERROR_INVALID_LEVEL
||
2306 GetLastError() == ERROR_NOT_SUPPORTED
/* Win9x/WinMe */)
2308 skip("Level %d not supported\n", level
);
2311 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %d\n", GetLastError());
2312 ok(needed
> 0,"not expected needed buffer size %d\n", needed
);
2314 /* GetPrinterA returns the same number of bytes as GetPrinterW */
2315 if (!on_win9x
&& !ret
&& pGetPrinterW
&& level
!= 6 && level
!= 7)
2317 DWORD double_needed
;
2318 ret
= pGetPrinterW(hprn
, level
, NULL
, 0, &double_needed
);
2319 ok(!ret
, "level %d: GetPrinter error %d\n", level
, GetLastError());
2320 ok(double_needed
== needed
, "level %d: GetPrinterA returned different size %d than GetPrinterW (%d)\n", level
, needed
, double_needed
);
2323 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2325 SetLastError(0xdeadbeef);
2327 ret
= GetPrinterA(hprn
, level
, buf
, needed
, &filled
);
2328 ok(ret
, "level %d: GetPrinter error %d\n", level
, GetLastError());
2329 ok(needed
== filled
, "needed %d != filled %d\n", needed
, filled
);
2333 PRINTER_INFO_2A
*pi_2
= (PRINTER_INFO_2A
*)buf
;
2335 ok(pi_2
->pPrinterName
!= NULL
, "not expected NULL ptr\n");
2336 ok(pi_2
->pDriverName
!= NULL
, "not expected NULL ptr\n");
2338 trace("pPrinterName %s\n", pi_2
->pPrinterName
);
2339 trace("pDriverName %s\n", pi_2
->pDriverName
);
2342 HeapFree(GetProcessHeap(), 0, buf
);
2345 SetLastError(0xdeadbeef);
2346 ret
= ClosePrinter(hprn
);
2347 ok(ret
, "ClosePrinter error %d\n", GetLastError());
2350 /* ########################### */
2352 static void test_GetPrinterData(void)
2357 CHAR buffer
[MAX_PATH
+ 1];
2361 /* ToDo: test parameter validation, test with the default printer */
2363 SetLastError(0xdeadbeef);
2364 res
= OpenPrinterA(NULL
, &hprn
, NULL
);
2367 /* printserver not available on win9x */
2369 win_skip("Unable to open the printserver: %d\n", GetLastError());
2373 memset(buffer
, '#', sizeof(buffer
));
2374 buffer
[MAX_PATH
] = 0;
2376 needed
= 0xdeadbeef;
2377 SetLastError(0xdeadbeef);
2378 res
= GetPrinterDataA(hprn
, defaultspooldirectory
, &type
, (LPBYTE
) buffer
, sizeof(buffer
), &needed
);
2380 len
= lstrlenA(buffer
) + sizeof(CHAR
);
2381 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2382 ok( !res
&& (type
== REG_SZ
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2383 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2384 res
, type
, needed
, buffer
, len
);
2386 needed
= 0xdeadbeef;
2387 SetLastError(0xdeadbeef);
2388 res
= GetPrinterDataA(hprn
, defaultspooldirectory
, NULL
, NULL
, 0, &needed
);
2389 ok( (res
== ERROR_MORE_DATA
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2390 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res
, needed
, len
);
2392 /* ToDo: test SPLREG_* */
2394 SetLastError(0xdeadbeef);
2395 res
= ClosePrinter(hprn
);
2396 ok(res
, "ClosePrinter error %d\n", GetLastError());
2399 /* ########################### */
2401 static void test_GetPrinterDataEx(void)
2406 CHAR buffer
[MAX_PATH
+ 1];
2410 /* not present before w2k */
2411 if (!pGetPrinterDataExA
) {
2412 win_skip("GetPrinterDataEx not found\n");
2416 /* ToDo: test parameter validation, test with the default printer */
2418 SetLastError(0xdeadbeef);
2419 res
= OpenPrinterA(NULL
, &hprn
, NULL
);
2422 win_skip("Unable to open the printserver: %d\n", GetLastError());
2426 /* keyname is ignored, when hprn is a HANDLE for a printserver */
2427 memset(buffer
, '#', sizeof(buffer
));
2428 buffer
[MAX_PATH
] = 0;
2430 needed
= 0xdeadbeef;
2431 SetLastError(0xdeadbeef);
2432 res
= pGetPrinterDataExA(hprn
, NULL
, defaultspooldirectory
, &type
,
2433 (LPBYTE
) buffer
, sizeof(buffer
), &needed
);
2435 len
= lstrlenA(buffer
) + sizeof(CHAR
);
2436 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2437 ok( !res
&& (type
== REG_SZ
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2438 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2439 res
, type
, needed
, buffer
, len
);
2441 memset(buffer
, '#', sizeof(buffer
));
2442 buffer
[MAX_PATH
] = 0;
2444 needed
= 0xdeadbeef;
2445 SetLastError(0xdeadbeef);
2446 res
= pGetPrinterDataExA(hprn
, "", defaultspooldirectory
, &type
,
2447 (LPBYTE
) buffer
, sizeof(buffer
), &needed
);
2448 len
= lstrlenA(buffer
) + sizeof(CHAR
);
2449 ok( !res
&& (type
== REG_SZ
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2450 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2451 res
, type
, needed
, buffer
, len
);
2453 memset(buffer
, '#', sizeof(buffer
));
2454 buffer
[MAX_PATH
] = 0;
2456 needed
= 0xdeadbeef;
2457 SetLastError(0xdeadbeef);
2458 /* Wine uses GetPrinterDataEx with "PrinterDriverData" to implement GetPrinterData */
2459 res
= pGetPrinterDataExA(hprn
, "PrinterDriverData", defaultspooldirectory
,
2460 &type
, (LPBYTE
) buffer
, sizeof(buffer
), &needed
);
2461 len
= lstrlenA(buffer
) + sizeof(CHAR
);
2462 ok( !res
&& (type
== REG_SZ
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2463 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2464 res
, type
, needed
, buffer
, len
);
2467 memset(buffer
, '#', sizeof(buffer
));
2468 buffer
[MAX_PATH
] = 0;
2470 needed
= 0xdeadbeef;
2471 SetLastError(0xdeadbeef);
2472 res
= pGetPrinterDataExA(hprn
, does_not_exist
, defaultspooldirectory
, &type
,
2473 (LPBYTE
) buffer
, sizeof(buffer
), &needed
);
2474 len
= lstrlenA(buffer
) + sizeof(CHAR
);
2475 ok( !res
&& (type
== REG_SZ
) && ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2476 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d)\n",
2477 res
, type
, needed
, buffer
, len
);
2479 needed
= 0xdeadbeef;
2480 SetLastError(0xdeadbeef);
2481 /* vista and w2k8 have a bug in GetPrinterDataEx:
2482 the current LastError value is returned as result */
2483 res
= pGetPrinterDataExA(hprn
, NULL
, defaultspooldirectory
, NULL
, NULL
, 0, &needed
);
2484 ok( ((res
== ERROR_MORE_DATA
) || broken(res
== 0xdeadbeef)) &&
2485 ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2486 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res
, needed
, len
);
2488 needed
= 0xdeadbeef;
2489 SetLastError(0xdeaddead);
2490 res
= pGetPrinterDataExA(hprn
, NULL
, defaultspooldirectory
, NULL
, NULL
, 0, &needed
);
2491 ok( ((res
== ERROR_MORE_DATA
) || broken(res
== 0xdeaddead)) &&
2492 ((needed
== len
) || (needed
== (len
* sizeof(WCHAR
)))),
2493 "got %d, needed: %d (expected ERROR_MORE_DATA and %d)\n", res
, needed
, len
);
2495 SetLastError(0xdeadbeef);
2496 res
= ClosePrinter(hprn
);
2497 ok(res
, "ClosePrinter error %d\n", GetLastError());
2500 /* ########################### */
2502 static void test_GetPrinterDriver(void)
2508 DWORD needed
, filled
;
2510 if (!default_printer
)
2512 skip("There is no default printer installed\n");
2517 ret
= OpenPrinterA(default_printer
, &hprn
, NULL
);
2520 skip("Unable to open the default printer (%s)\n", default_printer
);
2523 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
2525 for (level
= -1; level
<= 7; level
++)
2527 SetLastError(0xdeadbeef);
2529 ret
= GetPrinterDriverA(hprn
, NULL
, level
, NULL
, 0, &needed
);
2530 ok(!ret
, "level %d: GetPrinterDriver should fail\n", level
);
2531 if (level
>= 1 && level
<= 6)
2533 /* Not all levels are supported on all Windows-Versions */
2534 if(GetLastError() == ERROR_INVALID_LEVEL
) continue;
2535 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %d\n", GetLastError());
2536 ok(needed
> 0,"not expected needed buffer size %d\n", needed
);
2540 /* ERROR_OUTOFMEMORY found on win9x */
2541 ok( ((GetLastError() == ERROR_INVALID_LEVEL
) ||
2542 (GetLastError() == ERROR_OUTOFMEMORY
)),
2543 "%d: returned %d with %d (expected '0' with: "
2544 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2545 level
, ret
, GetLastError());
2546 /* needed is modified in win9x. The modified Value depends on the
2547 default Printer. testing for "needed == (DWORD)-1" will fail */
2551 /* GetPrinterDriverA returns the same number of bytes as GetPrinterDriverW */
2552 if (!on_win9x
&& !ret
&& pGetPrinterDriverW
)
2554 DWORD double_needed
;
2555 ret
= pGetPrinterDriverW(hprn
, NULL
, level
, NULL
, 0, &double_needed
);
2556 ok(!ret
, "level %d: GetPrinterDriver error %d\n", level
, GetLastError());
2557 ok(double_needed
== needed
, "GetPrinterDriverA returned different size %d than GetPrinterDriverW (%d)\n", needed
, double_needed
);
2560 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
2562 SetLastError(0xdeadbeef);
2564 ret
= GetPrinterDriverA(hprn
, NULL
, level
, buf
, needed
, &filled
);
2565 ok(ret
, "level %d: GetPrinterDriver error %d\n", level
, GetLastError());
2566 ok(needed
== filled
, "needed %d != filled %d\n", needed
, filled
);
2570 DRIVER_INFO_2A
*di_2
= (DRIVER_INFO_2A
*)buf
;
2571 DWORD calculated
= sizeof(*di_2
);
2574 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2575 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k-win7(Usermode): 3, win8 and above(Usermode): 4 */
2576 ok( (di_2
->cVersion
<= 4) ||
2577 (di_2
->cVersion
== 0x0400), "di_2->cVersion = %d\n", di_2
->cVersion
);
2578 ok(di_2
->pName
!= NULL
, "not expected NULL ptr\n");
2579 ok(di_2
->pEnvironment
!= NULL
, "not expected NULL ptr\n");
2580 ok(di_2
->pDriverPath
!= NULL
, "not expected NULL ptr\n");
2581 ok(di_2
->pDataFile
!= NULL
, "not expected NULL ptr\n");
2582 ok(di_2
->pConfigFile
!= NULL
, "not expected NULL ptr\n");
2584 trace("cVersion %d\n", di_2
->cVersion
);
2585 trace("pName %s\n", di_2
->pName
);
2586 calculated
+= strlen(di_2
->pName
) + 1;
2587 trace("pEnvironment %s\n", di_2
->pEnvironment
);
2588 calculated
+= strlen(di_2
->pEnvironment
) + 1;
2589 trace("pDriverPath %s\n", di_2
->pDriverPath
);
2590 calculated
+= strlen(di_2
->pDriverPath
) + 1;
2591 trace("pDataFile %s\n", di_2
->pDataFile
);
2592 calculated
+= strlen(di_2
->pDataFile
) + 1;
2593 trace("pConfigFile %s\n", di_2
->pConfigFile
);
2594 calculated
+= strlen(di_2
->pConfigFile
) + 1;
2596 hf
= CreateFileA(di_2
->pDriverPath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2597 if(hf
!= INVALID_HANDLE_VALUE
)
2600 ok(hf
!= INVALID_HANDLE_VALUE
, "Could not open %s\n", di_2
->pDriverPath
);
2602 hf
= CreateFileA(di_2
->pDataFile
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2603 if(hf
!= INVALID_HANDLE_VALUE
)
2605 ok(hf
!= INVALID_HANDLE_VALUE
, "Could not open %s\n", di_2
->pDataFile
);
2607 hf
= CreateFileA(di_2
->pConfigFile
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2608 if(hf
!= INVALID_HANDLE_VALUE
)
2611 ok(hf
!= INVALID_HANDLE_VALUE
, "Could not open %s\n", di_2
->pConfigFile
);
2613 /* XP allocates memory for both ANSI and unicode names */
2614 ok(filled
>= calculated
,"calculated %d != filled %d\n", calculated
, filled
);
2616 /* Obscure test - demonstrate that Windows zero fills the buffer, even on failure */
2617 ret
= GetPrinterDriverA(hprn
, NULL
, level
, buf
, needed
- 2, &filled
);
2618 ok(!ret
, "level %d: GetPrinterDriver succeeded with less buffer than it should\n", level
);
2619 ok(di_2
->pDataFile
== NULL
||
2620 broken(di_2
->pDataFile
!= NULL
), /* Win9x/WinMe */
2621 "Even on failure, GetPrinterDriver clears the buffer to zeros\n");
2624 HeapFree(GetProcessHeap(), 0, buf
);
2627 SetLastError(0xdeadbeef);
2628 ret
= ClosePrinter(hprn
);
2629 ok(ret
, "ClosePrinter error %d\n", GetLastError());
2632 static void test_DEVMODEA(const DEVMODEA
*dm
, LONG dmSize
, LPCSTR exp_prn_name
)
2634 /* On NT3.51, some fields in DEVMODEA are empty/zero
2635 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2636 We skip the Tests on this Platform */
2637 if (dm
->dmSpecVersion
|| dm
->dmDriverVersion
|| dm
->dmDriverExtra
) {
2638 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2639 ok(!strncmp(exp_prn_name
, (LPCSTR
)dm
->dmDeviceName
, CCHDEVICENAME
-1) ||
2640 !strncmp(exp_prn_name
, (LPCSTR
)dm
->dmDeviceName
, CCHDEVICENAME
-2), /* XP+ */
2641 "expected '%s', got '%s'\n", exp_prn_name
, dm
->dmDeviceName
);
2642 ok(dm
->dmSize
+ dm
->dmDriverExtra
== dmSize
,
2643 "%u != %d\n", dm
->dmSize
+ dm
->dmDriverExtra
, dmSize
);
2645 trace("dmFields %08x\n", dm
->dmFields
);
2648 static void test_DocumentProperties(void)
2653 char empty_str
[] = "";
2655 if (!default_printer
)
2657 skip("There is no default printer installed\n");
2662 ret
= OpenPrinterA(default_printer
, &hprn
, NULL
);
2665 skip("Unable to open the default printer (%s)\n", default_printer
);
2668 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
2670 dm_size
= DocumentPropertiesA(0, hprn
, NULL
, NULL
, NULL
, 0);
2671 trace("DEVMODEA required size %d\n", dm_size
);
2672 ok(dm_size
>= sizeof(DEVMODEA
), "unexpected DocumentPropertiesA ret value %d\n", dm_size
);
2674 dm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dm_size
);
2676 ret
= DocumentPropertiesA(0, hprn
, NULL
, dm
, dm
, DM_OUT_BUFFER
);
2677 ok(ret
== IDOK
, "DocumentPropertiesA ret value %d != expected IDOK\n", ret
);
2679 ret
= DocumentPropertiesA(0, hprn
, empty_str
, dm
, dm
, DM_OUT_BUFFER
);
2680 ok(ret
== IDOK
, "DocumentPropertiesA ret value %d != expected IDOK\n", ret
);
2682 test_DEVMODEA(dm
, dm_size
, default_printer
);
2684 HeapFree(GetProcessHeap(), 0, dm
);
2686 SetLastError(0xdeadbeef);
2687 ret
= ClosePrinter(hprn
);
2688 ok(ret
, "ClosePrinter error %d\n", GetLastError());
2691 static void test_EnumPrinters(void)
2693 DWORD neededA
, neededW
, num
;
2696 SetLastError(0xdeadbeef);
2698 ret
= EnumPrintersA(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededA
, &num
);
2699 if (is_spooler_deactivated(ret
, GetLastError())) return;
2702 /* We have 1 or more printers */
2703 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
2704 ok(neededA
> 0, "Expected neededA to show the number of needed bytes\n");
2708 /* We don't have any printers defined */
2709 ok(GetLastError() == S_OK
, "gle %d\n", GetLastError());
2710 ok(neededA
== 0, "Expected neededA to be zero\n");
2712 ok(num
== 0, "num %d\n", num
);
2714 SetLastError(0xdeadbeef);
2716 ret
= EnumPrintersW(PRINTER_ENUM_LOCAL
, NULL
, 2, NULL
, 0, &neededW
, &num
);
2717 /* EnumPrintersW is not supported on all platforms */
2718 if (!ret
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
2720 win_skip("EnumPrintersW is not implemented\n");
2726 /* We have 1 or more printers */
2727 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "gle %d\n", GetLastError());
2728 ok(neededW
> 0, "Expected neededW to show the number of needed bytes\n");
2732 /* We don't have any printers defined */
2733 ok(GetLastError() == S_OK
, "gle %d\n", GetLastError());
2734 ok(neededW
== 0, "Expected neededW to be zero\n");
2736 ok(num
== 0, "num %d\n", num
);
2738 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2739 to hold the buffer returned by EnumPrintersW */
2740 ok(neededA
== neededW
, "neededA %d neededW %d\n", neededA
, neededW
);
2743 static void test_DeviceCapabilities(void)
2746 BOOL (WINAPI
*pPrintDlgA
)(PRINTDLGA
*);
2750 const char *driver
, *device
, *port
;
2758 INT n_papers
, n_paper_size
, n_paper_names
, n_copies
, ret
;
2761 hComdlg32
= LoadLibraryA("comdlg32.dll");
2763 pPrintDlgA
= (void *)GetProcAddress(hComdlg32
, "PrintDlgA");
2766 memset(&prn_dlg
, 0, sizeof(prn_dlg
));
2767 prn_dlg
.lStructSize
= sizeof(prn_dlg
);
2768 prn_dlg
.Flags
= PD_RETURNDEFAULT
;
2769 ret
= pPrintDlgA(&prn_dlg
);
2770 FreeLibrary(hComdlg32
);
2773 skip("PrintDlg returned no default printer\n");
2776 ok(prn_dlg
.hDevMode
!= 0, "PrintDlg returned hDevMode == NULL\n");
2777 ok(prn_dlg
.hDevNames
!= 0, "PrintDlg returned hDevNames == NULL\n");
2779 dm
= GlobalLock(prn_dlg
.hDevMode
);
2780 ok(dm
!= NULL
, "GlobalLock(prn_dlg.hDevMode) failed\n");
2781 trace("dmDeviceName \"%s\"\n", dm
->dmDeviceName
);
2783 dn
= GlobalLock(prn_dlg
.hDevNames
);
2784 ok(dn
!= NULL
, "GlobalLock(prn_dlg.hDevNames) failed\n");
2785 ok(dn
->wDriverOffset
, "expected not 0 wDriverOffset\n");
2786 ok(dn
->wDeviceOffset
, "expected not 0 wDeviceOffset\n");
2787 ok(dn
->wOutputOffset
, "expected not 0 wOutputOffset\n");
2788 ok(dn
->wDefault
== DN_DEFAULTPRN
, "expected DN_DEFAULTPRN got %x\n", dn
->wDefault
);
2789 driver
= (const char *)dn
+ dn
->wDriverOffset
;
2790 device
= (const char *)dn
+ dn
->wDeviceOffset
;
2791 port
= (const char *)dn
+ dn
->wOutputOffset
;
2792 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver
, device
, port
);
2794 test_DEVMODEA(dm
, dm
->dmSize
+ dm
->dmDriverExtra
, device
);
2796 n_papers
= DeviceCapabilitiesA(device
, port
, DC_PAPERS
, NULL
, NULL
);
2797 ok(n_papers
> 0, "DeviceCapabilitiesA DC_PAPERS failed\n");
2798 papers
= HeapAlloc(GetProcessHeap(), 0, sizeof(*papers
) * n_papers
);
2799 ret
= DeviceCapabilitiesA(device
, port
, DC_PAPERS
, (LPSTR
)papers
, NULL
);
2800 ok(ret
== n_papers
, "expected %d, got %d\n", n_papers
, ret
);
2802 for (ret
= 0; ret
< n_papers
; ret
++)
2803 trace("papers[%d] = %d\n", ret
, papers
[ret
]);
2805 HeapFree(GetProcessHeap(), 0, papers
);
2807 n_paper_size
= DeviceCapabilitiesA(device
, port
, DC_PAPERSIZE
, NULL
, NULL
);
2808 ok(n_paper_size
> 0, "DeviceCapabilitiesA DC_PAPERSIZE failed\n");
2809 ok(n_paper_size
== n_papers
, "n_paper_size %d != n_papers %d\n", n_paper_size
, n_papers
);
2810 paper_size
= HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size
) * n_paper_size
);
2811 ret
= DeviceCapabilitiesA(device
, port
, DC_PAPERSIZE
, (LPSTR
)paper_size
, NULL
);
2812 ok(ret
== n_paper_size
, "expected %d, got %d\n", n_paper_size
, ret
);
2814 for (ret
= 0; ret
< n_paper_size
; ret
++)
2815 trace("paper_size[%d] = %d x %d\n", ret
, paper_size
[ret
].x
, paper_size
[ret
].y
);
2817 HeapFree(GetProcessHeap(), 0, paper_size
);
2819 n_paper_names
= DeviceCapabilitiesA(device
, port
, DC_PAPERNAMES
, NULL
, NULL
);
2820 ok(n_paper_names
> 0, "DeviceCapabilitiesA DC_PAPERNAMES failed\n");
2821 ok(n_paper_names
== n_papers
, "n_paper_names %d != n_papers %d\n", n_paper_names
, n_papers
);
2822 paper_name
= HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name
) * n_paper_names
);
2823 ret
= DeviceCapabilitiesA(device
, port
, DC_PAPERNAMES
, (LPSTR
)paper_name
, NULL
);
2824 ok(ret
== n_paper_names
, "expected %d, got %d\n", n_paper_names
, ret
);
2826 for (ret
= 0; ret
< n_paper_names
; ret
++)
2827 trace("paper_name[%u] = %s\n", ret
, paper_name
[ret
].name
);
2829 HeapFree(GetProcessHeap(), 0, paper_name
);
2831 n_copies
= DeviceCapabilitiesA(device
, port
, DC_COPIES
, NULL
, dm
);
2832 ok(n_copies
> 0, "DeviceCapabilitiesA DC_COPIES failed\n");
2833 trace("n_copies = %d\n", n_copies
);
2835 /* these capabilities are not available on all printer drivers */
2838 ret
= DeviceCapabilitiesA(device
, port
, DC_MAXEXTENT
, NULL
, NULL
);
2839 ok(ret
!= -1, "DeviceCapabilitiesA DC_MAXEXTENT failed\n");
2840 ext
= MAKEPOINTS(ret
);
2841 trace("max ext = %d x %d\n", ext
.x
, ext
.y
);
2843 ret
= DeviceCapabilitiesA(device
, port
, DC_MINEXTENT
, NULL
, NULL
);
2844 ok(ret
!= -1, "DeviceCapabilitiesA DC_MINEXTENT failed\n");
2845 ext
= MAKEPOINTS(ret
);
2846 trace("min ext = %d x %d\n", ext
.x
, ext
.y
);
2849 fields
= DeviceCapabilitiesA(device
, port
, DC_FIELDS
, NULL
, NULL
);
2850 ok(fields
!= (DWORD
)-1, "DeviceCapabilitiesA DC_FIELDS failed\n");
2851 ok(fields
== (dm
->dmFields
| DM_FORMNAME
) ||
2852 fields
== ((dm
->dmFields
| DM_FORMNAME
| DM_PAPERSIZE
) & ~(DM_PAPERLENGTH
|DM_PAPERWIDTH
)) ||
2853 broken(fields
== dm
->dmFields
), /* Win9x/WinMe */
2854 "fields %x, dm->dmFields %x\n", fields
, dm
->dmFields
);
2856 GlobalUnlock(prn_dlg
.hDevMode
);
2857 GlobalFree(prn_dlg
.hDevMode
);
2858 GlobalUnlock(prn_dlg
.hDevNames
);
2859 GlobalFree(prn_dlg
.hDevNames
);
2862 static void test_IsValidDevmodeW(void)
2866 if (!pIsValidDevmodeW
)
2868 win_skip("IsValidDevmodeW not implemented.\n");
2872 br
= pIsValidDevmodeW(NULL
, 0);
2873 ok(br
== FALSE
, "Got %d\n", br
);
2875 br
= pIsValidDevmodeW(NULL
, 1);
2876 ok(br
== FALSE
, "Got %d\n", br
);
2878 br
= pIsValidDevmodeW(NULL
, sizeof(DEVMODEW
));
2879 ok(br
== FALSE
, "Got %d\n", br
);
2882 static void test_OpenPrinter_defaults(void)
2888 ADDJOB_INFO_1A
*add_job
;
2889 JOB_INFO_2A
*job_info
;
2891 PRINTER_DEFAULTSA prn_def
;
2892 PRINTER_INFO_2A
*pi
;
2894 if (!default_printer
)
2896 skip("There is no default printer installed\n");
2900 /* Printer opened with NULL defaults. Retrieve default paper size
2901 and confirm that jobs have this size. */
2903 ret
= OpenPrinterA( default_printer
, &printer
, NULL
);
2906 skip("Unable to open the default printer (%s)\n", default_printer
);
2910 ret
= GetPrinterA( printer
, 2, NULL
, 0, &needed
);
2911 ok( !ret
, "got %d\n", ret
);
2912 pi
= HeapAlloc( GetProcessHeap(), 0, needed
);
2913 ret
= GetPrinterA( printer
, 2, (BYTE
*)pi
, needed
, &needed
);
2914 ok( ret
, "GetPrinterA() failed le=%d\n", GetLastError() );
2915 default_size
= pi
->pDevMode
->u1
.s1
.dmPaperSize
;
2916 HeapFree( GetProcessHeap(), 0, pi
);
2919 SetLastError( 0xdeadbeef );
2920 ret
= AddJobA( printer
, 1, NULL
, 0, &needed
);
2921 ok( !ret
, "got %d\n", ret
);
2922 if (GetLastError() == ERROR_NOT_SUPPORTED
) /* win8 */
2924 win_skip( "AddJob is not supported on this platform\n" );
2925 ClosePrinter( printer
);
2928 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError() );
2929 ok( needed
> sizeof(ADDJOB_INFO_1A
), "AddJob needs %u bytes\n", needed
);
2930 add_job
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, needed
);
2931 ret
= AddJobA( printer
, 1, (BYTE
*)add_job
, needed
, &needed
);
2932 ok( ret
, "AddJobA() failed le=%d\n", GetLastError() );
2934 ret
= GetJobA( printer
, add_job
->JobId
, 2, NULL
, 0, &needed
);
2935 ok( !ret
, "got %d\n", ret
);
2936 job_info
= HeapAlloc( GetProcessHeap(), 0, needed
);
2937 ret
= GetJobA( printer
, add_job
->JobId
, 2, (BYTE
*)job_info
, needed
, &needed
);
2938 ok( ret
, "GetJobA() failed le=%d\n", GetLastError() );
2941 ok( job_info
->pDevMode
!= NULL
, "got NULL DEVMODEA\n");
2942 if (job_info
->pDevMode
)
2943 ok( job_info
->pDevMode
->u1
.s1
.dmPaperSize
== default_size
, "got %d default %d\n",
2944 job_info
->pDevMode
->u1
.s1
.dmPaperSize
, default_size
);
2946 HeapFree( GetProcessHeap(), 0, job_info
);
2947 ScheduleJob( printer
, add_job
->JobId
); /* remove the empty job */
2948 HeapFree( GetProcessHeap(), 0, add_job
);
2949 ClosePrinter( printer
);
2951 /* Printer opened with something other than the default paper size. */
2953 memset( &my_dm
, 0, sizeof(my_dm
) );
2954 my_dm
.dmSize
= sizeof(my_dm
);
2955 my_dm
.dmFields
= DM_PAPERSIZE
;
2956 my_dm
.u1
.s1
.dmPaperSize
= (default_size
== DMPAPER_A4
) ? DMPAPER_LETTER
: DMPAPER_A4
;
2958 prn_def
.pDatatype
= NULL
;
2959 prn_def
.pDevMode
= &my_dm
;
2960 prn_def
.DesiredAccess
= PRINTER_ACCESS_USE
;
2962 ret
= OpenPrinterA( default_printer
, &printer
, &prn_def
);
2963 ok( ret
, "OpenPrinterA() failed le=%d\n", GetLastError() );
2965 /* GetPrinter stills returns default size */
2966 ret
= GetPrinterA( printer
, 2, NULL
, 0, &needed
);
2967 ok( !ret
, "got %d\n", ret
);
2968 pi
= HeapAlloc( GetProcessHeap(), 0, needed
);
2969 ret
= GetPrinterA( printer
, 2, (BYTE
*)pi
, needed
, &needed
);
2970 ok( ret
, "GetPrinterA() failed le=%d\n", GetLastError() );
2971 ok( pi
->pDevMode
->u1
.s1
.dmPaperSize
== default_size
, "got %d default %d\n",
2972 pi
->pDevMode
->u1
.s1
.dmPaperSize
, default_size
);
2974 HeapFree( GetProcessHeap(), 0, pi
);
2976 /* However the GetJobA has the new size */
2977 ret
= AddJobA( printer
, 1, NULL
, 0, &needed
);
2978 ok( !ret
, "got %d\n", ret
);
2979 add_job
= HeapAlloc( GetProcessHeap(), 0, needed
);
2980 ret
= AddJobA( printer
, 1, (BYTE
*)add_job
, needed
, &needed
);
2981 ok( ret
, "AddJobA() failed le=%d\n", GetLastError() );
2983 ret
= GetJobA( printer
, add_job
->JobId
, 2, NULL
, 0, &needed
);
2984 ok( !ret
, "got %d\n", ret
);
2985 job_info
= HeapAlloc( GetProcessHeap(), 0, needed
);
2986 ret
= GetJobA( printer
, add_job
->JobId
, 2, (BYTE
*)job_info
, needed
, &needed
);
2987 ok( ret
, "GetJobA() failed le=%d\n", GetLastError() );
2989 ok( job_info
->pDevMode
->dmFields
== DM_PAPERSIZE
, "got %08x\n",
2990 job_info
->pDevMode
->dmFields
);
2991 ok( job_info
->pDevMode
->u1
.s1
.dmPaperSize
== my_dm
.u1
.s1
.dmPaperSize
,
2992 "got %d new size %d\n",
2993 job_info
->pDevMode
->u1
.s1
.dmPaperSize
, my_dm
.u1
.s1
.dmPaperSize
);
2995 HeapFree( GetProcessHeap(), 0, job_info
);
2996 ScheduleJob( printer
, add_job
->JobId
); /* remove the empty job */
2997 HeapFree( GetProcessHeap(), 0, add_job
);
2998 ClosePrinter( printer
);
3003 hwinspool
= LoadLibraryA("winspool.drv");
3004 pAddPortExA
= (void *) GetProcAddress(hwinspool
, "AddPortExA");
3005 pEnumPrinterDriversW
= (void *) GetProcAddress(hwinspool
, "EnumPrinterDriversW");
3006 pGetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "GetDefaultPrinterA");
3007 pGetPrinterDataExA
= (void *) GetProcAddress(hwinspool
, "GetPrinterDataExA");
3008 pGetPrinterDriverW
= (void *) GetProcAddress(hwinspool
, "GetPrinterDriverW");
3009 pGetPrinterW
= (void *) GetProcAddress(hwinspool
, "GetPrinterW");
3010 pSetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "SetDefaultPrinterA");
3011 pXcvDataW
= (void *) GetProcAddress(hwinspool
, "XcvDataW");
3012 pIsValidDevmodeW
= (void *) GetProcAddress(hwinspool
, "IsValidDevmodeW");
3014 on_win9x
= check_win9x();
3016 win_skip("Several W-functions are not available on Win9x/WinMe\n");
3018 find_default_printer();
3019 find_local_server();
3025 test_ConfigurePort();
3026 test_DeleteMonitor();
3028 test_DeviceCapabilities();
3029 test_DocumentProperties();
3030 test_EnumForms(NULL
);
3031 if (default_printer
) test_EnumForms(default_printer
);
3032 test_EnumMonitors();
3034 test_EnumPrinterDrivers();
3035 test_EnumPrinters();
3036 test_EnumPrintProcessors();
3037 test_GetDefaultPrinter();
3038 test_GetPrinterDriverDirectory();
3039 test_GetPrintProcessorDirectory();
3042 test_GetPrinterData();
3043 test_GetPrinterDataEx();
3044 test_GetPrinterDriver();
3045 test_SetDefaultPrinter();
3046 test_XcvDataW_MonitorUI();
3047 test_XcvDataW_PortIsValid();
3048 test_IsValidDevmodeW();
3049 test_OpenPrinter_defaults();
3051 /* Cleanup our temporary file */
3052 DeleteFileA(tempfileA
);