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 #include "wine/test.h"
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);
30 #define PID_BEHAVIOR 0x80000003
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
**);
39 static void init_function_pointers(void)
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");
49 /* FIXME: this creates an ANSI storage, try to find conditions under which
50 * Unicode translation fails
52 static void testPropsHelper(IPropertySetStorage
**propSetStorage
)
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
];
62 IStorage
*storage
= NULL
;
63 IStream
*stream
= NULL
;
64 IPropertyStorage
*propertyStorage
= NULL
;
68 unsigned char clipcontent
[] = "foobar";
69 GUID anyOldGuid
= { 0x12345678,0xdead,0xbeef, {
70 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } };
73 trace("Testing property storage with a set...\n");
75 trace("Testing property storage without a set...\n");
77 if(!GetTempFileNameW(szDot
, szPrefix
, 0, filename
))
80 DeleteFileW(filename
);
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
);
88 if(!pStgCreatePropSetStg
)
90 IStorage_Release(storage
);
91 DeleteFileW(filename
);
94 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
95 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
97 hr
= IPropertySetStorage_Create(*propSetStorage
,
98 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
99 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
101 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
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
);
109 if(!pStgCreatePropStg
)
111 IStorage_Release(storage
);
112 IUnknown_Release(stream
);
113 DeleteFileW(filename
);
116 hr
= pStgCreatePropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
117 NULL
, PROPSETFLAG_ANSI
, 0, &propertyStorage
);
118 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
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
);
126 /* test setting one that I can't set */
127 spec
.ulKind
= PRSPEC_PROPID
;
128 U(spec
).propid
= PID_DICTIONARY
;
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
);
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
,
140 ok(hr
== STG_E_INVALIDPARAMETER
,
141 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr
);
143 /* test setting behavior (case-sensitive) */
144 spec
.ulKind
= PRSPEC_PROPID
;
145 U(spec
).propid
= PID_BEHAVIOR
;
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
);
151 /* set one by value.. */
152 spec
.ulKind
= PRSPEC_PROPID
;
153 U(spec
).propid
= PID_FIRST_USABLE
;
155 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
156 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
158 /* set one by name */
159 spec
.ulKind
= PRSPEC_LPWSTR
;
160 U(spec
).lpwstr
= propName
;
162 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
,
164 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
166 /* set a string value */
167 spec
.ulKind
= PRSPEC_PROPID
;
168 U(spec
).propid
= PIDSI_AUTHOR
;
171 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
172 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
174 /* set a clipboard value */
175 spec
.ulKind
= PRSPEC_PROPID
;
176 U(spec
).propid
= PIDSI_THUMBNAIL
;
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
);
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
);
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
);
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
);
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");
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
);
250 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
251 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
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
;
268 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
269 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
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 */
276 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
277 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
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
286 IPropertyStorage_Release(propertyStorage
);
287 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
288 IStorage_Release(storage
);
289 if(stream
) IUnknown_Release(stream
);
291 /* now open it again */
292 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
294 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
298 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
299 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
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
);
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
);
313 IStorage_Release(storage
);
314 IUnknown_Release(stream
);
315 DeleteFileW(filename
);
318 hr
= pStgOpenPropStg((IUnknown
*)stream
, &FMTID_SummaryInformation
,
319 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
320 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
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
);
340 IPropertyStorage_Release(propertyStorage
);
341 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
342 IStorage_Release(storage
);
343 if(stream
) IUnknown_Release(stream
);
345 DeleteFileW(filename
);
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
);
354 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
355 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
357 hr
= IPropertySetStorage_Create(*propSetStorage
,
358 &anyOldGuid
, NULL
, PROPSETFLAG_ANSI
,
359 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
361 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
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
);
369 hr
= pStgCreatePropStg((IUnknown
*)stream
, &anyOldGuid
, NULL
,
370 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
371 ok(hr
== S_OK
, "StgCreatePropStg failed: 0x%08x\n", hr
);
374 spec
.ulKind
= PRSPEC_PROPID
;
375 U(spec
).propid
= PID_FIRST_USABLE
;
378 hr
= IPropertyStorage_WriteMultiple(propertyStorage
, 1, &spec
, &var
, 0);
379 ok(hr
== S_OK
, "WriteMultiple failed: 0x%08x\n", hr
);
381 hr
= IPropertyStorage_Commit(propertyStorage
, STGC_DEFAULT
);
382 ok(hr
== S_OK
, "Commit failed: 0x%08x\n", hr
);
384 IPropertyStorage_Release(propertyStorage
);
385 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
386 IStorage_Release(storage
);
387 if(stream
) IUnknown_Release(stream
);
389 /* now open it again */
390 hr
= StgOpenStorage(filename
, NULL
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
392 ok(hr
== S_OK
, "StgOpenStorage failed: 0x%08x\n", hr
);
396 hr
= pStgCreatePropSetStg(storage
, 0, propSetStorage
);
397 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
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
);
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
);
409 hr
= pStgOpenPropStg((IUnknown
*)stream
, &anyOldGuid
,
410 PROPSETFLAG_DEFAULT
, 0, &propertyStorage
);
411 ok(hr
== S_OK
, "StgOpenPropStg failed: 0x%08x\n", hr
);
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
);
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
);
423 IPropertyStorage_Release(propertyStorage
);
424 if(propSetStorage
) IPropertySetStorage_Release(*propSetStorage
);
425 IStorage_Release(storage
);
426 if(stream
) IUnknown_Release(stream
);
428 DeleteFileW(filename
);
431 static void testProps(void)
433 IPropertySetStorage
*propSetStorage
= NULL
;
435 testPropsHelper(&propSetStorage
);
436 testPropsHelper(NULL
);
439 static void testCodepage(void)
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 };
446 IStorage
*storage
= NULL
;
447 IPropertySetStorage
*propSetStorage
= NULL
;
448 IPropertyStorage
*propertyStorage
= NULL
;
451 WCHAR fileName
[MAX_PATH
];
453 if(!GetTempFileNameW(szDot
, szPrefix
, 0, fileName
))
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
);
460 if(!pStgCreatePropSetStg
)
462 IStorage_Release(storage
);
463 DeleteFileW(fileName
);
466 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
467 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
469 hr
= IPropertySetStorage_Create(propSetStorage
,
470 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_DEFAULT
,
471 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
473 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
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 */
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 */
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
;
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.)
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
);
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
;
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
);
538 IPropertyStorage_Release(propertyStorage
);
539 IPropertySetStorage_Release(propSetStorage
);
540 IStorage_Release(storage
);
542 DeleteFileW(fileName
);
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
);
549 hr
= pStgCreatePropSetStg(storage
, 0, &propSetStorage
);
550 ok(hr
== S_OK
, "StgCreatePropSetStg failed: 0x%08x\n", hr
);
552 hr
= IPropertySetStorage_Create(propSetStorage
,
553 &FMTID_SummaryInformation
, NULL
, PROPSETFLAG_ANSI
,
554 STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
,
556 ok(hr
== S_OK
, "IPropertySetStorage_Create failed: 0x%08x\n", hr
);
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 */
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.
576 static unsigned char strVal
[] = { 0x81, 0xff, 0x04, 0 };
577 /* Set code page to 950 (Traditional Chinese) */
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
584 spec
.ulKind
= PRSPEC_PROPID
;
585 U(spec
).propid
= PID_FIRST_USABLE
;
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");
597 IPropertyStorage_Release(propertyStorage
);
598 IPropertySetStorage_Release(propSetStorage
);
599 IStorage_Release(storage
);
601 DeleteFileW(fileName
);
604 static void testFmtId(void)
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',
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',
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");
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",
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");
680 init_function_pointers();