include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / odbccp32 / tests / misc.c
blob3b812b77726e3141c877c78903efec954fc59b4e
1 /*
2 * Copyright 2007 Bill Medland
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.
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.
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
19 #include <wine/test.h>
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winreg.h"
25 #include "odbcinst.h"
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 };
30 static void check_error_(int line, DWORD expect)
32 RETCODE ret;
33 DWORD err;
34 ret = SQLInstallerError(1, &err, NULL, 0, NULL);
35 ok_(__FILE__, line)(ret == SQL_SUCCESS_WITH_INFO, "got %d\n", ret);
36 ok_(__FILE__, line)(err == expect, "expected %lu, got %u\n", expect, ret);
38 #define check_error(a) check_error_(__LINE__, a)
40 static void test_SQLConfigMode(void)
42 BOOL bool_ret;
43 DWORD error_code;
44 RETCODE sql_ret;
45 UWORD config_mode;
46 int i;
48 ok(SQLGetConfigMode(NULL), "SQLGetConfigMode(NULL) should succeed\n");
50 bool_ret = SQLGetConfigMode(&config_mode);
51 ok(bool_ret && config_mode == ODBC_BOTH_DSN, "Failed to get the initial SQLGetConfigMode or it was not both\n");
53 /* try to set invalid mode */
54 bool_ret = SQLSetConfigMode(ODBC_SYSTEM_DSN+1);
55 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
56 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");
58 for (i = ODBC_SYSTEM_DSN; i >= ODBC_BOTH_DSN; --i)
60 ok(SQLSetConfigMode((UWORD)i), "SQLSetConfigMode Failed to set config mode\n");
61 bool_ret = SQLGetConfigMode(&config_mode);
62 ok(bool_ret && config_mode == i, "Failed to confirm SQLSetConfigMode.\n");
64 /* And that leaves it correctly on BOTH */
67 static void test_SQLInstallerError(void)
69 RETCODE sql_ret;
71 /* MSDN states that the error number should be between 1 and 8. Passing 0 is an error */
72 sql_ret = SQLInstallerError(0, NULL, NULL, 0, NULL);
73 ok(sql_ret == SQL_ERROR, "SQLInstallerError(0...) failed with %d instead of SQL_ERROR\n", sql_ret);
74 /* However numbers greater than 8 do not return SQL_ERROR.
75 * I am currently unsure as to whether it should return SQL_NO_DATA or "the same as for error 8";
76 * I have never been able to generate 8 errors to test it
78 sql_ret = SQLInstallerError(65535, NULL, NULL, 0, NULL);
79 ok(sql_ret == SQL_NO_DATA, "SQLInstallerError(>8...) failed with %d instead of SQL_NO_DATA\n", sql_ret);
81 /* Force an error to work with. This should generate ODBC_ERROR_INVALID_BUFF_LEN */
82 ok(!SQLGetInstalledDrivers(0, 0, 0), "Failed to force an error for testing\n");
83 sql_ret = SQLInstallerError(2, NULL, NULL, 0, NULL);
84 ok(sql_ret == SQL_NO_DATA, "Too many errors when forcing an error for testing\n");
86 /* Null pointers are acceptable in all obvious places */
87 sql_ret = SQLInstallerError(1, NULL, NULL, 0, NULL);
88 ok(sql_ret == SQL_SUCCESS_WITH_INFO, "SQLInstallerError(null addresses) failed with %d instead of SQL_SUCCESS_WITH_INFO\n", sql_ret);
91 static void test_SQLInstallDriverManager(void)
93 BOOL bool_ret;
94 RETCODE sql_ret;
95 DWORD error_code;
96 CHAR target_path[MAX_PATH];
97 WORD path_out;
99 /* NULL check */
100 bool_ret = SQLInstallDriverManager(NULL, 0, NULL);
101 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
102 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
103 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
104 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
106 /* Length smaller than MAX_PATH */
107 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, NULL);
108 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
109 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
110 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
111 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
113 path_out = 0xcafe;
114 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, &path_out);
115 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
116 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
117 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
118 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
119 ok(path_out == 0xcafe, "Expected path_out to not have changed\n");
121 /* Length OK */
122 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, NULL);
123 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
124 if(!bool_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED)
126 win_skip("not enough privileges\n");
127 return;
129 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %ld\n",
130 error_code);
131 if (bool_ret)
132 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
133 else
134 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
135 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
137 path_out = 0xcafe;
138 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, &path_out);
139 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
140 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %ld\n",
141 error_code);
142 if (bool_ret)
143 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
144 else
145 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
146 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
147 /* path_out should in practice be less than 0xcafe */
148 ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n");
151 static void test_SQLWritePrivateProfileString(void)
153 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};
154 BOOL ret;
155 LONG reg_ret;
156 DWORD error_code;
158 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "");
159 ok(!ret, "SQLWritePrivateProfileString passed\n");
160 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
161 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %ld\n", error_code);
163 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", NULL);
164 ok(!ret, "SQLWritePrivateProfileString passed\n");
165 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
166 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %ld\n", error_code);
168 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "odbc.ini");
169 ok(ret, "SQLWritePrivateProfileString failed\n");
170 if(ret)
172 HKEY hkey;
174 ret = SQLWritePrivateProfileString("wineodbc", "testing" , NULL, "odbc.ini");
175 ok(ret, "SQLWritePrivateProfileString failed\n");
177 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, odbc_key, 0, KEY_READ, &hkey);
178 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
179 if(reg_ret == ERROR_SUCCESS)
181 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, odbc_key);
182 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
184 RegCloseKey(hkey);
188 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "abcd.ini");
189 ok(ret, "SQLWritePrivateProfileString failed\n");
190 if(ret)
192 HKEY hkey;
194 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey);
195 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
196 if(reg_ret == ERROR_SUCCESS)
198 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key);
199 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
201 RegCloseKey(hkey);
204 /* Cleanup key */
205 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key);
206 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
210 static void test_SQLGetPrivateProfileString(void)
212 int ret;
213 char buffer[256] = {0};
214 LONG reg_ret;
216 strcpy(buffer, "wine");
217 ret = SQLGetPrivateProfileString(NULL, "testing" , "default", buffer, 256, "ODBC.INI");
218 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
219 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
221 strcpy(buffer, "wine");
222 ret = SQLGetPrivateProfileString("wineodbc", NULL , "default", buffer, 256, "ODBC.INI");
223 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
224 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
226 strcpy(buffer, "value");
227 ret = SQLGetPrivateProfileString("wineodbc", "testing" , NULL, buffer, 256, "ODBC.INI");
228 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
229 ok(!strcmp(buffer, ""), "incorrect string '%s'\n", buffer);
231 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 256, "ODBC.INI");
232 ok(ret == strlen("defaultX"), "SQLGetPrivateProfileString returned %d\n", ret);
233 ok(!strcmp(buffer, "defaultX"), "incorrect string '%s'\n", buffer);
235 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 4, "ODBC.INI");
236 ok(ret == strlen("def"), "SQLGetPrivateProfileString returned %d\n", ret);
237 ok(!strcmp(buffer, "def"), "incorrect string '%s'\n", buffer);
239 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 8, "ODBC.INI");
240 ok(ret == strlen("default"), "SQLGetPrivateProfileString returned %d\n", ret);
241 ok(!strcmp(buffer, "default"), "incorrect string '%s'\n", buffer);
243 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", NULL, 256, "ODBC.INI");
244 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
246 strcpy(buffer, "value");
247 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", buffer, 0, "ODBC.INI");
248 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
249 ok(!strcmp(buffer, "value"), "incorrect string '%s'\n", buffer);
251 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
252 ok(ret, "SQLWritePrivateProfileString failed\n");
253 if(ret)
255 HKEY hkey;
257 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 256, "abcd.ini");
258 ok(ret == strlen("value0123456789"), "SQLGetPrivateProfileString returned %d\n", ret);
259 ok(!strcmp(buffer, "value0123456789"), "incorrect string '%s'\n", buffer);
261 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", NULL, 0, "abcd.ini");
262 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
264 ret = SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer, 7, "abcd.ini");
265 ok(ret == 6, "SQLGetPrivateProfileString returned %d\n", ret);
267 strcpy(buffer, "wine");
268 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini");
269 ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret);
270 ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer);
272 ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
273 ok(ret, "SQLWritePrivateProfileString failed\n");
275 strcpy(buffer, "wine");
276 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 256, "abcd.ini");
277 ok(ret == (strlen("testing") + strlen("value")+2), "SQLGetPrivateProfileString returned %d\n", ret);
278 if(ret >= (strlen("testing") + strlen("value")+2))
280 ok(memcmp(buffer, "testing\0value\0", 14) == 0, "incorrect string '%s'\n", buffer);
283 strcpy(buffer, "XXXXXXXXXXXXXXX");
284 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 10, "abcd.ini");
285 ok(ret == (strlen("testing")+1), "SQLGetPrivateProfileString returned %d\n", ret);
286 if(ret >= (strlen("testing")+1))
288 ok(!strcmp(buffer, "testing"), "incorrect string '%s'\n", buffer);
289 /* Show that the buffer is cleared and partial enteries aren't added */
290 ok(memcmp(buffer, "testing\0X", 9) != 0, "incorrect string '%s'\n", buffer);
293 strcpy(buffer, "wine");
294 ret = SQLGetPrivateProfileString("wineodbc", NULL , "", buffer, 2, "abcd.ini");
295 ok(ret == 0, "SQLGetPrivateProfileString returned %d\n", ret);
297 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey);
298 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
299 if(reg_ret == ERROR_SUCCESS)
301 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key);
302 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
304 RegCloseKey(hkey);
307 /* Cleanup key */
308 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key);
309 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
313 static void test_SQLGetPrivateProfileStringW(void)
315 static WCHAR testing[] = {'t','e','s','t','i','n','g',0};
316 static WCHAR wineodbc[] = {'w','i','n','e','o','d','b','c',0};
317 static WCHAR defaultval[] = {'d','e','f','a','u','l','t',0};
318 static WCHAR odbcini[] = {'O','D','B','C','.','I','N','I',0};
319 static WCHAR abcdini[] = {'a','b','c','d','.','I','N','I',0};
320 static WCHAR wine[] = {'w','i','n','e',0};
321 static WCHAR value[] = {'v','a','l','u','e',0};
322 static WCHAR empty[] = {0};
323 static WCHAR defaultX[] = {'d','e','f','a','u','l','t',0};
324 static WCHAR def[] = {'d','e','f',0};
325 static WCHAR value0[] = {'v','a','l','u','e','0','1','2','3','4','5','6','7','8','9',0};
326 static WCHAR testingvalue[] = {'t','e','s','t','i','n','g',0,'v','a','l','u','e',0};
327 int ret;
328 WCHAR buffer[256] = {0};
329 LONG reg_ret;
331 lstrcpyW(buffer, wine);
332 ret = SQLGetPrivateProfileStringW(NULL, testing , defaultval, buffer, 256, odbcini);
333 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
334 ok(!lstrcmpW(buffer, wine), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
336 lstrcpyW(buffer, wine);
337 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , defaultval, buffer, 256, odbcini);
338 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
339 ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
341 lstrcpyW(buffer, value);
342 ret = SQLGetPrivateProfileStringW(wineodbc, testing , NULL, buffer, 256, odbcini);
343 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
344 ok(!lstrcmpW(buffer, empty), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
346 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, odbcini);
347 ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret);
348 ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
350 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 4, odbcini);
351 ok(ret == lstrlenW(def), "SQLGetPrivateProfileStringW returned %d\n", ret);
352 ok(!lstrcmpW(buffer, def), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
354 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 8, odbcini);
355 ok(ret == lstrlenW(defaultX), "SQLGetPrivateProfileStringW returned %d\n", ret);
356 ok(!lstrcmpW(buffer, defaultX), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
358 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 256, odbcini);
359 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
361 lstrcpyW(buffer, value);
362 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 0, odbcini);
363 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
364 ok(!lstrcmpW(buffer, value), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
366 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
367 ok(ret, "SQLWritePrivateProfileString failed\n");
368 if(ret)
370 HKEY hkey;
372 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 256, abcdini);
373 ok(ret == lstrlenW(value0), "SQLGetPrivateProfileStringW returned %d\n", ret);
374 ok(!lstrcmpW(buffer, value0), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
376 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, NULL, 0, abcdini);
377 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
379 ret = SQLGetPrivateProfileStringW(wineodbc, testing , defaultX, buffer, 7, abcdini);
380 ok(ret == 6, "SQLGetPrivateProfileStringW returned %d\n", ret);
382 lstrcpyW(buffer, wine);
383 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini);
384 ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret);
385 ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
387 ret = SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
388 ok(ret, "SQLWritePrivateProfileString failed\n");
390 lstrcpyW(buffer, wine);
391 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 256, abcdini);
392 ok(ret == (lstrlenW(testing) + lstrlenW(value)+2), "SQLGetPrivateProfileStringW returned %d\n", ret);
393 if(ret == (lstrlenW(testing) + lstrlenW(value)+2))
395 ok(!memcmp(buffer, testingvalue, sizeof(testingvalue)),
396 "incorrect string '%s'\n", wine_dbgstr_wn(buffer, ret));
399 lstrcpyW(buffer, value);
400 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 10, abcdini);
401 ok(ret == lstrlenW(testing)+1, "SQLGetPrivateProfileStringW returned %d\n", ret);
402 if(ret >= lstrlenW(testing)+1)
404 ok(!lstrcmpW(buffer, testing), "incorrect string '%s'\n", wine_dbgstr_w(buffer));
407 lstrcpyW(buffer, value);
408 ret = SQLGetPrivateProfileStringW(wineodbc, NULL , empty, buffer, 2, abcdini);
409 ok(ret == 0, "SQLGetPrivateProfileStringW returned %d\n", ret);
411 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey);
412 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
413 if(reg_ret == ERROR_SUCCESS)
415 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key);
416 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
418 RegCloseKey(hkey);
421 /* Cleanup key */
422 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key);
423 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
427 static void test_SQLInstallDriverEx(void)
429 char path[MAX_PATH];
430 char syspath[MAX_PATH];
431 WORD size = 0;
432 BOOL ret, sql_ret;
433 DWORD cnt, error_code = 0;
434 HKEY hkey;
435 LONG res;
436 char error[1000];
438 GetSystemDirectoryA(syspath, MAX_PATH);
440 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", "CPTimeout=59", error, sizeof(error), NULL);
441 ok(!ret, "SQLConfigDriver returned %d\n", ret);
442 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
443 ok(sql_ret && error_code == ODBC_ERROR_COMPONENT_NOT_FOUND, "SQLConfigDriver returned %d, %lu\n", sql_ret, error_code);
445 ret = SQLInstallDriverEx("WINE ODBC Driver\0Driver=sample.dll\0Setup=sample.dll\0\0", NULL,
446 path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
447 ok(ret, "SQLInstallDriverEx failed\n");
448 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
449 if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED)
451 win_skip("not enough privileges\n");
452 return;
454 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLInstallDriverEx failed %d, %lu\n", sql_ret, error_code);
455 ok(!strcmp(path, syspath), "invalid path %s\n", path);
457 if (0) /* Crashes on XP. */
459 sql_ret = 0;
460 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", NULL, error, sizeof(error), NULL);
461 ok(!ret, "SQLConfigDriver failed '%s'\n",error);
464 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver", "CPTimeout=59\0NoWrite=60\0", error, sizeof(error), NULL);
465 ok(ret, "SQLConfigDriver failed\n");
466 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
467 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLConfigDriver failed %d, %lu\n", sql_ret, error_code);
469 ret = SQLInstallDriverEx("WINE ODBC Driver Path\0Driver=sample.dll\0Setup=sample.dll\0\0", "c:\\temp", path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
470 ok(ret, "SQLInstallDriverEx failed\n");
471 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
472 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLInstallDriverEx failed %d, %lu\n", sql_ret, error_code);
473 ok(!strcmp(path, "c:\\temp"), "invalid path %s\n", path);
475 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver Path", "empty", error, sizeof(error), NULL);
476 ok(!ret, "SQLConfigDriver successful\n");
477 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
478 ok(sql_ret && error_code == ODBC_ERROR_INVALID_KEYWORD_VALUE, "SQLConfigDriver failed %d, %lu\n", sql_ret, error_code);
480 ret = SQLConfigDriver(NULL, ODBC_CONFIG_DRIVER, "WINE ODBC Driver Path", "NoWrite=60;xxxx=555", error, sizeof(error), NULL);
481 ok(ret, "SQLConfigDriver failed\n");
482 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
483 ok(sql_ret == SQL_NO_DATA || (sql_ret && error_code == SQL_SUCCESS), "SQLConfigDriver failed %d, %lu\n", sql_ret, error_code);
485 if (ret)
487 DWORD type = 0xdeadbeef, size = MAX_PATH;
489 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Driver", 0, KEY_READ, &hkey);
490 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
491 if (res == ERROR_SUCCESS)
493 char driverpath[MAX_PATH];
495 strcpy(driverpath, syspath);
496 strcat(driverpath, "\\sample.dll");
498 memset(path, 0, sizeof(path));
499 res = RegQueryValueExA(hkey, "Driver", NULL, &type, (BYTE *)path, &size);
500 ok(res == ERROR_SUCCESS, "got %ld\n", res);
501 ok(type == REG_SZ, "got %lu\n", type);
502 ok(size == strlen(driverpath) + 1, "got %lu\n", size);
503 ok(!strcmp(path, driverpath), "invalid path %s\n", path);
505 res = RegQueryValueExA(hkey, "CPTimeout", NULL, &type, (BYTE *)&path, &size);
506 ok(res == ERROR_SUCCESS, "got %ld\n", res);
507 ok(type == REG_SZ, "got %lu\n", type);
508 ok(size == strlen("59") + 1, "got %lu\n", size);
509 ok(!strcmp(path, "59"), "invalid value %s\n", path);
511 res = RegQueryValueExA(hkey, "NoWrite", NULL, &type, (BYTE *)&path, &size);
512 ok(res == ERROR_FILE_NOT_FOUND, "got %ld\n", res);
514 RegCloseKey(hkey);
517 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Driver Path", 0, KEY_READ, &hkey);
518 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
519 if (res == ERROR_SUCCESS)
521 size = sizeof(path);
522 res = RegQueryValueExA(hkey, "NoWrite", NULL, &type, (BYTE *)&path, &size);
523 ok(res == ERROR_SUCCESS, "got %ld\n", res);
524 ok(type == REG_SZ, "got %lu\n", type);
525 ok(size == strlen("60;xxxx=555") + 1, "got %lu\n", size);
526 ok(!strcmp(path, "60;xxxx=555"), "invalid value %s\n", path);
528 res = RegQueryValueExA(hkey, "CPTimeout", NULL, &type, (BYTE *)&path, &size);
529 ok(res == ERROR_FILE_NOT_FOUND, "got %ld\n", res);
530 RegCloseKey(hkey);
534 cnt = 100;
535 ret = SQLRemoveDriver("WINE ODBC Driver", FALSE, &cnt);
536 ok(ret, "SQLRemoveDriver failed\n");
537 ok(cnt == 0, "SQLRemoveDriver failed %ld\n", cnt);
539 cnt = 100;
540 ret = SQLRemoveDriver("WINE ODBC Driver Path", FALSE, &cnt);
541 ok(ret, "SQLRemoveDriver failed\n");
542 ok(cnt == 0, "SQLRemoveDriver failed %ld\n", cnt);
545 static void test_SQLInstallTranslatorEx(void)
547 char path[MAX_PATH];
548 char syspath[MAX_PATH];
549 WORD size = 0;
550 BOOL ret, sql_ret;
551 DWORD cnt, error_code = 0;
552 HKEY hkey;
553 LONG res;
555 GetSystemDirectoryA(syspath, MAX_PATH);
557 ret = SQLInstallTranslatorEx("WINE ODBC Translator\0Translator=sample.dll\0Setup=sample.dll\0",
558 NULL, path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
559 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
560 if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED)
562 win_skip("not enough privileges\n");
563 return;
565 ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallDriverEx failed %d, %lu\n", sql_ret, error_code);
566 ok(!strcmp(path, syspath), "invalid path %s\n", path);
567 ok(size == strlen(path), "invalid length %d\n", size);
569 ret = SQLInstallTranslatorEx("WINE ODBC Translator Path\0Translator=sample.dll\0Setup=sample.dll\0",
570 "c:\\temp", path, MAX_PATH, &size, ODBC_INSTALL_COMPLETE, NULL);
571 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
572 ok(sql_ret && error_code == SQL_SUCCESS, "SQLInstallTranslatorEx failed %d, %lu\n", sql_ret, error_code);
573 ok(!strcmp(path, "c:\\temp"), "invalid path %s\n", path);
574 ok(size == strlen(path), "invalid length %d\n", size);
576 if(ret)
578 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI\\WINE ODBC Translator", 0,
579 KEY_READ, &hkey);
580 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
581 if (res == ERROR_SUCCESS)
583 DWORD type = 0xdeadbeef, size = MAX_PATH;
584 char driverpath[MAX_PATH];
586 strcpy(driverpath, syspath);
587 strcat(driverpath, "\\sample.dll");
589 memset(path, 0, sizeof(path));
590 res = RegQueryValueExA(hkey, "Translator", NULL, &type, (BYTE *)path, &size);
591 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
592 ok(type == REG_SZ, "got %lu\n", type);
593 ok(size == strlen(driverpath) + 1, "got %lu\n", size);
594 ok(!strcmp(path, driverpath), "invalid path %s\n", path);
596 RegCloseKey(hkey);
600 cnt = 100;
601 ret = SQLRemoveTranslator("WINE ODBC Translator", &cnt);
602 ok(ret, "SQLRemoveTranslator failed\n");
603 ok(cnt == 0, "SQLRemoveTranslator failed %ld\n", cnt);
605 cnt = 100;
606 ret = SQLRemoveTranslator("WINE ODBC Translator Path", &cnt);
607 ok(ret, "SQLRemoveTranslator failed\n");
608 ok(cnt == 0, "SQLRemoveTranslator failed %ld\n", cnt);
610 cnt = 100;
611 ret = SQLRemoveTranslator("WINE ODBC Translator NonExist", &cnt);
612 ok(!ret, "SQLRemoveTranslator succeeded\n");
613 ok(cnt == 100, "SQLRemoveTranslator succeeded %ld\n", cnt);
614 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
615 ok(sql_ret && error_code == ODBC_ERROR_COMPONENT_NOT_FOUND,
616 "SQLInstallTranslatorEx failed %d, %lu\n", sql_ret, error_code);
620 static void test_SQLGetInstalledDrivers(void)
622 char buffer[1000], *p;
623 WORD written, len;
624 BOOL ret, sql_ret;
625 DWORD error_code;
626 int found = 0;
628 ret = SQLInstallDriverEx("Wine test\0Driver=test.dll\0\0", NULL, buffer,
629 sizeof(buffer), &written, ODBC_INSTALL_COMPLETE, NULL);
630 ok(ret, "SQLInstallDriverEx failed: %d\n", ret);
631 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
632 if (sql_ret && error_code == ODBC_ERROR_WRITING_SYSINFO_FAILED)
634 skip("not enough privileges\n");
635 return;
638 ret = SQLGetInstalledDrivers(NULL, sizeof(buffer), &written);
639 ok(!ret, "got %d\n", ret);
640 check_error(ODBC_ERROR_INVALID_BUFF_LEN);
642 ret = SQLGetInstalledDrivers(buffer, 0, &written);
643 ok(!ret, "got %d\n", ret);
644 check_error(ODBC_ERROR_INVALID_BUFF_LEN);
646 ret = SQLGetInstalledDrivers(buffer, 10, NULL);
647 ok(ret, "got %d\n", ret);
648 ok(strlen(buffer) == 8, "got len %u\n", lstrlenA(buffer));
649 ok(!buffer[9], "buffer not doubly null-terminated\n");
651 ret = SQLGetInstalledDrivers(buffer, 10, &written);
652 ok(ret, "got %d\n", ret);
653 ok(strlen(buffer) == 8, "got len %u\n", lstrlenA(buffer));
654 ok(written == 10, "got written %d\n", written);
655 ok(!buffer[9], "buffer not doubly null-terminated\n");
657 ret = SQLGetInstalledDrivers(buffer, sizeof(buffer), &written);
658 ok(ret, "got %d\n", ret);
659 ok(!buffer[written-1] && !buffer[written-2], "buffer not doubly null-terminated\n");
660 len = strlen(buffer);
662 for (p = buffer; *p; p += strlen(p) + 1)
664 if (!strcmp(p, "Wine test"))
665 found = 1;
667 ok(found, "installed driver not found\n");
669 ret = SQLGetInstalledDrivers(buffer, len, &written);
670 ok(ret, "got %d\n", ret);
671 ok(strlen(buffer) == len-2, "expected len %d, got %u\n", len-2, lstrlenA(buffer));
672 ok(written == len, "expected written %d, got %d\n", len, written);
673 ok(!buffer[len-1], "buffer not doubly null-terminated\n");
675 ret = SQLGetInstalledDrivers(buffer, len+1, &written);
676 ok(ret, "got %d\n", ret);
677 ok(strlen(buffer) == len-1, "expected len %d, got %u\n", len-1, lstrlenA(buffer));
678 ok(written == len+1, "expected written %d, got %d\n", len+1, written);
679 ok(!buffer[len], "buffer not doubly null-terminated\n");
681 ret = SQLGetInstalledDrivers(buffer, len+2, &written);
682 ok(ret, "got %d\n", ret);
683 ok(strlen(buffer) == len, "expected len %d, got %u\n", len, lstrlenA(buffer));
684 ok(written == len+2, "expected written %d, got %d\n", len+2, written);
685 ok(!buffer[len+1], "buffer not doubly null-terminated\n");
687 SQLRemoveDriver("Wine test", TRUE, NULL);
690 static void test_SQLValidDSN(void)
692 static const char *invalid = "[]{}(),;?*=!@\\";
693 char str[10];
694 int i;
695 BOOL ret;
697 strcpy(str, "wine10");
698 for(i = 0; i < strlen(invalid); i++)
700 str[4] = invalid[i];
701 ret = SQLValidDSN(str);
702 ok(!ret, "got %d\n", ret);
705 /* Too large */
706 ret = SQLValidDSN("Wine123456789012345678901234567890");
707 ok(!ret, "got %d\n", ret);
709 /* Valid with a space */
710 ret = SQLValidDSN("Wine Vinegar");
711 ok(ret, "got %d\n", ret);
713 /* Max DSN name value */
714 ret = SQLValidDSN("12345678901234567890123456789012");
715 ok(ret, "got %d\n", ret);
718 static void test_SQLValidDSNW(void)
720 static const WCHAR invalid[] = {'[',']','{','}','(',')',',',';','?','*','=','!','@','\\',0};
721 static const WCHAR value[] = { 'w','i','n','e','1','0',0};
722 static const WCHAR too_large[] = { 'W','i','n','e','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5',
723 '6','7','8','9','0','1','2','3','4','5','6','7','8','9','0', 0};
724 static const WCHAR with_space[] = { 'W','i','n','e',' ','V','i','n','e','g','a','r', 0};
725 static const WCHAR max_dsn[] = { '1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0',
726 '1','2','3','4','5','6','7','8','9','0','1','2', 0};
727 WCHAR str[10];
728 int i;
729 BOOL ret;
731 lstrcpyW(str, value);
732 for(i = 0; i < lstrlenW(invalid); i++)
734 str[4] = invalid[i];
735 ret = SQLValidDSNW(str);
736 ok(!ret, "got %d\n", ret);
739 ret = SQLValidDSNW(too_large);
740 ok(!ret, "got %d\n", ret);
742 ret = SQLValidDSNW(with_space);
743 ok(ret, "got %d\n", ret);
745 ret = SQLValidDSNW(max_dsn);
746 ok(ret, "got %d\n", ret);
749 static void test_SQLConfigDataSource(void)
751 BOOL ret;
753 ret = SQLConfigDataSource(0, ODBC_ADD_DSN, "SQL Server", "DSN=WINEMQIS\0Database=MQIS\0\0");
754 todo_wine ok(ret, "got %d\n", ret);
756 ret = SQLConfigDataSource(0, ODBC_REMOVE_DSN, "SQL Server", "DSN=WINEMQIS\0\0");
757 todo_wine ok(ret, "got %d\n", ret);
759 ret = SQLConfigDataSource(0, ODBC_REMOVE_DSN, "SQL Server", "DSN=WINEMQIS\0\0");
760 if(!ret)
762 RETCODE ret;
763 DWORD err;
764 ret = SQLInstallerError(1, &err, NULL, 0, NULL);
765 ok(ret == SQL_SUCCESS_WITH_INFO, "got %d\n", ret);
766 todo_wine ok(err == ODBC_ERROR_INVALID_DSN, "got %lu\n", err);
769 ret = SQLConfigDataSource(0, ODBC_ADD_DSN, "ODBC driver", "DSN=ODBC data source\0\0");
770 ok(!ret, "got %d\n", ret);
771 check_error(ODBC_ERROR_COMPONENT_NOT_FOUND);
774 static void test_SQLWriteDSNToIni(void)
776 BOOL ret;
777 char buffer[MAX_PATH];
778 char path[MAX_PATH];
779 DWORD type, size;
781 SQLSetConfigMode(ODBC_SYSTEM_DSN);
783 ret = SQLWriteDSNToIni("wine_dbs", "SQL Server");
784 if (!ret)
786 win_skip("Doesn't have permission to write a System DSN\n");
787 return;
790 if(ret)
792 HKEY hkey;
793 LONG res;
795 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBC.INI\\ODBC Data Sources", 0,
796 KEY_READ, &hkey);
797 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
798 if (res == ERROR_SUCCESS)
800 type = 0xdeadbeef;
801 size = MAX_PATH;
803 memset(buffer, 0, sizeof(buffer));
804 res = RegQueryValueExA(hkey, "wine_dbs", NULL, &type, (BYTE *)buffer, &size);
805 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
806 ok(type == REG_SZ, "got %lu\n", type);
807 ok(!strcmp(buffer, "SQL Server"), "incorrect string '%s'\n", buffer);
809 RegCloseKey(hkey);
812 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBC.INI\\wine_dbs", 0,
813 KEY_READ, &hkey);
814 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
815 if (res == ERROR_SUCCESS)
817 type = 0xdeadbeef;
818 size = MAX_PATH;
820 memset(path, 0, sizeof(path));
821 res = RegQueryValueExA(hkey, "driver", NULL, &type, (BYTE *)path, &size);
822 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
823 ok(type == REG_SZ, "got %lu\n", type);
824 /* WINE doesn't have a 'SQL Server' driver available */
825 todo_wine ok(strlen(path) != 0, "Invalid value\n");
827 RegCloseKey(hkey);
830 ret = SQLRemoveDSNFromIni("wine_dbs");
831 ok(ret, "got %d\n", ret);
834 /* Show that values are written, even though an invalid driver was specified. */
835 ret = SQLWriteDSNToIni("wine_mis", "Missing Access Driver (*.mis)");
836 ok(ret, "got %d\n", ret);
837 if(ret)
839 HKEY hkey;
840 LONG res;
842 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBC.INI\\ODBC Data Sources", 0,
843 KEY_READ, &hkey);
844 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
845 if (res == ERROR_SUCCESS)
847 type = 0xdeadbeef;
848 size = MAX_PATH;
850 memset(buffer, 0, sizeof(buffer));
851 res = RegQueryValueExA(hkey, "wine_mis", NULL, &type, (BYTE *)buffer, &size);
852 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
853 ok(type == REG_SZ, "got %lu\n", type);
854 ok(!strcmp(buffer, "Missing Access Driver (*.mis)"), "incorrect string '%s'\n", buffer);
856 RegCloseKey(hkey);
859 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBC.INI\\wine_mis", 0,
860 KEY_READ, &hkey);
861 ok(res == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
862 if (res == ERROR_SUCCESS)
864 type = 0xdeadbeef;
865 size = MAX_PATH;
867 memset(path, 0, sizeof(path));
868 res = RegQueryValueExA(hkey, "driver", NULL, &type, (BYTE *)path, &size);
869 ok(res == ERROR_SUCCESS, "RegGetValueA failed\n");
870 ok(type == REG_SZ, "got %lu\n", type);
871 ok(strlen(path) == 0, "Invalid value\n");
873 RegCloseKey(hkey);
876 ret = SQLRemoveDSNFromIni("wine_mis");
877 ok(ret, "got %d\n", ret);
881 START_TEST(misc)
883 test_SQLConfigMode();
884 test_SQLInstallerError();
885 test_SQLInstallDriverManager();
886 test_SQLWritePrivateProfileString();
887 test_SQLGetPrivateProfileString();
888 test_SQLGetPrivateProfileStringW();
889 test_SQLInstallDriverEx();
890 test_SQLInstallTranslatorEx();
891 test_SQLGetInstalledDrivers();
892 test_SQLValidDSN();
893 test_SQLValidDSNW();
894 test_SQLConfigDataSource();
895 test_SQLWriteDSNToIni();