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