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