dmscript: Merge the IClassFactory implementations.
[wine/testsucceed.git] / dlls / ole32 / tests / stg_prop.c
blobdb4c14246a2bcaf04c3670f1ca8adf1b8741a91f
1 /* IPropertyStorage unit tests
2 * Copyright 2005 Juan Lang
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.
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.
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
18 #include <stdio.h>
19 #define COBJMACROS
20 #include "objbase.h"
21 #include "wine/test.h"
22 #include "initguid.h"
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);
29 #ifndef PID_BEHAVIOR
30 #define PID_BEHAVIOR 0x80000003
31 #endif
33 static HRESULT (WINAPI *pFmtIdToPropStgName)(const FMTID *, LPOLESTR);
34 static HRESULT (WINAPI *pPropStgNameToFmtId)(const LPOLESTR, FMTID *);
35 static HRESULT (WINAPI *pStgCreatePropSetStg)(IStorage *, DWORD, IPropertySetStorage **);
37 static void init_function_pointers(void)
39 HMODULE hmod = GetModuleHandleA("ole32.dll");
40 pFmtIdToPropStgName = (void*)GetProcAddress(hmod, "FmtIdToPropStgName");
41 pPropStgNameToFmtId = (void*)GetProcAddress(hmod, "PropStgNameToFmtId");
42 pStgCreatePropSetStg = (void*)GetProcAddress(hmod, "StgCreatePropSetStg");
44 /* FIXME: this creates an ANSI storage, try to find conditions under which
45 * Unicode translation fails
47 static void testProps(void)
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 } };
65 if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
66 return;
68 DeleteFileW(filename);
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);
74 if(!pStgCreatePropSetStg)
76 IStorage_Release(storage);
77 DeleteFileW(filename);
78 return;
80 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
81 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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(hr == S_OK, "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");
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);
218 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
219 ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
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?
254 IPropertyStorage_Release(propertyStorage);
255 propertyStorage = NULL;
256 IPropertySetStorage_Release(propSetStorage);
257 propSetStorage = NULL;
258 IStorage_Release(storage);
259 storage = NULL;
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);
266 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
267 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
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);
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);
290 IPropertyStorage_Release(propertyStorage);
291 IPropertySetStorage_Release(propSetStorage);
292 IStorage_Release(storage);
294 DeleteFileW(filename);
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);
301 if(!pStgCreatePropSetStg)
303 IStorage_Release(storage);
304 DeleteFileW(filename);
305 return;
307 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
308 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
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);
316 spec.ulKind = PRSPEC_PROPID;
317 U(spec).propid = PID_FIRST_USABLE;
318 var.vt = VT_I4;
319 U(var).lVal = 1;
320 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
321 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
323 hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
324 ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
326 IPropertyStorage_Release(propertyStorage);
327 IPropertySetStorage_Release(propSetStorage);
328 IStorage_Release(storage);
329 propertyStorage = NULL;
331 /* now open it again */
332 hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
333 NULL, 0, &storage);
334 ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);
336 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
337 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
339 hr = IPropertySetStorage_Open(propSetStorage, &anyOldGuid,
340 STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
341 ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
343 spec.ulKind = PRSPEC_PROPID;
344 U(spec).propid = PID_FIRST_USABLE;
345 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
346 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
348 ok(var.vt == VT_I4 && U(var).lVal == 1,
349 "Didn't get expected type or value for property (got type %d, value %d)\n",
350 var.vt, U(var).lVal);
352 IPropertyStorage_Release(propertyStorage);
353 IPropertySetStorage_Release(propSetStorage);
354 IStorage_Release(storage);
356 DeleteFileW(filename);
359 static void testCodepage(void)
361 static const WCHAR szDot[] = { '.',0 };
362 static const WCHAR szPrefix[] = { 's','t','g',0 };
363 static CHAR aval[] = "hi";
364 static WCHAR wval[] = { 'h','i',0 };
365 HRESULT hr;
366 IStorage *storage = NULL;
367 IPropertySetStorage *propSetStorage = NULL;
368 IPropertyStorage *propertyStorage = NULL;
369 PROPSPEC spec;
370 PROPVARIANT var;
371 WCHAR fileName[MAX_PATH];
373 if(!GetTempFileNameW(szDot, szPrefix, 0, fileName))
374 return;
376 hr = StgCreateDocfile(fileName,
377 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
378 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
380 if(!pStgCreatePropSetStg)
382 IStorage_Release(storage);
383 DeleteFileW(fileName);
384 return;
386 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
387 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
389 hr = IPropertySetStorage_Create(propSetStorage,
390 &FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT,
391 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
392 &propertyStorage);
393 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
395 PropVariantInit(&var);
396 spec.ulKind = PRSPEC_PROPID;
397 U(spec).propid = PID_CODEPAGE;
398 /* check code page before it's been explicitly set */
399 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
400 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
401 ok(var.vt == VT_I2 && U(var).iVal == 1200,
402 "Didn't get expected type or value for property\n");
403 /* Set the code page to ascii */
404 var.vt = VT_I2;
405 U(var).iVal = 1252;
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 == 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 /* Set a string value */
423 spec.ulKind = PRSPEC_PROPID;
424 U(spec).propid = PID_FIRST_USABLE;
425 var.vt = VT_LPSTR;
426 U(var).pszVal = aval;
427 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
428 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
429 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
430 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
431 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "hi"),
432 "Didn't get expected type or value for property\n");
433 PropVariantClear(&var);
434 /* This seemingly non-sensical test is to show that the string is indeed
435 * interpreted according to the current system code page, not according to
436 * the property set's code page. (If the latter were true, the whole
437 * string would be maintained. As it is, only the first character is.)
439 var.vt = VT_LPSTR;
440 U(var).pszVal = (LPSTR)wval;
441 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
442 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
443 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
444 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
445 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "h"),
446 "Didn't get expected type or value for property\n");
447 PropVariantClear(&var);
449 /* now that a property's been set, you can't change the code page */
450 spec.ulKind = PRSPEC_PROPID;
451 U(spec).propid = PID_CODEPAGE;
452 var.vt = VT_I2;
453 U(var).iVal = 1200;
454 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
455 ok(hr == STG_E_INVALIDPARAMETER,
456 "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
458 IPropertyStorage_Release(propertyStorage);
459 IPropertySetStorage_Release(propSetStorage);
460 IStorage_Release(storage);
462 DeleteFileW(fileName);
464 /* same tests, but with PROPSETFLAG_ANSI */
465 hr = StgCreateDocfile(fileName,
466 STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
467 ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
469 hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
470 ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
472 hr = IPropertySetStorage_Create(propSetStorage,
473 &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
474 STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
475 &propertyStorage);
476 ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
478 /* check code page before it's been explicitly set */
479 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
480 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
481 ok(var.vt == VT_I2, "Didn't get expected type for property (%u)\n", var.vt);
482 /* Set code page to Unicode */
483 U(var).iVal = 1200;
484 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
485 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
486 /* check code page */
487 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
488 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
489 ok(var.vt == VT_I2 && U(var).iVal == 1200,
490 "Didn't get expected type or value for property\n");
491 /* This test is commented out for documentation. It fails under Wine,
492 * and I expect it would under Windows as well, yet it succeeds. There's
493 * obviously something about string conversion I don't understand.
495 if(0) {
496 static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 };
497 /* Set code page to 950 (Traditional Chinese) */
498 U(var).iVal = 950;
499 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
500 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
501 /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
502 * Chinese.
504 spec.ulKind = PRSPEC_PROPID;
505 U(spec).propid = PID_FIRST_USABLE;
506 var.vt = VT_LPSTR;
507 U(var).pszVal = (LPSTR)strVal;
508 hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
509 ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
510 /* Check returned string */
511 hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
512 ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
513 ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal),
514 "Didn't get expected type or value for property\n");
517 IPropertyStorage_Release(propertyStorage);
518 IPropertySetStorage_Release(propSetStorage);
519 IStorage_Release(storage);
521 DeleteFileW(fileName);
524 static void testFmtId(void)
526 WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
527 'I','n','f','o','r','m','a','t','i','o','n',0 };
528 WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
529 'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
530 0 };
531 WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
532 'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
533 'c',0 };
534 WCHAR name[32];
535 FMTID fmtid;
536 HRESULT hr;
538 if (pFmtIdToPropStgName) {
539 hr = pFmtIdToPropStgName(NULL, name);
540 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
541 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
542 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
543 hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
544 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
545 ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
546 sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
547 hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
548 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
549 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
550 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
551 hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
552 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
553 ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
554 sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
555 hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
556 ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
557 ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
558 sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
561 if(pPropStgNameToFmtId) {
562 /* test args first */
563 hr = pPropStgNameToFmtId(NULL, NULL);
564 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
565 hr = pPropStgNameToFmtId(NULL, &fmtid);
566 ok(hr == STG_E_INVALIDNAME, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
567 hr);
568 hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
569 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
570 /* test the known format IDs */
571 hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
572 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
573 ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
574 "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
575 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
576 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
577 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
578 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
579 /* test another GUID */
580 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
581 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
582 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
583 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
584 /* now check case matching */
585 CharUpperW(szDocSummaryInfo + 1);
586 hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
587 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
588 ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
589 "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
590 CharUpperW(szIID_IPropSetStg + 1);
591 hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
592 ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
593 ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
594 "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
598 START_TEST(stg_prop)
600 init_function_pointers();
601 testProps();
602 testCodepage();
603 testFmtId();