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 NONAMELESSUNION
25 #define NONAMELESSSTRUCT
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 static void test_GetDataSource(WCHAR
*initstring
)
44 IDataInitialize
*datainit
= NULL
;
45 IDBInitialize
*dbinit
= NULL
;
48 trace("Data Source: %s\n", wine_dbgstr_w(initstring
));
50 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
,(void**)&datainit
);
51 ok(hr
== S_OK
, "got %08x\n", hr
);
53 /* a failure to create data source here may indicate provider is simply not present */
54 hr
= IDataInitialize_GetDataSource(datainit
, NULL
, CLSCTX_INPROC_SERVER
, initstring
, &IID_IDBInitialize
, (IUnknown
**)&dbinit
);
57 IDBProperties
*props
= NULL
;
59 hr
= IDBInitialize_QueryInterface(dbinit
, &IID_IDBProperties
, (void**)&props
);
60 ok(hr
== S_OK
, "got %08x\n", hr
);
64 DBPROPINFOSET
*pInfoset
;
67 hr
= IDBProperties_GetPropertyInfo(props
, 0, NULL
, &cnt
, &pInfoset
, &ary
);
68 todo_wine
ok(hr
== S_OK
, "got %08x\n", hr
);
72 for(i
=0; i
< pInfoset
->cPropertyInfos
; i
++)
74 trace("(0x%04x) '%s' %d\n", pInfoset
->rgPropertyInfos
[i
].dwPropertyID
, wine_dbgstr_w(pInfoset
->rgPropertyInfos
[i
].pwszDescription
),
75 pInfoset
->rgPropertyInfos
[i
].vtType
);
81 IDBProperties_Release(props
);
84 IDBInitialize_Release(dbinit
);
87 IDataInitialize_Release(datainit
);
90 static void test_database(void)
92 static WCHAR initstring_jet
[] = {'P','r','o','v','i','d','e','r','=','M','i','c','r','o','s','o','f','t','.',
93 'J','e','t','.','O','L','E','D','B','.','4','.','0',';',
94 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
95 '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};
96 static WCHAR initstring_lower
[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',0};
97 IDataInitialize
*datainit
= NULL
;
100 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
, (void**)&datainit
);
103 win_skip("Unable to load oledb library\n");
106 IDataInitialize_Release(datainit
);
108 test_GetDataSource(NULL
);
109 test_GetDataSource(initstring_jet
);
110 test_GetDataSource(initstring_default
);
111 test_GetDataSource(initstring_lower
);
114 static void test_errorinfo(void)
117 IUnknown
*unk
= NULL
;
119 hr
= CoCreateInstance(&CSLID_MSDAER
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,(void**)&unk
);
120 ok(hr
== S_OK
, "got %08x\n", hr
);
123 IErrorInfo
*errorinfo
;
124 IErrorRecords
*errrecs
;
126 hr
= IUnknown_QueryInterface(unk
, &IID_IErrorInfo
, (void**)&errorinfo
);
127 ok(hr
== S_OK
, "got %08x\n", hr
);
130 IErrorInfo_Release(errorinfo
);
133 hr
= IUnknown_QueryInterface(unk
, &IID_IErrorRecords
, (void**)&errrecs
);
134 ok(hr
== S_OK
, "got %08x\n", hr
);
137 ERRORINFO info
, info2
, info3
;
140 memset(&info
, 0, sizeof(ERRORINFO
));
142 memset(&info2
, 0, sizeof(ERRORINFO
));
144 memset(&info3
, 0, sizeof(ERRORINFO
));
146 hr
= IErrorRecords_AddErrorRecord(errrecs
, NULL
, 268435456, NULL
, NULL
, 0);
147 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
149 hr
= IErrorRecords_AddErrorRecord(errrecs
, &info
, 1, NULL
, NULL
, 0);
150 ok(hr
== S_OK
, "got %08x\n", hr
);
152 hr
= IErrorRecords_GetRecordCount(errrecs
, &cnt
);
153 ok(hr
== S_OK
, "got %08x\n", hr
);
154 ok(cnt
== 1, "expected 1 got %d\n", cnt
);
156 hr
= IErrorRecords_AddErrorRecord(errrecs
, &info2
, 2, NULL
, NULL
, 0);
157 ok(hr
== S_OK
, "got %08x\n", hr
);
159 hr
= IErrorRecords_GetRecordCount(errrecs
, &cnt
);
160 ok(hr
== S_OK
, "got %08x\n", hr
);
161 ok(cnt
== 2, "expected 2 got %d\n", cnt
);
163 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 0, NULL
);
164 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
166 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 100, &info3
);
167 ok(hr
== DB_E_BADRECORDNUM
, "got %08x\n", hr
);
169 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 0, &info3
);
170 todo_wine
ok(hr
== S_OK
, "got %08x\n", hr
);
173 ok(info3
.dwMinor
== 2, "expected 2 got %d\n", info3
.dwMinor
);
176 IErrorRecords_Release(errrecs
);
179 IUnknown_Release(unk
);
183 static void test_initializationstring(void)
185 static const WCHAR initstring_msdasql
[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
186 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
187 static const WCHAR initstring_sqloledb
[] = {'P','r','o','v','i','d','e','r','=','S','Q','L','O','L','E','D','B','.','1',';',
188 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
189 IDataInitialize
*datainit
= NULL
;
190 IDBInitialize
*dbinit
= NULL
;
192 WCHAR
*initstring
= NULL
;
194 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
,(void**)&datainit
);
195 ok(hr
== S_OK
, "got %08x\n", hr
);
198 hr
= IDataInitialize_GetDataSource(datainit
, NULL
, CLSCTX_INPROC_SERVER
, initstring_default
,
199 &IID_IDBInitialize
, (IUnknown
**)&dbinit
);
202 hr
= IDataInitialize_GetInitializationString(datainit
, (IUnknown
*)dbinit
, 0, &initstring
);
203 ok(hr
== S_OK
, "got %08x\n", hr
);
206 trace("Init String: %s\n", wine_dbgstr_w(initstring
));
207 todo_wine
ok(!lstrcmpW(initstring_msdasql
, initstring
) ||
208 !lstrcmpW(initstring_sqloledb
, initstring
), "got %s\n", wine_dbgstr_w(initstring
));
209 CoTaskMemFree(initstring
);
212 IDBInitialize_Release(dbinit
);
215 IDataInitialize_Release(datainit
);
219 static void test_rowposition(void)
221 IEnumConnectionPoints
*enum_points
;
222 IConnectionPointContainer
*cpc
;
223 IConnectionPoint
*cp
;
224 IRowPosition
*rowpos
;
228 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
229 ok(hr
== S_OK
, "got %08x\n", hr
);
231 hr
= IRowPosition_QueryInterface(rowpos
, &IID_IConnectionPointContainer
, (void**)&cpc
);
232 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
234 hr
= IConnectionPointContainer_EnumConnectionPoints(cpc
, &enum_points
);
236 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
238 hr
= IEnumConnectionPoints_Next(enum_points
, 1, &cp
, NULL
);
239 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
240 hr
= IConnectionPoint_GetConnectionInterface(cp
, &iid
);
241 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
242 ok(IsEqualIID(&iid
, &IID_IRowPositionChange
), "got %s\n", wine_dbgstr_guid(&iid
));
243 IConnectionPoint_Release(cp
);
245 hr
= IEnumConnectionPoints_Next(enum_points
, 1, &cp
, NULL
);
246 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
248 IEnumConnectionPoints_Release(enum_points
);
250 IConnectionPointContainer_Release(cpc
);
251 IRowPosition_Release(rowpos
);
256 IRowset IRowset_iface
;
257 IChapteredRowset IChapteredRowset_iface
;
260 static test_rset_t test_rset
;
262 static HRESULT WINAPI
rset_QI(IRowset
*iface
, REFIID riid
, void **obj
)
264 if (IsEqualIID(riid
, &IID_IUnknown
) ||
265 IsEqualIID(riid
, &IID_IRowset
))
267 *obj
= &test_rset
.IRowset_iface
;
270 else if (IsEqualIID(riid
, &IID_IChapteredRowset
))
272 *obj
= &test_rset
.IChapteredRowset_iface
;
276 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
277 return E_NOINTERFACE
;
280 static ULONG WINAPI
rset_AddRef(IRowset
*iface
)
285 static ULONG WINAPI
rset_Release(IRowset
*iface
)
290 static HRESULT WINAPI
rset_AddRefRows(IRowset
*iface
, DBCOUNTITEM cRows
,
291 const HROW rghRows
[], DBREFCOUNT rgRefCounts
[], DBROWSTATUS rgRowStatus
[])
293 trace("AddRefRows: %ld\n", rghRows
[0]);
297 static HRESULT WINAPI
rset_GetData(IRowset
*iface
, HROW hRow
, HACCESSOR hAccessor
, void *pData
)
299 ok(0, "unexpected call\n");
303 static HRESULT WINAPI
rset_GetNextRows(IRowset
*iface
, HCHAPTER hReserved
, DBROWOFFSET lRowsOffset
,
304 DBROWCOUNT cRows
, DBCOUNTITEM
*pcRowObtained
, HROW
**prghRows
)
306 ok(0, "unexpected call\n");
310 static HRESULT WINAPI
rset_ReleaseRows(IRowset
*iface
, DBCOUNTITEM cRows
, const HROW rghRows
[], DBROWOPTIONS rgRowOptions
[],
311 DBREFCOUNT rgRefCounts
[], DBROWSTATUS rgRowStatus
[])
316 static HRESULT WINAPI
rset_RestartPosition(IRowset
*iface
, HCHAPTER hReserved
)
318 ok(0, "unexpected call\n");
322 static const IRowsetVtbl rset_vtbl
= {
333 static HRESULT WINAPI
chrset_QI(IChapteredRowset
*iface
, REFIID riid
, void **obj
)
335 return IRowset_QueryInterface(&test_rset
.IRowset_iface
, riid
, obj
);
338 static ULONG WINAPI
chrset_AddRef(IChapteredRowset
*iface
)
340 return IRowset_AddRef(&test_rset
.IRowset_iface
);
343 static ULONG WINAPI
chrset_Release(IChapteredRowset
*iface
)
345 return IRowset_Release(&test_rset
.IRowset_iface
);
348 static HRESULT WINAPI
chrset_AddRefChapter(IChapteredRowset
*iface
, HCHAPTER chapter
, DBREFCOUNT
*refcount
)
353 static HRESULT WINAPI
chrset_ReleaseChapter(IChapteredRowset
*iface
, HCHAPTER chapter
, DBREFCOUNT
*refcount
)
358 static const IChapteredRowsetVtbl chrset_vtbl
= {
362 chrset_AddRefChapter
,
363 chrset_ReleaseChapter
366 static void init_test_rset(void)
368 test_rset
.IRowset_iface
.lpVtbl
= &rset_vtbl
;
369 test_rset
.IChapteredRowset_iface
.lpVtbl
= &chrset_vtbl
;
372 static void test_rowpos_initialize(void)
374 IRowPosition
*rowpos
;
377 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
378 ok(hr
== S_OK
, "got %08x\n", hr
);
381 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
382 ok(hr
== S_OK
, "got %08x\n", hr
);
384 IRowPosition_Release(rowpos
);
387 static HRESULT WINAPI
onchange_QI(IRowPositionChange
*iface
, REFIID riid
, void **obj
)
389 if (IsEqualIID(riid
, &IID_IUnknown
) ||
390 IsEqualIID(riid
, &IID_IRowPositionChange
))
396 return E_NOINTERFACE
;
399 static ULONG WINAPI
onchange_AddRef(IRowPositionChange
*iface
)
404 static ULONG WINAPI
onchange_Release(IRowPositionChange
*iface
)
409 static HRESULT WINAPI
onchange_OnRowPositionChange(IRowPositionChange
*iface
, DBREASON reason
,
410 DBEVENTPHASE phase
, BOOL cant_deny
)
412 trace("%d %d %d\n", reason
, phase
, cant_deny
);
416 static const IRowPositionChangeVtbl onchange_vtbl
= {
420 onchange_OnRowPositionChange
423 static IRowPositionChange onchangesink
= { &onchange_vtbl
};
425 static void init_onchange_sink(IRowPosition
*rowpos
)
427 IConnectionPointContainer
*cpc
;
428 IConnectionPoint
*cp
;
432 hr
= IRowPosition_QueryInterface(rowpos
, &IID_IConnectionPointContainer
, (void**)&cpc
);
433 ok(hr
== S_OK
, "got %08x\n", hr
);
434 hr
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IRowPositionChange
, &cp
);
435 ok(hr
== S_OK
, "got %08x\n", hr
);
436 hr
= IConnectionPoint_Advise(cp
, (IUnknown
*)&onchangesink
, &cookie
);
437 ok(hr
== S_OK
, "got %08x\n", hr
);
438 IConnectionPoint_Release(cp
);
439 IConnectionPointContainer_Release(cpc
);
442 static void test_rowpos_clearrowposition(void)
444 DBPOSITIONFLAGS flags
;
445 IRowPosition
*rowpos
;
451 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
452 ok(hr
== S_OK
, "got %08x\n", hr
);
454 hr
= IRowPosition_ClearRowPosition(rowpos
);
455 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
457 hr
= IRowPosition_GetRowset(rowpos
, &IID_IStream
, &unk
);
458 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
462 flags
= DBPOSITION_OK
;
463 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
464 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
465 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
466 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
467 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
470 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
471 ok(hr
== S_OK
, "got %08x\n", hr
);
475 flags
= DBPOSITION_OK
;
476 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
477 ok(hr
== S_OK
, "got %08x\n", hr
);
478 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
479 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
480 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
482 hr
= IRowPosition_GetRowset(rowpos
, &IID_IRowset
, &unk
);
483 ok(hr
== S_OK
, "got %08x\n", hr
);
485 init_onchange_sink(rowpos
);
486 hr
= IRowPosition_ClearRowPosition(rowpos
);
487 ok(hr
== S_OK
, "got %08x\n", hr
);
491 flags
= DBPOSITION_OK
;
492 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
493 ok(hr
== S_OK
, "got %08x\n", hr
);
494 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
495 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
496 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
498 IRowPosition_Release(rowpos
);
501 static void test_rowpos_setrowposition(void)
503 IRowPosition
*rowpos
;
506 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
507 ok(hr
== S_OK
, "got %08x\n", hr
);
510 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
511 ok(hr
== S_OK
, "got %08x\n", hr
);
513 hr
= IRowPosition_ClearRowPosition(rowpos
);
514 ok(hr
== S_OK
, "got %08x\n", hr
);
516 init_onchange_sink(rowpos
);
517 hr
= IRowPosition_SetRowPosition(rowpos
, 0x123, 0x456, DBPOSITION_OK
);
518 ok(hr
== S_OK
, "got %08x\n", hr
);
520 IRowPosition_Release(rowpos
);
523 static void test_dslocator(void)
525 IDataSourceLocator
*dslocator
= NULL
;
528 hr
= CoCreateInstance(&CLSID_DataLinks
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataSourceLocator
,(void**)&dslocator
);
529 ok(hr
== S_OK
, "got %08x\n", hr
);
532 COMPATIBLE_LONG hwnd
= 0;
534 /* Crashes under Window 7
535 hr = IDataSourceLocator_get_hWnd(dslocator, NULL);
536 ok(hr == E_INVALIDARG, "got %08x\n", hr);
539 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
540 ok(hr
== S_OK
, "got %08x\n", hr
);
541 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
544 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
545 ok(hr
== S_OK
, "got %08x\n", hr
);
546 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
549 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
550 ok(hr
== S_OK
, "got %08x\n", hr
);
553 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
554 ok(hr
== S_OK
, "got %08x\n", hr
);
555 ok(hwnd
== 0xDEADBEEF, "got %p\n", (HWND
)hwnd
);
558 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
559 ok(hr
== S_OK
, "got %08x\n", hr
);
562 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
563 ok(hr
== S_OK
, "got %08x\n", hr
);
564 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
566 IDataSourceLocator_Release(dslocator
);
576 test_initializationstring();
581 test_rowpos_initialize();
582 test_rowpos_clearrowposition();
583 test_rowpos_setrowposition();