From 8f8212b856a8e6b339fea6126381ace3613dfa7b Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Tue, 25 Sep 2012 12:43:58 +1000 Subject: [PATCH] oledb32: Add support for IDBInitialize interface in IDataInitialize. --- dlls/oledb32/datainit.c | 109 +++++++++++++++++++++++++++++++++ dlls/oledb32/tests/Makefile.in | 3 +- dlls/oledb32/tests/convert.c | 1 - dlls/oledb32/tests/database.c | 73 ++++++++++++++++++++++ dlls/oledb32/tests/marshal.c | 1 - 5 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 dlls/oledb32/tests/database.c diff --git a/dlls/oledb32/datainit.c b/dlls/oledb32/datainit.c index af596fead30..a84d8aa7a3c 100644 --- a/dlls/oledb32/datainit.c +++ b/dlls/oledb32/datainit.c @@ -47,6 +47,110 @@ static inline datainit *impl_from_IDataInitialize(IDataInitialize *iface) return CONTAINING_RECORD(iface, datainit, IDataInitialize_iface); } +typedef struct +{ + IDBInitialize IDBInitialize_iface; + + LONG ref; +} dbinit; + +static inline dbinit *impl_from_IDBInitialize(IDBInitialize *iface) +{ + return CONTAINING_RECORD(iface, dbinit, IDBInitialize_iface); +} + +static HRESULT WINAPI dbinit_QueryInterface(IDBInitialize *iface, REFIID riid, void **obj) +{ + dbinit *This = impl_from_IDBInitialize(iface); + TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj); + + *obj = NULL; + + if(IsEqualIID(riid, &IID_IUnknown) || + IsEqualIID(riid, &IID_IDBInitialize)) + { + *obj = iface; + } + else + { + FIXME("interface %s not implemented\n", debugstr_guid(riid)); + return E_NOINTERFACE; + } + + IDBInitialize_AddRef(iface); + return S_OK; +} + +static ULONG WINAPI dbinit_AddRef(IDBInitialize *iface) +{ + dbinit *This = impl_from_IDBInitialize(iface); + TRACE("(%p)\n", This); + + return InterlockedIncrement(&This->ref); +} + +static ULONG WINAPI dbinit_Release(IDBInitialize *iface) +{ + dbinit *This = impl_from_IDBInitialize(iface); + LONG ref; + + TRACE("(%p)\n", This); + + ref = InterlockedDecrement(&This->ref); + if(ref == 0) + { + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +static HRESULT WINAPI dbinit_Initialize(IDBInitialize *iface) +{ + dbinit *This = impl_from_IDBInitialize(iface); + + FIXME("(%p) stub\n", This); + + return S_OK; +} + +static HRESULT WINAPI dbinit_Uninitialize(IDBInitialize *iface) +{ + dbinit *This = impl_from_IDBInitialize(iface); + + FIXME("(%p) stub\n", This); + + return S_OK; +} + +static const IDBInitializeVtbl dbinit_vtbl = +{ + dbinit_QueryInterface, + dbinit_AddRef, + dbinit_Release, + dbinit_Initialize, + dbinit_Uninitialize +}; + +static HRESULT create_db_init(void **obj) +{ + dbinit *This; + + TRACE("()\n"); + + *obj = NULL; + + This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This)); + if(!This) return E_OUTOFMEMORY; + + This->IDBInitialize_iface.lpVtbl = &dbinit_vtbl; + This->ref = 1; + + *obj = &This->IDBInitialize_iface; + + return S_OK; +} + static HRESULT WINAPI datainit_QueryInterface(IDataInitialize *iface, REFIID riid, void **obj) { datainit *This = impl_from_IDataInitialize(iface); @@ -102,6 +206,11 @@ static HRESULT WINAPI datainit_GetDataSource(IDataInitialize *iface, IUnknown *p FIXME("(%p)->(%p %d %s %s %p)\n", This, pUnkOuter, dwClsCtx, debugstr_w(pwszInitializationString), debugstr_guid(riid), ppDataSource); + if(IsEqualIID(riid, &IID_IDBInitialize)) + { + return create_db_init( (LPVOID*)ppDataSource); + } + return E_NOTIMPL; } diff --git a/dlls/oledb32/tests/Makefile.in b/dlls/oledb32/tests/Makefile.in index f91f86bbc23..07a4892b5a5 100644 --- a/dlls/oledb32/tests/Makefile.in +++ b/dlls/oledb32/tests/Makefile.in @@ -1,8 +1,9 @@ TESTDLL = oledb32.dll -IMPORTS = oleaut32 ole32 user32 gdi32 advapi32 +IMPORTS = uuid oleaut32 ole32 user32 gdi32 advapi32 C_SRCS = \ convert.c \ + database.c \ marshal.c IDL_I_SRCS = convert.idl diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index 1a1ea9affa6..9d50b8a0483 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -35,7 +35,6 @@ #include "wine/test.h" -DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); static void test_dcinfo(void) { diff --git a/dlls/oledb32/tests/database.c b/dlls/oledb32/tests/database.c new file mode 100644 index 00000000000..c0d5237af72 --- /dev/null +++ b/dlls/oledb32/tests/database.c @@ -0,0 +1,73 @@ +/* OLEDB Database tests + * + * Copyright 2012 Alistair Leslie-Hughes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#include + +#define COBJMACROS +#define NONAMELESSUNION +#define NONAMELESSSTRUCT + +#include "windef.h" +#include "winbase.h" +#include "ole2.h" +#include "msdadc.h" +#include "msdasc.h" + +#include "wine/test.h" + + +void test_database(void) +{ + HRESULT hr; + IDBInitialize *dbinit = NULL; + IDataInitialize *datainit = NULL; + + hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit); + if(FAILED(hr)) + { + win_skip("Unable to load oledb library\n"); + return; + } + + hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, NULL, &IID_IDBInitialize, (IUnknown **)&dbinit); + ok(hr == S_OK, "got %08x\n", hr); + if(SUCCEEDED(hr)) + { + IDBProperties *props = NULL; + + hr = IDBInitialize_QueryInterface(dbinit, &IID_IDBProperties, (void**)&props); + todo_wine ok(hr == S_OK, "got %08x\n", hr); + if(SUCCEEDED(hr)) + { + IDBProperties_Release(props); + } + + IDBInitialize_Release(dbinit); + } + + IDataInitialize_Release(datainit); +} + +START_TEST(database) +{ + OleInitialize(NULL); + + test_database(); + + OleUninitialize(); +} diff --git a/dlls/oledb32/tests/marshal.c b/dlls/oledb32/tests/marshal.c index 39d8448fa10..f9a215044f7 100644 --- a/dlls/oledb32/tests/marshal.c +++ b/dlls/oledb32/tests/marshal.c @@ -27,7 +27,6 @@ #include "windef.h" #include "winbase.h" -#include "initguid.h" #include "objbase.h" #include "oledb.h"