Module: wine Branch: master Commit: 0e8b9b12114a7e89c778655db414e0cbbb8b4998 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0e8b9b12114a7e89c778655db4...
Author: Vincent Povirk vincent@codeweavers.com Date: Tue May 22 10:46:57 2012 -0500
propsys: Add tests for CLSID_InMemoryPropertyStore.
---
dlls/propsys/tests/Makefile.in | 1 + dlls/propsys/tests/propstore.c | 206 ++++++++++++++++++++++++++++++++++++++++ dlls/propsys/tests/propsys.c | 2 +- 3 files changed, 208 insertions(+), 1 deletions(-)
diff --git a/dlls/propsys/tests/Makefile.in b/dlls/propsys/tests/Makefile.in index 312a3a9..cb502fd 100644 --- a/dlls/propsys/tests/Makefile.in +++ b/dlls/propsys/tests/Makefile.in @@ -2,6 +2,7 @@ TESTDLL = propsys.dll IMPORTS = propsys ole32 oleaut32
C_SRCS = \ + propstore.c \ propsys.c
@MAKE_TEST_RULES@ diff --git a/dlls/propsys/tests/propstore.c b/dlls/propsys/tests/propstore.c new file mode 100644 index 0000000..e8bedc6 --- /dev/null +++ b/dlls/propsys/tests/propstore.c @@ -0,0 +1,206 @@ +/* + * Unit tests for IPropertyStore and related interfaces + * + * Copyright 2012 Vincent Povirk + * + * 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 + */ + +#define COBJMACROS + +#include <stdarg.h> +#include <stdio.h> + +#define NONAMELESSUNION + +#include "windef.h" +#include "winbase.h" +#include "objbase.h" +#include "propsys.h" +#include "wine/test.h" + +#include "initguid.h" + +DEFINE_GUID(PKEY_WineTest, 0x7b317433, 0xdfa3, 0x4c44, 0xad, 0x3e, 0x2f, 0x80, 0x4b, 0x90, 0xdb, 0xf4); + +static void test_inmemorystore(void) +{ + IPropertyStoreCache *propcache; + HRESULT hr; + PROPERTYKEY pkey; + PROPVARIANT propvar; + DWORD count; + PSC_STATE state; + + hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, + &IID_IPropertyStoreCache, (void**)&propcache); + todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); + + if (FAILED(hr)) + { + skip("CLSID_InMemoryPropertyStore not supported\n"); + return; + } + + hr = IPropertyStoreCache_GetCount(propcache, NULL); + ok(hr == E_POINTER, "GetCount failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_GetCount(propcache, &count); + ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); + ok(count == 0, "GetCount returned %i, expected 0\n", count); + + hr = IPropertyStoreCache_Commit(propcache); + ok(hr == S_OK, "Commit failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_Commit(propcache); + ok(hr == S_OK, "Commit failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); + ok(hr == E_INVALIDARG, "GetAt failed, hr=%x\n", hr); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + memset(&propvar, 0, sizeof(propvar)); + propvar.vt = VT_I4; + propvar.u.lVal = 12345; + + if (0) + { + /* Crashes on Windows 7 */ + hr = IPropertyStoreCache_SetValue(propcache, NULL, &propvar); + ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_SetValue(propcache, &pkey, NULL); + ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr); + } + + hr = IPropertyStoreCache_SetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "SetValue failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_GetCount(propcache, &count); + ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); + ok(count == 1, "GetCount returned %i, expected 0\n", count); + + memset(&pkey, 0, sizeof(pkey)); + + hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey); + ok(hr == S_OK, "GetAt failed, hr=%x\n", hr); + ok(IsEqualGUID(&pkey.fmtid, &PKEY_WineTest), "got wrong pkey\n"); + ok(pkey.pid == 4, "got pid of %i, expected 4\n", pkey.pid); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + memset(&propvar, 0, sizeof(propvar)); + + if (0) + { + /* Crashes on Windows 7 */ + hr = IPropertyStoreCache_GetValue(propcache, NULL, &propvar); + ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr); + } + + hr = IPropertyStoreCache_GetValue(propcache, &pkey, NULL); + ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr); + + hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.u.lVal == 12345, "expected 12345, got %d\n", propvar.u.lVal); + + pkey.fmtid = PKEY_WineTest; + pkey.pid = 10; + + /* Get information for field that isn't set yet */ + propvar.vt = VT_I2; + hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar); + ok(hr == S_OK, "GetValue failed, hr=%x\n", hr); + ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetState failed, hr=%x\n", hr); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + propvar.vt = VT_I2; + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetValueAndState failed, hr=%x\n", hr); + ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + /* Set state on an unset field */ + hr = IPropertyStoreCache_SetState(propcache, &pkey, PSC_NORMAL); + ok(hr == TYPE_E_ELEMENTNOTFOUND, "SetState failed, hr=%x\n", hr); + + /* Manipulate state on already set field */ + pkey.fmtid = PKEY_WineTest; + pkey.pid = 4; + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == S_OK, "GetState failed, hr=%x\n", hr); + ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state); + + hr = IPropertyStoreCache_SetState(propcache, &pkey, 10); + ok(hr == S_OK, "SetState failed, hr=%x\n", hr); + + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetState(propcache, &pkey, &state); + ok(hr == S_OK, "GetState failed, hr=%x\n", hr); + ok(state == 10, "expected 10, got %d\n", state); + + propvar.vt = VT_I4; + propvar.u.lVal = 12346; + hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, 5); + ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr); + + memset(&propvar, 0, sizeof(propvar)); + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.u.lVal == 12346, "expected 12346, got %d\n", propvar.vt); + ok(state == 5, "expected 5, got %d\n", state); + + /* Set new field with state */ + pkey.fmtid = PKEY_WineTest; + pkey.pid = 8; + + propvar.vt = VT_I4; + propvar.u.lVal = 12347; + hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, PSC_DIRTY); + ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr); + + memset(&propvar, 0, sizeof(propvar)); + state = 0xdeadbeef; + hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state); + ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr); + ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt); + ok(propvar.u.lVal == 12347, "expected 12347, got %d\n", propvar.vt); + ok(state == PSC_DIRTY, "expected PSC_DIRTY, got %d\n", state); + + IPropertyStoreCache_Release(propcache); +} + +START_TEST(propstore) +{ + CoInitialize(NULL); + + test_inmemorystore(); + + CoUninitialize(); +} diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c index 850d3d2..9641d05 100644 --- a/dlls/propsys/tests/propsys.c +++ b/dlls/propsys/tests/propsys.c @@ -29,9 +29,9 @@ #include "windef.h" #include "winbase.h" #include "objbase.h" +#include "initguid.h" #include "propsys.h" #include "propvarutil.h" -#include "initguid.h" #include "wine/test.h"
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);