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
*pGetDefaultCommConfigA
)(LPCSTR
, LPCOMMCONFIG
, LPDWORD
);
35 static DWORD (WINAPI
*pGetDefaultCommConfigW
)(LPCWSTR
, LPCOMMCONFIG
, LPDWORD
);
38 static const CHAR com1A
[] = "com1";
39 static const CHAR emptyA
[] = "";
40 static const CHAR fmt_comA
[] = "com%d";
41 static const CHAR str_colonA
[] = ":";
43 static const WCHAR com1W
[] = {'c','o','m','1',0};
44 static const WCHAR emptyW
[] = {0};
45 static const WCHAR fmt_comW
[] = {'c','o','m','%','d',0};
46 static const WCHAR str_colonW
[] = {':',0};
48 /* ################# */
50 static LPCSTR
load_functions(void)
55 hdll
= LoadLibraryA(ptr
);
56 if (!hdll
) return ptr
;
58 ptr
= "drvGetDefaultCommConfigA";
59 pGetDefaultCommConfigA
= (VOID
*) GetProcAddress(hdll
, ptr
);
60 if (!pGetDefaultCommConfigA
) return ptr
;
62 ptr
= "drvGetDefaultCommConfigW";
63 pGetDefaultCommConfigW
= (VOID
*) GetProcAddress(hdll
, ptr
);
64 if (!pGetDefaultCommConfigW
) return ptr
;
70 /* ################# */
72 static void test_drvGetDefaultCommConfigA(void)
81 /* off by one: one byte smaller */
82 i
= sizeof(COMMCONFIG
);
83 len
= sizeof(COMMCONFIG
) -1;
84 ZeroMemory(pCC
, sizeof(pCC
));
85 SetLastError(0xdeadbeef);
86 res
= pGetDefaultCommConfigA(com1A
, pCC
, &len
);
87 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
88 /* NT does not implement the ANSI API */
89 skip("*A not implemented\n");
92 ok( (res
== ERROR_INSUFFICIENT_BUFFER
) && (len
>= i
),
93 "returned %u with %u and %u (expected "
94 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res
, GetLastError(), len
, i
);
96 /* test ports "com0" - "com10" */
97 for (i
= 0; i
< 11 ; i
++) {
98 sprintf(bufferA
, fmt_comA
, i
);
100 ZeroMemory(pCC
, sizeof(pCC
));
101 SetLastError(0xdeadbeef);
102 res
= pGetDefaultCommConfigA(bufferA
, pCC
, &len
);
104 ok( res
== ERROR_BADKEY
,
105 "returned %u with %u and %u for %s (expected "
106 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
110 ok((res
== ERROR_SUCCESS
) || (res
== ERROR_BADKEY
),
111 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
112 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
115 /* a name with a colon is invalid */
116 if (res
== ERROR_SUCCESS
) {
117 lstrcatA(bufferA
, str_colonA
);
119 ZeroMemory(pCC
, sizeof(pCC
));
120 res
= pGetDefaultCommConfigA(bufferA
, pCC
, &len
);
121 ok( res
== ERROR_BADKEY
,
122 "returned %u with %u and %u for %s (expected '0' with "
123 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
128 /* an empty String is not allowed */
130 ZeroMemory(pCC
, sizeof(pCC
));
131 SetLastError(0xdeadbeef);
132 res
= pGetDefaultCommConfigA(emptyA
, pCC
, &len
);
133 ok( res
== ERROR_BADKEY
,
134 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
135 res
, GetLastError(), len
, emptyA
);
137 /* some NULL checks */
139 ZeroMemory(pCC
, sizeof(pCC
));
140 SetLastError(0xdeadbeef);
141 res
= pGetDefaultCommConfigA(NULL
, pCC
, &len
);
142 ok( res
== ERROR_INVALID_PARAMETER
,
143 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
144 res
, GetLastError(), len
);
148 SetLastError(0xdeadbeef);
149 res
= pGetDefaultCommConfigA(com1A
, NULL
, &len
);
150 ok( res
== ERROR_INVALID_PARAMETER
,
151 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
152 res
, GetLastError(), len
);
155 SetLastError(0xdeadbeef);
156 res
= pGetDefaultCommConfigA(com1A
, pCC
, NULL
);
157 ok( res
== ERROR_INVALID_PARAMETER
,
158 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
159 res
, GetLastError());
162 /* ################# */
164 static void test_drvGetDefaultCommConfigW(void)
174 /* off by one: one byte smaller */
175 i
= sizeof(COMMCONFIG
);
176 len
= sizeof(COMMCONFIG
) -1;
177 ZeroMemory(pCC
, sizeof(pCC
));
178 SetLastError(0xdeadbeef);
179 res
= pGetDefaultCommConfigW(com1W
, pCC
, &len
);
180 if (res
== ERROR_CALL_NOT_IMPLEMENTED
) {
181 skip("*W not implemented\n");
184 ok( (res
== ERROR_INSUFFICIENT_BUFFER
) && (len
>= i
),
185 "returned %u with %u and %u (expected "
186 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res
, GetLastError(), len
, i
);
188 /* test ports "com0" - "com10" */
189 for (i
= 0; i
< 11 ; i
++) {
190 sprintf(bufferA
, fmt_comA
, i
);
191 MultiByteToWideChar( CP_ACP
, 0, bufferA
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) );
193 ZeroMemory(pCC
, sizeof(pCC
));
194 SetLastError(0xdeadbeef);
195 res
= pGetDefaultCommConfigW(bufferW
, pCC
, &len
);
197 ok( res
== ERROR_BADKEY
,
198 "returned %u with %u and %u for %s (expected "
199 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
203 ok((res
== ERROR_SUCCESS
) || (res
== ERROR_BADKEY
),
204 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
205 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
208 /* a name with a colon is invalid */
209 if (res
== ERROR_SUCCESS
) {
210 lstrcatA(bufferA
, str_colonA
);
211 lstrcatW(bufferW
, str_colonW
);
213 ZeroMemory(pCC
, sizeof(pCC
));
214 res
= pGetDefaultCommConfigW(bufferW
, pCC
, &len
);
215 ok( res
== ERROR_BADKEY
,
216 "returned %u with %u and %u for %s (expected '0' with "
217 "ERROR_BADKEY)\n", res
, GetLastError(), len
, bufferA
);
221 /* an empty String is not allowed */
223 ZeroMemory(pCC
, sizeof(pCC
));
224 SetLastError(0xdeadbeef);
225 res
= pGetDefaultCommConfigW(emptyW
, pCC
, &len
);
226 ok( res
== ERROR_BADKEY
,
227 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
228 res
, GetLastError(), len
, emptyA
);
230 /* some NULL checks */
232 ZeroMemory(pCC
, sizeof(pCC
));
233 SetLastError(0xdeadbeef);
234 res
= pGetDefaultCommConfigW(NULL
, pCC
, &len
);
235 ok( res
== ERROR_INVALID_PARAMETER
,
236 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
237 res
, GetLastError(), len
);
241 SetLastError(0xdeadbeef);
242 res
= pGetDefaultCommConfigW(com1W
, NULL
, &len
);
243 ok( res
== ERROR_INVALID_PARAMETER
,
244 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
245 res
, GetLastError(), len
);
248 SetLastError(0xdeadbeef);
249 res
= pGetDefaultCommConfigW(com1W
, pCC
, NULL
);
250 ok( res
== ERROR_INVALID_PARAMETER
,
251 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
252 res
, GetLastError());
256 /* ################# */
262 ptr
= load_functions();
264 skip("got NULL with %u for %s\n", GetLastError(), ptr
);
268 test_drvGetDefaultCommConfigA();
269 test_drvGetDefaultCommConfigW();