2 * Unit test suite for comdlg32 API functions: printer dialogs
4 * Copyright 2006-2007 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/test.h"
36 /* ########################### */
38 static HMODULE hcomdlg32
;
39 static HRESULT (WINAPI
* pPrintDlgExA
)(LPPRINTDLGEXA
);
40 static HRESULT (WINAPI
* pPrintDlgExW
)(LPPRINTDLGEXW
);
42 /* ########################### */
44 static const CHAR emptyA
[] = "";
45 static const CHAR PrinterPortsA
[] = "PrinterPorts";
47 /* ########################### */
49 static LPCSTR
load_functions(void)
54 hcomdlg32
= LoadLibraryA(ptr
);
55 if (!hcomdlg32
) return ptr
;
58 pPrintDlgExA
= (void *) GetProcAddress(hcomdlg32
, ptr
);
59 if (!pPrintDlgExA
) return ptr
;
62 pPrintDlgExW
= (void *) GetProcAddress(hcomdlg32
, ptr
);
63 if (!pPrintDlgExW
) return ptr
;
69 /* ########################### */
71 static void test_PageSetupDlgA(void)
76 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA
)) * 2);
79 SetLastError(0xdeadbeef);
80 res
= PageSetupDlgA(NULL
);
81 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
82 "returned %u with %u and 0x%x (expected '0' and "
83 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
85 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
86 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) -1;
87 SetLastError(0xdeadbeef);
88 res
= PageSetupDlgA(pDlg
);
89 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
90 "returned %u with %u and 0x%x (expected '0' and "
91 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
93 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
94 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) +1;
95 pDlg
->Flags
= PSD_RETURNDEFAULT
;
96 SetLastError(0xdeadbeef);
97 res
= PageSetupDlgA(pDlg
);
98 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
99 "returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
100 res
, GetLastError(), CommDlgExtendedError());
103 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
104 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
);
105 pDlg
->Flags
= PSD_RETURNDEFAULT
| PSD_NOWARNING
;
106 SetLastError(0xdeadbeef);
107 res
= PageSetupDlgA(pDlg
);
108 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
109 "returned %u with %u and 0x%x (expected '!= 0' or '0' and "
110 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
112 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
113 skip("No printer configured.\n");
114 HeapFree(GetProcessHeap(), 0, pDlg
);
118 ok( pDlg
->hDevMode
&& pDlg
->hDevNames
,
119 "got %p and %p (expected '!= NULL' for both)\n",
120 pDlg
->hDevMode
, pDlg
->hDevNames
);
122 GlobalFree(pDlg
->hDevMode
);
123 GlobalFree(pDlg
->hDevNames
);
125 HeapFree(GetProcessHeap(), 0, pDlg
);
129 /* ########################### */
131 static void test_PrintDlgA(void)
139 CHAR buffer
[MAX_PATH
];
143 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA
)) * 2);
147 /* will crash with unpatched wine */
148 SetLastError(0xdeadbeef);
149 res
= PrintDlgA(NULL
);
150 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
151 "returned %d with 0x%x and 0x%x (expected '0' and "
152 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
154 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
155 pDlg
->lStructSize
= sizeof(PRINTDLGA
) - 1;
156 SetLastError(0xdeadbeef);
157 res
= PrintDlgA(pDlg
);
158 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
159 "returned %d with 0x%x and 0x%x (expected '0' and "
160 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
162 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
163 pDlg
->lStructSize
= sizeof(PRINTDLGA
) + 1;
164 pDlg
->Flags
= PD_RETURNDEFAULT
;
165 SetLastError(0xdeadbeef);
166 res
= PrintDlgA(pDlg
);
167 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
168 "returned %u with %u and 0x%x (expected '0' and "
169 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
172 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
173 pDlg
->lStructSize
= sizeof(PRINTDLGA
);
174 pDlg
->Flags
= PD_RETURNDEFAULT
;
175 SetLastError(0xdeadbeef);
176 res
= PrintDlgA(pDlg
);
177 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
178 "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
179 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
181 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
182 skip("No printer configured.\n");
183 HeapFree(GetProcessHeap(), 0, pDlg
);
187 ok(pDlg
->hDevNames
!= NULL
, "(expected '!= NULL')\n");
188 pDevNames
= GlobalLock(pDlg
->hDevNames
);
189 ok(pDevNames
!= NULL
, "(expected '!= NULL')\n");
192 ok(pDevNames
->wDriverOffset
, "(expected '!= 0' for wDriverOffset)\n");
193 ok(pDevNames
->wDeviceOffset
, "(expected '!= 0' for wDeviceOffset)\n");
194 ok(pDevNames
->wOutputOffset
, "(expected '!= 0' for wOutputOffset)\n");
195 ok(pDevNames
->wDefault
== DN_DEFAULTPRN
, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames
->wDefault
);
197 driver
= (LPCSTR
)pDevNames
+ pDevNames
->wDriverOffset
;
198 device
= (LPCSTR
)pDevNames
+ pDevNames
->wDeviceOffset
;
199 port
= (LPCSTR
)pDevNames
+ pDevNames
->wOutputOffset
;
200 trace("driver '%s' device '%s' port '%s'\n", driver
, device
, port
);
202 /* The Driver Entry does not include a Path */
203 ptr
= strrchr(driver
, '\\');
205 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for a simple name)\n", ptr
, driver
);
208 /* The Driver Entry does not have an extension (fixed to ".drv") */
209 ptr
= strrchr(driver
, '.');
211 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for no extension)\n", ptr
, driver
);
216 SetLastError(0xdeadbeef);
217 res
= GetProfileStringA(PrinterPortsA
, device
, emptyA
, buffer
, sizeof(buffer
));
218 ptr
= strchr(buffer
, ',');
220 ok( (res
> 1) && (ptr
!= NULL
),
221 "got %u with %u and %p for '%s' (expected '>1' and '!= NULL')\n",
222 res
, GetLastError(), ptr
, buffer
);
225 if (ptr
) ptr
[0] = '\0';
227 ok( lstrcmpiA(driver
, buffer
) == 0,
228 "got driver '%s' (expected '%s')\n", driver
, buffer
);
233 GlobalUnlock(pDlg
->hDevNames
);
235 GlobalFree(pDlg
->hDevMode
);
236 GlobalFree(pDlg
->hDevNames
);
237 HeapFree(GetProcessHeap(), 0, pDlg
);
241 /* ########################### */
243 static void test_PrintDlgExW(void)
248 /* Set CommDlgExtendedError != 0 */
250 SetLastError(0xdeadbeef);
251 res
= pPrintDlgExW(NULL
);
252 ok( (res
== E_INVALIDARG
),
253 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
254 res
, GetLastError(), CommDlgExtendedError());
257 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGEXW
)) + 8);
260 /* lStructSize must be exact */
261 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
262 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
) - 1;
264 SetLastError(0xdeadbeef);
265 res
= pPrintDlgExW(pDlg
);
266 ok( (res
== E_INVALIDARG
),
267 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
268 res
, GetLastError(), CommDlgExtendedError());
271 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
272 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
) + 1;
274 SetLastError(0xdeadbeef);
275 res
= pPrintDlgExW(pDlg
);
276 ok( (res
== E_INVALIDARG
),
277 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
278 res
, GetLastError(), CommDlgExtendedError());
281 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
282 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
283 SetLastError(0xdeadbeef);
284 res
= pPrintDlgExW(pDlg
);
285 ok( (res
== E_HANDLE
),
286 "got 0x%x with %u and %u (expected 'E_HANDLE')\n",
287 res
, GetLastError(), CommDlgExtendedError());
290 HeapFree(GetProcessHeap(), 0, pDlg
);
295 /* ########################### */
301 ptr
= load_functions();
303 test_PageSetupDlgA();
306 /* PrintDlgEx not present before w2k */