wintrust: Use path in WIN_TRUST_SUBJECT_FILE structure rather than assuming a path...
[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
63     if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
64         return;
65
66     DeleteFileW(filename);
67
68     hr = StgCreateDocfile(filename,
69      STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
70     ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
71
72     if(!pStgCreatePropSetStg)
73     {
74         IStorage_Release(storage);
75         DeleteFileW(filename);
76         return;
77     }
78     hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
79     ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
80
81     hr = IPropertySetStorage_Create(propSetStorage,
82      &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
83      STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
84      &propertyStorage);
85     ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
86
87     hr = IPropertyStorage_WriteMultiple(propertyStorage, 0, NULL, NULL, 0);
88     ok(hr == S_OK, "WriteMultiple with 0 args failed: 0x%08x\n", hr);
89     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, NULL, NULL, 0);
90     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
91
92     /* test setting one that I can't set */
93     spec.ulKind = PRSPEC_PROPID;
94     U(spec).propid = PID_DICTIONARY;
95     var.vt = VT_I4;
96     U(var).lVal = 1;
97     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
98     ok(hr == STG_E_INVALIDPARAMETER,
99      "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
100
101     /* test setting one by name with an invalid propidNameFirst */
102     spec.ulKind = PRSPEC_LPWSTR;
103     U(spec).lpwstr = (LPOLESTR)propName;
104     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
105      PID_DICTIONARY);
106     ok(hr == STG_E_INVALIDPARAMETER,
107      "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
108
109     /* test setting behavior (case-sensitive) */
110     spec.ulKind = PRSPEC_PROPID;
111     U(spec).propid = PID_BEHAVIOR;
112     U(var).lVal = 1;
113     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
114     ok(hr == STG_E_INVALIDPARAMETER,
115      "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
116
117     /* set one by value.. */
118     spec.ulKind = PRSPEC_PROPID;
119     U(spec).propid = PID_FIRST_USABLE;
120     U(var).lVal = 1;
121     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
122     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
123
124     /* set one by name */
125     spec.ulKind = PRSPEC_LPWSTR;
126     U(spec).lpwstr = (LPOLESTR)propName;
127     U(var).lVal = 2;
128     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
129      PID_FIRST_USABLE);
130     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
131
132     /* set a string value */
133     spec.ulKind = PRSPEC_PROPID;
134     U(spec).propid = PIDSI_AUTHOR;
135     var.vt = VT_LPSTR;
136     U(var).pszVal = val;
137     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
138     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
139
140     /* set a clipboard value */
141     spec.ulKind = PRSPEC_PROPID;
142     U(spec).propid = PIDSI_THUMBNAIL;
143     var.vt = VT_CF;
144     clipdata.cbSize = sizeof clipcontent + sizeof (ULONG);
145     clipdata.ulClipFmt = CF_ENHMETAFILE;
146     clipdata.pClipData = clipcontent;
147     U(var).pclipdata = &clipdata;
148     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
149     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
150
151
152     /* check reading */
153     hr = IPropertyStorage_ReadMultiple(propertyStorage, 0, NULL, NULL);
154     ok(hr == S_FALSE, "ReadMultiple with 0 args failed: 0x%08x\n", hr);
155     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, NULL, NULL);
156     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
157     /* read by propid */
158     spec.ulKind = PRSPEC_PROPID;
159     U(spec).propid = PID_FIRST_USABLE;
160     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
161     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
162     ok(var.vt == VT_I4 && U(var).lVal == 1,
163      "Didn't get expected type or value for property (got type %d, value %ld)\n",
164      var.vt, U(var).lVal);
165     /* read by name */
166     spec.ulKind = PRSPEC_LPWSTR;
167     U(spec).lpwstr = (LPOLESTR)propName;
168     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
169     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
170     ok(var.vt == VT_I4 && U(var).lVal == 2,
171      "Didn't get expected type or value for property (got type %d, value %ld)\n",
172      var.vt, U(var).lVal);
173     /* read string value */
174     spec.ulKind = PRSPEC_PROPID;
175     U(spec).propid = PIDSI_AUTHOR;
176     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
177     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
178     ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
179      "Didn't get expected type or value for property (got type %d, value %s)\n",
180      var.vt, U(var).pszVal);
181
182     /* read clipboard format */
183     spec.ulKind = PRSPEC_PROPID;
184     U(spec).propid = PIDSI_THUMBNAIL;
185     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
186     ok(SUCCEEDED(hr), "ReadMultiple failed: 0x%08x\n", hr);
187     ok(var.vt == VT_CF, "variant type wrong\n");
188     ok(U(var).pclipdata->ulClipFmt == CF_ENHMETAFILE,
189         "clipboard type wrong\n");
190     ok(U(var).pclipdata->cbSize == sizeof clipcontent + sizeof (ULONG),
191         "clipboard size wrong\n");
192     ok(!memcmp(U(var).pclipdata->pClipData, clipcontent, sizeof clipcontent),
193         "clipboard contents wrong\n");
194     ok(S_OK == PropVariantClear(&var), "failed to clear variant\n");
195
196     /* check deleting */
197     hr = IPropertyStorage_DeleteMultiple(propertyStorage, 0, NULL);
198     ok(hr == S_OK, "DeleteMultiple with 0 args failed: 0x%08x\n", hr);
199     hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, NULL);
200     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
201     /* contrary to what the docs say, you can't delete the dictionary */
202     spec.ulKind = PRSPEC_PROPID;
203     U(spec).propid = PID_DICTIONARY;
204     hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
205     ok(hr == STG_E_INVALIDPARAMETER,
206      "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
207     /* now delete the first value.. */
208     U(spec).propid = PID_FIRST_USABLE;
209     hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
210     ok(hr == S_OK, "DeleteMultiple failed: 0x%08x\n", hr);
211     /* and check that it's no longer readable */
212     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
213     ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
214
215     hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
216     ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
217
218     /* check reverting */
219     spec.ulKind = PRSPEC_PROPID;
220     U(spec).propid = PID_FIRST_USABLE;
221     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
222     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
223     hr = IPropertyStorage_Revert(propertyStorage);
224     ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
225     /* now check that it's still not there */
226     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
227     ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
228     /* set an integer value again */
229     spec.ulKind = PRSPEC_PROPID;
230     U(spec).propid = PID_FIRST_USABLE;
231     var.vt = VT_I4;
232     U(var).lVal = 1;
233     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
234     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
235     /* commit it */
236     hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
237     ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
238     /* set it to a string value */
239     var.vt = VT_LPSTR;
240     U(var).pszVal = (LPSTR)val;
241     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
242     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
243     /* revert it */
244     hr = IPropertyStorage_Revert(propertyStorage);
245     ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
246     /* Oddly enough, there's no guarantee that a successful revert actually
247      * implies the value wasn't saved.  Maybe transactional mode needs to be
248      * used for that?
249      */
250
251     IPropertyStorage_Release(propertyStorage);
252     propertyStorage = NULL;
253     IPropertySetStorage_Release(propSetStorage);
254     propSetStorage = NULL;
255     IStorage_Release(storage);
256     storage = NULL;
257
258     /* now open it again */
259     hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
260      NULL, 0, &storage);
261     ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);
262
263     hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
264     ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
265
266     hr = IPropertySetStorage_Open(propSetStorage, &FMTID_SummaryInformation,
267      STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
268     ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
269
270     /* check properties again */
271     spec.ulKind = PRSPEC_LPWSTR;
272     U(spec).lpwstr = (LPOLESTR)propName;
273     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
274     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
275     ok(var.vt == VT_I4 && U(var).lVal == 2,
276      "Didn't get expected type or value for property (got type %d, value %ld)\n",
277      var.vt, U(var).lVal);
278     spec.ulKind = PRSPEC_PROPID;
279     U(spec).propid = PIDSI_AUTHOR;
280     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
281     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
282     ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
283      "Didn't get expected type or value for property (got type %d, value %s)\n",
284      var.vt, U(var).pszVal);
285
286     IPropertyStorage_Release(propertyStorage);
287     IPropertySetStorage_Release(propSetStorage);
288     IStorage_Release(storage);
289
290     DeleteFileW(filename);
291 }
292
293 static void testCodepage(void)
294 {
295     static const WCHAR szDot[] = { '.',0 };
296     static const WCHAR szPrefix[] = { 's','t','g',0 };
297     static CHAR aval[] = "hi";
298     static WCHAR wval[] = { 'h','i',0 };
299     HRESULT hr;
300     IStorage *storage = NULL;
301     IPropertySetStorage *propSetStorage = NULL;
302     IPropertyStorage *propertyStorage = NULL;
303     PROPSPEC spec;
304     PROPVARIANT var;
305     WCHAR fileName[MAX_PATH];
306
307     if(!GetTempFileNameW(szDot, szPrefix, 0, fileName))
308         return;
309
310     hr = StgCreateDocfile(fileName,
311      STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
312     ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
313
314     if(!pStgCreatePropSetStg)
315     {
316         IStorage_Release(storage);
317         DeleteFileW(fileName);
318         return;
319     }
320     hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
321     ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
322
323     hr = IPropertySetStorage_Create(propSetStorage,
324      &FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT,
325      STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
326      &propertyStorage);
327     ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
328
329     PropVariantInit(&var);
330     spec.ulKind = PRSPEC_PROPID;
331     U(spec).propid = PID_CODEPAGE;
332     /* check code page before it's been explicitly set */
333     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
334     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
335     ok(var.vt == VT_I2 && U(var).iVal == 1200,
336      "Didn't get expected type or value for property\n");
337     /* Set the code page to ascii */
338     var.vt = VT_I2;
339     U(var).iVal = 1252;
340     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
341     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
342     /* check code page */
343     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
344     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
345     ok(var.vt == VT_I2 && U(var).iVal == 1252,
346      "Didn't get expected type or value for property\n");
347     /* Set code page to Unicode */
348     U(var).iVal = 1200;
349     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
350     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
351     /* check code page */
352     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
353     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
354     ok(var.vt == VT_I2 && U(var).iVal == 1200,
355      "Didn't get expected type or value for property\n");
356     /* Set a string value */
357     spec.ulKind = PRSPEC_PROPID;
358     U(spec).propid = PID_FIRST_USABLE;
359     var.vt = VT_LPSTR;
360     U(var).pszVal = aval;
361     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
362     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
363     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
364     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
365     ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "hi"),
366      "Didn't get expected type or value for property\n");
367     /* This seemingly non-sensical test is to show that the string is indeed
368      * interpreted according to the current system code page, not according to
369      * the property set's code page.  (If the latter were true, the whole
370      * string would be maintained.  As it is, only the first character is.)
371      */
372     U(var).pszVal = (LPSTR)wval;
373     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
374     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
375     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
376     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
377     ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "h"),
378      "Didn't get expected type or value for property\n");
379     /* now that a property's been set, you can't change the code page */
380     spec.ulKind = PRSPEC_PROPID;
381     U(spec).propid = PID_CODEPAGE;
382     var.vt = VT_I2;
383     U(var).iVal = 1200;
384     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
385     ok(hr == STG_E_INVALIDPARAMETER,
386      "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
387
388     IPropertyStorage_Release(propertyStorage);
389     IPropertySetStorage_Release(propSetStorage);
390     IStorage_Release(storage);
391
392     DeleteFileW(fileName);
393
394     /* same tests, but with PROPSETFLAG_ANSI */
395     hr = StgCreateDocfile(fileName,
396      STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
397     ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
398
399     hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
400     ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
401
402     hr = IPropertySetStorage_Create(propSetStorage,
403      &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
404      STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
405      &propertyStorage);
406     ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
407
408     /* check code page before it's been explicitly set */
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 == 1252,
412      "Didn't get expected type or value for property\n");
413     /* Set code page to Unicode */
414     U(var).iVal = 1200;
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 == 1200,
421      "Didn't get expected type or value for property\n");
422     /* This test is commented out for documentation.  It fails under Wine,
423      * and I expect it would under Windows as well, yet it succeeds.  There's
424      * obviously something about string conversion I don't understand.
425      */
426     if(0) {
427     static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 };
428     /* Set code page to 950 (Traditional Chinese) */
429     U(var).iVal = 950;
430     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
431     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
432     /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
433      * Chinese.
434      */
435     spec.ulKind = PRSPEC_PROPID;
436     U(spec).propid = PID_FIRST_USABLE;
437     var.vt = VT_LPSTR;
438     U(var).pszVal = (LPSTR)strVal;
439     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
440     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
441     /* Check returned string */
442     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
443     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
444     ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal),
445      "Didn't get expected type or value for property\n");
446     }
447
448     IPropertyStorage_Release(propertyStorage);
449     IPropertySetStorage_Release(propSetStorage);
450     IStorage_Release(storage);
451
452     DeleteFileW(fileName);
453 }
454
455 static void testFmtId(void)
456 {
457     WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
458         'I','n','f','o','r','m','a','t','i','o','n',0 };
459     WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
460         'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
461         0 };
462     WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
463         'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
464         'c',0 };
465     WCHAR name[32];
466     FMTID fmtid;
467     HRESULT hr;
468
469     if (pFmtIdToPropStgName) {
470     hr = pFmtIdToPropStgName(NULL, name);
471     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
472     hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
473     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
474     hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
475     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
476     ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
477      sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
478     hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
479     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
480     ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
481      sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
482     hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
483     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
484     ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
485      sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
486     hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
487     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
488     ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
489      sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
490     }
491
492     if(pPropStgNameToFmtId) {
493     /* test args first */
494     hr = pPropStgNameToFmtId(NULL, NULL);
495     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
496     hr = pPropStgNameToFmtId(NULL, &fmtid);
497     ok(hr == STG_E_INVALIDNAME, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
498      hr);
499     hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
500     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
501     /* test the known format IDs */
502     hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
503     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
504     ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
505      "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
506     hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
507     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
508     ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
509      "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
510     /* test another GUID */
511     hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
512     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
513     ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
514      "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
515     /* now check case matching */
516     CharUpperW(szDocSummaryInfo + 1);
517     hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
518     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
519     ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
520      "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
521     CharUpperW(szIID_IPropSetStg + 1);
522     hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
523     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
524     ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
525      "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
526     }
527 }
528
529 START_TEST(stg_prop)
530 {
531     init_function_pointers();
532     testProps();
533     testCodepage();
534     testFmtId();
535 }