comdlg32/tests: Initial tests for PrintDlgExW.
[wine.git] / dlls / comdlg32 / tests / printdlg.c
blob9842b17599a87f921e7f5504a6ca2d74df64283b
1 /*
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
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "wingdi.h"
29 #include "winuser.h"
31 #include "cderr.h"
32 #include "commdlg.h"
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)
51 LPCSTR ptr;
53 ptr = "comdlg32.dll";
54 hcomdlg32 = LoadLibraryA(ptr);
55 if (!hcomdlg32) return ptr;
57 ptr = "PrintDlgExA";
58 pPrintDlgExA = (void *) GetProcAddress(hcomdlg32, ptr);
59 if (!pPrintDlgExA) return ptr;
61 ptr = "PrintDlgExW";
62 pPrintDlgExW = (void *) GetProcAddress(hcomdlg32, ptr);
63 if (!pPrintDlgExW) return ptr;
65 return NULL;
69 /* ########################### */
71 static void test_PageSetupDlgA(void)
73 LPPAGESETUPDLGA pDlg;
74 DWORD res;
76 pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA)) * 2);
77 if (!pDlg) return;
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);
115 return;
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)
133 DWORD res;
134 LPPRINTDLGA pDlg;
135 DEVNAMES *pDevNames;
136 LPCSTR driver;
137 LPCSTR device;
138 LPCSTR port;
139 CHAR buffer[MAX_PATH];
140 LPSTR ptr;
143 pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2);
144 if (!pDlg) return;
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);
184 return;
187 ok(pDlg->hDevNames != NULL, "(expected '!= NULL')\n");
188 pDevNames = GlobalLock(pDlg->hDevNames);
189 ok(pDevNames != NULL, "(expected '!= NULL')\n");
191 if (pDevNames) {
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, '\\');
204 todo_wine {
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, '.');
210 todo_wine {
211 ok( ptr == NULL, "got %p for '%s' (expected NULL for no extension)\n", ptr, driver);
215 buffer[0] = '\0';
216 SetLastError(0xdeadbeef);
217 res = GetProfileStringA(PrinterPortsA, device, emptyA, buffer, sizeof(buffer));
218 ptr = strchr(buffer, ',');
219 todo_wine {
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';
226 todo_wine {
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)
245 LPPRINTDLGEXW pDlg;
246 HRESULT res;
248 /* Set CommDlgExtendedError != 0 */
249 PrintDlg(NULL);
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);
258 if (!pDlg) return;
260 /* lStructSize must be exact */
261 ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
262 pDlg->lStructSize = sizeof(PRINTDLGEXW) - 1;
263 PrintDlg(NULL);
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;
273 PrintDlg(NULL);
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);
291 return;
295 /* ########################### */
297 START_TEST(printdlg)
299 LPCSTR ptr;
301 ptr = load_functions();
303 test_PageSetupDlgA();
304 test_PrintDlgA();
306 /* PrintDlgEx not present before w2k */
307 if (ptr) {
308 skip("%s\n", ptr);
309 return;
312 test_PrintDlgExW();