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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
22 DEFINE_GUID(FMTID_SummaryInformation
,0xF29F85E0,0x4FF9,0x1068,0xAB,0x91,0x08,0x00,0x2B,0x27,0xB3,0xD9);
23 DEFINE_GUID(FMTID_DocSummaryInformation
,0xD5CDD502,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
24 DEFINE_GUID(FMTID_UserDefinedProperties
,0xD5CDD505,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
27 #define PID_BEHAVIOR 0x80000003
30 static HRESULT (WINAPI
*pFmtIdToPropStgName
)(const FMTID
*, LPOLESTR
);
31 static HRESULT (WINAPI
*pPropStgNameToFmtId
)(const LPOLESTR
, FMTID
*);
32 static HRESULT (WINAPI
*pStgCreatePropSetStg
)(IStorage
*, DWORD
, IPropertySetStorage
**);
33 static HRESULT (WINAPI
*pStgCreatePropStg
)(IUnknown
*, REFFMTID
, const CLSID
*, DWORD
, DWORD
, IPropertyStorage
**);
34 static HRESULT (WINAPI
*pStgOpenPropStg
)(IUnknown
*, REFFMTID
, DWORD
, DWORD
, IPropertyStorage
**);
36 static void init_function_pointers(void)
38 HMODULE hmod
= GetModuleHandleA("ole32.dll");
39 pFmtIdToPropStgName
= (void*)GetProcAddress(hmod
, "FmtIdToPropStgName");
40 pPropStgNameToFmtId
= (void*)GetProcAddress(hmod
, "PropStgNameToFmtId");
41 pStgCreatePropSetStg
= (void*)GetProcAddress(hmod
, "StgCreatePropSetStg");
42 pStgCreatePropStg
= (void*)GetProcAddress(hmod
, "StgCreatePropStg");
43 pStgOpenPropStg
= (void*)GetProcAddress(hmod
, "StgOpenPropStg");
46 /* FIXME: this creates an ANSI storage, try to find conditions under which
47 * Unicode translation fails
49 static void testPropsHelper(IPropertySetStorage
**propSetStorage
)
51 static const WCHAR szDot
[] = { '.',0 };
52 static const WCHAR szPrefix
[] = { 's','t','g',0 };
53 static const WCHAR szSummaryInfo
[] = { 5,'S','u','m','m','a','r','y',
54 'I','n','f','o','r','m','a','t','i','o','n',0 };
55 static WCHAR propName
[] = { 'p','r','o','p',0 };
56 static char val
[] = "l33t auth0r";
57 WCHAR filename
[MAX_PATH
];
59 IStorage
*storage
= NULL
;
60 IStream
*stream
= NULL
;
61 IPropertyStorage
*propertyStorage
= NULL
;
65 unsigned char clipcontent
[] = "foobar";
66 GUID anyOldGuid
= { 0x12345678,0xdead,0xbeef, {
67 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } };
70 trace("Testing property storage with a set...\n");
72 trace("Testing property storage without a set...\n");
74 if(!GetTempFileNameW(szDot
, szPrefix
, 0, filename
))
77 DeleteFileW(filename
);
79 hr
= StgCreateDocfile(filename
,
80 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
81 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
85 if(!pStgCreatePropSetStg
)
87 IStorage_Release(storage
);
88 DeleteFileW(filename
);
91 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
92 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
94 hr
= IPropertySetStorage_Create(*propSetStorage
,
95 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
96 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
98 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
102 hr
= IStorage_CreateStream(storage
, szSummaryInfo
,
103 STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stream
);
104 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
106 if(!pStgCreatePropStg
)
108 IStorage_Release(storage
);
109 IUnknown_Release(stream
);
110 DeleteFileW(filename
);
113 hr
= pStgCreatePropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
114 NULL
, PROPSETFLAG_ANSI
, 0, &propertyStorage
);
115 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
118 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 0, NULL
, NULL
, 0);
119 ok(hr
== S_OK
, "WriteMultiple with 0 args failed: 0x%08x\n", hr
);
120 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, NULL
, NULL
, 0);
121 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
123 /* test setting one that I can't set */
124 spec
.ulKind
= PRSPEC_PROPID
;
125 U(spec
).propid
= PID_DICTIONARY
;
128 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
129 ok(hr
== STG_E_INVALIDPARAMETER
,
130 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
132 /* test setting one by name with an invalid propidNameFirst */
133 spec
.ulKind
= PRSPEC_LPWSTR
;
134 U(spec
).lpwstr
= propName
;
135 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
,
137 ok(hr
== STG_E_INVALIDPARAMETER
,
138 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
140 /* test setting behavior (case-sensitive) */
141 spec
.ulKind
= PRSPEC_PROPID
;
142 U(spec
).propid
= PID_BEHAVIOR
;
144 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
145 ok(hr
== STG_E_INVALIDPARAMETER
,
146 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
148 /* set one by value.. */
149 spec
.ulKind
= PRSPEC_PROPID
;
150 U(spec
).propid
= PID_FIRST_USABLE
;
152 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
153 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
155 /* set one by name */
156 spec
.ulKind
= PRSPEC_LPWSTR
;
157 U(spec
).lpwstr
= propName
;
159 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
,
161 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
163 /* set a string value */
164 spec
.ulKind
= PRSPEC_PROPID
;
165 U(spec
).propid
= PIDSI_AUTHOR
;
168 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
169 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
171 /* set a clipboard value */
172 spec
.ulKind
= PRSPEC_PROPID
;
173 U(spec
).propid
= PIDSI_THUMBNAIL
;
175 clipdata
.cbSize
= sizeof clipcontent
+ sizeof (ULONG
);
176 clipdata
.ulClipFmt
= CF_ENHMETAFILE
;
177 clipdata
.pClipData
= clipcontent
;
178 U(var
).pclipdata
= &clipdata
;
179 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
180 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
184 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 0, NULL
, NULL
);
185 ok(hr
== S_FALSE
, "ReadMultiple with 0 args failed: 0x%08x\n", hr
);
186 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, NULL
, NULL
);
187 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
189 spec
.ulKind
= PRSPEC_PROPID
;
190 U(spec
).propid
= PID_FIRST_USABLE
;
191 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
192 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
193 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 1,
194 "Didn't get expected type or value for property (got type %d, value %d)\n",
195 var
.vt
, U(var
).lVal
);
197 spec
.ulKind
= PRSPEC_LPWSTR
;
198 U(spec
).lpwstr
= propName
;
199 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
200 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
201 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 2,
202 "Didn't get expected type or value for property (got type %d, value %d)\n",
203 var
.vt
, U(var
).lVal
);
204 /* read string value */
205 spec
.ulKind
= PRSPEC_PROPID
;
206 U(spec
).propid
= PIDSI_AUTHOR
;
207 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
208 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
209 ok(var
.vt
== VT_LPSTR
&& !lstrcmpA(U(var
).pszVal
, val
),
210 "Didn't get expected type or value for property (got type %d, value %s)\n",
211 var
.vt
, U(var
).pszVal
);
212 PropVariantClear(&var
);
214 /* read clipboard format */
215 spec
.ulKind
= PRSPEC_PROPID
;
216 U(spec
).propid
= PIDSI_THUMBNAIL
;
217 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
218 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
219 ok(var
.vt
== VT_CF
, "variant type wrong\n");
220 ok(U(var
).pclipdata
->ulClipFmt
== CF_ENHMETAFILE
,
221 "clipboard type wrong\n");
222 ok(U(var
).pclipdata
->cbSize
== sizeof clipcontent
+ sizeof (ULONG
),
223 "clipboard size wrong\n");
224 ok(!memcmp(U(var
).pclipdata
->pClipData
, clipcontent
, sizeof clipcontent
),
225 "clipboard contents wrong\n");
226 ok(S_OK
== PropVariantClear(&var
), "failed to clear variant\n");
229 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 0, NULL
);
230 ok(hr
== S_OK
, "DeleteMultiple with 0 args failed: 0x%08x\n", hr
);
231 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, NULL
);
232 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
233 /* contrary to what the docs say, you can't delete the dictionary */
234 spec
.ulKind
= PRSPEC_PROPID
;
235 U(spec
).propid
= PID_DICTIONARY
;
236 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, &spec
);
237 ok(hr
== STG_E_INVALIDPARAMETER
,
238 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
239 /* now delete the first value.. */
240 U(spec
).propid
= PID_FIRST_USABLE
;
241 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, &spec
);
242 ok(hr
== S_OK
, "DeleteMultiple failed: 0x%08x\n", hr
);
243 /* and check that it's no longer readable */
244 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
245 ok(hr
== S_FALSE
, "Expected S_FALSE, got 0x%08x\n", hr
);
247 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
248 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
250 /* check reverting */
251 spec
.ulKind
= PRSPEC_PROPID
;
252 U(spec
).propid
= PID_FIRST_USABLE
;
253 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
254 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
255 hr
= IPropertyStorage_Revert(propertyStorage
);
256 ok(hr
== S_OK
, "Revert failed: 0x%08x\n", hr
);
257 /* now check that it's still not there */
258 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
259 ok(hr
== S_FALSE
, "Expected S_FALSE, got 0x%08x\n", hr
);
260 /* set an integer value again */
261 spec
.ulKind
= PRSPEC_PROPID
;
262 U(spec
).propid
= PID_FIRST_USABLE
;
265 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
266 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
268 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
269 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
270 /* set it to a string value */
273 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
274 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
276 hr
= IPropertyStorage_Revert(propertyStorage
);
277 ok(hr
== S_OK
, "Revert failed: 0x%08x\n", hr
);
278 /* Oddly enough, there's no guarantee that a successful revert actually
279 * implies the value wasn't saved. Maybe transactional mode needs to be
283 IPropertyStorage_Release(propertyStorage
);
284 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
285 IStorage_Release(storage
);
286 if(stream
) IUnknown_Release(stream
);
288 /* now open it again */
289 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
291 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
295 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
296 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
298 hr
= IPropertySetStorage_Open(*propSetStorage
, &FMTID_SummaryInformation
,
299 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &propertyStorage
);
300 ok(hr
== S_OK
, "IPropertySetStorage_Open failed: 0x%08x\n", hr
);
304 hr
= IStorage_OpenStream(storage
, szSummaryInfo
,
305 0, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stream
);
306 ok(hr
== S_OK
, "IStorage_OpenStream failed: 0x%08x\n", hr
);
310 IStorage_Release(storage
);
311 IUnknown_Release(stream
);
312 DeleteFileW(filename
);
315 hr
= pStgOpenPropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
316 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
317 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
320 /* check properties again */
321 spec
.ulKind
= PRSPEC_LPWSTR
;
322 U(spec
).lpwstr
= propName
;
323 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
324 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
325 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 2,
326 "Didn't get expected type or value for property (got type %d, value %d)\n",
327 var
.vt
, U(var
).lVal
);
328 spec
.ulKind
= PRSPEC_PROPID
;
329 U(spec
).propid
= PIDSI_AUTHOR
;
330 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
331 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
332 ok(var
.vt
== VT_LPSTR
&& !lstrcmpA(U(var
).pszVal
, val
),
333 "Didn't get expected type or value for property (got type %d, value %s)\n",
334 var
.vt
, U(var
).pszVal
);
335 PropVariantClear(&var
);
337 IPropertyStorage_Release(propertyStorage
);
338 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
339 IStorage_Release(storage
);
340 if(stream
) IUnknown_Release(stream
);
342 DeleteFileW(filename
);
344 /* Test creating a property set storage with a random GUID */
345 hr
= StgCreateDocfile(filename
,
346 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
347 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
351 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
352 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
354 hr
= IPropertySetStorage_Create(*propSetStorage
,
355 &anyOldGuid
, NULL
, PROPSETFLAG_ANSI
,
356 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
358 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
362 hr
= IStorage_CreateStream(storage
, szSummaryInfo
,
363 STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stream
);
364 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
366 hr
= pStgCreatePropStg((IUnknown
*)stream
, &anyOldGuid
, NULL
,
367 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
368 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
371 spec
.ulKind
= PRSPEC_PROPID
;
372 U(spec
).propid
= PID_FIRST_USABLE
;
375 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
376 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
378 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
379 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
381 IPropertyStorage_Release(propertyStorage
);
382 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
383 IStorage_Release(storage
);
384 if(stream
) IUnknown_Release(stream
);
386 /* now open it again */
387 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
389 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
393 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
394 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
396 hr
= IPropertySetStorage_Open(*propSetStorage
, &anyOldGuid
,
397 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &propertyStorage
);
398 ok(hr
== S_OK
, "IPropertySetStorage_Open failed: 0x%08x\n", hr
);
402 hr
= IStorage_OpenStream(storage
, szSummaryInfo
,
403 0, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stream
);
404 ok(hr
== S_OK
, "IStorage_OpenStream failed: 0x%08x\n", hr
);
406 hr
= pStgOpenPropStg((IUnknown
*)stream
, &anyOldGuid
,
407 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
408 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
411 spec
.ulKind
= PRSPEC_PROPID
;
412 U(spec
).propid
= PID_FIRST_USABLE
;
413 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
414 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
416 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 1,
417 "Didn't get expected type or value for property (got type %d, value %d)\n",
418 var
.vt
, U(var
).lVal
);
420 IPropertyStorage_Release(propertyStorage
);
421 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
422 IStorage_Release(storage
);
423 if(stream
) IUnknown_Release(stream
);
425 DeleteFileW(filename
);
428 static void testProps(void)
430 IPropertySetStorage
*propSetStorage
= NULL
;
432 testPropsHelper(&propSetStorage
);
433 testPropsHelper(NULL
);
436 static void testCodepage(void)
438 static const WCHAR szDot
[] = { '.',0 };
439 static const WCHAR szPrefix
[] = { 's','t','g',0 };
440 static CHAR aval
[] = "hi";
441 static WCHAR wval
[] = { 'h','i',0 };
443 IStorage
*storage
= NULL
;
444 IPropertySetStorage
*propSetStorage
= NULL
;
445 IPropertyStorage
*propertyStorage
= NULL
;
448 WCHAR fileName
[MAX_PATH
];
450 if(!GetTempFileNameW(szDot
, szPrefix
, 0, fileName
))
453 hr
= StgCreateDocfile(fileName
,
454 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
455 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
457 if(!pStgCreatePropSetStg
)
459 IStorage_Release(storage
);
460 DeleteFileW(fileName
);
463 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
464 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
466 hr
= IPropertySetStorage_Create(propSetStorage
,
467 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_DEFAULT
,
468 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
470 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
472 PropVariantInit(&var
);
473 spec
.ulKind
= PRSPEC_PROPID
;
474 U(spec
).propid
= PID_CODEPAGE
;
475 /* check code page before it's been explicitly set */
476 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
477 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
478 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
479 "Didn't get expected type or value for property\n");
480 /* Set the code page to ascii */
483 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
484 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
485 /* check code page */
486 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
487 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
488 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1252,
489 "Didn't get expected type or value for property\n");
490 /* Set code page to Unicode */
492 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
493 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
494 /* check code page */
495 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
496 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
497 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
498 "Didn't get expected type or value for property\n");
499 /* Set a string value */
500 spec
.ulKind
= PRSPEC_PROPID
;
501 U(spec
).propid
= PID_FIRST_USABLE
;
503 U(var
).pszVal
= aval
;
504 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
505 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
506 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
507 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
508 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, "hi"),
509 "Didn't get expected type or value for property\n");
510 PropVariantClear(&var
);
511 /* This seemingly non-sensical test is to show that the string is indeed
512 * interpreted according to the current system code page, not according to
513 * the property set's code page. (If the latter were true, the whole
514 * string would be maintained. As it is, only the first character is.)
517 U(var
).pszVal
= (LPSTR
)wval
;
518 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
519 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
520 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
521 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
522 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, "h"),
523 "Didn't get expected type or value for property\n");
524 PropVariantClear(&var
);
526 /* now that a property's been set, you can't change the code page */
527 spec
.ulKind
= PRSPEC_PROPID
;
528 U(spec
).propid
= PID_CODEPAGE
;
531 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
532 ok(hr
== STG_E_INVALIDPARAMETER
,
533 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
535 IPropertyStorage_Release(propertyStorage
);
536 IPropertySetStorage_Release(propSetStorage
);
537 IStorage_Release(storage
);
539 DeleteFileW(fileName
);
541 /* same tests, but with PROPSETFLAG_ANSI */
542 hr
= StgCreateDocfile(fileName
,
543 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
544 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
546 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
547 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
549 hr
= IPropertySetStorage_Create(propSetStorage
,
550 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
551 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
553 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
555 /* check code page before it's been explicitly set */
556 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
557 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
558 ok(var
.vt
== VT_I2
, "Didn't get expected type for property (%u)\n", var
.vt
);
559 /* Set code page to Unicode */
561 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
562 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
563 /* check code page */
564 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
565 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
566 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
567 "Didn't get expected type or value for property\n");
568 /* This test is commented out for documentation. It fails under Wine,
569 * and I expect it would under Windows as well, yet it succeeds. There's
570 * obviously something about string conversion I don't understand.
573 static unsigned char strVal
[] = { 0x81, 0xff, 0x04, 0 };
574 /* Set code page to 950 (Traditional Chinese) */
576 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
577 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
578 /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
581 spec
.ulKind
= PRSPEC_PROPID
;
582 U(spec
).propid
= PID_FIRST_USABLE
;
584 U(var
).pszVal
= (LPSTR
)strVal
;
585 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
586 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
587 /* Check returned string */
588 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
589 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
590 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, (LPCSTR
)strVal
),
591 "Didn't get expected type or value for property\n");
594 IPropertyStorage_Release(propertyStorage
);
595 IPropertySetStorage_Release(propSetStorage
);
596 IStorage_Release(storage
);
598 DeleteFileW(fileName
);
601 static void testFmtId(void)
603 WCHAR szSummaryInfo
[] = { 5,'S','u','m','m','a','r','y',
604 'I','n','f','o','r','m','a','t','i','o','n',0 };
605 WCHAR szDocSummaryInfo
[] = { 5,'D','o','c','u','m','e','n','t',
606 'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
608 WCHAR szIID_IPropSetStg
[] = { 5,'0','j','a','a','a','a','a',
609 'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
615 if (pFmtIdToPropStgName
) {
616 hr
= pFmtIdToPropStgName(NULL
, name
);
617 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
618 hr
= pFmtIdToPropStgName(&FMTID_SummaryInformation
, NULL
);
619 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
620 hr
= pFmtIdToPropStgName(&FMTID_SummaryInformation
, name
);
621 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
622 ok(!memcmp(name
, szSummaryInfo
, (lstrlenW(szSummaryInfo
) + 1) *
623 sizeof(WCHAR
)), "Got wrong name for FMTID_SummaryInformation\n");
624 hr
= pFmtIdToPropStgName(&FMTID_DocSummaryInformation
, name
);
625 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
626 ok(!memcmp(name
, szDocSummaryInfo
, (lstrlenW(szDocSummaryInfo
) + 1) *
627 sizeof(WCHAR
)), "Got wrong name for FMTID_DocSummaryInformation\n");
628 hr
= pFmtIdToPropStgName(&FMTID_UserDefinedProperties
, name
);
629 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
630 ok(!memcmp(name
, szDocSummaryInfo
, (lstrlenW(szDocSummaryInfo
) + 1) *
631 sizeof(WCHAR
)), "Got wrong name for FMTID_DocSummaryInformation\n");
632 hr
= pFmtIdToPropStgName(&IID_IPropertySetStorage
, name
);
633 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
634 ok(!memcmp(name
, szIID_IPropSetStg
, (lstrlenW(szIID_IPropSetStg
) + 1) *
635 sizeof(WCHAR
)), "Got wrong name for IID_IPropertySetStorage\n");
638 if(pPropStgNameToFmtId
) {
639 /* test args first */
640 hr
= pPropStgNameToFmtId(NULL
, NULL
);
641 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
642 hr
= pPropStgNameToFmtId(NULL
, &fmtid
);
643 ok(hr
== STG_E_INVALIDNAME
, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
645 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, NULL
);
646 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
647 /* test the known format IDs */
648 hr
= pPropStgNameToFmtId(szSummaryInfo
, &fmtid
);
649 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
650 ok(!memcmp(&fmtid
, &FMTID_SummaryInformation
, sizeof(fmtid
)),
651 "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
652 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, &fmtid
);
653 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
654 ok(!memcmp(&fmtid
, &FMTID_DocSummaryInformation
, sizeof(fmtid
)),
655 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
656 /* test another GUID */
657 hr
= pPropStgNameToFmtId(szIID_IPropSetStg
, &fmtid
);
658 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
659 ok(!memcmp(&fmtid
, &IID_IPropertySetStorage
, sizeof(fmtid
)),
660 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
661 /* now check case matching */
662 CharUpperW(szDocSummaryInfo
+ 1);
663 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, &fmtid
);
664 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
665 ok(!memcmp(&fmtid
, &FMTID_DocSummaryInformation
, sizeof(fmtid
)),
666 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
667 CharUpperW(szIID_IPropSetStg
+ 1);
668 hr
= pPropStgNameToFmtId(szIID_IPropSetStg
, &fmtid
);
669 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
670 ok(!memcmp(&fmtid
, &IID_IPropertySetStorage
, sizeof(fmtid
)),
671 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
677 init_function_pointers();