f1f3f00316df1106ae3e8ede5be01ad4f5115ab4
[reactos.git] / rostests / winetests / odbccp32 / misc.c
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 void test_SQLConfigMode(void)
28 {
29 BOOL bool_ret;
30 DWORD error_code;
31 RETCODE sql_ret;
32 UWORD config_mode;
33 int i;
34
35 ok(SQLGetConfigMode(NULL), "SQLGetConfigMode(NULL) should succeed\n");
36
37 bool_ret = SQLGetConfigMode(&config_mode);
38 ok(bool_ret && config_mode == ODBC_BOTH_DSN, "Failed to get the initial SQLGetConfigMode or it was not both\n");
39
40 /* try to set invalid mode */
41 bool_ret = SQLSetConfigMode(ODBC_SYSTEM_DSN+1);
42 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
43 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");
44
45 for (i = ODBC_SYSTEM_DSN; i >= ODBC_BOTH_DSN; --i)
46 {
47 ok(SQLSetConfigMode((UWORD)i), "SQLSetConfigMode Failed to set config mode\n");
48 bool_ret = SQLGetConfigMode(&config_mode);
49 ok(bool_ret && config_mode == i, "Failed to confirm SQLSetConfigMode.\n");
50 }
51 /* And that leaves it correctly on BOTH */
52 }
53
54 static void test_SQLInstallerError(void)
55 {
56 RETCODE sql_ret;
57
58 /* MSDN states that the error number should be between 1 and 8. Passing 0 is an error */
59 sql_ret = SQLInstallerError(0, NULL, NULL, 0, NULL);
60 ok(sql_ret == SQL_ERROR, "SQLInstallerError(0...) failed with %d instead of SQL_ERROR\n", sql_ret);
61 /* However numbers greater than 8 do not return SQL_ERROR.
62 * I am currently unsure as to whether it should return SQL_NO_DATA or "the same as for error 8";
63 * I have never been able to generate 8 errors to test it
64 */
65 sql_ret = SQLInstallerError(65535, NULL, NULL, 0, NULL);
66 ok(sql_ret == SQL_NO_DATA, "SQLInstallerError(>8...) failed with %d instead of SQL_NO_DATA\n", sql_ret);
67
68 /* Force an error to work with. This should generate ODBC_ERROR_INVALID_BUFF_LEN */
69 ok(!SQLGetInstalledDrivers(0, 0, 0), "Failed to force an error for testing\n");
70 sql_ret = SQLInstallerError(2, NULL, NULL, 0, NULL);
71 ok(sql_ret == SQL_NO_DATA, "Too many errors when forcing an error for testing\n");
72
73 /* Null pointers are acceptable in all obvious places */
74 sql_ret = SQLInstallerError(1, NULL, NULL, 0, NULL);
75 ok(sql_ret == SQL_SUCCESS_WITH_INFO, "SQLInstallerError(null addresses) failed with %d instead of SQL_SUCCESS_WITH_INFO\n", sql_ret);
76 }
77
78 static void test_SQLInstallDriverManager(void)
79 {
80 BOOL bool_ret;
81 RETCODE sql_ret;
82 DWORD error_code;
83 CHAR target_path[MAX_PATH];
84 WORD path_out;
85
86 /* NULL check */
87 bool_ret = SQLInstallDriverManager(NULL, 0, NULL);
88 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
89 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
90 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
91 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
92
93 /* Length smaller than MAX_PATH */
94 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, NULL);
95 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
96 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
97 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
98 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
99
100 path_out = 0xcafe;
101 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, &path_out);
102 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
103 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
104 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
105 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
106 ok(path_out == 0xcafe, "Expected path_out to not have changed\n");
107
108 /* Length OK */
109 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, NULL);
110 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
111 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n",
112 error_code);
113 if (bool_ret)
114 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
115 else
116 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
117 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
118
119 path_out = 0xcafe;
120 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, &path_out);
121 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
122 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n",
123 error_code);
124 if (bool_ret)
125 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
126 else
127 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
128 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
129 /* path_out should in practice be less than 0xcafe */
130 ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n");
131 }
132
133 static void test_SQLWritePrivateProfileString(void)
134 {
135 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};
136 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};
137 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 };
138 BOOL ret;
139 LONG reg_ret;
140 DWORD error_code;
141
142 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "");
143 ok(!ret, "SQLWritePrivateProfileString passed\n");
144 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
145 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code);
146
147 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", NULL);
148 ok(!ret, "SQLWritePrivateProfileString passed\n");
149 SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
150 ok(error_code == ODBC_ERROR_INVALID_STR, "SQLInstallerErrorW ret: %d\n", error_code);
151
152 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "odbc.ini");
153 ok(ret, "SQLWritePrivateProfileString failed\n");
154 if(ret)
155 {
156 HKEY hkey;
157
158 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, odbc_key, 0, KEY_READ, &hkey);
159 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
160 if(reg_ret == ERROR_SUCCESS)
161 {
162 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, odbc_key);
163 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
164
165 RegCloseKey(hkey);
166 }
167 }
168
169 ret = SQLWritePrivateProfileString("wineodbc", "testing" , "value", "abcd.ini");
170 ok(ret, "SQLWritePrivateProfileString failed\n");
171 if(ret)
172 {
173 HKEY hkey;
174
175 reg_ret = RegOpenKeyExW(HKEY_CURRENT_USER, abcd_key, 0, KEY_READ, &hkey);
176 ok(reg_ret == ERROR_SUCCESS, "RegOpenKeyExW failed\n");
177 if(reg_ret == ERROR_SUCCESS)
178 {
179 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcd_key);
180 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
181
182 RegCloseKey(hkey);
183 }
184
185 /* Cleanup key */
186 reg_ret = RegDeleteKeyW(HKEY_CURRENT_USER, abcdini_key);
187 ok(reg_ret == ERROR_SUCCESS, "RegDeleteKeyW failed\n");
188 }
189 }
190
191 START_TEST(misc)
192 {
193 test_SQLConfigMode();
194 test_SQLInstallerError();
195 test_SQLInstallDriverManager();
196 test_SQLWritePrivateProfileString();
197 }