1 /* 2 * Copyright 2007 Bill Medland 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #include <wine/test.h> 20 #include <stdarg.h> 21 22 #include "windef.h" 23 #include "winbase.h" 24 #include "winreg.h" 25 #include "odbcinst.h" 26 27 static const WCHAR abcd_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','a','b','c','d','.','I','N','I','\\','w','i','n','e','o','d','b','c',0}; 28 static const WCHAR abcdini_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','a','b','c','d','.','I','N','I',0 }; 29 30 31 static void test_SQLConfigMode(void) 32 { 33 BOOL bool_ret; 34 DWORD error_code; 35 RETCODE sql_ret; 36 UWORD config_mode; 37 int i; 38 39 ok(SQLGetConfigMode(NULL), "SQLGetConfigMode(NULL) should succeed\n"); 40 41 bool_ret = SQLGetConfigMode(&config_mode); 42 ok(bool_ret && config_mode == ODBC_BOTH_DSN, "Failed to get the initial SQLGetConfigMode or it was not both\n"); 43 44 /* try to set invalid mode */ 45 bool_ret = SQLSetConfigMode(ODBC_SYSTEM_DSN+1); 46 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 47 ok(!bool_ret && sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_PARAM_SEQUENCE, "SQLSetConfigMode with invalid argument did not fail correctly\n"); 48 49 for (i = ODBC_SYSTEM_DSN; i >= ODBC_BOTH_DSN; --i) 50 { 51 ok(SQLSetConfigMode((UWORD)i), "SQLSetConfigMode Failed to set config mode\n"); 52 bool_ret = SQLGetConfigMode(&config_mode); 53 ok(bool_ret && config_mode == i, "Failed to confirm SQLSetConfigMode.\n"); 54 } 55 /* And that leaves it correctly on BOTH */ 56 } 57 58 static void test_SQLInstallerError(void) 59 { 60 RETCODE sql_ret; 61 62 /* MSDN states that the error number should be between 1 and 8. Passing 0 is an error */ 63 sql_ret = SQLInstallerError(0, NULL, NULL, 0, NULL); 64 ok(sql_ret == SQL_ERROR, "SQLInstallerError(0...) failed with %d instead of SQL_ERROR\n", sql_ret); 65 /* However numbers greater than 8 do not return SQL_ERROR. 66 * I am currently unsure as to whether it should return SQL_NO_DATA or "the same as for error 8"; 67 * I have never been able to generate 8 errors to test it 68 */ 69 sql_ret = SQLInstallerError(65535, NULL, NULL, 0, NULL); 70 ok(sql_ret == SQL_NO_DATA, "SQLInstallerError(>8...) failed with %d instead of SQL_NO_DATA\n", sql_ret); 71 72 /* Force an error to work with. This should generate ODBC_ERROR_INVALID_BUFF_LEN */ 73 ok(!SQLGetInstalledDrivers(0, 0, 0), "Failed to force an error for testing\n"); 74 sql_ret = SQLInstallerError(2, NULL, NULL, 0, NULL); 75 ok(sql_ret == SQL_NO_DATA, "Too many errors when forcing an error for testing\n"); 76 77 /* Null pointers are acceptable in all obvious places */ 78 sql_ret = SQLInstallerError(1, NULL, NULL, 0, NULL); 79 ok(sql_ret == SQL_SUCCESS_WITH_INFO, "SQLInstallerError(null addresses) failed with %d instead of SQL_SUCCESS_WITH_INFO\n", sql_ret); 80 } 81 82 static void test_SQLInstallDriverManager(void) 83 { 84 BOOL bool_ret; 85 RETCODE sql_ret; 86 DWORD error_code; 87 CHAR target_path[MAX_PATH]; 88 WORD path_out; 89 90 /* NULL check */ 91 bool_ret = SQLInstallDriverManager(NULL, 0, NULL); 92 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 93 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); 94 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, 95 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); 96 97 /* Length smaller than MAX_PATH */ 98 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, NULL); 99 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 100 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); 101 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, 102 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); 103 104 path_out = 0xcafe; 105 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, &path_out); 106 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 107 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n"); 108 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN, 109 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n"); 110 ok(path_out == 0xcafe, "Expected path_out to not have changed\n"); 111 112 /* Length OK */ 113 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, NULL); 114 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 115 if(!bool_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED) 116 { 117 win_skip("not enough privileges\n"); 118 return; 119 } 120 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n", 121 error_code); 122 if (bool_ret) 123 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret); 124 else 125 ok(sql_ret == SQL_SUCCESS_WITH_INFO, 126 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret); 127 128 path_out = 0xcafe; 129 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, &path_out); 130 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 131 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n", 132 error_code); 133 if (bool_ret) 134 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret); 135 else 136 ok(sql_ret == SQL_SUCCESS_WITH_INFO, 137 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret); 138 /* path_out should in practice be less than 0xcafe */ 139 ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n"); 140 } 141 142 static void test_SQLWritePrivateProfileString(void) 143 { 144 static const WCHAR odbc_key[] = {'S','o','f','t','w','a','r','e','\\','O','D','B','C','\\','O','D','B','C','.','I','N','I','\\','w','i','n','e','o','d','b','c',0}; 145 BOOL ret; 146 LONG reg_ret; 147 DWORD error_code; 148 149 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", ""); 150 ok(!ret, "SQLWritePrivateProfileString passed\n"); 151 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 152 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code); 153 154 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", NULL); 155 ok(!ret, "SQLWritePrivateProfileString passed\n"); 156 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 157 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code); 158 159 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "odbc.ini"); 160 ok(ret, "SQLWritePrivateProfileString failed\n"); 161 if(ret) 162 { 163 HKEY hkey; 164 165 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, odbc_key, 0, KEY_READ, &hkey); 166 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 167 if(reg_ret == ERROR_SUCCESS) 168 { 169 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, odbc_key); 170 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 171 172 RegCloseKey(hkey); 173 } 174 } 175 176 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "abcd.ini"); 177 ok(ret, "SQLWritePrivateProfileString failed\n"); 178 if(ret) 179 { 180 HKEY hkey; 181 182 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey); 183 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 184 if(reg_ret == ERROR_SUCCESS) 185 { 186 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key); 187 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 188 189 RegCloseKey(hkey); 190 } 191 192 /* Cleanup key */ 193 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key); 194 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 195 } 196 } 197 198 static void test_SQLGetPrivateProfileString(void) 199 { 200 int ret; 201 char buffer[256] = {0}; 202 LONG reg_ret; 203 204 strcpy(buffer, "wine"); 205 ret = SQLGetPrivateProfileString(NULL, "testing" , "default", buffer, 256, "ODBC.INI"); 206 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 207 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer); 208 209 strcpy(buffer, "wine"); 210 ret = SQLGetPrivateProfileString("wineodbc", NULL , "default", buffer, 256, "ODBC.INI"); 211 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 212 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer); 213 214 strcpy(buffer, "value"); 215 ret = SQLGetPrivateProfileString("wineodbc", "testing" , NULL, buffer, 256, "ODBC.INI"); 216 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 217 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer); 218 219 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 256, "ODBC.INI"); 220 ok(ret == strlen("defaultX"), "SQLGetPrivateProfileString returned %d\n", ret); 221 ok(!strcmp(buffer, "defaultX"), "incorrect string '%s'\n", buffer); 222 223 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 4, "ODBC.INI"); 224 ok(ret == strlen("def"), "SQLGetPrivateProfileString returned %d\n", ret); 225 ok(!strcmp(buffer, "def"), "incorrect string '%s'\n", buffer); 226 227 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 8, "ODBC.INI"); 228 ok(ret == strlen("default"), "SQLGetPrivateProfileString returned %d\n", ret); 229 ok(!strcmp(buffer, "default"), "incorrect string '%s'\n", buffer); 230 231 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", NULL, 256, "ODBC.INI"); 232 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 233 234 strcpy(buffer, "value"); 235 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 0, "ODBC.INI"); 236 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 237 ok(!strcmp(buffer, "value"), "incorrect string '%s'\n", buffer); 238 239 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini"); 240 ok(ret, "SQLWritePrivateProfileString failed\n"); 241 if(ret) 242 { 243 HKEY hkey; 244 245 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 256, "abcd.ini"); 246 ok(ret == strlen("value0123456789"), "SQLGetPrivateProfileString returned %d\n", ret); 247 ok(!strcmp(buffer, "value0123456789"), "incorrect string '%s'\n", buffer); 248 249 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", NULL, 0, "abcd.ini"); 250 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 251 252 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 7, "abcd.ini"); 253 ok(ret == 6, "SQLGetPrivateProfileString returned %d\n", ret); 254 255 strcpy(buffer, "wine"); 256 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini"); 257 ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret); 258 ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer); 259 260 ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini"); 261 ok(ret, "SQLWritePrivateProfileString failed\n"); 262 263 strcpy(buffer, "wine"); 264 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 256, "abcd.ini"); 265 ok(ret == (strlen("testing") + strlen("value")+2), "SQLGetPrivateProfileString returned %d\n", ret); 266 if(ret >= (strlen("testing") + strlen("value")+2)) 267 { 268 ok(memcmp(buffer, "testing\0value\0", 14) == 0, "incorrect string '%s'\n", buffer); 269 } 270 271 strcpy(buffer, "XXXXXXXXXXXXXXX"); 272 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini"); 273 ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret); 274 if(ret >= (strlen("testing")+1)) 275 { 276 ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer); 277 /* Show that the buffer is cleared and partial enteries aren't added */ 278 ok(memcmp(buffer, "testing\0X", 9) != 0, "incorrect string '%s'\n", buffer); 279 } 280 281 strcpy(buffer, "wine"); 282 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 2, "abcd.ini"); 283 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret); 284 285 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey); 286 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 287 if(reg_ret == ERROR_SUCCESS) 288 { 289 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key); 290 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 291 292 RegCloseKey(hkey); 293 } 294 295 /* Cleanup key */ 296 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key); 297 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 298 } 299 } 300 301 static void test_SQLGetPrivateProfileStringW(void) 302 { 303 static WCHAR testing[] = {'t','e','s','t','i','n','g',0}; 304 static WCHAR wineodbc[] = {'w','i','n','e','o','d','b','c',0}; 305 static WCHAR defaultval[] = {'d','e','f','a','u','l','t',0}; 306 static WCHAR odbcini[] = {'O','D','B','C','.','I','N','I',0}; 307 static WCHAR abcdini[] = {'a','b','c','d','.','I','N','I',0}; 308 static WCHAR wine[] = {'w','i','n','e',0}; 309 static WCHAR value[] = {'v','a','l','u','e',0}; 310 static WCHAR empty[] = {0}; 311 static WCHAR defaultX[] = {'d','e','f','a','u','l','t',0}; 312 static WCHAR def[] = {'d','e','f',0}; 313 static WCHAR value0[] = {'v','a','l','u','e','0','1','2','3','4','5','6','7','8','9',0}; 314 static WCHAR testingvalue[] = {'t','e','s','t','i','n','g',0,'v','a','l','u','e',0}; 315 int ret; 316 WCHAR buffer[256] = {0}; 317 LONG reg_ret; 318 319 lstrcpyW(buffer, wine); 320 ret = SQLGetPrivateProfileStringW(NULL, testing , defaultval, buffer, 256, odbcini); 321 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 322 ok(!lstrcmpW(buffer, wine), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 323 324 lstrcpyW(buffer, wine); 325 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , defaultval, buffer, 256, odbcini); 326 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 327 ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 328 329 lstrcpyW(buffer, value); 330 ret = SQLGetPrivateProfileStringW(wineodbc, testing , NULL, buffer, 256, odbcini); 331 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 332 ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 333 334 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, odbcini); 335 ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret); 336 ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 337 338 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 4, odbcini); 339 ok(ret == lstrlenW(def), "SQLGetPrivateProfileStringW returned %d\n", ret); 340 ok(!lstrcmpW(buffer, def), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 341 342 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 8, odbcini); 343 ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret); 344 ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 345 346 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 256, odbcini); 347 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 348 349 lstrcpyW(buffer, value); 350 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 0, odbcini); 351 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 352 ok(!lstrcmpW(buffer, value), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 353 354 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini"); 355 ok(ret, "SQLWritePrivateProfileString failed\n"); 356 if(ret) 357 { 358 HKEY hkey; 359 360 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, abcdini); 361 ok(ret == lstrlenW(value0), "SQLGetPrivateProfileStringW returned %d\n", ret); 362 ok(!lstrcmpW(buffer, value0), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 363 364 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 0, abcdini); 365 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 366 367 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 7, abcdini); 368 ok(ret == 6, "SQLGetPrivateProfileStringW returned %d\n", ret); 369 370 lstrcpyW(buffer, wine); 371 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini); 372 ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret); 373 ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 374 375 ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini"); 376 ok(ret, "SQLWritePrivateProfileString failed\n"); 377 378 lstrcpyW(buffer, wine); 379 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 256, abcdini); 380 ok(ret == (lstrlenW(testing) + lstrlenW(value)+2), "SQLGetPrivateProfileStringW returned %d\n", ret); 381 if(ret == (lstrlenW(testing) + lstrlenW(value)+2)) 382 { 383 ok(!memcmp(buffer, testingvalue, sizeof(testingvalue)), 384 "incorrect string '%s'\n", wine_dbgstr_wn(buffer, ret)); 385 } 386 387 lstrcpyW(buffer, value); 388 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini); 389 ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret); 390 if(ret >= lstrlenW(testing)+1) 391 { 392 ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer)); 393 } 394 395 lstrcpyW(buffer, value); 396 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 2, abcdini); 397 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret); 398 399 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey); 400 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 401 if(reg_ret == ERROR_SUCCESS) 402 { 403 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key); 404 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 405 406 RegCloseKey(hkey); 407 } 408 409 /* Cleanup key */ 410 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key); 411 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n"); 412 } 413 } 414 415 static void test_SQLInstallDriverEx(void) 416 { 417 char path[MAX_PATH]; 418 char syspath[MAX_PATH]; 419 WORD size = 0; 420 BOOL ret, sql_ret; 421 DWORD cnt, error_code = 0; 422 HKEY hkey; 423 LONG res; 424 char error[1000]; 425 426 GetSystemDirectoryA(syspath, MAX_PATH); 427 428 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", "CPTimeout=59", error, sizeof(error), NULL); 429 ok(!ret, "SQLConfigDriver returned %d\n", ret); 430 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 431 ok(sql_ret && error_code == ODBC_ERROR_COMPONENT_NOT_FOUND, "SQLConfigDriver returned %d, %u\n", sql_ret, error_code); 432 433 ret = SQLInstallDriverEx("WINE ODBC Driver\0Driver=sample.dll\0Setup=sample.dll\0\0", NULL, 434 path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL); 435 ok(ret, "SQLInstallDriverEx failed\n"); 436 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 437 if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED) 438 { 439 win_skip("not enough privileges\n"); 440 return; 441 } 442 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLInstallDriverEx failed %d, %u\n", sql_ret, error_code); 443 ok(!strcmp(path, syspath), "invalid path %s\n", path); 444 445 if (0) /* Crashes on XP. */ 446 { 447 sql_ret = 0; 448 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", NULL, error, sizeof(error), NULL); 449 ok(!ret, "SQLConfigDriver failed '%s'\n",error); 450 } 451 452 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", "CPTimeout=59\0NoWrite=60\0", error, sizeof(error), NULL); 453 ok(ret, "SQLConfigDriver failed\n"); 454 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 455 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLConfigDriver failed %d, %u\n", sql_ret, error_code); 456 457 ret = SQLInstallDriverEx("WINE ODBC Driver Path\0Driver=sample.dll\0Setup=sample.dll\0\0", "c:\\temp", path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL); 458 ok(ret, "SQLInstallDriverEx failed\n"); 459 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 460 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLInstallDriverEx failed %d, %u\n", sql_ret, error_code); 461 ok(!strcmp(path, "c:\\temp"), "invalid path %s\n", path); 462 463 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver Path", "empty", error, sizeof(error), NULL); 464 ok(!ret, "SQLConfigDriver successful\n"); 465 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 466 ok(sql_ret && error_code == ODBC_ERROR_INVALID_KEYWORD_VALUE, "SQLConfigDriver failed %d, %u\n", sql_ret, error_code); 467 468 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver Path", "NoWrite=60;xxxx=555", error, sizeof(error), NULL); 469 ok(ret, "SQLConfigDriver failed\n"); 470 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 471 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLConfigDriver failed %d, %u\n", sql_ret, error_code); 472 473 if (ret) 474 { 475 DWORD type = 0xdeadbeef, size = MAX_PATH; 476 477 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Driver", 0, KEY_READ, &hkey); 478 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 479 if (res == ERROR_SUCCESS) 480 { 481 char driverpath[MAX_PATH]; 482 483 strcpy(driverpath, syspath); 484 strcat(driverpath, "\\sample.dll"); 485 486 memset(path, 0, sizeof(path)); 487 res = RegQueryValueExA(hkey, "Driver", NULL, &type, (BYTE *)path, &size); 488 ok(res == ERROR_SUCCESS, "got %d\n", res); 489 ok(type == REG_SZ, "got %u\n", type); 490 ok(size == strlen(driverpath) + 1, "got %u\n", size); 491 ok(!strcmp(path, driverpath), "invalid path %s\n", path); 492 493 res = RegQueryValueExA(hkey, "CPTimeout", NULL, &type, (BYTE *)&path, &size); 494 ok(res == ERROR_SUCCESS, "got %d\n", res); 495 ok(type == REG_SZ, "got %u\n", type); 496 ok(size == strlen("59") + 1, "got %u\n", size); 497 ok(!strcmp(path, "59"), "invalid value %s\n", path); 498 499 res = RegQueryValueExA(hkey, "NoWrite", NULL, &type, (BYTE *)&path, &size); 500 ok(res == ERROR_FILE_NOT_FOUND, "got %d\n", res); 501 502 RegCloseKey(hkey); 503 } 504 505 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Driver Path", 0, KEY_READ, &hkey); 506 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 507 if (res == ERROR_SUCCESS) 508 { 509 size = sizeof(path); 510 res = RegQueryValueExA(hkey, "NoWrite", NULL, &type, (BYTE *)&path, &size); 511 ok(res == ERROR_SUCCESS, "got %d\n", res); 512 ok(type == REG_SZ, "got %u\n", type); 513 ok(size == strlen("60;xxxx=555") + 1, "got %u\n", size); 514 ok(!strcmp(path, "60;xxxx=555"), "invalid value %s\n", path); 515 516 res = RegQueryValueExA(hkey, "CPTimeout", NULL, &type, (BYTE *)&path, &size); 517 ok(res == ERROR_FILE_NOT_FOUND, "got %d\n", res); 518 RegCloseKey(hkey); 519 } 520 } 521 522 cnt = 100; 523 ret = SQLRemoveDriver("WINE ODBC Driver", FALSE, &cnt); 524 ok(ret, "SQLRemoveDriver failed\n"); 525 ok(cnt == 0, "SQLRemoveDriver failed %d\n", cnt); 526 527 cnt = 100; 528 ret = SQLRemoveDriver("WINE ODBC Driver Path", FALSE, &cnt); 529 ok(ret, "SQLRemoveDriver failed\n"); 530 ok(cnt == 0, "SQLRemoveDriver failed %d\n", cnt); 531 } 532 533 static void test_SQLInstallTranslatorEx(void) 534 { 535 char path[MAX_PATH]; 536 char syspath[MAX_PATH]; 537 WORD size = 0; 538 BOOL ret, sql_ret; 539 DWORD cnt, error_code = 0; 540 HKEY hkey; 541 LONG res; 542 543 GetSystemDirectoryA(syspath, MAX_PATH); 544 545 ret = SQLInstallTranslatorEx("WINE ODBC Translator\0Translator=sample.dll\0Setup=sample.dll\0", 546 NULL, path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL); 547 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 548 if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED) 549 { 550 win_skip("not enough privileges\n"); 551 return; 552 } 553 ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallDriverEx failed %d, %u\n", sql_ret, error_code); 554 ok(!strcmp(path, syspath), "invalid path %s\n", path); 555 ok(size == strlen(path), "invalid length %d\n", size); 556 557 ret = SQLInstallTranslatorEx("WINE ODBC Translator Path\0Translator=sample.dll\0Setup=sample.dll\0", 558 "c:\\temp", path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL); 559 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 560 ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallTranslatorEx failed %d, %u\n", sql_ret, error_code); 561 ok(!strcmp(path, "c:\\temp"), "invalid path %s\n", path); 562 ok(size == strlen(path), "invalid length %d\n", size); 563 564 if(ret) 565 { 566 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Translator", 0, 567 KEY_READ, &hkey); 568 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n"); 569 if (res == ERROR_SUCCESS) 570 { 571 DWORD type = 0xdeadbeef, size = MAX_PATH; 572 char driverpath[MAX_PATH]; 573 574 strcpy(driverpath, syspath); 575 strcat(driverpath, "\\sample.dll"); 576 577 memset(path, 0, sizeof(path)); 578 res = RegQueryValueExA(hkey, "Translator", NULL, &type, (BYTE *)path, &size); 579 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n"); 580 ok(type == REG_SZ, "got %u\n", type); 581 ok(size == strlen(driverpath) + 1, "got %u\n", size); 582 ok(!strcmp(path, driverpath), "invalid path %s\n", path); 583 584 RegCloseKey(hkey); 585 } 586 } 587 588 cnt = 100; 589 ret = SQLRemoveTranslator("WINE ODBC Translator", &cnt); 590 ok(ret, "SQLRemoveTranslator failed\n"); 591 ok(cnt == 0, "SQLRemoveTranslator failed %d\n", cnt); 592 593 cnt = 100; 594 ret = SQLRemoveTranslator("WINE ODBC Translator Path", &cnt); 595 ok(ret, "SQLRemoveTranslator failed\n"); 596 ok(cnt == 0, "SQLRemoveTranslator failed %d\n", cnt); 597 598 cnt = 100; 599 ret = SQLRemoveTranslator("WINE ODBC Translator NonExist", &cnt); 600 ok(!ret, "SQLRemoveTranslator succeeded\n"); 601 ok(cnt == 100, "SQLRemoveTranslator succeeded %d\n", cnt); 602 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL); 603 ok(sql_ret && error_code == ODBC_ERROR_COMPONENT_NOT_FOUND, 604 "SQLInstallTranslatorEx failed %d, %u\n", sql_ret, error_code); 605 606 } 607 608 START_TEST(misc) 609 { 610 test_SQLConfigMode(); 611 test_SQLInstallerError(); 612 test_SQLInstallDriverManager(); 613 test_SQLWritePrivateProfileString(); 614 test_SQLGetPrivateProfileString(); 615 test_SQLGetPrivateProfileStringW(); 616 test_SQLInstallDriverEx(); 617 test_SQLInstallTranslatorEx(); 618 } 619