mstask: Implement ITask::DeleteTrigger().
[wine.git] / dlls / oledb32 / tests / database.c
blob8ff55b9d2ad93c8fa1462274ffed588cf05c059a
1 /* OLEDB Database tests
3 * Copyright 2012 Alistair Leslie-Hughes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
23 #define CONST_VTABLE
24 #define DBINITCONSTANTS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "msdadc.h"
30 #include "msdasc.h"
31 #include "msdaguid.h"
32 #include "initguid.h"
33 #include "oledb.h"
34 #include "oledberr.h"
36 #include "wine/test.h"
38 DEFINE_GUID(CSLID_MSDAER, 0xc8b522cf,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);
40 static WCHAR initstring_default[] = {'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',0};
42 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
43 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
45 ULONG rc;
46 IUnknown_AddRef(obj);
47 rc = IUnknown_Release(obj);
48 ok_(__FILE__, line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
51 static void test_GetDataSource(WCHAR *initstring)
53 IDataInitialize *datainit = NULL;
54 IDBInitialize *dbinit = NULL;
55 HRESULT hr;
57 trace("Data Source: %s\n", wine_dbgstr_w(initstring));
59 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit);
60 ok(hr == S_OK, "got %08x\n", hr);
62 EXPECT_REF(datainit, 1);
64 /* a failure to create data source here may indicate provider is simply not present */
65 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring, &IID_IDBInitialize, (IUnknown**)&dbinit);
66 if(SUCCEEDED(hr))
68 IDBProperties *props = NULL;
70 EXPECT_REF(datainit, 1);
71 EXPECT_REF(dbinit, 1);
73 hr = IDBInitialize_QueryInterface(dbinit, &IID_IDBProperties, (void**)&props);
74 ok(hr == S_OK, "got %08x\n", hr);
75 if(SUCCEEDED(hr))
77 ULONG cnt;
78 DBPROPINFOSET *pInfoset;
79 OLECHAR *ary;
81 EXPECT_REF(dbinit, 2);
82 EXPECT_REF(props, 2);
83 hr = IDBProperties_GetPropertyInfo(props, 0, NULL, &cnt, &pInfoset, &ary);
84 todo_wine ok(hr == S_OK, "got %08x\n", hr);
85 if(hr == S_OK)
87 ULONG i;
88 for(i =0; i < pInfoset->cPropertyInfos; i++)
90 trace("(0x%04x) '%s' %d\n", pInfoset->rgPropertyInfos[i].dwPropertyID, wine_dbgstr_w(pInfoset->rgPropertyInfos[i].pwszDescription),
91 pInfoset->rgPropertyInfos[i].vtType);
94 CoTaskMemFree(pInfoset);
95 CoTaskMemFree(ary);
98 IDBProperties_Release(props);
101 EXPECT_REF(dbinit, 1);
102 IDBInitialize_Release(dbinit);
105 EXPECT_REF(datainit, 1);
106 IDataInitialize_Release(datainit);
109 /* IDBProperties stub */
110 static HRESULT WINAPI dbprops_QI(IDBProperties *iface, REFIID riid, void **obj)
112 if (IsEqualIID(riid, &IID_IDBProperties) || IsEqualIID(riid, &IID_IUnknown)) {
113 *obj = iface;
114 IDBProperties_AddRef(iface);
115 return S_OK;
118 *obj = NULL;
119 return E_NOINTERFACE;
122 static ULONG WINAPI dbprops_AddRef(IDBProperties *iface)
124 return 2;
127 static ULONG WINAPI dbprops_Release(IDBProperties *iface)
129 return 1;
132 static HRESULT WINAPI dbprops_GetProperties(IDBProperties *iface, ULONG cPropertyIDSets,
133 const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertySets, DBPROPSET **prgPropertySets)
135 ok(0, "unexpected call\n");
136 return E_NOTIMPL;
139 static HRESULT WINAPI dbprops_GetPropertyInfo(IDBProperties *iface, ULONG cPropertyIDSets,
140 const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertyInfoSets, DBPROPINFOSET **prgPropertyInfoSets,
141 OLECHAR **ppDescBuffer)
143 ok(0, "unexpected call\n");
144 return E_NOTIMPL;
147 static HRESULT WINAPI dbprops_SetProperties(IDBProperties *iface, ULONG set_count, DBPROPSET propsets[])
149 ok(set_count == 1, "got %u\n", set_count);
151 ok(IsEqualIID(&propsets->guidPropertySet, &DBPROPSET_DBINIT), "set guid %s\n", wine_dbgstr_guid(&propsets->guidPropertySet));
152 ok(propsets->cProperties == 2, "got propcount %u\n", propsets->cProperties);
154 if (propsets->cProperties == 2) {
155 ok(propsets->rgProperties[0].dwPropertyID == DBPROP_INIT_DATASOURCE, "got propid[0] %u\n", propsets->rgProperties[0].dwPropertyID);
156 ok(propsets->rgProperties[0].dwOptions == DBPROPOPTIONS_REQUIRED, "got options[0] %u\n", propsets->rgProperties[0].dwOptions);
157 ok(propsets->rgProperties[0].dwStatus == 0, "got status[0] %u\n", propsets->rgProperties[0].dwStatus);
158 ok(V_VT(&propsets->rgProperties[0].vValue) == VT_BSTR, "got vartype[0] %u\n", V_VT(&propsets->rgProperties[0].vValue));
160 ok(propsets->rgProperties[1].dwPropertyID == DBPROP_INIT_PROVIDERSTRING, "got propid[1] %u\n", propsets->rgProperties[1].dwPropertyID);
161 ok(propsets->rgProperties[1].dwOptions == DBPROPOPTIONS_REQUIRED, "got options[1] %u\n", propsets->rgProperties[1].dwOptions);
162 ok(propsets->rgProperties[1].dwStatus == 0, "got status[1] %u\n", propsets->rgProperties[1].dwStatus);
163 ok(V_VT(&propsets->rgProperties[1].vValue) == VT_BSTR, "got vartype[1] %u\n", V_VT(&propsets->rgProperties[1].vValue));
165 return S_OK;
168 static const IDBPropertiesVtbl dbpropsvtbl = {
169 dbprops_QI,
170 dbprops_AddRef,
171 dbprops_Release,
172 dbprops_GetProperties,
173 dbprops_GetPropertyInfo,
174 dbprops_SetProperties
177 static IDBProperties dbprops = { &dbpropsvtbl };
179 /* IPersist stub */
180 static HRESULT WINAPI dbpersist_QI(IPersist *iface, REFIID riid, void **obj)
182 if (IsEqualIID(riid, &IID_IPersist) || IsEqualIID(riid, &IID_IUnknown)) {
183 *obj = iface;
184 IPersist_AddRef(iface);
185 return S_OK;
188 *obj = NULL;
189 return E_NOINTERFACE;
192 static ULONG WINAPI dbpersist_AddRef(IPersist *iface)
194 return 2;
197 static ULONG WINAPI dbpersist_Release(IPersist *iface)
199 return 1;
202 static HRESULT WINAPI dbpersist_GetClassID(IPersist *iface, CLSID *clsid)
204 static const WCHAR msdasqlW[] = {'M','S','D','A','S','Q','L',0};
205 return CLSIDFromProgID(msdasqlW, clsid);
208 static const IPersistVtbl dbpersistvtbl = {
209 dbpersist_QI,
210 dbpersist_AddRef,
211 dbpersist_Release,
212 dbpersist_GetClassID
215 static IPersist dbpersist = { &dbpersistvtbl };
217 /* IDBInitialize stub */
218 static HRESULT WINAPI dbinit_QI(IDBInitialize *iface, REFIID riid, void **obj)
220 if (IsEqualIID(riid, &IID_IDBInitialize) || IsEqualIID(riid, &IID_IUnknown)) {
221 *obj = iface;
222 IDBInitialize_AddRef(iface);
223 return S_OK;
225 else if (IsEqualIID(riid, &IID_IPersist)) {
226 *obj = &dbpersist;
227 return S_OK;
229 else if (IsEqualIID(riid, &IID_IDBProperties)) {
230 *obj = &dbprops;
231 return S_OK;
234 *obj = NULL;
235 return E_NOINTERFACE;
238 static ULONG WINAPI dbinit_AddRef(IDBInitialize *iface)
240 return 2;
243 static ULONG WINAPI dbinit_Release(IDBInitialize *iface)
245 return 1;
248 static HRESULT WINAPI dbinit_Initialize(IDBInitialize *iface)
250 ok(0, "unexpected call\n");
251 return E_NOTIMPL;
254 static HRESULT WINAPI dbinit_Uninitialize(IDBInitialize *iface)
256 ok(0, "unexpected call\n");
257 return E_NOTIMPL;
260 static const IDBInitializeVtbl dbinitvtbl = {
261 dbinit_QI,
262 dbinit_AddRef,
263 dbinit_Release,
264 dbinit_Initialize,
265 dbinit_Uninitialize
268 static IDBInitialize dbinittest = { &dbinitvtbl };
270 static void test_GetDataSource2(WCHAR *initstring)
272 IDataInitialize *datainit = NULL;
273 IDBInitialize *dbinit = NULL;
274 HRESULT hr;
276 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit);
277 ok(hr == S_OK, "got %08x\n", hr);
279 dbinit = &dbinittest;
280 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring, &IID_IDBInitialize, (IUnknown**)&dbinit);
281 ok(hr == S_OK, "got %08x\n", hr);
283 IDataInitialize_Release(datainit);
286 static void test_database(void)
288 static WCHAR initstring_jet[] = {'P','r','o','v','i','d','e','r','=','M','i','c','r','o','s','o','f','t','.',
289 'J','e','t','.','O','L','E','D','B','.','4','.','0',';',
290 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
291 'P','e','r','s','i','s','t',' ','S','e','c','u','r','i','t','y',' ','I','n','f','o','=','F','a','l','s','e',';',0};
292 static WCHAR initstring_lower[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',0};
293 static WCHAR customprop[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',
294 'c','u','s','t','o','m','p','r','o','p','=','1','2','3','.','4',';',0};
295 static WCHAR extended_prop[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',
296 'E','x','t','e','n','d','e','d',' ','P','r','o','p','e','r','t','i','e','s','=','\"','D','R','I','V','E','R','=','A',
297 ' ','W','i','n','e',' ','O','D','B','C',' ','d','r','i','v','e','r',';','U','I','D','=','w','i','n','e',';','\"',';',0};
298 static WCHAR extended_prop2[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','\'','d','u','m','m','y','\'',';',
299 'c','u','s','t','o','m','p','r','o','p','=','\'','1','2','3','.','4','\'',';',0};
300 IDataInitialize *datainit = NULL;
301 HRESULT hr;
303 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize, (void**)&datainit);
304 if (FAILED(hr))
306 win_skip("Unable to load oledb library\n");
307 return;
309 IDataInitialize_Release(datainit);
311 test_GetDataSource(NULL);
312 test_GetDataSource(initstring_jet);
313 test_GetDataSource(initstring_default);
314 test_GetDataSource(initstring_lower);
315 test_GetDataSource2(customprop);
316 test_GetDataSource2(extended_prop);
317 test_GetDataSource2(extended_prop2);
320 static void free_dispparams(DISPPARAMS *params)
322 unsigned int i;
324 for (i = 0; i < params->cArgs && params->rgvarg; i++)
325 VariantClear(&params->rgvarg[i]);
326 CoTaskMemFree(params->rgvarg);
327 CoTaskMemFree(params->rgdispidNamedArgs);
330 static void test_errorinfo(void)
332 ICreateErrorInfo *createerror;
333 ERRORINFO info, info2, info3;
334 IErrorInfo *errorinfo, *errorinfo2;
335 IErrorRecords *errrecs;
336 IUnknown *unk = NULL, *unk2;
337 DISPPARAMS dispparams;
338 DISPID dispid;
339 DWORD context;
340 ULONG cnt = 0;
341 VARIANT arg;
342 HRESULT hr;
343 GUID guid;
344 BSTR str;
346 hr = CoCreateInstance(&CSLID_MSDAER, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&unk);
347 ok(hr == S_OK, "got %08x\n", hr);
349 hr = IUnknown_QueryInterface(unk, &IID_IErrorInfo, (void**)&errorinfo);
350 ok(hr == S_OK, "got %08x\n", hr);
352 hr = IErrorInfo_GetGUID(errorinfo, NULL);
353 ok(hr == E_INVALIDARG, "got %08x\n", hr);
355 hr = IErrorInfo_GetSource(errorinfo, NULL);
356 ok(hr == E_INVALIDARG, "got %08x\n", hr);
358 hr = IErrorInfo_GetDescription(errorinfo, NULL);
359 ok(hr == E_INVALIDARG, "got %08x\n", hr);
361 hr = IErrorInfo_GetHelpFile(errorinfo, NULL);
362 ok(hr == E_INVALIDARG, "got %08x\n", hr);
364 hr = IErrorInfo_GetHelpContext(errorinfo, NULL);
365 ok(hr == E_INVALIDARG, "got %08x\n", hr);
367 memset(&guid, 0xac, sizeof(guid));
368 hr = IErrorInfo_GetGUID(errorinfo, &guid);
369 ok(hr == S_OK, "got %08x\n", hr);
370 ok(IsEqualGUID(&guid, &GUID_NULL), "got wrong guid\n");
372 str = (BSTR)0x1;
373 hr = IErrorInfo_GetSource(errorinfo, &str);
374 ok(hr == E_FAIL, "got %08x\n", hr);
375 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
377 str = (BSTR)0x1;
378 hr = IErrorInfo_GetDescription(errorinfo, &str);
379 ok(hr == E_FAIL, "got %08x\n", hr);
380 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
382 str = (BSTR)0x1;
383 hr = IErrorInfo_GetHelpFile(errorinfo, &str);
384 ok(hr == E_FAIL, "got %08x\n", hr);
385 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
387 context = 1;
388 hr = IErrorInfo_GetHelpContext(errorinfo, &context);
389 ok(hr == E_FAIL, "got %08x\n", hr);
390 ok(context == 0, "got %d\n", context);
392 IErrorInfo_Release(errorinfo);
394 hr = IErrorInfo_QueryInterface(errorinfo, &IID_ICreateErrorInfo, (void**)&createerror);
395 ok(hr == E_NOINTERFACE, "got %08x\n", hr);
397 hr = IUnknown_QueryInterface(unk, &IID_IErrorRecords, (void**)&errrecs);
398 ok(hr == S_OK, "got %08x\n", hr);
400 hr = IErrorRecords_GetRecordCount(errrecs, &cnt);
401 ok(hr == S_OK, "got %08x\n", hr);
402 ok(cnt == 0, "Got unexpected record count %u\n", cnt);
404 hr = IErrorRecords_GetBasicErrorInfo(errrecs, 0, &info3);
405 ok(hr == DB_E_BADRECORDNUM, "got %08x\n", hr);
407 hr = IErrorRecords_GetCustomErrorObject(errrecs, 0, &IID_IUnknown, &unk2);
408 ok(hr == DB_E_BADRECORDNUM, "got %08x\n", hr);
410 hr = IErrorRecords_GetErrorInfo(errrecs, 0, 0, &errorinfo2);
411 ok(hr == DB_E_BADRECORDNUM, "got %08x\n", hr);
413 hr = IErrorRecords_GetErrorParameters(errrecs, 0, &dispparams);
414 ok(hr == DB_E_BADRECORDNUM, "got %08x\n", hr);
416 memset(&info, 0, sizeof(ERRORINFO));
417 info.dwMinor = 1;
418 memset(&info2, 0, sizeof(ERRORINFO));
419 info2.dwMinor = 2;
420 memset(&info3, 0, sizeof(ERRORINFO));
422 hr = IErrorRecords_AddErrorRecord(errrecs, NULL, 268435456, NULL, NULL, 0);
423 ok(hr == E_INVALIDARG, "got %08x\n", hr);
425 hr = IErrorRecords_AddErrorRecord(errrecs, &info, 1, NULL, NULL, 0);
426 ok(hr == S_OK, "got %08x\n", hr);
428 hr = IErrorRecords_GetRecordCount(errrecs, &cnt);
429 ok(hr == S_OK, "got %08x\n", hr);
430 ok(cnt == 1, "expected 1 got %d\n", cnt);
432 /* Record does not contain custom error object. */
433 unk2 = (void*)0xdeadbeef;
434 hr = IErrorRecords_GetCustomErrorObject(errrecs, 0, &IID_IUnknown, &unk2);
435 ok(hr == S_OK, "got %08x\n", hr);
436 ok(unk2 == NULL, "Got custom object %p.\n", unk2);
438 hr = IErrorRecords_AddErrorRecord(errrecs, &info2, 2, NULL, NULL, 0);
439 ok(hr == S_OK, "got %08x\n", hr);
441 hr = IErrorRecords_GetRecordCount(errrecs, &cnt);
442 ok(hr == S_OK, "got %08x\n", hr);
443 ok(cnt == 2, "expected 2 got %d\n", cnt);
445 hr = IErrorRecords_GetBasicErrorInfo(errrecs, 0, NULL);
446 ok(hr == E_INVALIDARG, "got %08x\n", hr);
448 hr = IErrorRecords_GetBasicErrorInfo(errrecs, 100, &info3);
449 ok(hr == DB_E_BADRECORDNUM, "got %08x\n", hr);
451 hr = IErrorRecords_GetBasicErrorInfo(errrecs, 0, &info3);
452 ok(hr == S_OK, "got %08x\n", hr);
453 ok(info3.dwMinor == 2, "expected 2 got %d\n", info3.dwMinor);
455 hr = IErrorRecords_GetErrorParameters(errrecs, 0, NULL);
456 ok(hr == E_INVALIDARG, "got %08x\n", hr);
458 memset(&dispparams, 0xcc, sizeof(dispparams));
459 hr = IErrorRecords_GetErrorParameters(errrecs, 0, &dispparams);
460 ok(hr == S_OK, "got %08x\n", hr);
461 ok(dispparams.rgvarg == NULL, "Got arguments %p\n", dispparams.rgvarg);
462 ok(dispparams.rgdispidNamedArgs == NULL, "Got named arguments %p\n", dispparams.rgdispidNamedArgs);
463 ok(dispparams.cArgs == 0, "Got argument count %u\n", dispparams.cArgs);
464 ok(dispparams.cNamedArgs == 0, "Got named argument count %u\n", dispparams.cNamedArgs);
466 V_VT(&arg) = VT_BSTR;
467 V_BSTR(&arg) = SysAllocStringLen(NULL, 0);
468 dispid = 0x123;
470 dispparams.rgvarg = &arg;
471 dispparams.cArgs = 1;
472 dispparams.rgdispidNamedArgs = &dispid;
473 dispparams.cNamedArgs = 1;
474 hr = IErrorRecords_AddErrorRecord(errrecs, &info2, 0, &dispparams, NULL, 0);
475 ok(hr == S_OK, "got %08x\n", hr);
477 memset(&dispparams, 0, sizeof(dispparams));
478 hr = IErrorRecords_GetErrorParameters(errrecs, 0, &dispparams);
479 ok(hr == S_OK, "got %08x\n", hr);
481 ok(V_VT(&dispparams.rgvarg[0]) == VT_BSTR, "Got arg type %d\n", V_VT(&dispparams.rgvarg[0]));
482 ok(V_BSTR(&dispparams.rgvarg[0]) != V_BSTR(&arg), "Got arg bstr %d\n", V_VT(&dispparams.rgvarg[0]));
484 ok(dispparams.rgdispidNamedArgs[0] == 0x123, "Got named argument %d\n", dispparams.rgdispidNamedArgs[0]);
485 ok(dispparams.cArgs == 1, "Got argument count %u\n", dispparams.cArgs);
486 ok(dispparams.cNamedArgs == 1, "Got named argument count %u\n", dispparams.cNamedArgs);
488 free_dispparams(&dispparams);
489 VariantClear(&arg);
491 IErrorRecords_Release(errrecs);
492 IUnknown_Release(unk);
495 static void test_initializationstring(void)
497 static const WCHAR initstring_msdasql[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
498 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
499 static const WCHAR initstring_msdasql2[] = {'p','R','o','V','i','D','e','R','=','M','S','D','A','S','Q','L','.','1',';',
500 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
501 static const WCHAR initstring_sqloledb[] = {'P','r','o','v','i','d','e','r','=','S','Q','L','O','L','E','D','B','.','1',';',
502 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
503 static const WCHAR initstring_mode[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
504 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
505 'M','o','d','e','=','i','n','v','a','l','i','d',0};
506 static const WCHAR initstring_mode2[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
507 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
508 'M','o','d','e','=','W','r','i','t','e','R','e','a','d',0};
509 static const WCHAR initstring_mode3[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
510 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
511 'M','o','d','e','=','R','e','a','d','W','R','I','T','E',0};
512 IDataInitialize *datainit = NULL;
513 IDBInitialize *dbinit;
514 HRESULT hr;
515 WCHAR *initstring = NULL;
517 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit);
518 ok(hr == S_OK, "got %08x\n", hr);
519 if(SUCCEEDED(hr))
521 EXPECT_REF(datainit, 1);
523 dbinit = NULL;
524 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring_default,
525 &IID_IDBInitialize, (IUnknown**)&dbinit);
526 if(SUCCEEDED(hr))
528 EXPECT_REF(datainit, 1);
529 EXPECT_REF(dbinit, 1);
531 hr = IDataInitialize_GetInitializationString(datainit, (IUnknown*)dbinit, 0, &initstring);
532 ok(hr == S_OK, "got %08x\n", hr);
533 if(hr == S_OK)
535 trace("Init String: %s\n", wine_dbgstr_w(initstring));
536 todo_wine ok(!lstrcmpW(initstring_msdasql, initstring) ||
537 !lstrcmpW(initstring_sqloledb, initstring), "got %s\n", wine_dbgstr_w(initstring));
538 CoTaskMemFree(initstring);
541 IDBInitialize_Release(dbinit);
543 /* mixed casing string */
544 dbinit = NULL;
545 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, (WCHAR*)initstring_msdasql2,
546 &IID_IDBInitialize, (IUnknown**)&dbinit);
547 ok(hr == S_OK, "got 0x%08x\n", hr);
548 IDBInitialize_Release(dbinit);
550 /* Invalid Mode value */
551 dbinit = NULL;
552 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, (WCHAR *)initstring_mode,
553 &IID_IDBInitialize, (IUnknown **)&dbinit);
554 ok(FAILED(hr), "got 0x%08x\n", hr);
556 dbinit = NULL;
557 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, (WCHAR *)initstring_mode2,
558 &IID_IDBInitialize, (IUnknown **)&dbinit);
559 ok(FAILED(hr), "got 0x%08x\n", hr);
561 dbinit = NULL;
562 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, (WCHAR *)initstring_mode3,
563 &IID_IDBInitialize, (IUnknown **)&dbinit);
564 ok(hr == S_OK, "got 0x%08x\n", hr);
565 IDBInitialize_Release(dbinit);
567 else
568 ok(dbinit == NULL, "got %p\n", dbinit);
570 IDataInitialize_Release(datainit);
574 static void test_rowposition(void)
576 IEnumConnectionPoints *enum_points;
577 IConnectionPointContainer *cpc;
578 IConnectionPoint *cp;
579 IRowPosition *rowpos;
580 HRESULT hr;
581 IID iid;
583 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
584 ok(hr == S_OK, "got %08x\n", hr);
586 hr = IRowPosition_QueryInterface(rowpos, &IID_IConnectionPointContainer, (void**)&cpc);
587 ok(hr == S_OK, "got 0x%08x\n", hr);
589 hr = IConnectionPointContainer_EnumConnectionPoints(cpc, &enum_points);
590 todo_wine
591 ok(hr == S_OK, "got 0x%08x\n", hr);
592 if (hr == S_OK) {
593 hr = IEnumConnectionPoints_Next(enum_points, 1, &cp, NULL);
594 ok(hr == S_OK, "got 0x%08x\n", hr);
595 hr = IConnectionPoint_GetConnectionInterface(cp, &iid);
596 ok(hr == S_OK, "got 0x%08x\n", hr);
597 ok(IsEqualIID(&iid, &IID_IRowPositionChange), "got %s\n", wine_dbgstr_guid(&iid));
598 IConnectionPoint_Release(cp);
600 hr = IEnumConnectionPoints_Next(enum_points, 1, &cp, NULL);
601 ok(hr == S_FALSE, "got 0x%08x\n", hr);
603 IEnumConnectionPoints_Release(enum_points);
605 IConnectionPointContainer_Release(cpc);
606 IRowPosition_Release(rowpos);
609 typedef struct
611 IRowset IRowset_iface;
612 IChapteredRowset IChapteredRowset_iface;
613 } test_rset_t;
615 static test_rset_t test_rset;
617 static HRESULT WINAPI rset_QI(IRowset *iface, REFIID riid, void **obj)
619 if (IsEqualIID(riid, &IID_IUnknown) ||
620 IsEqualIID(riid, &IID_IRowset))
622 *obj = &test_rset.IRowset_iface;
623 return S_OK;
625 else if (IsEqualIID(riid, &IID_IChapteredRowset))
627 *obj = &test_rset.IChapteredRowset_iface;
628 return S_OK;
631 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
632 return E_NOINTERFACE;
635 static ULONG WINAPI rset_AddRef(IRowset *iface)
637 return 2;
640 static ULONG WINAPI rset_Release(IRowset *iface)
642 return 1;
645 static HRESULT WINAPI rset_AddRefRows(IRowset *iface, DBCOUNTITEM cRows,
646 const HROW rghRows[], DBREFCOUNT rgRefCounts[], DBROWSTATUS rgRowStatus[])
648 trace("AddRefRows: %ld\n", rghRows[0]);
649 return S_OK;
652 static HRESULT WINAPI rset_GetData(IRowset *iface, HROW hRow, HACCESSOR hAccessor, void *pData)
654 ok(0, "unexpected call\n");
655 return E_NOTIMPL;
658 static HRESULT WINAPI rset_GetNextRows(IRowset *iface, HCHAPTER hReserved, DBROWOFFSET lRowsOffset,
659 DBROWCOUNT cRows, DBCOUNTITEM *pcRowObtained, HROW **prghRows)
661 ok(0, "unexpected call\n");
662 return E_NOTIMPL;
665 static HRESULT WINAPI rset_ReleaseRows(IRowset *iface, DBCOUNTITEM cRows, const HROW rghRows[], DBROWOPTIONS rgRowOptions[],
666 DBREFCOUNT rgRefCounts[], DBROWSTATUS rgRowStatus[])
668 return S_OK;
671 static HRESULT WINAPI rset_RestartPosition(IRowset *iface, HCHAPTER hReserved)
673 ok(0, "unexpected call\n");
674 return E_NOTIMPL;
677 static const IRowsetVtbl rset_vtbl = {
678 rset_QI,
679 rset_AddRef,
680 rset_Release,
681 rset_AddRefRows,
682 rset_GetData,
683 rset_GetNextRows,
684 rset_ReleaseRows,
685 rset_RestartPosition
688 static HRESULT WINAPI chrset_QI(IChapteredRowset *iface, REFIID riid, void **obj)
690 return IRowset_QueryInterface(&test_rset.IRowset_iface, riid, obj);
693 static ULONG WINAPI chrset_AddRef(IChapteredRowset *iface)
695 return IRowset_AddRef(&test_rset.IRowset_iface);
698 static ULONG WINAPI chrset_Release(IChapteredRowset *iface)
700 return IRowset_Release(&test_rset.IRowset_iface);
703 static HRESULT WINAPI chrset_AddRefChapter(IChapteredRowset *iface, HCHAPTER chapter, DBREFCOUNT *refcount)
705 return S_OK;
708 static HRESULT WINAPI chrset_ReleaseChapter(IChapteredRowset *iface, HCHAPTER chapter, DBREFCOUNT *refcount)
710 return S_OK;
713 static const IChapteredRowsetVtbl chrset_vtbl = {
714 chrset_QI,
715 chrset_AddRef,
716 chrset_Release,
717 chrset_AddRefChapter,
718 chrset_ReleaseChapter
721 static void init_test_rset(void)
723 test_rset.IRowset_iface.lpVtbl = &rset_vtbl;
724 test_rset.IChapteredRowset_iface.lpVtbl = &chrset_vtbl;
727 static void test_rowpos_initialize(void)
729 IRowPosition *rowpos;
730 HRESULT hr;
732 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
733 ok(hr == S_OK, "got %08x\n", hr);
735 init_test_rset();
736 hr = IRowPosition_Initialize(rowpos, (IUnknown*)&test_rset.IRowset_iface);
737 ok(hr == S_OK, "got %08x\n", hr);
739 IRowPosition_Release(rowpos);
742 static HRESULT WINAPI onchange_QI(IRowPositionChange *iface, REFIID riid, void **obj)
744 if (IsEqualIID(riid, &IID_IUnknown) ||
745 IsEqualIID(riid, &IID_IRowPositionChange))
747 *obj = iface;
748 return S_OK;
751 return E_NOINTERFACE;
754 static ULONG WINAPI onchange_AddRef(IRowPositionChange *iface)
756 return 2;
759 static ULONG WINAPI onchange_Release(IRowPositionChange *iface)
761 return 1;
764 static HRESULT WINAPI onchange_OnRowPositionChange(IRowPositionChange *iface, DBREASON reason,
765 DBEVENTPHASE phase, BOOL cant_deny)
767 trace("%d %d %d\n", reason, phase, cant_deny);
768 return S_OK;
771 static const IRowPositionChangeVtbl onchange_vtbl = {
772 onchange_QI,
773 onchange_AddRef,
774 onchange_Release,
775 onchange_OnRowPositionChange
778 static IRowPositionChange onchangesink = { &onchange_vtbl };
780 static void init_onchange_sink(IRowPosition *rowpos)
782 IConnectionPointContainer *cpc;
783 IConnectionPoint *cp;
784 DWORD cookie;
785 HRESULT hr;
787 hr = IRowPosition_QueryInterface(rowpos, &IID_IConnectionPointContainer, (void**)&cpc);
788 ok(hr == S_OK, "got %08x\n", hr);
789 hr = IConnectionPointContainer_FindConnectionPoint(cpc, &IID_IRowPositionChange, &cp);
790 ok(hr == S_OK, "got %08x\n", hr);
791 hr = IConnectionPoint_Advise(cp, (IUnknown*)&onchangesink, &cookie);
792 ok(hr == S_OK, "got %08x\n", hr);
793 IConnectionPoint_Release(cp);
794 IConnectionPointContainer_Release(cpc);
797 static void test_rowpos_clearrowposition(void)
799 DBPOSITIONFLAGS flags;
800 IRowPosition *rowpos;
801 HCHAPTER chapter;
802 IUnknown *unk;
803 HRESULT hr;
804 HROW row;
806 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
807 ok(hr == S_OK, "got %08x\n", hr);
809 hr = IRowPosition_ClearRowPosition(rowpos);
810 ok(hr == E_UNEXPECTED, "got %08x\n", hr);
812 hr = IRowPosition_GetRowset(rowpos, &IID_IStream, &unk);
813 ok(hr == E_UNEXPECTED, "got %08x\n", hr);
815 chapter = 1;
816 row = 1;
817 flags = DBPOSITION_OK;
818 hr = IRowPosition_GetRowPosition(rowpos, &chapter, &row, &flags);
819 ok(hr == E_UNEXPECTED, "got %08x\n", hr);
820 ok(chapter == DB_NULL_HCHAPTER, "got %ld\n", chapter);
821 ok(row == DB_NULL_HROW, "got %ld\n", row);
822 ok(flags == DBPOSITION_NOROW, "got %d\n", flags);
824 init_test_rset();
825 hr = IRowPosition_Initialize(rowpos, (IUnknown*)&test_rset.IRowset_iface);
826 ok(hr == S_OK, "got %08x\n", hr);
828 chapter = 1;
829 row = 1;
830 flags = DBPOSITION_OK;
831 hr = IRowPosition_GetRowPosition(rowpos, &chapter, &row, &flags);
832 ok(hr == S_OK, "got %08x\n", hr);
833 ok(chapter == DB_NULL_HCHAPTER, "got %ld\n", chapter);
834 ok(row == DB_NULL_HROW, "got %ld\n", row);
835 ok(flags == DBPOSITION_NOROW, "got %d\n", flags);
837 hr = IRowPosition_GetRowset(rowpos, &IID_IRowset, &unk);
838 ok(hr == S_OK, "got %08x\n", hr);
840 init_onchange_sink(rowpos);
841 hr = IRowPosition_ClearRowPosition(rowpos);
842 ok(hr == S_OK, "got %08x\n", hr);
844 chapter = 1;
845 row = 1;
846 flags = DBPOSITION_OK;
847 hr = IRowPosition_GetRowPosition(rowpos, &chapter, &row, &flags);
848 ok(hr == S_OK, "got %08x\n", hr);
849 ok(chapter == DB_NULL_HCHAPTER, "got %ld\n", chapter);
850 ok(row == DB_NULL_HROW, "got %ld\n", row);
851 ok(flags == DBPOSITION_NOROW, "got %d\n", flags);
853 IRowPosition_Release(rowpos);
856 static void test_rowpos_setrowposition(void)
858 IRowPosition *rowpos;
859 HRESULT hr;
861 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
862 ok(hr == S_OK, "got %08x\n", hr);
864 init_test_rset();
865 hr = IRowPosition_Initialize(rowpos, (IUnknown*)&test_rset.IRowset_iface);
866 ok(hr == S_OK, "got %08x\n", hr);
868 hr = IRowPosition_ClearRowPosition(rowpos);
869 ok(hr == S_OK, "got %08x\n", hr);
871 init_onchange_sink(rowpos);
872 hr = IRowPosition_SetRowPosition(rowpos, 0x123, 0x456, DBPOSITION_OK);
873 ok(hr == S_OK, "got %08x\n", hr);
875 IRowPosition_Release(rowpos);
878 static void test_dslocator(void)
880 IDataSourceLocator *dslocator = NULL;
881 HRESULT hr;
883 hr = CoCreateInstance(&CLSID_DataLinks, NULL, CLSCTX_INPROC_SERVER, &IID_IDataSourceLocator,(void**)&dslocator);
884 ok(hr == S_OK, "got %08x\n", hr);
885 if(SUCCEEDED(hr))
887 IDataInitialize *datainit, *datainit2;
888 IRunnableObject *runable;
889 IProvideClassInfo *info;
890 IMarshal *marshal;
891 IRpcOptions *opts;
892 COMPATIBLE_LONG hwnd = 0;
894 if (0) /* Crashes under Window 7 */
895 hr = IDataSourceLocator_get_hWnd(dslocator, NULL);
897 hr = IDataSourceLocator_get_hWnd(dslocator, &hwnd);
898 ok(hr == S_OK, "got %08x\n", hr);
899 ok(hwnd == 0, "got %p\n", (HWND)hwnd);
901 hwnd = 0xDEADBEEF;
902 hr = IDataSourceLocator_get_hWnd(dslocator, &hwnd);
903 ok(hr == S_OK, "got %08x\n", hr);
904 ok(hwnd == 0, "got %p\n", (HWND)hwnd);
906 hwnd = 0xDEADBEEF;
907 hr = IDataSourceLocator_put_hWnd(dslocator, hwnd);
908 ok(hr == S_OK, "got %08x\n", hr);
910 hwnd = 0;
911 hr = IDataSourceLocator_get_hWnd(dslocator, &hwnd);
912 ok(hr == S_OK, "got %08x\n", hr);
913 ok(hwnd == 0xDEADBEEF, "got %p\n", (HWND)hwnd);
915 hwnd = 0;
916 hr = IDataSourceLocator_put_hWnd(dslocator, hwnd);
917 ok(hr == S_OK, "got %08x\n", hr);
919 hwnd = 0xDEADBEEF;
920 hr = IDataSourceLocator_get_hWnd(dslocator, &hwnd);
921 ok(hr == S_OK, "got %08x\n", hr);
922 ok(hwnd == 0, "got %p\n", (HWND)hwnd);
924 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IDataInitialize, (void **)&datainit);
925 ok(hr == S_OK, "got %08x\n", hr);
927 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IDataInitialize, (void **)&datainit2);
928 ok(hr == S_OK, "got %08x\n", hr);
929 ok(datainit == datainit2, "Got %p, previous %p\n", datainit, datainit2);
931 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IRunnableObject, (void **)&runable);
932 ok(hr == E_NOINTERFACE, "got %08x\n", hr);
934 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IMarshal, (void **)&marshal);
935 ok(hr == E_NOINTERFACE, "got %08x\n", hr);
937 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IProvideClassInfo, (void **)&info);
938 ok(hr == E_NOINTERFACE, "got %08x\n", hr);
940 hr = IDataSourceLocator_QueryInterface(dslocator, &IID_IRpcOptions, (void **)&opts);
941 ok(hr == E_NOINTERFACE, "got %08x\n", hr);
943 IDataInitialize_Release(datainit2);
944 IDataInitialize_Release(datainit);
946 IDataSourceLocator_Release(dslocator);
950 START_TEST(database)
952 OleInitialize(NULL);
954 test_database();
955 test_errorinfo();
956 test_initializationstring();
957 test_dslocator();
959 /* row position */
960 test_rowposition();
961 test_rowpos_initialize();
962 test_rowpos_clearrowposition();
963 test_rowpos_setrowposition();
965 OleUninitialize();