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