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>
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 };
31 static void test_SQLConfigMode(void)
39 ok(SQLGetConfigMode(NULL
), "SQLGetConfigMode(NULL) should succeed\n");
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");
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");
49 for (i
= ODBC_SYSTEM_DSN
; i
>= ODBC_BOTH_DSN
; --i
)
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");
55 /* And that leaves it correctly on BOTH */
58 static void test_SQLInstallerError(void)
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
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
);
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");
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
);
82 static void test_SQLInstallDriverManager(void)
87 CHAR target_path
[MAX_PATH
];
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");
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");
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");
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
)
117 win_skip("not enough privileges\n");
120 ok(bool_ret
, "SQLInstallDriverManager unexpectedly failed: %d\n",
123 ok(sql_ret
== SQL_NO_DATA
, "Expected SQL_NO_DATA, got %d\n", sql_ret
);
125 ok(sql_ret
== SQL_SUCCESS_WITH_INFO
,
126 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret
);
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",
134 ok(sql_ret
== SQL_NO_DATA
, "Expected SQL_NO_DATA, got %d\n", sql_ret
);
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");
142 static void test_SQLWritePrivateProfileString(void)
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};
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
);
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
);
159 ret
= SQLWritePrivateProfileString("wineodbc", "testing" , "value", "odbc.ini");
160 ok(ret
, "SQLWritePrivateProfileString failed\n");
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
)
169 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, odbc_key
);
170 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
176 ret
= SQLWritePrivateProfileString("wineodbc", "testing" , "value", "abcd.ini");
177 ok(ret
, "SQLWritePrivateProfileString failed\n");
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
)
186 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcd_key
);
187 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
193 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcdini_key
);
194 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
198 static void test_SQLGetPrivateProfileString(void)
201 char buffer
[256] = {0};
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
);
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
);
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
);
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
);
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
);
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
);
231 ret
= SQLGetPrivateProfileString("wineodbc", "testing" , "defaultX", NULL
, 256, "ODBC.INI");
232 ok(ret
== 0, "SQLGetPrivateProfileString returned %d\n", ret
);
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
);
239 ret
= SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
240 ok(ret
, "SQLWritePrivateProfileString failed\n");
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
);
249 ret
= SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", NULL
, 0, "abcd.ini");
250 ok(ret
== 0, "SQLGetPrivateProfileString returned %d\n", ret
);
252 ret
= SQLGetPrivateProfileString("wineodbc", "testing" , "defaultY", buffer
, 7, "abcd.ini");
253 ok(ret
== 6, "SQLGetPrivateProfileString returned %d\n", ret
);
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
);
260 ret
= SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
261 ok(ret
, "SQLWritePrivateProfileString failed\n");
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))
268 ok(memcmp(buffer
, "testing\0value\0", 14) == 0, "incorrect string '%s'\n", buffer
);
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))
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
);
281 strcpy(buffer
, "wine");
282 ret
= SQLGetPrivateProfileString("wineodbc", NULL
, "", buffer
, 2, "abcd.ini");
283 ok(ret
== 0, "SQLGetPrivateProfileString returned %d\n", ret
);
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
)
289 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcd_key
);
290 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
296 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcdini_key
);
297 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
301 static void test_SQLGetPrivateProfileStringW(void)
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};
316 WCHAR buffer
[256] = {0};
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
));
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
));
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
));
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
));
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
));
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
));
346 ret
= SQLGetPrivateProfileStringW(wineodbc
, testing
, defaultX
, NULL
, 256, odbcini
);
347 ok(ret
== 0, "SQLGetPrivateProfileStringW returned %d\n", ret
);
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
));
354 ret
= SQLWritePrivateProfileString("wineodbc", "testing" , "value0123456789", "abcd.ini");
355 ok(ret
, "SQLWritePrivateProfileString failed\n");
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
));
364 ret
= SQLGetPrivateProfileStringW(wineodbc
, testing
, defaultX
, NULL
, 0, abcdini
);
365 ok(ret
== 0, "SQLGetPrivateProfileStringW returned %d\n", ret
);
367 ret
= SQLGetPrivateProfileStringW(wineodbc
, testing
, defaultX
, buffer
, 7, abcdini
);
368 ok(ret
== 6, "SQLGetPrivateProfileStringW returned %d\n", ret
);
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
));
375 ret
= SQLWritePrivateProfileString("wineodbc", "value" , "0", "abcd.ini");
376 ok(ret
, "SQLWritePrivateProfileString failed\n");
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))
383 ok(!memcmp(buffer
, testingvalue
, sizeof(testingvalue
)),
384 "incorrect string '%s'\n", wine_dbgstr_wn(buffer
, ret
));
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)
392 ok(!lstrcmpW(buffer
, testing
), "incorrect string '%s'\n", wine_dbgstr_w(buffer
));
395 lstrcpyW(buffer
, value
);
396 ret
= SQLGetPrivateProfileStringW(wineodbc
, NULL
, empty
, buffer
, 2, abcdini
);
397 ok(ret
== 0, "SQLGetPrivateProfileStringW returned %d\n", ret
);
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
)
403 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcd_key
);
404 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
410 reg_ret
= RegDeleteKeyW(HKEY_CURRENT_USER
, abcdini_key
);
411 ok(reg_ret
== ERROR_SUCCESS
, "RegDeleteKeyW failed\n");
417 test_SQLConfigMode();
418 test_SQLInstallerError();
419 test_SQLInstallDriverManager();
420 test_SQLWritePrivateProfileString();
421 test_SQLGetPrivateProfileString();
422 test_SQLGetPrivateProfileStringW();