Make ole32 tests loadable on NT4.
[wine/multimedia.git] / dlls / ole32 / tests / stg_prop.c
blobe309093f933eb27450407b87e8f8e7bf8eb13d48
1 /* IPropertyStorage unit tests
2 * Copyright 2005 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include <stdio.h>
19 #define COBJMACROS
20 #include "objbase.h"
21 #include "wine/test.h"
23 #ifdef NONAMELESSUNION
24 # define U(x) (x).u
25 #else
26 # define U(x) (x)
27 #endif
29 static HRESULT (WINAPI *pFmtIdToPropStgName)(const FMTID *, LPOLESTR);
30 static HRESULT (WINAPI *pPropStgNameToFmtId)(const LPOLESTR, FMTID *);
31 static HRESULT (WINAPI *pStgCreatePropSetStg)(IStorage *, DWORD, IPropertySetStorage **);
33 static void init_function_pointers(void)
35 HMODULE hmod = GetModuleHandleA("ole32.dll");
37 if(hmod)
39 pFmtIdToPropStgName = (void*)GetProcAddress(hmod, "FmtIdToPropStgName");
40 pPropStgNameToFmtId = (void*)GetProcAddress(hmod, "PropStgNameToFmtId");
41 pStgCreatePropSetStg = (void*)GetProcAddress(hmod, "StgCreatePropSetStg");
44 /* FIXME: this creates an ANSI storage, try to find conditions under which
45 * Unicode translation fails
47 static void testProps(void)
49 static const WCHAR szDot[] = { '.',0 };
50 static const WCHAR szPrefix[] = { 's','t','g',0 };
51 static const WCHAR propName[] = { 'p','r','o','p',0 };
52 static const char val[] = "l33t auth0r";
53 WCHAR filename[MAX_PATH];
54 HRESULT hr;
55 IStorage *storage = NULL;
56 IPropertySetStorage *propSetStorage = NULL;
57 IPropertyStorage *propertyStorage = NULL;
58 PROPSPEC spec;
59 PROPVARIANT var;
61 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
62 return;
64 DeleteFileW(filename);
66 hr = StgCreateDocfile(filename,
67 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
68 ok(SUCCEEDED(hr), "StgCreateDocfile failed: 0x%08lx\n", hr);
70 if(!pStgCreatePropSetStg) return;
71 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
72 ok(SUCCEEDED(hr), "StgCreatePropSetStg failed: 0x%08lx\n", hr);
74 hr = IPropertySetStorage_Create(propSetStorage,
75 &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
76 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
77 &propertyStorage);
78 ok(SUCCEEDED(hr), "IPropertySetStorage_Create failed: 0x%08lx\n", hr);
80 hr = IPropertyStorage_WriteMultiple(propertyStorage, 0, NULL, NULL, 0);
81 ok(SUCCEEDED(hr), "WriteMultiple with 0 args failed: 0x%08lx\n", hr);
82 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, NULL, NULL, 0);
83 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
85 /* test setting one that I can't set */
86 spec.ulKind = PRSPEC_PROPID;
87 U(spec).propid = PID_DICTIONARY;
88 PropVariantClear(&var);
89 var.vt = VT_I4;
90 U(var).lVal = 1;
91 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
92 ok(hr == STG_E_INVALIDPARAMETER,
93 "Expected STG_E_INVALIDPARAMETER, got 0x%08lx\n", hr);
95 /* test setting one by name with an invalid propidNameFirst */
96 spec.ulKind = PRSPEC_LPWSTR;
97 U(spec).lpwstr = (LPOLESTR)propName;
98 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
99 PID_DICTIONARY);
100 ok(hr == STG_E_INVALIDPARAMETER,
101 "Expected STG_E_INVALIDPARAMETER, got 0x%08lx\n", hr);
103 /* test setting behavior (case-sensitive) */
104 spec.ulKind = PRSPEC_PROPID;
105 U(spec).propid = PID_BEHAVIOR;
106 U(var).lVal = 1;
107 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
108 ok(hr == STG_E_INVALIDPARAMETER,
109 "Expected STG_E_INVALIDPARAMETER, got 0x%08lx\n", hr);
111 /* set one by value.. */
112 spec.ulKind = PRSPEC_PROPID;
113 U(spec).propid = PID_FIRST_USABLE;
114 U(var).lVal = 1;
115 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
116 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
118 /* set one by name */
119 spec.ulKind = PRSPEC_LPWSTR;
120 U(spec).lpwstr = (LPOLESTR)propName;
121 U(var).lVal = 2;
122 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
123 PID_FIRST_USABLE);
124 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
126 /* set a string value */
127 spec.ulKind = PRSPEC_PROPID;
128 U(spec).propid = PIDSI_AUTHOR;
129 var.vt = VT_LPSTR;
130 U(var).pszVal = (LPSTR)val;
131 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
132 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
134 /* check reading */
135 hr = IPropertyStorage_ReadMultiple(propertyStorage, 0, NULL, NULL);
136 ok(SUCCEEDED(hr), "ReadMultiple with 0 args failed: 0x%08lx\n", hr);
137 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, NULL, NULL);
138 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
139 /* read by propid */
140 spec.ulKind = PRSPEC_PROPID;
141 U(spec).propid = PID_FIRST_USABLE;
142 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
143 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
144 ok(var.vt == VT_I4 && U(var).lVal == 1,
145 "Didn't get expected type or value for property (got type %d, value %ld)\n",
146 var.vt, U(var).lVal);
147 /* read by name */
148 spec.ulKind = PRSPEC_LPWSTR;
149 U(spec).lpwstr = (LPOLESTR)propName;
150 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
151 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
152 ok(var.vt == VT_I4 && U(var).lVal == 2,
153 "Didn't get expected type or value for property (got type %d, value %ld)\n",
154 var.vt, U(var).lVal);
155 /* read string value */
156 spec.ulKind = PRSPEC_PROPID;
157 U(spec).propid = PIDSI_AUTHOR;
158 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
159 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
160 ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
161 "Didn't get expected type or value for property (got type %d, value %s)\n",
162 var.vt, U(var).pszVal);
164 /* check deleting */
165 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 0, NULL);
166 ok(SUCCEEDED(hr), "DeleteMultiple with 0 args failed: 0x%08lx\n", hr);
167 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, NULL);
168 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
169 /* contrary to what the docs say, you can't delete the dictionary */
170 spec.ulKind = PRSPEC_PROPID;
171 U(spec).propid = PID_DICTIONARY;
172 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
173 ok(hr == STG_E_INVALIDPARAMETER,
174 "Expected STG_E_INVALIDPARAMETER, got 0x%08lx\n", hr);
175 /* now delete the first value.. */
176 U(spec).propid = PID_FIRST_USABLE;
177 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
178 ok(SUCCEEDED(hr), "DeleteMultiple failed: 0x%08lx\n", hr);
179 /* and check that it's no longer readable */
180 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
181 ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08lx\n", hr);
183 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
184 ok(SUCCEEDED(hr), "Commit failed: 0x%08lx\n", hr);
186 /* check reverting */
187 spec.ulKind = PRSPEC_PROPID;
188 U(spec).propid = PID_FIRST_USABLE;
189 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
190 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
191 hr = IPropertyStorage_Revert(propertyStorage);
192 ok(SUCCEEDED(hr), "Revert failed: 0x%08lx\n", hr);
193 /* now check that it's still not there */
194 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
195 ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08lx\n", hr);
196 /* set an integer value again */
197 spec.ulKind = PRSPEC_PROPID;
198 U(spec).propid = PID_FIRST_USABLE;
199 var.vt = VT_I4;
200 U(var).lVal = 1;
201 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
202 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
203 /* commit it */
204 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
205 ok(SUCCEEDED(hr), "Commit failed: 0x%08lx\n", hr);
206 /* set it to a string value */
207 var.vt = VT_LPSTR;
208 U(var).pszVal = (LPSTR)val;
209 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
210 ok(SUCCEEDED(hr), "WriteMultiple failed: 0x%08lx\n", hr);
211 /* revert it */
212 hr = IPropertyStorage_Revert(propertyStorage);
213 ok(SUCCEEDED(hr), "Revert failed: 0x%08lx\n", hr);
214 /* and make sure it's still an integer */
215 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
216 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
217 ok(var.vt == VT_I4 && U(var).lVal == 1,
218 "Didn't get expected type or value for property (got type %d, value %ld)\n",
219 var.vt, U(var).lVal);
221 IPropertyStorage_Release(propertyStorage);
222 propertyStorage = NULL;
223 IPropertySetStorage_Release(propSetStorage);
224 propSetStorage = NULL;
225 IStorage_Release(storage);
226 storage = NULL;
228 /* now open it again */
229 hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
230 NULL, 0, &storage);
231 ok(SUCCEEDED(hr), "StgOpenStorage failed: 0x%08lx\n", hr);
233 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
234 ok(SUCCEEDED(hr), "StgCreatePropSetStg failed: 0x%08lx\n", hr);
236 hr = IPropertySetStorage_Open(propSetStorage, &FMTID_SummaryInformation,
237 STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
238 ok(SUCCEEDED(hr), "IPropertySetStorage_Open failed: 0x%08lx\n", hr);
240 /* check properties again */
241 spec.ulKind = PRSPEC_LPWSTR;
242 U(spec).lpwstr = (LPOLESTR)propName;
243 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
244 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
245 ok(var.vt == VT_I4 && U(var).lVal == 2,
246 "Didn't get expected type or value for property (got type %d, value %ld)\n",
247 var.vt, U(var).lVal);
248 spec.ulKind = PRSPEC_PROPID;
249 U(spec).propid = PIDSI_AUTHOR;
250 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
251 ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08lx\n", hr);
252 ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
253 "Didn't get expected type or value for property (got type %d, value %s)\n",
254 var.vt, U(var).pszVal);
256 IPropertyStorage_Release(propertyStorage);
257 IPropertySetStorage_Release(propSetStorage);
258 IStorage_Release(storage);
260 DeleteFileW(filename);
263 static void testFmtId(void)
265 WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
266 'I','n','f','o','r','m','a','t','i','o','n',0 };
267 WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
268 'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
269 0 };
270 WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
271 'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
272 'c',0 };
273 WCHAR name[32];
274 FMTID fmtid;
275 HRESULT hr;
277 if (pFmtIdToPropStgName) {
278 hr = pFmtIdToPropStgName(NULL, name);
279 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
280 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
281 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
282 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
283 ok(SUCCEEDED(hr), "FmtIdToPropStgName failed: 0x%08lx\n", hr);
284 ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
285 sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
286 hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
287 ok(SUCCEEDED(hr), "FmtIdToPropStgName failed: 0x%08lx\n", hr);
288 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
289 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
290 hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
291 ok(SUCCEEDED(hr), "FmtIdToPropStgName failed: 0x%08lx\n", hr);
292 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
293 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
294 hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
295 ok(SUCCEEDED(hr), "FmtIdToPropStgName failed: 0x%08lx\n", hr);
296 ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
297 sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
300 if(pPropStgNameToFmtId) {
301 /* test args first */
302 hr = pPropStgNameToFmtId(NULL, NULL);
303 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
304 hr = pPropStgNameToFmtId(NULL, &fmtid);
305 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
306 hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
307 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08lx\n", hr);
308 /* test the known format IDs */
309 hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
310 ok(SUCCEEDED(hr), "PropStgNameToFmtId failed: 0x%08lx\n", hr);
311 ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
312 "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
313 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
314 ok(SUCCEEDED(hr), "PropStgNameToFmtId failed: 0x%08lx\n", hr);
315 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
316 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
317 /* test another GUID */
318 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
319 ok(SUCCEEDED(hr), "PropStgNameToFmtId failed: 0x%08lx\n", hr);
320 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
321 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
322 /* now check case matching */
323 CharUpperW(szDocSummaryInfo + 1);
324 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
325 ok(SUCCEEDED(hr), "PropStgNameToFmtId failed: 0x%08lx\n", hr);
326 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
327 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
328 CharUpperW(szIID_IPropSetStg + 1);
329 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
330 ok(SUCCEEDED(hr), "PropStgNameToFmtId failed: 0x%08lx\n", hr);
331 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
332 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
336 START_TEST(stg_prop)
338 init_function_pointers();
339 testProps();
340 testFmtId();