2 * Copyright (C) 2003, 2004 Stefan Leichter
3 * Copyright (C) 2005, 2006 Detlef Riekenberg
4 * Copyright (C) 2006 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/test.h"
32 #define MAGIC_DEAD 0x00dead00
33 #define DEFAULT_PRINTER_SIZE 1000
35 static char env_x86
[] = "Windows NT x86";
36 static char env_win9x_case
[] = "windowS 4.0";
37 static char winetest_monitor
[] = "winetest";
39 static HANDLE hwinspool
;
40 static FARPROC pGetDefaultPrinterA
;
41 static FARPROC pSetDefaultPrinterA
;
43 struct monitor_entry
{
48 /* report common behavior only once */
49 static DWORD report_deactivated_spooler
= 1;
50 #define RETURN_ON_DEACTIVATED_SPOOLER(res) \
51 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) \
53 if(report_deactivated_spooler > 0) { \
54 report_deactivated_spooler--; \
55 trace("The Service 'Spooler' is required for many test\n"); \
61 static LPSTR
find_default_printer(VOID
)
63 static LPSTR default_printer
= NULL
;
64 static char buffer
[DEFAULT_PRINTER_SIZE
];
69 if ((default_printer
== NULL
) && (pGetDefaultPrinterA
))
72 needed
= sizeof(buffer
);
73 res
= pGetDefaultPrinterA(buffer
, &needed
);
74 if(res
) default_printer
= buffer
;
75 trace("default_printer: '%s'\n", default_printer
);
77 if (default_printer
== NULL
)
81 /* NT 3.x and above */
82 if (RegOpenKeyEx(HKEY_CURRENT_USER
,
83 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
84 0, KEY_QUERY_VALUE
, &hwindows
) == NO_ERROR
) {
86 needed
= sizeof(buffer
);
87 if (RegQueryValueEx(hwindows
, "device", NULL
,
88 &type
, (LPBYTE
)buffer
, &needed
) == NO_ERROR
) {
90 ptr
= strchr(buffer
, ',');
93 default_printer
= buffer
;
96 RegCloseKey(hwindows
);
98 trace("default_printer: '%s'\n", default_printer
);
100 if (default_printer
== NULL
)
103 needed
= sizeof(buffer
);
104 res
= GetProfileStringA("windows", "device", "*", buffer
, needed
);
106 ptr
= strchr(buffer
, ',');
109 default_printer
= buffer
;
112 trace("default_printer: '%s'\n", default_printer
);
114 return default_printer
;
118 static struct monitor_entry
* find_installed_monitor(void)
120 MONITOR_INFO_2A mi2a
;
121 static struct monitor_entry
* entry
= NULL
;
126 static struct monitor_entry monitor_table
[] = {
127 {env_win9x_case
, "localspl.dll"},
128 {env_x86
, "localspl.dll"},
129 {env_win9x_case
, "localmon.dll"},
130 {env_x86
, "localmon.dll"},
131 {env_win9x_case
, "tcpmon.dll"},
132 {env_x86
, "tcpmon.dll"},
133 {env_win9x_case
, "usbmon.dll"},
134 {env_x86
, "usbmon.dll"},
135 {env_win9x_case
, "mspp32.dll"},
136 {env_x86
, "win32spl.dll"},
137 {env_x86
, "redmonnt.dll"},
138 {env_x86
, "redmon35.dll"},
139 {env_win9x_case
, "redmon95.dll"},
140 {env_x86
, "pdfcmnnt.dll"},
141 {env_win9x_case
, "pdfcmn95.dll"},
144 if (entry
) return entry
;
146 num_tests
= (sizeof(monitor_table
)/sizeof(struct monitor_entry
));
148 SetLastError(MAGIC_DEAD
);
149 res
= DeleteMonitorA(NULL
, NULL
, NULL
);
150 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
151 trace("DeleteMonitorA() not implemented yet\n");
155 SetLastError(MAGIC_DEAD
);
156 res
= AddMonitorA(NULL
, 0, NULL
);
157 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
158 trace("AddMonitorA() not implemented yet\n");
163 DeleteMonitorA(NULL
, env_x86
, winetest_monitor
);
164 DeleteMonitorA(NULL
, env_win9x_case
, winetest_monitor
);
166 /* find a usable monitor from the table */
167 mi2a
.pName
= winetest_monitor
;
168 while ((entry
== NULL
) && (i
< num_tests
)) {
169 entry
= &monitor_table
[i
];
171 mi2a
.pEnvironment
= entry
->env
;
172 mi2a
.pDLLName
= entry
->dllname
;
174 if (AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
)) {
176 trace("using '%s', '%s'\n", entry
->env
, entry
->dllname
);
177 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
187 /* ########################### */
190 static void test_AddMonitor(void)
192 MONITOR_INFO_2A mi2a
;
193 struct monitor_entry
* entry
= NULL
;
196 entry
= find_installed_monitor();
198 SetLastError(MAGIC_DEAD
);
199 res
= AddMonitorA(NULL
, 1, NULL
);
200 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
201 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
202 res
, GetLastError());
204 SetLastError(MAGIC_DEAD
);
205 res
= AddMonitorA(NULL
, 3, NULL
);
206 ok(!res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
207 "returned %ld with %ld (expected '0' with ERROR_INVALID_LEVEL)\n",
208 res
, GetLastError());
210 SetLastError(MAGIC_DEAD
);
211 res
= AddMonitorA(NULL
, 2, NULL
);
212 /* NT: unchanged, 9x: ERROR_PRIVILEGE_NOT_HELD */
214 ((GetLastError() == MAGIC_DEAD
) ||
215 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
216 "returned %ld with %ld (expected '0' with: MAGIC_DEAD or " \
217 "ERROR_PRIVILEGE_NOT_HELD)\n", res
, GetLastError());
219 ZeroMemory(&mi2a
, sizeof(MONITOR_INFO_2A
));
220 SetLastError(MAGIC_DEAD
);
221 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
222 RETURN_ON_DEACTIVATED_SPOOLER(res
)
224 if (!res
&& (GetLastError() == ERROR_ACCESS_DENIED
)) {
225 trace("skip tests (ACCESS_DENIED)\n");
229 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_INVALID_ENVIRONMENT */
230 ok(!res
&& ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
231 (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
232 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
233 "ERROR_INVALID_ENVIRONMENT)\n", res
, GetLastError());
236 trace("No usable Monitor found: Skip tests\n");
241 /* The Test is deactivated, because when mi2a.pName is NULL, the subkey
242 HKLM\System\CurrentControlSet\Control\Print\Monitors\C:\WINDOWS\SYSTEM
243 or HKLM\System\CurrentControlSet\Control\Print\Monitors\ì
244 is created on win9x and we do not want to hit this bug here. */
246 mi2a
.pEnvironment
= entry
->env
;
247 SetLastError(MAGIC_DEAD
);
248 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
249 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
252 mi2a
.pEnvironment
= entry
->env
;
254 SetLastError(MAGIC_DEAD
);
255 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
256 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
258 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
259 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
260 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
261 "ERROR_PRIVILEGE_NOT_HELD)\n",
262 res
, GetLastError());
264 mi2a
.pName
= winetest_monitor
;
265 SetLastError(MAGIC_DEAD
);
266 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
267 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_PRIVILEGE_NOT_HELD */
269 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
270 (GetLastError() == ERROR_PRIVILEGE_NOT_HELD
)),
271 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
272 "ERROR_PRIVILEGE_NOT_HELD)\n",
273 res
, GetLastError());
276 SetLastError(MAGIC_DEAD
);
277 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
278 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
279 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
280 res
, GetLastError());
283 mi2a
.pDLLName
= "does_not_exists.dll";
284 SetLastError(MAGIC_DEAD
);
285 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
286 /* NT: ERROR_MOD_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
288 ((GetLastError() == ERROR_MOD_NOT_FOUND
) ||
289 (GetLastError() == ERROR_INVALID_PARAMETER
)),
290 "returned %ld with %ld (expected '0' with: ERROR_MOD_NOT_FOUND or " \
291 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
293 mi2a
.pDLLName
= "version.dll";
294 SetLastError(MAGIC_DEAD
);
295 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
296 /* NT: ERROR_PROC_NOT_FOUND, 9x: ERROR_INVALID_PARAMETER */
299 ((GetLastError() == ERROR_PROC_NOT_FOUND
) ||
300 (GetLastError() == ERROR_INVALID_PARAMETER
)),
301 "returned %ld with %ld (expected '0' with: ERROR_PROC_NOT_FOUND or " \
302 "ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
303 if (res
) DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
306 /* Test AddMonitor with real options */
307 mi2a
.pDLLName
= entry
->dllname
;
308 SetLastError(MAGIC_DEAD
);
309 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
310 ok(res
, "returned %ld with %ld (expected '!= 0')\n", res
, GetLastError());
312 /* add a monitor twice */
313 SetLastError(MAGIC_DEAD
);
314 res
= AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
315 /* NT: ERROR_PRINT_MONITOR_ALREADY_INSTALLED (3006), 9x: ERROR_ALREADY_EXISTS (183) */
317 ((GetLastError() == ERROR_PRINT_MONITOR_ALREADY_INSTALLED
) ||
318 (GetLastError() == ERROR_ALREADY_EXISTS
)),
319 "returned %ld with %ld (expected '0' with: " \
320 "ERROR_PRINT_MONITOR_ALREADY_INSTALLED or ERROR_ALREADY_EXISTS)\n",
321 res
, GetLastError());
323 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
324 SetLastError(MAGIC_DEAD
);
325 res
= AddMonitorA("", 2, (LPBYTE
) &mi2a
);
326 ok(res
, "returned %ld with %ld (expected '!= 0')\n", res
, GetLastError());
329 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
333 /* ########################### */
335 static void test_DeleteMonitor(void)
337 MONITOR_INFO_2A mi2a
;
338 struct monitor_entry
* entry
= NULL
;
341 entry
= find_installed_monitor();
344 trace("No usable Monitor found: Skip tests\n");
348 mi2a
.pName
= winetest_monitor
;
349 mi2a
.pEnvironment
= entry
->env
;
350 mi2a
.pDLLName
= entry
->dllname
;
352 /* Testing DeleteMonitor with real options */
353 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
355 SetLastError(MAGIC_DEAD
);
356 res
= DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
357 ok(res
, "returned %ld with %ld (expected '!= 0')\n", res
, GetLastError());
359 /* Delete the Monitor twice */
360 SetLastError(MAGIC_DEAD
);
361 res
= DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
362 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
364 ((GetLastError() == ERROR_UNKNOWN_PRINT_MONITOR
) ||
365 (GetLastError() == ERROR_INVALID_PARAMETER
)),
366 "returned %ld with %ld (expected '0' with: ERROR_UNKNOWN_PRINT_MONITOR" \
367 " or ERROR_INVALID_PARAMETER)\n", res
, GetLastError());
369 /* the environment */
370 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
371 SetLastError(MAGIC_DEAD
);
372 res
= DeleteMonitorA(NULL
, NULL
, winetest_monitor
);
373 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
375 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
376 SetLastError(MAGIC_DEAD
);
377 res
= DeleteMonitorA(NULL
, "", winetest_monitor
);
378 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
380 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
381 SetLastError(MAGIC_DEAD
);
382 res
= DeleteMonitorA(NULL
, "bad_env", winetest_monitor
);
383 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
385 /* the monitor-name */
386 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
387 SetLastError(MAGIC_DEAD
);
388 res
= DeleteMonitorA(NULL
, entry
->env
, NULL
);
389 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
391 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
392 (GetLastError() == ERROR_INVALID_NAME
)),
393 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
394 "ERROR_INVALID_NAME)\n", res
, GetLastError());
396 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
397 SetLastError(MAGIC_DEAD
);
398 res
= DeleteMonitorA(NULL
, entry
->env
, "");
399 /* NT: ERROR_INVALID_PARAMETER (87), 9x: ERROR_INVALID_NAME (123)*/
401 ((GetLastError() == ERROR_INVALID_PARAMETER
) ||
402 (GetLastError() == ERROR_INVALID_NAME
)),
403 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or " \
404 "ERROR_INVALID_NAME)\n", res
, GetLastError());
406 AddMonitorA(NULL
, 2, (LPBYTE
) &mi2a
);
407 SetLastError(MAGIC_DEAD
);
408 res
= DeleteMonitorA("", entry
->env
, winetest_monitor
);
409 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
412 DeleteMonitorA(NULL
, entry
->env
, winetest_monitor
);
416 /* ########################### */
418 static void test_EnumMonitors(void)
427 /* valid levels are 1 and 2 */
428 for(level
= 0; level
< 4; level
++) {
430 pcReturned
= MAGIC_DEAD
;
431 SetLastError(MAGIC_DEAD
);
432 res
= EnumMonitorsA(NULL
, level
, NULL
, 0, &cbBuf
, &pcReturned
);
434 RETURN_ON_DEACTIVATED_SPOOLER(res
)
436 /* not implemented yet in wine */
437 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) continue;
440 /* use only a short test, when we test with an invalid level */
441 if(!level
|| (level
> 2)) {
442 ok( (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) ||
443 (res
&& (pcReturned
== 0)),
444 "(%ld) returned %ld with %ld and 0x%08lx (expected '0' with " \
445 "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
446 level
, res
, GetLastError(), pcReturned
);
450 /* Level 2 is not supported on win9x */
451 if (!res
&& (GetLastError() == ERROR_INVALID_LEVEL
)) {
452 trace("Level %ld not supported, skipping tests\n", level
);
456 ok((!res
) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
457 "(%ld) returned %ld with %ld (expected '0' with " \
458 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
461 trace("no valid buffer size returned, skipping tests\n");
465 buffer
= HeapAlloc(GetProcessHeap(), 0, cbBuf
*2);
466 if (buffer
== NULL
) continue;
468 SetLastError(MAGIC_DEAD
);
469 pcbNeeded
= MAGIC_DEAD
;
470 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, &pcReturned
);
471 ok(res
, "(%ld) returned %ld with %ld (expected '!=0')\n",
472 level
, res
, GetLastError());
473 ok(pcbNeeded
== cbBuf
, "(%ld) returned %ld (expected %ld)\n",
474 level
, pcbNeeded
, cbBuf
);
475 /* We can validate the returned Data with the Registry here */
478 SetLastError(MAGIC_DEAD
);
479 pcReturned
= MAGIC_DEAD
;
480 pcbNeeded
= MAGIC_DEAD
;
481 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
+1, &pcbNeeded
, &pcReturned
);
482 ok(res
, "(%ld) returned %ld with %ld (expected '!=0')\n", level
,
483 res
, GetLastError());
484 ok(pcbNeeded
== cbBuf
, "(%ld) returned %ld (expected %ld)\n", level
,
487 SetLastError(MAGIC_DEAD
);
488 pcbNeeded
= MAGIC_DEAD
;
489 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
-1, &pcbNeeded
, &pcReturned
);
490 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
491 "(%ld) returned %ld with %ld (expected '0' with " \
492 "ERROR_INSUFFICIENT_BUFFER)\n", level
, res
, GetLastError());
494 ok(pcbNeeded
== cbBuf
, "(%ld) returned %ld (expected %ld)\n", level
,
498 Do not add the next test:
499 w2k+: RPC_X_NULL_REF_POINTER
500 NT3.5: ERROR_INVALID_USER_BUFFER
501 win9x: crash in winspool.drv
503 res = EnumMonitorsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
506 SetLastError(MAGIC_DEAD
);
507 pcbNeeded
= MAGIC_DEAD
;
508 pcReturned
= MAGIC_DEAD
;
509 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, NULL
, &pcReturned
);
510 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
511 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
512 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
514 pcbNeeded
= MAGIC_DEAD
;
515 pcReturned
= MAGIC_DEAD
;
516 SetLastError(MAGIC_DEAD
);
517 res
= EnumMonitorsA(NULL
, level
, buffer
, cbBuf
, &pcbNeeded
, NULL
);
518 ok( res
|| (!res
&& (GetLastError() == RPC_X_NULL_REF_POINTER
)) ,
519 "(%ld) returned %ld with %ld (expected '!=0' or '0' with "\
520 "RPC_X_NULL_REF_POINTER)\n", level
, res
, GetLastError());
522 HeapFree(GetProcessHeap(), 0, buffer
);
523 } /* for(level ... */
527 static void test_GetDefaultPrinter(void)
530 DWORD exact
= DEFAULT_PRINTER_SIZE
;
532 char buffer
[DEFAULT_PRINTER_SIZE
];
534 if (!pGetDefaultPrinterA
) return;
535 /* only supported on NT like OSes starting with win2k */
537 SetLastError(ERROR_SUCCESS
);
538 retval
= pGetDefaultPrinterA(buffer
, &exact
);
539 if (!retval
|| !exact
|| !strlen(buffer
) ||
540 (ERROR_SUCCESS
!= GetLastError())) {
541 if ((ERROR_FILE_NOT_FOUND
== GetLastError()) ||
542 (ERROR_INVALID_NAME
== GetLastError()))
543 trace("this test requires a default printer to be set\n");
545 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
546 "function returned %s\n"
547 "last error 0x%08lx\n"
548 "returned buffer size 0x%08lx\n"
549 "returned buffer content %s\n",
550 retval
? "true" : "false", GetLastError(), exact
, buffer
);
554 SetLastError(ERROR_SUCCESS
);
555 retval
= pGetDefaultPrinterA(NULL
, NULL
);
556 ok( !retval
, "function result wrong! False expected\n");
557 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
558 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
561 SetLastError(ERROR_SUCCESS
);
562 retval
= pGetDefaultPrinterA(buffer
, NULL
);
563 ok( !retval
, "function result wrong! False expected\n");
564 ok( ERROR_INVALID_PARAMETER
== GetLastError(),
565 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
568 SetLastError(ERROR_SUCCESS
);
570 retval
= pGetDefaultPrinterA(NULL
, &size
);
571 ok( !retval
, "function result wrong! False expected\n");
572 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
573 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
575 ok( size
== exact
, "Parameter size wrong! %ld expected got %ld\n",
578 SetLastError(ERROR_SUCCESS
);
579 size
= DEFAULT_PRINTER_SIZE
;
580 retval
= pGetDefaultPrinterA(NULL
, &size
);
581 ok( !retval
, "function result wrong! False expected\n");
582 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
583 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
585 ok( size
== exact
, "Parameter size wrong! %ld expected got %ld\n",
589 retval
= pGetDefaultPrinterA(buffer
, &size
);
590 ok( !retval
, "function result wrong! False expected\n");
591 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
592 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
594 ok( size
== exact
, "Parameter size wrong! %ld expected got %ld\n",
598 retval
= pGetDefaultPrinterA(buffer
, &size
);
599 ok( retval
, "function result wrong! True expected\n");
600 ok( size
== exact
, "Parameter size wrong! %ld expected got %ld\n",
604 static void test_GetPrinterDriverDirectory(void)
606 LPBYTE buffer
= NULL
;
607 DWORD cbBuf
= 0, pcbNeeded
= 0;
610 SetLastError(MAGIC_DEAD
);
611 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, 0, &cbBuf
);
612 trace("first call returned 0x%04x, with %ld: buffer size 0x%08lx\n",
613 res
, GetLastError(), cbBuf
);
615 RETURN_ON_DEACTIVATED_SPOOLER(res
)
616 ok((res
== 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
617 "returned %d with lasterror=%ld (expected '0' with " \
618 "ERROR_INSUFFICIENT_BUFFER)\n", res
, GetLastError());
621 trace("no valid buffer size returned, skipping tests\n");
625 buffer
= HeapAlloc( GetProcessHeap(), 0, cbBuf
*2);
626 if (buffer
== NULL
) return ;
628 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
, &pcbNeeded
);
629 ok( res
, "expected result != 0, got %d\n", res
);
630 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %ld instead of %ld\n",
633 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
634 ok( res
, "expected result != 0, got %d\n", res
);
635 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %ld instead of %ld\n",
638 SetLastError(MAGIC_DEAD
);
639 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
-1, &pcbNeeded
);
640 ok( !res
, "expected result == 0, got %d\n", res
);
641 ok( cbBuf
== pcbNeeded
, "pcbNeeded set to %ld instead of %ld\n",
644 ok( ERROR_INSUFFICIENT_BUFFER
== GetLastError(),
645 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
649 Do not add the next test:
650 XPsp2: crash in this app, when the spooler is not running
651 NT3.5: ERROR_INVALID_USER_BUFFER
652 win9x: ERROR_INVALID_PARAMETER
654 pcbNeeded = MAGIC_DEAD;
655 SetLastError(MAGIC_DEAD);
656 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
659 SetLastError(MAGIC_DEAD
);
660 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, buffer
, cbBuf
, NULL
);
661 ok( (!res
&& RPC_X_NULL_REF_POINTER
== GetLastError()) || res
,
662 "expected either result == 0 and "
663 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
664 "got result %d and last error == %ld\n", res
, GetLastError());
666 SetLastError(MAGIC_DEAD
);
667 res
= GetPrinterDriverDirectoryA( NULL
, NULL
, 1, NULL
, cbBuf
, NULL
);
668 ok(res
|| (GetLastError() == RPC_X_NULL_REF_POINTER
),
669 "returned %d with %ld (expected '!=0' or '0' with " \
670 "RPC_X_NULL_REF_POINTER)\n", res
, GetLastError());
673 /* with a valid buffer, but level is too large */
675 SetLastError(MAGIC_DEAD
);
676 res
= GetPrinterDriverDirectoryA(NULL
, NULL
, 2, buffer
, cbBuf
, &pcbNeeded
);
678 /* Level not checked in win9x and wine:*/
679 if((res
!= FALSE
) && buffer
[0])
681 trace("Level '2' not checked '%s'\n", buffer
);
685 ok( !res
&& (GetLastError() == ERROR_INVALID_LEVEL
),
686 "returned %d with lasterror=%ld (expected '0' with " \
687 "ERROR_INVALID_LEVEL)\n", res
, GetLastError());
690 /* printing environments are case insensitive */
691 /* "Windows 4.0" is valid for win9x and NT */
693 SetLastError(MAGIC_DEAD
);
694 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
695 buffer
, cbBuf
*2, &pcbNeeded
);
697 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
699 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
700 if (buffer
== NULL
) return ;
702 SetLastError(MAGIC_DEAD
);
703 res
= GetPrinterDriverDirectoryA(NULL
, env_win9x_case
, 1,
704 buffer
, cbBuf
*2, &pcbNeeded
);
707 ok(res
&& buffer
[0], "returned %d with " \
708 "lasterror=%ld and len=%d (expected '1' with 'len > 0')\n",
709 res
, GetLastError(), lstrlenA((char *)buffer
));
712 SetLastError(MAGIC_DEAD
);
713 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
714 buffer
, cbBuf
*2, &pcbNeeded
);
716 if(!res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)) {
718 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, cbBuf
*2);
719 if (buffer
== NULL
) return ;
722 SetLastError(MAGIC_DEAD
);
723 res
= GetPrinterDriverDirectoryA(NULL
, env_x86
, 1,
724 buffer
, cbBuf
*2, &pcbNeeded
);
727 /* "Windows NT x86" is invalid for win9x */
728 ok( (res
&& buffer
[0]) ||
729 (!res
&& (GetLastError() == ERROR_INVALID_ENVIRONMENT
)),
730 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
731 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
732 res
, GetLastError(), lstrlenA((char *)buffer
));
734 /* A Setup-Programm (PDFCreator_0.8.0) use empty strings */
735 SetLastError(MAGIC_DEAD
);
736 res
= GetPrinterDriverDirectoryA("", "", 1, buffer
, cbBuf
*2, &pcbNeeded
);
737 ok(res
, "returned %d with %ld (expected '!=0')\n", res
, GetLastError() );
739 SetLastError(MAGIC_DEAD
);
740 res
= GetPrinterDriverDirectoryA(NULL
, "", 1, buffer
, cbBuf
*2, &pcbNeeded
);
741 ok(res
, "returned %d with %ld (expected '!=0')\n", res
, GetLastError() );
743 SetLastError(MAGIC_DEAD
);
744 res
= GetPrinterDriverDirectoryA("", NULL
, 1, buffer
, cbBuf
*2, &pcbNeeded
);
745 ok(res
, "returned %d with %ld (expected '!=0')\n", res
, GetLastError() );
747 HeapFree( GetProcessHeap(), 0, buffer
);
750 static void test_OpenPrinter(void)
752 PRINTER_DEFAULTSA defaults
;
754 LPSTR default_printer
;
757 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
760 SetLastError(MAGIC_DEAD
);
761 res
= OpenPrinter(NULL
, NULL
, NULL
);
762 /* The deactivated Spooler is catched here on NT3.51 */
763 RETURN_ON_DEACTIVATED_SPOOLER(res
)
764 ok(!res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
765 "returned %ld with %ld (expected '0' with ERROR_INVALID_PARAMETER)\n",
766 res
, GetLastError());
769 /* Get Handle for the local Printserver (NT only)*/
770 hprinter
= (HANDLE
) MAGIC_DEAD
;
771 SetLastError(MAGIC_DEAD
);
772 res
= OpenPrinter(NULL
, &hprinter
, NULL
);
773 /* The deactivated Spooler is catched here on XPsp2 */
774 RETURN_ON_DEACTIVATED_SPOOLER(res
)
775 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
776 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
777 res
, GetLastError());
779 ClosePrinter(hprinter
);
781 defaults
.pDatatype
=NULL
;
782 defaults
.pDevMode
=NULL
;
784 defaults
.DesiredAccess
=0;
785 hprinter
= (HANDLE
) MAGIC_DEAD
;
786 SetLastError(MAGIC_DEAD
);
787 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
788 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
789 if (res
) ClosePrinter(hprinter
);
791 defaults
.DesiredAccess
=-1;
792 hprinter
= (HANDLE
) MAGIC_DEAD
;
793 SetLastError(MAGIC_DEAD
);
794 res
= OpenPrinter(NULL
, &hprinter
, &defaults
);
795 ok(!res
&& GetLastError() == ERROR_ACCESS_DENIED
,
796 "returned %ld with %ld (expected '0' with ERROR_ACCESS_DENIED)\n",
797 res
, GetLastError());
798 if (res
) ClosePrinter(hprinter
);
802 size
= sizeof(buffer
) - 3 ;
808 if (GetComputerNameA(ptr
, &size
)) {
810 hprinter
= (HANDLE
) MAGIC_DEAD
;
811 SetLastError(MAGIC_DEAD
);
812 res
= OpenPrinter(buffer
, &hprinter
, NULL
);
814 ok(res
|| (!res
&& GetLastError() == ERROR_INVALID_PARAMETER
),
815 "returned %ld with %ld (expected '!=0' or '0' with ERROR_INVALID_PARAMETER)\n",
816 res
, GetLastError());
818 if(res
) ClosePrinter(hprinter
);
821 /* Invalid Printername */
822 hprinter
= (HANDLE
) MAGIC_DEAD
;
823 SetLastError(MAGIC_DEAD
);
824 res
= OpenPrinter("illegal,name", &hprinter
, NULL
);
825 ok(!res
&& ((GetLastError() == ERROR_INVALID_PRINTER_NAME
) ||
826 (GetLastError() == ERROR_INVALID_PARAMETER
) ),
827 "returned %ld with %ld (expected '0' with: ERROR_INVALID_PARAMETER or" \
828 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
829 if(res
) ClosePrinter(hprinter
);
832 /* Get Handle for the default Printer */
833 if ((default_printer
= find_default_printer()))
835 hprinter
= (HANDLE
) MAGIC_DEAD
;
836 SetLastError(MAGIC_DEAD
);
837 res
= OpenPrinter(default_printer
, &hprinter
, NULL
);
838 if((!res
) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE
))
840 trace("The Service 'Spooler' is required for '%s'\n", default_printer
);
843 ok(res
, "returned %ld with %ld (expected '!=0')\n", res
, GetLastError());
844 if(res
) ClosePrinter(hprinter
);
846 defaults
.pDatatype
=NULL
;
847 defaults
.pDevMode
=NULL
;
848 defaults
.DesiredAccess
=0;
850 hprinter
= (HANDLE
) MAGIC_DEAD
;
851 SetLastError(MAGIC_DEAD
);
852 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
853 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
854 "returned %ld with %ld (expected '!=0' or '0' with " \
855 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
856 if(res
) ClosePrinter(hprinter
);
858 defaults
.pDatatype
="";
860 hprinter
= (HANDLE
) MAGIC_DEAD
;
861 SetLastError(MAGIC_DEAD
);
862 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
863 /* stop here, when a remote Printserver has no RPC-Service running */
864 RETURN_ON_DEACTIVATED_SPOOLER(res
)
865 ok(res
|| ((GetLastError() == ERROR_INVALID_DATATYPE
) ||
866 (GetLastError() == ERROR_ACCESS_DENIED
)),
867 "returned %ld with %ld (expected '!=0' or '0' with: " \
868 "ERROR_INVALID_DATATYPE or ERROR_ACCESS_DENIED)\n",
869 res
, GetLastError());
870 if(res
) ClosePrinter(hprinter
);
873 defaults
.pDatatype
=NULL
;
874 defaults
.DesiredAccess
=PRINTER_ACCESS_USE
;
876 hprinter
= (HANDLE
) MAGIC_DEAD
;
877 SetLastError(MAGIC_DEAD
);
878 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
879 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
880 "returned %ld with %ld (expected '!=0' or '0' with " \
881 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
882 if(res
) ClosePrinter(hprinter
);
885 defaults
.DesiredAccess
=PRINTER_ALL_ACCESS
;
886 hprinter
= (HANDLE
) MAGIC_DEAD
;
887 SetLastError(MAGIC_DEAD
);
888 res
= OpenPrinter(default_printer
, &hprinter
, &defaults
);
889 ok(res
|| GetLastError() == ERROR_ACCESS_DENIED
,
890 "returned %ld with %ld (expected '!=0' or '0' with " \
891 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
892 if(res
) ClosePrinter(hprinter
);
898 static void test_SetDefaultPrinter(void)
901 LPSTR default_printer
;
902 DWORD size
= DEFAULT_PRINTER_SIZE
;
903 CHAR buffer
[DEFAULT_PRINTER_SIZE
];
904 CHAR org_value
[DEFAULT_PRINTER_SIZE
];
907 if (!pSetDefaultPrinterA
) return;
908 /* only supported on win2k and above */
910 default_printer
= find_default_printer();
912 /* backup the original value */
914 SetLastError(MAGIC_DEAD
);
915 res
= GetProfileStringA("windows", "device", NULL
, org_value
, size
);
917 /* first part: with the default Printer */
918 SetLastError(MAGIC_DEAD
);
919 res
= pSetDefaultPrinterA("no_printer_with_this_name");
921 RETURN_ON_DEACTIVATED_SPOOLER(res
)
922 /* spooler is running or we have no spooler here*/
924 /* Not implemented in wine */
925 if (!res
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)) {
926 trace("SetDefaultPrinterA() not implemented yet.\n");
930 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
931 "returned %ld with %ld (expected '0' with " \
932 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
934 WriteProfileStringA("windows", "device", org_value
);
935 SetLastError(MAGIC_DEAD
);
936 res
= pSetDefaultPrinterA("");
937 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
938 "returned %ld with %ld (expected '!=0' or '0' with " \
939 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
941 WriteProfileStringA("windows", "device", org_value
);
942 SetLastError(MAGIC_DEAD
);
943 res
= pSetDefaultPrinterA(NULL
);
944 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
945 "returned %ld with %ld (expected '!=0' or '0' with " \
946 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
948 WriteProfileStringA("windows", "device", org_value
);
949 SetLastError(MAGIC_DEAD
);
950 res
= pSetDefaultPrinterA(default_printer
);
951 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
952 "returned %ld with %ld (expected '!=0' or '0' with " \
953 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
956 /* second part: always without a default Printer */
957 WriteProfileStringA("windows", "device", NULL
);
958 SetLastError(MAGIC_DEAD
);
959 res
= pSetDefaultPrinterA("no_printer_with_this_name");
961 ok(!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
),
962 "returned %ld with %ld (expected '0' with " \
963 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
965 WriteProfileStringA("windows", "device", NULL
);
966 SetLastError(MAGIC_DEAD
);
967 res
= pSetDefaultPrinterA("");
968 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
969 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
970 "returned %ld with %ld (expected '!=0' or '0' with " \
971 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
973 WriteProfileStringA("windows", "device", NULL
);
974 SetLastError(MAGIC_DEAD
);
975 res
= pSetDefaultPrinterA(NULL
);
976 /* we get ERROR_INVALID_PRINTER_NAME when no printer is installed */
977 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
978 "returned %ld with %ld (expected '!=0' or '0' with " \
979 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
981 WriteProfileStringA("windows", "device", NULL
);
982 SetLastError(MAGIC_DEAD
);
983 res
= pSetDefaultPrinterA(default_printer
);
984 ok(res
|| (!res
&& (GetLastError() == ERROR_INVALID_PRINTER_NAME
)),
985 "returned %ld with %ld (expected '!=0' or '0' with " \
986 "ERROR_INVALID_PRINTER_NAME)\n", res
, GetLastError());
988 /* restore the original value */
989 res
= pSetDefaultPrinterA(default_printer
); /* the nice way */
990 WriteProfileStringA("windows", "device", org_value
); /* the old way */
993 SetLastError(MAGIC_DEAD
);
994 res
= GetProfileStringA("windows", "device", NULL
, buffer
, size
);
995 ok(!lstrcmpA(org_value
, buffer
), "'%s' (expected '%s')\n", buffer
, org_value
);
999 static void test_GetPrinterDriver(void)
1001 LPSTR default_printer
;
1006 DWORD needed
, filled
;
1008 default_printer
= find_default_printer();
1009 if (!default_printer
)
1011 trace("There is no default printer installed, skiping the test\n");
1016 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
1019 trace("There is no printers installed, skiping the test\n");
1022 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
1024 for (level
= -1; level
<= 7; level
++)
1026 SetLastError(0xdeadbeef);
1028 ret
= GetPrinterDriver(hprn
, NULL
, level
, NULL
, 0, &needed
);
1029 ok(!ret
, "level %d: GetPrinterDriver should fail\n", level
);
1030 if (level
>= 1 && level
<= 6)
1032 /* Not all levels are supported on all Windows-Versions */
1033 if(GetLastError() == ERROR_INVALID_LEVEL
) continue;
1034 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "wrong error %ld\n", GetLastError());
1035 ok(needed
> 0,"not expected needed buffer size %ld\n", needed
);
1039 /* ERROR_OUTOFMEMORY found on win9x */
1040 ok( ((GetLastError() == ERROR_INVALID_LEVEL
) ||
1041 (GetLastError() == ERROR_OUTOFMEMORY
)),
1042 "%d: returned %d with %ld (expected '0' with: " \
1043 "ERROR_INVALID_LEVEL or ERROR_OUTOFMEMORY)\n",
1044 level
, ret
, GetLastError());
1045 /* needed is modified in win9x. The modified Value depends on the
1046 default Printer. testing for "needed == (DWORD)-1" will fail */
1050 buf
= HeapAlloc(GetProcessHeap(), 0, needed
);
1052 SetLastError(0xdeadbeef);
1054 ret
= GetPrinterDriver(hprn
, NULL
, level
, buf
, needed
, &filled
);
1055 ok(ret
, "level %d: GetPrinterDriver error %ld\n", level
, GetLastError());
1056 ok(needed
== filled
, "needed %ld != filled %ld\n", needed
, filled
);
1060 DRIVER_INFO_2
*di_2
= (DRIVER_INFO_2
*)buf
;
1061 DWORD calculated
= sizeof(*di_2
);
1063 /* MSDN is wrong: The Drivers on the win9x-CD's have cVersion=0x0400
1064 NT351: 1, NT4.0+w2k(Kernelmode): 2, w2k and above(Usermode): 3 */
1065 ok((di_2
->cVersion
>= 0 && di_2
->cVersion
<= 3) ||
1066 (di_2
->cVersion
== 0x0400), "di_2->cVersion = %ld\n", di_2
->cVersion
);
1067 ok(di_2
->pName
!= NULL
, "not expected NULL ptr\n");
1068 ok(di_2
->pEnvironment
!= NULL
, "not expected NULL ptr\n");
1069 ok(di_2
->pDriverPath
!= NULL
, "not expected NULL ptr\n");
1070 ok(di_2
->pDataFile
!= NULL
, "not expected NULL ptr\n");
1071 ok(di_2
->pConfigFile
!= NULL
, "not expected NULL ptr\n");
1073 trace("cVersion %ld\n", di_2
->cVersion
);
1074 trace("pName %s\n", di_2
->pName
);
1075 calculated
+= strlen(di_2
->pName
) + 1;
1076 trace("pEnvironment %s\n", di_2
->pEnvironment
);
1077 calculated
+= strlen(di_2
->pEnvironment
) + 1;
1078 trace("pDriverPath %s\n", di_2
->pDriverPath
);
1079 calculated
+= strlen(di_2
->pDriverPath
) + 1;
1080 trace("pDataFile %s\n", di_2
->pDataFile
);
1081 calculated
+= strlen(di_2
->pDataFile
) + 1;
1082 trace("pConfigFile %s\n", di_2
->pConfigFile
);
1083 calculated
+= strlen(di_2
->pConfigFile
) + 1;
1085 /* XP allocates memory for both ANSI and unicode names */
1086 ok(filled
>= calculated
,"calculated %ld != filled %ld\n", calculated
, filled
);
1089 HeapFree(GetProcessHeap(), 0, buf
);
1092 SetLastError(0xdeadbeef);
1093 ret
= ClosePrinter(hprn
);
1094 ok(ret
, "ClosePrinter error %ld\n", GetLastError());
1097 static void test_DEVMODE(const DEVMODE
*dm
, LONG dmSize
, LPCSTR exp_prn_name
)
1099 /* On NT3.51, some fields in DEVMODE are empty/zero
1100 (dmDeviceName, dmSpecVersion, dmDriverVersion and dmDriverExtra)
1101 We skip the Tests on this Platform */
1102 if (dm
->dmSpecVersion
|| dm
->dmDriverVersion
|| dm
->dmDriverExtra
) {
1103 /* The Printername can be larger (MAX_PATH) than CCHDEVICENAME */
1104 ok(!strncmp(exp_prn_name
, (LPCSTR
)dm
->dmDeviceName
, CCHDEVICENAME
),
1105 "expected '%s', got '%s'\n", exp_prn_name
, dm
->dmDeviceName
);
1106 ok(dm
->dmSize
+ dm
->dmDriverExtra
== dmSize
,
1107 "%u != %ld\n", dm
->dmSize
+ dm
->dmDriverExtra
, dmSize
);
1109 trace("dmFields %08lx\n", dm
->dmFields
);
1112 static void test_DocumentProperties(void)
1114 LPSTR default_printer
;
1119 default_printer
= find_default_printer();
1120 if (!default_printer
)
1122 trace("There is no default printer installed, skiping the test\n");
1127 ret
= OpenPrinter(default_printer
, &hprn
, NULL
);
1130 trace("There is no printers installed, skiping the test\n");
1133 ok(hprn
!= 0, "wrong hprn %p\n", hprn
);
1135 dm_size
= DocumentProperties(0, hprn
, NULL
, NULL
, NULL
, 0);
1136 trace("DEVMODE required size %ld\n", dm_size
);
1137 ok(dm_size
>= sizeof(DEVMODE
), "unexpected DocumentProperties ret value %ld\n", dm_size
);
1139 dm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dm_size
);
1141 ret
= DocumentProperties(0, hprn
, NULL
, dm
, dm
, DM_OUT_BUFFER
);
1142 ok(ret
== IDOK
, "DocumentProperties ret value %ld != expected IDOK\n", ret
);
1144 test_DEVMODE(dm
, dm_size
, default_printer
);
1146 HeapFree(GetProcessHeap(), 0, dm
);
1148 SetLastError(0xdeadbeef);
1149 ret
= ClosePrinter(hprn
);
1150 ok(ret
, "ClosePrinter error %ld\n", GetLastError());
1155 hwinspool
= GetModuleHandleA("winspool.drv");
1156 pGetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "GetDefaultPrinterA");
1157 pSetDefaultPrinterA
= (void *) GetProcAddress(hwinspool
, "SetDefaultPrinterA");
1159 find_default_printer();
1162 test_DeleteMonitor();
1163 test_DocumentProperties();
1164 test_EnumMonitors();
1165 test_GetDefaultPrinter();
1166 test_GetPrinterDriverDirectory();
1168 test_GetPrinterDriver();
1169 test_SetDefaultPrinter();