2012-05-22 17:46:57 +02:00
|
|
|
/*
|
|
|
|
* 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);
|
2012-05-22 21:18:11 +02:00
|
|
|
ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
skip("CLSID_InMemoryPropertyStore not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPropertyStoreCache_GetCount(propcache, NULL);
|
2012-05-22 22:24:03 +02:00
|
|
|
ok(hr == E_POINTER, "GetCount failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
hr = IPropertyStoreCache_GetCount(propcache, &count);
|
2012-05-22 22:24:03 +02:00
|
|
|
ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
|
|
|
|
ok(count == 0, "GetCount returned %i, expected 0\n", count);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
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);
|
2012-05-22 22:34:25 +02:00
|
|
|
ok(hr == E_INVALIDARG, "GetAt failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
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);
|
2012-05-22 22:19:51 +02:00
|
|
|
ok(hr == S_OK, "SetValue failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
hr = IPropertyStoreCache_GetCount(propcache, &count);
|
2012-05-22 22:24:03 +02:00
|
|
|
ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
|
|
|
|
ok(count == 1, "GetCount returned %i, expected 0\n", count);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
memset(&pkey, 0, sizeof(pkey));
|
|
|
|
|
|
|
|
hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey);
|
2012-05-22 22:34:25 +02:00
|
|
|
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);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
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);
|
2012-05-22 22:19:51 +02:00
|
|
|
ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar);
|
2012-05-22 22:19:51 +02:00
|
|
|
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);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
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);
|
2012-05-22 22:19:51 +02:00
|
|
|
ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
|
|
|
|
ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
propvar.vt = VT_I2;
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetValueAndState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt);
|
|
|
|
todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
/* Set state on an unset field */
|
|
|
|
hr = IPropertyStoreCache_SetState(propcache, &pkey, PSC_NORMAL);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "SetState failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
/* Manipulate state on already set field */
|
|
|
|
pkey.fmtid = PKEY_WineTest;
|
|
|
|
pkey.pid = 4;
|
|
|
|
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "GetState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
hr = IPropertyStoreCache_SetState(propcache, &pkey, 10);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "SetState failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "GetState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(state == 10, "expected 10, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
propvar.vt = VT_I4;
|
|
|
|
propvar.u.lVal = 12346;
|
|
|
|
hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, 5);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
memset(&propvar, 0, sizeof(propvar));
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt);
|
|
|
|
todo_wine ok(propvar.u.lVal == 12346, "expected 12346, got %d\n", propvar.vt);
|
|
|
|
todo_wine ok(state == 5, "expected 5, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
/* 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);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
memset(&propvar, 0, sizeof(propvar));
|
|
|
|
state = 0xdeadbeef;
|
|
|
|
hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
|
2012-05-22 21:18:11 +02:00
|
|
|
todo_wine ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr);
|
|
|
|
todo_wine ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt);
|
|
|
|
todo_wine ok(propvar.u.lVal == 12347, "expected 12347, got %d\n", propvar.vt);
|
|
|
|
todo_wine ok(state == PSC_DIRTY, "expected PSC_DIRTY, got %d\n", state);
|
2012-05-22 17:46:57 +02:00
|
|
|
|
|
|
|
IPropertyStoreCache_Release(propcache);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(propstore)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
test_inmemorystore();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|