include/windows.foundation: Add double reference.
[wine.git] / dlls / winspool.drv / tests / info.c
blob52849277c4c2141f3977adda424f6eec20bcf366
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 HANDLE hwinspool;
60 static BOOL (WINAPI * pAddPortExA)(LPSTR, DWORD, LPBYTE, LPSTR);
61 static BOOL (WINAPI * pEnumPrinterDriversW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
62 static BOOL (WINAPI * pGetDefaultPrinterA)(LPSTR, LPDWORD);
63 static DWORD (WINAPI * pGetPrinterDataExA)(HANDLE, LPCSTR, LPCSTR, LPDWORD, LPBYTE, DWORD, LPDWORD);
64 static BOOL (WINAPI * pGetPrinterDriverW)(HANDLE, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD);
65 static BOOL (WINAPI * pGetPrinterW)(HANDLE, DWORD, LPBYTE, DWORD, LPDWORD);
66 static BOOL (WINAPI * pSetDefaultPrinterA)(LPCSTR);
67 static DWORD (WINAPI * pXcvDataW)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD, PDWORD);
69 /* ################################ */
71 struct monitor_entry {
72 LPSTR env;
73 CHAR dllname[32];
76 static LPSTR default_printer = NULL;
77 static LPSTR local_server = NULL;
78 static LPSTR tempdirA = NULL;
79 static LPSTR tempfileA = NULL;
80 static LPWSTR tempdirW = NULL;
81 static LPWSTR tempfileW = NULL;
83 static BOOL is_spooler_deactivated(DWORD res, DWORD lasterror)
85 if (!res && lasterror == RPC_S_SERVER_UNAVAILABLE)
87 static int deactivated_spooler_reported = 0;
88 if (!deactivated_spooler_reported)
90 deactivated_spooler_reported = 1;
91 skip("The service 'Spooler' is required for many tests\n");
93 return TRUE;
95 return FALSE;
98 static BOOL is_access_denied(DWORD res, DWORD lasterror)
100 if (!res && lasterror == ERROR_ACCESS_DENIED)
102 static int access_denied_reported = 0;
103 if (!access_denied_reported)
105 access_denied_reported = 1;
106 skip("More access rights are required for many tests\n");
108 return TRUE;
110 return FALSE;
113 static void find_default_printer(VOID)
115 static char buffer[DEFAULT_PRINTER_SIZE];
116 DWORD needed;
117 DWORD res;
118 LPSTR ptr;
120 if ((default_printer == NULL) && (pGetDefaultPrinterA))
122 /* w2k and above */
123 needed = sizeof(buffer);
124 res = pGetDefaultPrinterA(buffer, &needed);
125 if(res) default_printer = buffer;
126 trace("default_printer: '%s'\n", default_printer ? default_printer : "(null)");
128 if (default_printer == NULL)
130 HKEY hwindows;
131 DWORD type;
132 /* NT 3.x and above */
133 if (RegOpenKeyExA(HKEY_CURRENT_USER,
134 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
135 0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
137 needed = sizeof(buffer);
138 if (RegQueryValueExA(hwindows, "device", NULL, &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
139 ptr = strchr(buffer, ',');
140 if (ptr) {
141 ptr[0] = '\0';
142 default_printer = buffer;
145 RegCloseKey(hwindows);
147 trace("default_printer: '%s'\n", default_printer ? default_printer : "(null)");
149 if (default_printer == NULL)
151 /* win9x */
152 needed = sizeof(buffer);
153 res = GetProfileStringA("windows", "device", "*", buffer, needed);
154 if(res) {
155 ptr = strchr(buffer, ',');
156 if (ptr) {
157 ptr[0] = '\0';
158 default_printer = buffer;
161 trace("default_printer: '%s'\n", default_printer ? default_printer : "(null)");
166 static struct monitor_entry * find_installed_monitor(void)
168 MONITOR_INFO_2A mi2a;
169 static struct monitor_entry * entry = NULL;
170 DWORD num_tests;
171 DWORD i = 0;
173 static struct monitor_entry monitor_table[] = {
174 {env_win9x_case, "localspl.dll"},
175 {env_x86, "localspl.dll"},
176 {env_x64, "localspl.dll"},
177 {env_win9x_case, "localmon.dll"},
178 {env_x86, "localmon.dll"},
179 {env_win9x_case, "tcpmon.dll"},
180 {env_x86, "tcpmon.dll"},
181 {env_win9x_case, "usbmon.dll"},
182 {env_x86, "usbmon.dll"},
183 {env_win9x_case, "mspp32.dll"},
184 {env_x86, "win32spl.dll"},
185 {env_x86, "redmonnt.dll"},
186 {env_x86, "redmon35.dll"},
187 {env_win9x_case, "redmon95.dll"},
188 {env_x86, "pdfcmnnt.dll"},
189 {env_win9x_case, "pdfcmn95.dll"},
192 if (entry) return entry;
194 num_tests = ARRAY_SIZE(monitor_table);
196 /* cleanup */
197 DeleteMonitorA(NULL, env_x64, winetest);
198 DeleteMonitorA(NULL, env_x86, winetest);
199 DeleteMonitorA(NULL, env_win9x_case, winetest);
201 /* find a usable monitor from the table */
202 mi2a.pName = winetest;
203 while ((entry == NULL) && (i < num_tests)) {
204 entry = &monitor_table[i];
205 i++;
206 mi2a.pEnvironment = entry->env;
207 mi2a.pDLLName = entry->dllname;
209 if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
210 /* we got one */
211 trace("using '%s', '%s'\n", entry->env, entry->dllname);
212 DeleteMonitorA(NULL, entry->env, winetest);
214 else
216 entry = NULL;
219 return entry;
223 /* ########################### */
225 static void find_local_server(VOID)
227 static char buffer[MAX_PATH];
228 DWORD res;
229 DWORD size;
231 size = sizeof(buffer) - 3 ;
232 buffer[0] = '\\';
233 buffer[1] = '\\';
234 buffer[2] = '\0';
236 SetLastError(0xdeadbeef);
237 res = GetComputerNameA(&buffer[2], &size);
238 trace("returned %ld with %ld and %ld: '%s'\n", res, GetLastError(), size, buffer);
240 ok( res != 0, "returned %ld with %ld and %ld: '%s' (expected '!= 0')\n",
241 res, GetLastError(), size, buffer);
243 if (res) local_server = buffer;
246 /* ########################### */
248 static void find_tempfile(VOID)
250 static CHAR buffer_dirA[MAX_PATH];
251 static CHAR buffer_fileA[MAX_PATH];
252 static WCHAR buffer_dirW[MAX_PATH];
253 static WCHAR buffer_fileW[MAX_PATH];
254 DWORD res;
255 int resint;
257 memset(buffer_dirA, 0, MAX_PATH - 1);
258 buffer_dirA[MAX_PATH - 1] = '\0';
259 SetLastError(0xdeadbeef);
260 res = GetTempPathA(MAX_PATH, buffer_dirA);
261 ok(res, "returned %lu with %lu and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
262 if (res == 0) return;
264 memset(buffer_fileA, 0, MAX_PATH - 1);
265 buffer_fileA[MAX_PATH - 1] = '\0';
266 SetLastError(0xdeadbeef);
267 res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
268 ok(res, "returned %lu with %lu and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
269 if (res == 0) return;
271 SetLastError(0xdeadbeef);
272 resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
273 ok(res, "returned %u with %lu (expected '!= 0')\n", resint, GetLastError());
274 if (resint == 0) return;
276 SetLastError(0xdeadbeef);
277 resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
278 ok(res, "returned %u with %lu (expected '!= 0')\n", resint, GetLastError());
279 if (resint == 0) return;
281 tempdirA = buffer_dirA;
282 tempfileA = buffer_fileA;
283 tempdirW = buffer_dirW;
284 tempfileW = buffer_fileW;
285 trace("tempfile: '%s'\n", tempfileA);
288 /* ########################### */
290 static void test_AddMonitor(void)
292 MONITOR_INFO_2A mi2a;
293 struct monitor_entry * entry = NULL;
294 DWORD res;
296 entry = find_installed_monitor();
298 SetLastError(MAGIC_DEAD);
299 res = AddMonitorA(NULL, 1, NULL);
300 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
301 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
302 res, GetLastError());
304 SetLastError(MAGIC_DEAD);
305 res = AddMonitorA(NULL, 3, NULL);
306 ok(!res && (GetLastError() == ERROR_INVALID_LEVEL),
307 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
308 res, GetLastError());
310 /* This test crashes win9x on vmware (works with win9x on qemu 0.8.1) */
311 SetLastError(MAGIC_DEAD);
312 res = AddMonitorA(NULL, 2, NULL);
313 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
314 ok(!res &&
315 ((GetLastError() == MAGIC_DEAD) ||
316 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
317 "returned %ld with %ld (expected '0' with: MAGIC_DEAD or "
318 "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
320 ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
321 SetLastError(MAGIC_DEAD);
322 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
323 if (is_spooler_deactivated(res, GetLastError())) return;
324 if (is_access_denied(res, GetLastError())) return;
326 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
327 ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
328 (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
329 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or "
330 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
332 if (!entry) {
333 skip("No usable Monitor found\n");
334 return;
337 if (0)
339 /* The test is deactivated, because when mi2a.pName is NULL, the subkey
340 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
341 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
342 is created on win9x and we do not want to hit this bug here. */
344 mi2a.pEnvironment = entry->env;
345 SetLastError(MAGIC_DEAD);
346 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
347 ok(res, "AddMonitor error %ld\n", GetLastError());
348 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
351 mi2a.pEnvironment = entry->env;
352 mi2a.pName = empty;
353 SetLastError(MAGIC_DEAD);
354 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
355 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
356 ok( !res &&
357 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
358 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
359 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or "
360 "ERROR_PRIVILEGE_NOT_HELD)\n",
361 res, GetLastError());
363 mi2a.pName = winetest;
364 SetLastError(MAGIC_DEAD);
365 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
366 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
367 ok( !res &&
368 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
369 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)),
370 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or "
371 "ERROR_PRIVILEGE_NOT_HELD)\n",
372 res, GetLastError());
374 mi2a.pDLLName = empty;
375 SetLastError(MAGIC_DEAD);
376 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
377 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
378 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
379 res, GetLastError());
381 mi2a.pDLLName = does_not_exist_dll;
382 SetLastError(MAGIC_DEAD);
383 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
384 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
385 ok( !res &&
386 ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
387 (GetLastError() == ERROR_INVALID_PARAMETER)),
388 "returned %ld with %ld (expected '0' with: ERROR_MOD_NOT_FOUND or "
389 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
391 mi2a.pDLLName = version_dll;
392 SetLastError(MAGIC_DEAD);
393 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
394 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
395 ok( !res &&
396 ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
397 (GetLastError() == ERROR_INVALID_PARAMETER)),
398 "returned %ld with %ld (expected '0' with: ERROR_PROC_NOT_FOUND or "
399 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
400 if (res) DeleteMonitorA(NULL, entry->env, winetest);
402 /* Test AddMonitor with real options */
403 mi2a.pDLLName = entry->dllname;
404 SetLastError(MAGIC_DEAD);
405 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
406 /* Some apps depend on the result of GetLastError() also on success of AddMonitor */
407 ok(res && (GetLastError() == ERROR_SUCCESS),
408 "returned %ld with %ld (expected '!= 0' with ERROR_SUCCESS)\n", res, GetLastError());
410 /* add a monitor twice */
411 SetLastError(MAGIC_DEAD);
412 res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
413 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
414 ok( !res &&
415 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
416 (GetLastError() == ERROR_ALREADY_EXISTS)),
417 "returned %ld with %ld (expected '0' with: "
418 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
419 res, GetLastError());
421 DeleteMonitorA(NULL, entry->env, winetest);
422 SetLastError(MAGIC_DEAD);
423 res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
424 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
426 /* cleanup */
427 DeleteMonitorA(NULL, entry->env, winetest);
431 /* ########################### */
433 static void test_AddPort(void)
435 DWORD res;
437 SetLastError(0xdeadbeef);
438 res = AddPortA(NULL, 0, NULL);
439 if (is_spooler_deactivated(res, GetLastError())) return;
440 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
441 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
442 (GetLastError() == ERROR_INVALID_PARAMETER)),
443 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
444 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
447 SetLastError(0xdeadbeef);
448 res = AddPortA(NULL, 0, empty);
449 /* Allowed only for (Printer-)Administrators */
450 if (is_access_denied(res, GetLastError())) return;
452 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
453 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
454 (GetLastError() == ERROR_INVALID_PARAMETER)),
455 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
456 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
459 SetLastError(0xdeadbeef);
460 res = AddPortA(NULL, 0, does_not_exist);
461 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
462 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
463 (GetLastError() == ERROR_INVALID_PARAMETER)),
464 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
465 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
469 /* ########################### */
471 static void test_AddPortEx(void)
473 PORT_INFO_2A pi;
474 DWORD res;
477 if (!pAddPortExA) {
478 win_skip("AddPortEx not supported\n");
479 return;
482 /* start test with a clean system */
483 DeletePortA(NULL, 0, tempfileA);
485 pi.pPortName = tempfileA;
486 SetLastError(0xdeadbeef);
487 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
488 if (is_spooler_deactivated(res, GetLastError())) return;
490 /* Allowed only for (Printer-)Administrators.
491 W2K+XP: ERROR_INVALID_PARAMETER */
492 if (!res && (GetLastError() == ERROR_INVALID_PARAMETER)) {
493 skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
494 return;
496 ok( res, "got %lu with %lu (expected '!= 0')\n", res, GetLastError());
498 /* add a port that already exists */
499 SetLastError(0xdeadbeef);
500 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
501 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
502 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
503 res, GetLastError());
504 DeletePortA(NULL, 0, tempfileA);
507 /* the Monitorname must match */
508 SetLastError(0xdeadbeef);
509 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, NULL);
510 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
511 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
512 res, GetLastError());
513 if (res) DeletePortA(NULL, 0, tempfileA);
515 SetLastError(0xdeadbeef);
516 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, empty);
517 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
518 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
519 res, GetLastError());
520 if (res) DeletePortA(NULL, 0, tempfileA);
522 SetLastError(0xdeadbeef);
523 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, does_not_exist);
524 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
525 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
526 res, GetLastError());
527 if (res) DeletePortA(NULL, 0, tempfileA);
530 /* We need a Portname */
531 SetLastError(0xdeadbeef);
532 res = pAddPortExA(NULL, 1, NULL, LocalPortA);
533 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
534 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
535 res, GetLastError());
537 pi.pPortName = NULL;
538 SetLastError(0xdeadbeef);
539 res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
540 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
541 "got %lu with %lu (expected '0' with ERROR_INVALID_PARAMETER)\n",
542 res, GetLastError());
543 if (res) DeletePortA(NULL, 0, tempfileA);
546 /* level 2 is documented as supported for Printmonitors,
547 but that is not supported for "Local Port" (localspl.dll) and
548 AddPortEx fails with ERROR_INVALID_LEVEL */
550 pi.pPortName = tempfileA;
551 pi.pMonitorName = LocalPortA;
552 pi.pDescription = winetest;
553 pi.fPortType = PORT_TYPE_WRITE;
555 SetLastError(0xdeadbeef);
556 res = pAddPortExA(NULL, 2, (LPBYTE) &pi, LocalPortA);
557 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
558 "got %lu with %lu (expected '0' with ERROR_INVALID_LEVEL)\n",
559 res, GetLastError());
560 if (res) DeletePortA(NULL, 0, tempfileA);
563 /* invalid levels */
564 SetLastError(0xdeadbeef);
565 res = pAddPortExA(NULL, 0, (LPBYTE) &pi, LocalPortA);
566 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
567 "got %lu with %lu (expected '0' with ERROR_INVALID_LEVEL)\n",
568 res, GetLastError());
570 SetLastError(0xdeadbeef);
571 res = pAddPortExA(NULL, 3, (LPBYTE) &pi, LocalPortA);
572 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
573 "got %lu with %lu (expected '0' with ERROR_INVALID_LEVEL)\n",
574 res, GetLastError());
577 /* cleanup */
578 DeletePortA(NULL, 0, tempfileA);
582 /* ########################### */
584 static void test_ConfigurePort(void)
586 DWORD res;
589 SetLastError(0xdeadbeef);
590 res = ConfigurePortA(NULL, 0, NULL);
591 if (is_spooler_deactivated(res, GetLastError())) return;
592 /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
593 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
594 (GetLastError() == ERROR_INVALID_PARAMETER)),
595 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
596 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
598 SetLastError(0xdeadbeef);
599 res = ConfigurePortA(NULL, 0, empty);
600 /* Allowed only for (Printer-)Administrators */
601 if (is_access_denied(res, GetLastError())) return;
603 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
604 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
605 (GetLastError() == ERROR_INVALID_PARAMETER)),
606 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
607 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
610 SetLastError(0xdeadbeef);
611 res = ConfigurePortA(NULL, 0, does_not_exist);
612 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
613 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
614 (GetLastError() == ERROR_INVALID_PARAMETER)),
615 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
616 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
619 /* Testing-Results:
620 - Case of Portnames is ignored
621 - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
622 - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
624 - Port not present => 9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
625 - "FILE:" => 9x:Success, NT:ERROR_CANCELED
626 - Cancel ("Local Port") => ERROR_CANCELED
627 - Cancel ("Redirected Port") => Success
629 if (winetest_interactive > 0) {
630 SetLastError(0xdeadbeef);
631 res = ConfigurePortA(NULL, 0, portname_com1);
632 trace("'%s' returned %ld with %ld\n", portname_com1, res, GetLastError());
634 SetLastError(0xdeadbeef);
635 res = ConfigurePortA(NULL, 0, portname_lpt1);
636 trace("'%s' returned %ld with %ld\n", portname_lpt1, res, GetLastError());
638 SetLastError(0xdeadbeef);
639 res = ConfigurePortA(NULL, 0, portname_file);
640 trace("'%s' returned %ld with %ld\n", portname_file, res, GetLastError());
644 /* ########################### */
646 static void test_ClosePrinter(void)
648 HANDLE printer = 0;
649 BOOL res;
651 /* NULL is handled */
652 SetLastError(0xdeadbeef);
653 res = ClosePrinter(NULL);
654 ok(!res && (GetLastError() == ERROR_INVALID_HANDLE),
655 "got %d with %ld (expected FALSE with ERROR_INVALID_HANDLE)\n",
656 res, GetLastError());
658 /* A random value as HANDLE is handled */
659 SetLastError(0xdeadbeef);
660 res = ClosePrinter( (void *) -1);
661 if (is_spooler_deactivated(res, GetLastError())) return;
662 ok(!res && (GetLastError() == ERROR_INVALID_HANDLE),
663 "got %d with %ld (expected FALSE with ERROR_INVALID_HANDLE)\n",
664 res, GetLastError());
667 /* Normal use (The Spooler service is needed) */
668 SetLastError(0xdeadbeef);
669 res = OpenPrinterA(default_printer, &printer, NULL);
670 if (is_spooler_deactivated(res, GetLastError())) return;
671 if (res)
673 SetLastError(0xdeadbeef);
674 res = ClosePrinter(printer);
675 ok(res, "got %d with %ld (expected TRUE)\n", res, GetLastError());
678 /* double free is handled */
679 SetLastError(0xdeadbeef);
680 res = ClosePrinter(printer);
681 ok(!res && (GetLastError() == ERROR_INVALID_HANDLE),
682 "got %d with %ld (expected FALSE with ERROR_INVALID_HANDLE)\n",
683 res, GetLastError());
688 /* ########################### */
690 static void test_DeleteMonitor(void)
692 MONITOR_INFO_2A mi2a;
693 struct monitor_entry * entry = NULL;
694 DWORD res;
697 entry = find_installed_monitor();
699 if (!entry) {
700 skip("No usable Monitor found\n");
701 return;
704 mi2a.pName = winetest;
705 mi2a.pEnvironment = entry->env;
706 mi2a.pDLLName = entry->dllname;
708 /* Testing DeleteMonitor with real options */
709 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
711 SetLastError(MAGIC_DEAD);
712 res = DeleteMonitorA(NULL, entry->env, winetest);
713 ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
715 /* Delete the Monitor twice */
716 SetLastError(MAGIC_DEAD);
717 res = DeleteMonitorA(NULL, entry->env, winetest);
718 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
719 ok( !res &&
720 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
721 (GetLastError() == ERROR_INVALID_PARAMETER)),
722 "returned %ld with %ld (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
723 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
725 /* the environment */
726 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
727 SetLastError(MAGIC_DEAD);
728 res = DeleteMonitorA(NULL, NULL, winetest);
729 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
731 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
732 SetLastError(MAGIC_DEAD);
733 res = DeleteMonitorA(NULL, empty, winetest);
734 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
736 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
737 SetLastError(MAGIC_DEAD);
738 res = DeleteMonitorA(NULL, invalid_env, winetest);
739 ok( res || GetLastError() == ERROR_INVALID_ENVIRONMENT /* Vista/W2K8 */,
740 "returned %ld with %ld\n", res, GetLastError());
742 /* the monitor-name */
743 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
744 SetLastError(MAGIC_DEAD);
745 res = DeleteMonitorA(NULL, entry->env, NULL);
746 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
747 ok( !res &&
748 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
749 (GetLastError() == ERROR_INVALID_NAME)),
750 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or "
751 "ERROR_INVALID_NAME)\n", res, GetLastError());
753 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
754 SetLastError(MAGIC_DEAD);
755 res = DeleteMonitorA(NULL, entry->env, empty);
756 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
757 ok( !res &&
758 ((GetLastError() == ERROR_INVALID_PARAMETER) ||
759 (GetLastError() == ERROR_INVALID_NAME)),
760 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or "
761 "ERROR_INVALID_NAME)\n", res, GetLastError());
763 AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
764 SetLastError(MAGIC_DEAD);
765 res = DeleteMonitorA(empty, entry->env, winetest);
766 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
768 /* cleanup */
769 DeleteMonitorA(NULL, entry->env, winetest);
772 /* ########################### */
774 static void test_DeletePort(void)
776 DWORD res;
778 SetLastError(0xdeadbeef);
779 res = DeletePortA(NULL, 0, NULL);
780 if (is_spooler_deactivated(res, GetLastError())) return;
782 SetLastError(0xdeadbeef);
783 res = DeletePortA(NULL, 0, empty);
784 /* Allowed only for (Printer-)Administrators */
785 if (is_access_denied(res, GetLastError())) return;
787 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
788 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
789 (GetLastError() == ERROR_INVALID_PARAMETER)),
790 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
791 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
794 SetLastError(0xdeadbeef);
795 res = DeletePortA(NULL, 0, does_not_exist);
796 /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
797 ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) ||
798 (GetLastError() == ERROR_INVALID_PARAMETER)),
799 "returned %ld with %ld (expected '0' with ERROR_NOT_SUPPORTED or "
800 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
804 /* ########################### */
806 static void test_EnumForms(LPSTR pName)
808 DWORD res;
809 HANDLE hprinter = 0;
810 LPBYTE buffer;
811 DWORD cbBuf;
812 DWORD pcbNeeded;
813 DWORD pcReturned;
814 DWORD level;
815 UINT i;
816 const char *formtype;
817 static const char * const formtypes[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
818 #define FORMTYPE_MAX 2
819 PFORM_INFO_1A pFI_1a;
820 PFORM_INFO_2A pFI_2a;
822 res = OpenPrinterA(pName, &hprinter, NULL);
823 if (is_spooler_deactivated(res, GetLastError())) return;
824 if (!res || !hprinter)
826 /* opening the local Printserver is not supported on win9x */
827 if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
828 return;
831 /* valid levels are 1 and 2 */
832 for(level = 0; level < 4; level++) {
833 cbBuf = 0xdeadbeef;
834 pcReturned = 0xdeadbeef;
835 SetLastError(0xdeadbeef);
836 res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
838 /* EnumForms is not implemented on win9x */
839 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
841 /* EnumForms for the server is not implemented on all NT-versions */
842 if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
844 /* Level 2 for EnumForms is not supported on all systems */
845 if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
847 /* use only a short test when testing an invalid level */
848 if(!level || (level > 2)) {
849 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
850 (res && (pcReturned == 0)),
851 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with "
852 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
853 level, res, GetLastError(), pcReturned);
854 continue;
857 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
858 "(%ld) returned %ld with %ld (expected '0' with "
859 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
861 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
862 if (buffer == NULL) continue;
864 SetLastError(0xdeadbeef);
865 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
866 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
867 level, res, GetLastError());
869 pFI_1a = (PFORM_INFO_1A)buffer;
870 pFI_2a = (PFORM_INFO_2A)buffer;
871 for (i = 0; i < pcReturned; i++)
873 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
874 formtype = (pFI_1a->Flags <= FORMTYPE_MAX) ? formtypes[pFI_1a->Flags] : formtypes[3];
875 if (winetest_debug > 1)
876 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i, pFI_1a->pName,
877 (float)pFI_1a->Size.cx/1000, (float)pFI_1a->Size.cy/1000, formtype);
879 if (level == 1) pFI_1a++;
880 else
882 BYTE get_buffer[1000];
883 FORM_INFO_2A *get_form = (FORM_INFO_2A *)get_buffer;
884 DWORD get_needed;
886 /* output additional FORM_INFO_2 fields */
887 if (winetest_debug > 1)
888 trace("\tkeyword=%s strtype=%lu muidll=%s resid=%lu dispname=%s langid=%u\n",
889 pFI_2a->pKeyword, pFI_2a->StringType, pFI_2a->pMuiDll,
890 pFI_2a->dwResourceId, pFI_2a->pDisplayName, pFI_2a->wLangId);
892 if (pName && i == 0) /* GetForm() appears only to work on a printer handle */
894 res = GetFormA( hprinter, pFI_1a->pName, level, NULL, 0, &get_needed );
895 ok( !res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %ld gle %ld\n", res, GetLastError() );
896 if (get_needed <= sizeof(get_buffer))
898 res = GetFormA( hprinter, pFI_1a->pName, level, get_buffer, get_needed, &get_needed );
899 ok( res, "got %ld\n", res );
900 ok( !strcmp( pFI_2a->pName, get_form->pName ), "name mismatch\n" );
901 res = GetFormA( hprinter, pFI_1a->pName, level, get_buffer, get_needed - 1, &get_needed );
902 ok( !res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %ld gle %ld\n", res, GetLastError() );
905 /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
906 pFI_2a++;
907 pFI_1a = (PFORM_INFO_1A)pFI_2a;
911 SetLastError(0xdeadbeef);
912 res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
913 ok( res, "(%ld) returned %ld with %ld (expected '!=0')\n",
914 level, res, GetLastError());
916 SetLastError(0xdeadbeef);
917 res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
918 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
919 "(%ld) returned %ld with %ld (expected '0' with "
920 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
923 SetLastError(0xdeadbeef);
924 res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
925 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
926 "(%ld) returned %ld with %ld (expected '0' with "
927 "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
930 SetLastError(0xdeadbeef);
931 res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
932 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
933 GetLastError() == ERROR_INVALID_PARAMETER),
934 "(%ld) returned %ld with %ld (expected '0' with "
935 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
937 SetLastError(0xdeadbeef);
938 res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
939 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
940 GetLastError() == ERROR_INVALID_PARAMETER),
941 "(%ld) returned %ld with %ld (expected '0' with "
942 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
944 SetLastError(0xdeadbeef);
945 res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
946 ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
947 "(%ld) returned %ld with %ld (expected '0' with "
948 "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
950 HeapFree(GetProcessHeap(), 0, buffer);
951 } /* for(level ... */
953 ClosePrinter(hprinter);
956 /* ########################### */
958 static void test_EnumMonitors(void)
960 DWORD res;
961 LPBYTE buffer;
962 DWORD cbBuf;
963 DWORD pcbNeeded;
964 DWORD pcReturned;
965 DWORD level;
967 /* valid levels are 1 and 2 */
968 for(level = 0; level < 4; level++) {
969 cbBuf = MAGIC_DEAD;
970 pcReturned = MAGIC_DEAD;
971 SetLastError(MAGIC_DEAD);
972 res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
973 if (is_spooler_deactivated(res, GetLastError())) return;
974 /* not implemented yet in wine */
975 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
978 /* use only a short test when testing an invalid level */
979 if(!level || (level > 2)) {
980 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
981 (res && (pcReturned == 0)),
982 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with "
983 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
984 level, res, GetLastError(), pcReturned);
985 continue;
988 /* Level 2 is not supported on win9x */
989 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
990 skip("Level %ld not supported\n", level);
991 continue;
994 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
995 "(%ld) returned %ld with %ld (expected '0' with "
996 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
998 if (!cbBuf) {
999 skip("no valid buffer size returned\n");
1000 continue;
1003 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1004 if (buffer == NULL) continue;
1006 SetLastError(MAGIC_DEAD);
1007 pcbNeeded = MAGIC_DEAD;
1008 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1009 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
1010 level, res, GetLastError());
1011 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n",
1012 level, pcbNeeded, cbBuf);
1013 /* We can validate the returned Data with the Registry here */
1016 SetLastError(MAGIC_DEAD);
1017 pcReturned = MAGIC_DEAD;
1018 pcbNeeded = MAGIC_DEAD;
1019 res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1020 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level,
1021 res, GetLastError());
1022 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
1023 pcbNeeded, cbBuf);
1025 SetLastError(MAGIC_DEAD);
1026 pcbNeeded = MAGIC_DEAD;
1027 res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1028 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1029 "(%ld) returned %ld with %ld (expected '0' with "
1030 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1032 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
1033 pcbNeeded, cbBuf);
1036 Do not add the next test:
1037 w2k+: RPC_X_NULL_REF_POINTER
1038 NT3.5: ERROR_INVALID_USER_BUFFER
1039 win9x: crash in winspool.drv
1041 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1044 SetLastError(MAGIC_DEAD);
1045 pcbNeeded = MAGIC_DEAD;
1046 pcReturned = MAGIC_DEAD;
1047 res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1048 ok( res || GetLastError() == RPC_X_NULL_REF_POINTER ||
1049 GetLastError() == ERROR_INVALID_PARAMETER,
1050 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "
1051 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1053 pcbNeeded = MAGIC_DEAD;
1054 pcReturned = MAGIC_DEAD;
1055 SetLastError(MAGIC_DEAD);
1056 res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1057 ok( res || GetLastError() == RPC_X_NULL_REF_POINTER ||
1058 GetLastError() == ERROR_INVALID_PARAMETER,
1059 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "
1060 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1062 HeapFree(GetProcessHeap(), 0, buffer);
1063 } /* for(level ... */
1066 /* ########################### */
1068 static void test_EnumPorts(void)
1070 DWORD res;
1071 DWORD level;
1072 LPBYTE buffer;
1073 DWORD cbBuf;
1074 DWORD pcbNeeded;
1075 DWORD pcReturned;
1077 /* valid levels are 1 and 2 */
1078 for(level = 0; level < 4; level++) {
1080 cbBuf = 0xdeadbeef;
1081 pcReturned = 0xdeadbeef;
1082 SetLastError(0xdeadbeef);
1083 res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
1084 if (is_spooler_deactivated(res, GetLastError())) return;
1086 /* use only a short test when testing an invalid level */
1087 if(!level || (level > 2)) {
1088 /* NT: ERROR_INVALID_LEVEL, 9x: success */
1089 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1090 (res && (pcReturned == 0)),
1091 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with "
1092 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1093 level, res, GetLastError(), pcReturned);
1094 continue;
1098 /* Level 2 is not supported on NT 3.x */
1099 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1100 skip("Level %ld not supported\n", level);
1101 continue;
1104 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1105 "(%ld) returned %ld with %ld (expected '0' with "
1106 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1108 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1109 if (buffer == NULL) continue;
1111 pcbNeeded = 0xdeadbeef;
1112 SetLastError(0xdeadbeef);
1113 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1114 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level, res, GetLastError());
1115 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level, pcbNeeded, cbBuf);
1116 /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1118 pcbNeeded = 0xdeadbeef;
1119 pcReturned = 0xdeadbeef;
1120 SetLastError(0xdeadbeef);
1121 res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1122 ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level, res, GetLastError());
1123 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level, pcbNeeded, cbBuf);
1125 pcbNeeded = 0xdeadbeef;
1126 SetLastError(0xdeadbeef);
1127 res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1128 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1129 "(%ld) returned %ld with %ld (expected '0' with "
1130 "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1131 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level, pcbNeeded, cbBuf);
1134 Do not add this test:
1135 res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1136 w2k+: RPC_X_NULL_REF_POINTER
1137 NT3.5: ERROR_INVALID_USER_BUFFER
1138 win9x: crash in winspool.drv
1141 SetLastError(0xdeadbeef);
1142 res = EnumPortsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1143 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1144 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
1145 GetLastError() == ERROR_INVALID_PARAMETER)) ||
1146 ( res && (GetLastError() == ERROR_SUCCESS) ),
1147 "(%ld) returned %ld with %ld (expected '0' with "
1148 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1149 level, res, GetLastError());
1152 SetLastError(0xdeadbeef);
1153 res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1154 /* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
1155 ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
1156 GetLastError() == ERROR_INVALID_PARAMETER)) ||
1157 ( res && (GetLastError() == ERROR_SUCCESS) ),
1158 "(%ld) returned %ld with %ld (expected '0' with "
1159 "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1160 level, res, GetLastError());
1162 HeapFree(GetProcessHeap(), 0, buffer);
1166 /* ########################### */
1168 static void test_EnumPrinterDrivers(void)
1170 static char env_all[] = "all";
1172 DWORD res;
1173 LPBYTE buffer;
1174 DWORD cbBuf;
1175 DWORD pcbNeeded;
1176 DWORD pcReturned;
1177 DWORD level;
1179 /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1180 for(level = 0; level < 10; level++) {
1181 cbBuf = 0xdeadbeef;
1182 pcReturned = 0xdeadbeef;
1183 SetLastError(0xdeadbeef);
1184 res = EnumPrinterDriversA(NULL, NULL, level, NULL, 0, &cbBuf, &pcReturned);
1185 if (is_spooler_deactivated(res, GetLastError())) return;
1187 /* use only a short test when testing an invalid level */
1188 if(!level || (level == 7) || (level > 8)) {
1190 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1191 (res && (pcReturned == 0)),
1192 "(%ld) got %lu with %lu and 0x%lx "
1193 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1194 level, res, GetLastError(), pcReturned);
1195 continue;
1198 /* some levels are not supported on all windows versions */
1199 if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1200 skip("Level %ld not supported\n", level);
1201 continue;
1204 ok( ((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ||
1205 (res && (default_printer == NULL)),
1206 "(%lu) got %lu with %lu for %s (expected '0' with "
1207 "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1208 level, res, GetLastError(), default_printer);
1210 if (!cbBuf) {
1211 skip("no valid buffer size returned\n");
1212 continue;
1215 /* EnumPrinterDriversA returns the same number of bytes as EnumPrinterDriversW */
1216 if (pEnumPrinterDriversW)
1218 DWORD double_needed;
1219 DWORD double_returned;
1220 pEnumPrinterDriversW(NULL, NULL, level, NULL, 0, &double_needed, &double_returned);
1221 ok(double_needed == cbBuf, "level %ld: EnumPrinterDriversA returned different size %ld than EnumPrinterDriversW (%ld)\n", level, cbBuf, double_needed);
1224 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1225 if (buffer == NULL) continue;
1227 SetLastError(0xdeadbeef);
1228 pcbNeeded = 0xdeadbeef;
1229 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1230 ok(res, "(%lu) got %lu with %lu (expected '!=0')\n", level, res, GetLastError());
1231 ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level, pcbNeeded, cbBuf);
1233 /* validate the returned data here */
1234 if (level > 1) {
1235 LPDRIVER_INFO_2A di = (LPDRIVER_INFO_2A) buffer;
1237 ok( strrchr(di->pDriverPath, '\\') != NULL,
1238 "(%lu) got %s for %s (expected a full path)\n",
1239 level, di->pDriverPath, di->pName);
1243 SetLastError(0xdeadbeef);
1244 pcReturned = 0xdeadbeef;
1245 pcbNeeded = 0xdeadbeef;
1246 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1247 ok(res, "(%lu) got %lu with %lu (expected '!=0')\n", level, res, GetLastError());
1248 ok(pcbNeeded == cbBuf, "(%lu) returned %lu (expected %lu)\n", level, pcbNeeded, cbBuf);
1250 SetLastError(0xdeadbeef);
1251 pcbNeeded = 0xdeadbeef;
1252 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1253 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1254 "(%lu) got %lu with %lu (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1255 level, res, GetLastError());
1256 ok(pcbNeeded == cbBuf, "(%lu) returned %lu (expected %lu)\n", level, pcbNeeded, cbBuf);
1259 Do not add the next test:
1260 NT: ERROR_INVALID_USER_BUFFER
1261 win9x: crash or 100% CPU
1263 res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1266 SetLastError(0xdeadbeef);
1267 pcbNeeded = 0xdeadbeef;
1268 pcReturned = 0xdeadbeef;
1269 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, NULL, &pcReturned);
1270 ok( res || GetLastError() == RPC_X_NULL_REF_POINTER ||
1271 GetLastError() == ERROR_INVALID_PARAMETER,
1272 "(%lu) got %lu with %lu (expected '!=0' or '0' with "
1273 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1275 pcbNeeded = 0xdeadbeef;
1276 pcReturned = 0xdeadbeef;
1277 SetLastError(0xdeadbeef);
1278 res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1279 ok( res || GetLastError() == RPC_X_NULL_REF_POINTER ||
1280 GetLastError() == ERROR_INVALID_PARAMETER,
1281 "(%lu) got %lu with %lu (expected '!=0' or '0' with "
1282 "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1284 HeapFree(GetProcessHeap(), 0, buffer);
1285 } /* for(level ... */
1287 pcbNeeded = 0;
1288 pcReturned = 0;
1289 SetLastError(0xdeadbeef);
1290 res = EnumPrinterDriversA(NULL, env_all, 1, NULL, 0, &pcbNeeded, &pcReturned);
1291 if (res)
1293 skip("no printer drivers found\n");
1294 return;
1296 if (GetLastError() == ERROR_INVALID_ENVIRONMENT)
1298 win_skip("NT4 and below don't support the 'all' environment value\n");
1299 return;
1301 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "unexpected error %lu\n", GetLastError());
1303 buffer = HeapAlloc(GetProcessHeap(), 0, pcbNeeded);
1304 res = EnumPrinterDriversA(NULL, env_all, 1, buffer, pcbNeeded, &pcbNeeded, &pcReturned);
1305 ok(res, "EnumPrinterDriversA failed %lu\n", GetLastError());
1306 if (res && pcReturned > 0)
1308 DRIVER_INFO_1A *di_1 = (DRIVER_INFO_1A *)buffer;
1309 ok((LPBYTE) di_1->pName == NULL || (LPBYTE) di_1->pName < buffer ||
1310 (LPBYTE) di_1->pName >= (LPBYTE)(di_1 + pcReturned),
1311 "Driver Information not in sequence; pName %p, top of data %p\n",
1312 di_1->pName, di_1 + pcReturned);
1315 HeapFree(GetProcessHeap(), 0, buffer);
1318 /* ########################### */
1320 static void test_EnumPrintProcessors(void)
1322 DWORD res;
1323 LPBYTE buffer;
1324 DWORD cbBuf;
1325 DWORD pcbNeeded;
1326 DWORD pcReturned;
1329 cbBuf = 0xdeadbeef;
1330 pcReturned = 0xdeadbeef;
1331 SetLastError(0xdeadbeef);
1332 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, 0, &cbBuf, &pcReturned);
1333 if (is_spooler_deactivated(res, GetLastError())) return;
1335 if (res && !cbBuf) {
1336 skip("No Printprocessor installed\n");
1337 return;
1340 ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1341 "got %lu with %lu (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1342 res, GetLastError());
1344 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1345 if (buffer == NULL)
1346 return;
1348 SetLastError(0xdeadbeef);
1349 pcbNeeded = 0xdeadbeef;
1350 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1351 ok(res, "got %lu with %lu (expected '!=0')\n", res, GetLastError());
1352 /* validate the returned data here. */
1355 SetLastError(0xdeadbeef);
1356 pcReturned = 0xdeadbeef;
1357 pcbNeeded = 0xdeadbeef;
1358 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1359 ok(res, "got %lu with %lu (expected '!=0')\n", res, GetLastError());
1361 SetLastError(0xdeadbeef);
1362 pcbNeeded = 0xdeadbeef;
1363 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1364 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1365 "got %lu with %lu (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1366 res, GetLastError());
1368 /* only level 1 is valid */
1369 if (0) {
1370 /* both tests crash on win98se */
1371 SetLastError(0xdeadbeef);
1372 pcbNeeded = 0xdeadbeef;
1373 pcReturned = 0xdeadbeef;
1374 res = EnumPrintProcessorsA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded, &pcReturned);
1375 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1376 "got %lu with %lu (expected '0' with ERROR_INVALID_LEVEL)\n",
1377 res, GetLastError());
1379 SetLastError(0xdeadbeef);
1380 pcbNeeded = 0xdeadbeef;
1381 res = EnumPrintProcessorsA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded, &pcReturned);
1382 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1383 "got %lu with %lu (expected '0' with ERROR_INVALID_LEVEL)\n",
1384 res, GetLastError());
1387 /* an empty environment is ignored */
1388 SetLastError(0xdeadbeef);
1389 pcbNeeded = 0xdeadbeef;
1390 res = EnumPrintProcessorsA(NULL, empty, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1391 ok(res, "got %lu with %lu (expected '!=0')\n", res, GetLastError());
1393 /* the environment is checked */
1394 SetLastError(0xdeadbeef);
1395 pcbNeeded = 0xdeadbeef;
1396 res = EnumPrintProcessorsA(NULL, invalid_env, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1397 /* NT5: ERROR_INVALID_ENVIRONMENT, NT4: res != 0, 9x: ERROR_INVALID_PARAMETER */
1398 ok( broken(res) || /* NT4 */
1399 (GetLastError() == ERROR_INVALID_ENVIRONMENT) ||
1400 (GetLastError() == ERROR_INVALID_PARAMETER),
1401 "got %lu with %lu (expected '0' with ERROR_INVALID_ENVIRONMENT or "
1402 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1405 /* failure-Codes for NULL */
1406 SetLastError(0xdeadbeef);
1407 pcbNeeded = 0xdeadbeef;
1408 pcReturned = 0xdeadbeef;
1409 res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, cbBuf, &pcbNeeded, &pcReturned);
1410 todo_wine {
1411 ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
1412 "got %lu with %lu (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1413 res, GetLastError());
1416 SetLastError(0xdeadbeef);
1417 pcbNeeded = 0xdeadbeef;
1418 pcReturned = 0xdeadbeef;
1419 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, NULL, &pcReturned);
1420 /* the NULL is ignored on win9x */
1421 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
1422 GetLastError() == ERROR_INVALID_PARAMETER)),
1423 "got %lu with %lu (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1424 res, GetLastError());
1426 pcbNeeded = 0xdeadbeef;
1427 pcReturned = 0xdeadbeef;
1428 SetLastError(0xdeadbeef);
1429 res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, NULL);
1430 /* the NULL is ignored on win9x */
1431 ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER ||
1432 GetLastError() == ERROR_INVALID_PARAMETER)),
1433 "got %lu with %lu (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1434 res, GetLastError());
1436 HeapFree(GetProcessHeap(), 0, buffer);
1440 /* ########################### */
1442 static void test_GetDefaultPrinter(void)
1444 BOOL retval;
1445 DWORD exact = DEFAULT_PRINTER_SIZE;
1446 DWORD size;
1447 char buffer[DEFAULT_PRINTER_SIZE];
1449 if (!pGetDefaultPrinterA) return;
1450 /* only supported on NT like OSes starting with win2k */
1452 SetLastError(ERROR_SUCCESS);
1453 retval = pGetDefaultPrinterA(buffer, &exact);
1454 if (!retval || !exact || !*buffer ||
1455 (ERROR_SUCCESS != GetLastError())) {
1456 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
1457 (ERROR_INVALID_NAME == GetLastError()))
1458 trace("this test requires a default printer to be set\n");
1459 else {
1460 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1461 "function returned %s\n"
1462 "last error 0x%08lx\n"
1463 "returned buffer size 0x%08lx\n"
1464 "returned buffer content %s\n",
1465 retval ? "true" : "false", GetLastError(), exact, buffer);
1467 return;
1469 SetLastError(ERROR_SUCCESS);
1470 retval = pGetDefaultPrinterA(NULL, NULL);
1471 ok( !retval, "function result wrong! False expected\n");
1472 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1473 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
1474 GetLastError());
1476 SetLastError(ERROR_SUCCESS);
1477 retval = pGetDefaultPrinterA(buffer, NULL);
1478 ok( !retval, "function result wrong! False expected\n");
1479 ok( ERROR_INVALID_PARAMETER == GetLastError(),
1480 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
1481 GetLastError());
1483 SetLastError(ERROR_SUCCESS);
1484 size = 0;
1485 retval = pGetDefaultPrinterA(NULL, &size);
1486 ok( !retval, "function result wrong! False expected\n");
1487 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1488 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
1489 GetLastError());
1490 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
1491 exact, size);
1493 SetLastError(ERROR_SUCCESS);
1494 size = DEFAULT_PRINTER_SIZE;
1495 retval = pGetDefaultPrinterA(NULL, &size);
1496 ok( !retval, "function result wrong! False expected\n");
1497 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1498 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
1499 GetLastError());
1500 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
1501 exact, size);
1503 size = 0;
1504 retval = pGetDefaultPrinterA(buffer, &size);
1505 ok( !retval, "function result wrong! False expected\n");
1506 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1507 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
1508 GetLastError());
1509 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
1510 exact, size);
1512 size = exact;
1513 retval = pGetDefaultPrinterA(buffer, &size);
1514 ok( retval, "function result wrong! True expected\n");
1515 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
1516 exact, size);
1519 static void test_GetPrinterDriverDirectory(void)
1521 LPBYTE buffer = NULL;
1522 DWORD cbBuf = 0, pcbNeeded = 0;
1523 BOOL res;
1526 SetLastError(MAGIC_DEAD);
1527 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1528 if (is_spooler_deactivated(res, GetLastError())) return;
1530 trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
1531 res, GetLastError(), cbBuf);
1533 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1534 "returned %d with lasterror=%ld (expected '0' with "
1535 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1537 if (!cbBuf) {
1538 skip("no valid buffer size returned\n");
1539 return;
1542 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1543 if (buffer == NULL) return ;
1545 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1546 ok( res, "expected result != 0, got %d\n", res);
1547 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
1548 pcbNeeded, cbBuf);
1550 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1551 ok( res, "expected result != 0, got %d\n", res);
1552 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
1553 pcbNeeded, cbBuf);
1555 SetLastError(MAGIC_DEAD);
1556 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1557 ok( !res , "expected result == 0, got %d\n", res);
1558 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
1559 pcbNeeded, cbBuf);
1561 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1562 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
1563 GetLastError());
1566 Do not add the next test:
1567 XPsp2: crash in this app, when the spooler is not running
1568 NT3.5: ERROR_INVALID_USER_BUFFER
1569 win9x: ERROR_INVALID_PARAMETER
1571 pcbNeeded = MAGIC_DEAD;
1572 SetLastError(MAGIC_DEAD);
1573 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1576 SetLastError(MAGIC_DEAD);
1577 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1578 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1579 NT: RPC_X_NULL_REF_POINTER */
1580 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER) ||
1581 (GetLastError() == ERROR_INVALID_PARAMETER),
1582 "returned %d with %ld (expected '!=0' or '0' with RPC_X_NULL_REF_POINTER "
1583 "or '0' with ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1585 SetLastError(MAGIC_DEAD);
1586 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1587 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1588 NT: RPC_X_NULL_REF_POINTER */
1589 ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER) ||
1590 (GetLastError() == ERROR_INVALID_PARAMETER),
1591 "returned %d with %ld (expected '!=0' or '0' with RPC_X_NULL_REF_POINTER "
1592 "or '0' with ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1594 /* with a valid buffer, but level is too large */
1595 buffer[0] = '\0';
1596 SetLastError(MAGIC_DEAD);
1597 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1599 /* Level not checked in win9x and wine:*/
1600 if((res != FALSE) && buffer[0])
1602 trace("Level '2' not checked '%s'\n", buffer);
1604 else
1606 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1607 "returned %d with lasterror=%ld (expected '0' with "
1608 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1611 /* printing environments are case insensitive */
1612 /* "Windows 4.0" is valid for win9x and NT */
1613 buffer[0] = '\0';
1614 SetLastError(MAGIC_DEAD);
1615 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1616 buffer, cbBuf*2, &pcbNeeded);
1618 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1619 cbBuf = pcbNeeded;
1620 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1621 if (buffer == NULL) return ;
1623 SetLastError(MAGIC_DEAD);
1624 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
1625 buffer, cbBuf*2, &pcbNeeded);
1628 ok(res && buffer[0], "returned %d with "
1629 "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n",
1630 res, GetLastError(), lstrlenA((char *)buffer));
1632 buffer[0] = '\0';
1633 SetLastError(MAGIC_DEAD);
1634 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1635 buffer, cbBuf*2, &pcbNeeded);
1637 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1638 cbBuf = pcbNeeded;
1639 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1640 if (buffer == NULL) return ;
1642 buffer[0] = '\0';
1643 SetLastError(MAGIC_DEAD);
1644 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
1645 buffer, cbBuf*2, &pcbNeeded);
1648 /* "Windows NT x86" is invalid for win9x */
1649 ok( (res && buffer[0]) ||
1650 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
1651 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with "
1652 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1653 res, GetLastError(), lstrlenA((char *)buffer));
1655 /* A setup program (PDFCreator_0.8.0) use empty strings */
1656 SetLastError(MAGIC_DEAD);
1657 res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1658 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
1660 SetLastError(MAGIC_DEAD);
1661 res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1662 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
1664 SetLastError(MAGIC_DEAD);
1665 res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1666 ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
1668 HeapFree( GetProcessHeap(), 0, buffer);
1671 /* ##### */
1673 static void test_GetPrintProcessorDirectory(void)
1675 LPBYTE buffer = NULL;
1676 DWORD cbBuf = 0;
1677 DWORD pcbNeeded = 0;
1678 BOOL res;
1681 SetLastError(0xdeadbeef);
1682 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1683 if (is_spooler_deactivated(res, GetLastError())) return;
1685 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1686 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1687 res, GetLastError());
1689 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1690 if(buffer == NULL) return;
1692 buffer[0] = '\0';
1693 SetLastError(0xdeadbeef);
1694 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1695 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
1697 SetLastError(0xdeadbeef);
1698 buffer[0] = '\0';
1699 res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1700 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
1702 /* Buffer too small */
1703 buffer[0] = '\0';
1704 SetLastError(0xdeadbeef);
1705 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1706 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1707 "returned %d with %ld (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1708 res, GetLastError());
1710 if (0)
1712 /* XPsp2: the program will crash here, when the spooler is not running */
1713 /* GetPrinterDriverDirectory has the same bug */
1714 pcbNeeded = 0;
1715 SetLastError(0xdeadbeef);
1716 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1717 /* NT: ERROR_INVALID_USER_BUFFER, 9x: res != 0 */
1718 ok( (!res && (GetLastError() == ERROR_INVALID_USER_BUFFER)) ||
1719 broken(res),
1720 "returned %d with %ld (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1721 res, GetLastError());
1724 buffer[0] = '\0';
1725 SetLastError(0xdeadbeef);
1726 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1727 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1728 NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1729 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
1730 (GetLastError() == ERROR_INVALID_PARAMETER)),
1731 "returned %d with %ld (expected '0' with RPC_X_NULL_REF_POINTER "
1732 "or with ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1734 buffer[0] = '\0';
1735 SetLastError(0xdeadbeef);
1736 res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1737 /* w7 with deactivated spooler: ERROR_INVALID_PARAMETER,
1738 NT: RPC_X_NULL_REF_POINTER, 9x: res != 0 */
1739 ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) ||
1740 (GetLastError() == ERROR_INVALID_PARAMETER)),
1741 "returned %d with %ld (expected '0' with RPC_X_NULL_REF_POINTER "
1742 "or with ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1744 /* with a valid buffer, but level is invalid */
1745 buffer[0] = '\0';
1746 SetLastError(0xdeadbeef);
1747 res = GetPrintProcessorDirectoryA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded);
1748 /* Level is ignored in win9x*/
1749 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1750 broken(res && buffer[0]),
1751 "returned %d with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
1752 res, GetLastError());
1754 buffer[0] = '\0';
1755 SetLastError(0xdeadbeef);
1756 res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1757 /* Level is ignored on win9x*/
1758 ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1759 broken(res && buffer[0]),
1760 "returned %d with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
1761 res, GetLastError());
1763 /* Empty environment is the same as the default environment */
1764 buffer[0] = '\0';
1765 SetLastError(0xdeadbeef);
1766 res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1767 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
1769 /* "Windows 4.0" is valid for win9x and NT */
1770 buffer[0] = '\0';
1771 SetLastError(0xdeadbeef);
1772 res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1773 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
1776 /* "Windows NT x86" is invalid for win9x */
1777 buffer[0] = '\0';
1778 SetLastError(0xdeadbeef);
1779 res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1780 ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1781 "returned %d with %ld (expected '!= 0' or '0' with "
1782 "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1784 /* invalid on all systems */
1785 buffer[0] = '\0';
1786 SetLastError(0xdeadbeef);
1787 res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1788 ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT),
1789 "returned %d with %ld (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1790 res, GetLastError());
1792 /* Empty servername is the same as the local computer */
1793 buffer[0] = '\0';
1794 SetLastError(0xdeadbeef);
1795 res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1796 ok(res, "returned %d with %ld (expected '!= 0')\n", res, GetLastError());
1798 /* invalid on all systems */
1799 buffer[0] = '\0';
1800 SetLastError(0xdeadbeef);
1801 res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1802 ok( !res, "expected failure\n");
1803 ok( GetLastError() == RPC_S_SERVER_UNAVAILABLE || /* NT */
1804 GetLastError() == ERROR_INVALID_PARAMETER || /* 9x */
1805 GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista */
1806 "unexpected last error %ld\n", GetLastError());
1808 HeapFree(GetProcessHeap(), 0, buffer);
1811 /* ##### */
1813 static void test_OpenPrinter(void)
1815 PRINTER_DEFAULTSA defaults;
1816 HANDLE hprinter;
1817 DWORD res;
1819 SetLastError(MAGIC_DEAD);
1820 res = OpenPrinterA(NULL, NULL, NULL);
1821 if (is_spooler_deactivated(res, GetLastError())) return;
1823 ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1824 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
1825 res, GetLastError());
1828 /* Get Handle for the local Printserver (NT only)*/
1829 hprinter = (HANDLE) MAGIC_DEAD;
1830 SetLastError(MAGIC_DEAD);
1831 res = OpenPrinterA(NULL, &hprinter, NULL);
1832 if (is_spooler_deactivated(res, GetLastError())) return;
1833 ok(res || GetLastError() == ERROR_INVALID_PARAMETER,
1834 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1835 res, GetLastError());
1836 if(res) {
1837 ClosePrinter(hprinter);
1839 defaults.pDatatype=NULL;
1840 defaults.pDevMode=NULL;
1842 defaults.DesiredAccess=0;
1843 hprinter = (HANDLE) MAGIC_DEAD;
1844 SetLastError(MAGIC_DEAD);
1845 res = OpenPrinterA(NULL, &hprinter, &defaults);
1846 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1847 if (res) ClosePrinter(hprinter);
1849 defaults.DesiredAccess=-1;
1850 hprinter = (HANDLE) MAGIC_DEAD;
1851 SetLastError(MAGIC_DEAD);
1852 res = OpenPrinterA(NULL, &hprinter, &defaults);
1853 todo_wine {
1854 ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1855 "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n",
1856 res, GetLastError());
1858 if (res) ClosePrinter(hprinter);
1863 if (local_server != NULL) {
1864 hprinter = (HANDLE) 0xdeadbeef;
1865 SetLastError(0xdeadbeef);
1866 res = OpenPrinterA(local_server, &hprinter, NULL);
1867 ok(res || GetLastError() == ERROR_INVALID_PARAMETER,
1868 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1869 res, GetLastError());
1870 if(res) ClosePrinter(hprinter);
1873 /* Invalid Printername */
1874 hprinter = (HANDLE) MAGIC_DEAD;
1875 SetLastError(MAGIC_DEAD);
1876 res = OpenPrinterA(illegal_name, &hprinter, NULL);
1877 ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1878 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1879 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or"
1880 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1881 if(res) ClosePrinter(hprinter);
1883 hprinter = (HANDLE) MAGIC_DEAD;
1884 SetLastError(MAGIC_DEAD);
1885 res = OpenPrinterA(empty, &hprinter, NULL);
1886 /* NT: ERROR_INVALID_PRINTER_NAME, 9x: ERROR_INVALID_PARAMETER */
1887 ok( !res &&
1888 ((GetLastError() == ERROR_INVALID_PRINTER_NAME) ||
1889 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1890 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1891 " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1892 if(res) ClosePrinter(hprinter);
1895 /* get handle for the default printer */
1896 if (default_printer)
1898 hprinter = (HANDLE) MAGIC_DEAD;
1899 SetLastError(MAGIC_DEAD);
1900 res = OpenPrinterA(default_printer, &hprinter, NULL);
1901 if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1903 trace("The service 'Spooler' is required for '%s'\n", default_printer);
1904 return;
1906 ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
1907 if(res) ClosePrinter(hprinter);
1909 SetLastError(MAGIC_DEAD);
1910 res = OpenPrinterA(default_printer, NULL, NULL);
1911 /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1912 ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1913 "returned %ld with %ld (expected '!=0' or '0' with "
1914 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1916 defaults.pDatatype=NULL;
1917 defaults.pDevMode=NULL;
1918 defaults.DesiredAccess=0;
1920 hprinter = (HANDLE) MAGIC_DEAD;
1921 SetLastError(MAGIC_DEAD);
1922 res = OpenPrinterA(default_printer, &hprinter, &defaults);
1923 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1924 "returned %ld with %ld (expected '!=0' or '0' with "
1925 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1926 if(res) ClosePrinter(hprinter);
1928 defaults.pDatatype = empty;
1930 hprinter = (HANDLE) MAGIC_DEAD;
1931 SetLastError(MAGIC_DEAD);
1932 res = OpenPrinterA(default_printer, &hprinter, &defaults);
1933 /* stop here, when a remote Printserver has no RPC-Service running */
1934 if (is_spooler_deactivated(res, GetLastError())) return;
1935 ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1936 (GetLastError() == ERROR_ACCESS_DENIED)),
1937 "returned %ld with %ld (expected '!=0' or '0' with: "
1938 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1939 res, GetLastError());
1940 if(res) ClosePrinter(hprinter);
1943 defaults.pDatatype=NULL;
1944 defaults.DesiredAccess=PRINTER_ACCESS_USE;
1946 hprinter = (HANDLE) MAGIC_DEAD;
1947 SetLastError(MAGIC_DEAD);
1948 res = OpenPrinterA(default_printer, &hprinter, &defaults);
1949 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1950 "returned %ld with %ld (expected '!=0' or '0' with "
1951 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1952 if(res) ClosePrinter(hprinter);
1955 defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1956 hprinter = (HANDLE) MAGIC_DEAD;
1957 SetLastError(MAGIC_DEAD);
1958 res = OpenPrinterA(default_printer, &hprinter, &defaults);
1959 ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1960 "returned %ld with %ld (expected '!=0' or '0' with "
1961 "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1962 if(res) ClosePrinter(hprinter);
1968 static void test_SetDefaultPrinter(void)
1970 DWORD res;
1971 DWORD size = DEFAULT_PRINTER_SIZE;
1972 CHAR buffer[DEFAULT_PRINTER_SIZE];
1973 CHAR org_value[DEFAULT_PRINTER_SIZE];
1975 if (!default_printer)
1977 skip("There is no default printer installed\n");
1978 return;
1981 if (!pSetDefaultPrinterA) return;
1982 /* only supported on win2k and above */
1984 /* backup the original value */
1985 org_value[0] = '\0';
1986 SetLastError(MAGIC_DEAD);
1987 res = GetProfileStringA("windows", "device", NULL, org_value, size);
1988 ok(res, "GetProfileString error %ld\n", GetLastError());
1990 /* first part: with the default Printer */
1991 SetLastError(MAGIC_DEAD);
1992 res = pSetDefaultPrinterA("no_printer_with_this_name");
1993 if (is_spooler_deactivated(res, GetLastError())) return;
1995 /* Not implemented in wine */
1996 if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1997 trace("SetDefaultPrinterA() not implemented yet.\n");
1998 return;
2001 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
2002 "returned %ld with %ld (expected '0' with "
2003 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2005 WriteProfileStringA("windows", "device", org_value);
2006 SetLastError(MAGIC_DEAD);
2007 res = pSetDefaultPrinterA("");
2008 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2009 "returned %ld with %ld (expected '!=0' or '0' with "
2010 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2012 WriteProfileStringA("windows", "device", org_value);
2013 SetLastError(MAGIC_DEAD);
2014 res = pSetDefaultPrinterA(NULL);
2015 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2016 "returned %ld with %ld (expected '!=0' or '0' with "
2017 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2019 WriteProfileStringA("windows", "device", org_value);
2020 SetLastError(MAGIC_DEAD);
2021 res = pSetDefaultPrinterA(default_printer);
2022 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2023 "returned %ld with %ld (expected '!=0' or '0' with "
2024 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2027 /* second part: always without a default Printer */
2028 WriteProfileStringA("windows", "device", NULL);
2029 SetLastError(MAGIC_DEAD);
2030 res = pSetDefaultPrinterA("no_printer_with_this_name");
2032 ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
2033 "returned %ld with %ld (expected '0' with "
2034 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2036 WriteProfileStringA("windows", "device", NULL);
2037 SetLastError(MAGIC_DEAD);
2038 res = pSetDefaultPrinterA("");
2039 if (is_spooler_deactivated(res, GetLastError()))
2040 goto restore_old_printer;
2042 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
2043 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2044 "returned %ld with %ld (expected '!=0' or '0' with "
2045 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2047 WriteProfileStringA("windows", "device", NULL);
2048 SetLastError(MAGIC_DEAD);
2049 res = pSetDefaultPrinterA(NULL);
2050 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
2051 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2052 "returned %ld with %ld (expected '!=0' or '0' with "
2053 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2055 WriteProfileStringA("windows", "device", NULL);
2056 SetLastError(MAGIC_DEAD);
2057 res = pSetDefaultPrinterA(default_printer);
2058 ok(res || GetLastError() == ERROR_INVALID_PRINTER_NAME,
2059 "returned %ld with %ld (expected '!=0' or '0' with "
2060 "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
2062 /* restore the original value */
2063 restore_old_printer:
2064 res = pSetDefaultPrinterA(default_printer); /* the nice way */
2065 ok(res, "SetDefaultPrinter error %ld\n", GetLastError());
2066 WriteProfileStringA("windows", "device", org_value); /* the old way */
2068 buffer[0] = '\0';
2069 SetLastError(MAGIC_DEAD);
2070 res = GetProfileStringA("windows", "device", NULL, buffer, size);
2071 ok(res, "GetProfileString error %ld\n", GetLastError());
2072 ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
2076 /* ########################### */
2078 static void test_XcvDataW_MonitorUI(void)
2080 DWORD res;
2081 HANDLE hXcv;
2082 BYTE buffer[MAX_PATH + 4];
2083 DWORD needed;
2084 DWORD status;
2085 DWORD len;
2086 PRINTER_DEFAULTSA pd;
2088 /* api is not present before w2k */
2089 if (pXcvDataW == NULL) return;
2091 pd.pDatatype = NULL;
2092 pd.pDevMode = NULL;
2093 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2095 hXcv = NULL;
2096 SetLastError(0xdeadbeef);
2097 res = OpenPrinterA(xcv_localport, &hXcv, &pd);
2098 if (is_spooler_deactivated(res, GetLastError())) return;
2099 if (is_access_denied(res, GetLastError())) return;
2101 ok(res, "returned %ld with %lu and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2102 if (!res) return;
2104 /* ask for needed size */
2105 needed = (DWORD) 0xdeadbeef;
2106 status = (DWORD) 0xdeadbeef;
2107 SetLastError(0xdeadbeef);
2108 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, NULL, 0, &needed, &status);
2109 ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
2110 "returned %ld with %lu and %lu for status %lu (expected '!= 0' and "
2111 "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
2112 res, GetLastError(), needed, status);
2114 if (needed > MAX_PATH) {
2115 ClosePrinter(hXcv);
2116 skip("buffer overflow (%lu)\n", needed);
2117 return;
2119 len = needed; /* Size is in bytes */
2121 /* the command is required */
2122 needed = (DWORD) 0xdeadbeef;
2123 status = (DWORD) 0xdeadbeef;
2124 SetLastError(0xdeadbeef);
2125 res = pXcvDataW(hXcv, L"", NULL, 0, NULL, 0, &needed, &status);
2126 ok( res && (status == ERROR_INVALID_PARAMETER),
2127 "returned %ld with %lu and %lu for status %lu (expected '!= 0' with "
2128 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2130 needed = (DWORD) 0xdeadbeef;
2131 status = (DWORD) 0xdeadbeef;
2132 SetLastError(0xdeadbeef);
2133 res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
2134 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2135 "returned %ld with %lu and %lu for status %lu (expected '0' with "
2136 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2138 /* "PDWORD needed" is checked before RPC-Errors */
2139 needed = (DWORD) 0xdeadbeef;
2140 status = (DWORD) 0xdeadbeef;
2141 SetLastError(0xdeadbeef);
2142 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, buffer, len, NULL, &status);
2143 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2144 "returned %ld with %lu and %lu for status %lu (expected '0' with "
2145 "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2147 needed = (DWORD) 0xdeadbeef;
2148 status = (DWORD) 0xdeadbeef;
2149 SetLastError(0xdeadbeef);
2150 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, NULL, len, &needed, &status);
2151 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2152 "returned %ld with %lu and %lu for status %lu (expected '0' with "
2153 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2155 needed = (DWORD) 0xdeadbeef;
2156 status = (DWORD) 0xdeadbeef;
2157 SetLastError(0xdeadbeef);
2158 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, buffer, len, &needed, NULL);
2159 ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2160 "returned %ld with %lu and %lu for status %lu (expected '0' with "
2161 "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2163 /* off by one: larger */
2164 needed = (DWORD) 0xdeadbeef;
2165 status = (DWORD) 0xdeadbeef;
2166 SetLastError(0xdeadbeef);
2167 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, buffer, len+1, &needed, &status);
2168 ok( res && (status == ERROR_SUCCESS),
2169 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for status "
2170 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2172 /* off by one: smaller */
2173 /* the buffer is not modified for NT4, w2k, XP */
2174 needed = (DWORD) 0xdeadbeef;
2175 status = (DWORD) 0xdeadbeef;
2176 SetLastError(0xdeadbeef);
2177 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, buffer, len-1, &needed, &status);
2178 ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
2179 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for status "
2180 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
2183 /* Normal use. The DLL-Name without a Path is returned */
2184 memset(buffer, 0, len);
2185 needed = (DWORD) 0xdeadbeef;
2186 status = (DWORD) 0xdeadbeef;
2187 SetLastError(0xdeadbeef);
2188 res = pXcvDataW(hXcv, L"MonitorUI", NULL, 0, buffer, len, &needed, &status);
2189 ok( res && (status == ERROR_SUCCESS),
2190 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for status "
2191 "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2193 ClosePrinter(hXcv);
2196 /* ########################### */
2198 static void test_XcvDataW_PortIsValid(void)
2200 DWORD res;
2201 HANDLE hXcv;
2202 DWORD needed;
2203 DWORD status;
2204 PRINTER_DEFAULTSA pd;
2206 /* api is not present before w2k */
2207 if (pXcvDataW == NULL) return;
2209 pd.pDatatype = NULL;
2210 pd.pDevMode = NULL;
2211 pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2213 hXcv = NULL;
2214 SetLastError(0xdeadbeef);
2215 res = OpenPrinterA(xcv_localport, &hXcv, &pd);
2216 if (is_spooler_deactivated(res, GetLastError())) return;
2217 if (is_access_denied(res, GetLastError())) return;
2219 ok(res, "returned %ld with %lu and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2220 if (!res) return;
2223 /* "PDWORD needed" is always required */
2224 needed = (DWORD) 0xdeadbeef;
2225 status = (DWORD) 0xdeadbeef;
2226 SetLastError(0xdeadbeef);
2227 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"LPT1:", sizeof(L"LPT1:"), NULL, 0, NULL, &status);
2228 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2229 "returned %ld with %lu and %lu for status %lu (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2230 res, GetLastError(), needed, status);
2232 /* an empty name is not allowed */
2233 needed = (DWORD) 0xdeadbeef;
2234 status = (DWORD) 0xdeadbeef;
2235 SetLastError(0xdeadbeef);
2236 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"", sizeof(L""), NULL, 0, &needed, &status);
2237 ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
2238 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for status: "
2239 "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2240 res, GetLastError(), needed, status);
2242 /* a directory is not allowed */
2243 needed = (DWORD) 0xdeadbeef;
2244 status = (DWORD) 0xdeadbeef;
2245 SetLastError(0xdeadbeef);
2246 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR),
2247 NULL, 0, &needed, &status);
2248 /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2249 ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
2250 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for status: "
2251 "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2252 res, GetLastError(), needed, status);
2254 /* more valid well known ports */
2255 needed = (DWORD) 0xdeadbeef;
2256 status = (DWORD) 0xdeadbeef;
2257 SetLastError(0xdeadbeef);
2258 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"LPT1:", sizeof(L"LPT1:"), NULL, 0, &needed, &status);
2259 ok( res && (status == ERROR_SUCCESS),
2260 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for ERROR_SUCCESS)\n",
2261 res, GetLastError(), needed, status);
2263 needed = (DWORD) 0xdeadbeef;
2264 status = (DWORD) 0xdeadbeef;
2265 SetLastError(0xdeadbeef);
2266 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"LPT2:", sizeof(L"LPT2:"), NULL, 0, &needed, &status);
2267 ok( res && (status == ERROR_SUCCESS),
2268 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for ERROR_SUCCESS)\n",
2269 res, GetLastError(), needed, status);
2271 needed = (DWORD) 0xdeadbeef;
2272 status = (DWORD) 0xdeadbeef;
2273 SetLastError(0xdeadbeef);
2274 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"COM1:", sizeof(L"COM1:"), NULL, 0, &needed, &status);
2275 ok( res && (status == ERROR_SUCCESS),
2276 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for ERROR_SUCCESS)\n",
2277 res, GetLastError(), needed, status);
2279 needed = (DWORD) 0xdeadbeef;
2280 status = (DWORD) 0xdeadbeef;
2281 SetLastError(0xdeadbeef);
2282 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"COM2:", sizeof(L"COM2:"), NULL, 0, &needed, &status);
2283 ok( res && (status == ERROR_SUCCESS),
2284 "returned %ld with %lu and %lu for status %lu (expected '!= 0' for ERROR_SUCCESS)\n",
2285 res, GetLastError(), needed, status);
2287 needed = (DWORD) 0xdeadbeef;
2288 status = (DWORD) 0xdeadbeef;
2289 SetLastError(0xdeadbeef);
2290 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) L"FILE:", sizeof(L"FILE:"), NULL, 0, &needed, &status);
2291 ok( res && (status == ERROR_SUCCESS),
2292 "returned %ld with %lu and %lu for status %lu (expected '!= 0' with ERROR_SUCCESS)\n",
2293 res, GetLastError(), needed, status);
2296 /* a normal, writable file is allowed */
2297 needed = (DWORD) 0xdeadbeef;
2298 status = (DWORD) 0xdeadbeef;
2299 SetLastError(0xdeadbeef);
2300 res = pXcvDataW(hXcv, L"PortIsValid", (BYTE *) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR),
2301 NULL, 0, &needed, &status);
2302 ok( res && (status == ERROR_SUCCESS),
2303 "returned %ld with %lu and %lu for status %lu (expected '!= 0' with ERROR_SUCCESS)\n",
2304 res, GetLastError(), needed, status);
2306 ClosePrinter(hXcv);
2309 /* ########################### */
2311 static void test_GetPrinter(void)
2313 HANDLE hprn;
2314 BOOL ret;
2315 BYTE *buf;
2316 INT level;
2317 DWORD needed, filled;
2319 if (!default_printer)
2321 skip("There is no default printer installed\n");
2322 return;
2325 hprn = 0;
2326 ret = OpenPrinterA(default_printer, &hprn, NULL);
2327 if (!ret)
2329 skip("Unable to open the default printer (%s)\n", default_printer);
2330 return;
2332 ok(hprn != 0, "wrong hprn %p\n", hprn);
2334 for (level = 1; level <= 9; level++)
2336 SetLastError(0xdeadbeef);
2337 needed = (DWORD)-1;
2338 ret = GetPrinterA(hprn, level, NULL, 0, &needed);
2339 if (ret)
2341 win_skip("Level %d is not supported on Win9x/WinMe\n", level);
2342 ok(GetLastError() == ERROR_SUCCESS, "wrong error %ld\n", GetLastError());
2343 ok(needed == 0,"Expected 0, got %ld\n", needed);
2344 continue;
2346 ok(!ret, "level %d: GetPrinter should fail\n", level);
2347 /* Not all levels are supported on all Windows-Versions */
2348 if (GetLastError() == ERROR_INVALID_LEVEL ||
2349 GetLastError() == ERROR_NOT_SUPPORTED /* Win9x/WinMe */)
2351 skip("Level %d not supported\n", level);
2352 continue;
2354 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
2355 ok(needed > 0,"not expected needed buffer size %ld\n", needed);
2357 /* GetPrinterA returns the same number of bytes as GetPrinterW */
2358 if (!ret && pGetPrinterW && level != 6 && level != 7)
2360 DWORD double_needed;
2361 ret = pGetPrinterW(hprn, level, NULL, 0, &double_needed);
2362 ok(!ret, "level %d: GetPrinter error %ld\n", level, GetLastError());
2363 ok(double_needed == needed, "level %d: GetPrinterA returned different size %ld than GetPrinterW (%ld)\n", level, needed, double_needed);
2366 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2368 SetLastError(0xdeadbeef);
2369 filled = -1;
2370 ret = GetPrinterA(hprn, level, buf, needed, &filled);
2371 ok(ret, "level %d: GetPrinter error %ld\n", level, GetLastError());
2372 ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
2374 if (level == 2)
2376 PRINTER_INFO_2A *pi_2 = (PRINTER_INFO_2A *)buf;
2378 ok(pi_2->pPrinterName!= NULL, "not expected NULL ptr\n");
2379 ok(pi_2->pDriverName!= NULL, "not expected NULL ptr\n");
2381 trace("pPrinterName %s\n", pi_2->pPrinterName);
2382 trace("pDriverName %s\n", pi_2->pDriverName);
2385 HeapFree(GetProcessHeap(), 0, buf);
2388 SetLastError(0xdeadbeef);
2389 ret = ClosePrinter(hprn);
2390 ok(ret, "ClosePrinter error %ld\n", GetLastError());
2393 /* ########################### */
2395 static void test_GetPrinterData(void)
2397 HANDLE hprn = 0;
2398 DWORD res;
2399 DWORD type;
2400 CHAR buffer[MAX_PATH + 1];
2401 DWORD needed;
2402 DWORD len;
2404 /* ToDo: test parameter validation, test with the default printer */
2406 SetLastError(0xdeadbeef);
2407 res = OpenPrinterA(NULL, &hprn, NULL);
2408 if (!res)
2410 return;
2413 memset(buffer, '#', sizeof(buffer));
2414 buffer[MAX_PATH] = 0;
2415 type = 0xdeadbeef;
2416 needed = 0xdeadbeef;
2417 SetLastError(0xdeadbeef);
2418 res = GetPrinterDataA(hprn, defaultspooldirectory, &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2420 len = lstrlenA(buffer) + sizeof(CHAR);
2421 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2422 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2423 "got %ld, type %ld, needed: %ld and '%s' (expected ERROR_SUCCESS, REG_SZ and %ld)\n",
2424 res, type, needed, buffer, len);
2426 needed = 0xdeadbeef;
2427 SetLastError(0xdeadbeef);
2428 res = GetPrinterDataA(hprn, defaultspooldirectory, NULL, NULL, 0, &needed);
2429 ok( (res == ERROR_MORE_DATA) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2430 "got %ld, needed: %ld (expected ERROR_MORE_DATA and %ld)\n", res, needed, len);
2432 /* ToDo: test SPLREG_* */
2434 SetLastError(0xdeadbeef);
2435 res = ClosePrinter(hprn);
2436 ok(res, "ClosePrinter error %ld\n", GetLastError());
2439 /* ########################### */
2441 static void test_GetPrinterDataEx(void)
2443 HANDLE hprn = 0;
2444 DWORD res;
2445 DWORD type;
2446 CHAR buffer[MAX_PATH + 1];
2447 DWORD needed;
2448 DWORD len;
2450 /* not present before w2k */
2451 if (!pGetPrinterDataExA) {
2452 win_skip("GetPrinterDataEx not found\n");
2453 return;
2456 /* ToDo: test parameter validation, test with the default printer */
2458 SetLastError(0xdeadbeef);
2459 res = OpenPrinterA(NULL, &hprn, NULL);
2460 if (!res)
2462 win_skip("Unable to open the printserver: %ld\n", GetLastError());
2463 return;
2466 /* keyname is ignored, when hprn is a HANDLE for a printserver */
2467 memset(buffer, '#', sizeof(buffer));
2468 buffer[MAX_PATH] = 0;
2469 type = 0xdeadbeef;
2470 needed = 0xdeadbeef;
2471 SetLastError(0xdeadbeef);
2472 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, &type,
2473 (LPBYTE) buffer, sizeof(buffer), &needed);
2475 len = lstrlenA(buffer) + sizeof(CHAR);
2476 /* NT4 and w2k require a buffer to save the UNICODE result also for the ANSI function */
2477 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2478 "got %ld, type %ld, needed: %ld and '%s' (expected ERROR_SUCCESS, REG_SZ and %ld)\n",
2479 res, type, needed, buffer, len);
2481 memset(buffer, '#', sizeof(buffer));
2482 buffer[MAX_PATH] = 0;
2483 type = 0xdeadbeef;
2484 needed = 0xdeadbeef;
2485 SetLastError(0xdeadbeef);
2486 res = pGetPrinterDataExA(hprn, "", defaultspooldirectory, &type,
2487 (LPBYTE) buffer, sizeof(buffer), &needed);
2488 len = lstrlenA(buffer) + sizeof(CHAR);
2489 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2490 "got %ld, type %ld, needed: %ld and '%s' (expected ERROR_SUCCESS, REG_SZ and %ld)\n",
2491 res, type, needed, buffer, len);
2493 memset(buffer, '#', sizeof(buffer));
2494 buffer[MAX_PATH] = 0;
2495 type = 0xdeadbeef;
2496 needed = 0xdeadbeef;
2497 SetLastError(0xdeadbeef);
2498 /* Wine uses GetPrinterDataEx with "PrinterDriverData" to implement GetPrinterData */
2499 res = pGetPrinterDataExA(hprn, "PrinterDriverData", defaultspooldirectory,
2500 &type, (LPBYTE) buffer, sizeof(buffer), &needed);
2501 len = lstrlenA(buffer) + sizeof(CHAR);
2502 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2503 "got %ld, type %ld, needed: %ld and '%s' (expected ERROR_SUCCESS, REG_SZ and %ld)\n",
2504 res, type, needed, buffer, len);
2507 memset(buffer, '#', sizeof(buffer));
2508 buffer[MAX_PATH] = 0;
2509 type = 0xdeadbeef;
2510 needed = 0xdeadbeef;
2511 SetLastError(0xdeadbeef);
2512 res = pGetPrinterDataExA(hprn, does_not_exist, defaultspooldirectory, &type,
2513 (LPBYTE) buffer, sizeof(buffer), &needed);
2514 len = lstrlenA(buffer) + sizeof(CHAR);
2515 ok( !res && (type == REG_SZ) && ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2516 "got %ld, type %ld, needed: %ld and '%s' (expected ERROR_SUCCESS, REG_SZ and %ld)\n",
2517 res, type, needed, buffer, len);
2519 needed = 0xdeadbeef;
2520 SetLastError(0xdeadbeef);
2521 /* vista and w2k8 have a bug in GetPrinterDataEx:
2522 the current LastError value is returned as result */
2523 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2524 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeadbeef)) &&
2525 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2526 "got %ld, needed: %ld (expected ERROR_MORE_DATA and %ld)\n", res, needed, len);
2528 needed = 0xdeadbeef;
2529 SetLastError(0xdeaddead);
2530 res = pGetPrinterDataExA(hprn, NULL, defaultspooldirectory, NULL, NULL, 0, &needed);
2531 ok( ((res == ERROR_MORE_DATA) || broken(res == 0xdeaddead)) &&
2532 ((needed == len) || (needed == (len * sizeof(WCHAR)))),
2533 "got %ld, needed: %ld (expected ERROR_MORE_DATA and %ld)\n", res, needed, len);
2535 SetLastError(0xdeadbeef);
2536 res = ClosePrinter(hprn);
2537 ok(res, "ClosePrinter error %ld\n", GetLastError());
2540 /* ########################### */
2542 static void test_GetPrinterDriver(void)
2544 HANDLE hprn;
2545 BOOL ret;
2546 BYTE *buf;
2547 INT level;
2548 DWORD needed, filled;
2550 if (!default_printer)
2552 skip("There is no default printer installed\n");
2553 return;
2556 hprn = 0;
2557 ret = OpenPrinterA(default_printer, &hprn, NULL);
2558 if (!ret)
2560 skip("Unable to open the default printer (%s)\n", default_printer);
2561 return;
2563 ok(hprn != 0, "wrong hprn %p\n", hprn);
2565 for (level = -1; level <= 7; level++)
2567 SetLastError(0xdeadbeef);
2568 needed = (DWORD)-1;
2569 ret = GetPrinterDriverA(hprn, NULL, level, NULL, 0, &needed);
2570 ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
2571 if (level >= 1 && level <= 6)
2573 /* Not all levels are supported on all Windows-Versions */
2574 if(GetLastError() == ERROR_INVALID_LEVEL) continue;
2575 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
2576 ok(needed > 0,"not expected needed buffer size %ld\n", needed);
2578 else
2580 /* ERROR_OUTOFMEMORY found on win9x */
2581 ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
2582 (GetLastError() == ERROR_OUTOFMEMORY)),
2583 "%d: returned %d with %ld (expected '0' with: "
2584 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2585 level, ret, GetLastError());
2586 /* needed is modified in win9x. The modified Value depends on the
2587 default Printer. testing for "needed == (DWORD)-1" will fail */
2588 continue;
2591 /* GetPrinterDriverA returns the same number of bytes as GetPrinterDriverW */
2592 if (!ret && pGetPrinterDriverW)
2594 DWORD double_needed;
2595 ret = pGetPrinterDriverW(hprn, NULL, level, NULL, 0, &double_needed);
2596 ok(!ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
2597 ok(double_needed == needed, "GetPrinterDriverA returned different size %ld than GetPrinterDriverW (%ld)\n", needed, double_needed);
2600 buf = HeapAlloc(GetProcessHeap(), 0, needed);
2602 SetLastError(0xdeadbeef);
2603 filled = -1;
2604 ret = GetPrinterDriverA(hprn, NULL, level, buf, needed, &filled);
2605 ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
2606 ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
2608 if (level == 2)
2610 DRIVER_INFO_2A *di_2 = (DRIVER_INFO_2A *)buf;
2611 DWORD calculated = sizeof(*di_2);
2612 HANDLE hf;
2614 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2615 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k-win7(Usermode): 3, win8 and above(Usermode): 4 */
2616 ok( (di_2->cVersion <= 4) ||
2617 (di_2->cVersion == 0x0400), "di_2->cVersion = %ld\n", di_2->cVersion);
2618 ok(di_2->pName != NULL, "not expected NULL ptr\n");
2619 ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
2620 ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
2621 ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
2622 ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
2624 trace("cVersion %ld\n", di_2->cVersion);
2625 trace("pName %s\n", di_2->pName);
2626 calculated += strlen(di_2->pName) + 1;
2627 trace("pEnvironment %s\n", di_2->pEnvironment);
2628 calculated += strlen(di_2->pEnvironment) + 1;
2629 trace("pDriverPath %s\n", di_2->pDriverPath);
2630 calculated += strlen(di_2->pDriverPath) + 1;
2631 trace("pDataFile %s\n", di_2->pDataFile);
2632 calculated += strlen(di_2->pDataFile) + 1;
2633 trace("pConfigFile %s\n", di_2->pConfigFile);
2634 calculated += strlen(di_2->pConfigFile) + 1;
2636 hf = CreateFileA(di_2->pDriverPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2637 if(hf != INVALID_HANDLE_VALUE)
2638 CloseHandle(hf);
2639 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDriverPath);
2641 hf = CreateFileA(di_2->pDataFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2642 if(hf != INVALID_HANDLE_VALUE)
2643 CloseHandle(hf);
2644 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pDataFile);
2646 hf = CreateFileA(di_2->pConfigFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2647 if(hf != INVALID_HANDLE_VALUE)
2648 CloseHandle(hf);
2649 ok(hf != INVALID_HANDLE_VALUE, "Could not open %s\n", di_2->pConfigFile);
2651 /* XP allocates memory for both ANSI and unicode names */
2652 ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
2654 /* Obscure test - demonstrate that Windows zero fills the buffer, even on failure */
2655 ret = GetPrinterDriverA(hprn, NULL, level, buf, needed - 2, &filled);
2656 ok(!ret, "level %d: GetPrinterDriver succeeded with less buffer than it should\n", level);
2657 ok(di_2->pDataFile == NULL ||
2658 broken(di_2->pDataFile != NULL), /* Win9x/WinMe */
2659 "Even on failure, GetPrinterDriver clears the buffer to zeros\n");
2662 HeapFree(GetProcessHeap(), 0, buf);
2665 SetLastError(0xdeadbeef);
2666 ret = ClosePrinter(hprn);
2667 ok(ret, "ClosePrinter error %ld\n", GetLastError());
2670 static void test_DEVMODEA(const DEVMODEA *dm, LONG dmSize, LPCSTR exp_prn_name)
2672 /* On NT3.51, some fields in DEVMODEA are empty/zero
2673 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2674 We skip the Tests on this Platform */
2675 if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
2676 /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2677 ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1) ||
2678 !strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -2), /* XP+ */
2679 "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
2680 ok(dm->dmSize + dm->dmDriverExtra == dmSize,
2681 "%u != %ld\n", dm->dmSize + dm->dmDriverExtra, dmSize);
2683 trace("dmFields %08lx\n", dm->dmFields);
2686 static void test_DocumentProperties(void)
2688 HANDLE hprn;
2689 LONG dm_size, ret;
2690 DEVMODEA *dm;
2691 char empty_str[] = "";
2692 char nonexistent_str[] = "nonexistent printer";
2694 if (!default_printer)
2696 skip("There is no default printer installed\n");
2697 return;
2700 hprn = 0;
2701 ret = OpenPrinterA(default_printer, &hprn, NULL);
2702 if (!ret)
2704 skip("Unable to open the default printer (%s)\n", default_printer);
2705 return;
2707 ok(hprn != 0, "wrong hprn %p\n", hprn);
2709 dm_size = DocumentPropertiesA(0, hprn, NULL, NULL, NULL, 0);
2710 trace("DEVMODEA required size %ld\n", dm_size);
2711 ok(dm_size >= sizeof(DEVMODEA), "unexpected DocumentPropertiesA ret value %ld\n", dm_size);
2713 dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
2715 ret = DocumentPropertiesA(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
2716 ok(ret == IDOK, "DocumentPropertiesA ret value %ld != expected IDOK\n", ret);
2718 ret = DocumentPropertiesA(0, hprn, empty_str, dm, dm, DM_OUT_BUFFER);
2719 ok(ret == IDOK, "DocumentPropertiesA ret value %ld != expected IDOK\n", ret);
2721 ret = DocumentPropertiesA(0, hprn, nonexistent_str, dm, dm, DM_OUT_BUFFER);
2722 ok(ret == IDOK, "DocumentPropertiesA ret value %ld != expected IDOK\n", ret);
2724 test_DEVMODEA(dm, dm_size, default_printer);
2726 HeapFree(GetProcessHeap(), 0, dm);
2728 SetLastError(0xdeadbeef);
2729 ret = ClosePrinter(hprn);
2730 ok(ret, "ClosePrinter error %ld\n", GetLastError());
2733 static void test_EnumPrinters(void)
2735 DWORD neededA, neededW, num;
2736 DWORD ret;
2738 SetLastError(0xdeadbeef);
2739 neededA = -1;
2740 ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
2741 if (is_spooler_deactivated(ret, GetLastError())) return;
2742 if (!ret)
2744 /* We have 1 or more printers */
2745 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %ld\n", GetLastError());
2746 ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
2748 else
2750 /* We don't have any printers defined */
2751 ok(GetLastError() == S_OK, "gle %ld\n", GetLastError());
2752 ok(neededA == 0, "Expected neededA to be zero\n");
2754 ok(num == 0, "num %ld\n", num);
2756 SetLastError(0xdeadbeef);
2757 neededW = -1;
2758 ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
2759 /* EnumPrintersW is not supported on all platforms */
2760 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
2762 win_skip("EnumPrintersW is not implemented\n");
2763 return;
2766 if (!ret)
2768 /* We have 1 or more printers */
2769 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %ld\n", GetLastError());
2770 ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
2772 else
2774 /* We don't have any printers defined */
2775 ok(GetLastError() == S_OK, "gle %ld\n", GetLastError());
2776 ok(neededW == 0, "Expected neededW to be zero\n");
2778 ok(num == 0, "num %ld\n", num);
2780 /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2781 to hold the buffer returned by EnumPrintersW */
2782 ok(neededA == neededW, "neededA %ld neededW %ld\n", neededA, neededW);
2785 static void test_DeviceCapabilities(void)
2787 HANDLE hComdlg32;
2788 BOOL (WINAPI *pPrintDlgA)(PRINTDLGA *);
2789 PRINTDLGA prn_dlg;
2790 DEVMODEA *dm;
2791 DEVNAMES *dn;
2792 const char *driver, *device, *port;
2793 WORD *papers;
2794 POINT *paper_size;
2795 POINTS ext;
2796 struct
2798 char name[64];
2799 } *paper_name;
2800 INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
2801 DWORD fields;
2803 hComdlg32 = LoadLibraryA("comdlg32.dll");
2804 assert(hComdlg32);
2805 pPrintDlgA = (void *)GetProcAddress(hComdlg32, "PrintDlgA");
2806 assert(pPrintDlgA);
2808 memset(&prn_dlg, 0, sizeof(prn_dlg));
2809 prn_dlg.lStructSize = sizeof(prn_dlg);
2810 prn_dlg.Flags = PD_RETURNDEFAULT;
2811 ret = pPrintDlgA(&prn_dlg);
2812 FreeLibrary(hComdlg32);
2813 if (!ret)
2815 skip("PrintDlg returned no default printer\n");
2816 return;
2818 ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
2819 ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
2821 dm = GlobalLock(prn_dlg.hDevMode);
2822 ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
2823 trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
2825 dn = GlobalLock(prn_dlg.hDevNames);
2826 ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
2827 ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
2828 ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
2829 ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
2830 ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
2831 driver = (const char *)dn + dn->wDriverOffset;
2832 device = (const char *)dn + dn->wDeviceOffset;
2833 port = (const char *)dn + dn->wOutputOffset;
2834 trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
2836 test_DEVMODEA(dm, dm->dmSize + dm->dmDriverExtra, device);
2838 n_papers = DeviceCapabilitiesA(device, port, DC_PAPERS, NULL, NULL);
2839 ok(n_papers > 0, "DeviceCapabilitiesA DC_PAPERS failed\n");
2840 papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
2841 ret = DeviceCapabilitiesA(device, port, DC_PAPERS, (LPSTR)papers, NULL);
2842 ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
2843 #ifdef VERBOSE
2844 for (ret = 0; ret < n_papers; ret++)
2845 trace("papers[%d] = %d\n", ret, papers[ret]);
2846 #endif
2847 HeapFree(GetProcessHeap(), 0, papers);
2849 n_paper_size = DeviceCapabilitiesA(device, port, DC_PAPERSIZE, NULL, NULL);
2850 ok(n_paper_size > 0, "DeviceCapabilitiesA DC_PAPERSIZE failed\n");
2851 ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
2852 paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
2853 ret = DeviceCapabilitiesA(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
2854 ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
2855 #ifdef VERBOSE
2856 for (ret = 0; ret < n_paper_size; ret++)
2857 trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
2858 #endif
2859 HeapFree(GetProcessHeap(), 0, paper_size);
2861 n_paper_names = DeviceCapabilitiesA(device, port, DC_PAPERNAMES, NULL, NULL);
2862 ok(n_paper_names > 0, "DeviceCapabilitiesA DC_PAPERNAMES failed\n");
2863 ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
2864 paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
2865 ret = DeviceCapabilitiesA(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
2866 ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
2867 #ifdef VERBOSE
2868 for (ret = 0; ret < n_paper_names; ret++)
2869 trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
2870 #endif
2871 HeapFree(GetProcessHeap(), 0, paper_name);
2873 n_copies = DeviceCapabilitiesA(device, port, DC_COPIES, NULL, dm);
2874 ok(n_copies > 0, "DeviceCapabilitiesA DC_COPIES failed\n");
2875 trace("n_copies = %d\n", n_copies);
2877 /* these capabilities are not available on all printer drivers */
2878 if (0)
2880 ret = DeviceCapabilitiesA(device, port, DC_MAXEXTENT, NULL, NULL);
2881 ok(ret != -1, "DeviceCapabilitiesA DC_MAXEXTENT failed\n");
2882 ext = MAKEPOINTS(ret);
2883 trace("max ext = %d x %d\n", ext.x, ext.y);
2885 ret = DeviceCapabilitiesA(device, port, DC_MINEXTENT, NULL, NULL);
2886 ok(ret != -1, "DeviceCapabilitiesA DC_MINEXTENT failed\n");
2887 ext = MAKEPOINTS(ret);
2888 trace("min ext = %d x %d\n", ext.x, ext.y);
2891 fields = DeviceCapabilitiesA(device, port, DC_FIELDS, NULL, NULL);
2892 ok(fields != (DWORD)-1, "DeviceCapabilitiesA DC_FIELDS failed\n");
2893 ok(fields == (dm->dmFields | DM_FORMNAME) ||
2894 fields == ((dm->dmFields | DM_FORMNAME | DM_PAPERSIZE) & ~(DM_PAPERLENGTH|DM_PAPERWIDTH)) ||
2895 broken(fields == dm->dmFields), /* Win9x/WinMe */
2896 "fields %lx, dm->dmFields %lx\n", fields, dm->dmFields);
2898 GlobalUnlock(prn_dlg.hDevMode);
2899 GlobalFree(prn_dlg.hDevMode);
2900 GlobalUnlock(prn_dlg.hDevNames);
2901 GlobalFree(prn_dlg.hDevNames);
2904 static void test_OpenPrinter_defaults(void)
2906 HANDLE printer;
2907 BOOL ret;
2908 DWORD needed;
2909 short default_size;
2910 ADDJOB_INFO_1A *add_job;
2911 JOB_INFO_2A *job_info;
2912 DEVMODEA my_dm;
2913 PRINTER_DEFAULTSA prn_def;
2914 PRINTER_INFO_2A *pi;
2916 if (!default_printer)
2918 skip("There is no default printer installed\n");
2919 return;
2922 /* Printer opened with NULL defaults. Retrieve default paper size
2923 and confirm that jobs have this size. */
2925 ret = OpenPrinterA( default_printer, &printer, NULL );
2926 if (!ret)
2928 skip("Unable to open the default printer (%s)\n", default_printer);
2929 return;
2932 ret = GetPrinterA( printer, 2, NULL, 0, &needed );
2933 ok( !ret, "got %d\n", ret );
2934 pi = HeapAlloc( GetProcessHeap(), 0, needed );
2935 ret = GetPrinterA( printer, 2, (BYTE *)pi, needed, &needed );
2936 ok( ret, "GetPrinterA() failed le=%ld\n", GetLastError() );
2937 default_size = pi->pDevMode->u1.s1.dmPaperSize;
2938 HeapFree( GetProcessHeap(), 0, pi );
2940 needed = 0;
2941 SetLastError( 0xdeadbeef );
2942 ret = AddJobA( printer, 1, NULL, 0, &needed );
2943 ok( !ret, "got %d\n", ret );
2944 if (GetLastError() == ERROR_NOT_SUPPORTED) /* win8 */
2946 win_skip( "AddJob is not supported on this platform\n" );
2947 ClosePrinter( printer );
2948 return;
2950 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError() );
2951 ok( needed > sizeof(ADDJOB_INFO_1A), "AddJob needs %lu bytes\n", needed);
2952 add_job = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, needed );
2953 ret = AddJobA( printer, 1, (BYTE *)add_job, needed, &needed );
2954 ok( ret, "AddJobA() failed le=%ld\n", GetLastError() );
2956 ret = GetJobA( printer, add_job->JobId, 2, NULL, 0, &needed );
2957 ok( !ret, "got %d\n", ret );
2958 job_info = HeapAlloc( GetProcessHeap(), 0, needed );
2959 ret = GetJobA( printer, add_job->JobId, 2, (BYTE *)job_info, needed, &needed );
2960 ok( ret, "GetJobA() failed le=%ld\n", GetLastError() );
2962 todo_wine
2963 ok( job_info->pDevMode != NULL, "got NULL DEVMODEA\n");
2964 if (job_info->pDevMode)
2965 ok( job_info->pDevMode->u1.s1.dmPaperSize == default_size, "got %d default %d\n",
2966 job_info->pDevMode->u1.s1.dmPaperSize, default_size );
2968 HeapFree( GetProcessHeap(), 0, job_info );
2969 ScheduleJob( printer, add_job->JobId ); /* remove the empty job */
2970 HeapFree( GetProcessHeap(), 0, add_job );
2971 ClosePrinter( printer );
2973 /* Printer opened with something other than the default paper size. */
2975 memset( &my_dm, 0, sizeof(my_dm) );
2976 my_dm.dmSize = sizeof(my_dm);
2977 my_dm.dmFields = DM_PAPERSIZE;
2978 my_dm.u1.s1.dmPaperSize = (default_size == DMPAPER_A4) ? DMPAPER_LETTER : DMPAPER_A4;
2980 prn_def.pDatatype = NULL;
2981 prn_def.pDevMode = &my_dm;
2982 prn_def.DesiredAccess = PRINTER_ACCESS_USE;
2984 ret = OpenPrinterA( default_printer, &printer, &prn_def );
2985 ok( ret, "OpenPrinterA() failed le=%ld\n", GetLastError() );
2987 /* GetPrinter stills returns default size */
2988 ret = GetPrinterA( printer, 2, NULL, 0, &needed );
2989 ok( !ret, "got %d\n", ret );
2990 pi = HeapAlloc( GetProcessHeap(), 0, needed );
2991 ret = GetPrinterA( printer, 2, (BYTE *)pi, needed, &needed );
2992 ok( ret, "GetPrinterA() failed le=%ld\n", GetLastError() );
2993 ok( pi->pDevMode->u1.s1.dmPaperSize == default_size, "got %d default %d\n",
2994 pi->pDevMode->u1.s1.dmPaperSize, default_size );
2996 HeapFree( GetProcessHeap(), 0, pi );
2998 /* However the GetJobA has the new size */
2999 ret = AddJobA( printer, 1, NULL, 0, &needed );
3000 ok( !ret, "got %d\n", ret );
3001 add_job = HeapAlloc( GetProcessHeap(), 0, needed );
3002 ret = AddJobA( printer, 1, (BYTE *)add_job, needed, &needed );
3003 ok( ret, "AddJobA() failed le=%ld\n", GetLastError() );
3005 ret = GetJobA( printer, add_job->JobId, 2, NULL, 0, &needed );
3006 ok( !ret, "got %d\n", ret );
3007 job_info = HeapAlloc( GetProcessHeap(), 0, needed );
3008 ret = GetJobA( printer, add_job->JobId, 2, (BYTE *)job_info, needed, &needed );
3009 ok( ret, "GetJobA() failed le=%ld\n", GetLastError() );
3011 ok( job_info->pDevMode->dmFields == DM_PAPERSIZE, "got %08lx\n",
3012 job_info->pDevMode->dmFields );
3013 ok( job_info->pDevMode->u1.s1.dmPaperSize == my_dm.u1.s1.dmPaperSize,
3014 "got %d new size %d\n",
3015 job_info->pDevMode->u1.s1.dmPaperSize, my_dm.u1.s1.dmPaperSize );
3017 HeapFree( GetProcessHeap(), 0, job_info );
3018 ScheduleJob( printer, add_job->JobId ); /* remove the empty job */
3019 HeapFree( GetProcessHeap(), 0, add_job );
3020 ClosePrinter( printer );
3023 static void test_IsValidDevmodeW(void)
3025 static const struct
3027 DWORD dmFields;
3028 WORD dmSize;
3029 BOOL ret;
3030 } test[] =
3032 { 0, FIELD_OFFSET(DEVMODEW, dmFields) + 0, FALSE },
3033 { 0, FIELD_OFFSET(DEVMODEW, dmFields) + 1, FALSE },
3034 { 0, FIELD_OFFSET(DEVMODEW, dmFields) + 2, FALSE },
3035 { 0, FIELD_OFFSET(DEVMODEW, dmFields) + 3, FALSE },
3036 { 0, FIELD_OFFSET(DEVMODEW, dmFields) + 4, TRUE },
3038 { DM_ORIENTATION, FIELD_OFFSET(DEVMODEW, u1.s1.dmOrientation) + 0, FALSE },
3039 { DM_ORIENTATION, FIELD_OFFSET(DEVMODEW, u1.s1.dmOrientation) + 1, FALSE },
3040 { DM_ORIENTATION, FIELD_OFFSET(DEVMODEW, u1.s1.dmOrientation) + 2, TRUE },
3042 { DM_NUP, FIELD_OFFSET(DEVMODEW, u2.dmNup) + 0, FALSE },
3043 { DM_NUP, FIELD_OFFSET(DEVMODEW, u2.dmNup) + 1, FALSE },
3044 { DM_NUP, FIELD_OFFSET(DEVMODEW, u2.dmNup) + 2, FALSE },
3045 { DM_NUP, FIELD_OFFSET(DEVMODEW, u2.dmNup) + 3, FALSE },
3046 { DM_NUP, FIELD_OFFSET(DEVMODEW, u2.dmNup) + 4, TRUE },
3049 static const struct
3051 DWORD dmSize;
3052 DWORD dmDriverExtra;
3053 DWORD bufSize;
3054 BOOL ret;
3055 } size_test[] =
3057 { FIELD_OFFSET(DEVMODEW, dmFields) + 3, 1, FIELD_OFFSET(DEVMODEW, dmFields) + 4, FALSE },
3058 { FIELD_OFFSET(DEVMODEW, dmFields) + 4, 1, FIELD_OFFSET(DEVMODEW, dmFields) + 8, TRUE },
3059 { FIELD_OFFSET(DEVMODEW, dmFields) + 4, 2, FIELD_OFFSET(DEVMODEW, dmFields) + 8, TRUE },
3060 { FIELD_OFFSET(DEVMODEW, dmFields) + 4, 3, FIELD_OFFSET(DEVMODEW, dmFields) + 8, TRUE },
3061 { FIELD_OFFSET(DEVMODEW, dmFields) + 4, 4, FIELD_OFFSET(DEVMODEW, dmFields) + 8, TRUE },
3062 { FIELD_OFFSET(DEVMODEW, dmFields) + 4, 5, FIELD_OFFSET(DEVMODEW, dmFields) + 8, FALSE },
3063 { FIELD_OFFSET(DEVMODEW, dmFields) + 12, 1, FIELD_OFFSET(DEVMODEW, dmFields) + 16, TRUE },
3064 { FIELD_OFFSET(DEVMODEW, dmFields) + 12, 2, FIELD_OFFSET(DEVMODEW, dmFields) + 16, TRUE },
3065 { FIELD_OFFSET(DEVMODEW, dmFields) + 12, 3, FIELD_OFFSET(DEVMODEW, dmFields) + 16, TRUE },
3066 { FIELD_OFFSET(DEVMODEW, dmFields) + 12, 4, FIELD_OFFSET(DEVMODEW, dmFields) + 16, TRUE },
3067 { FIELD_OFFSET(DEVMODEW, dmFields) + 12, 5, FIELD_OFFSET(DEVMODEW, dmFields) + 16, FALSE },
3069 DEVMODEW dm;
3070 int i;
3071 BOOL ret;
3073 ret = IsValidDevmodeW(NULL, 0);
3074 ok(!ret, "got %d\n", ret);
3076 ret = IsValidDevmodeW(NULL, sizeof(DEVMODEW));
3077 ok(!ret, "got %d\n", ret);
3079 memset(&dm, 0, sizeof(dm));
3081 for (i = 0; i < ARRAY_SIZE(test); i++)
3083 dm.dmSize = test[i].dmSize;
3084 dm.dmFields = test[i].dmFields;
3085 ret = IsValidDevmodeW(&dm, dm.dmSize);
3086 ok(ret == test[i].ret, "%d: got %d\n", i, ret);
3087 ret = IsValidDevmodeW(&dm, dm.dmSize + 4);
3088 ok(ret == test[i].ret, "%d: got %d\n", i, ret);
3091 dm.dmFields = 0;
3092 for (i = 0; i < ARRAY_SIZE(size_test); i++)
3094 dm.dmSize = size_test[i].dmSize;
3095 dm.dmDriverExtra = size_test[i].dmDriverExtra;
3096 ret = IsValidDevmodeW(&dm, size_test[i].bufSize);
3097 ok(ret == size_test[i].ret, "%d: got %d\n", i, ret);
3101 START_TEST(info)
3103 hwinspool = LoadLibraryA("winspool.drv");
3104 pAddPortExA = (void *) GetProcAddress(hwinspool, "AddPortExA");
3105 pEnumPrinterDriversW = (void *) GetProcAddress(hwinspool, "EnumPrinterDriversW");
3106 pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
3107 pGetPrinterDataExA = (void *) GetProcAddress(hwinspool, "GetPrinterDataExA");
3108 pGetPrinterDriverW = (void *) GetProcAddress(hwinspool, "GetPrinterDriverW");
3109 pGetPrinterW = (void *) GetProcAddress(hwinspool, "GetPrinterW");
3110 pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
3111 pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
3113 find_default_printer();
3114 find_local_server();
3115 find_tempfile();
3117 test_AddMonitor();
3118 test_AddPort();
3119 test_AddPortEx();
3120 test_ConfigurePort();
3121 test_ClosePrinter();
3122 test_DeleteMonitor();
3123 test_DeletePort();
3124 test_DeviceCapabilities();
3125 test_DocumentProperties();
3126 test_EnumForms(NULL);
3127 if (default_printer) test_EnumForms(default_printer);
3128 test_EnumMonitors();
3129 test_EnumPorts();
3130 test_EnumPrinterDrivers();
3131 test_EnumPrinters();
3132 test_EnumPrintProcessors();
3133 test_GetDefaultPrinter();
3134 test_GetPrinterDriverDirectory();
3135 test_GetPrintProcessorDirectory();
3136 test_IsValidDevmodeW();
3137 test_OpenPrinter();
3138 test_OpenPrinter_defaults();
3139 test_GetPrinter();
3140 test_GetPrinterData();
3141 test_GetPrinterDataEx();
3142 test_GetPrinterDriver();
3143 test_SetDefaultPrinter();
3144 test_XcvDataW_MonitorUI();
3145 test_XcvDataW_PortIsValid();
3147 /* Cleanup our temporary file */
3148 DeleteFileA(tempfileA);