2 * Unit test suite for the Local Printmonitor User Interface
4 * Copyright 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
33 #include "ddk/winsplp.h"
35 #include "wine/test.h"
41 static PMONITORUI (WINAPI
*pInitializePrintMonitorUI
)(VOID
);
42 static PMONITORUI pui
;
43 static BOOL (WINAPI
*pAddPortUI
)(PCWSTR
, HWND
, PCWSTR
, PWSTR
*);
44 static BOOL (WINAPI
*pConfigurePortUI
)(PCWSTR
, HWND
, PCWSTR
);
45 static BOOL (WINAPI
*pDeletePortUI
)(PCWSTR
, HWND
, PCWSTR
);
47 static WCHAR does_not_existW
[] = {'d','o','e','s','_','n','o','t','_','e','x','i','s','t',0};
48 static WCHAR emptyW
[] = {0};
49 static CHAR fmt_comA
[] = {'C','O','M','%','u',':',0};
50 static CHAR fmt_lptA
[] = {'L','P','T','%','u',':',0};
51 static WCHAR localportW
[] = {'L','o','c','a','l',' ','P','o','r','t',0};
52 static WCHAR portname_fileW
[] = {'F','I','L','E',':',0};
54 static LPBYTE pi_buffer
;
55 static DWORD pi_numports
;
56 static DWORD pi_needed
;
58 static PORT_INFO_2W
* lpt_present
;
59 static PORT_INFO_2W
* com_present
;
60 static PORT_INFO_2W
* file_present
;
62 static LPWSTR lpt_absent
;
63 static LPWSTR com_absent
;
65 /* ########################### */
67 static PORT_INFO_2W
* find_portinfo2(LPWSTR pPort
)
73 res
= EnumPortsW(NULL
, 2, NULL
, 0, &pi_needed
, &pi_numports
);
74 pi_buffer
= HeapAlloc(GetProcessHeap(), 0, pi_needed
);
75 SetLastError(0xdeadbeef);
76 res
= EnumPortsW(NULL
, 2, pi_buffer
, pi_needed
, &pi_needed
, &pi_numports
);
79 pi
= (PORT_INFO_2W
*) pi_buffer
;
81 while (pi_numports
> res
) {
82 if (lstrcmpiW(pi
->pPortName
, pPort
) == 0) {
93 /* ########################### */
95 static LPCSTR
load_functions(void)
100 hdll
= LoadLibraryA(ptr
);
101 if (!hdll
) return ptr
;
103 ptr
= "InitializePrintMonitorUI";
104 pInitializePrintMonitorUI
= (VOID
*) GetProcAddress(hdll
, ptr
);
105 if (!pInitializePrintMonitorUI
) return ptr
;
110 /* ###########################
114 static LPWSTR
strdupW(LPCWSTR strW
)
118 ptr
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(strW
) + 1) * sizeof(WCHAR
));
125 /* ########################### */
127 static void test_AddPortUI(void)
132 /* not present before w2k */
134 skip("AddPortUI not found\n");
138 SetLastError(0xdeadbeef);
139 res
= pAddPortUI(NULL
, NULL
, NULL
, NULL
);
140 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
141 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
142 res
, GetLastError());
144 SetLastError(0xdeadbeef);
145 res
= pAddPortUI(NULL
, NULL
, emptyW
, NULL
);
146 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
147 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
148 res
, GetLastError());
150 SetLastError(0xdeadbeef);
151 res
= pAddPortUI(NULL
, NULL
, does_not_existW
, NULL
);
152 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
153 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
154 res
, GetLastError());
156 if (winetest_interactive
) {
157 SetLastError(0xdeadbeef);
160 * - On MSDN, you can read, that no dialogs should be displayed, when hWnd
161 * is NULL, but native localui does not care
162 * - when the new port already exist,
163 * TRUE is returned, but new_portname is NULL
164 * - when the new port starts with "COM" or "LPT",
165 * FALSE is returned with ERROR_NOT_SUPPORTED in windows
167 res
= pAddPortUI(NULL
, NULL
, localportW
, &new_portname
);
169 (GetLastError() == ERROR_CANCELLED
) ||
170 (GetLastError() == ERROR_ACCESS_DENIED
) ||
171 (GetLastError() == ERROR_NOT_SUPPORTED
),
172 "got %d with %u and %p (expected '!= 0' or '0' with: "
173 "ERROR_CANCELLED, ERROR_ACCESS_DENIED or ERROR_NOT_SUPPORTED)\n",
174 res
, GetLastError(), new_portname
);
176 GlobalFree(new_portname
);
180 /* ########################### */
182 static void test_ConfigurePortUI(void)
186 /* not present before w2k */
187 if (!pConfigurePortUI
) {
188 skip("ConfigurePortUI not found\n");
192 SetLastError(0xdeadbeef);
193 res
= pConfigurePortUI(NULL
, NULL
, NULL
);
194 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
195 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
196 res
, GetLastError());
199 SetLastError(0xdeadbeef);
200 res
= pConfigurePortUI(NULL
, NULL
, emptyW
);
201 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
202 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
203 res
, GetLastError());
206 SetLastError(0xdeadbeef);
207 res
= pConfigurePortUI(NULL
, NULL
, does_not_existW
);
208 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
209 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
210 res
, GetLastError());
213 if (winetest_interactive
&& lpt_present
) {
214 SetLastError(0xdeadbeef);
215 res
= pConfigurePortUI(NULL
, NULL
, lpt_present
->pPortName
);
217 (GetLastError() == ERROR_CANCELLED
) || (GetLastError() == ERROR_ACCESS_DENIED
),
218 "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
219 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
223 SetLastError(0xdeadbeef);
224 res
= pConfigurePortUI(NULL
, NULL
, lpt_absent
);
225 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
226 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
227 res
, GetLastError());
230 if (winetest_interactive
&& com_present
) {
231 SetLastError(0xdeadbeef);
232 res
= pConfigurePortUI(NULL
, NULL
, com_present
->pPortName
);
234 (GetLastError() == ERROR_CANCELLED
) || (GetLastError() == ERROR_ACCESS_DENIED
),
235 "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
236 "ERROR_ACCESS_DENIED)\n", res
, GetLastError());
240 SetLastError(0xdeadbeef);
241 res
= pConfigurePortUI(NULL
, NULL
, com_absent
);
242 ok( !res
&& (GetLastError() == ERROR_UNKNOWN_PORT
),
243 "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
244 res
, GetLastError());
247 if (winetest_interactive
&& file_present
) {
248 SetLastError(0xdeadbeef);
249 res
= pConfigurePortUI(NULL
, NULL
, portname_fileW
);
250 ok( !res
&& (GetLastError() == ERROR_CANCELLED
),
251 "got %d with %u (expected '0' with ERROR_CANCELLED)\n",
252 res
, GetLastError());
256 /* ########################### */
267 /* localui.dll does not exist before w2k */
268 ptr
= load_functions();
270 skip("%s not found\n", ptr
);
274 pui
= pInitializePrintMonitorUI();
276 numentries
= (pui
->dwMonitorUISize
- sizeof(DWORD
)) / sizeof(VOID
*);
278 "dwMonitorUISize (%d) => %d Functions\n", pui
->dwMonitorUISize
, numentries
);
280 if (numentries
> 2) {
281 pAddPortUI
= pui
->pfnAddPortUI
;
282 pConfigurePortUI
= pui
->pfnConfigurePortUI
;
283 pDeletePortUI
= pui
->pfnDeletePortUI
;
287 /* find installed Ports */
290 /* "LPT1:" - "LPT9:" */
291 while (((lpt_present
== NULL
) || (lpt_absent
== NULL
)) && id
< 9) {
293 sprintf(bufferA
, fmt_lptA
, id
);
294 MultiByteToWideChar( CP_ACP
, 0, bufferA
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
295 pi2
= find_portinfo2(bufferW
);
296 if (pi2
&& (lpt_present
== NULL
)) lpt_present
= pi2
;
297 if (!pi2
&& (lpt_absent
== NULL
)) lpt_absent
= strdupW(bufferW
);
301 /* "COM1:" - "COM9:" */
302 while (((com_present
== NULL
) || (com_absent
== NULL
)) && id
< 9) {
304 sprintf(bufferA
, fmt_comA
, id
);
305 MultiByteToWideChar( CP_ACP
, 0, bufferA
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
306 pi2
= find_portinfo2(bufferW
);
307 if (pi2
&& (com_present
== NULL
)) com_present
= pi2
;
308 if (!pi2
&& (com_absent
== NULL
)) com_absent
= strdupW(bufferW
);
312 file_present
= find_portinfo2(portname_fileW
);
315 test_ConfigurePortUI();
318 HeapFree(GetProcessHeap(), 0, lpt_absent
);
319 HeapFree(GetProcessHeap(), 0, com_absent
);
320 HeapFree(GetProcessHeap(), 0, pi_buffer
);