c6d7d3efe9c2f0eac015bf475a175fbdba17f85b
[reactos.git] / modules / rostests / winetests / ole32 / stg_prop.c
1 /* IPropertyStorage unit tests
2 * Copyright 2005 Juan Lang
3 *
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.
8 *
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.
13 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18 #include <stdio.h>
19 #define COBJMACROS
20 #include "objbase.h"
21 #include "wine/test.h"
22 #include "initguid.h"
23
24 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
25 DEFINE_GUID(FMTID_SummaryInformation,0xF29F85E0,0x4FF9,0x1068,0xAB,0x91,0x08,0x00,0x2B,0x27,0xB3,0xD9);
26 DEFINE_GUID(FMTID_DocSummaryInformation,0xD5CDD502,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
27 DEFINE_GUID(FMTID_UserDefinedProperties,0xD5CDD505,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
28
29 #ifndef PID_BEHAVIOR
30 #define PID_BEHAVIOR 0x80000003
31 #endif
32
33 static HRESULT (WINAPI *pFmtIdToPropStgName)(const FMTID *, LPOLESTR);
34 static HRESULT (WINAPI *pPropStgNameToFmtId)(const LPOLESTR, FMTID *);
35 static HRESULT (WINAPI *pStgCreatePropSetStg)(IStorage *, DWORD, IPropertySetStorage **);
36 static HRESULT (WINAPI *pStgCreatePropStg)(IUnknown *, REFFMTID, const CLSID *, DWORD, DWORD, IPropertyStorage **);
37 static HRESULT (WINAPI *pStgOpenPropStg)(IUnknown *, REFFMTID, DWORD, DWORD, IPropertyStorage **);
38
39 static void init_function_pointers(void)
40 {
41 HMODULE hmod = GetModuleHandleA("ole32.dll");
42 pFmtIdToPropStgName = (void*)GetProcAddress(hmod, "FmtIdToPropStgName");
43 pPropStgNameToFmtId = (void*)GetProcAddress(hmod, "PropStgNameToFmtId");
44 pStgCreatePropSetStg = (void*)GetProcAddress(hmod, "StgCreatePropSetStg");
45 pStgCreatePropStg = (void*)GetProcAddress(hmod, "StgCreatePropStg");
46 pStgOpenPropStg = (void*)GetProcAddress(hmod, "StgOpenPropStg");
47 }
48
49 /* FIXME: this creates an ANSI storage, try to find conditions under which
50 * Unicode translation fails
51 */
52 static void testPropsHelper(IPropertySetStorage **propSetStorage)
53 {
54 static const WCHAR szDot[] = { '.',0 };
55 static const WCHAR szPrefix[] = { 's','t','g',0 };
56 static const WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
57 'I','n','f','o','r','m','a','t','i','o','n',0 };
58 static WCHAR propName[] = { 'p','r','o','p',0 };
59 static char val[] = "l33t auth0r";
60 WCHAR filename[MAX_PATH];
61 HRESULT hr;
62 IStorage *storage = NULL;
63 IStream *stream = NULL;
64 IPropertyStorage *propertyStorage = NULL;
65 PROPSPEC spec;
66 PROPVARIANT var;
67 CLIPDATA clipdata;
68 unsigned char clipcontent[] = "foobar";
69 GUID anyOldGuid = { 0x12345678,0xdead,0xbeef, {
70 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } };
71
72 if(propSetStorage)
73 trace("Testing property storage with a set...\n");
74 else
75 trace("Testing property storage without a set...\n");
76
77 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
78 return;
79
80 DeleteFileW(filename);
81
82 hr = StgCreateDocfile(filename,
83 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
84 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
85
86 if(propSetStorage)
87 {
88 if(!pStgCreatePropSetStg)
89 {
90 IStorage_Release(storage);
91 DeleteFileW(filename);
92 return;
93 }
94 hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
95 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
96
97 hr = IPropertySetStorage_Create(*propSetStorage,
98 &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
99 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
100 &propertyStorage);
101 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
102 }
103 else
104 {
105 hr = IStorage_CreateStream(storage, szSummaryInfo,
106 STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
107 ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
108
109 if(!pStgCreatePropStg)
110 {
111 IStorage_Release(storage);
112 IUnknown_Release(stream);
113 DeleteFileW(filename);
114 return;
115 }
116 hr = pStgCreatePropStg((IUnknown *)stream, &FMTID_SummaryInformation,
117 NULL, PROPSETFLAG_ANSI, 0, &propertyStorage);
118 ok(hr == S_OK, "StgCreatePropStg failed: 0x%08x\n", hr);
119 }
120
121 hr = IPropertyStorage_WriteMultiple(propertyStorage, 0, NULL, NULL, 0);
122 ok(hr == S_OK, "WriteMultiple with 0 args failed: 0x%08x\n", hr);
123 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, NULL, NULL, 0);
124 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
125
126 /* test setting one that I can't set */
127 spec.ulKind = PRSPEC_PROPID;
128 U(spec).propid = PID_DICTIONARY;
129 var.vt = VT_I4;
130 U(var).lVal = 1;
131 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
132 ok(hr == STG_E_INVALIDPARAMETER,
133 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
134
135 /* test setting one by name with an invalid propidNameFirst */
136 spec.ulKind = PRSPEC_LPWSTR;
137 U(spec).lpwstr = propName;
138 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
139 PID_DICTIONARY);
140 ok(hr == STG_E_INVALIDPARAMETER,
141 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
142
143 /* test setting behavior (case-sensitive) */
144 spec.ulKind = PRSPEC_PROPID;
145 U(spec).propid = PID_BEHAVIOR;
146 U(var).lVal = 1;
147 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
148 ok(hr == STG_E_INVALIDPARAMETER,
149 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
150
151 /* set one by value.. */
152 spec.ulKind = PRSPEC_PROPID;
153 U(spec).propid = PID_FIRST_USABLE;
154 U(var).lVal = 1;
155 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
156 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
157
158 /* set one by name */
159 spec.ulKind = PRSPEC_LPWSTR;
160 U(spec).lpwstr = propName;
161 U(var).lVal = 2;
162 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
163 PID_FIRST_USABLE);
164 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
165
166 /* set a string value */
167 spec.ulKind = PRSPEC_PROPID;
168 U(spec).propid = PIDSI_AUTHOR;
169 var.vt = VT_LPSTR;
170 U(var).pszVal = val;
171 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
172 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
173
174 /* set a clipboard value */
175 spec.ulKind = PRSPEC_PROPID;
176 U(spec).propid = PIDSI_THUMBNAIL;
177 var.vt = VT_CF;
178 clipdata.cbSize = sizeof clipcontent + sizeof (ULONG);
179 clipdata.ulClipFmt = CF_ENHMETAFILE;
180 clipdata.pClipData = clipcontent;
181 U(var).pclipdata = &clipdata;
182 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
183 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
184
185
186 /* check reading */
187 hr = IPropertyStorage_ReadMultiple(propertyStorage, 0, NULL, NULL);
188 ok(hr == S_FALSE, "ReadMultiple with 0 args failed: 0x%08x\n", hr);
189 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, NULL, NULL);
190 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
191 /* read by propid */
192 spec.ulKind = PRSPEC_PROPID;
193 U(spec).propid = PID_FIRST_USABLE;
194 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
195 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
196 ok(var.vt == VT_I4 && U(var).lVal == 1,
197 "Didn't get expected type or value for property (got type %d, value %d)\n",
198 var.vt, U(var).lVal);
199 /* read by name */
200 spec.ulKind = PRSPEC_LPWSTR;
201 U(spec).lpwstr = propName;
202 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
203 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
204 ok(var.vt == VT_I4 && U(var).lVal == 2,
205 "Didn't get expected type or value for property (got type %d, value %d)\n",
206 var.vt, U(var).lVal);
207 /* read string value */
208 spec.ulKind = PRSPEC_PROPID;
209 U(spec).propid = PIDSI_AUTHOR;
210 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
211 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
212 ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
213 "Didn't get expected type or value for property (got type %d, value %s)\n",
214 var.vt, U(var).pszVal);
215 PropVariantClear(&var);
216
217 /* read clipboard format */
218 spec.ulKind = PRSPEC_PROPID;
219 U(spec).propid = PIDSI_THUMBNAIL;
220 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
221 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
222 ok(var.vt == VT_CF, "variant type wrong\n");
223 ok(U(var).pclipdata->ulClipFmt == CF_ENHMETAFILE,
224 "clipboard type wrong\n");
225 ok(U(var).pclipdata->cbSize == sizeof clipcontent + sizeof (ULONG),
226 "clipboard size wrong\n");
227 ok(!memcmp(U(var).pclipdata->pClipData, clipcontent, sizeof clipcontent),
228 "clipboard contents wrong\n");
229 ok(S_OK == PropVariantClear(&var), "failed to clear variant\n");
230
231 /* check deleting */
232 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 0, NULL);
233 ok(hr == S_OK, "DeleteMultiple with 0 args failed: 0x%08x\n", hr);
234 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, NULL);
235 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
236 /* contrary to what the docs say, you can't delete the dictionary */
237 spec.ulKind = PRSPEC_PROPID;
238 U(spec).propid = PID_DICTIONARY;
239 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
240 ok(hr == STG_E_INVALIDPARAMETER,
241 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
242 /* now delete the first value.. */
243 U(spec).propid = PID_FIRST_USABLE;
244 hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
245 ok(hr == S_OK, "DeleteMultiple failed: 0x%08x\n", hr);
246 /* and check that it's no longer readable */
247 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
248 ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
249
250 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
251 ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
252
253 /* check reverting */
254 spec.ulKind = PRSPEC_PROPID;
255 U(spec).propid = PID_FIRST_USABLE;
256 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
257 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
258 hr = IPropertyStorage_Revert(propertyStorage);
259 ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
260 /* now check that it's still not there */
261 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
262 ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
263 /* set an integer value again */
264 spec.ulKind = PRSPEC_PROPID;
265 U(spec).propid = PID_FIRST_USABLE;
266 var.vt = VT_I4;
267 U(var).lVal = 1;
268 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
269 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
270 /* commit it */
271 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
272 ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
273 /* set it to a string value */
274 var.vt = VT_LPSTR;
275 U(var).pszVal = val;
276 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
277 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
278 /* revert it */
279 hr = IPropertyStorage_Revert(propertyStorage);
280 ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
281 /* Oddly enough, there's no guarantee that a successful revert actually
282 * implies the value wasn't saved. Maybe transactional mode needs to be
283 * used for that?
284 */
285
286 IPropertyStorage_Release(propertyStorage);
287 if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
288 IStorage_Release(storage);
289 if(stream) IUnknown_Release(stream);
290
291 /* now open it again */
292 hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
293 NULL, 0, &storage);
294 ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);
295
296 if(propSetStorage)
297 {
298 hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
299 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
300
301 hr = IPropertySetStorage_Open(*propSetStorage, &FMTID_SummaryInformation,
302 STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
303 ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
304 }
305 else
306 {
307 hr = IStorage_OpenStream(storage, szSummaryInfo,
308 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
309 ok(hr == S_OK, "IStorage_OpenStream failed: 0x%08x\n", hr);
310
311 if(!pStgOpenPropStg)
312 {
313 IStorage_Release(storage);
314 IUnknown_Release(stream);
315 DeleteFileW(filename);
316 return;
317 }
318 hr = pStgOpenPropStg((IUnknown *)stream, &FMTID_SummaryInformation,
319 PROPSETFLAG_DEFAULT, 0, &propertyStorage);
320 ok(hr == S_OK, "StgOpenPropStg failed: 0x%08x\n", hr);
321 }
322
323 /* check properties again */
324 spec.ulKind = PRSPEC_LPWSTR;
325 U(spec).lpwstr = propName;
326 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
327 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
328 ok(var.vt == VT_I4 && U(var).lVal == 2,
329 "Didn't get expected type or value for property (got type %d, value %d)\n",
330 var.vt, U(var).lVal);
331 spec.ulKind = PRSPEC_PROPID;
332 U(spec).propid = PIDSI_AUTHOR;
333 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
334 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
335 ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
336 "Didn't get expected type or value for property (got type %d, value %s)\n",
337 var.vt, U(var).pszVal);
338 PropVariantClear(&var);
339
340 IPropertyStorage_Release(propertyStorage);
341 if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
342 IStorage_Release(storage);
343 if(stream) IUnknown_Release(stream);
344
345 DeleteFileW(filename);
346
347 /* Test creating a property set storage with a random GUID */
348 hr = StgCreateDocfile(filename,
349 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
350 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
351
352 if(propSetStorage)
353 {
354 hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
355 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
356
357 hr = IPropertySetStorage_Create(*propSetStorage,
358 &anyOldGuid, NULL, PROPSETFLAG_ANSI,
359 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
360 &propertyStorage);
361 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
362 }
363 else
364 {
365 hr = IStorage_CreateStream(storage, szSummaryInfo,
366 STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
367 ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
368
369 hr = pStgCreatePropStg((IUnknown *)stream, &anyOldGuid, NULL,
370 PROPSETFLAG_DEFAULT, 0, &propertyStorage);
371 ok(hr == S_OK, "StgCreatePropStg failed: 0x%08x\n", hr);
372 }
373
374 spec.ulKind = PRSPEC_PROPID;
375 U(spec).propid = PID_FIRST_USABLE;
376 var.vt = VT_I4;
377 U(var).lVal = 1;
378 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
379 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
380
381 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
382 ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
383
384 IPropertyStorage_Release(propertyStorage);
385 if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
386 IStorage_Release(storage);
387 if(stream) IUnknown_Release(stream);
388
389 /* now open it again */
390 hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
391 NULL, 0, &storage);
392 ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);
393
394 if(propSetStorage)
395 {
396 hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
397 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
398
399 hr = IPropertySetStorage_Open(*propSetStorage, &anyOldGuid,
400 STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
401 ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
402 }
403 else
404 {
405 hr = IStorage_OpenStream(storage, szSummaryInfo,
406 0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
407 ok(hr == S_OK, "IStorage_OpenStream failed: 0x%08x\n", hr);
408
409 hr = pStgOpenPropStg((IUnknown *)stream, &anyOldGuid,
410 PROPSETFLAG_DEFAULT, 0, &propertyStorage);
411 ok(hr == S_OK, "StgOpenPropStg failed: 0x%08x\n", hr);
412 }
413
414 spec.ulKind = PRSPEC_PROPID;
415 U(spec).propid = PID_FIRST_USABLE;
416 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
417 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
418
419 ok(var.vt == VT_I4 && U(var).lVal == 1,
420 "Didn't get expected type or value for property (got type %d, value %d)\n",
421 var.vt, U(var).lVal);
422
423 IPropertyStorage_Release(propertyStorage);
424 if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
425 IStorage_Release(storage);
426 if(stream) IUnknown_Release(stream);
427
428 DeleteFileW(filename);
429 }
430
431 static void testProps(void)
432 {
433 IPropertySetStorage *propSetStorage = NULL;
434
435 testPropsHelper(&propSetStorage);
436 testPropsHelper(NULL);
437 }
438
439 static void testCodepage(void)
440 {
441 static const WCHAR szDot[] = { '.',0 };
442 static const WCHAR szPrefix[] = { 's','t','g',0 };
443 static CHAR aval[] = "hi";
444 static WCHAR wval[] = { 'h','i',0 };
445 HRESULT hr;
446 IStorage *storage = NULL;
447 IPropertySetStorage *propSetStorage = NULL;
448 IPropertyStorage *propertyStorage = NULL;
449 PROPSPEC spec;
450 PROPVARIANT var;
451 WCHAR fileName[MAX_PATH];
452
453 if(!GetTempFileNameW(szDot, szPrefix, 0, fileName))
454 return;
455
456 hr = StgCreateDocfile(fileName,
457 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
458 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
459
460 if(!pStgCreatePropSetStg)
461 {
462 IStorage_Release(storage);
463 DeleteFileW(fileName);
464 return;
465 }
466 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
467 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
468
469 hr = IPropertySetStorage_Create(propSetStorage,
470 &FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT,
471 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
472 &propertyStorage);
473 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
474
475 PropVariantInit(&var);
476 spec.ulKind = PRSPEC_PROPID;
477 U(spec).propid = PID_CODEPAGE;
478 /* check code page before it's been explicitly set */
479 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
480 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
481 ok(var.vt == VT_I2 && U(var).iVal == 1200,
482 "Didn't get expected type or value for property\n");
483 /* Set the code page to ascii */
484 var.vt = VT_I2;
485 U(var).iVal = 1252;
486 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
487 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
488 /* check code page */
489 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
490 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
491 ok(var.vt == VT_I2 && U(var).iVal == 1252,
492 "Didn't get expected type or value for property\n");
493 /* Set code page to Unicode */
494 U(var).iVal = 1200;
495 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
496 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
497 /* check code page */
498 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
499 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
500 ok(var.vt == VT_I2 && U(var).iVal == 1200,
501 "Didn't get expected type or value for property\n");
502 /* Set a string value */
503 spec.ulKind = PRSPEC_PROPID;
504 U(spec).propid = PID_FIRST_USABLE;
505 var.vt = VT_LPSTR;
506 U(var).pszVal = aval;
507 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
508 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
509 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
510 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
511 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "hi"),
512 "Didn't get expected type or value for property\n");
513 PropVariantClear(&var);
514 /* This seemingly non-sensical test is to show that the string is indeed
515 * interpreted according to the current system code page, not according to
516 * the property set's code page. (If the latter were true, the whole
517 * string would be maintained. As it is, only the first character is.)
518 */
519 var.vt = VT_LPSTR;
520 U(var).pszVal = (LPSTR)wval;
521 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
522 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
523 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
524 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
525 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "h"),
526 "Didn't get expected type or value for property\n");
527 PropVariantClear(&var);
528
529 /* now that a property's been set, you can't change the code page */
530 spec.ulKind = PRSPEC_PROPID;
531 U(spec).propid = PID_CODEPAGE;
532 var.vt = VT_I2;
533 U(var).iVal = 1200;
534 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
535 ok(hr == STG_E_INVALIDPARAMETER,
536 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
537
538 IPropertyStorage_Release(propertyStorage);
539 IPropertySetStorage_Release(propSetStorage);
540 IStorage_Release(storage);
541
542 DeleteFileW(fileName);
543
544 /* same tests, but with PROPSETFLAG_ANSI */
545 hr = StgCreateDocfile(fileName,
546 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
547 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
548
549 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
550 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
551
552 hr = IPropertySetStorage_Create(propSetStorage,
553 &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
554 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
555 &propertyStorage);
556 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
557
558 /* check code page before it's been explicitly set */
559 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
560 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
561 ok(var.vt == VT_I2, "Didn't get expected type for property (%u)\n", var.vt);
562 /* Set code page to Unicode */
563 U(var).iVal = 1200;
564 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
565 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
566 /* check code page */
567 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
568 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
569 ok(var.vt == VT_I2 && U(var).iVal == 1200,
570 "Didn't get expected type or value for property\n");
571 /* This test is commented out for documentation. It fails under Wine,
572 * and I expect it would under Windows as well, yet it succeeds. There's
573 * obviously something about string conversion I don't understand.
574 */
575 if(0) {
576 static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 };
577 /* Set code page to 950 (Traditional Chinese) */
578 U(var).iVal = 950;
579 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
580 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
581 /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
582 * Chinese.
583 */
584 spec.ulKind = PRSPEC_PROPID;
585 U(spec).propid = PID_FIRST_USABLE;
586 var.vt = VT_LPSTR;
587 U(var).pszVal = (LPSTR)strVal;
588 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
589 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
590 /* Check returned string */
591 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
592 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
593 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal),
594 "Didn't get expected type or value for property\n");
595 }
596
597 IPropertyStorage_Release(propertyStorage);
598 IPropertySetStorage_Release(propSetStorage);
599 IStorage_Release(storage);
600
601 DeleteFileW(fileName);
602 }
603
604 static void testFmtId(void)
605 {
606 WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
607 'I','n','f','o','r','m','a','t','i','o','n',0 };
608 WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
609 'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
610 0 };
611 WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
612 'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
613 'c',0 };
614 WCHAR name[32];
615 FMTID fmtid;
616 HRESULT hr;
617
618 if (pFmtIdToPropStgName) {
619 hr = pFmtIdToPropStgName(NULL, name);
620 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
621 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
622 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
623 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
624 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
625 ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
626 sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
627 hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
628 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
629 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
630 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
631 hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
632 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
633 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
634 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
635 hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
636 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
637 ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
638 sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
639 }
640
641 if(pPropStgNameToFmtId) {
642 /* test args first */
643 hr = pPropStgNameToFmtId(NULL, NULL);
644 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
645 hr = pPropStgNameToFmtId(NULL, &fmtid);
646 ok(hr == STG_E_INVALIDNAME, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
647 hr);
648 hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
649 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
650 /* test the known format IDs */
651 hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
652 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
653 ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
654 "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
655 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
656 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
657 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
658 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
659 /* test another GUID */
660 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
661 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
662 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
663 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
664 /* now check case matching */
665 CharUpperW(szDocSummaryInfo + 1);
666 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
667 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
668 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
669 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
670 CharUpperW(szIID_IPropSetStg + 1);
671 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
672 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
673 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
674 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
675 }
676 }
677
678 START_TEST(stg_prop)
679 {
680 init_function_pointers();
681 testProps();
682 testCodepage();
683 testFmtId();
684 }