Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/tests/printdlg.c
4389 views
1
/*
2
* Unit test suite for comdlg32 API functions: printer dialogs
3
*
4
* Copyright 2006-2007 Detlef Riekenberg
5
* Copyright 2013 Dmitry Timoshkov
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*
21
*/
22
23
#define COBJMACROS
24
#define CONST_VTABLE
25
26
#include <stdarg.h>
27
#include <stdio.h>
28
29
#include "windef.h"
30
#include "winbase.h"
31
#include "winerror.h"
32
#include "wingdi.h"
33
#include "winuser.h"
34
#include "objbase.h"
35
36
#include "cderr.h"
37
#include "commdlg.h"
38
#include "dlgs.h"
39
#include "winspool.h"
40
41
#include "wine/test.h"
42
43
/* ########################### */
44
45
extern const IID IID_IObjectWithSite;
46
47
static HMODULE hcomdlg32;
48
static HRESULT (WINAPI * pPrintDlgExW)(LPPRINTDLGEXW);
49
50
/* ########################### */
51
52
static const CHAR emptyA[] = "";
53
static const CHAR PrinterPortsA[] = "PrinterPorts";
54
55
/* ########################### */
56
57
static void test_PageSetupDlgA(void)
58
{
59
LPPAGESETUPDLGA pDlg;
60
DWORD res;
61
62
pDlg = malloc((sizeof(PAGESETUPDLGA)) * 2);
63
if (!pDlg) return;
64
65
SetLastError(0xdeadbeef);
66
res = PageSetupDlgA(NULL);
67
ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
68
"returned %lu with %lu and 0x%lx (expected '0' and "
69
"CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
70
71
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
72
pDlg->lStructSize = sizeof(PAGESETUPDLGA) -1;
73
SetLastError(0xdeadbeef);
74
res = PageSetupDlgA(pDlg);
75
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
76
"returned %lu with %lu and 0x%lx (expected '0' and "
77
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
78
79
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
80
pDlg->lStructSize = sizeof(PAGESETUPDLGA) +1;
81
pDlg->Flags = PSD_RETURNDEFAULT;
82
SetLastError(0xdeadbeef);
83
res = PageSetupDlgA(pDlg);
84
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
85
"returned %lu with %lu and 0x%lx (expected '0' and CDERR_STRUCTSIZE)\n",
86
res, GetLastError(), CommDlgExtendedError());
87
88
89
ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
90
pDlg->lStructSize = sizeof(PAGESETUPDLGA);
91
pDlg->Flags = PSD_RETURNDEFAULT | PSD_NOWARNING;
92
SetLastError(0xdeadbeef);
93
res = PageSetupDlgA(pDlg);
94
ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
95
"returned %lu with %lu and 0x%lx (expected '!= 0' or '0' and "
96
"PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
97
98
if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
99
skip("No printer configured.\n");
100
free(pDlg);
101
return;
102
}
103
104
ok( pDlg->hDevMode && pDlg->hDevNames,
105
"got %p and %p (expected '!= NULL' for both)\n",
106
pDlg->hDevMode, pDlg->hDevNames);
107
108
GlobalFree(pDlg->hDevMode);
109
GlobalFree(pDlg->hDevNames);
110
111
free(pDlg);
112
}
113
114
/* ########################### */
115
116
static UINT_PTR CALLBACK print_hook_proc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
117
{
118
if (msg == WM_INITDIALOG)
119
{
120
/* some driver popup a dialog and hung the test or silently limit the number of copies,
121
when trying to set more than 999 copies */
122
SetDlgItemInt(hdlg, edt3, 123, FALSE);
123
PostMessageA(hdlg, WM_COMMAND, IDOK, FALSE);
124
}
125
return 0;
126
}
127
128
static UINT_PTR CALLBACK printer_properties_hook_procA(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
129
{
130
DEVMODEA* dm;
131
PRINTDLGA* dlg;
132
133
if (msg == WM_INITDIALOG)
134
{
135
PostMessageW(hdlg, WM_COMMAND, psh2, lp);
136
}
137
if (msg == WM_COMMAND && wp == psh2)
138
{
139
dlg = (PRINTDLGA*)lp;
140
dm = GlobalLock(dlg->hDevMode);
141
dm->dmDuplex = 999;
142
dm->dmPaperSize = 888;
143
GlobalUnlock(dlg->hDevMode);
144
PostMessageW(hdlg, WM_COMMAND, IDOK, FALSE);
145
return TRUE;
146
}
147
return 0;
148
}
149
150
static void test_PrintDlgA(void)
151
{
152
DWORD res, n_copies = 0;
153
LPPRINTDLGA pDlg;
154
DEVNAMES *pDevNames;
155
LPCSTR driver;
156
LPCSTR device;
157
LPCSTR port;
158
CHAR buffer[MAX_PATH];
159
LPSTR ptr;
160
DEVMODEA *dm;
161
162
pDlg = malloc((sizeof(PRINTDLGA)) * 2);
163
if (!pDlg) return;
164
165
166
/* will crash with unpatched wine */
167
SetLastError(0xdeadbeef);
168
res = PrintDlgA(NULL);
169
ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
170
"returned %ld with 0x%lx and 0x%lx (expected '0' and "
171
"CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
172
173
ZeroMemory(pDlg, sizeof(PRINTDLGA));
174
pDlg->lStructSize = sizeof(PRINTDLGA) - 1;
175
SetLastError(0xdeadbeef);
176
res = PrintDlgA(pDlg);
177
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
178
"returned %ld with 0x%lx and 0x%lx (expected '0' and "
179
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
180
181
ZeroMemory(pDlg, sizeof(PRINTDLGA));
182
pDlg->lStructSize = sizeof(PRINTDLGA) + 1;
183
pDlg->Flags = PD_RETURNDEFAULT;
184
SetLastError(0xdeadbeef);
185
res = PrintDlgA(pDlg);
186
ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
187
"returned %lu with %lu and 0x%lx (expected '0' and "
188
"CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
189
190
191
ZeroMemory(pDlg, sizeof(PRINTDLGA));
192
pDlg->lStructSize = sizeof(PRINTDLGA);
193
pDlg->Flags = PD_RETURNDEFAULT;
194
SetLastError(0xdeadbeef);
195
res = PrintDlgA(pDlg);
196
ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
197
"returned %ld with 0x%lx and 0x%lx (expected '!= 0' or '0' and "
198
"PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
199
200
if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
201
skip("No printer configured.\n");
202
free(pDlg);
203
return;
204
}
205
206
ok(pDlg->hDevNames != NULL, "(expected '!= NULL')\n");
207
pDevNames = GlobalLock(pDlg->hDevNames);
208
ok(pDevNames != NULL, "(expected '!= NULL')\n");
209
210
if (pDevNames) {
211
ok(pDevNames->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n");
212
ok(pDevNames->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n");
213
ok(pDevNames->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n");
214
ok(pDevNames->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames->wDefault);
215
216
driver = (LPCSTR)pDevNames + pDevNames->wDriverOffset;
217
device = (LPCSTR)pDevNames + pDevNames->wDeviceOffset;
218
port = (LPCSTR)pDevNames + pDevNames->wOutputOffset;
219
trace("driver '%s' device '%s' port '%s'\n", driver, device, port);
220
221
/* The Driver Entry does not include a Path */
222
ptr = strrchr(driver, '\\');
223
ok( ptr == NULL, "got %p for '%s' (expected NULL for a simple name)\n", ptr, driver);
224
225
/* The Driver Entry does not have an extension (fixed to ".drv") */
226
ptr = strrchr(driver, '.');
227
todo_wine {
228
ok( ptr == NULL, "got %p for '%s' (expected NULL for no extension)\n", ptr, driver);
229
}
230
231
232
buffer[0] = '\0';
233
SetLastError(0xdeadbeef);
234
res = GetProfileStringA(PrinterPortsA, device, emptyA, buffer, sizeof(buffer));
235
ptr = strchr(buffer, ',');
236
ok( (res > 1) && (ptr != NULL),
237
"got %lu with %lu and %p for '%s' (expected '>1' and '!= NULL')\n",
238
res, GetLastError(), ptr, buffer);
239
240
if (ptr) ptr[0] = '\0';
241
ok( lstrcmpiA(driver, buffer) == 0,
242
"got driver '%s' (expected '%s')\n", driver, buffer);
243
244
n_copies = DeviceCapabilitiesA(device, port, DC_COPIES, NULL, NULL);
245
ok(n_copies > 0, "DeviceCapabilities(DC_COPIES) failed\n");
246
}
247
248
GlobalUnlock(pDlg->hDevNames);
249
GlobalFree(pDlg->hDevMode);
250
GlobalFree(pDlg->hDevNames);
251
252
/* if device doesn't support printing of multiple copies then
253
* an attempt to set number of copies > 1 in print dialog would
254
* cause the PrintDlg under Windows display the MessageBox and
255
* the test will hang waiting for user response.
256
*/
257
if (n_copies > 1)
258
{
259
ZeroMemory(pDlg, sizeof(*pDlg));
260
pDlg->lStructSize = sizeof(*pDlg);
261
pDlg->Flags = PD_ENABLEPRINTHOOK;
262
pDlg->lpfnPrintHook = print_hook_proc;
263
res = PrintDlgA(pDlg);
264
ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError());
265
/* Version of Microsoft XPS Document Writer driver shipped before Win7
266
* reports that it can print multiple copies, but returns 1.
267
*/
268
ok(pDlg->nCopies == 123 || broken(pDlg->nCopies == 1), "expected nCopies 123, got %d\n", pDlg->nCopies);
269
ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n");
270
dm = GlobalLock(pDlg->hDevMode);
271
/* some broken drivers use always PD_USEDEVMODECOPIES */
272
ok((dm->dmCopies == 1) || broken(dm->dmCopies == 123),
273
"expected dm->dmCopies 1, got %d\n", dm->dmCopies);
274
GlobalUnlock(pDlg->hDevMode);
275
GlobalFree(pDlg->hDevMode);
276
GlobalFree(pDlg->hDevNames);
277
278
ZeroMemory(pDlg, sizeof(*pDlg));
279
pDlg->lStructSize = sizeof(*pDlg);
280
pDlg->Flags = PD_ENABLEPRINTHOOK | PD_USEDEVMODECOPIES;
281
pDlg->lpfnPrintHook = print_hook_proc;
282
res = PrintDlgA(pDlg);
283
ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError());
284
ok(pDlg->nCopies == 1, "expected nCopies 1, got %d\n", pDlg->nCopies);
285
ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n");
286
dm = GlobalLock(pDlg->hDevMode);
287
ok(dm->dmCopies == 123, "expected dm->dmCopies 123, got %d\n", dm->dmCopies);
288
GlobalUnlock(pDlg->hDevMode);
289
GlobalFree(pDlg->hDevMode);
290
GlobalFree(pDlg->hDevNames);
291
}
292
293
ZeroMemory(pDlg, sizeof(*pDlg));
294
295
pDlg->lStructSize = sizeof(*pDlg);
296
pDlg->Flags = PD_ENABLEPRINTHOOK;
297
pDlg->lpfnPrintHook = printer_properties_hook_procA;
298
299
pDlg->hDevMode = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(DEVMODEA));
300
dm = GlobalLock(pDlg->hDevMode);
301
dm->dmSize = sizeof(*dm);
302
dm->dmFields |= DM_DUPLEX | DM_PAPERSIZE;
303
dm->dmDuplex = 123;
304
dm->dmPaperSize = 321;
305
GlobalUnlock(pDlg->hDevMode);
306
307
PrintDlgA(pDlg);
308
dm = GlobalLock(pDlg->hDevMode);
309
ok(dm->dmDuplex == 999, "expected 999, but got %d.\n", dm->dmDuplex);
310
ok(dm->dmPaperSize == 888, "expected 888, but got %d.\n", dm->dmPaperSize);
311
GlobalUnlock(pDlg->hDevMode);
312
GlobalFree(pDlg->hDevMode);
313
314
free(pDlg);
315
}
316
317
static UINT_PTR CALLBACK printer_properties_hook_procW(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
318
{
319
DEVMODEW* dm;
320
PRINTDLGW* dlg;
321
322
if (msg == WM_INITDIALOG)
323
{
324
PostMessageW(hdlg, WM_COMMAND, psh2, lp);
325
}
326
if (msg == WM_COMMAND && wp == psh2)
327
{
328
dlg = (PRINTDLGW*)lp;
329
dm = GlobalLock(dlg->hDevMode);
330
dm->dmDuplex = 999;
331
dm->dmPaperSize = 888;
332
GlobalUnlock(dlg->hDevMode);
333
PostMessageW(hdlg, WM_COMMAND, IDOK, FALSE);
334
return TRUE;
335
}
336
return 0;
337
}
338
339
void test_PrintDlgW(void)
340
{
341
PRINTDLGW pd = { 0 };
342
DEVMODEW* dm;
343
DWORD name_size = 0;
344
345
GetDefaultPrinterW(NULL, &name_size);
346
if(name_size == 0)
347
{
348
skip("No printer configured.\n");
349
return;
350
}
351
352
pd.lStructSize = sizeof(pd);
353
pd.Flags = PD_ENABLEPRINTHOOK;
354
pd.lpfnPrintHook = printer_properties_hook_procW;
355
356
pd.hDevMode = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(DEVMODEW));
357
dm = GlobalLock(pd.hDevMode);
358
dm->dmSize = sizeof(*dm);
359
dm->dmFields |= DM_DUPLEX | DM_PAPERSIZE;
360
dm->dmDuplex = 123;
361
dm->dmPaperSize = 321;
362
GlobalUnlock(pd.hDevMode);
363
364
PrintDlgW(&pd);
365
dm = GlobalLock(pd.hDevMode);
366
ok(dm->dmDuplex == 999, "expected 999, but got %d.\n", dm->dmDuplex);
367
ok(dm->dmPaperSize == 888, "expected 888, but got %d.\n", dm->dmPaperSize);
368
GlobalUnlock(pd.hDevMode);
369
GlobalFree(pd.hDevMode);
370
}
371
372
/* ########################### */
373
374
static HRESULT WINAPI callback_QueryInterface(IPrintDialogCallback *iface,
375
REFIID riid, void **ppv)
376
{
377
ok(0, "callback_QueryInterface(%s): unexpected call\n", wine_dbgstr_guid(riid));
378
return E_NOINTERFACE;
379
}
380
381
static ULONG WINAPI callback_AddRef(IPrintDialogCallback *iface)
382
{
383
trace("callback_AddRef\n");
384
return 2;
385
}
386
387
static ULONG WINAPI callback_Release(IPrintDialogCallback *iface)
388
{
389
trace("callback_Release\n");
390
return 1;
391
}
392
393
static HRESULT WINAPI callback_InitDone(IPrintDialogCallback *iface)
394
{
395
trace("callback_InitDone\n");
396
return S_OK;
397
}
398
399
static HRESULT WINAPI callback_SelectionChange(IPrintDialogCallback *iface)
400
{
401
trace("callback_SelectionChange\n");
402
return S_OK;
403
}
404
405
static HRESULT WINAPI callback_HandleMessage(IPrintDialogCallback *iface,
406
HWND hdlg, UINT msg, WPARAM wp, LPARAM lp, LRESULT *res)
407
{
408
trace("callback_HandleMessage %p,%04x,%Ix,%Ix,%p\n", hdlg, msg, wp, lp, res);
409
/* *res = PD_RESULT_PRINT; */
410
return S_OK;
411
}
412
413
static const IPrintDialogCallbackVtbl callback_Vtbl =
414
{
415
callback_QueryInterface,
416
callback_AddRef,
417
callback_Release,
418
callback_InitDone,
419
callback_SelectionChange,
420
callback_HandleMessage
421
};
422
423
static IPrintDialogCallback callback = { &callback_Vtbl };
424
425
static HRESULT WINAPI unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
426
{
427
trace("unknown_QueryInterface %s\n", wine_dbgstr_guid(riid));
428
429
if (IsEqualGUID(riid, &IID_IPrintDialogCallback))
430
{
431
*ppv = &callback;
432
return S_OK;
433
}
434
else if (IsEqualGUID(riid, &IID_IObjectWithSite))
435
{
436
*ppv = NULL;
437
return E_NOINTERFACE;
438
}
439
440
ok(0, "unexpected IID %s\n", wine_dbgstr_guid(riid));
441
*ppv = NULL;
442
return E_NOINTERFACE;
443
}
444
445
static ULONG WINAPI unknown_AddRef(IUnknown *iface)
446
{
447
trace("unknown_AddRef\n");
448
return 2;
449
}
450
451
static ULONG WINAPI unknown_Release(IUnknown *iface)
452
{
453
trace("unknown_Release\n");
454
return 1;
455
}
456
457
static const IUnknownVtbl unknown_Vtbl =
458
{
459
unknown_QueryInterface,
460
unknown_AddRef,
461
unknown_Release
462
};
463
464
static IUnknown unknown = { &unknown_Vtbl };
465
466
static void test_PrintDlgExW(void)
467
{
468
PRINTPAGERANGE pagerange[2];
469
LPPRINTDLGEXW pDlg;
470
DEVNAMES *dn;
471
HRESULT res;
472
473
/* PrintDlgEx not present before w2k */
474
if (!pPrintDlgExW) {
475
win_skip("PrintDlgExW not available\n");
476
return;
477
}
478
479
if (0) /* Crashes on Win10 */
480
{
481
/* Set CommDlgExtendedError != 0 */
482
PrintDlgA(NULL);
483
SetLastError(0xdeadbeef);
484
res = pPrintDlgExW(NULL);
485
ok( (res == E_INVALIDARG),
486
"got 0x%lx with %lu and %lu (expected 'E_INVALIDARG')\n",
487
res, GetLastError(), CommDlgExtendedError() );
488
}
489
490
pDlg = malloc(sizeof(PRINTDLGEXW) + 8);
491
if (!pDlg) return;
492
493
/* lStructSize must be exact */
494
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
495
pDlg->lStructSize = sizeof(PRINTDLGEXW) - 1;
496
PrintDlgA(NULL);
497
SetLastError(0xdeadbeef);
498
res = pPrintDlgExW(pDlg);
499
ok( (res == E_INVALIDARG),
500
"got 0x%lx with %lu and %lu (expected 'E_INVALIDARG')\n",
501
res, GetLastError(), CommDlgExtendedError());
502
503
504
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
505
pDlg->lStructSize = sizeof(PRINTDLGEXW) + 1;
506
PrintDlgA(NULL);
507
SetLastError(0xdeadbeef);
508
res = pPrintDlgExW(pDlg);
509
ok( (res == E_INVALIDARG),
510
"got 0x%lx with %lu and %lu (expected 'E_INVALIDARG')\n",
511
res, GetLastError(), CommDlgExtendedError());
512
513
514
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
515
pDlg->lStructSize = sizeof(PRINTDLGEXW);
516
SetLastError(0xdeadbeef);
517
res = pPrintDlgExW(pDlg);
518
ok( (res == E_HANDLE),
519
"got 0x%lx with %lu and %lu (expected 'E_HANDLE')\n",
520
res, GetLastError(), CommDlgExtendedError());
521
522
/* nStartPage must be START_PAGE_GENERAL for the general page or a valid property sheet index */
523
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
524
pDlg->lStructSize = sizeof(PRINTDLGEXW);
525
pDlg->hwndOwner = GetDesktopWindow();
526
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS;
527
res = pPrintDlgExW(pDlg);
528
ok((res == E_INVALIDARG), "got 0x%lx (expected 'E_INVALIDARG')\n", res);
529
530
/* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
531
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
532
pDlg->lStructSize = sizeof(PRINTDLGEXW);
533
pDlg->hwndOwner = GetDesktopWindow();
534
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
535
pDlg->nStartPage = START_PAGE_GENERAL;
536
res = pPrintDlgExW(pDlg);
537
ok((res == E_INVALIDARG), "got 0x%lx (expected 'E_INVALIDARG')\n", res);
538
539
/* this is invalid: a valid lpPageRanges with 0 for nMaxPageRanges */
540
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
541
pDlg->lStructSize = sizeof(PRINTDLGEXW);
542
pDlg->hwndOwner = GetDesktopWindow();
543
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
544
pDlg->lpPageRanges = pagerange;
545
pDlg->nStartPage = START_PAGE_GENERAL;
546
res = pPrintDlgExW(pDlg);
547
ok((res == E_INVALIDARG), "got 0x%lx (expected 'E_INVALIDARG')\n", res);
548
549
/* this is invalid: NULL for lpPageRanges with a valid nMaxPageRanges */
550
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
551
pDlg->lStructSize = sizeof(PRINTDLGEXW);
552
pDlg->hwndOwner = GetDesktopWindow();
553
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
554
pDlg->nMaxPageRanges = 1;
555
pDlg->nStartPage = START_PAGE_GENERAL;
556
res = pPrintDlgExW(pDlg);
557
ok((res == E_INVALIDARG), "got 0x%lx (expected 'E_INVALIDARG')\n", res);
558
559
/* this works: lpPageRanges with a valid nMaxPageRanges */
560
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
561
pDlg->lStructSize = sizeof(PRINTDLGEXW);
562
pDlg->hwndOwner = GetDesktopWindow();
563
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
564
pDlg->nMaxPageRanges = 1;
565
pDlg->lpPageRanges = pagerange;
566
pDlg->nStartPage = START_PAGE_GENERAL;
567
res = pPrintDlgExW(pDlg);
568
if (res == E_FAIL)
569
{
570
skip("No printer configured.\n");
571
free(pDlg);
572
return;
573
}
574
575
ok(res == S_OK, "got 0x%lx (expected S_OK)\n", res);
576
577
dn = GlobalLock(pDlg->hDevNames);
578
ok(dn != NULL, "expected '!= NULL' for GlobalLock(%p)\n",pDlg->hDevNames);
579
if (dn)
580
{
581
ok(dn->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n");
582
ok(dn->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n");
583
ok(dn->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n");
584
ok(dn->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", dn->wDefault);
585
586
GlobalUnlock(pDlg->hDevNames);
587
}
588
GlobalFree(pDlg->hDevMode);
589
GlobalFree(pDlg->hDevNames);
590
591
/* this works also: PD_NOPAGENUMS */
592
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
593
pDlg->lStructSize = sizeof(PRINTDLGEXW);
594
pDlg->hwndOwner = GetDesktopWindow();
595
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS;
596
pDlg->nStartPage = START_PAGE_GENERAL;
597
res = pPrintDlgExW(pDlg);
598
ok(res == S_OK, "got 0x%lx (expected S_OK)\n", res);
599
GlobalFree(pDlg->hDevMode);
600
GlobalFree(pDlg->hDevNames);
601
602
/* this works: PD_RETURNDC with PD_RETURNDEFAULT */
603
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
604
pDlg->lStructSize = sizeof(PRINTDLGEXW);
605
pDlg->hwndOwner = GetDesktopWindow();
606
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS | PD_RETURNDC;
607
pDlg->nStartPage = START_PAGE_GENERAL;
608
res = pPrintDlgExW(pDlg);
609
ok(res == S_OK, "got 0x%lx (expected S_OK)\n", res);
610
ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNDC\n");
611
GlobalFree(pDlg->hDevMode);
612
GlobalFree(pDlg->hDevNames);
613
DeleteDC(pDlg->hDC);
614
615
/* this works: PD_RETURNIC with PD_RETURNDEFAULT */
616
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
617
pDlg->lStructSize = sizeof(PRINTDLGEXW);
618
pDlg->hwndOwner = GetDesktopWindow();
619
pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS | PD_RETURNIC;
620
pDlg->nStartPage = START_PAGE_GENERAL;
621
res = pPrintDlgExW(pDlg);
622
ok(res == S_OK, "got 0x%lx (expected S_OK)\n", res);
623
ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n");
624
GlobalFree(pDlg->hDevMode);
625
GlobalFree(pDlg->hDevNames);
626
DeleteDC(pDlg->hDC);
627
628
/* interactive PrintDlgEx tests */
629
630
if (!winetest_interactive)
631
{
632
skip("interactive PrintDlgEx tests (set WINETEST_INTERACTIVE=1)\n");
633
free(pDlg);
634
return;
635
}
636
637
ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
638
pDlg->lStructSize = sizeof(PRINTDLGEXW);
639
pDlg->hwndOwner = GetDesktopWindow();
640
pDlg->Flags = PD_NOPAGENUMS | PD_RETURNIC;
641
pDlg->nStartPage = START_PAGE_GENERAL;
642
pDlg->lpCallback = &unknown;
643
pDlg->dwResultAction = S_OK;
644
res = pPrintDlgExW(pDlg);
645
ok(res == S_OK, "got 0x%lx (expected S_OK)\n", res);
646
ok(pDlg->dwResultAction == PD_RESULT_PRINT, "expected PD_RESULT_PRINT, got %#lx\n", pDlg->dwResultAction);
647
ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n");
648
GlobalFree(pDlg->hDevMode);
649
GlobalFree(pDlg->hDevNames);
650
DeleteDC(pDlg->hDC);
651
652
free(pDlg);
653
}
654
655
static BOOL abort_proc_called = FALSE;
656
static BOOL CALLBACK abort_proc(HDC hdc, int error) { return abort_proc_called = TRUE; }
657
static void test_abort_proc(void)
658
{
659
HDC print_dc;
660
RECT rect = {0, 0, 100, 100};
661
DOCINFOA doc_info = {0};
662
PRINTDLGA pd = {0};
663
char filename[MAX_PATH];
664
int job_id;
665
666
if (!GetTempFileNameA(".", "prn", 0, filename))
667
{
668
skip("Failed to create a temporary file name\n");
669
return;
670
}
671
672
pd.lStructSize = sizeof(pd);
673
pd.Flags = PD_RETURNDEFAULT | PD_ALLPAGES | PD_RETURNDC | PD_PRINTTOFILE;
674
pd.nFromPage = 1;
675
pd.nToPage = 1;
676
pd.nCopies = 1;
677
678
if (!PrintDlgA(&pd))
679
{
680
skip("No default printer available.\n");
681
goto end;
682
}
683
GlobalFree(pd.hDevMode);
684
GlobalFree(pd.hDevNames);
685
686
ok(pd.hDC != NULL, "PrintDlg didn't return a DC.\n");
687
if (!(print_dc = pd.hDC))
688
goto end;
689
690
ok(SetAbortProc(print_dc, abort_proc) > 0, "SetAbortProc failed\n");
691
ok(!abort_proc_called, "AbortProc got called unexpectedly by SetAbortProc.\n");
692
abort_proc_called = FALSE;
693
694
doc_info.cbSize = sizeof(doc_info);
695
doc_info.lpszDocName = "Some document";
696
doc_info.lpszOutput = filename;
697
698
job_id = StartDocA(print_dc, &doc_info);
699
700
ok(job_id > 0 ||
701
GetLastError() == ERROR_SPL_NO_STARTDOC, /* Vista can fail with this error when using the XPS driver */
702
"StartDocA failed ret %d gle %ld\n", job_id, GetLastError());
703
704
if(job_id <= 0)
705
{
706
skip("StartDoc failed\n");
707
goto end;
708
}
709
710
/* StartDoc may or may not call abort proc */
711
712
abort_proc_called = FALSE;
713
ok(StartPage(print_dc) > 0, "StartPage failed\n");
714
ok(!abort_proc_called, "AbortProc got called unexpectedly by StartPage.\n");
715
abort_proc_called = FALSE;
716
717
/* following functions sometimes call abort proc too */
718
ok(FillRect(print_dc, &rect, (HBRUSH)(COLOR_BACKGROUND + 1)), "FillRect failed\n");
719
ok(EndPage(print_dc) > 0, "EndPage failed\n");
720
ok(EndDoc(print_dc) > 0, "EndDoc failed\n");
721
722
abort_proc_called = FALSE;
723
ok(DeleteDC(print_dc), "DeleteDC failed\n");
724
ok(!abort_proc_called, "AbortProc got called unexpectedly by DeleteDC.\n");
725
abort_proc_called = FALSE;
726
727
end:
728
SetLastError(0xdeadbeef);
729
if(!DeleteFileA(filename))
730
trace("Failed to delete temporary file (err = %lx)\n", GetLastError());
731
}
732
733
/* ########################### */
734
735
START_TEST(printdlg)
736
{
737
hcomdlg32 = GetModuleHandleA("comdlg32.dll");
738
pPrintDlgExW = (void *) GetProcAddress(hcomdlg32, "PrintDlgExW");
739
740
test_PageSetupDlgA();
741
test_PrintDlgA();
742
test_PrintDlgW();
743
test_PrintDlgExW();
744
test_abort_proc();
745
}
746
747