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