msdasql: Add IColumnsInfo interface for ICommandText.
[wine.git] / dlls / msdasql / tests / provider.c
blobd4c6930bc8e8ac2b58e3e4e797cbd77ba2a31319
1 /*
2 * Copyright 2019 Alistair Leslie-Hughes
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 <stdio.h>
20 #define COBJMACROS
22 #include "msdasc.h"
23 #include "oledb.h"
24 #include "odbcinst.h"
25 #include "wtypes.h"
27 #include "initguid.h"
29 #include "msdasql.h"
31 #include "wine/test.h"
33 DEFINE_GUID(DBPROPSET_DBINITALL, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
34 DEFINE_GUID(DBPROPSET_DBINIT, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
36 static BOOL db_created;
37 static char mdbpath[MAX_PATH];
39 static const VARTYPE intptr_vartype = (sizeof(void *) == 8 ? VT_I8 : VT_I4);
41 static void test_msdasql(void)
43 HRESULT hr;
44 IUnknown *unk;
45 IPersist *persist;
46 CLSID classid;
48 hr = CoCreateInstance( &CLSID_MSDASQL, NULL, CLSCTX_ALL, &IID_IUnknown, (void **)&unk);
49 ok(hr == S_OK, "Failed to create object 0x%08x\n", hr);
50 if (FAILED(hr))
52 return;
55 hr = IUnknown_QueryInterface(unk, &IID_IPersist, (void**)&persist);
56 ok(hr == S_OK, "got 0x%08x\n", hr);
58 hr = IPersist_GetClassID(persist, &classid);
59 ok(hr == S_OK, "got 0x%08x\n", hr);
60 ok(IsEqualGUID(&classid, &CLSID_MSDASQL), "got %s\n", debugstr_guid(&classid));
62 IPersist_Release(persist);
64 IUnknown_Release(unk);
67 static void test_Properties(void)
69 HRESULT hr;
70 IDBProperties *props;
71 DBPROPIDSET propidset;
72 ULONG infocount;
73 DBPROPINFOSET *propinfoset;
74 WCHAR *desc;
76 hr = CoCreateInstance( &CLSID_MSDASQL, NULL, CLSCTX_ALL, &IID_IDBProperties, (void **)&props);
77 ok(hr == S_OK, "Failed to create object 0x%08x\n", hr);
79 propidset.rgPropertyIDs = NULL;
80 propidset.cPropertyIDs = 0;
81 propidset.guidPropertySet = DBPROPSET_DBINITALL;
83 infocount = 0;
84 hr = IDBProperties_GetPropertyInfo(props, 1, &propidset, &infocount, &propinfoset, &desc);
85 ok(hr == S_OK, "got 0x%08x\n", hr);
86 if (hr == S_OK)
88 ULONG i;
89 VARTYPE types[14] = { VT_BSTR, VT_BOOL, VT_BSTR, VT_BSTR, intptr_vartype, VT_BSTR, VT_I4, VT_I2 , VT_I4, VT_BSTR, VT_I4, VT_BSTR, VT_I4, VT_I4 };
91 ok(IsEqualGUID(&propinfoset->guidPropertySet, &DBPROPSET_DBINIT), "got %s\n", debugstr_guid(&propinfoset->guidPropertySet));
92 ok(propinfoset->cPropertyInfos == 14, "got %d\n", propinfoset->cPropertyInfos);
94 for (i = 0; i < propinfoset->cPropertyInfos; i++)
96 trace("%d: pwszDescription: %s\n", i, debugstr_w(propinfoset->rgPropertyInfos[i].pwszDescription) );
97 ok(propinfoset->rgPropertyInfos[i].vtType == types[i], "got %d\n", propinfoset->rgPropertyInfos[i].vtType);
98 ok(propinfoset->rgPropertyInfos[i].dwFlags == (DBPROPFLAGS_DBINIT | DBPROPFLAGS_READ | DBPROPFLAGS_WRITE),
99 "got %d\n", propinfoset->rgPropertyInfos[i].dwFlags);
102 for (i = 0; i < propinfoset->cPropertyInfos; i++)
103 VariantClear(&propinfoset->rgPropertyInfos[i].vValues);
105 CoTaskMemFree(propinfoset->rgPropertyInfos);
106 CoTaskMemFree(propinfoset);
109 IDBProperties_Release(props);
112 static void test_command_interfaces(IUnknown *cmd)
114 HRESULT hr;
115 ICommandProperties *commandProp;
116 ICommandText *comand_text;
117 IConvertType *convertype;
118 ICommandPrepare *commandprepare;
119 ICommandStream *commandstream;
120 IColumnsInfo *colinfo;
121 IMultipleResults *multiple;
122 IUnknown *unk;
124 hr = IUnknown_QueryInterface(cmd, &IID_ICommandProperties, (void**)&commandProp);
125 ok(hr == S_OK, "got 0x%08x\n", hr);
126 ICommandProperties_Release(commandProp);
128 hr = IUnknown_QueryInterface(cmd, &IID_ICommandText, (void**)&comand_text);
129 ok(hr == S_OK, "got 0x%08x\n", hr);
130 ICommandText_Release(comand_text);
132 hr = IUnknown_QueryInterface(cmd, &IID_IConvertType, (void**)&convertype);
133 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
134 if (hr == S_OK)
135 IConvertType_Release(convertype);
137 hr = IUnknown_QueryInterface(cmd, &IID_ICommandPrepare, (void**)&commandprepare);
138 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
139 if (hr == S_OK)
140 ICommandPrepare_Release(commandprepare);
142 hr = IUnknown_QueryInterface(cmd, &IID_IColumnsInfo, (void**)&colinfo);
143 ok(hr == S_OK, "got 0x%08x\n", hr);
144 IColumnsInfo_Release(colinfo);
146 hr = IUnknown_QueryInterface(cmd, &IID_ICommandStream, (void**)&commandstream);
147 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
149 hr = IUnknown_QueryInterface(cmd, &IID_IMultipleResults, (void**)&multiple);
150 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
152 hr = IUnknown_QueryInterface(cmd, &IID_IRowsetChange, (void**)&unk);
153 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
155 hr = IUnknown_QueryInterface(cmd, &IID_IRowsetUpdate, (void**)&unk);
156 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
158 hr = IUnknown_QueryInterface(cmd, &IID_IRowsetLocate, (void**)&unk);
159 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
162 static void test_sessions(void)
164 IDBProperties *props;
165 IDBInitialize *dbinit = NULL;
166 IDataInitialize *datainit;
167 IDBCreateSession *dbsession = NULL;
168 IUnknown *session = NULL;
169 IOpenRowset *openrowset = NULL;
170 IDBCreateCommand *create_command = NULL;
171 IGetDataSource *datasource = NULL;
172 ISessionProperties *session_props = NULL;
173 IUnknown *cmd = NULL;
174 HRESULT hr;
175 BSTR connect_str;
177 if (!db_created)
179 skip("ODBC source wine_test not available.\n");
180 return;
183 connect_str = SysAllocString(L"Provider=MSDASQL.1;Persist Security Info=False;Data Source=wine_test");
185 hr = CoCreateInstance( &CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,
186 (void **)&datainit );
187 ok(hr == S_OK, "Failed to create object 0x%08x\n", hr);
188 hr = IDataInitialize_GetDataSource( datainit, NULL, CLSCTX_INPROC_SERVER, connect_str, &IID_IDBInitialize,
189 (IUnknown **)&dbinit );
190 SysFreeString(connect_str);
191 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
192 if(FAILED(hr))
194 IDataInitialize_Release( datainit );
195 return;
198 hr = IDBInitialize_QueryInterface( dbinit, &IID_IDBProperties, (void **)&props );
199 ok(hr == S_OK, "got 0x%08x\n", hr);
200 IDBProperties_Release(props);
202 hr = IDBInitialize_Initialize( dbinit );
203 ok(hr == S_OK, "got 0x%08x\n", hr);
204 if(FAILED(hr))
206 IDBInitialize_Release( dbinit );
207 IDataInitialize_Release( datainit );
208 return;
211 hr = IDBInitialize_QueryInterface( dbinit, &IID_IDBCreateSession, (void **)&dbsession );
212 ok(hr == S_OK, "got 0x%08x\n", hr);
214 hr = IDBCreateSession_CreateSession( dbsession, NULL, &IID_IUnknown, &session );
215 ok(hr == S_OK, "got 0x%08x\n", hr);
217 hr = IUnknown_QueryInterface(session, &IID_IGetDataSource, (void**)&datasource);
218 ok(hr == S_OK, "got 0x%08x\n", hr);
219 IGetDataSource_Release(datasource);
221 hr = IUnknown_QueryInterface(session, &IID_ISessionProperties, (void**)&session_props);
222 ok(hr == S_OK, "got 0x%08x\n", hr);
223 ISessionProperties_Release(session_props);
225 hr = IUnknown_QueryInterface(session, &IID_IOpenRowset, (void**)&openrowset);
226 ok(hr == S_OK, "got 0x%08x\n", hr);
228 hr = IOpenRowset_QueryInterface(openrowset, &IID_IDBCreateCommand, (void**)&create_command);
229 ok(hr == S_OK, "got 0x%08x\n", hr);
231 hr = IDBCreateCommand_CreateCommand(create_command, NULL, &IID_IUnknown, (IUnknown **)&cmd);
232 ok(hr == S_OK, "got 0x%08x\n", hr);
233 if (hr == S_OK)
235 test_command_interfaces(cmd);
236 IUnknown_Release(cmd);
239 IDBCreateCommand_Release(create_command);
240 IOpenRowset_Release(openrowset);
241 IUnknown_Release( session );
242 IDBCreateSession_Release(dbsession);
243 IDBInitialize_Uninitialize( dbinit );
244 IDBInitialize_Release( dbinit );
245 IDataInitialize_Release( datainit );
248 static void setup_database(void)
250 char *driver;
251 DWORD code;
252 char buffer[1024];
253 WORD size;
255 if (winetest_interactive)
257 trace("assuming odbc 'wine_test' is available\n");
258 db_created = TRUE;
259 return;
263 * 32 bit Windows has a default driver for "Microsoft Access Driver" (Windows 7+)
264 * and has the ability to create files on the fly.
266 * 64 bit Windows ONLY has a driver for "SQL Server", which we cannot use since we don't have a
267 * server to connect to.
269 * The filename passed to CREATE_DB must end in mdb.
271 GetTempPathA(sizeof(mdbpath), mdbpath);
272 strcat(mdbpath, "wine_test.mdb");
274 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof("DSN=wine_test\0CREATE_DB=") + strlen(mdbpath) + 2);
275 memcpy(driver, "DSN=wine_test\0CREATE_DB=", sizeof("DSN=wine_test\0CREATE_DB="));
276 strcat(driver+sizeof("DSN=wine_test\0CREATE_DB=")-1, mdbpath);
278 db_created = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", driver);
279 if (!db_created)
281 SQLInstallerError(1, &code, buffer, sizeof(buffer), &size);
282 trace("code %d, buffer %s, size %d\n", code, debugstr_a(buffer), size);
284 HeapFree(GetProcessHeap(), 0, driver);
286 return;
289 memcpy(driver, "DSN=wine_test\0DBQ=", sizeof("DSN=wine_test\0DBQ="));
290 strcat(driver+sizeof("DSN=wine_test\0DBQ=")-1, mdbpath);
291 db_created = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", driver);
293 HeapFree(GetProcessHeap(), 0, driver);
296 static void cleanup_database(void)
298 BOOL ret;
300 if (winetest_interactive)
301 return;
303 ret = SQLConfigDataSource(NULL, ODBC_REMOVE_DSN, "Microsoft Access Driver (*.mdb)", "DSN=wine_test\0\0");
304 if (!ret)
306 DWORD code;
307 char buffer[1024];
308 WORD size;
310 SQLInstallerError(1, &code, buffer, sizeof(buffer), &size);
311 trace("code %d, buffer %s, size %d\n", code, debugstr_a(buffer), size);
314 DeleteFileA(mdbpath);
317 START_TEST(provider)
319 CoInitialize(0);
321 setup_database();
323 test_msdasql();
324 test_Properties();
325 test_sessions();
327 cleanup_database();
329 CoUninitialize();