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 WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
30 #define NONAMELESSUNION
36 #include <wine/test.h>
40 DEFINE_GUID(PKEY_WineTest
, 0x7b317433, 0xdfa3, 0x4c44, 0xad, 0x3e, 0x2f, 0x80, 0x4b, 0x90, 0xdb, 0xf4);
42 static void test_inmemorystore(void)
44 IPropertyStoreCache
*propcache
;
51 hr
= CoCreateInstance(&CLSID_InMemoryPropertyStore
, NULL
, CLSCTX_INPROC_SERVER
,
52 &IID_IPropertyStoreCache
, (void**)&propcache
);
53 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
57 skip("CLSID_InMemoryPropertyStore not supported\n");
61 hr
= IPropertyStoreCache_GetCount(propcache
, NULL
);
62 ok(hr
== E_POINTER
, "GetCount failed, hr=%x\n", hr
);
64 hr
= IPropertyStoreCache_GetCount(propcache
, &count
);
65 ok(hr
== S_OK
, "GetCount failed, hr=%x\n", hr
);
66 ok(count
== 0, "GetCount returned %i, expected 0\n", count
);
68 hr
= IPropertyStoreCache_Commit(propcache
);
69 ok(hr
== S_OK
, "Commit failed, hr=%x\n", hr
);
71 hr
= IPropertyStoreCache_Commit(propcache
);
72 ok(hr
== S_OK
, "Commit failed, hr=%x\n", hr
);
74 hr
= IPropertyStoreCache_GetAt(propcache
, 0, &pkey
);
75 ok(hr
== E_INVALIDARG
, "GetAt failed, hr=%x\n", hr
);
77 pkey
.fmtid
= PKEY_WineTest
;
80 memset(&propvar
, 0, sizeof(propvar
));
82 propvar
.u
.lVal
= 12345;
86 /* Crashes on Windows 7 */
87 hr
= IPropertyStoreCache_SetValue(propcache
, NULL
, &propvar
);
88 ok(hr
== E_POINTER
, "SetValue failed, hr=%x\n", hr
);
90 hr
= IPropertyStoreCache_SetValue(propcache
, &pkey
, NULL
);
91 ok(hr
== E_POINTER
, "SetValue failed, hr=%x\n", hr
);
94 hr
= IPropertyStoreCache_SetValue(propcache
, &pkey
, &propvar
);
95 ok(hr
== S_OK
, "SetValue failed, hr=%x\n", hr
);
97 hr
= IPropertyStoreCache_GetCount(propcache
, &count
);
98 ok(hr
== S_OK
, "GetCount failed, hr=%x\n", hr
);
99 ok(count
== 1, "GetCount returned %i, expected 0\n", count
);
101 memset(&pkey
, 0, sizeof(pkey
));
103 hr
= IPropertyStoreCache_GetAt(propcache
, 0, &pkey
);
104 ok(hr
== S_OK
, "GetAt failed, hr=%x\n", hr
);
105 ok(IsEqualGUID(&pkey
.fmtid
, &PKEY_WineTest
), "got wrong pkey\n");
106 ok(pkey
.pid
== 4, "got pid of %i, expected 4\n", pkey
.pid
);
108 pkey
.fmtid
= PKEY_WineTest
;
111 memset(&propvar
, 0, sizeof(propvar
));
115 /* Crashes on Windows 7 */
116 hr
= IPropertyStoreCache_GetValue(propcache
, NULL
, &propvar
);
117 ok(hr
== E_POINTER
, "GetValue failed, hr=%x\n", hr
);
120 hr
= IPropertyStoreCache_GetValue(propcache
, &pkey
, NULL
);
121 ok(hr
== E_POINTER
, "GetValue failed, hr=%x\n", hr
);
123 hr
= IPropertyStoreCache_GetValue(propcache
, &pkey
, &propvar
);
124 ok(hr
== S_OK
, "GetValue failed, hr=%x\n", hr
);
125 ok(propvar
.vt
== VT_I4
, "expected VT_I4, got %d\n", propvar
.vt
);
126 ok(propvar
.u
.lVal
== 12345, "expected 12345, got %d\n", propvar
.u
.lVal
);
128 pkey
.fmtid
= PKEY_WineTest
;
131 /* Get information for field that isn't set yet */
133 hr
= IPropertyStoreCache_GetValue(propcache
, &pkey
, &propvar
);
134 ok(hr
== S_OK
, "GetValue failed, hr=%x\n", hr
);
135 ok(propvar
.vt
== VT_EMPTY
, "expected VT_EMPTY, got %d\n", propvar
.vt
);
138 hr
= IPropertyStoreCache_GetState(propcache
, &pkey
, &state
);
139 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetState failed, hr=%x\n", hr
);
140 ok(state
== PSC_NORMAL
, "expected PSC_NORMAL, got %d\n", state
);
144 hr
= IPropertyStoreCache_GetValueAndState(propcache
, &pkey
, &propvar
, &state
);
145 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "GetValueAndState failed, hr=%x\n", hr
);
146 ok(propvar
.vt
== VT_EMPTY
, "expected VT_EMPTY, got %d\n", propvar
.vt
);
147 ok(state
== PSC_NORMAL
, "expected PSC_NORMAL, got %d\n", state
);
149 /* Set state on an unset field */
150 hr
= IPropertyStoreCache_SetState(propcache
, &pkey
, PSC_NORMAL
);
151 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "SetState failed, hr=%x\n", hr
);
153 /* Manipulate state on already set field */
154 pkey
.fmtid
= PKEY_WineTest
;
158 hr
= IPropertyStoreCache_GetState(propcache
, &pkey
, &state
);
159 ok(hr
== S_OK
, "GetState failed, hr=%x\n", hr
);
160 ok(state
== PSC_NORMAL
, "expected PSC_NORMAL, got %d\n", state
);
162 hr
= IPropertyStoreCache_SetState(propcache
, &pkey
, 10);
163 ok(hr
== S_OK
, "SetState failed, hr=%x\n", hr
);
166 hr
= IPropertyStoreCache_GetState(propcache
, &pkey
, &state
);
167 ok(hr
== S_OK
, "GetState failed, hr=%x\n", hr
);
168 ok(state
== 10, "expected 10, got %d\n", state
);
171 propvar
.u
.lVal
= 12346;
172 hr
= IPropertyStoreCache_SetValueAndState(propcache
, &pkey
, &propvar
, 5);
173 ok(hr
== S_OK
, "SetValueAndState failed, hr=%x\n", hr
);
175 memset(&propvar
, 0, sizeof(propvar
));
177 hr
= IPropertyStoreCache_GetValueAndState(propcache
, &pkey
, &propvar
, &state
);
178 ok(hr
== S_OK
, "GetValueAndState failed, hr=%x\n", hr
);
179 ok(propvar
.vt
== VT_I4
, "expected VT_I4, got %d\n", propvar
.vt
);
180 ok(propvar
.u
.lVal
== 12346, "expected 12346, got %d\n", propvar
.vt
);
181 ok(state
== 5, "expected 5, got %d\n", state
);
183 /* Set new field with state */
184 pkey
.fmtid
= PKEY_WineTest
;
188 propvar
.u
.lVal
= 12347;
189 hr
= IPropertyStoreCache_SetValueAndState(propcache
, &pkey
, &propvar
, PSC_DIRTY
);
190 ok(hr
== S_OK
, "SetValueAndState failed, hr=%x\n", hr
);
192 memset(&propvar
, 0, sizeof(propvar
));
194 hr
= IPropertyStoreCache_GetValueAndState(propcache
, &pkey
, &propvar
, &state
);
195 ok(hr
== S_OK
, "GetValueAndState failed, hr=%x\n", hr
);
196 ok(propvar
.vt
== VT_I4
, "expected VT_I4, got %d\n", propvar
.vt
);
197 ok(propvar
.u
.lVal
== 12347, "expected 12347, got %d\n", propvar
.vt
);
198 ok(state
== PSC_DIRTY
, "expected PSC_DIRTY, got %d\n", state
);
200 IPropertyStoreCache_Release(propcache
);
203 static void test_persistserialized(void)
205 IPropertyStore
*propstore
;
206 IPersistSerializedPropStorage
*serialized
;
208 SERIALIZEDPROPSTORAGE
*result
;
211 hr
= CoCreateInstance(&CLSID_InMemoryPropertyStore
, NULL
, CLSCTX_INPROC_SERVER
,
212 &IID_IPropertyStore
, (void**)&propstore
);
213 ok(hr
== S_OK
, "CoCreateInstance failed, hr=%x\n", hr
);
215 hr
= IPropertyStore_QueryInterface(propstore
, &IID_IPersistSerializedPropStorage
,
216 (void**)&serialized
);
217 todo_wine
ok(hr
== S_OK
, "QueryInterface failed, hr=%x\n", hr
);
221 skip("IPersistSerializedPropStorage not supported\n");
225 hr
= IPersistSerializedPropStorage_GetPropertyStorage(serialized
, NULL
, &result_size
);
226 ok(hr
== E_POINTER
, "GetPropertyStorage failed, hr=%x\n", hr
);
228 hr
= IPersistSerializedPropStorage_GetPropertyStorage(serialized
, &result
, NULL
);
229 ok(hr
== E_POINTER
, "GetPropertyStorage failed, hr=%x\n", hr
);
231 hr
= IPersistSerializedPropStorage_GetPropertyStorage(serialized
, &result
, &result_size
);
232 ok(hr
== S_OK
, "GetPropertyStorage failed, hr=%x\n", hr
);
236 ok(result_size
== 0, "expected 0 bytes, got %i\n", result_size
);
238 CoTaskMemFree(result
);
241 hr
= IPersistSerializedPropStorage_SetPropertyStorage(serialized
, NULL
, 4);
242 ok(hr
== E_POINTER
, "SetPropertyStorage failed, hr=%x\n", hr
);
244 hr
= IPersistSerializedPropStorage_SetPropertyStorage(serialized
, NULL
, 0);
245 ok(hr
== S_OK
, "SetPropertyStorage failed, hr=%x\n", hr
);
247 hr
= IPropertyStore_GetCount(propstore
, &result_size
);
248 ok(hr
== S_OK
, "GetCount failed, hr=%x\n", hr
);
249 ok(result_size
== 0, "expecting 0, got %d\n", result_size
);
251 IPropertyStore_Release(propstore
);
252 IPersistSerializedPropStorage_Release(serialized
);
255 START_TEST(propstore
)
259 test_inmemorystore();
260 test_persistserialized();