comctl32: We can now store binary files in the repository.
[wine] / dlls / comdlg32 / tests / printdlg.c
1 /* 
2  * Unit test suite for comdlg32 API functions: printer dialogs
3  *
4  * Copyright 2006 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 "wingdi.h"
29 #include "winuser.h"
30
31 #include "cderr.h"
32 #include "commdlg.h"
33
34 #include "wine/test.h"
35
36
37 /* ######## */
38
39 static void test_PageSetupDlgA(void)
40 {
41     LPPAGESETUPDLGA pDlg;
42     DWORD res;
43
44     pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA)) * 2);
45     if (!pDlg) return;
46
47     SetLastError(0xdeadbeef);
48     res = PageSetupDlgA(NULL);
49     ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
50         "returned %u with %u and 0x%x (expected '0' and "
51         "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
52
53     ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
54     pDlg->lStructSize = sizeof(PAGESETUPDLGA) -1;
55     SetLastError(0xdeadbeef);
56     res = PageSetupDlgA(pDlg);
57     ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
58         "returned %u with %u and 0x%x (expected '0' and "
59         "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
60
61     ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
62     pDlg->lStructSize = sizeof(PAGESETUPDLGA) +1;
63     pDlg->Flags = PSD_RETURNDEFAULT;
64     SetLastError(0xdeadbeef);
65     res = PageSetupDlgA(pDlg);
66     ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
67         "returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
68         res, GetLastError(), CommDlgExtendedError());
69
70
71     ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
72     pDlg->lStructSize = sizeof(PAGESETUPDLGA);
73     pDlg->Flags = PSD_RETURNDEFAULT;
74     SetLastError(0xdeadbeef);
75     res = PageSetupDlgA(pDlg);
76     trace("after pagesetupdlga res = %d, le %d, ext error 0x%x\n",
77         res, GetLastError(), CommDlgExtendedError());
78     ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
79         "returned %u with %u and 0x%x (expected '!= 0' or '0' and "
80         "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
81     if (!res && (CommDlgExtendedError() == PDERR_NODEFAULTPRN)) {
82         skip("No printer configured.\n");
83         HeapFree(GetProcessHeap(), 0, pDlg);
84         return;
85     }
86     ok( pDlg->hDevMode && pDlg->hDevNames,
87         "got %p and %p (expected '!= NULL' for both)\n",
88         pDlg->hDevMode, pDlg->hDevNames);
89
90     GlobalFree(pDlg->hDevMode);
91     GlobalFree(pDlg->hDevNames);
92
93     HeapFree(GetProcessHeap(), 0, pDlg);
94
95 }
96
97 /* ##### */
98
99 static void test_PrintDlgA(void)
100 {
101     DWORD       res;
102     LPPRINTDLGA pDlg;
103
104
105     pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2);
106     if (!pDlg) return;
107
108
109     /* will crash with unpatched wine */
110     SetLastError(0xdeadbeef);
111     res = PrintDlgA(NULL);
112     ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
113         "returned %d with 0x%x and 0x%x (expected '0' and "
114         "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
115
116     ZeroMemory(pDlg, sizeof(PRINTDLGA));
117     pDlg->lStructSize = sizeof(PRINTDLGA) - 1;
118     SetLastError(0xdeadbeef);
119     res = PrintDlgA(pDlg);
120     ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
121         "returned %d with 0x%x and 0x%x (expected '0' and "
122         "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
123
124     ZeroMemory(pDlg, sizeof(PRINTDLGA));
125     pDlg->lStructSize = sizeof(PRINTDLGA) + 1;
126     pDlg->Flags = PD_RETURNDEFAULT;
127     SetLastError(0xdeadbeef);
128     res = PrintDlgA(pDlg);
129     ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
130         "returned %u with %u and 0x%x (expected '0' and "
131         "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
132
133
134     ZeroMemory(pDlg, sizeof(PRINTDLGA));
135     pDlg->lStructSize = sizeof(PRINTDLGA);
136     pDlg->Flags = PD_RETURNDEFAULT;
137     SetLastError(0xdeadbeef);
138     res = PrintDlgA(pDlg);
139     ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
140         "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
141         "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
142
143     HeapFree(GetProcessHeap(), 0, pDlg);
144
145 }
146
147
148 START_TEST(printdlg)
149 {
150     test_PageSetupDlgA();
151     test_PrintDlgA();
152
153 }