winspool: Basic tests for DeleteMonitor.
[wine] / dlls / winspool / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winreg.h"
29 #include "winspool.h"
30
31 #define MAGIC_DEAD  0x00dead00
32 #define DEFAULT_PRINTER_SIZE 1000
33
34 static char env_x86[] = "Windows NT x86";
35 static char env_win9x_case[] = "windowS 4.0";
36 static char winetest_monitor[] = "winetest";
37
38 static HANDLE  hwinspool;
39 static FARPROC pGetDefaultPrinterA;
40 static FARPROC pSetDefaultPrinterA;
41
42 struct monitor_entry {
43     LPSTR  env;
44     LPSTR  dllname;
45 };
46
47 /* report common behavior only once */
48 static DWORD report_deactivated_spooler = 1;
49 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
50     if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
51     { \
52         if(report_deactivated_spooler > 0) { \
53             report_deactivated_spooler--; \
54             trace("The Service 'Spooler' is required for many test\n"); \
55         } \
56         return; \
57     }
58
59
60 static LPSTR find_default_printer(VOID)
61 {
62     static  LPSTR   default_printer = NULL;
63     static  char    buffer[DEFAULT_PRINTER_SIZE];
64     DWORD   needed;
65     DWORD   res;
66     LPSTR   ptr;
67
68     if ((default_printer == NULL) && (pGetDefaultPrinterA))
69     {
70         /* w2k and above */
71         needed = sizeof(buffer);
72         res = pGetDefaultPrinterA(buffer, &needed);
73         if(res)  default_printer = buffer;
74         trace("default_printer: '%s'\n", default_printer);
75     }
76     if (default_printer == NULL)
77     {
78         HKEY hwindows;
79         DWORD   type;
80         /* NT 3.x and above */
81         if (RegOpenKeyEx(HKEY_CURRENT_USER, 
82                         "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
83                         0, KEY_QUERY_VALUE, &hwindows) == NO_ERROR) {
84
85             needed = sizeof(buffer);
86             if (RegQueryValueEx(hwindows, "device", NULL, 
87                                 &type, (LPBYTE)buffer, &needed) == NO_ERROR) {
88
89                 ptr = strchr(buffer, ',');
90                 if (ptr) {
91                     ptr[0] = '\0';
92                     default_printer = buffer;
93                 }
94             }
95             RegCloseKey(hwindows);
96         }
97         trace("default_printer: '%s'\n", default_printer);
98     }
99     if (default_printer == NULL)
100     {
101         /* win9x */
102         needed = sizeof(buffer);
103         res = GetProfileStringA("windows", "device", "*", buffer, needed);
104         if(res) {
105             ptr = strchr(buffer, ',');
106             if (ptr) {
107                 ptr[0] = '\0';
108                 default_printer = buffer;
109             }
110         }
111         trace("default_printer: '%s'\n", default_printer);
112     }
113     return default_printer;
114 }
115
116
117 static struct monitor_entry * find_installed_monitor(void)
118 {
119     MONITOR_INFO_2A mi2a; 
120     static struct  monitor_entry * entry = NULL;
121     DWORD   res;
122     DWORD   num_tests;
123     DWORD   i = 0;
124
125     static struct monitor_entry  monitor_table[] = {
126         {env_win9x_case, "localspl.dll"},
127         {env_x86,        "localspl.dll"},
128         {env_win9x_case, "localmon.dll"},
129         {env_x86,        "localmon.dll"},
130         {env_win9x_case, "tcpmon.dll"},
131         {env_x86,        "tcpmon.dll"},
132         {env_win9x_case, "usbmon.dll"},
133         {env_x86,        "usbmon.dll"},
134         {env_win9x_case, "mspp32.dll"},
135         {env_x86,        "win32spl.dll"},
136         {env_x86,        "redmonnt.dll"},
137         {env_x86,        "redmon35.dll"},
138         {env_win9x_case, "redmon95.dll"},
139         {env_x86,        "pdfcmnnt.dll"},
140         {env_win9x_case, "pdfcmn95.dll"},
141     };
142
143     if (entry) return entry;
144
145     num_tests = (sizeof(monitor_table)/sizeof(struct monitor_entry));
146
147     SetLastError(MAGIC_DEAD);
148     res = DeleteMonitorA(NULL, NULL, NULL);
149     if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
150         trace("DeleteMonitorA() not implemented yet\n");
151         return NULL;
152     }
153
154     SetLastError(MAGIC_DEAD);
155     res = AddMonitorA(NULL, 0, NULL);
156     if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
157         trace("AddMonitorA() not implemented yet\n");
158         return NULL;
159     }
160
161     /* cleanup */
162     DeleteMonitorA(NULL, env_x86, winetest_monitor);
163     DeleteMonitorA(NULL, env_win9x_case, winetest_monitor);
164
165     /* find a usable monitor from the table */    
166     mi2a.pName = winetest_monitor;
167     while ((entry == NULL) && (i < num_tests)) {
168         entry = &monitor_table[i];
169         i++;
170         mi2a.pEnvironment = entry->env;
171         mi2a.pDLLName = entry->dllname;
172
173         if (AddMonitorA(NULL, 2, (LPBYTE) &mi2a)) {
174             /* we got one */
175             trace("using '%s', '%s'\n", entry->env, entry->dllname);
176             DeleteMonitorA(NULL, entry->env, winetest_monitor);
177         }
178         else
179         {
180             entry = NULL;
181         }
182     }
183     return entry;
184 }
185
186 /* ########################### */
187
188
189 static void test_AddMonitor(void)
190 {
191     MONITOR_INFO_2A mi2a; 
192     struct  monitor_entry * entry = NULL;
193     DWORD   res;
194
195     entry = find_installed_monitor();
196
197     SetLastError(MAGIC_DEAD);
198     res = AddMonitorA(NULL, 1, NULL);
199     ok(!res && (GetLastError() == ERROR_INVALID_LEVEL), 
200         "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
201         res, GetLastError());
202
203     SetLastError(MAGIC_DEAD);
204     res = AddMonitorA(NULL, 3, NULL);
205     ok(!res && (GetLastError() == ERROR_INVALID_LEVEL), 
206         "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
207         res, GetLastError());
208
209     SetLastError(MAGIC_DEAD);
210     res = AddMonitorA(NULL, 2, NULL);
211     /* NT: unchanged,  9x: ERROR_PRIVILEGE_NOT_HELD */
212     ok(!res &&
213         ((GetLastError() == MAGIC_DEAD) ||
214          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
215         "returned %ld with %ld (expected '0' with: MAGIC_DEAD or " \
216         "ERROR_PRIVILEGE_NOT_HELD)\n", res, GetLastError());
217
218     ZeroMemory(&mi2a, sizeof(MONITOR_INFO_2A));
219     SetLastError(MAGIC_DEAD);
220     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
221     RETURN_ON_DEACTIVATED_SPOOLER(res)
222
223     if (!res && (GetLastError() == ERROR_ACCESS_DENIED)) {
224         trace("skip tests (ACCESS_DENIED)\n");
225         return;
226     }
227
228     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_INVALID_ENVIRONMENT */
229     ok(!res && ((GetLastError() == ERROR_INVALID_PARAMETER) ||
230                 (GetLastError() == ERROR_INVALID_ENVIRONMENT)), 
231         "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
232         "ERROR_INVALID_ENVIRONMENT)\n", res, GetLastError());
233
234     if (!entry) {
235         trace("No usable Monitor found: Skip tests\n");
236         return;
237     }
238
239 #if 0
240     /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
241        HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
242        or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
243        is created on win9x and we do not want to hit this bug here. */
244
245     mi2a.pEnvironment = entry->env;
246     SetLastError(MAGIC_DEAD);
247     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
248     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
249 #endif
250
251     mi2a.pEnvironment = entry->env;
252     mi2a.pName = "";
253     SetLastError(MAGIC_DEAD);
254     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
255     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
256     ok( !res &&
257         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
258          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
259         "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
260         "ERROR_PRIVILEGE_NOT_HELD)\n",
261         res, GetLastError());
262
263     mi2a.pName = winetest_monitor;
264     SetLastError(MAGIC_DEAD);
265     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
266     /* NT: ERROR_INVALID_PARAMETER,  9x: ERROR_PRIVILEGE_NOT_HELD */
267     ok( !res &&
268         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
269          (GetLastError() == ERROR_PRIVILEGE_NOT_HELD)), 
270         "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
271         "ERROR_PRIVILEGE_NOT_HELD)\n",
272         res, GetLastError());
273
274     mi2a.pDLLName = "";
275     SetLastError(MAGIC_DEAD);
276     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
277     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
278         "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
279         res, GetLastError());
280
281
282     mi2a.pDLLName = "does_not_exists.dll";
283     SetLastError(MAGIC_DEAD);
284     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
285     /* NT: ERROR_MOD_NOT_FOUND,  9x: ERROR_INVALID_PARAMETER */
286     ok( !res &&
287         ((GetLastError() == ERROR_MOD_NOT_FOUND) ||
288         (GetLastError() == ERROR_INVALID_PARAMETER)),
289         "returned %ld with %ld (expected '0' with: ERROR_MOD_NOT_FOUND or " \
290         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
291
292     mi2a.pDLLName = "version.dll";
293     SetLastError(MAGIC_DEAD);
294     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
295     /* NT: ERROR_PROC_NOT_FOUND,  9x: ERROR_INVALID_PARAMETER */
296     todo_wine {
297     ok( !res &&
298         ((GetLastError() == ERROR_PROC_NOT_FOUND) ||
299         (GetLastError() == ERROR_INVALID_PARAMETER)),
300         "returned %ld with %ld (expected '0' with: ERROR_PROC_NOT_FOUND or " \
301         "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
302     if (res) DeleteMonitorA(NULL, entry->env, winetest_monitor); 
303     }
304
305    /* Test AddMonitor with real options */
306     mi2a.pDLLName = entry->dllname;
307     SetLastError(MAGIC_DEAD);
308     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
309     ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
310     
311     /* add a monitor twice */
312     SetLastError(MAGIC_DEAD);
313     res = AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
314     /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
315     ok( !res &&
316         ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED) ||
317         (GetLastError() == ERROR_ALREADY_EXISTS)), 
318         "returned %ld with %ld (expected '0' with: " \
319         "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
320         res, GetLastError());
321
322     DeleteMonitorA(NULL, entry->env, winetest_monitor); 
323     SetLastError(MAGIC_DEAD);
324     res = AddMonitorA("", 2, (LPBYTE) &mi2a);
325     ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
326
327     /* cleanup */
328     DeleteMonitorA(NULL, entry->env, winetest_monitor);
329
330 }
331
332 /* ########################### */
333
334 static void test_DeleteMonitor(void)
335 {
336     MONITOR_INFO_2A mi2a; 
337     struct  monitor_entry * entry = NULL;
338     DWORD   res;
339
340     entry = find_installed_monitor();
341
342     if (!entry) {
343         trace("No usable Monitor found: Skip tests\n");
344         return;
345     }
346
347     mi2a.pName = winetest_monitor;
348     mi2a.pEnvironment = entry->env;
349     mi2a.pDLLName = entry->dllname;
350
351     /* Testing DeleteMonitor with real options */
352     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
353
354     SetLastError(MAGIC_DEAD);
355     res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
356     ok(res, "returned %ld with %ld (expected '!= 0')\n", res, GetLastError());
357
358     /* Delete the Monitor twice */
359     SetLastError(MAGIC_DEAD);
360     res = DeleteMonitorA(NULL, entry->env, winetest_monitor);
361     /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
362     ok( !res &&
363         ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR) ||
364         (GetLastError() == ERROR_INVALID_PARAMETER)), 
365         "returned %ld with %ld (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR" \
366         " or ERROR_INVALID_PARAMETER)\n", res, GetLastError());
367
368     /* the environment */
369     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
370     SetLastError(MAGIC_DEAD);
371     res = DeleteMonitorA(NULL, NULL, winetest_monitor);
372     ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
373
374     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
375     SetLastError(MAGIC_DEAD);
376     res = DeleteMonitorA(NULL, "", winetest_monitor);
377     ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
378
379     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
380     SetLastError(MAGIC_DEAD);
381     res = DeleteMonitorA(NULL, "bad_env", winetest_monitor);
382     ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
383
384     /* the monitor-name */
385     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
386     SetLastError(MAGIC_DEAD);
387     res = DeleteMonitorA(NULL, entry->env, NULL);
388     /* NT: ERROR_INVALID_PARAMETER (87),  9x: ERROR_INVALID_NAME (123)*/
389     ok( !res &&
390         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
391         (GetLastError() == ERROR_INVALID_NAME)),
392         "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
393         "ERROR_INVALID_NAME)\n", res, GetLastError());
394
395     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
396     SetLastError(MAGIC_DEAD);
397     res = DeleteMonitorA(NULL, entry->env, "");
398     /* NT: ERROR_INVALID_PARAMETER (87),  9x: ERROR_INVALID_NAME (123)*/
399     ok( !res && 
400         ((GetLastError() == ERROR_INVALID_PARAMETER) ||
401         (GetLastError() == ERROR_INVALID_NAME)),
402         "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
403         "ERROR_INVALID_NAME)\n", res, GetLastError());
404
405     AddMonitorA(NULL, 2, (LPBYTE) &mi2a);
406     SetLastError(MAGIC_DEAD);
407     res = DeleteMonitorA("", entry->env, winetest_monitor);
408     ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
409
410     /* cleanup */
411     DeleteMonitorA(NULL, entry->env, winetest_monitor);
412 }
413
414
415 /* ########################### */
416
417 static void test_EnumMonitors(void)
418 {
419     DWORD   res;
420     LPBYTE  buffer;
421     DWORD   cbBuf;
422     DWORD   pcbNeeded;
423     DWORD   pcReturned;
424     DWORD   level;
425
426     /* valid levels are 1 and 2 */
427     for(level = 0; level < 4; level++) {
428         cbBuf = MAGIC_DEAD;
429         pcReturned = MAGIC_DEAD;
430         SetLastError(MAGIC_DEAD);
431         res = EnumMonitorsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
432
433         RETURN_ON_DEACTIVATED_SPOOLER(res)
434
435         /* not implemented yet in wine */
436         if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) continue;
437
438
439         /* use only a short test, when we test with an invalid level */
440         if(!level || (level > 2)) {
441             ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
442                 (res && (pcReturned == 0)),
443                 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
444                 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
445                 level, res, GetLastError(), pcReturned);
446             continue;
447         }        
448
449         /* Level 2 is not supported on win9x */
450         if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
451             trace("Level %ld not supported, skipping tests\n", level);
452             continue;
453         }
454
455         ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
456             "(%ld) returned %ld with %ld (expected '0' with " \
457             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
458
459         if (!cbBuf) {
460             trace("no valid buffer size returned, skipping tests\n");
461             continue;
462         }
463
464         buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
465         if (buffer == NULL) continue;
466
467         SetLastError(MAGIC_DEAD);
468         pcbNeeded = MAGIC_DEAD;
469         res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
470         ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n",
471                 level, res, GetLastError());
472         ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n",
473                 level, pcbNeeded, cbBuf);
474         /* We can validate the returned Data with the Registry here */
475
476
477         SetLastError(MAGIC_DEAD);
478         pcReturned = MAGIC_DEAD;
479         pcbNeeded = MAGIC_DEAD;
480         res = EnumMonitorsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
481         ok(res, "(%ld) returned %ld with %ld (expected '!=0')\n", level,
482                 res, GetLastError());
483         ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
484                 pcbNeeded, cbBuf);
485
486         SetLastError(MAGIC_DEAD);
487         pcbNeeded = MAGIC_DEAD;
488         res = EnumMonitorsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
489         ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
490             "(%ld) returned %ld with %ld (expected '0' with " \
491             "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
492
493         ok(pcbNeeded == cbBuf, "(%ld) returned %ld (expected %ld)\n", level,
494                 pcbNeeded, cbBuf);
495
496 /*
497       Do not add the next test:
498       w2k+:  RPC_X_NULL_REF_POINTER 
499       NT3.5: ERROR_INVALID_USER_BUFFER
500       win9x: crash in winspool.drv
501
502       res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
503 */
504
505         SetLastError(MAGIC_DEAD);
506         pcbNeeded = MAGIC_DEAD;
507         pcReturned = MAGIC_DEAD;
508         res = EnumMonitorsA(NULL, level, buffer, cbBuf, NULL, &pcReturned);
509         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
510             "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
511             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
512
513         pcbNeeded = MAGIC_DEAD;
514         pcReturned = MAGIC_DEAD;
515         SetLastError(MAGIC_DEAD);
516         res = EnumMonitorsA(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
517         ok( res || (!res && (GetLastError() == RPC_X_NULL_REF_POINTER)) ,
518             "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
519             "RPC_X_NULL_REF_POINTER)\n", level, res, GetLastError());
520
521         HeapFree(GetProcessHeap(), 0, buffer);
522     } /* for(level ... */
523 }
524
525
526 static void test_GetDefaultPrinter(void)
527 {
528     BOOL    retval;
529     DWORD   exact = DEFAULT_PRINTER_SIZE;
530     DWORD   size;
531     char    buffer[DEFAULT_PRINTER_SIZE];
532
533     if (!pGetDefaultPrinterA)  return;
534         /* only supported on NT like OSes starting with win2k */
535
536     SetLastError(ERROR_SUCCESS);
537     retval = pGetDefaultPrinterA(buffer, &exact);
538     if (!retval || !exact || !strlen(buffer) ||
539         (ERROR_SUCCESS != GetLastError())) {
540         if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
541             (ERROR_INVALID_NAME == GetLastError()))
542             trace("this test requires a default printer to be set\n");
543         else {
544                 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
545                 "function returned %s\n"
546                 "last error 0x%08lx\n"
547                 "returned buffer size 0x%08lx\n"
548                 "returned buffer content %s\n",
549                 retval ? "true" : "false", GetLastError(), exact, buffer);
550         }
551         return;
552     }
553     SetLastError(ERROR_SUCCESS);
554     retval = pGetDefaultPrinterA(NULL, NULL); 
555     ok( !retval, "function result wrong! False expected\n");
556     ok( ERROR_INVALID_PARAMETER == GetLastError(),
557         "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
558         GetLastError());
559
560     SetLastError(ERROR_SUCCESS);
561     retval = pGetDefaultPrinterA(buffer, NULL); 
562     ok( !retval, "function result wrong! False expected\n");
563     ok( ERROR_INVALID_PARAMETER == GetLastError(),
564         "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
565         GetLastError());
566
567     SetLastError(ERROR_SUCCESS);
568     size = 0;
569     retval = pGetDefaultPrinterA(NULL, &size); 
570     ok( !retval, "function result wrong! False expected\n");
571     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
572         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
573         GetLastError());
574     ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
575         exact, size);
576
577     SetLastError(ERROR_SUCCESS);
578     size = DEFAULT_PRINTER_SIZE;
579     retval = pGetDefaultPrinterA(NULL, &size); 
580     ok( !retval, "function result wrong! False expected\n");
581     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
582         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
583         GetLastError());
584     ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
585         exact, size);
586
587     size = 0;
588     retval = pGetDefaultPrinterA(buffer, &size); 
589     ok( !retval, "function result wrong! False expected\n");
590     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
591         "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
592         GetLastError());
593     ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
594         exact, size);
595
596     size = exact;
597     retval = pGetDefaultPrinterA(buffer, &size); 
598     ok( retval, "function result wrong! True expected\n");
599     ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
600         exact, size);
601 }
602
603 static void test_GetPrinterDriverDirectory(void)
604 {
605     LPBYTE buffer = NULL;
606     DWORD  cbBuf = 0, pcbNeeded = 0;
607     BOOL   res;
608
609     SetLastError(MAGIC_DEAD);
610     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
611     trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
612     res, GetLastError(), cbBuf);
613
614     RETURN_ON_DEACTIVATED_SPOOLER(res)
615     ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
616         "returned %d with lasterror=%ld (expected '0' with " \
617         "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
618
619     if (!cbBuf) {
620         trace("no valid buffer size returned, skipping tests\n");
621         return;
622     }
623
624     buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
625     if (buffer == NULL)  return ;
626
627     res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
628     ok( res, "expected result != 0, got %d\n", res);
629     ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
630                             pcbNeeded, cbBuf);
631
632     res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
633     ok( res, "expected result != 0, got %d\n", res);
634     ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
635                             pcbNeeded, cbBuf);
636  
637     SetLastError(MAGIC_DEAD);
638     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
639     ok( !res , "expected result == 0, got %d\n", res);
640     ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
641                             pcbNeeded, cbBuf);
642     
643     ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
644         "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
645         GetLastError());
646
647 /*
648     Do not add the next test:
649     XPsp2: crash in this app, when the spooler is not running 
650     NT3.5: ERROR_INVALID_USER_BUFFER
651     win9x: ERROR_INVALID_PARAMETER
652
653     pcbNeeded = MAGIC_DEAD;
654     SetLastError(MAGIC_DEAD);
655     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
656 */
657
658     SetLastError(MAGIC_DEAD);
659     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
660     ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
661          "expected either result == 0 and "
662          "last error == RPC_X_NULL_REF_POINTER or result != 0 "
663          "got result %d and last error == %ld\n", res, GetLastError());
664
665     SetLastError(MAGIC_DEAD);
666     res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
667     ok(res || (GetLastError() == RPC_X_NULL_REF_POINTER),
668         "returned %d with %ld (expected '!=0' or '0' with " \
669         "RPC_X_NULL_REF_POINTER)\n", res, GetLastError());
670  
671  
672     /* with a valid buffer, but level is too large */
673     buffer[0] = '\0';
674     SetLastError(MAGIC_DEAD);
675     res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
676
677     /* Level not checked in win9x and wine:*/
678     if((res != FALSE) && buffer[0])
679     {
680         trace("Level '2' not checked '%s'\n", buffer);
681     }
682     else
683     {
684         ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
685         "returned %d with lasterror=%ld (expected '0' with " \
686         "ERROR_INVALID_LEVEL)\n", res, GetLastError());
687     }
688
689     /* printing environments are case insensitive */
690     /* "Windows 4.0" is valid for win9x and NT */
691     buffer[0] = '\0';
692     SetLastError(MAGIC_DEAD);
693     res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1, 
694                                         buffer, cbBuf*2, &pcbNeeded);
695
696     if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
697         cbBuf = pcbNeeded;
698         buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
699         if (buffer == NULL)  return ;
700
701         SetLastError(MAGIC_DEAD);
702         res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1, 
703                                         buffer, cbBuf*2, &pcbNeeded);
704     }
705
706     ok(res && buffer[0], "returned %d with " \
707         "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n", 
708         res, GetLastError(), lstrlenA((char *)buffer));
709
710     buffer[0] = '\0';
711     SetLastError(MAGIC_DEAD);
712     res = GetPrinterDriverDirectoryA(NULL, env_x86, 1, 
713                                         buffer, cbBuf*2, &pcbNeeded);
714
715     if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
716         cbBuf = pcbNeeded;
717         buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
718         if (buffer == NULL)  return ;
719
720         buffer[0] = '\0';
721         SetLastError(MAGIC_DEAD);
722         res = GetPrinterDriverDirectoryA(NULL, env_x86, 1, 
723                                         buffer, cbBuf*2, &pcbNeeded);
724     }
725
726     /* "Windows NT x86" is invalid for win9x */
727     ok( (res && buffer[0]) ||
728         (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)), 
729         "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
730         "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
731         res, GetLastError(), lstrlenA((char *)buffer));
732
733     /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
734     SetLastError(MAGIC_DEAD);
735     res = GetPrinterDriverDirectoryA("", "", 1, buffer, cbBuf*2, &pcbNeeded);
736     ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
737
738     SetLastError(MAGIC_DEAD);
739     res = GetPrinterDriverDirectoryA(NULL, "", 1, buffer, cbBuf*2, &pcbNeeded);
740     ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
741
742     SetLastError(MAGIC_DEAD);
743     res = GetPrinterDriverDirectoryA("", NULL, 1, buffer, cbBuf*2, &pcbNeeded);
744     ok(res, "returned %d with %ld (expected '!=0')\n", res, GetLastError() );
745
746     HeapFree( GetProcessHeap(), 0, buffer);
747 }
748
749 static void test_OpenPrinter(void)
750 {
751     PRINTER_DEFAULTSA defaults;
752     HANDLE  hprinter;
753     LPSTR   default_printer;
754     DWORD   res;
755     DWORD   size;
756     CHAR    buffer[DEFAULT_PRINTER_SIZE];
757     LPSTR   ptr;
758
759     SetLastError(MAGIC_DEAD);
760     res = OpenPrinter(NULL, NULL, NULL);    
761     /* The deactivated Spooler is catched here on NT3.51 */
762     RETURN_ON_DEACTIVATED_SPOOLER(res)
763     ok(!res && (GetLastError() == ERROR_INVALID_PARAMETER),
764         "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
765         res, GetLastError());
766
767
768     /* Get Handle for the local Printserver (NT only)*/
769     hprinter = (HANDLE) MAGIC_DEAD;
770     SetLastError(MAGIC_DEAD);
771     res = OpenPrinter(NULL, &hprinter, NULL);
772     /* The deactivated Spooler is catched here on XPsp2 */
773     RETURN_ON_DEACTIVATED_SPOOLER(res)
774     ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
775         "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
776         res, GetLastError());
777     if(res) {
778         ClosePrinter(hprinter);
779
780         defaults.pDatatype=NULL;
781         defaults.pDevMode=NULL;
782
783         defaults.DesiredAccess=0;
784         hprinter = (HANDLE) MAGIC_DEAD;
785         SetLastError(MAGIC_DEAD);
786         res = OpenPrinter(NULL, &hprinter, &defaults);
787         ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
788         if (res) ClosePrinter(hprinter);
789
790         defaults.DesiredAccess=-1;
791         hprinter = (HANDLE) MAGIC_DEAD;
792         SetLastError(MAGIC_DEAD);
793         res = OpenPrinter(NULL, &hprinter, &defaults);
794         ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
795             "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n", 
796             res, GetLastError());
797         if (res) ClosePrinter(hprinter);
798
799     }
800
801     size = sizeof(buffer) - 3 ;
802     ptr = buffer;
803     ptr[0] = '\\';
804     ptr++;
805     ptr[0] = '\\';
806     ptr++;
807     if (GetComputerNameA(ptr, &size)) {
808
809         hprinter = (HANDLE) MAGIC_DEAD;
810         SetLastError(MAGIC_DEAD);
811         res = OpenPrinter(buffer, &hprinter, NULL);
812         todo_wine {
813         ok(res || (!res && GetLastError() == ERROR_INVALID_PARAMETER),
814             "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
815             res, GetLastError());
816         }
817         if(res) ClosePrinter(hprinter);
818     }
819
820     /* Invalid Printername */
821     hprinter = (HANDLE) MAGIC_DEAD;
822     SetLastError(MAGIC_DEAD);
823     res = OpenPrinter("illegal,name", &hprinter, NULL);
824     ok(!res && ((GetLastError() == ERROR_INVALID_PRINTER_NAME) || 
825                 (GetLastError() == ERROR_INVALID_PARAMETER) ),
826        "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or" \
827        "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
828     if(res) ClosePrinter(hprinter);
829
830
831     /* Get Handle for the default Printer */
832     if ((default_printer = find_default_printer()))
833     {
834         hprinter = (HANDLE) MAGIC_DEAD;
835         SetLastError(MAGIC_DEAD);
836         res = OpenPrinter(default_printer, &hprinter, NULL);
837         if((!res) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
838         {
839                 trace("The Service 'Spooler' is required for '%s'\n", default_printer);
840             return;
841         }
842         ok(res, "returned %ld with %ld (expected '!=0')\n", res, GetLastError());
843         if(res) ClosePrinter(hprinter);
844
845         defaults.pDatatype=NULL;
846         defaults.pDevMode=NULL;
847         defaults.DesiredAccess=0;
848
849         hprinter = (HANDLE) MAGIC_DEAD;
850         SetLastError(MAGIC_DEAD);
851         res = OpenPrinter(default_printer, &hprinter, &defaults);
852         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
853             "returned %ld with %ld (expected '!=0' or '0' with " \
854             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
855         if(res) ClosePrinter(hprinter);
856
857         defaults.pDatatype="";
858
859         hprinter = (HANDLE) MAGIC_DEAD;
860         SetLastError(MAGIC_DEAD);
861         res = OpenPrinter(default_printer, &hprinter, &defaults);
862         /* stop here, when a remote Printserver has no RPC-Service running */
863         RETURN_ON_DEACTIVATED_SPOOLER(res)
864         ok(res || ((GetLastError() == ERROR_INVALID_DATATYPE) ||
865                    (GetLastError() == ERROR_ACCESS_DENIED)),
866             "returned %ld with %ld (expected '!=0' or '0' with: " \
867             "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
868             res, GetLastError());
869         if(res) ClosePrinter(hprinter);
870
871
872         defaults.pDatatype=NULL;
873         defaults.DesiredAccess=PRINTER_ACCESS_USE;
874
875         hprinter = (HANDLE) MAGIC_DEAD;
876         SetLastError(MAGIC_DEAD);
877         res = OpenPrinter(default_printer, &hprinter, &defaults);
878         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
879             "returned %ld with %ld (expected '!=0' or '0' with " \
880             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
881         if(res) ClosePrinter(hprinter);
882
883
884         defaults.DesiredAccess=PRINTER_ALL_ACCESS;
885         hprinter = (HANDLE) MAGIC_DEAD;
886         SetLastError(MAGIC_DEAD);
887         res = OpenPrinter(default_printer, &hprinter, &defaults);
888         ok(res || GetLastError() == ERROR_ACCESS_DENIED,
889             "returned %ld with %ld (expected '!=0' or '0' with " \
890             "ERROR_ACCESS_DENIED)\n", res, GetLastError());
891         if(res) ClosePrinter(hprinter);
892     }
893
894 }
895
896
897 static void test_SetDefaultPrinter(void)
898 {
899     DWORD   res;
900     LPSTR   default_printer;
901     DWORD   size = DEFAULT_PRINTER_SIZE;
902     CHAR    buffer[DEFAULT_PRINTER_SIZE];
903     CHAR    org_value[DEFAULT_PRINTER_SIZE];
904
905
906     if (!pSetDefaultPrinterA)  return;
907         /* only supported on win2k and above */
908
909     default_printer = find_default_printer();
910
911     /* backup the original value */
912     org_value[0] = '\0';
913     SetLastError(MAGIC_DEAD);
914     res = GetProfileStringA("windows", "device", NULL, org_value, size);
915
916     /* first part: with the default Printer */
917     SetLastError(MAGIC_DEAD);
918     res = pSetDefaultPrinterA("no_printer_with_this_name");
919
920     RETURN_ON_DEACTIVATED_SPOOLER(res)
921     /* spooler is running or we have no spooler here*/
922
923     /* Not implemented in wine */
924     if (!res && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) {
925         trace("SetDefaultPrinterA() not implemented yet.\n");
926         return;
927     }
928
929     ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
930         "returned %ld with %ld (expected '0' with " \
931         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
932
933     WriteProfileStringA("windows", "device", org_value);
934     SetLastError(MAGIC_DEAD);
935     res = pSetDefaultPrinterA("");
936     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
937         "returned %ld with %ld (expected '!=0' or '0' with " \
938         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
939
940     WriteProfileStringA("windows", "device", org_value);
941     SetLastError(MAGIC_DEAD);
942     res = pSetDefaultPrinterA(NULL);
943     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
944         "returned %ld with %ld (expected '!=0' or '0' with " \
945         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
946
947     WriteProfileStringA("windows", "device", org_value);
948     SetLastError(MAGIC_DEAD);
949     res = pSetDefaultPrinterA(default_printer);
950     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
951         "returned %ld with %ld (expected '!=0' or '0' with " \
952         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
953
954
955     /* second part: always without a default Printer */
956     WriteProfileStringA("windows", "device", NULL);    
957     SetLastError(MAGIC_DEAD);
958     res = pSetDefaultPrinterA("no_printer_with_this_name");
959
960     ok(!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME),
961         "returned %ld with %ld (expected '0' with " \
962         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
963
964     WriteProfileStringA("windows", "device", NULL);    
965     SetLastError(MAGIC_DEAD);
966     res = pSetDefaultPrinterA("");
967     /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
968     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
969          "returned %ld with %ld (expected '!=0' or '0' with " \
970          "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
971
972     WriteProfileStringA("windows", "device", NULL);    
973     SetLastError(MAGIC_DEAD);
974     res = pSetDefaultPrinterA(NULL);
975     /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
976     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
977         "returned %ld with %ld (expected '!=0' or '0' with " \
978         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
979
980     WriteProfileStringA("windows", "device", NULL);    
981     SetLastError(MAGIC_DEAD);
982     res = pSetDefaultPrinterA(default_printer);
983     ok(res || (!res && (GetLastError() == ERROR_INVALID_PRINTER_NAME)),
984         "returned %ld with %ld (expected '!=0' or '0' with " \
985         "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
986
987     /* restore the original value */
988     res = pSetDefaultPrinterA(default_printer);          /* the nice way */
989     WriteProfileStringA("windows", "device", org_value); /* the old way */
990
991     buffer[0] = '\0';
992     SetLastError(MAGIC_DEAD);
993     res = GetProfileStringA("windows", "device", NULL, buffer, size);
994     ok(!lstrcmpA(org_value, buffer), "'%s' (expected '%s')\n", buffer, org_value);
995
996 }
997
998 static void test_GetPrinterDriver(void)
999 {
1000     LPSTR default_printer;
1001     HANDLE hprn;
1002     BOOL ret;
1003     BYTE *buf;
1004     INT level;
1005     DWORD needed, filled;
1006
1007     default_printer = find_default_printer();
1008     if (!default_printer)
1009     {
1010         trace("There is no default printer installed, skiping the test\n");
1011         return;
1012     }
1013
1014     hprn = 0;
1015     ret = OpenPrinter(default_printer, &hprn, NULL);
1016     if (!ret)
1017     {
1018         trace("There is no printers installed, skiping the test\n");
1019         return;
1020     }
1021     ok(hprn != 0, "wrong hprn %p\n", hprn);
1022
1023     for (level = -1; level <= 7; level++)
1024     {
1025         SetLastError(0xdeadbeef);
1026         needed = (DWORD)-1;
1027         ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
1028         ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
1029         if (level >= 1 && level <= 6)
1030         {
1031             ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
1032             ok(needed > 0,"not expected needed buffer size %ld\n", needed);
1033         }
1034         else
1035         {
1036             ok(GetLastError() == ERROR_INVALID_LEVEL, "wrong error %ld\n", GetLastError());
1037             ok(needed == (DWORD)-1,"not expected needed buffer size %ld\n", needed);
1038             continue;
1039         }
1040
1041         buf = HeapAlloc(GetProcessHeap(), 0, needed);
1042
1043         SetLastError(0xdeadbeef);
1044         filled = -1;
1045         ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
1046         ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
1047         ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
1048
1049         if (level == 2)
1050         {
1051             DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
1052             DWORD calculated = sizeof(*di_2);
1053
1054             ok(di_2->cVersion >= 0 && di_2->cVersion <= 3, "di_2->cVersion = %ld\n", di_2->cVersion);
1055             ok(di_2->pName != NULL, "not expected NULL ptr\n");
1056             ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
1057             ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
1058             ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
1059             ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
1060
1061             trace("cVersion %ld\n", di_2->cVersion);
1062             trace("pName %s\n", di_2->pName);
1063             calculated += strlen(di_2->pName) + 1;
1064             trace("pEnvironment %s\n", di_2->pEnvironment);
1065             calculated += strlen(di_2->pEnvironment) + 1;
1066             trace("pDriverPath %s\n", di_2->pDriverPath);
1067             calculated += strlen(di_2->pDriverPath) + 1;
1068             trace("pDataFile %s\n", di_2->pDataFile);
1069             calculated += strlen(di_2->pDataFile) + 1;
1070             trace("pConfigFile %s\n", di_2->pConfigFile);
1071             calculated += strlen(di_2->pConfigFile) + 1;
1072
1073             /* XP allocates memory for both ANSI and unicode names */
1074             ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
1075         }
1076
1077         HeapFree(GetProcessHeap(), 0, buf);
1078     }
1079
1080     SetLastError(0xdeadbeef);
1081     ret = ClosePrinter(hprn);
1082     ok(ret, "ClosePrinter error %ld\n", GetLastError());
1083 }
1084
1085 START_TEST(info)
1086 {
1087     hwinspool = GetModuleHandleA("winspool.drv");
1088     pGetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "GetDefaultPrinterA");
1089     pSetDefaultPrinterA = (void *) GetProcAddress(hwinspool, "SetDefaultPrinterA");
1090
1091     find_default_printer();
1092
1093     test_AddMonitor();
1094     test_DeleteMonitor();
1095     test_EnumMonitors(); 
1096     test_GetDefaultPrinter();
1097     test_GetPrinterDriverDirectory();
1098     test_OpenPrinter();
1099     test_GetPrinterDriver();
1100     test_SetDefaultPrinter();
1101 }