2 * Unit test suite for serialui API functions
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
30 #include "wine/test.h"
33 static HINSTANCE hdll
;
34 static DWORD (WINAPI
*pCommConfigDialogA
)(LPCSTR
, HWND
, LPCOMMCONFIG
);
35 static DWORD (WINAPI
*pCommConfigDialogW
)(LPCWSTR
, HWND
, LPCOMMCONFIG
);
36 static DWORD (WINAPI
*pGetDefaultCommConfigA
)(LPCSTR
, LPCOMMCONFIG
, LPDWORD
);
37 static DWORD (WINAPI
*pGetDefaultCommConfigW
)(LPCWSTR
, LPCOMMCONFIG
, LPDWORD
);
40 static const CHAR com1A
[] = "com1";
41 static const CHAR emptyA
[] = "";
42 static const CHAR fmt_comA
[] = "com%d";
43 static const CHAR str_colonA
[] = ":";
45 static const WCHAR com1W
[] = {'c','o','m','1',0};
46 static const WCHAR emptyW
[] = {0};
47 static const WCHAR str_colonW
[] = {':',0};
49 /* ################# */
51 static LPCSTR
load_functions(void)
56 hdll
= LoadLibraryA(ptr
);
57 if (!hdll
) return ptr
;
59 ptr
= "drvCommConfigDialogA";
60 pCommConfigDialogA
= (VOID
*) GetProcAddress(hdll
, ptr
);
61 if (!pCommConfigDialogA
) return ptr
;
63 ptr
= "drvCommConfigDialogW";
64 pCommConfigDialogW
= (VOID
*) GetProcAddress(hdll
, ptr
);
65 if (!pCommConfigDialogW
) return ptr
;
67 ptr
= "drvGetDefaultCommConfigA";
68 pGetDefaultCommConfigA
= (VOID
*) GetProcAddress(hdll
, ptr
);
69 if (!pGetDefaultCommConfigA
) return ptr
;
71 ptr
= "drvGetDefaultCommConfigW";
72 pGetDefaultCommConfigW
= (VOID
*) GetProcAddress(hdll
, ptr
);
73 if (!pGetDefaultCommConfigW
) return ptr
;
79 /* ################# */
81 static void test_drvCommConfigDialogA(void)
90 /* test ports "com1" - "com4" */
91 for (i
= 1; i
< 5 ; i
++) {
92 sprintf(bufferA
, fmt_comA
, i
);
94 ZeroMemory(pCC
, sizeof(pCC
));
95 SetLastError(0xdeadbeef);
96 res
= pGetDefaultCommConfigA(bufferA
, pCC
, &len
);
97 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
98 /* NT does not implement the ANSI API */
99 win_skip("*A not implemented\n");
103 if (res
== ERROR_SUCCESS
) {
105 if (winetest_interactive
) {
106 SetLastError(0xdeadbeef);
107 res
= pCommConfigDialogA(bufferA
, NULL
, pCC
);
108 /* OK: ERROR_SUCCESS, Cancel: ERROR_CANCELLED */
109 trace("returned %u with %u for '%s'\n", res
, GetLastError(), bufferA
);
112 ZeroMemory(pCC
, sizeof(pCC
));
113 SetLastError(0xdeadbeef);
114 res
= pCommConfigDialogA(bufferA
, NULL
, pCC
);
115 ok( res
== ERROR_INSUFFICIENT_BUFFER
,
116 "returned %u with %u for '%s' (expected ERROR_INSUFFICIENT_BUFFER)\n",
117 res
, GetLastError(), bufferA
);
120 SetLastError(0xdeadbeef);
121 res
= pCommConfigDialogA(bufferA
, NULL
, NULL
);
122 ok( res
== ERROR_INVALID_PARAMETER
,
123 "returned %u with %u for '%s' (expected ERROR_INVALID_PARAMETER)\n",
124 res
, GetLastError(), bufferA
);
129 ZeroMemory(pCC
, sizeof(pCC
));
130 SetLastError(0xdeadbeef);
131 res
= pCommConfigDialogA(emptyA
, NULL
, pCC
);
132 ok( res
== ERROR_INSUFFICIENT_BUFFER
,
133 "returned %u with %u (expected ERROR_INSUFFICIENT_BUFFER)\n",
134 res
, GetLastError());
137 ZeroMemory(pCC
, sizeof(pCC
));
138 pCC
[0].dwSize
= sizeof(COMMCONFIG
);
139 SetLastError(0xdeadbeef);
140 res
= pCommConfigDialogA(emptyA
, NULL
, pCC
);
141 ok( res
== ERROR_BADKEY
, "returned %u with %u (expected ERROR_BADKEY)\n",
142 res
, GetLastError());
145 ZeroMemory(pCC
, sizeof(pCC
));
146 SetLastError(0xdeadbeef);
147 res
= pCommConfigDialogA(NULL
, NULL
, pCC
);
148 ok( res
== ERROR_INVALID_PARAMETER
,
149 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
150 res
, GetLastError());
153 /* ################# */
155 static void test_drvCommConfigDialogW(void)
165 /* test ports "com1" - "com4" */
166 for (i
= 1; i
< 5 ; i
++) {
167 sprintf(bufferA
, fmt_comA
, i
);
168 MultiByteToWideChar( CP_ACP
, 0, bufferA
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
170 ZeroMemory(pCC
, sizeof(pCC
));
171 SetLastError(0xdeadbeef);
172 res
= pGetDefaultCommConfigW(bufferW
, pCC
, &len
);
173 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
174 win_skip("*W not implemented\n");
178 if (res
== ERROR_SUCCESS
) {
180 if (winetest_interactive
) {
181 SetLastError(0xdeadbeef);
182 res
= pCommConfigDialogW(bufferW
, NULL
, pCC
);
183 /* OK: ERROR_SUCCESS, Cancel: ERROR_CANCELLED */
184 trace("returned %u with %u for '%s'\n", res
, GetLastError(), bufferA
);
187 ZeroMemory(pCC
, sizeof(pCC
));
188 SetLastError(0xdeadbeef);
189 res
= pCommConfigDialogW(bufferW
, NULL
, pCC
);
190 ok( res
== ERROR_INSUFFICIENT_BUFFER
,
191 "returned %u with %u for '%s' (expected ERROR_INSUFFICIENT_BUFFER)\n",
192 res
, GetLastError(), bufferA
);
194 SetLastError(0xdeadbeef);
195 res
= pCommConfigDialogW(bufferW
, NULL
, NULL
);
196 ok( res
== ERROR_INVALID_PARAMETER
,
197 "returned %u with %u for '%s' (expected ERROR_INVALID_PARAMETER)\n",
198 res
, GetLastError(), bufferA
);
203 ZeroMemory(pCC
, sizeof(pCC
));
204 SetLastError(0xdeadbeef);
205 res
= pCommConfigDialogW(emptyW
, NULL
, pCC
);
206 ok( res
== ERROR_INSUFFICIENT_BUFFER
,
207 "returned %u with %u (expected ERROR_INSUFFICIENT_BUFFER)\n",
208 res
, GetLastError());
211 ZeroMemory(pCC
, sizeof(pCC
));
212 pCC
[0].dwSize
= sizeof(COMMCONFIG
);
213 SetLastError(0xdeadbeef);
214 res
= pCommConfigDialogW(emptyW
, NULL
, pCC
);
215 ok( res
== ERROR_BADKEY
, "returned %u with %u (expected ERROR_BADKEY)\n",
216 res
, GetLastError());
219 ZeroMemory(pCC
, sizeof(pCC
));
220 SetLastError(0xdeadbeef);
221 res
= pCommConfigDialogW(NULL
, NULL
, pCC
);
222 ok( res
== ERROR_INVALID_PARAMETER
,
223 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
224 res
, GetLastError());
228 /* ################# */
230 static void test_drvGetDefaultCommConfigA(void)
239 /* off by one: one byte smaller */
240 i
= sizeof(COMMCONFIG
);
241 len
= sizeof(COMMCONFIG
) -1;
242 ZeroMemory(pCC
, sizeof(pCC
));
243 SetLastError(0xdeadbeef);
244 res
= pGetDefaultCommConfigA(com1A
, pCC
, &len
);
245 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
246 /* NT does not implement the ANSI API */
247 win_skip("*A not implemented\n");
250 ok( (res
== ERROR_INSUFFICIENT_BUFFER
) && (len
>= i
),
251 "returned %u with %u and %u (expected "
252 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res
, GetLastError(), len
, i
);
254 /* test ports "com0" - "com10" */
255 for (i
= 0; i
< 11 ; i
++) {
256 sprintf(bufferA
, fmt_comA
, i
);
258 ZeroMemory(pCC
, sizeof(pCC
));
259 SetLastError(0xdeadbeef);
260 res
= pGetDefaultCommConfigA(bufferA
, pCC
, &len
);
262 ok( res
== ERROR_BADKEY
,
263 "returned %u with %u and %u for %s (expected "
264 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
268 ok((res
== ERROR_SUCCESS
) || (res
== ERROR_BADKEY
),
269 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
270 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
273 /* a name with a colon is invalid */
274 if (res
== ERROR_SUCCESS
) {
275 lstrcatA(bufferA
, str_colonA
);
277 ZeroMemory(pCC
, sizeof(pCC
));
278 res
= pGetDefaultCommConfigA(bufferA
, pCC
, &len
);
279 ok( res
== ERROR_BADKEY
,
280 "returned %u with %u and %u for %s (expected '0' with "
281 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
286 /* an empty String is not allowed */
288 ZeroMemory(pCC
, sizeof(pCC
));
289 SetLastError(0xdeadbeef);
290 res
= pGetDefaultCommConfigA(emptyA
, pCC
, &len
);
291 ok( res
== ERROR_BADKEY
,
292 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
293 res
, GetLastError(), len
, emptyA
);
295 /* some NULL checks */
297 ZeroMemory(pCC
, sizeof(pCC
));
298 SetLastError(0xdeadbeef);
299 res
= pGetDefaultCommConfigA(NULL
, pCC
, &len
);
300 ok( res
== ERROR_INVALID_PARAMETER
,
301 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
302 res
, GetLastError(), len
);
306 SetLastError(0xdeadbeef);
307 res
= pGetDefaultCommConfigA(com1A
, NULL
, &len
);
308 ok( res
== ERROR_INVALID_PARAMETER
,
309 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
310 res
, GetLastError(), len
);
313 SetLastError(0xdeadbeef);
314 res
= pGetDefaultCommConfigA(com1A
, pCC
, NULL
);
315 ok( res
== ERROR_INVALID_PARAMETER
,
316 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
317 res
, GetLastError());
320 /* ################# */
322 static void test_drvGetDefaultCommConfigW(void)
332 /* off by one: one byte smaller */
333 i
= sizeof(COMMCONFIG
);
334 len
= sizeof(COMMCONFIG
) -1;
335 ZeroMemory(pCC
, sizeof(pCC
));
336 SetLastError(0xdeadbeef);
337 res
= pGetDefaultCommConfigW(com1W
, pCC
, &len
);
338 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
339 win_skip("*W not implemented\n");
342 ok( (res
== ERROR_INSUFFICIENT_BUFFER
) && (len
>= i
),
343 "returned %u with %u and %u (expected "
344 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res
, GetLastError(), len
, i
);
346 /* test ports "com0" - "com10" */
347 for (i
= 0; i
< 11 ; i
++) {
348 sprintf(bufferA
, fmt_comA
, i
);
349 MultiByteToWideChar( CP_ACP
, 0, bufferA
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
351 ZeroMemory(pCC
, sizeof(pCC
));
352 SetLastError(0xdeadbeef);
353 res
= pGetDefaultCommConfigW(bufferW
, pCC
, &len
);
355 ok( res
== ERROR_BADKEY
,
356 "returned %u with %u and %u for %s (expected "
357 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
361 ok((res
== ERROR_SUCCESS
) || (res
== ERROR_BADKEY
),
362 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
363 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
366 /* a name with a colon is invalid */
367 if (res
== ERROR_SUCCESS
) {
368 lstrcatA(bufferA
, str_colonA
);
369 lstrcatW(bufferW
, str_colonW
);
371 ZeroMemory(pCC
, sizeof(pCC
));
372 res
= pGetDefaultCommConfigW(bufferW
, pCC
, &len
);
373 ok( res
== ERROR_BADKEY
,
374 "returned %u with %u and %u for %s (expected '0' with "
375 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
379 /* an empty String is not allowed */
381 ZeroMemory(pCC
, sizeof(pCC
));
382 SetLastError(0xdeadbeef);
383 res
= pGetDefaultCommConfigW(emptyW
, pCC
, &len
);
384 ok( res
== ERROR_BADKEY
,
385 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
386 res
, GetLastError(), len
, emptyA
);
388 /* some NULL checks */
390 ZeroMemory(pCC
, sizeof(pCC
));
391 SetLastError(0xdeadbeef);
392 res
= pGetDefaultCommConfigW(NULL
, pCC
, &len
);
393 ok( res
== ERROR_INVALID_PARAMETER
,
394 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
395 res
, GetLastError(), len
);
399 SetLastError(0xdeadbeef);
400 res
= pGetDefaultCommConfigW(com1W
, NULL
, &len
);
401 ok( res
== ERROR_INVALID_PARAMETER
,
402 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
403 res
, GetLastError(), len
);
406 SetLastError(0xdeadbeef);
407 res
= pGetDefaultCommConfigW(com1W
, pCC
, NULL
);
408 ok( res
== ERROR_INVALID_PARAMETER
,
409 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
410 res
, GetLastError());
414 /* ################# */
420 ptr
= load_functions();
422 win_skip("got NULL with %u for %s\n", GetLastError(), ptr
);
426 test_drvCommConfigDialogA();
427 test_drvCommConfigDialogW();
428 test_drvGetDefaultCommConfigA();
429 test_drvGetDefaultCommConfigW();