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
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
30 #include <wine/test.h>
31 //#include "initguid.h"
33 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
34 DEFINE_GUID(FMTID_SummaryInformation
,0xF29F85E0,0x4FF9,0x1068,0xAB,0x91,0x08,0x00,0x2B,0x27,0xB3,0xD9);
35 DEFINE_GUID(FMTID_DocSummaryInformation
,0xD5CDD502,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
36 DEFINE_GUID(FMTID_UserDefinedProperties
,0xD5CDD505,0x2E9C,0x101B,0x93,0x97,0x08,0x00,0x2B,0x2C,0xF9,0xAE);
39 #define PID_BEHAVIOR 0x80000003
42 static HRESULT (WINAPI
*pFmtIdToPropStgName
)(const FMTID
*, LPOLESTR
);
43 static HRESULT (WINAPI
*pPropStgNameToFmtId
)(const LPOLESTR
, FMTID
*);
44 static HRESULT (WINAPI
*pStgCreatePropSetStg
)(IStorage
*, DWORD
, IPropertySetStorage
**);
45 static HRESULT (WINAPI
*pStgCreatePropStg
)(IUnknown
*, REFFMTID
, const CLSID
*, DWORD
, DWORD
, IPropertyStorage
**);
46 static HRESULT (WINAPI
*pStgOpenPropStg
)(IUnknown
*, REFFMTID
, DWORD
, DWORD
, IPropertyStorage
**);
48 static void init_function_pointers(void)
50 HMODULE hmod
= GetModuleHandleA("ole32.dll");
51 pFmtIdToPropStgName
= (void*)GetProcAddress(hmod
, "FmtIdToPropStgName");
52 pPropStgNameToFmtId
= (void*)GetProcAddress(hmod
, "PropStgNameToFmtId");
53 pStgCreatePropSetStg
= (void*)GetProcAddress(hmod
, "StgCreatePropSetStg");
54 pStgCreatePropStg
= (void*)GetProcAddress(hmod
, "StgCreatePropStg");
55 pStgOpenPropStg
= (void*)GetProcAddress(hmod
, "StgOpenPropStg");
58 /* FIXME: this creates an ANSI storage, try to find conditions under which
59 * Unicode translation fails
61 static void testPropsHelper(IPropertySetStorage
**propSetStorage
)
63 static const WCHAR szDot
[] = { '.',0 };
64 static const WCHAR szPrefix
[] = { 's','t','g',0 };
65 static const WCHAR szSummaryInfo
[] = { 5,'S','u','m','m','a','r','y',
66 'I','n','f','o','r','m','a','t','i','o','n',0 };
67 static WCHAR propName
[] = { 'p','r','o','p',0 };
68 static char val
[] = "l33t auth0r";
69 WCHAR filename
[MAX_PATH
];
71 IStorage
*storage
= NULL
;
72 IStream
*stream
= NULL
;
73 IPropertyStorage
*propertyStorage
= NULL
;
77 unsigned char clipcontent
[] = "foobar";
78 GUID anyOldGuid
= { 0x12345678,0xdead,0xbeef, {
79 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } };
82 trace("Testing property storage with a set...\n");
84 trace("Testing property storage without a set...\n");
86 if(!GetTempFileNameW(szDot
, szPrefix
, 0, filename
))
89 DeleteFileW(filename
);
91 hr
= StgCreateDocfile(filename
,
92 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
93 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
97 if(!pStgCreatePropSetStg
)
99 IStorage_Release(storage
);
100 DeleteFileW(filename
);
103 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
104 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
106 hr
= IPropertySetStorage_Create(*propSetStorage
,
107 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
108 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
110 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
114 hr
= IStorage_CreateStream(storage
, szSummaryInfo
,
115 STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stream
);
116 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
118 if(!pStgCreatePropStg
)
120 IStorage_Release(storage
);
121 IUnknown_Release(stream
);
122 DeleteFileW(filename
);
125 hr
= pStgCreatePropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
126 NULL
, PROPSETFLAG_ANSI
, 0, &propertyStorage
);
127 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
130 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 0, NULL
, NULL
, 0);
131 ok(hr
== S_OK
, "WriteMultiple with 0 args failed: 0x%08x\n", hr
);
132 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, NULL
, NULL
, 0);
133 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
135 /* test setting one that I can't set */
136 spec
.ulKind
= PRSPEC_PROPID
;
137 U(spec
).propid
= PID_DICTIONARY
;
140 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
141 ok(hr
== STG_E_INVALIDPARAMETER
,
142 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
144 /* test setting one by name with an invalid propidNameFirst */
145 spec
.ulKind
= PRSPEC_LPWSTR
;
146 U(spec
).lpwstr
= propName
;
147 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
,
149 ok(hr
== STG_E_INVALIDPARAMETER
,
150 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
152 /* test setting behavior (case-sensitive) */
153 spec
.ulKind
= PRSPEC_PROPID
;
154 U(spec
).propid
= PID_BEHAVIOR
;
156 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
157 ok(hr
== STG_E_INVALIDPARAMETER
,
158 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
160 /* set one by value.. */
161 spec
.ulKind
= PRSPEC_PROPID
;
162 U(spec
).propid
= PID_FIRST_USABLE
;
164 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
165 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
167 /* set one by name */
168 spec
.ulKind
= PRSPEC_LPWSTR
;
169 U(spec
).lpwstr
= propName
;
171 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
,
173 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
175 /* set a string value */
176 spec
.ulKind
= PRSPEC_PROPID
;
177 U(spec
).propid
= PIDSI_AUTHOR
;
180 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
181 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
183 /* set a clipboard value */
184 spec
.ulKind
= PRSPEC_PROPID
;
185 U(spec
).propid
= PIDSI_THUMBNAIL
;
187 clipdata
.cbSize
= sizeof clipcontent
+ sizeof (ULONG
);
188 clipdata
.ulClipFmt
= CF_ENHMETAFILE
;
189 clipdata
.pClipData
= clipcontent
;
190 U(var
).pclipdata
= &clipdata
;
191 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
192 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
196 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 0, NULL
, NULL
);
197 ok(hr
== S_FALSE
, "ReadMultiple with 0 args failed: 0x%08x\n", hr
);
198 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, NULL
, NULL
);
199 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
201 spec
.ulKind
= PRSPEC_PROPID
;
202 U(spec
).propid
= PID_FIRST_USABLE
;
203 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
204 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
205 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 1,
206 "Didn't get expected type or value for property (got type %d, value %d)\n",
207 var
.vt
, U(var
).lVal
);
209 spec
.ulKind
= PRSPEC_LPWSTR
;
210 U(spec
).lpwstr
= propName
;
211 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
212 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
213 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 2,
214 "Didn't get expected type or value for property (got type %d, value %d)\n",
215 var
.vt
, U(var
).lVal
);
216 /* read string value */
217 spec
.ulKind
= PRSPEC_PROPID
;
218 U(spec
).propid
= PIDSI_AUTHOR
;
219 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
220 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
221 ok(var
.vt
== VT_LPSTR
&& !lstrcmpA(U(var
).pszVal
, val
),
222 "Didn't get expected type or value for property (got type %d, value %s)\n",
223 var
.vt
, U(var
).pszVal
);
224 PropVariantClear(&var
);
226 /* read clipboard format */
227 spec
.ulKind
= PRSPEC_PROPID
;
228 U(spec
).propid
= PIDSI_THUMBNAIL
;
229 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
230 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
231 ok(var
.vt
== VT_CF
, "variant type wrong\n");
232 ok(U(var
).pclipdata
->ulClipFmt
== CF_ENHMETAFILE
,
233 "clipboard type wrong\n");
234 ok(U(var
).pclipdata
->cbSize
== sizeof clipcontent
+ sizeof (ULONG
),
235 "clipboard size wrong\n");
236 ok(!memcmp(U(var
).pclipdata
->pClipData
, clipcontent
, sizeof clipcontent
),
237 "clipboard contents wrong\n");
238 ok(S_OK
== PropVariantClear(&var
), "failed to clear variant\n");
241 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 0, NULL
);
242 ok(hr
== S_OK
, "DeleteMultiple with 0 args failed: 0x%08x\n", hr
);
243 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, NULL
);
244 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
245 /* contrary to what the docs say, you can't delete the dictionary */
246 spec
.ulKind
= PRSPEC_PROPID
;
247 U(spec
).propid
= PID_DICTIONARY
;
248 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, &spec
);
249 ok(hr
== STG_E_INVALIDPARAMETER
,
250 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
251 /* now delete the first value.. */
252 U(spec
).propid
= PID_FIRST_USABLE
;
253 hr
= IPropertyStorage_DeleteMultiple(propertyStorage
, 1, &spec
);
254 ok(hr
== S_OK
, "DeleteMultiple failed: 0x%08x\n", hr
);
255 /* and check that it's no longer readable */
256 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
257 ok(hr
== S_FALSE
, "Expected S_FALSE, got 0x%08x\n", hr
);
259 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
260 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
262 /* check reverting */
263 spec
.ulKind
= PRSPEC_PROPID
;
264 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
);
267 hr
= IPropertyStorage_Revert(propertyStorage
);
268 ok(hr
== S_OK
, "Revert failed: 0x%08x\n", hr
);
269 /* now check that it's still not there */
270 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
271 ok(hr
== S_FALSE
, "Expected S_FALSE, got 0x%08x\n", hr
);
272 /* set an integer value again */
273 spec
.ulKind
= PRSPEC_PROPID
;
274 U(spec
).propid
= PID_FIRST_USABLE
;
277 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
278 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
280 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
281 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
282 /* set it to a string value */
285 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
286 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
288 hr
= IPropertyStorage_Revert(propertyStorage
);
289 ok(hr
== S_OK
, "Revert failed: 0x%08x\n", hr
);
290 /* Oddly enough, there's no guarantee that a successful revert actually
291 * implies the value wasn't saved. Maybe transactional mode needs to be
295 IPropertyStorage_Release(propertyStorage
);
296 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
297 IStorage_Release(storage
);
298 if(stream
) IUnknown_Release(stream
);
300 /* now open it again */
301 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
303 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
307 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
308 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
310 hr
= IPropertySetStorage_Open(*propSetStorage
, &FMTID_SummaryInformation
,
311 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &propertyStorage
);
312 ok(hr
== S_OK
, "IPropertySetStorage_Open failed: 0x%08x\n", hr
);
316 hr
= IStorage_OpenStream(storage
, szSummaryInfo
,
317 0, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stream
);
318 ok(hr
== S_OK
, "IStorage_OpenStream failed: 0x%08x\n", hr
);
322 IStorage_Release(storage
);
323 IUnknown_Release(stream
);
324 DeleteFileW(filename
);
327 hr
= pStgOpenPropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
328 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
329 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
332 /* check properties again */
333 spec
.ulKind
= PRSPEC_LPWSTR
;
334 U(spec
).lpwstr
= propName
;
335 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
336 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
337 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 2,
338 "Didn't get expected type or value for property (got type %d, value %d)\n",
339 var
.vt
, U(var
).lVal
);
340 spec
.ulKind
= PRSPEC_PROPID
;
341 U(spec
).propid
= PIDSI_AUTHOR
;
342 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
343 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
344 ok(var
.vt
== VT_LPSTR
&& !lstrcmpA(U(var
).pszVal
, val
),
345 "Didn't get expected type or value for property (got type %d, value %s)\n",
346 var
.vt
, U(var
).pszVal
);
347 PropVariantClear(&var
);
349 IPropertyStorage_Release(propertyStorage
);
350 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
351 IStorage_Release(storage
);
352 if(stream
) IUnknown_Release(stream
);
354 DeleteFileW(filename
);
356 /* Test creating a property set storage with a random GUID */
357 hr
= StgCreateDocfile(filename
,
358 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
359 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
363 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
364 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
366 hr
= IPropertySetStorage_Create(*propSetStorage
,
367 &anyOldGuid
, NULL
, PROPSETFLAG_ANSI
,
368 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
370 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
374 hr
= IStorage_CreateStream(storage
, szSummaryInfo
,
375 STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stream
);
376 ok(hr
== S_OK
, "IStorage_CreateStream failed: 0x%08x\n", hr
);
378 hr
= pStgCreatePropStg((IUnknown
*)stream
, &anyOldGuid
, NULL
,
379 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
380 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
383 spec
.ulKind
= PRSPEC_PROPID
;
384 U(spec
).propid
= PID_FIRST_USABLE
;
387 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
388 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
390 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
391 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
393 IPropertyStorage_Release(propertyStorage
);
394 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
395 IStorage_Release(storage
);
396 if(stream
) IUnknown_Release(stream
);
398 /* now open it again */
399 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
401 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
405 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
406 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
408 hr
= IPropertySetStorage_Open(*propSetStorage
, &anyOldGuid
,
409 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &propertyStorage
);
410 ok(hr
== S_OK
, "IPropertySetStorage_Open failed: 0x%08x\n", hr
);
414 hr
= IStorage_OpenStream(storage
, szSummaryInfo
,
415 0, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stream
);
416 ok(hr
== S_OK
, "IStorage_OpenStream failed: 0x%08x\n", hr
);
418 hr
= pStgOpenPropStg((IUnknown
*)stream
, &anyOldGuid
,
419 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
420 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
423 spec
.ulKind
= PRSPEC_PROPID
;
424 U(spec
).propid
= PID_FIRST_USABLE
;
425 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
426 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
428 ok(var
.vt
== VT_I4
&& U(var
).lVal
== 1,
429 "Didn't get expected type or value for property (got type %d, value %d)\n",
430 var
.vt
, U(var
).lVal
);
432 IPropertyStorage_Release(propertyStorage
);
433 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
434 IStorage_Release(storage
);
435 if(stream
) IUnknown_Release(stream
);
437 DeleteFileW(filename
);
440 static void testProps(void)
442 IPropertySetStorage
*propSetStorage
= NULL
;
444 testPropsHelper(&propSetStorage
);
445 testPropsHelper(NULL
);
448 static void testCodepage(void)
450 static const WCHAR szDot
[] = { '.',0 };
451 static const WCHAR szPrefix
[] = { 's','t','g',0 };
452 static CHAR aval
[] = "hi";
453 static WCHAR wval
[] = { 'h','i',0 };
455 IStorage
*storage
= NULL
;
456 IPropertySetStorage
*propSetStorage
= NULL
;
457 IPropertyStorage
*propertyStorage
= NULL
;
460 WCHAR fileName
[MAX_PATH
];
462 if(!GetTempFileNameW(szDot
, szPrefix
, 0, fileName
))
465 hr
= StgCreateDocfile(fileName
,
466 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
467 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
469 if(!pStgCreatePropSetStg
)
471 IStorage_Release(storage
);
472 DeleteFileW(fileName
);
475 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
476 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
478 hr
= IPropertySetStorage_Create(propSetStorage
,
479 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_DEFAULT
,
480 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
482 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
484 PropVariantInit(&var
);
485 spec
.ulKind
= PRSPEC_PROPID
;
486 U(spec
).propid
= PID_CODEPAGE
;
487 /* check code page before it's been explicitly set */
488 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
489 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
490 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
491 "Didn't get expected type or value for property\n");
492 /* Set the code page to ascii */
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
== 1252,
501 "Didn't get expected type or value for property\n");
502 /* Set code page to Unicode */
504 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
505 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
506 /* check code page */
507 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
508 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
509 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
510 "Didn't get expected type or value for property\n");
511 /* Set a string value */
512 spec
.ulKind
= PRSPEC_PROPID
;
513 U(spec
).propid
= PID_FIRST_USABLE
;
515 U(var
).pszVal
= aval
;
516 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
517 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
518 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
519 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
520 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, "hi"),
521 "Didn't get expected type or value for property\n");
522 PropVariantClear(&var
);
523 /* This seemingly non-sensical test is to show that the string is indeed
524 * interpreted according to the current system code page, not according to
525 * the property set's code page. (If the latter were true, the whole
526 * string would be maintained. As it is, only the first character is.)
529 U(var
).pszVal
= (LPSTR
)wval
;
530 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
531 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
532 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
533 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
534 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, "h"),
535 "Didn't get expected type or value for property\n");
536 PropVariantClear(&var
);
538 /* now that a property's been set, you can't change the code page */
539 spec
.ulKind
= PRSPEC_PROPID
;
540 U(spec
).propid
= PID_CODEPAGE
;
543 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
544 ok(hr
== STG_E_INVALIDPARAMETER
,
545 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
547 IPropertyStorage_Release(propertyStorage
);
548 IPropertySetStorage_Release(propSetStorage
);
549 IStorage_Release(storage
);
551 DeleteFileW(fileName
);
553 /* same tests, but with PROPSETFLAG_ANSI */
554 hr
= StgCreateDocfile(fileName
,
555 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_CREATE
, 0, &storage
);
556 ok(hr
== S_OK
, "StgCreateDocfile failed: 0x%08x\n", hr
);
558 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
559 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
561 hr
= IPropertySetStorage_Create(propSetStorage
,
562 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
563 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
565 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
567 /* check code page before it's been explicitly set */
568 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
569 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
570 ok(var
.vt
== VT_I2
, "Didn't get expected type for property (%u)\n", var
.vt
);
571 /* Set code page to Unicode */
573 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
574 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
575 /* check code page */
576 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
577 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
578 ok(var
.vt
== VT_I2
&& U(var
).iVal
== 1200,
579 "Didn't get expected type or value for property\n");
580 /* This test is commented out for documentation. It fails under Wine,
581 * and I expect it would under Windows as well, yet it succeeds. There's
582 * obviously something about string conversion I don't understand.
585 static unsigned char strVal
[] = { 0x81, 0xff, 0x04, 0 };
586 /* Set code page to 950 (Traditional Chinese) */
588 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
589 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
590 /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
593 spec
.ulKind
= PRSPEC_PROPID
;
594 U(spec
).propid
= PID_FIRST_USABLE
;
596 U(var
).pszVal
= (LPSTR
)strVal
;
597 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
598 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
599 /* Check returned string */
600 hr
= IPropertyStorage_ReadMultiple(propertyStorage
, 1, &spec
, &var
);
601 ok(hr
== S_OK
, "ReadMultiple failed: 0x%08x\n", hr
);
602 ok(var
.vt
== VT_LPSTR
&& !strcmp(U(var
).pszVal
, (LPCSTR
)strVal
),
603 "Didn't get expected type or value for property\n");
606 IPropertyStorage_Release(propertyStorage
);
607 IPropertySetStorage_Release(propSetStorage
);
608 IStorage_Release(storage
);
610 DeleteFileW(fileName
);
613 static void testFmtId(void)
615 WCHAR szSummaryInfo
[] = { 5,'S','u','m','m','a','r','y',
616 'I','n','f','o','r','m','a','t','i','o','n',0 };
617 WCHAR szDocSummaryInfo
[] = { 5,'D','o','c','u','m','e','n','t',
618 'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
620 WCHAR szIID_IPropSetStg
[] = { 5,'0','j','a','a','a','a','a',
621 'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
627 if (pFmtIdToPropStgName
) {
628 hr
= pFmtIdToPropStgName(NULL
, name
);
629 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
630 hr
= pFmtIdToPropStgName(&FMTID_SummaryInformation
, NULL
);
631 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
632 hr
= pFmtIdToPropStgName(&FMTID_SummaryInformation
, name
);
633 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
634 ok(!memcmp(name
, szSummaryInfo
, (lstrlenW(szSummaryInfo
) + 1) *
635 sizeof(WCHAR
)), "Got wrong name for FMTID_SummaryInformation\n");
636 hr
= pFmtIdToPropStgName(&FMTID_DocSummaryInformation
, name
);
637 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
638 ok(!memcmp(name
, szDocSummaryInfo
, (lstrlenW(szDocSummaryInfo
) + 1) *
639 sizeof(WCHAR
)), "Got wrong name for FMTID_DocSummaryInformation\n");
640 hr
= pFmtIdToPropStgName(&FMTID_UserDefinedProperties
, name
);
641 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
642 ok(!memcmp(name
, szDocSummaryInfo
, (lstrlenW(szDocSummaryInfo
) + 1) *
643 sizeof(WCHAR
)), "Got wrong name for FMTID_DocSummaryInformation\n");
644 hr
= pFmtIdToPropStgName(&IID_IPropertySetStorage
, name
);
645 ok(hr
== S_OK
, "FmtIdToPropStgName failed: 0x%08x\n", hr
);
646 ok(!memcmp(name
, szIID_IPropSetStg
, (lstrlenW(szIID_IPropSetStg
) + 1) *
647 sizeof(WCHAR
)), "Got wrong name for IID_IPropertySetStorage\n");
650 if(pPropStgNameToFmtId
) {
651 /* test args first */
652 hr
= pPropStgNameToFmtId(NULL
, NULL
);
653 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
654 hr
= pPropStgNameToFmtId(NULL
, &fmtid
);
655 ok(hr
== STG_E_INVALIDNAME
, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
657 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, NULL
);
658 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got 0x%08x\n", hr
);
659 /* test the known format IDs */
660 hr
= pPropStgNameToFmtId(szSummaryInfo
, &fmtid
);
661 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
662 ok(!memcmp(&fmtid
, &FMTID_SummaryInformation
, sizeof(fmtid
)),
663 "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
664 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, &fmtid
);
665 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
666 ok(!memcmp(&fmtid
, &FMTID_DocSummaryInformation
, sizeof(fmtid
)),
667 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
668 /* test another GUID */
669 hr
= pPropStgNameToFmtId(szIID_IPropSetStg
, &fmtid
);
670 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
671 ok(!memcmp(&fmtid
, &IID_IPropertySetStorage
, sizeof(fmtid
)),
672 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
673 /* now check case matching */
674 CharUpperW(szDocSummaryInfo
+ 1);
675 hr
= pPropStgNameToFmtId(szDocSummaryInfo
, &fmtid
);
676 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
677 ok(!memcmp(&fmtid
, &FMTID_DocSummaryInformation
, sizeof(fmtid
)),
678 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
679 CharUpperW(szIID_IPropSetStg
+ 1);
680 hr
= pPropStgNameToFmtId(szIID_IPropSetStg
, &fmtid
);
681 ok(hr
== S_OK
, "PropStgNameToFmtId failed: 0x%08x\n", hr
);
682 ok(!memcmp(&fmtid
, &IID_IPropertySetStorage
, sizeof(fmtid
)),
683 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
689 init_function_pointers();