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
24 #define DBINITCONSTANTS
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
)
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
;
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
);
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
);
78 DBPROPINFOSET
*pInfoset
;
81 EXPECT_REF(dbinit
, 2);
83 hr
= IDBProperties_GetPropertyInfo(props
, 0, NULL
, &cnt
, &pInfoset
, &ary
);
84 todo_wine
ok(hr
== S_OK
, "got %08x\n", hr
);
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
);
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
)) {
114 IDBProperties_AddRef(iface
);
119 return E_NOINTERFACE
;
122 static ULONG WINAPI
dbprops_AddRef(IDBProperties
*iface
)
127 static ULONG WINAPI
dbprops_Release(IDBProperties
*iface
)
132 static HRESULT WINAPI
dbprops_GetProperties(IDBProperties
*iface
, ULONG cPropertyIDSets
,
133 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertySets
, DBPROPSET
**prgPropertySets
)
135 ok(0, "unexpected call\n");
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");
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
));
168 static const IDBPropertiesVtbl dbpropsvtbl
= {
172 dbprops_GetProperties
,
173 dbprops_GetPropertyInfo
,
174 dbprops_SetProperties
177 static IDBProperties dbprops
= { &dbpropsvtbl
};
180 static HRESULT WINAPI
dbpersist_QI(IPersist
*iface
, REFIID riid
, void **obj
)
182 if (IsEqualIID(riid
, &IID_IPersist
) || IsEqualIID(riid
, &IID_IUnknown
)) {
184 IPersist_AddRef(iface
);
189 return E_NOINTERFACE
;
192 static ULONG WINAPI
dbpersist_AddRef(IPersist
*iface
)
197 static ULONG WINAPI
dbpersist_Release(IPersist
*iface
)
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
= {
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
)) {
222 IDBInitialize_AddRef(iface
);
225 else if (IsEqualIID(riid
, &IID_IPersist
)) {
229 else if (IsEqualIID(riid
, &IID_IDBProperties
)) {
235 return E_NOINTERFACE
;
238 static ULONG WINAPI
dbinit_AddRef(IDBInitialize
*iface
)
243 static ULONG WINAPI
dbinit_Release(IDBInitialize
*iface
)
248 static HRESULT WINAPI
dbinit_Initialize(IDBInitialize
*iface
)
250 ok(0, "unexpected call\n");
254 static HRESULT WINAPI
dbinit_Uninitialize(IDBInitialize
*iface
)
256 ok(0, "unexpected call\n");
260 static const IDBInitializeVtbl dbinitvtbl
= {
268 static IDBInitialize dbinittest
= { &dbinitvtbl
};
270 static void test_GetDataSource2(WCHAR
*initstring
)
272 IDataInitialize
*datainit
= NULL
;
273 IDBInitialize
*dbinit
= NULL
;
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
;
303 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
, (void**)&datainit
);
306 win_skip("Unable to load oledb library\n");
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
)
324 for (i
= 0; i
< params
->cArgs
&& params
->rgvarg
; i
++)
325 VariantClear(¶ms
->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
;
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");
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
));
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
));
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
));
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
));
418 memset(&info2
, 0, sizeof(ERRORINFO
));
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);
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
);
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
;
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
);
521 EXPECT_REF(datainit
, 1);
524 hr
= IDataInitialize_GetDataSource(datainit
, NULL
, CLSCTX_INPROC_SERVER
, initstring_default
,
525 &IID_IDBInitialize
, (IUnknown
**)&dbinit
);
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
);
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 */
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 */
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
);
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
);
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
);
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
;
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
);
591 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
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
);
611 IRowset IRowset_iface
;
612 IChapteredRowset IChapteredRowset_iface
;
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
;
625 else if (IsEqualIID(riid
, &IID_IChapteredRowset
))
627 *obj
= &test_rset
.IChapteredRowset_iface
;
631 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
632 return E_NOINTERFACE
;
635 static ULONG WINAPI
rset_AddRef(IRowset
*iface
)
640 static ULONG WINAPI
rset_Release(IRowset
*iface
)
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]);
652 static HRESULT WINAPI
rset_GetData(IRowset
*iface
, HROW hRow
, HACCESSOR hAccessor
, void *pData
)
654 ok(0, "unexpected call\n");
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");
665 static HRESULT WINAPI
rset_ReleaseRows(IRowset
*iface
, DBCOUNTITEM cRows
, const HROW rghRows
[], DBROWOPTIONS rgRowOptions
[],
666 DBREFCOUNT rgRefCounts
[], DBROWSTATUS rgRowStatus
[])
671 static HRESULT WINAPI
rset_RestartPosition(IRowset
*iface
, HCHAPTER hReserved
)
673 ok(0, "unexpected call\n");
677 static const IRowsetVtbl rset_vtbl
= {
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
)
708 static HRESULT WINAPI
chrset_ReleaseChapter(IChapteredRowset
*iface
, HCHAPTER chapter
, DBREFCOUNT
*refcount
)
713 static const IChapteredRowsetVtbl chrset_vtbl
= {
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
;
732 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
733 ok(hr
== S_OK
, "got %08x\n", hr
);
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
))
751 return E_NOINTERFACE
;
754 static ULONG WINAPI
onchange_AddRef(IRowPositionChange
*iface
)
759 static ULONG WINAPI
onchange_Release(IRowPositionChange
*iface
)
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
);
771 static const IRowPositionChangeVtbl onchange_vtbl
= {
775 onchange_OnRowPositionChange
778 static IRowPositionChange onchangesink
= { &onchange_vtbl
};
780 static void init_onchange_sink(IRowPosition
*rowpos
)
782 IConnectionPointContainer
*cpc
;
783 IConnectionPoint
*cp
;
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
;
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
);
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
);
825 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
826 ok(hr
== S_OK
, "got %08x\n", hr
);
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
);
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
;
861 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
862 ok(hr
== S_OK
, "got %08x\n", hr
);
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
;
883 hr
= CoCreateInstance(&CLSID_DataLinks
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataSourceLocator
,(void**)&dslocator
);
884 ok(hr
== S_OK
, "got %08x\n", hr
);
887 IDataInitialize
*datainit
, *datainit2
;
888 IRunnableObject
*runable
;
889 IProvideClassInfo
*info
;
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
);
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
);
907 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
908 ok(hr
== S_OK
, "got %08x\n", hr
);
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
);
916 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
917 ok(hr
== S_OK
, "got %08x\n", hr
);
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
);
956 test_initializationstring();
961 test_rowpos_initialize();
962 test_rowpos_clearrowposition();
963 test_rowpos_setrowposition();