ole32: Fix test failure on win2000+.
[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
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 = 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 = 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 %d)\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, "Didn't get expected type for property (%u)\n", var.vt);
412     /* Set code page to Unicode */
413     U(var).iVal = 1200;
414     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
415     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
416     /* check code page */
417     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
418     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
419     ok(var.vt == VT_I2 && U(var).iVal == 1200,
420      "Didn't get expected type or value for property\n");
421     /* This test is commented out for documentation.  It fails under Wine,
422      * and I expect it would under Windows as well, yet it succeeds.  There's
423      * obviously something about string conversion I don't understand.
424      */
425     if(0) {
426     static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 };
427     /* Set code page to 950 (Traditional Chinese) */
428     U(var).iVal = 950;
429     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
430     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
431     /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
432      * Chinese.
433      */
434     spec.ulKind = PRSPEC_PROPID;
435     U(spec).propid = PID_FIRST_USABLE;
436     var.vt = VT_LPSTR;
437     U(var).pszVal = (LPSTR)strVal;
438     hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
439     ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
440     /* Check returned string */
441     hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
442     ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
443     ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal),
444      "Didn't get expected type or value for property\n");
445     }
446
447     IPropertyStorage_Release(propertyStorage);
448     IPropertySetStorage_Release(propSetStorage);
449     IStorage_Release(storage);
450
451     DeleteFileW(fileName);
452 }
453
454 static void testFmtId(void)
455 {
456     WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
457         'I','n','f','o','r','m','a','t','i','o','n',0 };
458     WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
459         'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
460         0 };
461     WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
462         'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
463         'c',0 };
464     WCHAR name[32];
465     FMTID fmtid;
466     HRESULT hr;
467
468     if (pFmtIdToPropStgName) {
469     hr = pFmtIdToPropStgName(NULL, name);
470     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
471     hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
472     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
473     hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
474     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
475     ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
476      sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
477     hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
478     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
479     ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
480      sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
481     hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
482     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
483     ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
484      sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
485     hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
486     ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
487     ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
488      sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
489     }
490
491     if(pPropStgNameToFmtId) {
492     /* test args first */
493     hr = pPropStgNameToFmtId(NULL, NULL);
494     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
495     hr = pPropStgNameToFmtId(NULL, &fmtid);
496     ok(hr == STG_E_INVALIDNAME, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
497      hr);
498     hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
499     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
500     /* test the known format IDs */
501     hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
502     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
503     ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
504      "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
505     hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
506     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
507     ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
508      "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
509     /* test another GUID */
510     hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
511     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
512     ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
513      "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
514     /* now check case matching */
515     CharUpperW(szDocSummaryInfo + 1);
516     hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
517     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
518     ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
519      "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
520     CharUpperW(szIID_IPropSetStg + 1);
521     hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
522     ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
523     ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
524      "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
525     }
526 }
527
528 START_TEST(stg_prop)
529 {
530     init_function_pointers();
531     testProps();
532     testCodepage();
533     testFmtId();
534 }