comctl32/tooltips: Remove redundant code, let handlers deal with A<->W conversions.
[wine] / dlls / winspool.drv / tests / info.c
1 /*
2  * Copyright (C) 2003, 2004 Stefan Leichter
3  * Copyright (C) 2005, 2006 Detlef Riekenberg
4  * Copyright (C) 2006 Dmitry Timoshkov
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <assert.h>
23
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
26
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"
37
38 #define MAGIC_DEAD  0xdeadbeef
39 #define DEFAULT_PRINTER_SIZE 1000
40
41 static CHAR does_not_exist_dll[]= "does_not_exist.dll";
42 static CHAR does_not_exist[]    = "does_not_exist";
43 static CHAR empty[]             = "";
44 static CHAR env_x64[]           = "Windows x64";
45 static CHAR env_x86[]           = "Windows NT x86";
46 static CHAR env_win9x_case[]    = "windowS 4.0";
47 static CHAR illegal_name[]      = "illegal,name";
48 static CHAR invalid_env[]       = "invalid_env";
49 static CHAR LocalPortA[]        = "Local Port";
50 static CHAR portname_com1[]     = "COM1:";
51 static CHAR portname_file[]     = "FILE:";
52 static CHAR portname_lpt1[]     = "LPT1:";
53 static CHAR server_does_not_exist[] = "\\does_not_exist";
54 static CHAR version_dll[]       = "version.dll";
55 static CHAR winetest[]          = "winetest";
56 static CHAR xcv_localport[]     = ",XcvMonitor Local Port";
57
58 static WCHAR cmd_MonitorUIW[] = {'M','o','n','i','t','o','r','U','I',0};
59 static WCHAR cmd_PortIsValidW[] = {'P','o','r','t','I','s','V','a','l','i','d',0};
60 static WCHAR emptyW[] = {0};
61
62 static WCHAR portname_com1W[] = {'C','O','M','1',':',0};
63 static WCHAR portname_com2W[] = {'C','O','M','2',':',0};
64 static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
65 static WCHAR portname_lpt1W[] = {'L','P','T','1',':',0};
66 static WCHAR portname_lpt2W[] = {'L','P','T','2',':',0};
67
68 static HANDLE  hwinspool;
69 static BOOL  (WINAPI * pGetDefaultPrinterA)(LPSTR, LPDWORD);
70 static BOOL  (WINAPI * pSetDefaultPrinterA)(LPCSTR);
71 static DWORD (WINAPI * pXcvDataW)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD, PDWORD);
72 static BOOL  (WINAPI * pAddPortExA)(LPSTR, DWORD, LPBYTE, LPSTR);
73
74
75 /* ################################ */
76
77 struct monitor_entry {
78     LPSTR  env;
79     CHAR  dllname[32];
80 };
81
82 static LPSTR default_printer = NULL;
83 static LPSTR local_server = NULL;
84 static LPSTR tempdirA = NULL;
85 static LPSTR tempfileA = NULL;
86 static LPWSTR tempdirW = NULL;
87 static LPWSTR tempfileW = NULL;
88
89 /* ################################ */
90 /* report common behavior only once */
91 static DWORD deactivated_spooler_reported = 0;
92 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
93     if ((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
94     { \
95         if (!deactivated_spooler_reported) { \
96             deactivated_spooler_reported++; \
97             skip("The Service 'Spooler' is required for many test\n"); \
98         } \
99         return; \
100     }
101
102 static DWORD access_denied_reported = 0;
103 #define RETURN_ON_ACCESS_DENIED(res) \
104     if ((res == 0) && (GetLastError() == ERROR_ACCESS_DENIED)) \
105     { \
106         if (!access_denied_reported) { \
107             access_denied_reported++; \
108             skip("More Access-Rights are required for many test\n"); \
109         } \
110         return; \
111     }
112
113 /* ################################ */
114
115 static void find_default_printer(VOID)
116 {
117     static  char    buffer[DEFAULT_PRINTER_SIZE];
118     DWORD   needed;
119     DWORD   res;
120     LPSTR   ptr;
121
122     if ((default_printer == NULL) && (pGetDefaultPrinterA))
123     {
124         /* w2k and above */
125         needed = sizeof(buffer);
126         res = pGetDefaultPrinterA(buffer, &needed);
127         if(res)  default_printer = buffer;
128         trace("default_printer: '%s'\n", default_printer);
129     }
130     if (default_printer == NULL)
131     {
132         HKEY hwindows;
133         DWORD   type;
134         /* NT 3.x and above */
135         if (RegOpenKeyEx(HKEY_CURRENT_USER, 
136                         "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
137                         0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
138
139             needed = sizeof(buffer);
140             if (RegQueryValueEx(hwindows, "device", NULL, 
141                                 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
142
143                 ptr = strchr(buffer, ',');
144                 if (ptr) {
145                     ptr[0] = '\0';
146                     default_printer = buffer;
147                 }
148             }
149             RegCloseKey(hwindows);
150         }
151         trace("default_printer: '%s'\n", default_printer);
152     }
153     if (default_printer == NULL)
154     {
155         /* win9x */
156         needed = sizeof(buffer);
157         res = GetProfileStringA("windows", "device", "*", buffer, needed);
158         if(res) {
159             ptr = strchr(buffer, ',');
160             if (ptr) {
161                 ptr[0] = '\0';
162                 default_printer = buffer;
163             }
164         }
165         trace("default_printer: '%s'\n", default_printer);
166     }
167 }
168
169
170 static struct monitor_entry * find_installed_monitor(void)
171 {
172     MONITOR_INFO_2A mi2a; 
173     static struct  monitor_entry * entry = NULL;
174     DWORD   num_tests;
175     DWORD   i = 0;
176
177     static struct monitor_entry  monitor_table[] = {
178         {env_win9x_case, "localspl.dll"},
179         {env_x86,        "localspl.dll"},
180         {env_x64,        "localspl.dll"},
181         {env_win9x_case, "localmon.dll"},
182         {env_x86,        "localmon.dll"},
183         {env_win9x_case, "tcpmon.dll"},
184         {env_x86,        "tcpmon.dll"},
185         {env_win9x_case, "usbmon.dll"},
186         {env_x86,        "usbmon.dll"},
187         {env_win9x_case, "mspp32.dll"},
188         {env_x86,        "win32spl.dll"},
189         {env_x86,        "redmonnt.dll"},
190         {env_x86,        "redmon35.dll"},
191         {env_win9x_case, "redmon95.dll"},
192         {env_x86,        "pdfcmnnt.dll"},
193         {env_win9x_case, "pdfcmn95.dll"},
194     };
195
196     if (entry) return entry;
197
198     num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
199
200     /* cleanup */
201     DeleteMonitorA(NULL, env_x64, winetest);
202     DeleteMonitorA(NULL, env_x86, winetest);
203     DeleteMonitorA(NULL, env_win9x_case, winetest);
204
205     /* find a usable monitor from the table */
206     mi2a.pName = winetest;
207     while ((entry == NULL) && (i < num_tests)) {
208         entry = &monitor_table[i];
209         i++;
210         mi2a.pEnvironment = entry->env;
211         mi2a.pDLLName = entry->dllname;
212
213         if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
214             /* we got one */
215             trace("using '%s', '%s'\n", entry->env, entry->dllname);
216             DeleteMonitorA(NULL, entry->env, winetest);
217         }
218         else
219         {
220             entry = NULL;
221         }
222     }
223     return entry;
224 }
225
226
227 /* ########################### */
228
229 static void find_local_server(VOID)
230 {
231     static  char    buffer[MAX_PATH];
232     DWORD   res;
233     DWORD   size;
234
235     size = sizeof(buffer) - 3 ;
236     buffer[0] = '\\';
237     buffer[1] = '\\';
238     buffer[2] = '\0';
239
240     SetLastError(0xdeadbeef);
241     res = GetComputerNameA(&buffer[2], &size);
242     trace("returned %d with %d and %d: '%s'\n", res, GetLastError(), size, buffer);
243
244     ok( res != 0, "returned %d with %d and %d: '%s' (expected '!= 0')\n",
245         res, GetLastError(), size, buffer);
246
247     if (res) local_server = buffer;
248 }
249
250 /* ########################### */
251
252 static void find_tempfile(VOID)
253 {
254     static CHAR buffer_dirA[MAX_PATH];
255     static CHAR buffer_fileA[MAX_PATH];
256     static WCHAR buffer_dirW[MAX_PATH];
257     static WCHAR buffer_fileW[MAX_PATH];
258     DWORD   res;
259     int     resint;
260
261     memset(buffer_dirA, 0, MAX_PATH - 1);
262     buffer_dirA[MAX_PATH - 1] = '\0';
263     SetLastError(0xdeadbeef);
264     res = GetTempPathA(MAX_PATH, buffer_dirA);
265     ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_dirA);
266     if (res == 0) return;
267
268     memset(buffer_fileA, 0, MAX_PATH - 1);
269     buffer_fileA[MAX_PATH - 1] = '\0';
270     SetLastError(0xdeadbeef);
271     res = GetTempFileNameA(buffer_dirA, winetest, 0, buffer_fileA);
272     ok(res, "returned %u with %u and '%s' (expected '!= 0')\n", res, GetLastError(), buffer_fileA);
273     if (res == 0) return;
274
275     SetLastError(0xdeadbeef);
276     resint = MultiByteToWideChar(CP_ACP, 0, buffer_dirA, -1, buffer_dirW, MAX_PATH);
277     ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
278     if (resint == 0) return;
279
280     SetLastError(0xdeadbeef);
281     resint = MultiByteToWideChar(CP_ACP, 0, buffer_fileA, -1, buffer_fileW, MAX_PATH);
282     ok(res, "returned %u with %u (expected '!= 0')\n", resint, GetLastError());
283     if (resint == 0) return;
284
285     tempdirA  = buffer_dirA;
286     tempfileA = buffer_fileA;
287     tempdirW  = buffer_dirW;
288     tempfileW = buffer_fileW;
289     trace("tempfile: '%s'\n", tempfileA);
290 }
291
292 /* ########################### */
293
294 static void test_AddMonitor(void)
295 {
296     MONITOR_INFO_2A mi2a; 
297     struct  monitor_entry * entry = NULL;
298     DWORD   res;
299
300     entry = find_installed_monitor();
301
302     SetLastError(MAGIC_DEAD);
303     res = AddMonitorA(NULL, 1, NULL);
304     ok(!res && (GetLastError() == ERROR_INVALID_LEVEL), 
305         "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
306         res, GetLastError());
307
308     SetLastError(MAGIC_DEAD);
309     res = AddMonitorA(NULL, 3, NULL);
310     ok(!res && (GetLastError() == ERROR_INVALID_LEVEL), 
311         "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
312         res, GetLastError());
313
314     if (0)
315     {
316     /* This test crash with win9x on vmware (works with win9x on qemu 0.8.1) */
317     SetLastError(MAGIC_DEAD);
318     res = AddMonitorA(NULL, 2, NULL);
319     /* NT: unchanged,  9x: ERROR_PRIVILEGE_NOT_HELD */
320     ok(!res &&
321         ((GetLastError() == MAGIC_DEAD) ||
322          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
323         "returned %d with %d (expected '0' with: MAGIC_DEAD or "
324         "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
325     }
326
327     ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
328     SetLastError(MAGIC_DEAD);
329     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
330     RETURN_ON_DEACTIVATED_SPOOLER(res)
331     RETURN_ON_ACCESS_DENIED(res)
332
333     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_INVALID_ENVIRONMENT */
334     ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
335                 (GetLastError() == ERROR_INVALID_ENVIRONMENT)), 
336         "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
337         "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
338
339     if (!entry) {
340         skip("No usable Monitor found\n");
341         return;
342     }
343
344     if (0)
345     {
346     /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
347        HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
348        or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
349        is created on win9x and we do not want to hit this bug here. */
350
351     mi2a.pEnvironment = entry->env;
352     SetLastError(MAGIC_DEAD);
353     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
354     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
355     }
356
357     mi2a.pEnvironment = entry->env;
358     mi2a.pName = empty;
359     SetLastError(MAGIC_DEAD);
360     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
361     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
362     ok( !res &&
363         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
364          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
365         "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
366         "ERROR_PRIVILEGE_NOT_HELD)\n",
367         res, GetLastError());
368
369     mi2a.pName = winetest;
370     SetLastError(MAGIC_DEAD);
371     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
372     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
373     ok( !res &&
374         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
375          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
376         "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
377         "ERROR_PRIVILEGE_NOT_HELD)\n",
378         res, GetLastError());
379
380     mi2a.pDLLName = empty;
381     SetLastError(MAGIC_DEAD);
382     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
383     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
384         "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
385         res, GetLastError());
386
387     mi2a.pDLLName = does_not_exist_dll;
388     SetLastError(MAGIC_DEAD);
389     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
390     /* NT: ERROR_MOD_NOT_FOUND,  9x: ERROR_INVALID_PARAMETER */
391     ok( !res &&
392         ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
393         (GetLastError() == ERROR_INVALID_PARAMETER)),
394         "returned %d with %d (expected '0' with: ERROR_MOD_NOT_FOUND or "
395         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
396
397     mi2a.pDLLName = version_dll;
398     SetLastError(MAGIC_DEAD);
399     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
400     /* NT: ERROR_PROC_NOT_FOUND,  9x: ERROR_INVALID_PARAMETER */
401     ok( !res &&
402         ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
403         (GetLastError() == ERROR_INVALID_PARAMETER)),
404         "returned %d with %d (expected '0' with: ERROR_PROC_NOT_FOUND or "
405         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
406     if (res) DeleteMonitorA(NULL, entry->env, winetest);
407
408    /* Test AddMonitor with real options */
409     mi2a.pDLLName = entry->dllname;
410     SetLastError(MAGIC_DEAD);
411     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
412     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
413
414     /* add a monitor twice */
415     SetLastError(MAGIC_DEAD);
416     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
417     /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
418     ok( !res &&
419         ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
420         (GetLastError() == ERROR_ALREADY_EXISTS)), 
421         "returned %d with %d (expected '0' with: "
422         "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
423         res, GetLastError());
424
425     DeleteMonitorA(NULL, entry->env, winetest);
426     SetLastError(MAGIC_DEAD);
427     res = AddMonitorA(empty, 2, (LPBYTE) &mi2a);
428     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
429
430     /* cleanup */
431     DeleteMonitorA(NULL, entry->env, winetest);
432
433 }
434
435 /* ########################### */
436
437 static void test_AddPort(void)
438 {
439     DWORD   res;
440
441     SetLastError(0xdeadbeef);
442     res = AddPortA(NULL, 0, NULL);
443     RETURN_ON_DEACTIVATED_SPOOLER(res)
444     /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
445     ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) || 
446                  (GetLastError() == ERROR_INVALID_PARAMETER)),
447         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
448         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
449
450
451     SetLastError(0xdeadbeef);
452     res = AddPortA(NULL, 0, empty);
453     /* Allowed only for (Printer-)Administrators */
454     RETURN_ON_ACCESS_DENIED(res)
455
456     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
457     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
458                  (GetLastError() == ERROR_INVALID_PARAMETER)),
459         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
460         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
461
462
463     SetLastError(0xdeadbeef);
464     res = AddPortA(NULL, 0, does_not_exist);
465     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
466     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
467                  (GetLastError() == ERROR_INVALID_PARAMETER)),
468         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
469         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
470
471 }
472
473 /* ########################### */
474
475 static void test_AddPortEx(void)
476 {
477     PORT_INFO_2A pi;
478     DWORD   res;
479
480
481     if (!pAddPortExA) {
482         win_skip("AddPortEx not supported\n");
483         return;
484     }
485
486     /* start test with a clean system */
487     DeletePortA(NULL, 0, tempfileA);
488
489     pi.pPortName = tempfileA;
490     SetLastError(0xdeadbeef);
491     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
492     RETURN_ON_DEACTIVATED_SPOOLER(res)
493
494     /* Allowed only for (Printer-)Administrators.
495        W2K+XP: ERROR_INVALID_PARAMETER  */
496     if (!res && (GetLastError() == ERROR_INVALID_PARAMETER)) {
497         skip("ACCESS_DENIED (ERROR_INVALID_PARAMETER)\n");
498         return;
499     }
500     ok( res, "got %u with %u (expected '!= 0')\n", res, GetLastError());
501
502     /* Add a port, that already exist */
503     SetLastError(0xdeadbeef);
504     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
505     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
506         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
507         res, GetLastError());
508     DeletePortA(NULL, 0, tempfileA);
509
510
511     /* the Monitorname must match */
512     SetLastError(0xdeadbeef);
513     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, NULL);
514     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
515         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
516         res, GetLastError());
517     if (res) DeletePortA(NULL, 0, tempfileA);
518
519     SetLastError(0xdeadbeef);
520     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, empty);
521     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
522         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
523         res, GetLastError());
524     if (res) DeletePortA(NULL, 0, tempfileA);
525
526     SetLastError(0xdeadbeef);
527     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, does_not_exist);
528     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
529         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
530         res, GetLastError());
531     if (res) DeletePortA(NULL, 0, tempfileA);
532
533
534     /* We need a Portname */
535     SetLastError(0xdeadbeef);
536     res = pAddPortExA(NULL, 1, NULL, LocalPortA);
537     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
538         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
539         res, GetLastError());
540
541     pi.pPortName = NULL;
542     SetLastError(0xdeadbeef);
543     res = pAddPortExA(NULL, 1, (LPBYTE) &pi, LocalPortA);
544     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
545         "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
546         res, GetLastError());
547     if (res) DeletePortA(NULL, 0, tempfileA);
548
549
550     /*  level 2 is documented as supported for Printmonitors,
551         but that is not supported for "Local Port" (localspl.dll) and
552         AddPortEx fails with ERROR_INVALID_LEVEL */
553
554     pi.pPortName = tempfileA;
555     pi.pMonitorName = LocalPortA;
556     pi.pDescription = winetest;
557     pi.fPortType = PORT_TYPE_WRITE;
558
559     SetLastError(0xdeadbeef);
560     res = pAddPortExA(NULL, 2, (LPBYTE) &pi, LocalPortA);
561     ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
562         "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
563         res, GetLastError());
564     if (res) DeletePortA(NULL, 0, tempfileA);
565
566
567     /* invalid levels */
568     SetLastError(0xdeadbeef);
569     res = pAddPortExA(NULL, 0, (LPBYTE) &pi, LocalPortA);
570     ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
571         "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
572         res, GetLastError());
573
574     SetLastError(0xdeadbeef);
575     res = pAddPortExA(NULL, 3, (LPBYTE) &pi, LocalPortA);
576     ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
577         "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
578         res, GetLastError());
579
580
581     /* cleanup */
582     DeletePortA(NULL, 0, tempfileA);
583
584 }
585
586 /* ########################### */
587
588 static void test_ConfigurePort(void)
589 {
590     DWORD   res;
591
592
593     SetLastError(0xdeadbeef);
594     res = ConfigurePortA(NULL, 0, NULL);
595     RETURN_ON_DEACTIVATED_SPOOLER(res)
596     /* NT: RPC_X_NULL_REF_POINTER, 9x: ERROR_INVALID_PARAMETER */
597     ok( !res && ((GetLastError() == RPC_X_NULL_REF_POINTER) || 
598                  (GetLastError() == ERROR_INVALID_PARAMETER)),
599         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
600         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
601
602     SetLastError(0xdeadbeef);
603     res = ConfigurePortA(NULL, 0, empty);
604     /* Allowed only for (Printer-)Administrators */
605     RETURN_ON_ACCESS_DENIED(res)
606
607     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
608     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
609                  (GetLastError() == ERROR_INVALID_PARAMETER)),
610         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
611         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
612
613
614     SetLastError(0xdeadbeef);
615     res = ConfigurePortA(NULL, 0, does_not_exist);
616     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
617     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
618                  (GetLastError() == ERROR_INVALID_PARAMETER)),
619         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
620         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
621
622
623     /*  Testing-Results:
624         - Case of Portnames is ignored 
625         - Portname without ":" => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
626         - Empty Servername (LPT1:) => NT: ERROR_NOT_SUPPORTED, 9x: Dialog comes up
627
628         - Port not present =>  9x: ERROR_INVALID_PARAMETER, NT:ERROR_NOT_SUPPORTED
629         - "FILE:" => 9x:Success, NT:ERROR_CANCELED
630         - Cancel ("Local Port") => ERROR_CANCELED
631         - Cancel ("Redirected Port") => Success
632     */
633     if (winetest_interactive > 0) {
634         SetLastError(0xdeadbeef);
635         res = ConfigurePortA(NULL, 0, portname_com1);
636         trace("'%s' returned %d with %d\n", portname_com1, res, GetLastError());
637
638         SetLastError(0xdeadbeef);
639         res = ConfigurePortA(NULL, 0, portname_lpt1);
640         trace("'%s' returned %d with %d\n", portname_lpt1, res, GetLastError());
641
642         SetLastError(0xdeadbeef);
643         res = ConfigurePortA(NULL, 0, portname_file);
644         trace("'%s' returned %d with %d\n", portname_file, res, GetLastError());
645     }
646 }
647
648 /* ########################### */
649
650 static void test_DeleteMonitor(void)
651 {
652     MONITOR_INFO_2A         mi2a;
653     struct monitor_entry  * entry = NULL;
654     DWORD                   res;
655
656
657     entry = find_installed_monitor();
658
659     if (!entry) {
660         skip("No usable Monitor found\n");
661         return;
662     }
663
664     mi2a.pName = winetest;
665     mi2a.pEnvironment = entry->env;
666     mi2a.pDLLName = entry->dllname;
667
668     /* Testing DeleteMonitor with real options */
669     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
670
671     SetLastError(MAGIC_DEAD);
672     res = DeleteMonitorA(NULL, entry->env, winetest);
673     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
674
675     /* Delete the Monitor twice */
676     SetLastError(MAGIC_DEAD);
677     res = DeleteMonitorA(NULL, entry->env, winetest);
678     /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
679     ok( !res &&
680         ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
681         (GetLastError() == ERROR_INVALID_PARAMETER)), 
682         "returned %d with %d (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR"
683         " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
684
685     /* the environment */
686     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
687     SetLastError(MAGIC_DEAD);
688     res = DeleteMonitorA(NULL, NULL, winetest);
689     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
690
691     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
692     SetLastError(MAGIC_DEAD);
693     res = DeleteMonitorA(NULL, empty, winetest);
694     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
695
696     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
697     SetLastError(MAGIC_DEAD);
698     res = DeleteMonitorA(NULL, invalid_env, winetest);
699     ok( res ||
700         (!res && GetLastError() == ERROR_INVALID_ENVIRONMENT) /* Vista/W2K8 */,
701         "returned %d with %d\n", res, GetLastError());
702
703     /* the monitor-name */
704     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
705     SetLastError(MAGIC_DEAD);
706     res = DeleteMonitorA(NULL, entry->env, NULL);
707     /* NT: ERROR_INVALID_PARAMETER (87),  9x: ERROR_INVALID_NAME (123)*/
708     ok( !res &&
709         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
710         (GetLastError() == ERROR_INVALID_NAME)),
711         "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
712         "ERROR_INVALID_NAME)\n", res, GetLastError());
713
714     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
715     SetLastError(MAGIC_DEAD);
716     res = DeleteMonitorA(NULL, entry->env, empty);
717     /* NT: ERROR_INVALID_PARAMETER (87),  9x: ERROR_INVALID_NAME (123)*/
718     ok( !res && 
719         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
720         (GetLastError() == ERROR_INVALID_NAME)),
721         "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or "
722         "ERROR_INVALID_NAME)\n", res, GetLastError());
723
724     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
725     SetLastError(MAGIC_DEAD);
726     res = DeleteMonitorA(empty, entry->env, winetest);
727     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
728
729     /* cleanup */
730     DeleteMonitorA(NULL, entry->env, winetest);
731 }
732
733 /* ########################### */
734
735 static void test_DeletePort(void)
736 {
737     DWORD   res;
738
739     SetLastError(0xdeadbeef);
740     res = DeletePortA(NULL, 0, NULL);
741     RETURN_ON_DEACTIVATED_SPOOLER(res)
742
743     SetLastError(0xdeadbeef);
744     res = DeletePortA(NULL, 0, empty);
745     /* Allowed only for (Printer-)Administrators */
746     RETURN_ON_ACCESS_DENIED(res)
747
748     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
749     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
750                  (GetLastError() == ERROR_INVALID_PARAMETER)),
751         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
752         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
753
754
755     SetLastError(0xdeadbeef);
756     res = DeletePortA(NULL, 0, does_not_exist);
757     /* XP: ERROR_NOT_SUPPORTED, NT351 and 9x: ERROR_INVALID_PARAMETER */
758     ok( !res && ((GetLastError() == ERROR_NOT_SUPPORTED) || 
759                  (GetLastError() == ERROR_INVALID_PARAMETER)),
760         "returned %d with %d (expected '0' with ERROR_NOT_SUPPORTED or "
761         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
762
763 }
764
765 /* ########################### */
766
767 static void test_EnumForms(LPSTR pName)
768 {
769     DWORD   res;
770     HANDLE  hprinter = 0;
771     LPBYTE  buffer;
772     DWORD   cbBuf;
773     DWORD   pcbNeeded;
774     DWORD   pcReturned;
775     DWORD   level;
776     UINT    i;
777     const char *formtype;
778     static const char * const formtypes[] = { "FORM_USER", "FORM_BUILTIN", "FORM_PRINTER", "FORM_flag_unknown" };
779 #define FORMTYPE_MAX 2
780     PFORM_INFO_1A pFI_1a;
781     PFORM_INFO_2A pFI_2a;
782
783     res = OpenPrinter(pName, &hprinter, NULL);
784     RETURN_ON_DEACTIVATED_SPOOLER(res)
785     if (!res || !hprinter)
786     {
787         /* Open the local Prinserver is not supported on win9x */
788         if (pName) skip("Failed to open '%s' (not supported on win9x)\n", pName);
789         return;
790     }
791
792     /* valid levels are 1 and 2 */
793     for(level = 0; level < 4; level++) {
794         cbBuf = 0xdeadbeef;
795         pcReturned = 0xdeadbeef;
796         SetLastError(0xdeadbeef);
797         res = EnumFormsA(hprinter, level, NULL, 0, &cbBuf, &pcReturned);
798
799         /* EnumForms is not implemented in win9x */
800         if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
801
802         /* EnumForms for the Server not implemented on all NT-Versions */
803         if (!res && (GetLastError() == ERROR_INVALID_HANDLE) && !pName) continue;
804
805         /* Level 2 for EnumForms is not supported on all systems */
806         if (!res && (GetLastError() == ERROR_INVALID_LEVEL) && (level == 2)) continue;
807
808         /* use only a short test, when we test with an invalid level */
809         if(!level || (level > 2)) {
810             ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
811                 (res && (pcReturned == 0)),
812                 "(%d) returned %d with %d and 0x%08x (expected '0' with "
813                 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
814                 level, res, GetLastError(), pcReturned);
815             continue;
816         }
817
818         ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
819             "(%d) returned %d with %d (expected '0' with "
820             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
821
822         buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
823         if (buffer == NULL) continue;
824
825         SetLastError(0xdeadbeef);
826         res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
827         ok(res, "(%d) returned %d with %d (expected '!=0')\n",
828                 level, res, GetLastError());
829
830         if (winetest_debug > 1) {
831             trace("dumping %d forms level %d\n", pcReturned, level);
832             pFI_1a = (PFORM_INFO_1A)buffer;
833             pFI_2a = (PFORM_INFO_2A)buffer;
834             for (i = 0; i < pcReturned; i++)
835             {
836                 /* first part is same in FORM_INFO_1 and FORM_INFO_2 */
837                 formtype = (pFI_1a->Flags <= FORMTYPE_MAX) ? formtypes[pFI_1a->Flags] : formtypes[3];
838                 trace("%u (%s): %.03fmm x %.03fmm, %s\n", i, pFI_1a->pName,
839                       (float)pFI_1a->Size.cx/1000, (float)pFI_1a->Size.cy/1000, formtype);
840
841                 if (level == 1) pFI_1a ++;
842                 else {
843                     /* output additional FORM_INFO_2 fields */
844                     trace("\tkeyword=%s strtype=%u muidll=%s resid=%u dispname=%s langid=%u\n",
845                           pFI_2a->pKeyword, pFI_2a->StringType, pFI_2a->pMuiDll,
846                           pFI_2a->dwResourceId, pFI_2a->pDisplayName, pFI_2a->wLangId);
847
848                     /* offset pointer pFI_1a by 1*sizeof(FORM_INFO_2A) Bytes */
849                     pFI_2a ++;
850                     pFI_1a = (PFORM_INFO_1A)pFI_2a;
851                 }
852             }
853         }
854
855         SetLastError(0xdeadbeef);
856         res = EnumFormsA(hprinter, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
857         ok( res, "(%d) returned %d with %d (expected '!=0')\n",
858             level, res, GetLastError());
859
860         SetLastError(0xdeadbeef);
861         res = EnumFormsA(hprinter, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
862         ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
863             "(%d) returned %d with %d (expected '0' with "
864             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
865
866
867         SetLastError(0xdeadbeef);
868         res = EnumFormsA(hprinter, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
869         ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
870             "(%d) returned %d with %d (expected '0' with "
871             "ERROR_INVALID_USER_BUFFER)\n", level, res, GetLastError());
872
873
874         SetLastError(0xdeadbeef);
875         res = EnumFormsA(hprinter, level, buffer, cbBuf, NULL, &pcReturned);
876         ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
877             "(%d) returned %d with %d (expected '0' with "
878             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
879
880         SetLastError(0xdeadbeef);
881         res = EnumFormsA(hprinter, level, buffer, cbBuf, &pcbNeeded, NULL);
882         ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER) ,
883             "(%d) returned %d with %d (expected '0' with "
884             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
885
886         SetLastError(0xdeadbeef);
887         res = EnumFormsA(0, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
888         ok( !res && (GetLastError() == ERROR_INVALID_HANDLE) ,
889             "(%d) returned %d with %d (expected '0' with "
890             "ERROR_INVALID_HANDLE)\n", level, res, GetLastError());
891
892         HeapFree(GetProcessHeap(), 0, buffer);
893     } /* for(level ... */
894
895     ClosePrinter(hprinter);
896 }
897
898 /* ########################### */
899
900 static void test_EnumMonitors(void)
901 {
902     DWORD   res;
903     LPBYTE  buffer;
904     DWORD   cbBuf;
905     DWORD   pcbNeeded;
906     DWORD   pcReturned;
907     DWORD   level;
908
909     /* valid levels are 1 and 2 */
910     for(level = 0; level < 4; level++) {
911         cbBuf = MAGIC_DEAD;
912         pcReturned = MAGIC_DEAD;
913         SetLastError(MAGIC_DEAD);
914         res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
915
916         RETURN_ON_DEACTIVATED_SPOOLER(res)
917
918         /* not implemented yet in wine */
919         if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
920
921
922         /* use only a short test, when we test with an invalid level */
923         if(!level || (level > 2)) {
924             ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
925                 (res && (pcReturned == 0)),
926                 "(%d) returned %d with %d and 0x%08x (expected '0' with "
927                 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
928                 level, res, GetLastError(), pcReturned);
929             continue;
930         }        
931
932         /* Level 2 is not supported on win9x */
933         if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
934             skip("Level %d not supported\n", level);
935             continue;
936         }
937
938         ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
939             "(%d) returned %d with %d (expected '0' with "
940             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
941
942         if (!cbBuf) {
943             skip("no valid buffer size returned\n");
944             continue;
945         }
946
947         buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
948         if (buffer == NULL) continue;
949
950         SetLastError(MAGIC_DEAD);
951         pcbNeeded = MAGIC_DEAD;
952         res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
953         ok(res, "(%d) returned %d with %d (expected '!=0')\n",
954                 level, res, GetLastError());
955         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n",
956                 level, pcbNeeded, cbBuf);
957         /* We can validate the returned Data with the Registry here */
958
959
960         SetLastError(MAGIC_DEAD);
961         pcReturned = MAGIC_DEAD;
962         pcbNeeded = MAGIC_DEAD;
963         res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
964         ok(res, "(%d) returned %d with %d (expected '!=0')\n", level,
965                 res, GetLastError());
966         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
967                 pcbNeeded, cbBuf);
968
969         SetLastError(MAGIC_DEAD);
970         pcbNeeded = MAGIC_DEAD;
971         res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
972         ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
973             "(%d) returned %d with %d (expected '0' with "
974             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
975
976         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level,
977                 pcbNeeded, cbBuf);
978
979 /*
980       Do not add the next test:
981       w2k+:  RPC_X_NULL_REF_POINTER 
982       NT3.5: ERROR_INVALID_USER_BUFFER
983       win9x: crash in winspool.drv
984
985       res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
986 */
987
988         SetLastError(MAGIC_DEAD);
989         pcbNeeded = MAGIC_DEAD;
990         pcReturned = MAGIC_DEAD;
991         res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
992         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
993             "(%d) returned %d with %d (expected '!=0' or '0' with "
994             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
995
996         pcbNeeded = MAGIC_DEAD;
997         pcReturned = MAGIC_DEAD;
998         SetLastError(MAGIC_DEAD);
999         res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1000         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1001             "(%d) returned %d with %d (expected '!=0' or '0' with "
1002             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1003
1004         HeapFree(GetProcessHeap(), 0, buffer);
1005     } /* for(level ... */
1006 }
1007
1008 /* ########################### */
1009
1010 static void test_EnumPorts(void)
1011 {
1012     DWORD   res;
1013     DWORD   level;
1014     LPBYTE  buffer;
1015     DWORD   cbBuf;
1016     DWORD   pcbNeeded;
1017     DWORD   pcReturned;
1018
1019     /* valid levels are 1 and 2 */
1020     for(level = 0; level < 4; level++) {
1021
1022         cbBuf = 0xdeadbeef;
1023         pcReturned = 0xdeadbeef;
1024         SetLastError(0xdeadbeef);
1025         res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
1026         RETURN_ON_DEACTIVATED_SPOOLER(res)
1027
1028         /* use only a short test, when we test with an invalid level */
1029         if(!level || (level > 2)) {
1030             /* NT: ERROR_INVALID_LEVEL, 9x: success */
1031             ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1032                 (res && (pcReturned == 0)),
1033                 "(%d) returned %d with %d and 0x%08x (expected '0' with "
1034                 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1035                 level, res, GetLastError(), pcReturned);
1036             continue;
1037         }        
1038
1039         
1040         /* Level 2 is not supported on NT 3.x */
1041         if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1042             skip("Level %d not supported\n", level);
1043             continue;
1044         }
1045
1046         ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1047             "(%d) returned %d with %d (expected '0' with "
1048             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1049
1050         buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
1051         if (buffer == NULL) continue;
1052
1053         pcbNeeded = 0xdeadbeef;
1054         SetLastError(0xdeadbeef);
1055         res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1056         ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1057         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1058         /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
1059
1060         pcbNeeded = 0xdeadbeef;
1061         pcReturned = 0xdeadbeef;
1062         SetLastError(0xdeadbeef);
1063         res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1064         ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
1065         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1066
1067         pcbNeeded = 0xdeadbeef;
1068         SetLastError(0xdeadbeef);
1069         res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1070         ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1071             "(%d) returned %d with %d (expected '0' with "
1072             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
1073         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1074
1075         /*
1076           Do not add this test:
1077           res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1078           w2k+:  RPC_X_NULL_REF_POINTER 
1079           NT3.5: ERROR_INVALID_USER_BUFFER
1080           win9x: crash in winspool.drv
1081          */
1082
1083         SetLastError(0xdeadbeef);
1084         res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
1085         /* NT: RPC_X_NULL_REF_POINTER (1780),  9x: success */
1086         ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1087             ( res && (GetLastError() == ERROR_SUCCESS) ),
1088             "(%d) returned %d with %d (expected '0' with "
1089             "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1090             level, res, GetLastError());
1091
1092
1093         SetLastError(0xdeadbeef);
1094         res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1095         /* NT: RPC_X_NULL_REF_POINTER (1780),  9x: success */
1096         ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
1097             ( res && (GetLastError() == ERROR_SUCCESS) ),
1098             "(%d) returned %d with %d (expected '0' with "
1099             "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
1100             level, res, GetLastError());
1101
1102         HeapFree(GetProcessHeap(), 0, buffer);
1103     }
1104 }
1105
1106 /* ########################### */
1107
1108 static void test_EnumPrinterDrivers(void)
1109 {
1110     static char env_all[] = "all";
1111
1112     DWORD   res;
1113     LPBYTE  buffer;
1114     DWORD   cbBuf;
1115     DWORD   pcbNeeded;
1116     DWORD   pcReturned;
1117     DWORD   level;
1118
1119     /* 1-3 for w95/w98/NT4; 1-3+6 for me; 1-6 for w2k/xp/2003; 1-6+8 for vista */
1120     for(level = 0; level < 10; level++) {
1121         cbBuf = 0xdeadbeef;
1122         pcReturned = 0xdeadbeef;
1123         SetLastError(0xdeadbeef);
1124         res = EnumPrinterDriversA(NULL, NULL, level, NULL, 0, &cbBuf, &pcReturned);
1125         RETURN_ON_DEACTIVATED_SPOOLER(res)
1126
1127         /* use only a short test, when we test with an invalid level */
1128         if(!level || (level == 7) || (level > 8)) {
1129
1130             ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
1131                 (res && (pcReturned == 0)),
1132                 "(%d) got %u with %u and 0x%x "
1133                 "(expected '0' with ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
1134                 level, res, GetLastError(), pcReturned);
1135             continue;
1136         }
1137
1138         /* some level are not supported in all windows versions */
1139         if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
1140             skip("Level %d not supported\n", level);
1141             continue;
1142         }
1143
1144         ok( ((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) ||
1145             (res && (default_printer == NULL)),
1146             "(%u) got %u with %u for %s (expected '0' with "
1147             "ERROR_INSUFFICIENT_BUFFER or '!= 0' without a printer)\n",
1148             level, res, GetLastError(), default_printer);
1149
1150         if (!cbBuf) {
1151             skip("no valid buffer size returned\n");
1152             continue;
1153         }
1154
1155         buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1156         if (buffer == NULL) continue;
1157
1158         SetLastError(0xdeadbeef);
1159         pcbNeeded = 0xdeadbeef;
1160         res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
1161         ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1162         ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
1163
1164         /* validate the returned Data here */
1165         if (level > 1) {
1166             LPDRIVER_INFO_2A di = (LPDRIVER_INFO_2A) buffer;
1167
1168             ok( strrchr(di->pDriverPath, '\\') != NULL,
1169                 "(%u) got %s for %s (expected a full path)\n",
1170                 level, di->pDriverPath, di->pName);
1171
1172         }
1173
1174         SetLastError(0xdeadbeef);
1175         pcReturned = 0xdeadbeef;
1176         pcbNeeded = 0xdeadbeef;
1177         res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1178         ok(res, "(%u) got %u with %u (expected '!=0')\n", level, res, GetLastError());
1179         ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1180
1181         SetLastError(0xdeadbeef);
1182         pcbNeeded = 0xdeadbeef;
1183         res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1184         ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1185             "(%u) got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1186             level, res, GetLastError());
1187         ok(pcbNeeded == cbBuf, "(%u) returned %u (expected %u)\n", level, pcbNeeded, cbBuf);
1188
1189 /*
1190       Do not add the next test:
1191       NT: ERROR_INVALID_USER_BUFFER
1192       win9x: crash or 100% CPU
1193
1194       res = EnumPrinterDriversA(NULL, NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
1195 */
1196
1197         SetLastError(0xdeadbeef);
1198         pcbNeeded = 0xdeadbeef;
1199         pcReturned = 0xdeadbeef;
1200         res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, NULL, &pcReturned);
1201         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1202             "(%u) got %u with %u (expected '!=0' or '0' with "
1203             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1204
1205         pcbNeeded = 0xdeadbeef;
1206         pcReturned = 0xdeadbeef;
1207         SetLastError(0xdeadbeef);
1208         res = EnumPrinterDriversA(NULL, NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
1209         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
1210             "(%u) got %u with %u (expected '!=0' or '0' with "
1211             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
1212
1213         HeapFree(GetProcessHeap(), 0, buffer);
1214     } /* for(level ... */
1215
1216     pcbNeeded = 0;
1217     pcReturned = 0;
1218     SetLastError(0xdeadbeef);
1219     res = EnumPrinterDriversA(NULL, env_all, 1, NULL, 0, &pcbNeeded, &pcReturned);
1220     if (res)
1221     {
1222         skip("no printer drivers found\n");
1223         return;
1224     }
1225     if (GetLastError() == ERROR_INVALID_ENVIRONMENT)
1226     {
1227         win_skip("NT4 and below don't support the 'all' environment value\n");
1228         return;
1229     }
1230     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "unexpected error %u\n", GetLastError());
1231
1232     buffer = HeapAlloc(GetProcessHeap(), 0, pcbNeeded);
1233     res = EnumPrinterDriversA(NULL, env_all, 1, buffer, pcbNeeded, &pcbNeeded, &pcReturned);
1234     ok(res, "EnumPrinterDriversA failed %u\n", GetLastError());
1235
1236     HeapFree(GetProcessHeap(), 0, buffer);
1237 }
1238
1239 /* ########################### */
1240
1241 static void test_EnumPrintProcessors(void)
1242 {
1243     DWORD   res;
1244     LPBYTE  buffer;
1245     DWORD   cbBuf;
1246     DWORD   pcbNeeded;
1247     DWORD   pcReturned;
1248
1249
1250     cbBuf = 0xdeadbeef;
1251     pcReturned = 0xdeadbeef;
1252     SetLastError(0xdeadbeef);
1253     res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, 0, &cbBuf, &pcReturned);
1254     RETURN_ON_DEACTIVATED_SPOOLER(res)
1255
1256     if (res && !cbBuf) {
1257         skip("No Printprocessor installed\n");
1258         return;
1259     }
1260
1261     ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1262         "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1263         res, GetLastError());
1264
1265     buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf + 4);
1266     if (buffer == NULL)
1267         return;
1268
1269     SetLastError(0xdeadbeef);
1270     pcbNeeded = 0xdeadbeef;
1271     res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1272     ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1273     /* validate the returned Data here. */
1274
1275
1276     SetLastError(0xdeadbeef);
1277     pcReturned = 0xdeadbeef;
1278     pcbNeeded = 0xdeadbeef;
1279     res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
1280     ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1281
1282     SetLastError(0xdeadbeef);
1283     pcbNeeded = 0xdeadbeef;
1284     res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
1285     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1286         "got %u with %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1287         res, GetLastError());
1288
1289     /* only level 1 is valid */
1290     if (0) {
1291         /* both tests crash on win98se */
1292         SetLastError(0xdeadbeef);
1293         pcbNeeded = 0xdeadbeef;
1294         pcReturned = 0xdeadbeef;
1295         res = EnumPrintProcessorsA(NULL, NULL, 0, buffer, cbBuf, &pcbNeeded, &pcReturned);
1296         ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1297             "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1298             res, GetLastError());
1299
1300         SetLastError(0xdeadbeef);
1301         pcbNeeded = 0xdeadbeef;
1302         res = EnumPrintProcessorsA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded, &pcReturned);
1303         ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1304             "got %u with %u (expected '0' with ERROR_INVALID_LEVEL)\n",
1305             res, GetLastError());
1306     }
1307
1308     /* an empty environment is ignored */
1309     SetLastError(0xdeadbeef);
1310     pcbNeeded = 0xdeadbeef;
1311     res = EnumPrintProcessorsA(NULL, empty, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1312     ok(res, "got %u with %u (expected '!=0')\n", res, GetLastError());
1313
1314     /* the environment is checked */
1315     SetLastError(0xdeadbeef);
1316     pcbNeeded = 0xdeadbeef;
1317     res = EnumPrintProcessorsA(NULL, invalid_env, 1, buffer, cbBuf, &pcbNeeded, &pcReturned);
1318     /* NT5: ERROR_INVALID_ENVIRONMENT, 9x: ERROR_INVALID_PARAMETER */
1319     ok( !res && ((GetLastError() == ERROR_INVALID_ENVIRONMENT) ||
1320                  (GetLastError() == ERROR_INVALID_PARAMETER)),
1321         "got %u with %u (expected '0' with ERROR_INVALID_ENVIRONMENT or "
1322         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1323
1324
1325     /* failure-Codes for NULL */
1326     if (0) {
1327         /* this test crash on win98se */
1328         SetLastError(0xdeadbeef);
1329         pcbNeeded = 0xdeadbeef;
1330         pcReturned = 0xdeadbeef;
1331         res = EnumPrintProcessorsA(NULL, NULL, 1, NULL, cbBuf, &pcbNeeded, &pcReturned);
1332         ok( !res && (GetLastError() == ERROR_INVALID_USER_BUFFER) ,
1333             "got %u with %u (expected '0' with ERROR_INVALID_USER_BUFFER)\n",
1334             res, GetLastError());
1335     }
1336
1337     SetLastError(0xdeadbeef);
1338     pcbNeeded = 0xdeadbeef;
1339     pcReturned = 0xdeadbeef;
1340     res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, NULL, &pcReturned);
1341     /* the NULL is ignored on win9x */
1342     ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1343         "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1344         res, GetLastError());
1345
1346     pcbNeeded = 0xdeadbeef;
1347     pcReturned = 0xdeadbeef;
1348     SetLastError(0xdeadbeef);
1349     res = EnumPrintProcessorsA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded, NULL);
1350     /* the NULL is ignored on win9x */
1351     ok( broken(res) || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)),
1352         "got %u with %u (expected '0' with RPC_X_NULL_REF_POINTER)\n",
1353         res, GetLastError());
1354
1355     HeapFree(GetProcessHeap(), 0, buffer);
1356
1357 }
1358
1359 /* ########################### */
1360
1361 static void test_GetDefaultPrinter(void)
1362 {
1363     BOOL    retval;
1364     DWORD   exact = DEFAULT_PRINTER_SIZE;
1365     DWORD   size;
1366     char    buffer[DEFAULT_PRINTER_SIZE];
1367
1368     if (!pGetDefaultPrinterA)  return;
1369         /* only supported on NT like OSes starting with win2k */
1370
1371     SetLastError(ERROR_SUCCESS);
1372     retval = pGetDefaultPrinterA(buffer, &exact);
1373     if (!retval || !exact || !strlen(buffer) ||
1374         (ERROR_SUCCESS != GetLastError())) {
1375         if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
1376             (ERROR_INVALID_NAME == GetLastError()))
1377             trace("this test requires a default printer to be set\n");
1378         else {
1379                 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
1380                 "function returned %s\n"
1381                 "last error 0x%08x\n"
1382                 "returned buffer size 0x%08x\n"
1383                 "returned buffer content %s\n",
1384                 retval ? "true" : "false", GetLastError(), exact, buffer);
1385         }
1386         return;
1387     }
1388     SetLastError(ERROR_SUCCESS);
1389     retval = pGetDefaultPrinterA(NULL, NULL); 
1390     ok( !retval, "function result wrong! False expected\n");
1391     ok( ERROR_INVALID_PARAMETER == GetLastError(),
1392         "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1393         GetLastError());
1394
1395     SetLastError(ERROR_SUCCESS);
1396     retval = pGetDefaultPrinterA(buffer, NULL); 
1397     ok( !retval, "function result wrong! False expected\n");
1398     ok( ERROR_INVALID_PARAMETER == GetLastError(),
1399         "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08x\n",
1400         GetLastError());
1401
1402     SetLastError(ERROR_SUCCESS);
1403     size = 0;
1404     retval = pGetDefaultPrinterA(NULL, &size); 
1405     ok( !retval, "function result wrong! False expected\n");
1406     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1407         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1408         GetLastError());
1409     ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1410         exact, size);
1411
1412     SetLastError(ERROR_SUCCESS);
1413     size = DEFAULT_PRINTER_SIZE;
1414     retval = pGetDefaultPrinterA(NULL, &size); 
1415     ok( !retval, "function result wrong! False expected\n");
1416     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1417         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1418         GetLastError());
1419     ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1420         exact, size);
1421
1422     size = 0;
1423     retval = pGetDefaultPrinterA(buffer, &size); 
1424     ok( !retval, "function result wrong! False expected\n");
1425     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1426         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08x\n",
1427         GetLastError());
1428     ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1429         exact, size);
1430
1431     size = exact;
1432     retval = pGetDefaultPrinterA(buffer, &size); 
1433     ok( retval, "function result wrong! True expected\n");
1434     ok( size == exact, "Parameter size wrong! %d expected got %d\n",
1435         exact, size);
1436 }
1437
1438 static void test_GetPrinterDriverDirectory(void)
1439 {
1440     LPBYTE      buffer = NULL;
1441     DWORD       cbBuf = 0, pcbNeeded = 0;
1442     BOOL        res;
1443
1444
1445     SetLastError(MAGIC_DEAD);
1446     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
1447     trace("first call returned 0x%04x, with %d: buffer size 0x%08x\n",
1448     res, GetLastError(), cbBuf);
1449
1450     RETURN_ON_DEACTIVATED_SPOOLER(res)
1451     ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1452         "returned %d with lasterror=%d (expected '0' with "
1453         "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
1454
1455     if (!cbBuf) {
1456         skip("no valid buffer size returned\n");
1457         return;
1458     }
1459
1460     buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
1461     if (buffer == NULL)  return ;
1462
1463     res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1464     ok( res, "expected result != 0, got %d\n", res);
1465     ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1466                             pcbNeeded, cbBuf);
1467
1468     res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1469     ok( res, "expected result != 0, got %d\n", res);
1470     ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1471                             pcbNeeded, cbBuf);
1472  
1473     SetLastError(MAGIC_DEAD);
1474     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1475     ok( !res , "expected result == 0, got %d\n", res);
1476     ok( cbBuf == pcbNeeded, "pcbNeeded set to %d instead of %d\n",
1477                             pcbNeeded, cbBuf);
1478     
1479     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
1480         "last error set to %d instead of ERROR_INSUFFICIENT_BUFFER\n",
1481         GetLastError());
1482
1483 /*
1484     Do not add the next test:
1485     XPsp2: crash in this app, when the spooler is not running 
1486     NT3.5: ERROR_INVALID_USER_BUFFER
1487     win9x: ERROR_INVALID_PARAMETER
1488
1489     pcbNeeded = MAGIC_DEAD;
1490     SetLastError(MAGIC_DEAD);
1491     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1492 */
1493
1494     SetLastError(MAGIC_DEAD);
1495     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1496     ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
1497          "expected either result == 0 and "
1498          "last error == RPC_X_NULL_REF_POINTER or result != 0 "
1499          "got result %d and last error == %d\n", res, GetLastError());
1500
1501     SetLastError(MAGIC_DEAD);
1502     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1503     ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1504         "returned %d with %d (expected '!=0' or '0' with "
1505         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1506  
1507  
1508     /* with a valid buffer, but level is too large */
1509     buffer[0] = '\0';
1510     SetLastError(MAGIC_DEAD);
1511     res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1512
1513     /* Level not checked in win9x and wine:*/
1514     if((res != FALSE) && buffer[0])
1515     {
1516         trace("Level '2' not checked '%s'\n", buffer);
1517     }
1518     else
1519     {
1520         ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1521         "returned %d with lasterror=%d (expected '0' with "
1522         "ERROR_INVALID_LEVEL)\n", res, GetLastError());
1523     }
1524
1525     /* printing environments are case insensitive */
1526     /* "Windows 4.0" is valid for win9x and NT */
1527     buffer[0] = '\0';
1528     SetLastError(MAGIC_DEAD);
1529     res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1, 
1530                                         buffer, cbBuf*2, &pcbNeeded);
1531
1532     if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1533         cbBuf = pcbNeeded;
1534         buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1535         if (buffer == NULL)  return ;
1536
1537         SetLastError(MAGIC_DEAD);
1538         res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1, 
1539                                         buffer, cbBuf*2, &pcbNeeded);
1540     }
1541
1542     ok(res && buffer[0], "returned %d with "
1543         "lasterror=%d and len=%d (expected '1' with 'len > 0')\n", 
1544         res, GetLastError(), lstrlenA((char *)buffer));
1545
1546     buffer[0] = '\0';
1547     SetLastError(MAGIC_DEAD);
1548     res = GetPrinterDriverDirectoryA(NULL, env_x86, 1, 
1549                                         buffer, cbBuf*2, &pcbNeeded);
1550
1551     if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
1552         cbBuf = pcbNeeded;
1553         buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
1554         if (buffer == NULL)  return ;
1555
1556         buffer[0] = '\0';
1557         SetLastError(MAGIC_DEAD);
1558         res = GetPrinterDriverDirectoryA(NULL, env_x86, 1, 
1559                                         buffer, cbBuf*2, &pcbNeeded);
1560     }
1561
1562     /* "Windows NT x86" is invalid for win9x */
1563     ok( (res && buffer[0]) ||
1564         (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)), 
1565         "returned %d with lasterror=%d and len=%d (expected '!= 0' with "
1566         "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
1567         res, GetLastError(), lstrlenA((char *)buffer));
1568
1569     /* A setup program (PDFCreator_0.8.0) use empty strings */
1570     SetLastError(MAGIC_DEAD);
1571     res = GetPrinterDriverDirectoryA(empty, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1572     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1573
1574     SetLastError(MAGIC_DEAD);
1575     res = GetPrinterDriverDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1576     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1577
1578     SetLastError(MAGIC_DEAD);
1579     res = GetPrinterDriverDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1580     ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError() );
1581
1582     HeapFree( GetProcessHeap(), 0, buffer);
1583 }
1584
1585 /* ##### */
1586
1587 static void test_GetPrintProcessorDirectory(void)
1588 {
1589     LPBYTE      buffer = NULL;
1590     DWORD       cbBuf = 0;
1591     DWORD       pcbNeeded = 0;
1592     BOOL        res;
1593
1594
1595     SetLastError(0xdeadbeef);
1596     res = GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbBuf);
1597     /* The deactivated Spooler is caught here on NT3.51 */
1598     RETURN_ON_DEACTIVATED_SPOOLER(res)
1599     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1600         "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1601         res, GetLastError());
1602
1603     buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf*2);
1604     if(buffer == NULL)  return;
1605
1606     buffer[0] = '\0';
1607     SetLastError(0xdeadbeef);
1608     res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
1609     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1610
1611     SetLastError(0xdeadbeef);
1612     buffer[0] = '\0';
1613     res = GetPrintProcessorDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1614     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1615  
1616     /* Buffer to small */
1617     buffer[0] = '\0';
1618     SetLastError(0xdeadbeef);
1619     res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
1620     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
1621         "returned %d with %d (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
1622         res, GetLastError());
1623
1624     if (0)
1625     {
1626     /* XPsp2: the program will crash here, when the spooler is not running  */
1627     /*        GetPrinterDriverDirectory has the same bug */
1628     pcbNeeded = 0;
1629     SetLastError(0xdeadbeef);
1630     res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
1631     }
1632
1633     buffer[0] = '\0';
1634     SetLastError(0xdeadbeef);
1635     res = GetPrintProcessorDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
1636     /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0  */
1637     ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1638         "returned %d with %d (expected '!= 0' or '0' with "
1639         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1640
1641
1642     buffer[0] = '\0';
1643     SetLastError(0xdeadbeef);
1644     res = GetPrintProcessorDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
1645     /* NT: RPC_X_NULL_REF_POINTER, 9x: res != 0  */
1646     ok( res || (GetLastError() == RPC_X_NULL_REF_POINTER),
1647         "returned %d with %d (expected '!= 0' or '0' with "
1648         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
1649
1650  
1651     /* with a valid buffer, but level is invalid */
1652     buffer[0] = '\0';
1653     SetLastError(0xdeadbeef);
1654     res = GetPrintProcessorDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
1655     if (res && buffer[0])
1656     {
1657         /* Level is ignored in win9x*/
1658         trace("invalid level (2) was ignored\n");
1659     }
1660     else
1661     {
1662         ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
1663             "returned %d with %d (expected '0' with ERROR_INVALID_LEVEL)\n",
1664             res, GetLastError());
1665     }
1666
1667     /* Empty environment is the same as the default environment */
1668     buffer[0] = '\0';
1669     SetLastError(0xdeadbeef);
1670     res = GetPrintProcessorDirectoryA(NULL, empty, 1, buffer, cbBuf*2, &pcbNeeded);
1671     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1672
1673     /* "Windows 4.0" is valid for win9x and NT */
1674     buffer[0] = '\0';
1675     SetLastError(0xdeadbeef);
1676     res = GetPrintProcessorDirectoryA(NULL, env_win9x_case, 1, buffer, cbBuf*2, &pcbNeeded);
1677     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1678
1679
1680     /* "Windows NT x86" is invalid for win9x */
1681     buffer[0] = '\0';
1682     SetLastError(0xdeadbeef);
1683     res = GetPrintProcessorDirectoryA(NULL, env_x86, 1, buffer, cbBuf*2, &pcbNeeded);
1684     ok( res || (GetLastError() == ERROR_INVALID_ENVIRONMENT), 
1685         "returned %d with %d (expected '!= 0' or '0' with "
1686         "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
1687
1688     /* invalid on all Systems */
1689     buffer[0] = '\0';
1690     SetLastError(0xdeadbeef);
1691     res = GetPrintProcessorDirectoryA(NULL, invalid_env, 1, buffer, cbBuf*2, &pcbNeeded);
1692     ok( !res && (GetLastError() == ERROR_INVALID_ENVIRONMENT), 
1693         "returned %d with %d (expected '0' with ERROR_INVALID_ENVIRONMENT)\n",
1694         res, GetLastError());
1695
1696     /* Empty servername is the same as the local computer */
1697     buffer[0] = '\0';
1698     SetLastError(0xdeadbeef);
1699     res = GetPrintProcessorDirectoryA(empty, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1700     ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
1701
1702     /* invalid on all Systems */
1703     buffer[0] = '\0';
1704     SetLastError(0xdeadbeef);
1705     res = GetPrintProcessorDirectoryA(server_does_not_exist, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
1706     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER), 
1707         "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1708         res, GetLastError());
1709
1710     HeapFree(GetProcessHeap(), 0, buffer);
1711 }
1712
1713 /* ##### */
1714
1715 static void test_OpenPrinter(void)
1716 {
1717     PRINTER_DEFAULTSA   defaults;
1718     HANDLE              hprinter;
1719     DWORD               res;
1720
1721     SetLastError(MAGIC_DEAD);
1722     res = OpenPrinter(NULL, NULL, NULL);    
1723     /* The deactivated Spooler is caught here on NT3.51 */
1724     RETURN_ON_DEACTIVATED_SPOOLER(res)
1725     ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
1726         "returned %d with %d (expected '0' with ERROR_INVALID_PARAMETER)\n",
1727         res, GetLastError());
1728
1729
1730     /* Get Handle for the local Printserver (NT only)*/
1731     hprinter = (HANDLE) MAGIC_DEAD;
1732     SetLastError(MAGIC_DEAD);
1733     res = OpenPrinter(NULL, &hprinter, NULL);
1734     /* The deactivated Spooler is caught here on XPsp2 */
1735     RETURN_ON_DEACTIVATED_SPOOLER(res)
1736     ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1737         "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1738         res, GetLastError());
1739     if(res) {
1740         ClosePrinter(hprinter);
1741
1742         defaults.pDatatype=NULL;
1743         defaults.pDevMode=NULL;
1744
1745         defaults.DesiredAccess=0;
1746         hprinter = (HANDLE) MAGIC_DEAD;
1747         SetLastError(MAGIC_DEAD);
1748         res = OpenPrinter(NULL, &hprinter, &defaults);
1749         ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1750         if (res) ClosePrinter(hprinter);
1751
1752         defaults.DesiredAccess=-1;
1753         hprinter = (HANDLE) MAGIC_DEAD;
1754         SetLastError(MAGIC_DEAD);
1755         res = OpenPrinter(NULL, &hprinter, &defaults);
1756         todo_wine {
1757         ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
1758             "returned %d with %d (expected '0' with ERROR_ACCESS_DENIED)\n", 
1759             res, GetLastError());
1760         }
1761         if (res) ClosePrinter(hprinter);
1762
1763     }
1764
1765
1766     if (local_server != NULL) {
1767         hprinter = (HANDLE) 0xdeadbeef;
1768         SetLastError(0xdeadbeef);
1769         res = OpenPrinter(local_server, &hprinter, NULL);
1770         ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
1771             "returned %d with %d (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
1772             res, GetLastError());
1773         if(res) ClosePrinter(hprinter);
1774     }
1775
1776     /* Invalid Printername */
1777     hprinter = (HANDLE) MAGIC_DEAD;
1778     SetLastError(MAGIC_DEAD);
1779     res = OpenPrinter(illegal_name, &hprinter, NULL);
1780     ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) || 
1781                 (GetLastError() == ERROR_INVALID_PARAMETER) ),
1782        "returned %d with %d (expected '0' with: ERROR_INVALID_PARAMETER or"
1783        "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1784     if(res) ClosePrinter(hprinter);
1785
1786     hprinter = (HANDLE) MAGIC_DEAD;
1787     SetLastError(MAGIC_DEAD);
1788     res = OpenPrinter(empty, &hprinter, NULL);
1789     /* NT: ERROR_INVALID_PRINTER_NAME,  9x: ERROR_INVALID_PARAMETER */
1790     ok( !res &&
1791         ((GetLastError() == ERROR_INVALID_PRINTER_NAME) || 
1792         (GetLastError() == ERROR_INVALID_PARAMETER) ),
1793         "returned %d with %d (expected '0' with: ERROR_INVALID_PRINTER_NAME"
1794         " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1795     if(res) ClosePrinter(hprinter);
1796
1797
1798     /* Get Handle for the default Printer */
1799     if (default_printer)
1800     {
1801         hprinter = (HANDLE) MAGIC_DEAD;
1802         SetLastError(MAGIC_DEAD);
1803         res = OpenPrinter(default_printer, &hprinter, NULL);
1804         if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
1805         {
1806             trace("The Service 'Spooler' is required for '%s'\n", default_printer);
1807             return;
1808         }
1809         ok(res, "returned %d with %d (expected '!=0')\n", res, GetLastError());
1810         if(res) ClosePrinter(hprinter);
1811
1812         SetLastError(MAGIC_DEAD);
1813         res = OpenPrinter(default_printer, NULL, NULL);
1814         /* NT: FALSE with ERROR_INVALID_PARAMETER, 9x: TRUE */
1815         ok(res || (GetLastError() == ERROR_INVALID_PARAMETER),
1816             "returned %d with %d (expected '!=0' or '0' with "
1817             "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
1818
1819         defaults.pDatatype=NULL;
1820         defaults.pDevMode=NULL;
1821         defaults.DesiredAccess=0;
1822
1823         hprinter = (HANDLE) MAGIC_DEAD;
1824         SetLastError(MAGIC_DEAD);
1825         res = OpenPrinter(default_printer, &hprinter, &defaults);
1826         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1827             "returned %d with %d (expected '!=0' or '0' with "
1828             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1829         if(res) ClosePrinter(hprinter);
1830
1831         defaults.pDatatype = empty;
1832
1833         hprinter = (HANDLE) MAGIC_DEAD;
1834         SetLastError(MAGIC_DEAD);
1835         res = OpenPrinter(default_printer, &hprinter, &defaults);
1836         /* stop here, when a remote Printserver has no RPC-Service running */
1837         RETURN_ON_DEACTIVATED_SPOOLER(res)
1838         ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
1839                    (GetLastError() == ERROR_ACCESS_DENIED)),
1840             "returned %d with %d (expected '!=0' or '0' with: "
1841             "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
1842             res, GetLastError());
1843         if(res) ClosePrinter(hprinter);
1844
1845
1846         defaults.pDatatype=NULL;
1847         defaults.DesiredAccess=PRINTER_ACCESS_USE;
1848
1849         hprinter = (HANDLE) MAGIC_DEAD;
1850         SetLastError(MAGIC_DEAD);
1851         res = OpenPrinter(default_printer, &hprinter, &defaults);
1852         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1853             "returned %d with %d (expected '!=0' or '0' with "
1854             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1855         if(res) ClosePrinter(hprinter);
1856
1857
1858         defaults.DesiredAccess=PRINTER_ALL_ACCESS;
1859         hprinter = (HANDLE) MAGIC_DEAD;
1860         SetLastError(MAGIC_DEAD);
1861         res = OpenPrinter(default_printer, &hprinter, &defaults);
1862         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
1863             "returned %d with %d (expected '!=0' or '0' with "
1864             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
1865         if(res) ClosePrinter(hprinter);
1866     }
1867
1868 }
1869
1870
1871 static void test_SetDefaultPrinter(void)
1872 {
1873     DWORD   res;
1874     DWORD   size = DEFAULT_PRINTER_SIZE;
1875     CHAR    buffer[DEFAULT_PRINTER_SIZE];
1876     CHAR    org_value[DEFAULT_PRINTER_SIZE];
1877
1878
1879     if (!pSetDefaultPrinterA)  return;
1880         /* only supported on win2k and above */
1881
1882     /* backup the original value */
1883     org_value[0] = '\0';
1884     SetLastError(MAGIC_DEAD);
1885     res = GetProfileStringA("windows", "device", NULL, org_value, size);
1886
1887     /* first part: with the default Printer */
1888     SetLastError(MAGIC_DEAD);
1889     res = pSetDefaultPrinterA("no_printer_with_this_name");
1890
1891     RETURN_ON_DEACTIVATED_SPOOLER(res)
1892     /* spooler is running or we have no spooler here*/
1893
1894     /* Not implemented in wine */
1895     if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
1896         trace("SetDefaultPrinterA() not implemented yet.\n");
1897         return;
1898     }
1899
1900     ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1901         "returned %d with %d (expected '0' with "
1902         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1903
1904     WriteProfileStringA("windows", "device", org_value);
1905     SetLastError(MAGIC_DEAD);
1906     res = pSetDefaultPrinterA("");
1907     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1908         "returned %d with %d (expected '!=0' or '0' with "
1909         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1910
1911     WriteProfileStringA("windows", "device", org_value);
1912     SetLastError(MAGIC_DEAD);
1913     res = pSetDefaultPrinterA(NULL);
1914     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1915         "returned %d with %d (expected '!=0' or '0' with "
1916         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1917
1918     WriteProfileStringA("windows", "device", org_value);
1919     SetLastError(MAGIC_DEAD);
1920     res = pSetDefaultPrinterA(default_printer);
1921     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1922         "returned %d with %d (expected '!=0' or '0' with "
1923         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1924
1925
1926     /* second part: always without a default Printer */
1927     WriteProfileStringA("windows", "device", NULL);    
1928     SetLastError(MAGIC_DEAD);
1929     res = pSetDefaultPrinterA("no_printer_with_this_name");
1930
1931     ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
1932         "returned %d with %d (expected '0' with "
1933         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1934
1935     WriteProfileStringA("windows", "device", NULL);    
1936     SetLastError(MAGIC_DEAD);
1937     res = pSetDefaultPrinterA("");
1938     /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1939     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1940          "returned %d with %d (expected '!=0' or '0' with "
1941          "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1942
1943     WriteProfileStringA("windows", "device", NULL);    
1944     SetLastError(MAGIC_DEAD);
1945     res = pSetDefaultPrinterA(NULL);
1946     /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
1947     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1948         "returned %d with %d (expected '!=0' or '0' with "
1949         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1950
1951     WriteProfileStringA("windows", "device", NULL);    
1952     SetLastError(MAGIC_DEAD);
1953     res = pSetDefaultPrinterA(default_printer);
1954     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
1955         "returned %d with %d (expected '!=0' or '0' with "
1956         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
1957
1958     /* restore the original value */
1959     res = pSetDefaultPrinterA(default_printer);          /* the nice way */
1960     WriteProfileStringA("windows", "device", org_value); /* the old way */
1961
1962     buffer[0] = '\0';
1963     SetLastError(MAGIC_DEAD);
1964     res = GetProfileStringA("windows", "device", NULL, buffer, size);
1965     ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
1966
1967 }
1968
1969 /* ########################### */
1970
1971 static void test_XcvDataW_MonitorUI(void)
1972 {
1973     DWORD   res;
1974     HANDLE  hXcv;
1975     BYTE    buffer[MAX_PATH + 4];
1976     DWORD   needed;
1977     DWORD   status;
1978     DWORD   len;
1979     PRINTER_DEFAULTSA pd;
1980
1981     /* api is not present before w2k */
1982     if (pXcvDataW == NULL) return;
1983
1984     pd.pDatatype = NULL;
1985     pd.pDevMode  = NULL;
1986     pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
1987
1988     hXcv = NULL;
1989     SetLastError(0xdeadbeef);
1990     res = OpenPrinter(xcv_localport, &hXcv, &pd);
1991     RETURN_ON_DEACTIVATED_SPOOLER(res)
1992     RETURN_ON_ACCESS_DENIED(res)
1993
1994     ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
1995     if (!res) return;
1996
1997     /* ask for needed size */
1998     needed = (DWORD) 0xdeadbeef;
1999     status = (DWORD) 0xdeadbeef;
2000     SetLastError(0xdeadbeef);
2001     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed, &status);
2002     ok( res && (status == ERROR_INSUFFICIENT_BUFFER) && (needed <= MAX_PATH),
2003         "returned %d with %u and %u for status %u (expected '!= 0' and "
2004         "'<= MAX_PATH' for status ERROR_INSUFFICIENT_BUFFER)\n",
2005         res, GetLastError(), needed, status);
2006
2007     if (needed > MAX_PATH) {
2008         ClosePrinter(hXcv);
2009         skip("buffer overflow (%u)\n", needed);
2010         return;
2011     }
2012     len = needed;       /* Size is in bytes */
2013
2014     /* the command is required */
2015     needed = (DWORD) 0xdeadbeef;
2016     status = (DWORD) 0xdeadbeef;
2017     SetLastError(0xdeadbeef);
2018     res = pXcvDataW(hXcv, emptyW, NULL, 0, NULL, 0, &needed, &status);
2019     ok( res && (status == ERROR_INVALID_PARAMETER),
2020         "returned %d with %u and %u for status %u (expected '!= 0' with "
2021         "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2022
2023     needed = (DWORD) 0xdeadbeef;
2024     status = (DWORD) 0xdeadbeef;
2025     SetLastError(0xdeadbeef);
2026     res = pXcvDataW(hXcv, NULL, NULL, 0, buffer, MAX_PATH, &needed, &status);
2027     ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2028         "returned %d with %u and %u for status %u (expected '0' with "
2029         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2030
2031     /* "PDWORD needed" is checked before RPC-Errors */
2032     needed = (DWORD) 0xdeadbeef;
2033     status = (DWORD) 0xdeadbeef;
2034     SetLastError(0xdeadbeef);
2035     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, NULL, &status);
2036     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2037         "returned %d with %u and %u for status %u (expected '0' with "
2038         "ERROR_INVALID_PARAMETER)\n", res, GetLastError(), needed, status);
2039
2040     needed = (DWORD) 0xdeadbeef;
2041     status = (DWORD) 0xdeadbeef;
2042     SetLastError(0xdeadbeef);
2043     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, NULL, len, &needed, &status);
2044     ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2045         "returned %d with %u and %u for status %u (expected '0' with "
2046         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2047
2048     needed = (DWORD) 0xdeadbeef;
2049     status = (DWORD) 0xdeadbeef;
2050     SetLastError(0xdeadbeef);
2051     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, NULL);
2052     ok( !res && (GetLastError() == RPC_X_NULL_REF_POINTER),
2053         "returned %d with %u and %u for status %u (expected '0' with "
2054         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError(), needed, status);
2055
2056     /* off by one: larger  */
2057     needed = (DWORD) 0xdeadbeef;
2058     status = (DWORD) 0xdeadbeef;
2059     SetLastError(0xdeadbeef);
2060     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len+1, &needed, &status);
2061     ok( res && (status == ERROR_SUCCESS),
2062         "returned %d with %u and %u for status %u (expected '!= 0' for status "
2063         "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2064
2065     /* off by one: smaller */
2066     /* the buffer is not modified for NT4, w2k, XP */
2067     needed = (DWORD) 0xdeadbeef;
2068     status = (DWORD) 0xdeadbeef;
2069     SetLastError(0xdeadbeef);
2070     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len-1, &needed, &status);
2071     ok( res && (status == ERROR_INSUFFICIENT_BUFFER),
2072         "returned %d with %u and %u for status %u (expected '!= 0' for status "
2073         "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError(), needed, status);
2074
2075
2076     /* Normal use. The DLL-Name without a Path is returned */
2077     memset(buffer, 0, len);
2078     needed = (DWORD) 0xdeadbeef;
2079     status = (DWORD) 0xdeadbeef;
2080     SetLastError(0xdeadbeef);
2081     res = pXcvDataW(hXcv, cmd_MonitorUIW, NULL, 0, buffer, len, &needed, &status);
2082     ok( res && (status == ERROR_SUCCESS),
2083         "returned %d with %u and %u for status %u (expected '!= 0' for status "
2084         "ERROR_SUCCESS)\n", res, GetLastError(), needed, status);
2085
2086     ClosePrinter(hXcv);
2087 }
2088
2089 /* ########################### */
2090
2091 static void test_XcvDataW_PortIsValid(void)
2092 {
2093     DWORD   res;
2094     HANDLE  hXcv;
2095     DWORD   needed;
2096     DWORD   status;
2097     PRINTER_DEFAULTSA   pd;
2098
2099     /* api is not present before w2k */
2100     if (pXcvDataW == NULL) return;
2101
2102     pd.pDatatype = NULL;
2103     pd.pDevMode  = NULL;
2104     pd.DesiredAccess = SERVER_ACCESS_ADMINISTER;
2105
2106     hXcv = NULL;
2107     SetLastError(0xdeadbeef);
2108     res = OpenPrinter(xcv_localport, &hXcv, &pd);
2109
2110     RETURN_ON_DEACTIVATED_SPOOLER(res)
2111     RETURN_ON_ACCESS_DENIED(res)
2112
2113     ok(res, "returned %d with %u and handle %p (expected '!= 0')\n", res, GetLastError(), hXcv);
2114     if (!res) return;
2115
2116
2117     /* "PDWORD needed" is always required */
2118     needed = (DWORD) 0xdeadbeef;
2119     status = (DWORD) 0xdeadbeef;
2120     SetLastError(0xdeadbeef);
2121     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, NULL, &status);
2122     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
2123         "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_INVALID_PARAMETER)\n",
2124          res, GetLastError(), needed, status);
2125
2126     /* an empty name is not allowed */
2127     needed = (DWORD) 0xdeadbeef;
2128     status = (DWORD) 0xdeadbeef;
2129     SetLastError(0xdeadbeef);
2130     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) emptyW, sizeof(emptyW), NULL, 0, &needed, &status);
2131     ok( res && ((status == ERROR_FILE_NOT_FOUND) || (status == ERROR_PATH_NOT_FOUND)),
2132         "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2133         "ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND)\n",
2134         res, GetLastError(), needed, status);
2135
2136     /* a directory is not allowed */
2137     needed = (DWORD) 0xdeadbeef;
2138     status = (DWORD) 0xdeadbeef;
2139     SetLastError(0xdeadbeef);
2140     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempdirW, (lstrlenW(tempdirW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2141     /* XP: ERROR_PATH_NOT_FOUND, w2k ERROR_ACCESS_DENIED */
2142     ok( res && ((status == ERROR_PATH_NOT_FOUND) || (status == ERROR_ACCESS_DENIED)),
2143         "returned %d with %u and %u for status %u (expected '!= 0' for status: "
2144         "ERROR_PATH_NOT_FOUND or ERROR_ACCESS_DENIED)\n",
2145         res, GetLastError(), needed, status);
2146
2147     /* more valid well known Ports */
2148     needed = (DWORD) 0xdeadbeef;
2149     status = (DWORD) 0xdeadbeef;
2150     SetLastError(0xdeadbeef);
2151     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed, &status);
2152     ok( res && (status == ERROR_SUCCESS),
2153         "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2154         res, GetLastError(), needed, status);
2155
2156     needed = (DWORD) 0xdeadbeef;
2157     status = (DWORD) 0xdeadbeef;
2158     SetLastError(0xdeadbeef);
2159     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt2W, sizeof(portname_lpt2W), NULL, 0, &needed, &status);
2160     ok( res && (status == ERROR_SUCCESS),
2161         "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2162         res, GetLastError(), needed, status);
2163
2164     needed = (DWORD) 0xdeadbeef;
2165     status = (DWORD) 0xdeadbeef;
2166     SetLastError(0xdeadbeef);
2167     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com1W, sizeof(portname_com1W), NULL, 0, &needed, &status);
2168     ok( res && (status == ERROR_SUCCESS),
2169         "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2170         res, GetLastError(), needed, status);
2171
2172     needed = (DWORD) 0xdeadbeef;
2173     status = (DWORD) 0xdeadbeef;
2174     SetLastError(0xdeadbeef);
2175     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_com2W, sizeof(portname_com2W), NULL, 0, &needed, &status);
2176     ok( res && (status == ERROR_SUCCESS),
2177         "returned %d with %u and %u for status %u (expected '!= 0' for ERROR_SUCCESS)\n",
2178         res, GetLastError(), needed, status);
2179
2180     needed = (DWORD) 0xdeadbeef;
2181     status = (DWORD) 0xdeadbeef;
2182     SetLastError(0xdeadbeef);
2183     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) portname_fileW, sizeof(portname_fileW), NULL, 0, &needed, &status);
2184     ok( res && (status == ERROR_SUCCESS),
2185         "returned %d with %u and %u for status %u (expected '!= 0' with  ERROR_SUCCESS)\n",
2186         res, GetLastError(), needed, status);
2187
2188
2189     /* a normal, writable file is allowed */
2190     needed = (DWORD) 0xdeadbeef;
2191     status = (DWORD) 0xdeadbeef;
2192     SetLastError(0xdeadbeef);
2193     res = pXcvDataW(hXcv, cmd_PortIsValidW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, &needed, &status);
2194     ok( res && (status == ERROR_SUCCESS),
2195         "returned %d with %u and %u for status %u (expected '!= 0' with ERROR_SUCCESS)\n",
2196         res, GetLastError(), needed, status);
2197
2198     ClosePrinter(hXcv);
2199 }
2200
2201 /* ########################### */
2202
2203 static void test_GetPrinterDriver(void)
2204 {
2205     HANDLE hprn;
2206     BOOL ret;
2207     BYTE *buf;
2208     INT level;
2209     DWORD needed, filled;
2210
2211     if (!default_printer)
2212     {
2213         skip("There is no default printer installed\n");
2214         return;
2215     }
2216
2217     hprn = 0;
2218     ret = OpenPrinter(default_printer, &hprn, NULL);
2219     if (!ret)
2220     {
2221         skip("Unable to open the default printer (%s)\n", default_printer);
2222         return;
2223     }
2224     ok(hprn != 0, "wrong hprn %p\n", hprn);
2225
2226     for (level = -1; level <= 7; level++)
2227     {
2228         SetLastError(0xdeadbeef);
2229         needed = (DWORD)-1;
2230         ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
2231         ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
2232         if (level >= 1 && level <= 6)
2233         {
2234             /* Not all levels are supported on all Windows-Versions */
2235             if(GetLastError() == ERROR_INVALID_LEVEL) continue;
2236             ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %d\n", GetLastError());
2237             ok(needed > 0,"not expected needed buffer size %d\n", needed);
2238         }
2239         else
2240         {
2241             /* ERROR_OUTOFMEMORY found on win9x */
2242             ok( ((GetLastError() == ERROR_INVALID_LEVEL) ||
2243                  (GetLastError() == ERROR_OUTOFMEMORY)),
2244                 "%d: returned %d with %d (expected '0' with: "
2245                 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
2246                 level, ret, GetLastError());
2247             /* needed is modified in win9x. The modified Value depends on the
2248                default Printer. testing for "needed == (DWORD)-1" will fail */
2249             continue;
2250         }
2251
2252         buf = HeapAlloc(GetProcessHeap(), 0, needed);
2253
2254         SetLastError(0xdeadbeef);
2255         filled = -1;
2256         ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
2257         ok(ret, "level %d: GetPrinterDriver error %d\n", level, GetLastError());
2258         ok(needed == filled, "needed %d != filled %d\n", needed, filled);
2259
2260         if (level == 2)
2261         {
2262             DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
2263             DWORD calculated = sizeof(*di_2);
2264
2265             /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
2266                NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3  */
2267             ok( (di_2->cVersion <= 3) ||
2268                 (di_2->cVersion == 0x0400), "di_2->cVersion = %d\n", di_2->cVersion);
2269             ok(di_2->pName != NULL, "not expected NULL ptr\n");
2270             ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
2271             ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
2272             ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
2273             ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
2274
2275             trace("cVersion %d\n", di_2->cVersion);
2276             trace("pName %s\n", di_2->pName);
2277             calculated += strlen(di_2->pName) + 1;
2278             trace("pEnvironment %s\n", di_2->pEnvironment);
2279             calculated += strlen(di_2->pEnvironment) + 1;
2280             trace("pDriverPath %s\n", di_2->pDriverPath);
2281             calculated += strlen(di_2->pDriverPath) + 1;
2282             trace("pDataFile %s\n", di_2->pDataFile);
2283             calculated += strlen(di_2->pDataFile) + 1;
2284             trace("pConfigFile %s\n", di_2->pConfigFile);
2285             calculated += strlen(di_2->pConfigFile) + 1;
2286
2287             /* XP allocates memory for both ANSI and unicode names */
2288             ok(filled >= calculated,"calculated %d != filled %d\n", calculated, filled);
2289         }
2290
2291         HeapFree(GetProcessHeap(), 0, buf);
2292     }
2293
2294     SetLastError(0xdeadbeef);
2295     ret = ClosePrinter(hprn);
2296     ok(ret, "ClosePrinter error %d\n", GetLastError());
2297 }
2298
2299 static void test_DEVMODE(const DEVMODE *dm, LONG dmSize, LPCSTR exp_prn_name)
2300 {
2301     /* On NT3.51, some fields in DEVMODE are empty/zero
2302       (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
2303        We skip the Tests on this Platform */
2304     if (dm->dmSpecVersion || dm->dmDriverVersion || dm->dmDriverExtra) {
2305     /* The 0-terminated Printername can be larger (MAX_PATH) than CCHDEVICENAME */
2306         ok(!strncmp(exp_prn_name, (LPCSTR)dm->dmDeviceName, CCHDEVICENAME -1),
2307             "expected '%s', got '%s'\n", exp_prn_name, dm->dmDeviceName);
2308         ok(dm->dmSize + dm->dmDriverExtra == dmSize,
2309             "%u != %d\n", dm->dmSize + dm->dmDriverExtra, dmSize);
2310     }
2311     trace("dmFields %08x\n", dm->dmFields);
2312 }
2313
2314 static void test_DocumentProperties(void)
2315 {
2316     HANDLE hprn;
2317     LONG dm_size, ret;
2318     DEVMODE *dm;
2319
2320     if (!default_printer)
2321     {
2322         skip("There is no default printer installed\n");
2323         return;
2324     }
2325
2326     hprn = 0;
2327     ret = OpenPrinter(default_printer, &hprn, NULL);
2328     if (!ret)
2329     {
2330         skip("Unable to open the default printer (%s)\n", default_printer);
2331         return;
2332     }
2333     ok(hprn != 0, "wrong hprn %p\n", hprn);
2334
2335     dm_size = DocumentProperties(0, hprn, NULL, NULL, NULL, 0);
2336     trace("DEVMODE required size %d\n", dm_size);
2337     ok(dm_size >= sizeof(DEVMODE), "unexpected DocumentProperties ret value %d\n", dm_size);
2338
2339     dm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dm_size);
2340
2341     ret = DocumentProperties(0, hprn, NULL, dm, dm, DM_OUT_BUFFER);
2342     ok(ret == IDOK, "DocumentProperties ret value %d != expected IDOK\n", ret);
2343
2344     test_DEVMODE(dm, dm_size, default_printer);
2345
2346     HeapFree(GetProcessHeap(), 0, dm);
2347
2348     SetLastError(0xdeadbeef);
2349     ret = ClosePrinter(hprn);
2350     ok(ret, "ClosePrinter error %d\n", GetLastError());
2351 }
2352
2353 static void test_EnumPrinters(void)
2354 {
2355     DWORD neededA, neededW, num;
2356     DWORD ret;
2357
2358     SetLastError(0xdeadbeef);
2359     neededA = -1;
2360     ret = EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededA, &num);
2361     RETURN_ON_DEACTIVATED_SPOOLER(ret)
2362     if (!ret)
2363     {
2364         /* We have 1 or more printers */
2365         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2366         ok(neededA > 0, "Expected neededA to show the number of needed bytes\n");
2367     }
2368     else
2369     {
2370         /* We don't have any printers defined */
2371         ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2372         ok(neededA == 0, "Expected neededA to be zero\n");
2373     }
2374     ok(num == 0, "num %d\n", num);
2375
2376     SetLastError(0xdeadbeef);
2377     neededW = -1;
2378     ret = EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &neededW, &num);
2379     /* EnumPrintersW is not supported on all platforms */
2380     if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
2381     {
2382         win_skip("EnumPrintersW is not implemented\n");
2383         return;
2384     }
2385
2386     if (!ret)
2387     {
2388         /* We have 1 or more printers */
2389         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "gle %d\n", GetLastError());
2390         ok(neededW > 0, "Expected neededW to show the number of needed bytes\n");
2391     }
2392     else
2393     {
2394         /* We don't have any printers defined */
2395         ok(GetLastError() == S_OK, "gle %d\n", GetLastError());
2396         ok(neededW == 0, "Expected neededW to be zero\n");
2397     }
2398     ok(num == 0, "num %d\n", num);
2399
2400     /* Outlook2003 relies on the buffer size returned by EnumPrintersA being big enough
2401        to hold the buffer returned by EnumPrintersW */
2402     ok(neededA == neededW, "neededA %d neededW %d\n", neededA, neededW);
2403 }
2404
2405 static void test_DeviceCapabilities(void)
2406 {
2407     HANDLE hComdlg32;
2408     BOOL (WINAPI *pPrintDlgA)(PRINTDLGA *);
2409     PRINTDLGA prn_dlg;
2410     DEVMODE *dm;
2411     DEVNAMES *dn;
2412     const char *driver, *device, *port;
2413     WORD *papers;
2414     POINT *paper_size;
2415     POINTS ext;
2416     struct
2417     {
2418         char name[64];
2419     } *paper_name;
2420     INT n_papers, n_paper_size, n_paper_names, n_copies, ret;
2421     DWORD fields;
2422
2423     hComdlg32 = LoadLibrary("comdlg32.dll");
2424     assert(hComdlg32);
2425     pPrintDlgA = (void *)GetProcAddress(hComdlg32, "PrintDlgA");
2426     assert(pPrintDlgA);
2427
2428     memset(&prn_dlg, 0, sizeof(prn_dlg));
2429     prn_dlg.lStructSize = sizeof(prn_dlg);
2430     prn_dlg.Flags = PD_RETURNDEFAULT;
2431     ret = pPrintDlgA(&prn_dlg);
2432     FreeLibrary(hComdlg32);
2433     if (!ret)
2434     {
2435         skip("PrintDlg returned no default printer\n");
2436         return;
2437     }
2438     ok(prn_dlg.hDevMode != 0, "PrintDlg returned hDevMode == NULL\n");
2439     ok(prn_dlg.hDevNames != 0, "PrintDlg returned hDevNames == NULL\n");
2440
2441     dm = GlobalLock(prn_dlg.hDevMode);
2442     ok(dm != NULL, "GlobalLock(prn_dlg.hDevMode) failed\n");
2443     trace("dmDeviceName \"%s\"\n", dm->dmDeviceName);
2444
2445     dn = GlobalLock(prn_dlg.hDevNames);
2446     ok(dn != NULL, "GlobalLock(prn_dlg.hDevNames) failed\n");
2447     ok(dn->wDriverOffset, "expected not 0 wDriverOffset\n");
2448     ok(dn->wDeviceOffset, "expected not 0 wDeviceOffset\n");
2449     ok(dn->wOutputOffset, "expected not 0 wOutputOffset\n");
2450     ok(dn->wDefault == DN_DEFAULTPRN, "expected DN_DEFAULTPRN got %x\n", dn->wDefault);
2451     driver = (const char *)dn + dn->wDriverOffset;
2452     device = (const char *)dn + dn->wDeviceOffset;
2453     port = (const char *)dn + dn->wOutputOffset;
2454     trace("driver \"%s\" device \"%s\" port \"%s\"\n", driver, device, port);
2455
2456     test_DEVMODE(dm, dm->dmSize + dm->dmDriverExtra, device);
2457
2458     n_papers = DeviceCapabilities(device, port, DC_PAPERS, NULL, NULL);
2459     ok(n_papers > 0, "DeviceCapabilities DC_PAPERS failed\n");
2460     papers = HeapAlloc(GetProcessHeap(), 0, sizeof(*papers) * n_papers);
2461     ret = DeviceCapabilities(device, port, DC_PAPERS, (LPSTR)papers, NULL);
2462     ok(ret == n_papers, "expected %d, got %d\n", n_papers, ret);
2463 #if VERBOSE
2464     for (ret = 0; ret < n_papers; ret++)
2465         trace("papers[%d] = %d\n", ret, papers[ret]);
2466 #endif
2467     HeapFree(GetProcessHeap(), 0, papers);
2468
2469     n_paper_size = DeviceCapabilities(device, port, DC_PAPERSIZE, NULL, NULL);
2470     ok(n_paper_size > 0, "DeviceCapabilities DC_PAPERSIZE failed\n");
2471     ok(n_paper_size == n_papers, "n_paper_size %d != n_papers %d\n", n_paper_size, n_papers);
2472     paper_size = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_size) * n_paper_size);
2473     ret = DeviceCapabilities(device, port, DC_PAPERSIZE, (LPSTR)paper_size, NULL);
2474     ok(ret == n_paper_size, "expected %d, got %d\n", n_paper_size, ret);
2475 #if VERBOSE
2476     for (ret = 0; ret < n_paper_size; ret++)
2477         trace("paper_size[%d] = %d x %d\n", ret, paper_size[ret].x, paper_size[ret].y);
2478 #endif
2479     HeapFree(GetProcessHeap(), 0, paper_size);
2480
2481     n_paper_names = DeviceCapabilities(device, port, DC_PAPERNAMES, NULL, NULL);
2482     ok(n_paper_names > 0, "DeviceCapabilities DC_PAPERNAMES failed\n");
2483     ok(n_paper_names == n_papers, "n_paper_names %d != n_papers %d\n", n_paper_names, n_papers);
2484     paper_name = HeapAlloc(GetProcessHeap(), 0, sizeof(*paper_name) * n_paper_names);
2485     ret = DeviceCapabilities(device, port, DC_PAPERNAMES, (LPSTR)paper_name, NULL);
2486     ok(ret == n_paper_names, "expected %d, got %d\n", n_paper_names, ret);
2487 #if VERBOSE
2488     for (ret = 0; ret < n_paper_names; ret++)
2489         trace("paper_name[%u] = %s\n", ret, paper_name[ret].name);
2490 #endif
2491     HeapFree(GetProcessHeap(), 0, paper_name);
2492
2493     n_copies = DeviceCapabilities(device, port, DC_COPIES, NULL, dm);
2494     ok(n_copies > 0, "DeviceCapabilities DC_COPIES failed\n");
2495     trace("n_copies = %d\n", n_copies);
2496
2497     /* these capabilities not available on all printer drivers */
2498     if (0)
2499     {
2500         ret = DeviceCapabilities(device, port, DC_MAXEXTENT, NULL, NULL);
2501         ok(ret != -1, "DeviceCapabilities DC_MAXEXTENT failed\n");
2502         ext = MAKEPOINTS(ret);
2503         trace("max ext = %d x %d\n", ext.x, ext.y);
2504
2505         ret = DeviceCapabilities(device, port, DC_MINEXTENT, NULL, NULL);
2506         ok(ret != -1, "DeviceCapabilities DC_MINEXTENT failed\n");
2507         ext = MAKEPOINTS(ret);
2508         trace("min ext = %d x %d\n", ext.x, ext.y);
2509     }
2510
2511     fields = DeviceCapabilities(device, port, DC_FIELDS, NULL, NULL);
2512     ok(fields != (DWORD)-1, "DeviceCapabilities DC_FIELDS failed\n");
2513     todo_wine
2514     ok(fields == (dm->dmFields | DM_FORMNAME),
2515         "fields %x != (dm->dmFields | DM_FORMNAME) %x\n", fields, dm->dmFields);
2516
2517     GlobalUnlock(prn_dlg.hDevMode);
2518     GlobalFree(prn_dlg.hDevMode);
2519     GlobalUnlock(prn_dlg.hDevNames);
2520     GlobalFree(prn_dlg.hDevNames);
2521 }
2522
2523 START_TEST(info)
2524 {
2525     hwinspool = GetModuleHandleA("winspool.drv");
2526     pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
2527     pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
2528     pXcvDataW = (void *) GetProcAddress(hwinspool, "XcvDataW");
2529     pAddPortExA = (void *) GetProcAddress(hwinspool, "AddPortExA");
2530
2531     find_default_printer();
2532     find_local_server();
2533     find_tempfile();
2534
2535     test_AddMonitor();
2536     test_AddPort();
2537     test_AddPortEx();
2538     test_ConfigurePort();
2539     test_DeleteMonitor();
2540     test_DeletePort();
2541     test_DeviceCapabilities();
2542     test_DocumentProperties();
2543     test_EnumForms(NULL);
2544     if (default_printer) test_EnumForms(default_printer);
2545     test_EnumMonitors();
2546     test_EnumPorts();
2547     test_EnumPrinterDrivers();
2548     test_EnumPrinters();
2549     test_EnumPrintProcessors();
2550     test_GetDefaultPrinter();
2551     test_GetPrinterDriverDirectory();
2552     test_GetPrintProcessorDirectory();
2553     test_OpenPrinter();
2554     test_GetPrinterDriver();
2555     test_SetDefaultPrinter();
2556     test_XcvDataW_MonitorUI();
2557     test_XcvDataW_PortIsValid();
2558
2559     /* Cleanup our temporary file */
2560     DeleteFileA(tempfileA);
2561 }