propsys: Implement IPropertyStore::GetAt.
[wine/multimedia.git] / dlls / propsys / tests / propstore.c
blob7915b96614facccb82cf4cff3a0267ed7da8ec05
1 /*
2 * Unit tests for IPropertyStore and related interfaces
4 * Copyright 2012 Vincent Povirk
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include <stdio.h>
26 #define NONAMELESSUNION
28 #include "windef.h"
29 #include "winbase.h"
30 #include "objbase.h"
31 #include "propsys.h"
32 #include "wine/test.h"
34 #include "initguid.h"
36 DEFINE_GUID(PKEY_WineTest, 0x7b317433, 0xdfa3, 0x4c44, 0xad, 0x3e, 0x2f, 0x80, 0x4b, 0x90, 0xdb, 0xf4);
38 static void test_inmemorystore(void)
40 IPropertyStoreCache *propcache;
41 HRESULT hr;
42 PROPERTYKEY pkey;
43 PROPVARIANT propvar;
44 DWORD count;
45 PSC_STATE state;
47 hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER,
48 &IID_IPropertyStoreCache, (void**)&propcache);
49 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
51 if (FAILED(hr))
53 skip("CLSID_InMemoryPropertyStore not supported\n");
54 return;
57 hr = IPropertyStoreCache_GetCount(propcache, NULL);
58 ok(hr == E_POINTER, "GetCount failed, hr=%x\n", hr);
60 hr = IPropertyStoreCache_GetCount(propcache, &count);
61 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
62 ok(count == 0, "GetCount returned %i, expected 0\n", count);
64 hr = IPropertyStoreCache_Commit(propcache);
65 ok(hr == S_OK, "Commit failed, hr=%x\n", hr);
67 hr = IPropertyStoreCache_Commit(propcache);
68 ok(hr == S_OK, "Commit failed, hr=%x\n", hr);
70 hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey);
71 ok(hr == E_INVALIDARG, "GetAt failed, hr=%x\n", hr);
73 pkey.fmtid = PKEY_WineTest;
74 pkey.pid = 4;
76 memset(&propvar, 0, sizeof(propvar));
77 propvar.vt = VT_I4;
78 propvar.u.lVal = 12345;
80 if (0)
82 /* Crashes on Windows 7 */
83 hr = IPropertyStoreCache_SetValue(propcache, NULL, &propvar);
84 ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr);
86 hr = IPropertyStoreCache_SetValue(propcache, &pkey, NULL);
87 ok(hr == E_POINTER, "SetValue failed, hr=%x\n", hr);
90 hr = IPropertyStoreCache_SetValue(propcache, &pkey, &propvar);
91 ok(hr == S_OK, "SetValue failed, hr=%x\n", hr);
93 hr = IPropertyStoreCache_GetCount(propcache, &count);
94 ok(hr == S_OK, "GetCount failed, hr=%x\n", hr);
95 ok(count == 1, "GetCount returned %i, expected 0\n", count);
97 memset(&pkey, 0, sizeof(pkey));
99 hr = IPropertyStoreCache_GetAt(propcache, 0, &pkey);
100 ok(hr == S_OK, "GetAt failed, hr=%x\n", hr);
101 ok(IsEqualGUID(&pkey.fmtid, &PKEY_WineTest), "got wrong pkey\n");
102 ok(pkey.pid == 4, "got pid of %i, expected 4\n", pkey.pid);
104 pkey.fmtid = PKEY_WineTest;
105 pkey.pid = 4;
107 memset(&propvar, 0, sizeof(propvar));
109 if (0)
111 /* Crashes on Windows 7 */
112 hr = IPropertyStoreCache_GetValue(propcache, NULL, &propvar);
113 ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr);
116 hr = IPropertyStoreCache_GetValue(propcache, &pkey, NULL);
117 ok(hr == E_POINTER, "GetValue failed, hr=%x\n", hr);
119 hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar);
120 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
121 ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt);
122 ok(propvar.u.lVal == 12345, "expected 12345, got %d\n", propvar.u.lVal);
124 pkey.fmtid = PKEY_WineTest;
125 pkey.pid = 10;
127 /* Get information for field that isn't set yet */
128 propvar.vt = VT_I2;
129 hr = IPropertyStoreCache_GetValue(propcache, &pkey, &propvar);
130 ok(hr == S_OK, "GetValue failed, hr=%x\n", hr);
131 ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt);
133 state = 0xdeadbeef;
134 hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
135 todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetState failed, hr=%x\n", hr);
136 todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
138 propvar.vt = VT_I2;
139 state = 0xdeadbeef;
140 hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
141 todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "GetValueAndState failed, hr=%x\n", hr);
142 todo_wine ok(propvar.vt == VT_EMPTY, "expected VT_EMPTY, got %d\n", propvar.vt);
143 todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
145 /* Set state on an unset field */
146 hr = IPropertyStoreCache_SetState(propcache, &pkey, PSC_NORMAL);
147 todo_wine ok(hr == TYPE_E_ELEMENTNOTFOUND, "SetState failed, hr=%x\n", hr);
149 /* Manipulate state on already set field */
150 pkey.fmtid = PKEY_WineTest;
151 pkey.pid = 4;
153 state = 0xdeadbeef;
154 hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
155 todo_wine ok(hr == S_OK, "GetState failed, hr=%x\n", hr);
156 todo_wine ok(state == PSC_NORMAL, "expected PSC_NORMAL, got %d\n", state);
158 hr = IPropertyStoreCache_SetState(propcache, &pkey, 10);
159 todo_wine ok(hr == S_OK, "SetState failed, hr=%x\n", hr);
161 state = 0xdeadbeef;
162 hr = IPropertyStoreCache_GetState(propcache, &pkey, &state);
163 todo_wine ok(hr == S_OK, "GetState failed, hr=%x\n", hr);
164 todo_wine ok(state == 10, "expected 10, got %d\n", state);
166 propvar.vt = VT_I4;
167 propvar.u.lVal = 12346;
168 hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, 5);
169 todo_wine ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr);
171 memset(&propvar, 0, sizeof(propvar));
172 state = 0xdeadbeef;
173 hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
174 todo_wine ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr);
175 todo_wine ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt);
176 todo_wine ok(propvar.u.lVal == 12346, "expected 12346, got %d\n", propvar.vt);
177 todo_wine ok(state == 5, "expected 5, got %d\n", state);
179 /* Set new field with state */
180 pkey.fmtid = PKEY_WineTest;
181 pkey.pid = 8;
183 propvar.vt = VT_I4;
184 propvar.u.lVal = 12347;
185 hr = IPropertyStoreCache_SetValueAndState(propcache, &pkey, &propvar, PSC_DIRTY);
186 todo_wine ok(hr == S_OK, "SetValueAndState failed, hr=%x\n", hr);
188 memset(&propvar, 0, sizeof(propvar));
189 state = 0xdeadbeef;
190 hr = IPropertyStoreCache_GetValueAndState(propcache, &pkey, &propvar, &state);
191 todo_wine ok(hr == S_OK, "GetValueAndState failed, hr=%x\n", hr);
192 todo_wine ok(propvar.vt == VT_I4, "expected VT_I4, got %d\n", propvar.vt);
193 todo_wine ok(propvar.u.lVal == 12347, "expected 12347, got %d\n", propvar.vt);
194 todo_wine ok(state == PSC_DIRTY, "expected PSC_DIRTY, got %d\n", state);
196 IPropertyStoreCache_Release(propcache);
199 START_TEST(propstore)
201 CoInitialize(NULL);
203 test_inmemorystore();
205 CoUninitialize();