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
37 #include "wine/test.h"
39 DEFINE_GUID(CSLID_MSDAER
, 0xc8b522cf,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);
41 static WCHAR initstring_default
[] = {'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',0};
43 static const char *debugstr_guid(REFIID riid
)
50 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
51 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
52 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
53 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
58 static void test_GetDataSource(WCHAR
*initstring
)
60 IDataInitialize
*datainit
= NULL
;
61 IDBInitialize
*dbinit
= NULL
;
64 trace("Data Source: %s\n", wine_dbgstr_w(initstring
));
66 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
,(void**)&datainit
);
67 ok(hr
== S_OK
, "got %08x\n", hr
);
69 /* a failure to create data source here may indicate provider is simply not present */
70 hr
= IDataInitialize_GetDataSource(datainit
, NULL
, CLSCTX_INPROC_SERVER
, initstring
, &IID_IDBInitialize
, (IUnknown
**)&dbinit
);
73 IDBProperties
*props
= NULL
;
76 hr
= SHGetMalloc(&ppM
);
79 ok(0, "Couldn't get IMalloc object.\n");
83 hr
= IDBInitialize_QueryInterface(dbinit
, &IID_IDBProperties
, (void**)&props
);
84 ok(hr
== S_OK
, "got %08x\n", hr
);
88 DBPROPINFOSET
*pInfoset
;
91 hr
= IDBProperties_GetPropertyInfo(props
, 0, NULL
, &cnt
, &pInfoset
, &ary
);
92 todo_wine
ok(hr
== S_OK
, "got %08x\n", hr
);
96 for(i
=0; i
< pInfoset
->cPropertyInfos
; i
++)
98 trace("(0x%04x) '%s' %d\n", pInfoset
->rgPropertyInfos
[i
].dwPropertyID
, wine_dbgstr_w(pInfoset
->rgPropertyInfos
[i
].pwszDescription
),
99 pInfoset
->rgPropertyInfos
[i
].vtType
);
102 IMalloc_Free(ppM
, ary
);
105 IDBProperties_Release(props
);
108 IMalloc_Release(ppM
);
111 IDBInitialize_Release(dbinit
);
114 IDataInitialize_Release(datainit
);
117 static void test_database(void)
119 static WCHAR initstring_jet
[] = {'P','r','o','v','i','d','e','r','=','M','i','c','r','o','s','o','f','t','.',
120 'J','e','t','.','O','L','E','D','B','.','4','.','0',';',
121 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
122 '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};
123 static WCHAR initstring_lower
[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',0};
124 IDataInitialize
*datainit
= NULL
;
127 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
, (void**)&datainit
);
130 win_skip("Unable to load oledb library\n");
133 IDataInitialize_Release(datainit
);
135 test_GetDataSource(NULL
);
136 test_GetDataSource(initstring_jet
);
137 test_GetDataSource(initstring_default
);
138 test_GetDataSource(initstring_lower
);
141 static void test_errorinfo(void)
144 IUnknown
*unk
= NULL
;
146 hr
= CoCreateInstance(&CSLID_MSDAER
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
,(void**)&unk
);
147 ok(hr
== S_OK
, "got %08x\n", hr
);
150 IErrorInfo
*errorinfo
;
151 IErrorRecords
*errrecs
;
153 hr
= IUnknown_QueryInterface(unk
, &IID_IErrorInfo
, (void**)&errorinfo
);
154 ok(hr
== S_OK
, "got %08x\n", hr
);
157 IErrorInfo_Release(errorinfo
);
160 hr
= IUnknown_QueryInterface(unk
, &IID_IErrorRecords
, (void**)&errrecs
);
161 ok(hr
== S_OK
, "got %08x\n", hr
);
164 ERRORINFO info
, info2
, info3
;
167 memset(&info
, 0, sizeof(ERRORINFO
));
169 memset(&info2
, 0, sizeof(ERRORINFO
));
171 memset(&info3
, 0, sizeof(ERRORINFO
));
173 hr
= IErrorRecords_AddErrorRecord(errrecs
, NULL
, 268435456, NULL
, NULL
, 0);
174 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
176 hr
= IErrorRecords_AddErrorRecord(errrecs
, &info
, 1, NULL
, NULL
, 0);
177 ok(hr
== S_OK
, "got %08x\n", hr
);
179 hr
= IErrorRecords_GetRecordCount(errrecs
, &cnt
);
180 ok(hr
== S_OK
, "got %08x\n", hr
);
181 ok(cnt
== 1, "expected 1 got %d\n", cnt
);
183 hr
= IErrorRecords_AddErrorRecord(errrecs
, &info2
, 2, NULL
, NULL
, 0);
184 ok(hr
== S_OK
, "got %08x\n", hr
);
186 hr
= IErrorRecords_GetRecordCount(errrecs
, &cnt
);
187 ok(hr
== S_OK
, "got %08x\n", hr
);
188 ok(cnt
== 2, "expected 2 got %d\n", cnt
);
190 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 0, NULL
);
191 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
193 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 100, &info3
);
194 ok(hr
== DB_E_BADRECORDNUM
, "got %08x\n", hr
);
196 hr
= IErrorRecords_GetBasicErrorInfo(errrecs
, 0, &info3
);
197 todo_wine
ok(hr
== S_OK
, "got %08x\n", hr
);
200 ok(info3
.dwMinor
== 2, "expected 2 got %d\n", info3
.dwMinor
);
203 IErrorRecords_Release(errrecs
);
206 IUnknown_Release(unk
);
210 static void test_initializationstring(void)
212 static WCHAR initstring_msdasql
[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
213 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
214 static WCHAR initstring_sqloledb
[] = {'P','r','o','v','i','d','e','r','=','S','Q','L','O','L','E','D','B','.','1',';',
215 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
216 IDataInitialize
*datainit
= NULL
;
217 IDBInitialize
*dbinit
= NULL
;
219 WCHAR
*initstring
= NULL
;
221 hr
= CoCreateInstance(&CLSID_MSDAINITIALIZE
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataInitialize
,(void**)&datainit
);
222 ok(hr
== S_OK
, "got %08x\n", hr
);
225 hr
= IDataInitialize_GetDataSource(datainit
, NULL
, CLSCTX_INPROC_SERVER
, initstring_default
,
226 &IID_IDBInitialize
, (IUnknown
**)&dbinit
);
229 hr
= IDataInitialize_GetInitializationString(datainit
, (IUnknown
*)dbinit
, 0, &initstring
);
230 ok(hr
== S_OK
, "got %08x\n", hr
);
233 trace("Init String: %s\n", wine_dbgstr_w(initstring
));
234 todo_wine
ok(!lstrcmpW(initstring_msdasql
, initstring
) ||
235 !lstrcmpW(initstring_sqloledb
, initstring
), "got %s\n", wine_dbgstr_w(initstring
));
236 CoTaskMemFree(initstring
);
239 IDBInitialize_Release(dbinit
);
242 IDataInitialize_Release(datainit
);
246 static void test_rowposition(void)
248 IEnumConnectionPoints
*enum_points
;
249 IConnectionPointContainer
*cpc
;
250 IConnectionPoint
*cp
;
251 IRowPosition
*rowpos
;
255 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
256 ok(hr
== S_OK
, "got %08x\n", hr
);
258 hr
= IRowPosition_QueryInterface(rowpos
, &IID_IConnectionPointContainer
, (void**)&cpc
);
259 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
261 hr
= IConnectionPointContainer_EnumConnectionPoints(cpc
, &enum_points
);
263 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
265 hr
= IEnumConnectionPoints_Next(enum_points
, 1, &cp
, NULL
);
266 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
267 hr
= IConnectionPoint_GetConnectionInterface(cp
, &iid
);
268 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
269 ok(IsEqualIID(&iid
, &IID_IRowPositionChange
), "got %s\n", debugstr_guid(&iid
));
270 IConnectionPoint_Release(cp
);
272 hr
= IEnumConnectionPoints_Next(enum_points
, 1, &cp
, NULL
);
273 ok(hr
== S_FALSE
, "got 0x%08x\n", hr
);
275 IEnumConnectionPoints_Release(enum_points
);
277 IConnectionPointContainer_Release(cpc
);
278 IRowPosition_Release(rowpos
);
283 IRowset IRowset_iface
;
284 IChapteredRowset IChapteredRowset_iface
;
287 static test_rset_t test_rset
;
289 static HRESULT WINAPI
rset_QI(IRowset
*iface
, REFIID riid
, void **obj
)
291 if (IsEqualIID(riid
, &IID_IUnknown
) ||
292 IsEqualIID(riid
, &IID_IRowset
))
294 *obj
= &test_rset
.IRowset_iface
;
297 else if (IsEqualIID(riid
, &IID_IChapteredRowset
))
299 *obj
= &test_rset
.IChapteredRowset_iface
;
303 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
304 return E_NOINTERFACE
;
307 static ULONG WINAPI
rset_AddRef(IRowset
*iface
)
312 static ULONG WINAPI
rset_Release(IRowset
*iface
)
317 static HRESULT WINAPI
rset_AddRefRows(IRowset
*iface
, DBCOUNTITEM cRows
,
318 const HROW rghRows
[], DBREFCOUNT rgRefCounts
[], DBROWSTATUS rgRowStatus
[])
320 trace("AddRefRows: %ld\n", rghRows
[0]);
324 static HRESULT WINAPI
rset_GetData(IRowset
*iface
, HROW hRow
, HACCESSOR hAccessor
, void *pData
)
326 ok(0, "unexpected call\n");
330 static HRESULT WINAPI
rset_GetNextRows(IRowset
*iface
, HCHAPTER hReserved
, DBROWOFFSET lRowsOffset
,
331 DBROWCOUNT cRows
, DBCOUNTITEM
*pcRowObtained
, HROW
**prghRows
)
333 ok(0, "unexpected call\n");
337 static HRESULT WINAPI
rset_ReleaseRows(IRowset
*iface
, DBCOUNTITEM cRows
, const HROW rghRows
[], DBROWOPTIONS rgRowOptions
[],
338 DBREFCOUNT rgRefCounts
[], DBROWSTATUS rgRowStatus
[])
343 static HRESULT WINAPI
rset_RestartPosition(IRowset
*iface
, HCHAPTER hReserved
)
345 ok(0, "unexpected call\n");
349 static const IRowsetVtbl rset_vtbl
= {
360 static HRESULT WINAPI
chrset_QI(IChapteredRowset
*iface
, REFIID riid
, void **obj
)
362 return IRowset_QueryInterface(&test_rset
.IRowset_iface
, riid
, obj
);
365 static ULONG WINAPI
chrset_AddRef(IChapteredRowset
*iface
)
367 return IRowset_AddRef(&test_rset
.IRowset_iface
);
370 static ULONG WINAPI
chrset_Release(IChapteredRowset
*iface
)
372 return IRowset_Release(&test_rset
.IRowset_iface
);
375 static HRESULT WINAPI
chrset_AddRefChapter(IChapteredRowset
*iface
, HCHAPTER chapter
, DBREFCOUNT
*refcount
)
380 static HRESULT WINAPI
chrset_ReleaseChapter(IChapteredRowset
*iface
, HCHAPTER chapter
, DBREFCOUNT
*refcount
)
385 static const IChapteredRowsetVtbl chrset_vtbl
= {
389 chrset_AddRefChapter
,
390 chrset_ReleaseChapter
393 static void init_test_rset(void)
395 test_rset
.IRowset_iface
.lpVtbl
= &rset_vtbl
;
396 test_rset
.IChapteredRowset_iface
.lpVtbl
= &chrset_vtbl
;
399 static void test_rowpos_initialize(void)
401 IRowPosition
*rowpos
;
404 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
405 ok(hr
== S_OK
, "got %08x\n", hr
);
408 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
409 ok(hr
== S_OK
, "got %08x\n", hr
);
411 IRowPosition_Release(rowpos
);
414 static HRESULT WINAPI
onchange_QI(IRowPositionChange
*iface
, REFIID riid
, void **obj
)
416 if (IsEqualIID(riid
, &IID_IUnknown
) ||
417 IsEqualIID(riid
, &IID_IRowPositionChange
))
423 return E_NOINTERFACE
;
426 static ULONG WINAPI
onchange_AddRef(IRowPositionChange
*iface
)
431 static ULONG WINAPI
onchange_Release(IRowPositionChange
*iface
)
436 static HRESULT WINAPI
onchange_OnRowPositionChange(IRowPositionChange
*iface
, DBREASON reason
,
437 DBEVENTPHASE phase
, BOOL cant_deny
)
439 trace("%d %d %d\n", reason
, phase
, cant_deny
);
443 static const IRowPositionChangeVtbl onchange_vtbl
= {
447 onchange_OnRowPositionChange
450 static IRowPositionChange onchangesink
= { &onchange_vtbl
};
452 static void init_onchange_sink(IRowPosition
*rowpos
)
454 IConnectionPointContainer
*cpc
;
455 IConnectionPoint
*cp
;
459 hr
= IRowPosition_QueryInterface(rowpos
, &IID_IConnectionPointContainer
, (void**)&cpc
);
460 ok(hr
== S_OK
, "got %08x\n", hr
);
461 hr
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IRowPositionChange
, &cp
);
462 ok(hr
== S_OK
, "got %08x\n", hr
);
463 hr
= IConnectionPoint_Advise(cp
, (IUnknown
*)&onchangesink
, &cookie
);
464 ok(hr
== S_OK
, "got %08x\n", hr
);
465 IConnectionPoint_Release(cp
);
466 IConnectionPointContainer_Release(cpc
);
469 static void test_rowpos_clearrowposition(void)
471 DBPOSITIONFLAGS flags
;
472 IRowPosition
*rowpos
;
478 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
479 ok(hr
== S_OK
, "got %08x\n", hr
);
481 hr
= IRowPosition_ClearRowPosition(rowpos
);
482 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
484 hr
= IRowPosition_GetRowset(rowpos
, &IID_IStream
, &unk
);
485 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
489 flags
= DBPOSITION_OK
;
490 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
491 ok(hr
== E_UNEXPECTED
, "got %08x\n", hr
);
492 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
493 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
494 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
497 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
498 ok(hr
== S_OK
, "got %08x\n", hr
);
502 flags
= DBPOSITION_OK
;
503 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
504 ok(hr
== S_OK
, "got %08x\n", hr
);
505 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
506 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
507 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
509 hr
= IRowPosition_GetRowset(rowpos
, &IID_IRowset
, &unk
);
510 ok(hr
== S_OK
, "got %08x\n", hr
);
512 init_onchange_sink(rowpos
);
513 hr
= IRowPosition_ClearRowPosition(rowpos
);
514 ok(hr
== S_OK
, "got %08x\n", hr
);
518 flags
= DBPOSITION_OK
;
519 hr
= IRowPosition_GetRowPosition(rowpos
, &chapter
, &row
, &flags
);
520 ok(hr
== S_OK
, "got %08x\n", hr
);
521 ok(chapter
== DB_NULL_HCHAPTER
, "got %ld\n", chapter
);
522 ok(row
== DB_NULL_HROW
, "got %ld\n", row
);
523 ok(flags
== DBPOSITION_NOROW
, "got %d\n", flags
);
525 IRowPosition_Release(rowpos
);
528 static void test_rowpos_setrowposition(void)
530 IRowPosition
*rowpos
;
533 hr
= CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IRowPosition
, (void**)&rowpos
);
534 ok(hr
== S_OK
, "got %08x\n", hr
);
537 hr
= IRowPosition_Initialize(rowpos
, (IUnknown
*)&test_rset
.IRowset_iface
);
538 ok(hr
== S_OK
, "got %08x\n", hr
);
540 hr
= IRowPosition_ClearRowPosition(rowpos
);
541 ok(hr
== S_OK
, "got %08x\n", hr
);
543 init_onchange_sink(rowpos
);
544 hr
= IRowPosition_SetRowPosition(rowpos
, 0x123, 0x456, DBPOSITION_OK
);
545 ok(hr
== S_OK
, "got %08x\n", hr
);
547 IRowPosition_Release(rowpos
);
550 static void test_dslocator(void)
552 IDataSourceLocator
*dslocator
= NULL
;
555 hr
= CoCreateInstance(&CLSID_DataLinks
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDataSourceLocator
,(void**)&dslocator
);
556 ok(hr
== S_OK
, "got %08x\n", hr
);
559 COMPATIBLE_LONG hwnd
= 0;
561 /* Crashes under Window 7
562 hr = IDataSourceLocator_get_hWnd(dslocator, NULL);
563 ok(hr == E_INVALIDARG, "got %08x\n", hr);
566 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
567 ok(hr
== S_OK
, "got %08x\n", hr
);
568 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
571 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
572 ok(hr
== S_OK
, "got %08x\n", hr
);
573 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
576 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
577 ok(hr
== S_OK
, "got %08x\n", hr
);
580 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
581 ok(hr
== S_OK
, "got %08x\n", hr
);
582 ok(hwnd
== 0xDEADBEEF, "got %p\n", (HWND
)hwnd
);
585 hr
= IDataSourceLocator_put_hWnd(dslocator
, hwnd
);
586 ok(hr
== S_OK
, "got %08x\n", hr
);
589 hr
= IDataSourceLocator_get_hWnd(dslocator
, &hwnd
);
590 ok(hr
== S_OK
, "got %08x\n", hr
);
591 ok(hwnd
== 0, "got %p\n", (HWND
)hwnd
);
593 IDataSourceLocator_Release(dslocator
);
603 test_initializationstring();
608 test_rowpos_initialize();
609 test_rowpos_clearrowposition();
610 test_rowpos_setrowposition();