quartz: Make dwSamplesProcessed a longlong.
[wine] / dlls / comdlg32 / tests / printdlg.c
1 /* 
2  * Unit test suite for comdlg32 API functions: printer dialogs
3  *
4  * Copyright 2006-2007 Detlef Riekenberg
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "objbase.h"
30
31 #include "cderr.h"
32 #include "commdlg.h"
33
34 #include "wine/test.h"
35
36 /* ########################### */
37
38 static HMODULE  hcomdlg32;
39 static HRESULT (WINAPI * pPrintDlgExA)(LPPRINTDLGEXA);
40 static HRESULT (WINAPI * pPrintDlgExW)(LPPRINTDLGEXW);
41
42 /* ########################### */
43
44 static const CHAR emptyA[] = "";
45 static const CHAR PrinterPortsA[] = "PrinterPorts";
46
47 /* ########################### */
48
49 static LPCSTR load_functions(void)
50 {
51     LPCSTR  ptr;
52
53     ptr = "comdlg32.dll";
54     hcomdlg32 = LoadLibraryA(ptr);
55     if (!hcomdlg32) return ptr;
56
57     ptr = "PrintDlgExA";
58     pPrintDlgExA = (void *) GetProcAddress(hcomdlg32, ptr);
59     if (!pPrintDlgExA) return ptr;
60
61     ptr = "PrintDlgExW";
62     pPrintDlgExW = (void *) GetProcAddress(hcomdlg32, ptr);
63     if (!pPrintDlgExW) return ptr;
64
65     return NULL;
66
67 }
68
69 /* ########################### */
70
71 static void test_PageSetupDlgA(void)
72 {
73     LPPAGESETUPDLGA pDlg;
74     DWORD res;
75
76     pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA)) * 2);
77     if (!pDlg) return;
78
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());
84
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());
92
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());
101
102
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());
111
112     if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
113         skip("No printer configured.\n");
114         HeapFree(GetProcessHeap(), 0, pDlg);
115         return;
116     }
117
118     ok( pDlg->hDevMode && pDlg->hDevNames,
119         "got %p and %p (expected '!= NULL' for both)\n",
120         pDlg->hDevMode, pDlg->hDevNames);
121
122     GlobalFree(pDlg->hDevMode);
123     GlobalFree(pDlg->hDevNames);
124
125     HeapFree(GetProcessHeap(), 0, pDlg);
126
127 }
128
129 /* ########################### */
130
131 static void test_PrintDlgA(void)
132 {
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;
141
142
143     pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2);
144     if (!pDlg) return;
145
146
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());
153
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());
161
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());
170
171
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());
180
181     if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
182         skip("No printer configured.\n");
183         HeapFree(GetProcessHeap(), 0, pDlg);
184         return;
185     }
186
187     ok(pDlg->hDevNames != NULL, "(expected '!= NULL')\n");
188     pDevNames = GlobalLock(pDlg->hDevNames);
189     ok(pDevNames != NULL, "(expected '!= NULL')\n");
190
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);
196
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);
201
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);
206         }
207
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);
212         }
213
214
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);
223         }
224
225         if (ptr) ptr[0] = '\0';
226         todo_wine {
227         ok( lstrcmpiA(driver, buffer) == 0,
228             "got driver '%s' (expected '%s')\n", driver, buffer);
229         }
230
231     }
232
233     GlobalUnlock(pDlg->hDevNames);
234
235     GlobalFree(pDlg->hDevMode);
236     GlobalFree(pDlg->hDevNames);
237     HeapFree(GetProcessHeap(), 0, pDlg);
238
239 }
240
241 /* ########################### */
242
243 static void test_PrintDlgExW(void)
244 {
245     LPPRINTDLGEXW pDlg;
246     HRESULT res;
247
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());
255
256
257     pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGEXW)) + 8);
258     if (!pDlg) return;
259
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());
269
270
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());
279
280
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());
288
289
290     HeapFree(GetProcessHeap(), 0, pDlg);
291     return;
292
293 }
294
295 /* ########################### */
296
297 START_TEST(printdlg)
298 {
299     LPCSTR  ptr;
300
301     ptr = load_functions();
302
303     test_PageSetupDlgA();
304     test_PrintDlgA();
305
306     /* PrintDlgEx not present before w2k */
307     if (ptr) {
308         skip("%s\n", ptr);
309         return;
310     }
311
312     test_PrintDlgExW();
313 }