mshtml: Wine Gecko 2.34-beta2 release.
[wine/wine-gecko.git] / dlls / oledb32 / tests / database.c
bloba46725c0451d0977929834186689613c0a21e89d
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 NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ole2.h"
30 #include "msdadc.h"
31 #include "msdasc.h"
32 #include "msdaguid.h"
33 #include "initguid.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 static void test_GetDataSource(WCHAR *initstring)
44 IDataInitialize *datainit = NULL;
45 IDBInitialize *dbinit = NULL;
46 HRESULT hr;
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);
55 if(SUCCEEDED(hr))
57 IDBProperties *props = NULL;
59 hr = IDBInitialize_QueryInterface(dbinit, &IID_IDBProperties, (void**)&props);
60 ok(hr == S_OK, "got %08x\n", hr);
61 if(SUCCEEDED(hr))
63 ULONG cnt;
64 DBPROPINFOSET *pInfoset;
65 OLECHAR *ary;
67 hr = IDBProperties_GetPropertyInfo(props, 0, NULL, &cnt, &pInfoset, &ary);
68 todo_wine ok(hr == S_OK, "got %08x\n", hr);
69 if(hr == S_OK)
71 ULONG i;
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);
78 CoTaskMemFree(ary);
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;
98 HRESULT hr;
100 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize, (void**)&datainit);
101 if (FAILED(hr))
103 win_skip("Unable to load oledb library\n");
104 return;
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)
116 HRESULT hr;
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);
121 if(hr == S_OK)
123 IErrorInfo *errorinfo;
124 IErrorRecords *errrecs;
126 hr = IUnknown_QueryInterface(unk, &IID_IErrorInfo, (void**)&errorinfo);
127 ok(hr == S_OK, "got %08x\n", hr);
128 if(hr == S_OK)
130 IErrorInfo_Release(errorinfo);
133 hr = IUnknown_QueryInterface(unk, &IID_IErrorRecords, (void**)&errrecs);
134 ok(hr == S_OK, "got %08x\n", hr);
135 if(hr == S_OK)
137 ERRORINFO info, info2, info3;
138 ULONG cnt = 0;
140 memset(&info, 0, sizeof(ERRORINFO));
141 info.dwMinor = 1;
142 memset(&info2, 0, sizeof(ERRORINFO));
143 info2.dwMinor = 2;
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);
171 if(hr == S_OK)
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;
191 HRESULT hr;
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);
196 if(SUCCEEDED(hr))
198 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring_default,
199 &IID_IDBInitialize, (IUnknown**)&dbinit);
200 if(SUCCEEDED(hr))
202 hr = IDataInitialize_GetInitializationString(datainit, (IUnknown*)dbinit, 0, &initstring);
203 ok(hr == S_OK, "got %08x\n", hr);
204 if(hr == S_OK)
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;
225 HRESULT hr;
226 IID iid;
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);
235 todo_wine
236 ok(hr == S_OK, "got 0x%08x\n", hr);
237 if (hr == S_OK) {
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);
254 typedef struct
256 IRowset IRowset_iface;
257 IChapteredRowset IChapteredRowset_iface;
258 } test_rset_t;
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;
268 return S_OK;
270 else if (IsEqualIID(riid, &IID_IChapteredRowset))
272 *obj = &test_rset.IChapteredRowset_iface;
273 return S_OK;
276 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
277 return E_NOINTERFACE;
280 static ULONG WINAPI rset_AddRef(IRowset *iface)
282 return 2;
285 static ULONG WINAPI rset_Release(IRowset *iface)
287 return 1;
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]);
294 return S_OK;
297 static HRESULT WINAPI rset_GetData(IRowset *iface, HROW hRow, HACCESSOR hAccessor, void *pData)
299 ok(0, "unexpected call\n");
300 return E_NOTIMPL;
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");
307 return E_NOTIMPL;
310 static HRESULT WINAPI rset_ReleaseRows(IRowset *iface, DBCOUNTITEM cRows, const HROW rghRows[], DBROWOPTIONS rgRowOptions[],
311 DBREFCOUNT rgRefCounts[], DBROWSTATUS rgRowStatus[])
313 return S_OK;
316 static HRESULT WINAPI rset_RestartPosition(IRowset *iface, HCHAPTER hReserved)
318 ok(0, "unexpected call\n");
319 return E_NOTIMPL;
322 static const IRowsetVtbl rset_vtbl = {
323 rset_QI,
324 rset_AddRef,
325 rset_Release,
326 rset_AddRefRows,
327 rset_GetData,
328 rset_GetNextRows,
329 rset_ReleaseRows,
330 rset_RestartPosition
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)
350 return S_OK;
353 static HRESULT WINAPI chrset_ReleaseChapter(IChapteredRowset *iface, HCHAPTER chapter, DBREFCOUNT *refcount)
355 return S_OK;
358 static const IChapteredRowsetVtbl chrset_vtbl = {
359 chrset_QI,
360 chrset_AddRef,
361 chrset_Release,
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;
375 HRESULT hr;
377 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
378 ok(hr == S_OK, "got %08x\n", hr);
380 init_test_rset();
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))
392 *obj = iface;
393 return S_OK;
396 return E_NOINTERFACE;
399 static ULONG WINAPI onchange_AddRef(IRowPositionChange *iface)
401 return 2;
404 static ULONG WINAPI onchange_Release(IRowPositionChange *iface)
406 return 1;
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);
413 return S_OK;
416 static const IRowPositionChangeVtbl onchange_vtbl = {
417 onchange_QI,
418 onchange_AddRef,
419 onchange_Release,
420 onchange_OnRowPositionChange
423 static IRowPositionChange onchangesink = { &onchange_vtbl };
425 static void init_onchange_sink(IRowPosition *rowpos)
427 IConnectionPointContainer *cpc;
428 IConnectionPoint *cp;
429 DWORD cookie;
430 HRESULT hr;
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;
446 HCHAPTER chapter;
447 IUnknown *unk;
448 HRESULT hr;
449 HROW row;
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);
460 chapter = 1;
461 row = 1;
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);
469 init_test_rset();
470 hr = IRowPosition_Initialize(rowpos, (IUnknown*)&test_rset.IRowset_iface);
471 ok(hr == S_OK, "got %08x\n", hr);
473 chapter = 1;
474 row = 1;
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);
489 chapter = 1;
490 row = 1;
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;
504 HRESULT hr;
506 hr = CoCreateInstance(&CLSID_OLEDB_ROWPOSITIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IRowPosition, (void**)&rowpos);
507 ok(hr == S_OK, "got %08x\n", hr);
509 init_test_rset();
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;
526 HRESULT hr;
528 hr = CoCreateInstance(&CLSID_DataLinks, NULL, CLSCTX_INPROC_SERVER, &IID_IDataSourceLocator,(void**)&dslocator);
529 ok(hr == S_OK, "got %08x\n", hr);
530 if(SUCCEEDED(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);
543 hwnd = 0xDEADBEEF;
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);
548 hwnd = 0xDEADBEEF;
549 hr = IDataSourceLocator_put_hWnd(dslocator, hwnd);
550 ok(hr == S_OK, "got %08x\n", hr);
552 hwnd = 0xDEADBEEF;
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);
557 hwnd = 0;
558 hr = IDataSourceLocator_put_hWnd(dslocator, hwnd);
559 ok(hr == S_OK, "got %08x\n", hr);
561 hwnd = 0xDEADBEEF;
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);
570 START_TEST(database)
572 OleInitialize(NULL);
574 test_database();
575 test_errorinfo();
576 test_initializationstring();
577 test_dslocator();
579 /* row position */
580 test_rowposition();
581 test_rowpos_initialize();
582 test_rowpos_clearrowposition();
583 test_rowpos_setrowposition();
585 OleUninitialize();