winspool/tests: Handle the Windows bug in GetPrinterDataEx.
[wine.git] / dlls / winspool.drv / tests / info.c
blobb81bde44fee44c9bdf3eafd241775891a6fe7939
1 /*
2 * Copyright (C) 2003, 2004 Stefan Leichter
3 * Copyright (C) 2005, 2006 Detlef Riekenberg
4 * Copyright (C) 2006 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <assert.h>
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "winuser.h"
33 #include "winreg.h"
34 #include "winspool.h"
35 #include "commdlg.h"
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 WCHAR cmd_MonitorUIW[] = {'M','o','n','i','t','o','r','U','I',0};
60 static 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);
80 /* ################################ */
82 struct monitor_entry {
83 LPSTR env;
84 CHAR dllname[32];
87 static LPSTR default_printer = NULL;
88 static LPSTR local_server = NULL;
89 static LPSTR tempdirA = NULL;
90 static LPSTR tempfileA = NULL;
91 static LPWSTR tempdirW = NULL;
92 static LPWSTR tempfileW = NULL;
94 /* ################################ */
95 /* report common behavior only once */
96 static DWORD deactivated_spooler_reported = 0;
97 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
98 if ((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
99 { \
100 if (!deactivated_spooler_reported) { \
101 deactivated_spooler_reported++; \
102 skip("The Service 'Spooler' is required for many test\n"); \
104 return; \
107 static DWORD access_denied_reported = 0;
108 #define RETURN_ON_ACCESS_DENIED(res) \
109 if ((res == 0) && (GetLastError() == ERROR_ACCESS_DENIED)) \
111 if (!access_denied_reported) { \
112 access_denied_reported++; \
113 skip("More Access-Rights are required for many test\n"); \
115 return; \
118 /* ################################ */
120 static BOOL on_win9x = FALSE;
122 static BOOL check_win9x(void)
124 if (pGetPrinterW)
126 SetLastError(0xdeadbeef);
127 pGetPrinterW(NULL, 0, NULL, 0, NULL);
128 return (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
130 else
132 return TRUE;
136 static void find_default_printer(VOID)
138 static char buffer[DEFAULT_PRINTER_SIZE];
139 DWORD needed;
140 DWORD res;
141 LPSTR ptr;
143 if ((default_printer == NULL) && (pGetDefaultPrinterA))
145 /* w2k and above */
146 needed = sizeof(buffer);
147 res = pGetDefaultPrinterA(buffer, &needed);
148 if(res) default_printer = buffer;
149 trace("default_printer: '%s'\n", default_printer);
151 if (default_printer == NULL)
153 HKEY hwindows;
154 DWORD type;
155 /* NT 3.x and above */
156 if (RegOpenKeyEx(HKEY_CURRENT_USER,
157 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
158 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
160 needed = sizeof(buffer);
161 if (RegQueryValueEx(hwindows, "device", NULL,
162 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
164 ptr = strchr(buffer, ',');
165 if (ptr) {
166 ptr[0] = '\0';
167 default_printer = buffer;
170 RegCloseKey(hwindows);
172 trace("default_printer: '%s'\n", default_printer);
174 if (default_printer == NULL)
176 /* win9x */
177 needed = sizeof(buffer);
178 res = GetProfileStringA("windows", "device", "*", buffer, needed);
179 if(res) {
180 ptr = strchr(buffer, ',');
181 if (ptr) {
182 ptr[0] = '\0';
183 default_printer = buffer;
186 trace("default_printer: '%s'\n", default_printer);
191 static struct monitor_entry * find_installed_monitor(void)
193 MONITOR_INFO_2A mi2a;
194 static struct monitor_entry * entry = NULL;
195 DWORD num_tests;
196 DWORD i = 0;
198 static struct monitor_entry monitor_table[] = {
199 {env_win9x_case, "localspl.dll"},
200 {env_x86, "localspl.dll"},
201 {env_x64, "localspl.dll"},
202 {env_win9x_case, "localmon.dll"},
203 {env_x86, "localmon.dll"},
204 {env_win9x_case, "tcpmon.dll"},
205 {env_x86, "tcpmon.dll"},
206 {env_win9x_case, "usbmon.dll"},
207 {env_x86, "usbmon.dll"},
208 {env_win9x_case, "mspp32.dll"},
209 {env_x86, "win32spl.dll"},
210 {env_x86, "redmonnt.dll"},
211 {env_x86, "redmon35.dll"},
212 {env_win9x_case, "redmon95.dll"},
213 {env_x86, "pdfcmnnt.dll"},
214 {env_win9x_case, "pdfcmn95.dll"},
217 if (entry) return entry;
219 num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
221 /* cleanup */
222 DeleteMonitorA(NULL, env_x64, winetest);
223 DeleteMonitorA(NULL, env_x86, winetest);
224 DeleteMonitorA(NULL, env_win9x_case, winetest);
226 /* find a usable monitor from the table */
227 mi2a.pName = winetest;
228 while ((entry == NULL) && (i < num_tests)) {
229 entry = &monitor_table[i];
230 i++;
231 mi2a.pEnvironment = entry->env;
232 mi2a.pDLLName = entry->dllname;
234 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
235 /* we got one */
236 trace("using '%s', '%s'\n", entry->env, entry->dllname);
237 DeleteMonitorA(NULL, entry->env, winetest);
239 else
241 entry = NULL;
244 return entry;
248 /* ########################### */
250 static void find_local_server(VOID)
252 static char buffer[MAX_PATH];
253 DWORD res;
254 DWORD size;
256 size = sizeof(buffer) - 3 ;
257 buffer[0] = '\\';
258 buffer[1] = '\\';
259 buffer[2] = '\0';
261 SetLastError(0xdeadbeef);
262 res = GetComputerNameA(&buffer[2], &size);
263 trace("returned %d with %d and %d: '%s'\n", res, GetLastError(), size, buffer);
265 ok( res != 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
266 res, GetLastError(), size, buffer);
268 if (res) local_server = buffer;
271 /* ########################### */
273 static void find_tempfile(VOID)
275 static CHAR buffer_dirA[MAX_PATH];
276 static CHAR buffer_fileA[MAX_PATH];
277 static WCHAR buffer_dirW[MAX_PATH];
278 static WCHAR buffer_fileW[MAX_PATH];
279 DWORD res;
280 int resint;
282 memset(buffer_dirA, 0, MAX_PATH - 1);
283 buffer_dirA[MAX_PATH - 1] = '\0';
284 SetLastError(0xdeadbeef);
285 res = GetTempPathA(MAX_PATH, buffer_dirA);
286 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
287 if (res == 0) return;
289 memset(buffer_fileA, 0, MAX_PATH - 1);
290 buffer_fileA[MAX_PATH - 1] = '\0';
291 SetLastError(0xdeadbeef);
292 res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
293 ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
294 if (res == 0) return;
296 SetLastError(0xdeadbeef);
297 resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
298 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
299 if (resint == 0) return;
301 SetLastError(0xdeadbeef);
302 resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
303 ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
304 if (resint == 0) return;
306 tempdirA = buffer_dirA;
307 tempfileA = buffer_fileA;
308 tempdirW = buffer_dirW;
309 tempfileW = buffer_fileW;
310 trace("tempfile: '%s'\n", tempfileA);
313 /* ########################### */
315 static void test_AddMonitor(void)
317 MONITOR_INFO_2A mi2a;
318 struct monitor_entry * entry = NULL;
319 DWORD res;
321 entry = find_installed_monitor();
323 SetLastError(MAGIC_DEAD);
324 res = AddMonitorA(NULL, 1, NULL);
325 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
326 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
327 res, GetLastError());
329 SetLastError(MAGIC_DEAD);
330 res = AddMonitorA(NULL, 3, NULL);
331 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
332 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
333 res, GetLastError());
335 if (0)
337 /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
338 SetLastError(MAGIC_DEAD);
339 res = AddMonitorA(NULL, 2, NULL);
340 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
341 ok(!res &&
342 ((GetLastError() == MAGIC_DEAD) ||
343 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
344 "returned %d with %d (expected '0' with: MAGIC_DEAD or "
345 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
348 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
349 SetLastError(MAGIC_DEAD);
350 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
351 RETURN_ON_DEACTIVATED_SPOOLER(res)
352 RETURN_ON_ACCESS_DENIED(res)
354 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
355 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
356 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
357 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
358 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
360 if (!entry) {
361 skip("No usable Monitor found\n");
362 return;
365 if (0)
367 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
368 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
369 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
370 is created on win9x and we do not want to hit this bug here. */
372 mi2a.pEnvironment = entry->env;
373 SetLastError(MAGIC_DEAD);
374 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
375 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
378 mi2a.pEnvironment = entry->env;
379 mi2a.pName = empty;
380 SetLastError(MAGIC_DEAD);
381 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
382 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
383 ok( !res &&
384 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
385 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
386 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
387 "ERROR_PRIVILEGE_NOT_HELD)\n",
388 res, GetLastError());
390 mi2a.pName = winetest;
391 SetLastError(MAGIC_DEAD);
392 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
393 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
394 ok( !res &&
395 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
396 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
397 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
398 "ERROR_PRIVILEGE_NOT_HELD)\n",
399 res, GetLastError());
401 mi2a.pDLLName = empty;
402 SetLastError(MAGIC_DEAD);
403 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
404 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
405 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
406 res, GetLastError());
408 mi2a.pDLLName = does_not_exist_dll;
409 SetLastError(MAGIC_DEAD);
410 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
411 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
412 ok( !res &&
413 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
414 (GetLastError() == ERROR_INVALID_PARAMETER)),
415 "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
416 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
418 mi2a.pDLLName = version_dll;
419 SetLastError(MAGIC_DEAD);
420 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
421 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
422 ok( !res &&
423 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
424 (GetLastError() == ERROR_INVALID_PARAMETER)),
425 "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
426 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
427 if (res) DeleteMonitorA(NULL, entry->env, winetest);
429 /* Test AddMonitor with real options */
430 mi2a.pDLLName = entry->dllname;
431 SetLastError(MAGIC_DEAD);
432 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
433 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
435 /* add a monitor twice */
436 SetLastError(MAGIC_DEAD);
437 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
438 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
439 ok( !res &&
440 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
441 (GetLastError() == ERROR_ALREADY_EXISTS)),
442 "returned %d with %d (expected '0' with: "
443 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
444 res, GetLastError());
446 DeleteMonitorA(NULL, entry->env, winetest);
447 SetLastError(MAGIC_DEAD);
448 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
449 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
451 /* cleanup */
452 DeleteMonitorA(NULL, entry->env, winetest);
456 /* ########################### */
458 static void test_AddPort(void)
460 DWORD res;
462 SetLastError(0xdeadbeef);
463 res = AddPortA(NULL, 0, NULL);
464 RETURN_ON_DEACTIVATED_SPOOLER(res)
465 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
466 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
467 (GetLastError() == ERROR_INVALID_PARAMETER)),
468 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
469 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
472 SetLastError(0xdeadbeef);
473 res = AddPortA(NULL, 0, empty);
474 /* Allowed only for (Printer-)Administrators */
475 RETURN_ON_ACCESS_DENIED(res)
477 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
478 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
479 (GetLastError() == ERROR_INVALID_PARAMETER)),
480 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
481 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
484 SetLastError(0xdeadbeef);
485 res = AddPortA(NULL, 0, does_not_exist);
486 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
487 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
488 (GetLastError() == ERROR_INVALID_PARAMETER)),
489 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
490 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
494 /* ########################### */
496 static void test_AddPortEx(void)
498 PORT_INFO_2A pi;
499 DWORD res;
502 if (!pAddPortExA) {
503 win_skip("AddPortEx not supported\n");
504 return;
507 /* start test with a clean system */
508 DeletePortA(NULL, 0, tempfileA);
510 pi.pPortName = tempfileA;
511 SetLastError(0xdeadbeef);
512 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
513 RETURN_ON_DEACTIVATED_SPOOLER(res)
515 /* Allowed only for (Printer-)Administrators.
516 W2K+XP: ERROR_INVALID_PARAMETER */
517 if (!res && (GetLastError() == ERROR_INVALID_PARAMETER)) {
518 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
519 return;
521 ok( res, "got %u with %u (expected '!= 0')\n", res, GetLastError());
523 /* Add a port, that already exist */
524 SetLastError(0xdeadbeef);
525 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
526 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
527 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
528 res, GetLastError());
529 DeletePortA(NULL, 0, tempfileA);
532 /* the Monitorname must match */
533 SetLastError(0xdeadbeef);
534 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, NULL);
535 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
536 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
537 res, GetLastError());
538 if (res) DeletePortA(NULL, 0, tempfileA);
540 SetLastError(0xdeadbeef);
541 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, empty);
542 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
543 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
544 res, GetLastError());
545 if (res) DeletePortA(NULL, 0, tempfileA);
547 SetLastError(0xdeadbeef);
548 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, does_not_exist);
549 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
550 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
551 res, GetLastError());
552 if (res) DeletePortA(NULL, 0, tempfileA);
555 /* We need a Portname */
556 SetLastError(0xdeadbeef);
557 res = pAddPortExA(NULL, 1, NULL, LocalPortA);
558 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
559 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
560 res, GetLastError());
562 pi.pPortName = NULL;
563 SetLastError(0xdeadbeef);
564 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
565 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
566 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
567 res, GetLastError());
568 if (res) DeletePortA(NULL, 0, tempfileA);
571 /* level 2 is documented as supported for Printmonitors,
572 but that is not supported for "Local Port" (localspl.dll) and
573 AddPortEx fails with ERROR_INVALID_LEVEL */
575 pi.pPortName = tempfileA;
576 pi.pMonitorName = LocalPortA;
577 pi.pDescription = winetest;
578 pi.fPortType = PORT_TYPE_WRITE;
580 SetLastError(0xdeadbeef);
581 res = pAddPortExA(NULL, 2, (LPBYTE) &pi, LocalPortA);
582 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
583 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
584 res, GetLastError());
585 if (res) DeletePortA(NULL, 0, tempfileA);
588 /* invalid levels */
589 SetLastError(0xdeadbeef);
590 res = pAddPortExA(NULL, 0, (LPBYTE) &pi, LocalPortA);
591 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
592 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
593 res, GetLastError());
595 SetLastError(0xdeadbeef);
596 res = pAddPortExA(NULL, 3, (LPBYTE) &pi, LocalPortA);
597 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
598 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
599 res, GetLastError());
602 /* cleanup */
603 DeletePortA(NULL, 0, tempfileA);
607 /* ########################### */
609 static void test_ConfigurePort(void)
611 DWORD res;
614 SetLastError(0xdeadbeef);
615 res = ConfigurePortA(NULL, 0, NULL);
616 RETURN_ON_DEACTIVATED_SPOOLER(res)
617 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
618 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
619 (GetLastError() == ERROR_INVALID_PARAMETER)),
620 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
621 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
623 SetLastError(0xdeadbeef);
624 res = ConfigurePortA(NULL, 0, empty);
625 /* Allowed only for (Printer-)Administrators */
626 RETURN_ON_ACCESS_DENIED(res)
628 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
629 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
630 (GetLastError() == ERROR_INVALID_PARAMETER)),
631 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
632 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
635 SetLastError(0xdeadbeef);
636 res = ConfigurePortA(NULL, 0, does_not_exist);
637 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
638 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
639 (GetLastError() == ERROR_INVALID_PARAMETER)),
640 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
641 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
644 /* Testing-Results:
645 - Case of Portnames is ignored
646 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
647 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
649 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
650 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
651 - Cancel ("Local Port") => ERROR_CANCELED
652 - Cancel ("Redirected Port") => Success
654 if (winetest_interactive > 0) {
655 SetLastError(0xdeadbeef);
656 res = ConfigurePortA(NULL, 0, portname_com1);
657 trace("'%s' returned %d with %d\n", portname_com1, res, GetLastError());
659 SetLastError(0xdeadbeef);
660 res = ConfigurePortA(NULL, 0, portname_lpt1);
661 trace("'%s' returned %d with %d\n", portname_lpt1, res, GetLastError());
663 SetLastError(0xdeadbeef);
664 res = ConfigurePortA(NULL, 0, portname_file);
665 trace("'%s' returned %d with %d\n", portname_file, res, GetLastError());
669 /* ########################### */
671 static void test_DeleteMonitor(void)
673 MONITOR_INFO_2A mi2a;
674 struct monitor_entry * entry = NULL;
675 DWORD res;
678 entry = find_installed_monitor();
680 if (!entry) {
681 skip("No usable Monitor found\n");
682 return;
685 mi2a.pName = winetest;
686 mi2a.pEnvironment = entry->env;
687 mi2a.pDLLName = entry->dllname;
689 /* Testing DeleteMonitor with real options */
690 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
692 SetLastError(MAGIC_DEAD);
693 res = DeleteMonitorA(NULL, entry->env, winetest);
694 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
696 /* Delete the Monitor twice */
697 SetLastError(MAGIC_DEAD);
698 res = DeleteMonitorA(NULL, entry->env, winetest);
699 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
700 ok( !res &&
701 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
702 (GetLastError() == ERROR_INVALID_PARAMETER)),
703 "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
704 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
706 /* the environment */
707 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
708 SetLastError(MAGIC_DEAD);
709 res = DeleteMonitorA(NULL, NULL, winetest);
710 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
712 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
713 SetLastError(MAGIC_DEAD);
714 res = DeleteMonitorA(NULL, empty, winetest);
715 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
717 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
718 SetLastError(MAGIC_DEAD);
719 res = DeleteMonitorA(NULL, invalid_env, winetest);
720 ok( res ||
721 (!res && GetLastError() == ERROR_INVALID_ENVIRONMENT) /* Vista/W2K8 */,
722 "returned %d with %d\n", res, GetLastError());
724 /* the monitor-name */
725 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
726 SetLastError(MAGIC_DEAD);
727 res = DeleteMonitorA(NULL, entry->env, NULL);
728 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
729 ok( !res &&
730 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
731 (GetLastError() == ERROR_INVALID_NAME)),
732 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
733 "ERROR_INVALID_NAME)\n", res, GetLastError());
735 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
736 SetLastError(MAGIC_DEAD);
737 res = DeleteMonitorA(NULL, entry->env, empty);
738 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
739 ok( !res &&
740 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
741 (GetLastError() == ERROR_INVALID_NAME)),
742 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
743 "ERROR_INVALID_NAME)\n", res, GetLastError());
745 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
746 SetLastError(MAGIC_DEAD);
747 res = DeleteMonitorA(empty, entry->env, winetest);
748 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
750 /* cleanup */
751 DeleteMonitorA(NULL, entry->env, winetest);
754 /* ########################### */
756 static void test_DeletePort(void)
758 DWORD res;
760 SetLastError(0xdeadbeef);
761 res = DeletePortA(NULL, 0, NULL);
762 RETURN_ON_DEACTIVATED_SPOOLER(res)
764 SetLastError(0xdeadbeef);
765 res = DeletePortA(NULL, 0, empty);
766 /* Allowed only for (Printer-)Administrators */
767 RETURN_ON_ACCESS_DENIED(res)
769 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
770 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
771 (GetLastError() == ERROR_INVALID_PARAMETER)),
772 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
773 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
776 SetLastError(0xdeadbeef);
777 res = DeletePortA(NULL, 0, does_not_exist);
778 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
779 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
780 (GetLastError() == ERROR_INVALID_PARAMETER)),
781 "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
782 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
786 /* ########################### */
788 static void test_EnumForms(LPSTR pName)
790 DWORD res;
791 HANDLE hprinter = 0;
792 LPBYTE buffer;
793 DWORD cbBuf;
794 DWORD pcbNeeded;
795 DWORD pcReturned;
796 DWORD level;
797 UINT i;
798 const char *formtype;
799 static const char * const formtypes[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
800 #define FORMTYPE_MAX 2
801 PFORM_INFO_1A pFI_1a;
802 PFORM_INFO_2A pFI_2a;
804 res = OpenPrinter(pName, &hprinter, NULL);
805 RETURN_ON_DEACTIVATED_SPOOLER(res)
806 if (!res || !hprinter)
808 /* Open the local Prinserver is not supported on win9x */
809 if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
810 return;
813 /* valid levels are 1 and 2 */
814 for(level = 0; level < 4; level++) {
815 cbBuf = 0xdeadbeef;
816 pcReturned = 0xdeadbeef;
817 SetLastError(0xdeadbeef);
818 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
820 /* EnumForms is not implemented in win9x */
821 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
823 /* EnumForms for the Server not implemented on all NT-Versions */
824 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
826 /* Level 2 for EnumForms is not supported on all systems */
827 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
829 /* use only a short test, when we test with an invalid level */
830 if(!level || (level > 2)) {
831 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
832 (res && (pcReturned == 0)),
833 "(%d) returned %d with %d and 0x%08x (expected '0' with "
834 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
835 level, res, GetLastError(), pcReturned);
836 continue;
839 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
840 "(%d) returned %d with %d (expected '0' with "
841 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
843 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
844 if (buffer == NULL) continue;
846 SetLastError(0xdeadbeef);
847 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
848 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
849 level, res, GetLastError());
851 if (winetest_debug > 1) {
852 trace("dumping %d forms level %d\n", pcReturned, level);
853 pFI_1a = (PFORM_INFO_1A)buffer;
854 pFI_2a = (PFORM_INFO_2A)buffer;
855 for (i = 0; i < pcReturned; i++)
857 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
858 formtype = (pFI_1a->Flags <= FORMTYPE_MAX) ? formtypes[pFI_1a->Flags] : formtypes[3];
859 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i, pFI_1a->pName,
860 (float)pFI_1a->Size.cx/1000, (float)pFI_1a->Size.cy/1000, formtype);
862 if (level == 1) pFI_1a ++;
863 else {
864 /* output additional FORM_INFO_2 fields */
865 trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
866 pFI_2a->pKeyword, pFI_2a->StringType, pFI_2a->pMuiDll,
867 pFI_2a->dwResourceId, pFI_2a->pDisplayName, pFI_2a->wLangId);
869 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
870 pFI_2a ++;
871 pFI_1a = (PFORM_INFO_1A)pFI_2a;
876 SetLastError(0xdeadbeef);
877 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
878 ok( res, "(%d) returned %d with %d (expected '!=0')\n",
879 level, res, GetLastError());
881 SetLastError(0xdeadbeef);
882 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
883 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
884 "(%d) returned %d with %d (expected '0' with "
885 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
888 SetLastError(0xdeadbeef);
889 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
890 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
891 "(%d) returned %d with %d (expected '0' with "
892 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
895 SetLastError(0xdeadbeef);
896 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
897 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
898 "(%d) returned %d with %d (expected '0' with "
899 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
901 SetLastError(0xdeadbeef);
902 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
903 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
904 "(%d) returned %d with %d (expected '0' with "
905 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
907 SetLastError(0xdeadbeef);
908 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
909 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
910 "(%d) returned %d with %d (expected '0' with "
911 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
913 HeapFree(GetProcessHeap(), 0, buffer);
914 } /* for(level ... */
916 ClosePrinter(hprinter);
919 /* ########################### */
921 static void test_EnumMonitors(void)
923 DWORD res;
924 LPBYTE buffer;
925 DWORD cbBuf;
926 DWORD pcbNeeded;
927 DWORD pcReturned;
928 DWORD level;
930 /* valid levels are 1 and 2 */
931 for(level = 0; level < 4; level++) {
932 cbBuf = MAGIC_DEAD;
933 pcReturned = MAGIC_DEAD;
934 SetLastError(MAGIC_DEAD);
935 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
937 RETURN_ON_DEACTIVATED_SPOOLER(res)
939 /* not implemented yet in wine */
940 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
943 /* use only a short test, when we test with an invalid level */
944 if(!level || (level > 2)) {
945 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
946 (res && (pcReturned == 0)),
947 "(%d) returned %d with %d and 0x%08x (expected '0' with "
948 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
949 level, res, GetLastError(), pcReturned);
950 continue;
953 /* Level 2 is not supported on win9x */
954 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
955 skip("Level %d not supported\n", level);
956 continue;
959 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
960 "(%d) returned %d with %d (expected '0' with "
961 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
963 if (!cbBuf) {
964 skip("no valid buffer size returned\n");
965 continue;
968 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
969 if (buffer == NULL) continue;
971 SetLastError(MAGIC_DEAD);
972 pcbNeeded = MAGIC_DEAD;
973 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
974 ok(res, "(%d) returned %d with %d (expected '!=0')\n",
975 level, res, GetLastError());
976 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n",
977 level, pcbNeeded, cbBuf);
978 /* We can validate the returned Data with the Registry here */
981 SetLastError(MAGIC_DEAD);
982 pcReturned = MAGIC_DEAD;
983 pcbNeeded = MAGIC_DEAD;
984 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
985 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level,
986 res, GetLastError());
987 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
988 pcbNeeded, cbBuf);
990 SetLastError(MAGIC_DEAD);
991 pcbNeeded = MAGIC_DEAD;
992 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
993 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
994 "(%d) returned %d with %d (expected '0' with "
995 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
997 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
998 pcbNeeded, cbBuf);
1001 Do not add the next test:
1002 w2k+: RPC_X_NULL_REF_POINTER
1003 NT3.5: ERROR_INVALID_USER_BUFFER
1004 win9x: crash in winspool.drv
1006 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1009 SetLastError(MAGIC_DEAD);
1010 pcbNeeded = MAGIC_DEAD;
1011 pcReturned = MAGIC_DEAD;
1012 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1013 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1014 "(%d) returned %d with %d (expected '!=0' or '0' with "
1015 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1017 pcbNeeded = MAGIC_DEAD;
1018 pcReturned = MAGIC_DEAD;
1019 SetLastError(MAGIC_DEAD);
1020 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1021 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1022 "(%d) returned %d with %d (expected '!=0' or '0' with "
1023 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1025 HeapFree(GetProcessHeap(), 0, buffer);
1026 } /* for(level ... */
1029 /* ########################### */
1031 static void test_EnumPorts(void)
1033 DWORD res;
1034 DWORD level;
1035 LPBYTE buffer;
1036 DWORD cbBuf;
1037 DWORD pcbNeeded;
1038 DWORD pcReturned;
1040 /* valid levels are 1 and 2 */
1041 for(level = 0; level < 4; level++) {
1043 cbBuf = 0xdeadbeef;
1044 pcReturned = 0xdeadbeef;
1045 SetLastError(0xdeadbeef);
1046 res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
1047 RETURN_ON_DEACTIVATED_SPOOLER(res)
1049 /* use only a short test, when we test with an invalid level */
1050 if(!level || (level > 2)) {
1051 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1052 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1053 (res && (pcReturned == 0)),
1054 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1055 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1056 level, res, GetLastError(), pcReturned);
1057 continue;
1061 /* Level 2 is not supported on NT 3.x */
1062 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1063 skip("Level %d not supported\n", level);
1064 continue;
1067 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1068 "(%d) returned %d with %d (expected '0' with "
1069 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1071 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1072 if (buffer == NULL) continue;
1074 pcbNeeded = 0xdeadbeef;
1075 SetLastError(0xdeadbeef);
1076 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1077 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1078 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1079 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1081 pcbNeeded = 0xdeadbeef;
1082 pcReturned = 0xdeadbeef;
1083 SetLastError(0xdeadbeef);
1084 res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1085 ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1086 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1088 pcbNeeded = 0xdeadbeef;
1089 SetLastError(0xdeadbeef);
1090 res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1091 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1092 "(%d) returned %d with %d (expected '0' with "
1093 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1094 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1097 Do not add this test:
1098 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1099 w2k+: RPC_X_NULL_REF_POINTER
1100 NT3.5: ERROR_INVALID_USER_BUFFER
1101 win9x: crash in winspool.drv
1104 SetLastError(0xdeadbeef);
1105 res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1106 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1107 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1108 ( res && (GetLastError() == ERROR_SUCCESS) ),
1109 "(%d) returned %d with %d (expected '0' with "
1110 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1111 level, res, GetLastError());
1114 SetLastError(0xdeadbeef);
1115 res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1116 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1117 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1118 ( res && (GetLastError() == ERROR_SUCCESS) ),
1119 "(%d) returned %d with %d (expected '0' with "
1120 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1121 level, res, GetLastError());
1123 HeapFree(GetProcessHeap(), 0, buffer);
1127 /* ########################### */
1129 static void test_EnumPrinterDrivers(void)
1131 static char env_all[] = "all";
1133 DWORD res;
1134 LPBYTE buffer;
1135 DWORD cbBuf;
1136 DWORD pcbNeeded;
1137 DWORD pcReturned;
1138 DWORD level;
1140 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1141 for(level = 0; level < 10; level++) {
1142 cbBuf = 0xdeadbeef;
1143 pcReturned = 0xdeadbeef;
1144 SetLastError(0xdeadbeef);
1145 res = EnumPrinterDriversA(NULL, NULL, level, NULL, 0, &cbBuf, &pcReturned);
1146 RETURN_ON_DEACTIVATED_SPOOLER(res)
1148 /* use only a short test, when we test with an invalid level */
1149 if(!level || (level == 7) || (level > 8)) {
1151 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1152 (res && (pcReturned == 0)),
1153 "(%d) got %u with %u and 0x%x "
1154 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1155 level, res, GetLastError(), pcReturned);
1156 continue;
1159 /* some level are not supported in all windows versions */
1160 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1161 skip("Level %d not supported\n", level);
1162 continue;
1165 ok( ((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ||
1166 (res && (default_printer == NULL)),
1167 "(%u) got %u with %u for %s (expected '0' with "
1168 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1169 level, res, GetLastError(), default_printer);
1171 if (!cbBuf) {
1172 skip("no valid buffer size returned\n");
1173 continue;
1176 /* EnumPrinterDriversA returns the same number of bytes as EnumPrinterDriversW */
1177 if (!on_win9x && pEnumPrinterDriversW)
1179 DWORD double_needed;
1180 DWORD double_returned;
1181 pEnumPrinterDriversW(NULL, NULL, level, NULL, 0, &double_needed, &double_returned);
1182 ok(double_needed == cbBuf, "level %d: EnumPrinterDriversA returned different size %d than EnumPrinterDriversW (%d)\n", level, cbBuf, double_needed);
1185 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1186 if (buffer == NULL) continue;
1188 SetLastError(0xdeadbeef);
1189 pcbNeeded = 0xdeadbeef;
1190 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1191 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1192 ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1194 /* validate the returned Data here */
1195 if (level > 1) {
1196 LPDRIVER_INFO_2A di = (LPDRIVER_INFO_2A) buffer;
1198 ok( strrchr(di->pDriverPath, '\\') != NULL,
1199 "(%u) got %s for %s (expected a full path)\n",
1200 level, di->pDriverPath, di->pName);
1204 SetLastError(0xdeadbeef);
1205 pcReturned = 0xdeadbeef;
1206 pcbNeeded = 0xdeadbeef;
1207 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1208 ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1209 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1211 SetLastError(0xdeadbeef);
1212 pcbNeeded = 0xdeadbeef;
1213 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1214 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1215 "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1216 level, res, GetLastError());
1217 ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1220 Do not add the next test:
1221 NT: ERROR_INVALID_USER_BUFFER
1222 win9x: crash or 100% CPU
1224 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1227 SetLastError(0xdeadbeef);
1228 pcbNeeded = 0xdeadbeef;
1229 pcReturned = 0xdeadbeef;
1230 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, NULL, &pcReturned);
1231 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1232 "(%u) got %u with %u (expected '!=0' or '0' with "
1233 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1235 pcbNeeded = 0xdeadbeef;
1236 pcReturned = 0xdeadbeef;
1237 SetLastError(0xdeadbeef);
1238 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1239 ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1240 "(%u) got %u with %u (expected '!=0' or '0' with "
1241 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1243 HeapFree(GetProcessHeap(), 0, buffer);
1244 } /* for(level ... */
1246 pcbNeeded = 0;
1247 pcReturned = 0;
1248 SetLastError(0xdeadbeef);
1249 res = EnumPrinterDriversA(NULL, env_all, 1, NULL, 0, &pcbNeeded, &pcReturned);
1250 if (res)
1252 skip("no printer drivers found\n");
1253 return;
1255 if (GetLastError() == ERROR_INVALID_ENVIRONMENT)
1257 win_skip("NT4 and below don't support the 'all' environment value\n");
1258 return;
1260 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "unexpected error %u\n", GetLastError());
1262 buffer = HeapAlloc(GetProcessHeap(), 0, pcbNeeded);
1263 res = EnumPrinterDriversA(NULL, env_all, 1, buffer, pcbNeeded, &pcbNeeded, &pcReturned);
1264 ok(res, "EnumPrinterDriversA failed %u\n", GetLastError());
1265 if (res && pcReturned > 0)
1267 DRIVER_INFO_1 *di_1 = (DRIVER_INFO_1 *)buffer;
1268 ok((LPBYTE) di_1->pName == NULL || (LPBYTE) di_1->pName < buffer ||
1269 (LPBYTE) di_1->pName >= (LPBYTE)(di_1 + pcReturned),
1270 "Driver Information not in sequence; pName %p, top of data %p\n",
1271 di_1->pName, di_1 + pcReturned);
1274 HeapFree(GetProcessHeap(), 0, buffer);
1277 /* ########################### */
1279 static void test_EnumPrintProcessors(void)
1281 DWORD res;
1282 LPBYTE buffer;
1283 DWORD cbBuf;
1284 DWORD pcbNeeded;
1285 DWORD pcReturned;
1288 cbBuf = 0xdeadbeef;
1289 pcReturned = 0xdeadbeef;
1290 SetLastError(0xdeadbeef);
1291 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, 0, &cbBuf, &pcReturned);
1292 RETURN_ON_DEACTIVATED_SPOOLER(res)
1294 if (res && !cbBuf) {
1295 skip("No Printprocessor installed\n");
1296 return;
1299 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1300 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1301 res, GetLastError());
1303 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1304 if (buffer == NULL)
1305 return;
1307 SetLastError(0xdeadbeef);
1308 pcbNeeded = 0xdeadbeef;
1309 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1310 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1311 /* validate the returned Data here. */
1314 SetLastError(0xdeadbeef);
1315 pcReturned = 0xdeadbeef;
1316 pcbNeeded = 0xdeadbeef;
1317 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1318 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1320 SetLastError(0xdeadbeef);
1321 pcbNeeded = 0xdeadbeef;
1322 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1323 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1324 "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1325 res, GetLastError());
1327 /* only level 1 is valid */
1328 if (0) {
1329 /* both tests crash on win98se */
1330 SetLastError(0xdeadbeef);
1331 pcbNeeded = 0xdeadbeef;
1332 pcReturned = 0xdeadbeef;
1333 res = EnumPrintProcessorsA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded, &pcReturned);
1334 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1335 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1336 res, GetLastError());
1338 SetLastError(0xdeadbeef);
1339 pcbNeeded = 0xdeadbeef;
1340 res = EnumPrintProcessorsA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded, &pcReturned);
1341 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1342 "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1343 res, GetLastError());
1346 /* an empty environment is ignored */
1347 SetLastError(0xdeadbeef);
1348 pcbNeeded = 0xdeadbeef;
1349 res = EnumPrintProcessorsA(NULL, empty, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1350 ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1352 /* the environment is checked */
1353 SetLastError(0xdeadbeef);
1354 pcbNeeded = 0xdeadbeef;
1355 res = EnumPrintProcessorsA(NULL, invalid_env, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1356 /* NT5: ERROR_INVALID_ENVIRONMENT, NT4: res != 0, 9x: ERROR_INVALID_PARAMETER */
1357 ok( broken(res) || /* NT4 */
1358 (GetLastError() == ERROR_INVALID_ENVIRONMENT) ||
1359 (GetLastError() == ERROR_INVALID_PARAMETER),
1360 "got %u with %u (expected '0' with ERROR_INVALID_ENVIRONMENT or "
1361 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1364 /* failure-Codes for NULL */
1365 if (0) {
1366 /* this test crash on win98se */
1367 SetLastError(0xdeadbeef);
1368 pcbNeeded = 0xdeadbeef;
1369 pcReturned = 0xdeadbeef;
1370 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, cbBuf, &pcbNeeded, &pcReturned);
1371 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
1372 "got %u with %u (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1373 res, GetLastError());
1376 SetLastError(0xdeadbeef);
1377 pcbNeeded = 0xdeadbeef;
1378 pcReturned = 0xdeadbeef;
1379 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, NULL, &pcReturned);
1380 /* the NULL is ignored on win9x */
1381 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1382 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1383 res, GetLastError());
1385 pcbNeeded = 0xdeadbeef;
1386 pcReturned = 0xdeadbeef;
1387 SetLastError(0xdeadbeef);
1388 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, NULL);
1389 /* the NULL is ignored on win9x */
1390 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1391 "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1392 res, GetLastError());
1394 HeapFree(GetProcessHeap(), 0, buffer);
1398 /* ########################### */
1400 static void test_GetDefaultPrinter(void)
1402 BOOL retval;
1403 DWORD exact = DEFAULT_PRINTER_SIZE;
1404 DWORD size;
1405 char buffer[DEFAULT_PRINTER_SIZE];
1407 if (!pGetDefaultPrinterA) return;
1408 /* only supported on NT like OSes starting with win2k */
1410 SetLastError(ERROR_SUCCESS);
1411 retval = pGetDefaultPrinterA(buffer, &exact);
1412 if (!retval || !exact || !strlen(buffer) ||
1413 (ERROR_SUCCESS != GetLastError())) {
1414 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
1415 (ERROR_INVALID_NAME == GetLastError()))
1416 trace("this test requires a default printer to be set\n");
1417 else {
1418 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1419 "function returned %s\n"
1420 "last error 0x%08x\n"
1421 "returned buffer size 0x%08x\n"
1422 "returned buffer content %s\n",
1423 retval ? "true" : "false", GetLastError(), exact, buffer);
1425 return;
1427 SetLastError(ERROR_SUCCESS);
1428 retval = pGetDefaultPrinterA(NULL, NULL);
1429 ok( !retval, "function result wrong! False expected\n");
1430 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1431 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1432 GetLastError());
1434 SetLastError(ERROR_SUCCESS);
1435 retval = pGetDefaultPrinterA(buffer, NULL);
1436 ok( !retval, "function result wrong! False expected\n");
1437 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1438 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1439 GetLastError());
1441 SetLastError(ERROR_SUCCESS);
1442 size = 0;
1443 retval = pGetDefaultPrinterA(NULL, &size);
1444 ok( !retval, "function result wrong! False expected\n");
1445 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1446 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1447 GetLastError());
1448 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1449 exact, size);
1451 SetLastError(ERROR_SUCCESS);
1452 size = DEFAULT_PRINTER_SIZE;
1453 retval = pGetDefaultPrinterA(NULL, &size);
1454 ok( !retval, "function result wrong! False expected\n");
1455 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1456 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1457 GetLastError());
1458 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1459 exact, size);
1461 size = 0;
1462 retval = pGetDefaultPrinterA(buffer, &size);
1463 ok( !retval, "function result wrong! False expected\n");
1464 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1465 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1466 GetLastError());
1467 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1468 exact, size);
1470 size = exact;
1471 retval = pGetDefaultPrinterA(buffer, &size);
1472 ok( retval, "function result wrong! True expected\n");
1473 ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1474 exact, size);
1477 static void test_GetPrinterDriverDirectory(void)
1479 LPBYTE buffer = NULL;
1480 DWORD cbBuf = 0, pcbNeeded = 0;
1481 BOOL res;
1484 SetLastError(MAGIC_DEAD);
1485 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1486 trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1487 res, GetLastError(), cbBuf);
1489 RETURN_ON_DEACTIVATED_SPOOLER(res)
1490 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1491 "returned %d with lasterror=%d (expected '0' with "
1492 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1494 if (!cbBuf) {
1495 skip("no valid buffer size returned\n");
1496 return;
1499 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1500 if (buffer == NULL) return ;
1502 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1503 ok( res, "expected result != 0, got %d\n", res);
1504 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1505 pcbNeeded, cbBuf);
1507 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1508 ok( res, "expected result != 0, got %d\n", res);
1509 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1510 pcbNeeded, cbBuf);
1512 SetLastError(MAGIC_DEAD);
1513 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1514 ok( !res , "expected result == 0, got %d\n", res);
1515 ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1516 pcbNeeded, cbBuf);
1518 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1519 "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1520 GetLastError());
1523 Do not add the next test:
1524 XPsp2: crash in this app, when the spooler is not running
1525 NT3.5: ERROR_INVALID_USER_BUFFER
1526 win9x: ERROR_INVALID_PARAMETER
1528 pcbNeeded = MAGIC_DEAD;
1529 SetLastError(MAGIC_DEAD);
1530 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1533 SetLastError(MAGIC_DEAD);
1534 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1535 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
1536 "expected either result == 0 and "
1537 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1538 "got result %d and last error == %d\n", res, GetLastError());
1540 SetLastError(MAGIC_DEAD);
1541 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1542 ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1543 "returned %d with %d (expected '!=0' or '0' with "
1544 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1547 /* with a valid buffer, but level is too large */
1548 buffer[0] = '\0';
1549 SetLastError(MAGIC_DEAD);
1550 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1552 /* Level not checked in win9x and wine:*/
1553 if((res != FALSE) && buffer[0])
1555 trace("Level '2' not checked '%s'\n", buffer);
1557 else
1559 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1560 "returned %d with lasterror=%d (expected '0' with "
1561 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1564 /* printing environments are case insensitive */
1565 /* "Windows 4.0" is valid for win9x and NT */
1566 buffer[0] = '\0';
1567 SetLastError(MAGIC_DEAD);
1568 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1569 buffer, cbBuf*2, &pcbNeeded);
1571 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1572 cbBuf = pcbNeeded;
1573 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1574 if (buffer == NULL) return ;
1576 SetLastError(MAGIC_DEAD);
1577 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1578 buffer, cbBuf*2, &pcbNeeded);
1581 ok(res && buffer[0], "returned %d with "
1582 "lasterror=%d and len=%d (expected '1' with 'len > 0')\n",
1583 res, GetLastError(), lstrlenA((char *)buffer));
1585 buffer[0] = '\0';
1586 SetLastError(MAGIC_DEAD);
1587 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1588 buffer, cbBuf*2, &pcbNeeded);
1590 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1591 cbBuf = pcbNeeded;
1592 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1593 if (buffer == NULL) return ;
1595 buffer[0] = '\0';
1596 SetLastError(MAGIC_DEAD);
1597 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1598 buffer, cbBuf*2, &pcbNeeded);
1601 /* "Windows NT x86" is invalid for win9x */
1602 ok( (res && buffer[0]) ||
1603 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
1604 "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1605 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1606 res, GetLastError(), lstrlenA((char *)buffer));
1608 /* A setup program (PDFCreator_0.8.0) use empty strings */
1609 SetLastError(MAGIC_DEAD);
1610 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1611 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1613 SetLastError(MAGIC_DEAD);
1614 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1615 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1617 SetLastError(MAGIC_DEAD);
1618 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1619 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1621 HeapFree( GetProcessHeap(), 0, buffer);
1624 /* ##### */
1626 static void test_GetPrintProcessorDirectory(void)
1628 LPBYTE buffer = NULL;
1629 DWORD cbBuf = 0;
1630 DWORD pcbNeeded = 0;
1631 BOOL res;
1634 SetLastError(0xdeadbeef);
1635 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1636 /* The deactivated Spooler is caught here on NT3.51 */
1637 RETURN_ON_DEACTIVATED_SPOOLER(res)
1638 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1639 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1640 res, GetLastError());
1642 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1643 if(buffer == NULL) return;
1645 buffer[0] = '\0';
1646 SetLastError(0xdeadbeef);
1647 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1648 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1650 SetLastError(0xdeadbeef);
1651 buffer[0] = '\0';
1652 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1653 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1655 /* Buffer to small */
1656 buffer[0] = '\0';
1657 SetLastError(0xdeadbeef);
1658 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1659 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1660 "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1661 res, GetLastError());
1663 if (0)
1665 /* XPsp2: the program will crash here, when the spooler is not running */
1666 /* GetPrinterDriverDirectory has the same bug */
1667 pcbNeeded = 0;
1668 SetLastError(0xdeadbeef);
1669 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1670 /* NT: ERROR_INVALID_USER_BUFFER, 9x: res != 0 */
1671 ok( (!res && (GetLastError() == ERROR_INVALID_USER_BUFFER)) ||
1672 broken(res),
1673 "returned %d with %d (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1674 res, GetLastError());
1677 buffer[0] = '\0';
1678 SetLastError(0xdeadbeef);
1679 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1680 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1681 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ||
1682 broken(res),
1683 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1684 res, GetLastError());
1686 buffer[0] = '\0';
1687 SetLastError(0xdeadbeef);
1688 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1689 /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1690 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ||
1691 broken(res),
1692 "returned %d with %d (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1693 res, GetLastError());
1695 /* with a valid buffer, but level is invalid */
1696 buffer[0] = '\0';
1697 SetLastError(0xdeadbeef);
1698 res = GetPrintProcessorDirectoryA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded);
1699 /* Level is ignored in win9x*/
1700 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1701 broken(res && buffer[0]),
1702 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1703 res, GetLastError());
1705 buffer[0] = '\0';
1706 SetLastError(0xdeadbeef);
1707 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1708 /* Level is ignored in win9x*/
1709 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1710 broken(res && buffer[0]),
1711 "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1712 res, GetLastError());
1714 /* Empty environment is the same as the default environment */
1715 buffer[0] = '\0';
1716 SetLastError(0xdeadbeef);
1717 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1718 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1720 /* "Windows 4.0" is valid for win9x and NT */
1721 buffer[0] = '\0';
1722 SetLastError(0xdeadbeef);
1723 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1724 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1727 /* "Windows NT x86" is invalid for win9x */
1728 buffer[0] = '\0';
1729 SetLastError(0xdeadbeef);
1730 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1731 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1732 "returned %d with %d (expected '!= 0' or '0' with "
1733 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1735 /* invalid on all Systems */
1736 buffer[0] = '\0';
1737 SetLastError(0xdeadbeef);
1738 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1739 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1740 "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1741 res, GetLastError());
1743 /* Empty servername is the same as the local computer */
1744 buffer[0] = '\0';
1745 SetLastError(0xdeadbeef);
1746 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1747 ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1749 /* invalid on all Systems */
1750 buffer[0] = '\0';
1751 SetLastError(0xdeadbeef);
1752 res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1753 ok( !res, "expected failure\n");
1754 ok( GetLastError() == RPC_S_SERVER_UNAVAILABLE || /* NT */
1755 GetLastError() == ERROR_INVALID_PARAMETER || /* 9x */
1756 GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista */
1757 "unexpected last error %d\n", GetLastError());
1759 HeapFree(GetProcessHeap(), 0, buffer);
1762 /* ##### */
1764 static void test_OpenPrinter(void)
1766 PRINTER_DEFAULTSA defaults;
1767 HANDLE hprinter;
1768 DWORD res;
1770 SetLastError(MAGIC_DEAD);
1771 res = OpenPrinter(NULL, NULL, NULL);
1772 /* The deactivated Spooler is caught here on NT3.51 */
1773 RETURN_ON_DEACTIVATED_SPOOLER(res)
1774 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1775 "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1776 res, GetLastError());
1779 /* Get Handle for the local Printserver (NT only)*/
1780 hprinter = (HANDLE) MAGIC_DEAD;
1781 SetLastError(MAGIC_DEAD);
1782 res = OpenPrinter(NULL, &hprinter, NULL);
1783 /* The deactivated Spooler is caught here on XPsp2 */
1784 RETURN_ON_DEACTIVATED_SPOOLER(res)
1785 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1786 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1787 res, GetLastError());
1788 if(res) {
1789 ClosePrinter(hprinter);
1791 defaults.pDatatype=NULL;
1792 defaults.pDevMode=NULL;
1794 defaults.DesiredAccess=0;
1795 hprinter = (HANDLE) MAGIC_DEAD;
1796 SetLastError(MAGIC_DEAD);
1797 res = OpenPrinter(NULL, &hprinter, &defaults);
1798 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1799 if (res) ClosePrinter(hprinter);
1801 defaults.DesiredAccess=-1;
1802 hprinter = (HANDLE) MAGIC_DEAD;
1803 SetLastError(MAGIC_DEAD);
1804 res = OpenPrinter(NULL, &hprinter, &defaults);
1805 todo_wine {
1806 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1807 "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n",
1808 res, GetLastError());
1810 if (res) ClosePrinter(hprinter);
1815 if (local_server != NULL) {
1816 hprinter = (HANDLE) 0xdeadbeef;
1817 SetLastError(0xdeadbeef);
1818 res = OpenPrinter(local_server, &hprinter, NULL);
1819 ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1820 "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1821 res, GetLastError());
1822 if(res) ClosePrinter(hprinter);
1825 /* Invalid Printername */
1826 hprinter = (HANDLE) MAGIC_DEAD;
1827 SetLastError(MAGIC_DEAD);
1828 res = OpenPrinter(illegal_name, &hprinter, NULL);
1829 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1830 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1831 "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1832 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1833 if(res) ClosePrinter(hprinter);
1835 hprinter = (HANDLE) MAGIC_DEAD;
1836 SetLastError(MAGIC_DEAD);
1837 res = OpenPrinter(empty, &hprinter, NULL);
1838 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1839 ok( !res &&
1840 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1841 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1842 "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1843 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1844 if(res) ClosePrinter(hprinter);
1847 /* Get Handle for the default Printer */
1848 if (default_printer)
1850 hprinter = (HANDLE) MAGIC_DEAD;
1851 SetLastError(MAGIC_DEAD);
1852 res = OpenPrinter(default_printer, &hprinter, NULL);
1853 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1855 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1856 return;
1858 ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1859 if(res) ClosePrinter(hprinter);
1861 SetLastError(MAGIC_DEAD);
1862 res = OpenPrinter(default_printer, NULL, NULL);
1863 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1864 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1865 "returned %d with %d (expected '!=0' or '0' with "
1866 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1868 defaults.pDatatype=NULL;
1869 defaults.pDevMode=NULL;
1870 defaults.DesiredAccess=0;
1872 hprinter = (HANDLE) MAGIC_DEAD;
1873 SetLastError(MAGIC_DEAD);
1874 res = OpenPrinter(default_printer, &hprinter, &defaults);
1875 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1876 "returned %d with %d (expected '!=0' or '0' with "
1877 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1878 if(res) ClosePrinter(hprinter);
1880 defaults.pDatatype = empty;
1882 hprinter = (HANDLE) MAGIC_DEAD;
1883 SetLastError(MAGIC_DEAD);
1884 res = OpenPrinter(default_printer, &hprinter, &defaults);
1885 /* stop here, when a remote Printserver has no RPC-Service running */
1886 RETURN_ON_DEACTIVATED_SPOOLER(res)
1887 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1888 (GetLastError() == ERROR_ACCESS_DENIED)),
1889 "returned %d with %d (expected '!=0' or '0' with: "
1890 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1891 res, GetLastError());
1892 if(res) ClosePrinter(hprinter);
1895 defaults.pDatatype=NULL;
1896 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1898 hprinter = (HANDLE) MAGIC_DEAD;
1899 SetLastError(MAGIC_DEAD);
1900 res = OpenPrinter(default_printer, &hprinter, &defaults);
1901 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1902 "returned %d with %d (expected '!=0' or '0' with "
1903 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1904 if(res) ClosePrinter(hprinter);
1907 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1908 hprinter = (HANDLE) MAGIC_DEAD;
1909 SetLastError(MAGIC_DEAD);
1910 res = OpenPrinter(default_printer, &hprinter, &defaults);
1911 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1912 "returned %d with %d (expected '!=0' or '0' with "
1913 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1914 if(res) ClosePrinter(hprinter);
1920 static void test_SetDefaultPrinter(void)
1922 DWORD res;
1923 DWORD size = DEFAULT_PRINTER_SIZE;
1924 CHAR buffer[DEFAULT_PRINTER_SIZE];
1925 CHAR org_value[DEFAULT_PRINTER_SIZE];
1928 if (!pSetDefaultPrinterA) return;
1929 /* only supported on win2k and above */
1931 /* backup the original value */
1932 org_value[0] = '\0';
1933 SetLastError(MAGIC_DEAD);
1934 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1936 /* first part: with the default Printer */
1937 SetLastError(MAGIC_DEAD);
1938 res = pSetDefaultPrinterA("no_printer_with_this_name");
1940 RETURN_ON_DEACTIVATED_SPOOLER(res)
1941 /* spooler is running or we have no spooler here*/
1943 /* Not implemented in wine */
1944 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1945 trace("SetDefaultPrinterA() not implemented yet.\n");
1946 return;
1949 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1950 "returned %d with %d (expected '0' with "
1951 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1953 WriteProfileStringA("windows", "device", org_value);
1954 SetLastError(MAGIC_DEAD);
1955 res = pSetDefaultPrinterA("");
1956 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1957 "returned %d with %d (expected '!=0' or '0' with "
1958 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1960 WriteProfileStringA("windows", "device", org_value);
1961 SetLastError(MAGIC_DEAD);
1962 res = pSetDefaultPrinterA(NULL);
1963 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1964 "returned %d with %d (expected '!=0' or '0' with "
1965 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1967 WriteProfileStringA("windows", "device", org_value);
1968 SetLastError(MAGIC_DEAD);
1969 res = pSetDefaultPrinterA(default_printer);
1970 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1971 "returned %d with %d (expected '!=0' or '0' with "
1972 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1975 /* second part: always without a default Printer */
1976 WriteProfileStringA("windows", "device", NULL);
1977 SetLastError(MAGIC_DEAD);
1978 res = pSetDefaultPrinterA("no_printer_with_this_name");
1980 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1981 "returned %d with %d (expected '0' with "
1982 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1984 WriteProfileStringA("windows", "device", NULL);
1985 SetLastError(MAGIC_DEAD);
1986 res = pSetDefaultPrinterA("");
1987 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1988 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1989 "returned %d with %d (expected '!=0' or '0' with "
1990 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1992 WriteProfileStringA("windows", "device", NULL);
1993 SetLastError(MAGIC_DEAD);
1994 res = pSetDefaultPrinterA(NULL);
1995 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1996 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1997 "returned %d with %d (expected '!=0' or '0' with "
1998 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2000 WriteProfileStringA("windows", "device", NULL);
2001 SetLastError(MAGIC_DEAD);
2002 res = pSetDefaultPrinterA(default_printer);
2003 ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
2004 "returned %d with %d (expected '!=0' or '0' with "
2005 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2007 /* restore the original value */
2008 res = pSetDefaultPrinterA(default_printer); /* the nice way */
2009 WriteProfileStringA("windows", "device", org_value); /* the old way */
2011 buffer[0] = '\0';
2012 SetLastError(MAGIC_DEAD);
2013 res = GetProfileStringA("windows", "device", NULL, buffer, size);
2014 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
2018 /* ########################### */
2020 static void test_XcvDataW_MonitorUI(void)
2022 DWORD res;
2023 HANDLE hXcv;
2024 BYTE buffer[MAX_PATH + 4];
2025 DWORD needed;
2026 DWORD status;
2027 DWORD len;
2028 PRINTER_DEFAULTSA pd;
2030 /* api is not present before w2k */
2031 if (pXcvDataW == NULL) return;
2033 pd.pDatatype = NULL;
2034 pd.pDevMode = NULL;
2035 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2037 hXcv = NULL;
2038 SetLastError(0xdeadbeef);
2039 res = OpenPrinter(xcv_localport, &hXcv, &pd);
2040 RETURN_ON_DEACTIVATED_SPOOLER(res)
2041 RETURN_ON_ACCESS_DENIED(res)
2043 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2044 if (!res) return;
2046 /* ask for needed size */
2047 needed = (DWORD) 0xdeadbeef;
2048 status = (DWORD) 0xdeadbeef;
2049 SetLastError(0xdeadbeef);
2050 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed, &status);
2051 ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
2052 "returned %d with %u and %u for status %u (expected '!= 0' and "
2053 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
2054 res, GetLastError(), needed, status);
2056 if (needed > MAX_PATH) {
2057 ClosePrinter(hXcv);
2058 skip("buffer overflow (%u)\n", needed);
2059 return;
2061 len = needed; /* Size is in bytes */
2063 /* the command is required */
2064 needed = (DWORD) 0xdeadbeef;
2065 status = (DWORD) 0xdeadbeef;
2066 SetLastError(0xdeadbeef);
2067 res = pXcvDataW(hXcv, emptyW, NULL, 0, NULL, 0, &needed, &status);
2068 ok( res && (status == ERROR_INVALID_PARAMETER),
2069 "returned %d with %u and %u for status %u (expected '!= 0' with "
2070 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2072 needed = (DWORD) 0xdeadbeef;
2073 status = (DWORD) 0xdeadbeef;
2074 SetLastError(0xdeadbeef);
2075 res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
2076 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2077 "returned %d with %u and %u for status %u (expected '0' with "
2078 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2080 /* "PDWORD needed" is checked before RPC-Errors */
2081 needed = (DWORD) 0xdeadbeef;
2082 status = (DWORD) 0xdeadbeef;
2083 SetLastError(0xdeadbeef);
2084 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, NULL, &status);
2085 ok( !res && (GetLastError() == 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, cmd_MonitorUIW, NULL, 0, NULL, len, &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 needed = (DWORD) 0xdeadbeef;
2098 status = (DWORD) 0xdeadbeef;
2099 SetLastError(0xdeadbeef);
2100 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, NULL);
2101 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2102 "returned %d with %u and %u for status %u (expected '0' with "
2103 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2105 /* off by one: larger */
2106 needed = (DWORD) 0xdeadbeef;
2107 status = (DWORD) 0xdeadbeef;
2108 SetLastError(0xdeadbeef);
2109 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len+1, &needed, &status);
2110 ok( res && (status == ERROR_SUCCESS),
2111 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2112 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2114 /* off by one: smaller */
2115 /* the buffer is not modified for NT4, w2k, XP */
2116 needed = (DWORD) 0xdeadbeef;
2117 status = (DWORD) 0xdeadbeef;
2118 SetLastError(0xdeadbeef);
2119 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len-1, &needed, &status);
2120 ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
2121 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2122 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
2125 /* Normal use. The DLL-Name without a Path is returned */
2126 memset(buffer, 0, len);
2127 needed = (DWORD) 0xdeadbeef;
2128 status = (DWORD) 0xdeadbeef;
2129 SetLastError(0xdeadbeef);
2130 res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, &status);
2131 ok( res && (status == ERROR_SUCCESS),
2132 "returned %d with %u and %u for status %u (expected '!= 0' for status "
2133 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2135 ClosePrinter(hXcv);
2138 /* ########################### */
2140 static void test_XcvDataW_PortIsValid(void)
2142 DWORD res;
2143 HANDLE hXcv;
2144 DWORD needed;
2145 DWORD status;
2146 PRINTER_DEFAULTSA pd;
2148 /* api is not present before w2k */
2149 if (pXcvDataW == NULL) return;
2151 pd.pDatatype = NULL;
2152 pd.pDevMode = NULL;
2153 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2155 hXcv = NULL;
2156 SetLastError(0xdeadbeef);
2157 res = OpenPrinter(xcv_localport, &hXcv, &pd);
2159 RETURN_ON_DEACTIVATED_SPOOLER(res)
2160 RETURN_ON_ACCESS_DENIED(res)
2162 ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2163 if (!res) return;
2166 /* "PDWORD needed" is always required */
2167 needed = (DWORD) 0xdeadbeef;
2168 status = (DWORD) 0xdeadbeef;
2169 SetLastError(0xdeadbeef);
2170 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, NULL, &status);
2171 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2172 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2173 res, GetLastError(), needed, status);
2175 /* an empty name is not allowed */
2176 needed = (DWORD) 0xdeadbeef;
2177 status = (DWORD) 0xdeadbeef;
2178 SetLastError(0xdeadbeef);
2179 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) emptyW, sizeof(emptyW), NULL, 0, &needed, &status);
2180 ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
2181 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2182 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2183 res, GetLastError(), needed, status);
2185 /* a directory is not allowed */
2186 needed = (DWORD) 0xdeadbeef;
2187 status = (DWORD) 0xdeadbeef;
2188 SetLastError(0xdeadbeef);
2189 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2190 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2191 ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
2192 "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2193 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2194 res, GetLastError(), needed, status);
2196 /* more valid well known Ports */
2197 needed = (DWORD) 0xdeadbeef;
2198 status = (DWORD) 0xdeadbeef;
2199 SetLastError(0xdeadbeef);
2200 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed, &status);
2201 ok( res && (status == ERROR_SUCCESS),
2202 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2203 res, GetLastError(), needed, status);
2205 needed = (DWORD) 0xdeadbeef;
2206 status = (DWORD) 0xdeadbeef;
2207 SetLastError(0xdeadbeef);
2208 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt2W, sizeof(portname_lpt2W), NULL, 0, &needed, &status);
2209 ok( res && (status == ERROR_SUCCESS),
2210 "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2211 res, GetLastError(), needed, status);
2213 needed = (DWORD) 0xdeadbeef;
2214 status = (DWORD) 0xdeadbeef;
2215 SetLastError(0xdeadbeef);
2216 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com1W, sizeof(portname_com1W), 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_com2W, sizeof(portname_com2W), 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_fileW, sizeof(portname_fileW), NULL, 0, &needed, &status);
2233 ok( res && (status == ERROR_SUCCESS),
2234 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2235 res, GetLastError(), needed, status);
2238 /* a normal, writable file is allowed */
2239 needed = (DWORD) 0xdeadbeef;
2240 status = (DWORD) 0xdeadbeef;
2241 SetLastError(0xdeadbeef);
2242 res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2243 ok( res && (status == ERROR_SUCCESS),
2244 "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2245 res, GetLastError(), needed, status);
2247 ClosePrinter(hXcv);
2250 /* ########################### */
2252 static void test_GetPrinter(void)
2254 HANDLE hprn;
2255 BOOL ret;
2256 BYTE *buf;
2257 INT level;
2258 DWORD needed, filled;
2260 if (!default_printer)
2262 skip("There is no default printer installed\n");
2263 return;
2266 hprn = 0;
2267 ret = OpenPrinter(default_printer, &hprn, NULL);
2268 if (!ret)
2270 skip("Unable to open the default printer (%s)\n", default_printer);
2271 return;
2273 ok(hprn != 0, "wrong hprn %p\n", hprn);
2275 for (level = 1; level <= 9; level++)
2277 SetLastError(0xdeadbeef);
2278 needed = (DWORD)-1;
2279 ret = GetPrinter(hprn, level, NULL, 0, &needed);
2280 if (ret)
2282 win_skip("Level %d is not supported on Win9x/WinMe\n", level);
2283 ok(GetLastError() == ERROR_SUCCESS, "wrong error %d\n", GetLastError());
2284 ok(needed == 0,"Expected 0, got %d\n", needed);
2285 continue;
2287 ok(!ret, "level %d: GetPrinter should fail\n", level);
2288 /* Not all levels are supported on all Windows-Versions */
2289 if (GetLastError() == ERROR_INVALID_LEVEL ||
2290 GetLastError() == ERROR_NOT_SUPPORTED /* Win9x/WinMe */)
2292 skip("Level %d not supported\n", level);
2293 continue;
2295 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2296 ok(needed > 0,"not expected needed buffer size %d\n", needed);
2298 /* GetPrinterA returns the same number of bytes as GetPrinterW */
2299 if (!on_win9x && !ret && pGetPrinterW && level != 6 && level != 7)
2301 DWORD double_needed;
2302 ret = pGetPrinterW(hprn, level, NULL, 0, &double_needed);
2303 ok(double_needed == needed, "level %d: GetPrinterA returned different size %d than GetPrinterW (%d)\n", level, needed, double_needed);
2306 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2308 SetLastError(0xdeadbeef);
2309 filled = -1;
2310 ret = GetPrinter(hprn, level, buf, needed, &filled);
2311 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2313 if (level == 2)
2315 PRINTER_INFO_2 *pi_2 = (PRINTER_INFO_2 *)buf;
2317 ok(pi_2->pPrinterName!= NULL, "not expected NULL ptr\n");
2318 ok(pi_2->pDriverName!= NULL, "not expected NULL ptr\n");
2320 trace("pPrinterName %s\n", pi_2->pPrinterName);
2321 trace("pDriverName %s\n", pi_2->pDriverName);
2324 HeapFree(GetProcessHeap(), 0, buf);
2327 SetLastError(0xdeadbeef);
2328 ret = ClosePrinter(hprn);
2329 ok(ret, "ClosePrinter error %d\n", GetLastError());
2332 /* ########################### */
2334 static void test_GetPrinterData(void)
2336 HANDLE hprn = 0;
2337 DWORD res;
2338 DWORD type;
2339 CHAR buffer[MAX_PATH + 1];
2340 DWORD needed;
2341 DWORD len;
2343 /* ToDo: test parameter validation, test with the default printer */
2345 SetLastError(0xdeadbeef);
2346 res = OpenPrinter(NULL, &hprn, NULL);
2347 if (!res)
2349 /* printserver not available on win9x */
2350 if (!on_win9x)
2351 win_skip("Unable to open the printserver: %d\n", GetLastError());
2352 return;
2355 memset(buffer, '#', sizeof(buffer));
2356 buffer[MAX_PATH] = 0;
2357 type = 0xdeadbeef;
2358 needed = 0xdeadbeef;
2359 SetLastError(0xdeadbeef);
2360 res = GetPrinterDataA(hprn, defaultspooldirectory, &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2362 len = lstrlenA(buffer) + sizeof(CHAR);
2363 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2364 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2365 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d or %d)\n",
2366 res, type, needed, buffer, len, len * sizeof(WCHAR));
2368 needed = 0xdeadbeef;
2369 SetLastError(0xdeadbeef);
2370 res = GetPrinterDataA(hprn, defaultspooldirectory, NULL, NULL, 0, &needed);
2371 ok( (res == ERROR_MORE_DATA) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2372 "got %d, needed: %d (expected ERROR_MORE_DATA and %d or %d)\n",
2373 res, needed, len, len * sizeof(WCHAR));
2375 /* ToDo: test SPLREG_* */
2377 SetLastError(0xdeadbeef);
2378 res = ClosePrinter(hprn);
2379 ok(res, "ClosePrinter error %d\n", GetLastError());
2382 /* ########################### */
2384 static void test_GetPrinterDataEx(void)
2386 HANDLE hprn = 0;
2387 DWORD res;
2388 DWORD type;
2389 CHAR buffer[MAX_PATH + 1];
2390 DWORD needed;
2391 DWORD len;
2393 /* not present before w2k */
2394 if (!pGetPrinterDataExA) {
2395 win_skip("GetPrinterDataEx not found\n");
2396 return;
2399 /* ToDo: test parameter validation, test with the default printer */
2401 SetLastError(0xdeadbeef);
2402 res = OpenPrinter(NULL, &hprn, NULL);
2403 if (!res)
2405 win_skip("Unable to open the printserver: %d\n", GetLastError());
2406 return;
2409 /* keyname is ignored, when hprn is a HANDLE for a printserver */
2410 memset(buffer, '#', sizeof(buffer));
2411 buffer[MAX_PATH] = 0;
2412 type = 0xdeadbeef;
2413 needed = 0xdeadbeef;
2414 SetLastError(0xdeadbeef);
2415 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, &type,
2416 (LPBYTE) buffer, sizeof(buffer), &needed);
2418 len = lstrlenA(buffer) + sizeof(CHAR);
2419 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2420 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2421 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d or %d)\n",
2422 res, type, needed, buffer, len, len * sizeof(WCHAR));
2424 memset(buffer, '#', sizeof(buffer));
2425 buffer[MAX_PATH] = 0;
2426 type = 0xdeadbeef;
2427 needed = 0xdeadbeef;
2428 SetLastError(0xdeadbeef);
2429 res = pGetPrinterDataExA(hprn, "", defaultspooldirectory, &type,
2430 (LPBYTE) buffer, sizeof(buffer), &needed);
2431 len = lstrlenA(buffer) + sizeof(CHAR);
2432 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2433 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d or %d)\n",
2434 res, type, needed, buffer, len, len * sizeof(WCHAR));
2436 memset(buffer, '#', sizeof(buffer));
2437 buffer[MAX_PATH] = 0;
2438 type = 0xdeadbeef;
2439 needed = 0xdeadbeef;
2440 SetLastError(0xdeadbeef);
2441 /* Wine uses GetPrinterDataEx with "PrinterDriverData" to implement GetPrinterData */
2442 res = pGetPrinterDataExA(hprn, "PrinterDriverData", defaultspooldirectory,
2443 &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2444 len = lstrlenA(buffer) + sizeof(CHAR);
2445 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2446 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d or %d)\n",
2447 res, type, needed, buffer, len, len * sizeof(WCHAR));
2450 memset(buffer, '#', sizeof(buffer));
2451 buffer[MAX_PATH] = 0;
2452 type = 0xdeadbeef;
2453 needed = 0xdeadbeef;
2454 SetLastError(0xdeadbeef);
2455 res = pGetPrinterDataExA(hprn, does_not_exist, defaultspooldirectory, &type,
2456 (LPBYTE) buffer, sizeof(buffer), &needed);
2457 len = lstrlenA(buffer) + sizeof(CHAR);
2458 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2459 "got %d, type %d, needed: %d and '%s' (expected ERROR_SUCCESS, REG_SZ and %d or %d)\n",
2460 res, type, needed, buffer, len, len * sizeof(WCHAR));
2462 needed = 0xdeadbeef;
2463 SetLastError(0xdeadbeef);
2464 /* vista and w2k8 have a bug in GetPrinterDataEx:
2465 the current LastError value is returned as result */
2466 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2467 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeadbeef)) &&
2468 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2469 "got %d, needed: %d (expected ERROR_MORE_DATA and %d or %d)\n",
2470 res, needed, len, len * sizeof(WCHAR));
2472 needed = 0xdeadbeef;
2473 SetLastError(0xdeaddead);
2474 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2475 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeaddead)) &&
2476 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2477 "got %d, needed: %d (expected ERROR_MORE_DATA and %d or %d)\n",
2478 res, needed, len, len * sizeof(WCHAR));
2480 SetLastError(0xdeadbeef);
2481 res = ClosePrinter(hprn);
2482 ok(res, "ClosePrinter error %d\n", GetLastError());
2485 /* ########################### */
2487 static void test_GetPrinterDriver(void)
2489 HANDLE hprn;
2490 BOOL ret;
2491 BYTE *buf;
2492 INT level;
2493 DWORD needed, filled;
2495 if (!default_printer)
2497 skip("There is no default printer installed\n");
2498 return;
2501 hprn = 0;
2502 ret = OpenPrinter(default_printer, &hprn, NULL);
2503 if (!ret)
2505 skip("Unable to open the default printer (%s)\n", default_printer);
2506 return;
2508 ok(hprn != 0, "wrong hprn %p\n", hprn);
2510 for (level = -1; level <= 7; level++)
2512 SetLastError(0xdeadbeef);
2513 needed = (DWORD)-1;
2514 ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
2515 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
2516 if (level >= 1 && level <= 6)
2518 /* Not all levels are supported on all Windows-Versions */
2519 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
2520 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2521 ok(needed > 0,"not expected needed buffer size %d\n", needed);
2523 else
2525 /* ERROR_OUTOFMEMORY found on win9x */
2526 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
2527 (GetLastError() == ERROR_OUTOFMEMORY)),
2528 "%d: returned %d with %d (expected '0' with: "
2529 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2530 level, ret, GetLastError());
2531 /* needed is modified in win9x. The modified Value depends on the
2532 default Printer. testing for "needed == (DWORD)-1" will fail */
2533 continue;
2536 /* GetPrinterDriverA returns the same number of bytes as GetPrinterDriverW */
2537 if (!on_win9x && !ret && pGetPrinterDriverW)
2539 DWORD double_needed;
2540 ret = pGetPrinterDriverW(hprn, NULL, level, NULL, 0, &double_needed);
2541 ok(double_needed == needed, "GetPrinterDriverA returned different size %d than GetPrinterDriverW (%d)\n", needed, double_needed);
2544 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2546 SetLastError(0xdeadbeef);
2547 filled = -1;
2548 ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
2549 ok(ret, "level %d: GetPrinterDriver error %d\n", level, GetLastError());
2550 ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2552 if (level == 2)
2554 DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
2555 DWORD calculated = sizeof(*di_2);
2556 HANDLE hf;
2558 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2559 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
2560 ok( (di_2->cVersion <= 3) ||
2561 (di_2->cVersion == 0x0400), "di_2->cVersion = %d\n", di_2->cVersion);
2562 ok(di_2->pName != NULL, "not expected NULL ptr\n");
2563 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
2564 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
2565 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
2566 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
2568 trace("cVersion %d\n", di_2->cVersion);
2569 trace("pName %s\n", di_2->pName);
2570 calculated += strlen(di_2->pName) + 1;
2571 trace("pEnvironment %s\n", di_2->pEnvironment);
2572 calculated += strlen(di_2->pEnvironment) + 1;
2573 trace("pDriverPath %s\n", di_2->pDriverPath);
2574 calculated += strlen(di_2->pDriverPath) + 1;
2575 trace("pDataFile %s\n", di_2->pDataFile);
2576 calculated += strlen(di_2->pDataFile) + 1;
2577 trace("pConfigFile %s\n", di_2->pConfigFile);
2578 calculated += strlen(di_2->pConfigFile) + 1;
2580 hf = CreateFileA(di_2->pDriverPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2581 if(hf != INVALID_HANDLE_VALUE)
2582 CloseHandle(hf);
2583 todo_wine
2584 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDriverPath);
2586 hf = CreateFileA(di_2->pDataFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2587 if(hf != INVALID_HANDLE_VALUE)
2588 CloseHandle(hf);
2589 todo_wine
2590 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDataFile);
2592 hf = CreateFileA(di_2->pConfigFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2593 if(hf != INVALID_HANDLE_VALUE)
2594 CloseHandle(hf);
2595 todo_wine
2596 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pConfigFile);
2598 /* XP allocates memory for both ANSI and unicode names */
2599 ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
2601 /* Obscure test - demonstrate that Windows zero fills the buffer, even on failure */
2602 if (di_2->pDataFile)
2604 ret = GetPrinterDriver(hprn, NULL, level, buf, needed - 2, &filled);
2605 ok(!ret, "level %d: GetPrinterDriver succeeded with less buffer than it should\n", level);
2606 ok(di_2->pDataFile == NULL ||
2607 broken(di_2->pDataFile != NULL), /* Win9x/WinMe */
2608 "Even on failure, GetPrinterDriver clears the buffer to zeros\n");
2612 HeapFree(GetProcessHeap(), 0, buf);
2615 SetLastError(0xdeadbeef);
2616 ret = ClosePrinter(hprn);
2617 ok(ret, "ClosePrinter error %d\n", GetLastError());
2620 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
2622 /* On NT3.51, some fields in DEVMODE are empty/zero
2623 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2624 We skip the Tests on this Platform */
2625 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
2626 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2627 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1) ||
2628 !strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -2), /* XP+ */
2629 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
2630 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
2631 "%u != %d\n", dm->dmSize + dm->dmDriverExtra, dmSize);
2633 trace("dmFields %08x\n", dm->dmFields);
2636 static void test_DocumentProperties(void)
2638 HANDLE hprn;
2639 LONG dm_size, ret;
2640 DEVMODE *dm;
2642 if (!default_printer)
2644 skip("There is no default printer installed\n");
2645 return;
2648 hprn = 0;
2649 ret = OpenPrinter(default_printer, &hprn, NULL);
2650 if (!ret)
2652 skip("Unable to open the default printer (%s)\n", default_printer);
2653 return;
2655 ok(hprn != 0, "wrong hprn %p\n", hprn);
2657 dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
2658 trace("DEVMODE required size %d\n", dm_size);
2659 ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %d\n", dm_size);
2661 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
2663 ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
2664 ok(ret == IDOK, "DocumentProperties ret value %d != expected IDOK\n", ret);
2666 test_DEVMODE(dm, dm_size, default_printer);
2668 HeapFree(GetProcessHeap(), 0, dm);
2670 SetLastError(0xdeadbeef);
2671 ret = ClosePrinter(hprn);
2672 ok(ret, "ClosePrinter error %d\n", GetLastError());
2675 static void test_EnumPrinters(void)
2677 DWORD neededA, neededW, num;
2678 DWORD ret;
2680 SetLastError(0xdeadbeef);
2681 neededA = -1;
2682 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
2683 RETURN_ON_DEACTIVATED_SPOOLER(ret)
2684 if (!ret)
2686 /* We have 1 or more printers */
2687 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2688 ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
2690 else
2692 /* We don't have any printers defined */
2693 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2694 ok(neededA == 0, "Expected neededA to be zero\n");
2696 ok(num == 0, "num %d\n", num);
2698 SetLastError(0xdeadbeef);
2699 neededW = -1;
2700 ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
2701 /* EnumPrintersW is not supported on all platforms */
2702 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
2704 win_skip("EnumPrintersW is not implemented\n");
2705 return;
2708 if (!ret)
2710 /* We have 1 or more printers */
2711 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2712 ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
2714 else
2716 /* We don't have any printers defined */
2717 ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2718 ok(neededW == 0, "Expected neededW to be zero\n");
2720 ok(num == 0, "num %d\n", num);
2722 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2723 to hold the buffer returned by EnumPrintersW */
2724 ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
2727 static void test_DeviceCapabilities(void)
2729 HANDLE hComdlg32;
2730 BOOL (WINAPI *pPrintDlgA)(PRINTDLGA *);
2731 PRINTDLGA prn_dlg;
2732 DEVMODE *dm;
2733 DEVNAMES *dn;
2734 const char *driver, *device, *port;
2735 WORD *papers;
2736 POINT *paper_size;
2737 POINTS ext;
2738 struct
2740 char name[64];
2741 } *paper_name;
2742 INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
2743 DWORD fields;
2745 hComdlg32 = LoadLibrary("comdlg32.dll");
2746 assert(hComdlg32);
2747 pPrintDlgA = (void *)GetProcAddress(hComdlg32, "PrintDlgA");
2748 assert(pPrintDlgA);
2750 memset(&prn_dlg, 0, sizeof(prn_dlg));
2751 prn_dlg.lStructSize = sizeof(prn_dlg);
2752 prn_dlg.Flags = PD_RETURNDEFAULT;
2753 ret = pPrintDlgA(&prn_dlg);
2754 FreeLibrary(hComdlg32);
2755 if (!ret)
2757 skip("PrintDlg returned no default printer\n");
2758 return;
2760 ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
2761 ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
2763 dm = GlobalLock(prn_dlg.hDevMode);
2764 ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
2765 trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
2767 dn = GlobalLock(prn_dlg.hDevNames);
2768 ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
2769 ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
2770 ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
2771 ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
2772 ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
2773 driver = (const char *)dn + dn->wDriverOffset;
2774 device = (const char *)dn + dn->wDeviceOffset;
2775 port = (const char *)dn + dn->wOutputOffset;
2776 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
2778 test_DEVMODE(dm, dm->dmSize + dm->dmDriverExtra, device);
2780 n_papers = DeviceCapabilities(device, port, DC_PAPERS, NULL, NULL);
2781 ok(n_papers > 0, "DeviceCapabilities DC_PAPERS failed\n");
2782 papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
2783 ret = DeviceCapabilities(device, port, DC_PAPERS, (LPSTR)papers, NULL);
2784 ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
2785 #ifdef VERBOSE
2786 for (ret = 0; ret < n_papers; ret++)
2787 trace("papers[%d] = %d\n", ret, papers[ret]);
2788 #endif
2789 HeapFree(GetProcessHeap(), 0, papers);
2791 n_paper_size = DeviceCapabilities(device, port, DC_PAPERSIZE, NULL, NULL);
2792 ok(n_paper_size > 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
2793 ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
2794 paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
2795 ret = DeviceCapabilities(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
2796 ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
2797 #ifdef VERBOSE
2798 for (ret = 0; ret < n_paper_size; ret++)
2799 trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
2800 #endif
2801 HeapFree(GetProcessHeap(), 0, paper_size);
2803 n_paper_names = DeviceCapabilities(device, port, DC_PAPERNAMES, NULL, NULL);
2804 ok(n_paper_names > 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
2805 ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
2806 paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
2807 ret = DeviceCapabilities(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
2808 ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
2809 #ifdef VERBOSE
2810 for (ret = 0; ret < n_paper_names; ret++)
2811 trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
2812 #endif
2813 HeapFree(GetProcessHeap(), 0, paper_name);
2815 n_copies = DeviceCapabilities(device, port, DC_COPIES, NULL, dm);
2816 ok(n_copies > 0, "DeviceCapabilities DC_COPIES failed\n");
2817 trace("n_copies = %d\n", n_copies);
2819 /* these capabilities not available on all printer drivers */
2820 if (0)
2822 ret = DeviceCapabilities(device, port, DC_MAXEXTENT, NULL, NULL);
2823 ok(ret != -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
2824 ext = MAKEPOINTS(ret);
2825 trace("max ext = %d x %d\n", ext.x, ext.y);
2827 ret = DeviceCapabilities(device, port, DC_MINEXTENT, NULL, NULL);
2828 ok(ret != -1, "DeviceCapabilities DC_MINEXTENT failed\n");
2829 ext = MAKEPOINTS(ret);
2830 trace("min ext = %d x %d\n", ext.x, ext.y);
2833 fields = DeviceCapabilities(device, port, DC_FIELDS, NULL, NULL);
2834 ok(fields != (DWORD)-1, "DeviceCapabilities DC_FIELDS failed\n");
2835 todo_wine
2836 ok(fields == (dm->dmFields | DM_FORMNAME) ||
2837 broken(fields == dm->dmFields), /* Win9x/WinMe */
2838 "fields %x != (dm->dmFields | DM_FORMNAME) %lx\n", fields, (dm->dmFields | DM_FORMNAME));
2840 GlobalUnlock(prn_dlg.hDevMode);
2841 GlobalFree(prn_dlg.hDevMode);
2842 GlobalUnlock(prn_dlg.hDevNames);
2843 GlobalFree(prn_dlg.hDevNames);
2846 START_TEST(info)
2848 hwinspool = GetModuleHandleA("winspool.drv");
2849 pAddPortExA = (void *) GetProcAddress(hwinspool, "AddPortExA");
2850 pEnumPrinterDriversW = (void *) GetProcAddress(hwinspool, "EnumPrinterDriversW");
2851 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
2852 pGetPrinterDataExA = (void *) GetProcAddress(hwinspool, "GetPrinterDataExA");
2853 pGetPrinterDriverW = (void *) GetProcAddress(hwinspool, "GetPrinterDriverW");
2854 pGetPrinterW = (void *) GetProcAddress(hwinspool, "GetPrinterW");
2855 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
2856 pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
2858 on_win9x = check_win9x();
2859 if (on_win9x)
2860 win_skip("Several W-functions are not available on Win9x/WinMe\n");
2862 find_default_printer();
2863 find_local_server();
2864 find_tempfile();
2866 test_AddMonitor();
2867 test_AddPort();
2868 test_AddPortEx();
2869 test_ConfigurePort();
2870 test_DeleteMonitor();
2871 test_DeletePort();
2872 test_DeviceCapabilities();
2873 test_DocumentProperties();
2874 test_EnumForms(NULL);
2875 if (default_printer) test_EnumForms(default_printer);
2876 test_EnumMonitors();
2877 test_EnumPorts();
2878 test_EnumPrinterDrivers();
2879 test_EnumPrinters();
2880 test_EnumPrintProcessors();
2881 test_GetDefaultPrinter();
2882 test_GetPrinterDriverDirectory();
2883 test_GetPrintProcessorDirectory();
2884 test_OpenPrinter();
2885 test_GetPrinter();
2886 test_GetPrinterData();
2887 test_GetPrinterDataEx();
2888 test_GetPrinterDriver();
2889 test_SetDefaultPrinter();
2890 test_XcvDataW_MonitorUI();
2891 test_XcvDataW_PortIsValid();
2893 /* Cleanup our temporary file */
2894 DeleteFileA(tempfileA);