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