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 str_colonW[] = {':',0}; 48 49 /* ################# */ 50 51 static LPCSTR load_functions(void) 52 { 53 LPCSTR ptr; 54 55 ptr = "serialui.dll"; 56 hdll = LoadLibraryA(ptr); 57 if (!hdll) return ptr; 58 59 ptr = "drvCommConfigDialogA"; 60 pCommConfigDialogA = (VOID *) GetProcAddress(hdll, ptr); 61 if (!pCommConfigDialogA) return ptr; 62 63 ptr = "drvCommConfigDialogW"; 64 pCommConfigDialogW = (VOID *) GetProcAddress(hdll, ptr); 65 if (!pCommConfigDialogW) return ptr; 66 67 ptr = "drvGetDefaultCommConfigA"; 68 pGetDefaultCommConfigA = (VOID *) GetProcAddress(hdll, ptr); 69 if (!pGetDefaultCommConfigA) return ptr; 70 71 ptr = "drvGetDefaultCommConfigW"; 72 pGetDefaultCommConfigW = (VOID *) GetProcAddress(hdll, ptr); 73 if (!pGetDefaultCommConfigW) return ptr; 74 75 76 return NULL; 77 } 78 79 /* ################# */ 80 81 static void test_drvCommConfigDialogA(void) 82 { 83 COMMCONFIG pCC[3]; 84 CHAR bufferA[16]; 85 DWORD i; 86 DWORD res; 87 DWORD len; 88 89 90 /* test ports "com1" - "com4" */ 91 for (i = 1; i < 5 ; i++) { 92 sprintf(bufferA, fmt_comA, i); 93 len = sizeof(pCC); 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"); 100 return; 101 } 102 103 if (res == ERROR_SUCCESS) { 104 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); 110 } 111 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); 118 119 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); 125 } 126 } 127 128 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()); 135 136 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()); 143 144 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()); 151 } 152 153 /* ################# */ 154 155 static void test_drvCommConfigDialogW(void) 156 { 157 COMMCONFIG pCC[3]; 158 CHAR bufferA[16]; 159 WCHAR bufferW[16]; 160 DWORD i; 161 DWORD res; 162 DWORD len; 163 164 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, ARRAY_SIZE(bufferW)); 169 len = sizeof(pCC); 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"); 175 return; 176 } 177 178 if (res == ERROR_SUCCESS) { 179 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); 185 } 186 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); 193 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); 199 } 200 } 201 202 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()); 209 210 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()); 217 218 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()); 225 } 226 227 228 /* ################# */ 229 230 static void test_drvGetDefaultCommConfigA(void) 231 { 232 COMMCONFIG pCC[3]; 233 CHAR bufferA[16]; 234 DWORD i; 235 DWORD res; 236 DWORD len; 237 238 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"); 248 return; 249 } 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); 253 254 /* test ports "com0" - "com10" */ 255 for (i = 0; i < 11 ; i++) { 256 sprintf(bufferA, fmt_comA, i); 257 len = sizeof(pCC); 258 ZeroMemory(pCC, sizeof(pCC)); 259 SetLastError(0xdeadbeef); 260 res = pGetDefaultCommConfigA(bufferA, pCC, &len); 261 if (i == 0) { 262 ok( res == ERROR_BADKEY, 263 "returned %u with %u and %u for %s (expected " 264 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA); 265 } 266 else 267 { 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); 271 } 272 273 /* a name with a colon is invalid */ 274 if (res == ERROR_SUCCESS) { 275 lstrcatA(bufferA, str_colonA); 276 len = sizeof(pCC); 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); 282 } 283 } 284 285 286 /* an empty String is not allowed */ 287 len = sizeof(pCC); 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); 294 295 /* some NULL checks */ 296 len = sizeof(pCC); 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); 303 304 305 len = sizeof(pCC); 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); 311 312 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()); 318 } 319 320 /* ################# */ 321 322 static void test_drvGetDefaultCommConfigW(void) 323 { 324 COMMCONFIG pCC[3]; 325 WCHAR bufferW[16]; 326 CHAR bufferA[16]; 327 DWORD i; 328 DWORD res; 329 DWORD len; 330 331 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"); 340 return; 341 } 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); 345 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, ARRAY_SIZE(bufferW)); 350 len = sizeof(pCC); 351 ZeroMemory(pCC, sizeof(pCC)); 352 SetLastError(0xdeadbeef); 353 res = pGetDefaultCommConfigW(bufferW, pCC, &len); 354 if (i == 0) { 355 ok( res == ERROR_BADKEY, 356 "returned %u with %u and %u for %s (expected " 357 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA); 358 } 359 else 360 { 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); 364 } 365 366 /* a name with a colon is invalid */ 367 if (res == ERROR_SUCCESS) { 368 lstrcatA(bufferA, str_colonA); 369 lstrcatW(bufferW, str_colonW); 370 len = sizeof(pCC); 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); 376 } 377 } 378 379 /* an empty String is not allowed */ 380 len = sizeof(pCC); 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); 387 388 /* some NULL checks */ 389 len = sizeof(pCC); 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); 396 397 398 len = sizeof(pCC); 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); 404 405 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()); 411 412 } 413 414 /* ################# */ 415 416 START_TEST(confdlg) 417 { 418 LPCSTR ptr; 419 420 ptr = load_functions(); 421 if (ptr) { 422 win_skip("got NULL with %u for %s\n", GetLastError(), ptr); 423 return; 424 } 425 426 test_drvCommConfigDialogA(); 427 test_drvCommConfigDialogW(); 428 test_drvGetDefaultCommConfigA(); 429 test_drvGetDefaultCommConfigW(); 430 431 } 432