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"
38 static const CHAR emptyA
[] = "";
39 static const CHAR PrinterPortsA
[] = "PrinterPorts";
43 static void test_PageSetupDlgA(void)
48 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA
)) * 2);
51 SetLastError(0xdeadbeef);
52 res
= PageSetupDlgA(NULL
);
53 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
54 "returned %u with %u and 0x%x (expected '0' and "
55 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
57 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
58 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) -1;
59 SetLastError(0xdeadbeef);
60 res
= PageSetupDlgA(pDlg
);
61 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
62 "returned %u with %u and 0x%x (expected '0' and "
63 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
65 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
66 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) +1;
67 pDlg
->Flags
= PSD_RETURNDEFAULT
;
68 SetLastError(0xdeadbeef);
69 res
= PageSetupDlgA(pDlg
);
70 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
71 "returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
72 res
, GetLastError(), CommDlgExtendedError());
75 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
76 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
);
77 pDlg
->Flags
= PSD_RETURNDEFAULT
;
78 SetLastError(0xdeadbeef);
79 res
= PageSetupDlgA(pDlg
);
80 trace("after pagesetupdlga res = %d, le %d, ext error 0x%x\n",
81 res
, GetLastError(), CommDlgExtendedError());
82 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
83 "returned %u with %u and 0x%x (expected '!= 0' or '0' and "
84 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
85 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
86 skip("No printer configured.\n");
87 HeapFree(GetProcessHeap(), 0, pDlg
);
90 ok( pDlg
->hDevMode
&& pDlg
->hDevNames
,
91 "got %p and %p (expected '!= NULL' for both)\n",
92 pDlg
->hDevMode
, pDlg
->hDevNames
);
94 GlobalFree(pDlg
->hDevMode
);
95 GlobalFree(pDlg
->hDevNames
);
97 HeapFree(GetProcessHeap(), 0, pDlg
);
103 static void test_PrintDlgA(void)
111 CHAR buffer
[MAX_PATH
];
115 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA
)) * 2);
119 /* will crash with unpatched wine */
120 SetLastError(0xdeadbeef);
121 res
= PrintDlgA(NULL
);
122 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
123 "returned %d with 0x%x and 0x%x (expected '0' and "
124 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
126 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
127 pDlg
->lStructSize
= sizeof(PRINTDLGA
) - 1;
128 SetLastError(0xdeadbeef);
129 res
= PrintDlgA(pDlg
);
130 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
131 "returned %d with 0x%x and 0x%x (expected '0' and "
132 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
134 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
135 pDlg
->lStructSize
= sizeof(PRINTDLGA
) + 1;
136 pDlg
->Flags
= PD_RETURNDEFAULT
;
137 SetLastError(0xdeadbeef);
138 res
= PrintDlgA(pDlg
);
139 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
140 "returned %u with %u and 0x%x (expected '0' and "
141 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
144 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
145 pDlg
->lStructSize
= sizeof(PRINTDLGA
);
146 pDlg
->Flags
= PD_RETURNDEFAULT
;
147 SetLastError(0xdeadbeef);
148 res
= PrintDlgA(pDlg
);
149 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
150 "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
151 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
153 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
154 skip("No printer configured.\n");
155 HeapFree(GetProcessHeap(), 0, pDlg
);
159 ok(pDlg
->hDevNames
!= NULL
, "(expected '!= NULL')\n");
160 pDevNames
= GlobalLock(pDlg
->hDevNames
);
161 ok(pDevNames
!= NULL
, "(expected '!= NULL')\n");
164 ok(pDevNames
->wDriverOffset
, "(expected '!= 0' for wDriverOffset)\n");
165 ok(pDevNames
->wDeviceOffset
, "(expected '!= 0' for wDeviceOffset)\n");
166 ok(pDevNames
->wOutputOffset
, "(expected '!= 0' for wOutputOffset)\n");
167 ok(pDevNames
->wDefault
== DN_DEFAULTPRN
, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames
->wDefault
);
169 driver
= (LPCSTR
)pDevNames
+ pDevNames
->wDriverOffset
;
170 device
= (LPCSTR
)pDevNames
+ pDevNames
->wDeviceOffset
;
171 port
= (LPCSTR
)pDevNames
+ pDevNames
->wOutputOffset
;
172 trace("driver '%s' device '%s' port '%s'\n", driver
, device
, port
);
174 /* The Driver Entry does not include a Path */
175 ptr
= strrchr(driver
, '\\');
177 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for a simple name)\n", ptr
, driver
);
180 /* The Driver Entry does not have an extension (fixed to ".drv") */
181 ptr
= strrchr(driver
, '.');
183 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for no extension)\n", ptr
, driver
);
188 SetLastError(0xdeadbeef);
189 res
= GetProfileStringA(PrinterPortsA
, device
, emptyA
, buffer
, sizeof(buffer
));
190 ptr
= strchr(buffer
, ',');
192 ok( (res
> 1) && (ptr
!= NULL
),
193 "got %u with %u and %p for '%s' (expected '>1' and '!= NULL')\n",
194 res
, GetLastError(), ptr
, buffer
);
197 if (ptr
) ptr
[0] = '\0';
199 ok( lstrcmpiA(driver
, buffer
) == 0,
200 "got driver '%s' (expected '%s')\n", driver
, buffer
);
205 GlobalUnlock(pDlg
->hDevNames
);
207 GlobalFree(pDlg
->hDevMode
);
208 GlobalFree(pDlg
->hDevNames
);
209 HeapFree(GetProcessHeap(), 0, pDlg
);
216 test_PageSetupDlgA();