mcicda: Exclude unused headers.
[wine] / dlls / serialui / tests / confdlg.c
1 /*
2  * Unit test suite for serialui API functions
3  *
4  * Copyright 2007 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 #include <stdio.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winnls.h"
29
30 #include "wine/test.h"
31
32
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);
38
39
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[] = ":";
44
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};
49
50 /* ################# */
51
52 static LPCSTR load_functions(void)
53 {
54     LPCSTR ptr;
55
56     ptr = "serialui.dll";
57     hdll = LoadLibraryA(ptr);
58     if (!hdll) return ptr;
59
60     ptr = "drvCommConfigDialogA";
61     pCommConfigDialogA = (VOID *) GetProcAddress(hdll, ptr);
62     if (!pCommConfigDialogA) return ptr;
63
64     ptr = "drvCommConfigDialogW";
65     pCommConfigDialogW = (VOID *) GetProcAddress(hdll, ptr);
66     if (!pCommConfigDialogW) return ptr;
67
68     ptr = "drvGetDefaultCommConfigA";
69     pGetDefaultCommConfigA = (VOID *) GetProcAddress(hdll, ptr);
70     if (!pGetDefaultCommConfigA) return ptr;
71
72     ptr = "drvGetDefaultCommConfigW";
73     pGetDefaultCommConfigW = (VOID *) GetProcAddress(hdll, ptr);
74     if (!pGetDefaultCommConfigW) return ptr;
75
76
77     return NULL;
78 }
79
80 /* ################# */
81
82 static void test_drvCommConfigDialogA(void)
83 {
84     COMMCONFIG  pCC[3];
85     CHAR        bufferA[16];
86     DWORD       i;
87     DWORD       res;
88     DWORD       len;
89
90
91     /* test ports "com1" - "com4" */
92     for (i = 1; i < 5 ; i++) {
93         sprintf(bufferA, fmt_comA, i);
94         len = sizeof(pCC);
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");
101             return;
102         }
103
104         if (res == ERROR_SUCCESS) {
105
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);
111             }
112
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);
119
120
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);
126         }
127     }
128
129
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());
136
137
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());
144
145
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());
152 }
153
154 /* ################# */
155
156 static void test_drvCommConfigDialogW(void)
157 {
158     COMMCONFIG  pCC[3];
159     CHAR        bufferA[16];
160     WCHAR       bufferW[16];
161     DWORD       i;
162     DWORD       res;
163     DWORD       len;
164
165
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) );
170         len = sizeof(pCC);
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");
176             return;
177         }
178
179         if (res == ERROR_SUCCESS) {
180
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);
186             }
187
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);
194
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);
200         }
201     }
202
203
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());
210
211
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());
218
219
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());
226 }
227
228
229 /* ################# */
230
231 static void test_drvGetDefaultCommConfigA(void)
232 {
233     COMMCONFIG  pCC[3];
234     CHAR        bufferA[16];
235     DWORD       i;
236     DWORD       res;
237     DWORD       len;
238
239
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");
249         return;
250     }
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);
254
255     /* test ports "com0" - "com10" */
256     for (i = 0; i < 11 ; i++) {
257         sprintf(bufferA, fmt_comA, i);
258         len = sizeof(pCC);
259         ZeroMemory(pCC, sizeof(pCC));
260         SetLastError(0xdeadbeef);
261         res = pGetDefaultCommConfigA(bufferA, pCC, &len);
262         if (i == 0) {
263             ok( res == ERROR_BADKEY,
264                 "returned %u with %u and %u for %s (expected "
265                 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
266         }
267         else
268         {
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);
272         }
273
274         /* a name with a colon is invalid */
275         if (res == ERROR_SUCCESS) {
276             lstrcatA(bufferA, str_colonA);
277             len = sizeof(pCC);
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);
283         }
284     }
285
286
287     /* an empty String is not allowed */
288     len = sizeof(pCC);
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);
295
296     /* some NULL checks */
297     len = sizeof(pCC);
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);
304
305
306     len = sizeof(pCC);
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);
312
313
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());
319 }
320
321 /* ################# */
322
323 static void test_drvGetDefaultCommConfigW(void)
324 {
325     COMMCONFIG  pCC[3];
326     WCHAR       bufferW[16];
327     CHAR        bufferA[16];
328     DWORD       i;
329     DWORD       res;
330     DWORD       len;
331
332
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");
341         return;
342     }
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);
346
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) );
351         len = sizeof(pCC);
352         ZeroMemory(pCC, sizeof(pCC));
353         SetLastError(0xdeadbeef);
354         res = pGetDefaultCommConfigW(bufferW, pCC, &len);
355         if (i == 0) {
356             ok( res == ERROR_BADKEY,
357                 "returned %u with %u and %u for %s (expected "
358                 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
359         }
360         else
361         {
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);
365         }
366
367         /* a name with a colon is invalid */
368         if (res == ERROR_SUCCESS) {
369             lstrcatA(bufferA, str_colonA);
370             lstrcatW(bufferW, str_colonW);
371             len = sizeof(pCC);
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);
377         }
378     }
379
380     /* an empty String is not allowed */
381     len = sizeof(pCC);
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);
388
389     /* some NULL checks */
390     len = sizeof(pCC);
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);
397
398
399     len = sizeof(pCC);
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);
405
406
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());
412
413 }
414
415 /* ################# */
416
417 START_TEST(confdlg)
418 {
419     LPCSTR ptr;
420
421     ptr = load_functions();
422     if (ptr) {
423         skip("got NULL with %u for %s\n", GetLastError(), ptr);
424         return;
425     }
426
427     test_drvCommConfigDialogA();
428     test_drvCommConfigDialogW();
429     test_drvGetDefaultCommConfigA();
430     test_drvGetDefaultCommConfigW();
431
432 }