oledb32: Add more database tests.
[wine/multimedia.git] / dlls / oledb32 / tests / database.c
blob9a0ee204b2ebe12cd1fa7d1a71216bcd723d100a
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>
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28 #include "msdadc.h"
29 #include "msdasc.h"
30 #include "shlobj.h"
31 #include "initguid.h"
33 #include "wine/test.h"
35 DEFINE_GUID(CSLID_MSDAER, 0xc8b522cf,0x5cf3,0x11ce,0xad,0xe5,0x00,0xaa,0x00,0x44,0x77,0x3d);
37 static WCHAR initstring_default[] = {'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',0};
39 static void test_GetDataSource(WCHAR *initstring)
41 IDataInitialize *datainit = NULL;
42 IDBInitialize *dbinit = NULL;
43 HRESULT hr;
45 trace("Data Source: %s\n", wine_dbgstr_w(initstring));
47 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit);
48 ok(hr == S_OK, "got %08x\n", hr);
50 /* a failure to create data source here may indicate provider is simply not present */
51 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring, &IID_IDBInitialize, (IUnknown**)&dbinit);
52 if(SUCCEEDED(hr))
54 IDBProperties *props = NULL;
55 IMalloc *ppM = NULL;
57 hr = SHGetMalloc(&ppM);
58 if (FAILED(hr))
60 ok(0, "Couldn't get IMalloc object.\n");
61 goto end;
64 hr = IDBInitialize_QueryInterface(dbinit, &IID_IDBProperties, (void**)&props);
65 ok(hr == S_OK, "got %08x\n", hr);
66 if(SUCCEEDED(hr))
68 ULONG cnt;
69 DBPROPINFOSET *pInfoset;
70 OLECHAR *ary;
72 hr = IDBProperties_GetPropertyInfo(props, 0, NULL, &cnt, &pInfoset, &ary);
73 todo_wine ok(hr == S_OK, "got %08x\n", hr);
74 if(hr == S_OK)
76 ULONG i;
77 for(i =0; i < pInfoset->cPropertyInfos; i++)
79 trace("(0x%04x) '%s' %d\n", pInfoset->rgPropertyInfos[i].dwPropertyID, wine_dbgstr_w(pInfoset->rgPropertyInfos[i].pwszDescription),
80 pInfoset->rgPropertyInfos[i].vtType);
83 IMalloc_Free(ppM, ary);
86 IDBProperties_Release(props);
89 IMalloc_Release(ppM);
91 end:
92 IDBInitialize_Release(dbinit);
95 IDataInitialize_Release(datainit);
98 static void test_database(void)
100 static WCHAR initstring_jet[] = {'P','r','o','v','i','d','e','r','=','M','i','c','r','o','s','o','f','t','.',
101 'J','e','t','.','O','L','E','D','B','.','4','.','0',';',
102 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y',';',
103 '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};
104 static WCHAR initstring_lower[] = {'d','a','t','a',' ','s','o','u','r','c','e','=','d','u','m','m','y',';',0};
105 IDataInitialize *datainit = NULL;
106 HRESULT hr;
108 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize, (void**)&datainit);
109 if (FAILED(hr))
111 win_skip("Unable to load oledb library\n");
112 return;
114 IDataInitialize_Release(datainit);
116 test_GetDataSource(NULL);
117 test_GetDataSource(initstring_jet);
118 test_GetDataSource(initstring_default);
119 test_GetDataSource(initstring_lower);
122 static void test_errorinfo(void)
124 HRESULT hr;
125 IUnknown *unk = NULL;
127 hr = CoCreateInstance(&CSLID_MSDAER, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,(void**)&unk);
128 todo_wine ok(hr == S_OK, "got %08x\n", hr);
129 if(hr == S_OK)
131 IErrorInfo *errorinfo;
133 hr = IUnknown_QueryInterface(unk, &IID_IErrorInfo, (void**)&errorinfo);
134 ok(hr == S_OK, "got %08x\n", hr);
135 if(hr == S_OK)
137 IErrorInfo_Release(errorinfo);
140 IUnknown_Release(unk);
144 static void test_initializationstring(void)
146 static WCHAR initstring_msdasql[] = {'P','r','o','v','i','d','e','r','=','M','S','D','A','S','Q','L','.','1',';',
147 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
148 static WCHAR initstring_sqloledb[] = {'P','r','o','v','i','d','e','r','=','S','Q','L','O','L','E','D','B','.','1',';',
149 'D','a','t','a',' ','S','o','u','r','c','e','=','d','u','m','m','y', 0};
150 IDataInitialize *datainit = NULL;
151 IDBInitialize *dbinit = NULL;
152 HRESULT hr;
153 WCHAR *initstring = NULL;
155 hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit);
156 ok(hr == S_OK, "got %08x\n", hr);
157 if(SUCCEEDED(hr))
159 hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring_default,
160 &IID_IDBInitialize, (IUnknown**)&dbinit);
161 if(SUCCEEDED(hr))
163 hr = IDataInitialize_GetInitializationString(datainit, (IUnknown*)dbinit, 0, &initstring);
164 ok(hr == S_OK, "got %08x\n", hr);
165 if(hr == S_OK)
167 trace("Init String: %s\n", wine_dbgstr_w(initstring));
168 todo_wine ok(!lstrcmpW(initstring_msdasql, initstring) ||
169 !lstrcmpW(initstring_sqloledb, initstring), "got %s\n", wine_dbgstr_w(initstring));
170 CoTaskMemFree(initstring);
173 IDBInitialize_Release(dbinit);
176 IDataInitialize_Release(datainit);
180 START_TEST(database)
182 OleInitialize(NULL);
184 test_database();
185 test_errorinfo();
186 test_initializationstring();
188 OleUninitialize();