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 fmt_comW[] = {'c','o','m','%','d',0};
48 static const WCHAR str_colonW[] = {':',0};
50 /* ################# */
52 static LPCSTR load_functions(void)
57 hdll = LoadLibraryA(ptr);
58 if (!hdll) return ptr;
60 ptr = "drvCommConfigDialogA";
61 pCommConfigDialogA = (VOID *) GetProcAddress(hdll, ptr);
62 if (!pCommConfigDialogA) return ptr;
64 ptr = "drvCommConfigDialogW";
65 pCommConfigDialogW = (VOID *) GetProcAddress(hdll, ptr);
66 if (!pCommConfigDialogW) return ptr;
68 ptr = "drvGetDefaultCommConfigA";
69 pGetDefaultCommConfigA = (VOID *) GetProcAddress(hdll, ptr);
70 if (!pGetDefaultCommConfigA) return ptr;
72 ptr = "drvGetDefaultCommConfigW";
73 pGetDefaultCommConfigW = (VOID *) GetProcAddress(hdll, ptr);
74 if (!pGetDefaultCommConfigW) return ptr;
80 /* ################# */
82 static void test_drvCommConfigDialogA(void)
91 /* test ports "com1" - "com4" */
92 for (i = 1; i < 5 ; i++) {
93 sprintf(bufferA, fmt_comA, i);
95 ZeroMemory(pCC, sizeof(pCC));
96 SetLastError(0xdeadbeef);
97 res = pGetDefaultCommConfigA(bufferA, pCC, &len);
98 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
99 /* NT does not implement the ANSI API */
100 skip("*A not implemented\n");
104 if (res == ERROR_SUCCESS) {
106 if (winetest_interactive) {
107 SetLastError(0xdeadbeef);
108 res = pCommConfigDialogA(bufferA, NULL, pCC);
109 /* OK: ERROR_SUCCESS, Cancel: ERROR_CANCELLED */
110 trace("returned %u with %u for '%s'\n", res, GetLastError(), bufferA);
113 ZeroMemory(pCC, sizeof(pCC));
114 SetLastError(0xdeadbeef);
115 res = pCommConfigDialogA(bufferA, NULL, pCC);
116 ok( res == ERROR_INSUFFICIENT_BUFFER,
117 "returned %u with %u for '%s' (expected ERROR_INSUFFICIENT_BUFFER)\n",
118 res, GetLastError(), bufferA);
121 SetLastError(0xdeadbeef);
122 res = pCommConfigDialogA(bufferA, NULL, NULL);
123 ok( res == ERROR_INVALID_PARAMETER,
124 "returned %u with %u for '%s' (expected ERROR_INVALID_PARAMETER)\n",
125 res, GetLastError(), bufferA);
130 ZeroMemory(pCC, sizeof(pCC));
131 SetLastError(0xdeadbeef);
132 res = pCommConfigDialogA(emptyA, NULL, pCC);
133 ok( res == ERROR_INSUFFICIENT_BUFFER,
134 "returned %u with %u (expected ERROR_INSUFFICIENT_BUFFER)\n",
135 res, GetLastError());
138 ZeroMemory(pCC, sizeof(pCC));
139 pCC[0].dwSize = sizeof(COMMCONFIG);
140 SetLastError(0xdeadbeef);
141 res = pCommConfigDialogA(emptyA, NULL, pCC);
142 ok( res == ERROR_BADKEY, "returned %u with %u (expected ERROR_BADKEY)\n",
143 res, GetLastError());
146 ZeroMemory(pCC, sizeof(pCC));
147 SetLastError(0xdeadbeef);
148 res = pCommConfigDialogA(NULL, NULL, pCC);
149 ok( res == ERROR_INVALID_PARAMETER,
150 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
151 res, GetLastError());
154 /* ################# */
156 static void test_drvCommConfigDialogW(void)
166 /* test ports "com1" - "com4" */
167 for (i = 1; i < 5 ; i++) {
168 sprintf(bufferA, fmt_comA, i);
169 MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, sizeof(bufferW)/sizeof(WCHAR) );
171 ZeroMemory(pCC, sizeof(pCC));
172 SetLastError(0xdeadbeef);
173 res = pGetDefaultCommConfigW(bufferW, pCC, &len);
174 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
175 skip("*W not implemented\n");
179 if (res == ERROR_SUCCESS) {
181 if (winetest_interactive) {
182 SetLastError(0xdeadbeef);
183 res = pCommConfigDialogW(bufferW, NULL, pCC);
184 /* OK: ERROR_SUCCESS, Cancel: ERROR_CANCELLED */
185 trace("returned %u with %u for '%s'\n", res, GetLastError(), bufferA);
188 ZeroMemory(pCC, sizeof(pCC));
189 SetLastError(0xdeadbeef);
190 res = pCommConfigDialogW(bufferW, NULL, pCC);
191 ok( res == ERROR_INSUFFICIENT_BUFFER,
192 "returned %u with %u for '%s' (expected ERROR_INSUFFICIENT_BUFFER)\n",
193 res, GetLastError(), bufferA);
195 SetLastError(0xdeadbeef);
196 res = pCommConfigDialogW(bufferW, NULL, NULL);
197 ok( res == ERROR_INVALID_PARAMETER,
198 "returned %u with %u for '%s' (expected ERROR_INVALID_PARAMETER)\n",
199 res, GetLastError(), bufferA);
204 ZeroMemory(pCC, sizeof(pCC));
205 SetLastError(0xdeadbeef);
206 res = pCommConfigDialogW(emptyW, NULL, pCC);
207 ok( res == ERROR_INSUFFICIENT_BUFFER,
208 "returned %u with %u (expected ERROR_INSUFFICIENT_BUFFER)\n",
209 res, GetLastError());
212 ZeroMemory(pCC, sizeof(pCC));
213 pCC[0].dwSize = sizeof(COMMCONFIG);
214 SetLastError(0xdeadbeef);
215 res = pCommConfigDialogW(emptyW, NULL, pCC);
216 ok( res == ERROR_BADKEY, "returned %u with %u (expected ERROR_BADKEY)\n",
217 res, GetLastError());
220 ZeroMemory(pCC, sizeof(pCC));
221 SetLastError(0xdeadbeef);
222 res = pCommConfigDialogW(NULL, NULL, pCC);
223 ok( res == ERROR_INVALID_PARAMETER,
224 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
225 res, GetLastError());
229 /* ################# */
231 static void test_drvGetDefaultCommConfigA(void)
240 /* off by one: one byte smaller */
241 i = sizeof(COMMCONFIG);
242 len = sizeof(COMMCONFIG) -1;
243 ZeroMemory(pCC, sizeof(pCC));
244 SetLastError(0xdeadbeef);
245 res = pGetDefaultCommConfigA(com1A, pCC, &len);
246 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
247 /* NT does not implement the ANSI API */
248 skip("*A not implemented\n");
251 ok( (res == ERROR_INSUFFICIENT_BUFFER) && (len >= i),
252 "returned %u with %u and %u (expected "
253 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res, GetLastError(), len, i);
255 /* test ports "com0" - "com10" */
256 for (i = 0; i < 11 ; i++) {
257 sprintf(bufferA, fmt_comA, i);
259 ZeroMemory(pCC, sizeof(pCC));
260 SetLastError(0xdeadbeef);
261 res = pGetDefaultCommConfigA(bufferA, pCC, &len);
263 ok( res == ERROR_BADKEY,
264 "returned %u with %u and %u for %s (expected "
265 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
269 ok((res == ERROR_SUCCESS) || (res == ERROR_BADKEY),
270 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
271 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
274 /* a name with a colon is invalid */
275 if (res == ERROR_SUCCESS) {
276 lstrcatA(bufferA, str_colonA);
278 ZeroMemory(pCC, sizeof(pCC));
279 res = pGetDefaultCommConfigA(bufferA, pCC, &len);
280 ok( res == ERROR_BADKEY,
281 "returned %u with %u and %u for %s (expected '0' with "
282 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
287 /* an empty String is not allowed */
289 ZeroMemory(pCC, sizeof(pCC));
290 SetLastError(0xdeadbeef);
291 res = pGetDefaultCommConfigA(emptyA, pCC, &len);
292 ok( res == ERROR_BADKEY,
293 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
294 res, GetLastError(), len, emptyA);
296 /* some NULL checks */
298 ZeroMemory(pCC, sizeof(pCC));
299 SetLastError(0xdeadbeef);
300 res = pGetDefaultCommConfigA(NULL, pCC, &len);
301 ok( res == ERROR_INVALID_PARAMETER,
302 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
303 res, GetLastError(), len);
307 SetLastError(0xdeadbeef);
308 res = pGetDefaultCommConfigA(com1A, NULL, &len);
309 ok( res == ERROR_INVALID_PARAMETER,
310 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
311 res, GetLastError(), len);
314 SetLastError(0xdeadbeef);
315 res = pGetDefaultCommConfigA(com1A, pCC, NULL);
316 ok( res == ERROR_INVALID_PARAMETER,
317 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
318 res, GetLastError());
321 /* ################# */
323 static void test_drvGetDefaultCommConfigW(void)
333 /* off by one: one byte smaller */
334 i = sizeof(COMMCONFIG);
335 len = sizeof(COMMCONFIG) -1;
336 ZeroMemory(pCC, sizeof(pCC));
337 SetLastError(0xdeadbeef);
338 res = pGetDefaultCommConfigW(com1W, pCC, &len);
339 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
340 skip("*W not implemented\n");
343 ok( (res == ERROR_INSUFFICIENT_BUFFER) && (len >= i),
344 "returned %u with %u and %u (expected "
345 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res, GetLastError(), len, i);
347 /* test ports "com0" - "com10" */
348 for (i = 0; i < 11 ; i++) {
349 sprintf(bufferA, fmt_comA, i);
350 MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, sizeof(bufferW)/sizeof(WCHAR) );
352 ZeroMemory(pCC, sizeof(pCC));
353 SetLastError(0xdeadbeef);
354 res = pGetDefaultCommConfigW(bufferW, pCC, &len);
356 ok( res == ERROR_BADKEY,
357 "returned %u with %u and %u for %s (expected "
358 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
362 ok((res == ERROR_SUCCESS) || (res == ERROR_BADKEY),
363 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
364 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
367 /* a name with a colon is invalid */
368 if (res == ERROR_SUCCESS) {
369 lstrcatA(bufferA, str_colonA);
370 lstrcatW(bufferW, str_colonW);
372 ZeroMemory(pCC, sizeof(pCC));
373 res = pGetDefaultCommConfigW(bufferW, pCC, &len);
374 ok( res == ERROR_BADKEY,
375 "returned %u with %u and %u for %s (expected '0' with "
376 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
380 /* an empty String is not allowed */
382 ZeroMemory(pCC, sizeof(pCC));
383 SetLastError(0xdeadbeef);
384 res = pGetDefaultCommConfigW(emptyW, pCC, &len);
385 ok( res == ERROR_BADKEY,
386 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
387 res, GetLastError(), len, emptyA);
389 /* some NULL checks */
391 ZeroMemory(pCC, sizeof(pCC));
392 SetLastError(0xdeadbeef);
393 res = pGetDefaultCommConfigW(NULL, pCC, &len);
394 ok( res == ERROR_INVALID_PARAMETER,
395 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
396 res, GetLastError(), len);
400 SetLastError(0xdeadbeef);
401 res = pGetDefaultCommConfigW(com1W, NULL, &len);
402 ok( res == ERROR_INVALID_PARAMETER,
403 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
404 res, GetLastError(), len);
407 SetLastError(0xdeadbeef);
408 res = pGetDefaultCommConfigW(com1W, pCC, NULL);
409 ok( res == ERROR_INVALID_PARAMETER,
410 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
411 res, GetLastError());
415 /* ################# */
421 ptr = load_functions();
423 skip("got NULL with %u for %s\n", GetLastError(), ptr);
427 test_drvCommConfigDialogA();
428 test_drvCommConfigDialogW();
429 test_drvGetDefaultCommConfigA();
430 test_drvGetDefaultCommConfigW();