stg_prop.c 27.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* IPropertyStorage unit tests
 * Copyright 2005 Juan Lang
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 20 21 22
 */
#include <stdio.h>
#define COBJMACROS
#include "objbase.h"
#include "wine/test.h"

23 24 25 26
#ifndef PID_BEHAVIOR
#define PID_BEHAVIOR 0x80000003
#endif

27 28 29
static HRESULT (WINAPI *pFmtIdToPropStgName)(const FMTID *, LPOLESTR);
static HRESULT (WINAPI *pPropStgNameToFmtId)(const LPOLESTR, FMTID *);
static HRESULT (WINAPI *pStgCreatePropSetStg)(IStorage *, DWORD, IPropertySetStorage **);
30 31
static HRESULT (WINAPI *pStgCreatePropStg)(IUnknown *, REFFMTID, const CLSID *, DWORD, DWORD, IPropertyStorage **);
static HRESULT (WINAPI *pStgOpenPropStg)(IUnknown *, REFFMTID, DWORD, DWORD, IPropertyStorage **);
32 33 34 35

static void init_function_pointers(void)
{
    HMODULE hmod = GetModuleHandleA("ole32.dll");
36 37 38
    pFmtIdToPropStgName = (void*)GetProcAddress(hmod, "FmtIdToPropStgName");
    pPropStgNameToFmtId = (void*)GetProcAddress(hmod, "PropStgNameToFmtId");
    pStgCreatePropSetStg = (void*)GetProcAddress(hmod, "StgCreatePropSetStg");
39 40
    pStgCreatePropStg = (void*)GetProcAddress(hmod, "StgCreatePropStg");
    pStgOpenPropStg = (void*)GetProcAddress(hmod, "StgOpenPropStg");
41
}
42

43
/* FIXME: this creates an ANSI storage, try to find conditions under which
44 45
 * Unicode translation fails
 */
46
static void testPropsHelper(IPropertySetStorage **propSetStorage)
47 48 49
{
    static const WCHAR szDot[] = { '.',0 };
    static const WCHAR szPrefix[] = { 's','t','g',0 };
50 51
    static const WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
        'I','n','f','o','r','m','a','t','i','o','n',0 };
52 53
    static WCHAR propName[] = { 'p','r','o','p',0 };
    static char val[] = "l33t auth0r";
54 55 56
    WCHAR filename[MAX_PATH];
    HRESULT hr;
    IStorage *storage = NULL;
57
    IStream *stream = NULL;
58 59 60
    IPropertyStorage *propertyStorage = NULL;
    PROPSPEC spec;
    PROPVARIANT var;
61 62
    CLIPDATA clipdata;
    unsigned char clipcontent[] = "foobar";
63 64
    GUID anyOldGuid = { 0x12345678,0xdead,0xbeef, {
     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } };
65

66 67 68 69 70
    if(propSetStorage)
        trace("Testing property storage with a set...\n");
    else
        trace("Testing property storage without a set...\n");

71 72 73 74 75 76 77
    if(!GetTempFileNameW(szDot, szPrefix, 0, filename))
        return;

    DeleteFileW(filename);

    hr = StgCreateDocfile(filename,
     STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
78
    ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
79

80
    if(propSetStorage)
81
    {
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        if(!pStgCreatePropSetStg)
        {
            IStorage_Release(storage);
            DeleteFileW(filename);
            return;
        }
        hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
        ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);

        hr = IPropertySetStorage_Create(*propSetStorage,
         &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
         STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
         &propertyStorage);
        ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
    }
    else
    {
        hr = IStorage_CreateStream(storage, szSummaryInfo,
         STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
        ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);

        if(!pStgCreatePropStg)
        {
            IStorage_Release(storage);
            IUnknown_Release(stream);
            DeleteFileW(filename);
            return;
        }
        hr = pStgCreatePropStg((IUnknown *)stream, &FMTID_SummaryInformation,
         NULL, PROPSETFLAG_ANSI, 0, &propertyStorage);
        ok(hr == S_OK, "StgCreatePropStg failed: 0x%08x\n", hr);
113
    }
114 115

    hr = IPropertyStorage_WriteMultiple(propertyStorage, 0, NULL, NULL, 0);
116
    ok(hr == S_OK, "WriteMultiple with 0 args failed: 0x%08x\n", hr);
117
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, NULL, NULL, 0);
118
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
119 120 121 122 123 124 125 126

    /* test setting one that I can't set */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_DICTIONARY;
    var.vt = VT_I4;
    U(var).lVal = 1;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
    ok(hr == STG_E_INVALIDPARAMETER,
127
     "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
128 129 130

    /* test setting one by name with an invalid propidNameFirst */
    spec.ulKind = PRSPEC_LPWSTR;
131
    U(spec).lpwstr = propName;
132 133 134
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
     PID_DICTIONARY);
    ok(hr == STG_E_INVALIDPARAMETER,
135
     "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
136 137 138 139 140 141 142

    /* test setting behavior (case-sensitive) */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_BEHAVIOR;
    U(var).lVal = 1;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
    ok(hr == STG_E_INVALIDPARAMETER,
143
     "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
144 145 146 147 148 149

    /* set one by value.. */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    U(var).lVal = 1;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
150
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
151

152
    /* set one by name */
153
    spec.ulKind = PRSPEC_LPWSTR;
154
    U(spec).lpwstr = propName;
155 156 157
    U(var).lVal = 2;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var,
     PID_FIRST_USABLE);
158
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
159

160 161 162 163
    /* set a string value */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PIDSI_AUTHOR;
    var.vt = VT_LPSTR;
164
    U(var).pszVal = val;
165
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
166
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
167

168 169 170 171 172 173 174 175 176
    /* set a clipboard value */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PIDSI_THUMBNAIL;
    var.vt = VT_CF;
    clipdata.cbSize = sizeof clipcontent + sizeof (ULONG);
    clipdata.ulClipFmt = CF_ENHMETAFILE;
    clipdata.pClipData = clipcontent;
    U(var).pclipdata = &clipdata;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
177
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
178 179


180 181
    /* check reading */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 0, NULL, NULL);
182
    ok(hr == S_FALSE, "ReadMultiple with 0 args failed: 0x%08x\n", hr);
183
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, NULL, NULL);
184
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
185 186 187 188
    /* read by propid */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
189
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
190
    ok(var.vt == VT_I4 && U(var).lVal == 1,
191
     "Didn't get expected type or value for property (got type %d, value %d)\n",
192 193 194
     var.vt, U(var).lVal);
    /* read by name */
    spec.ulKind = PRSPEC_LPWSTR;
195
    U(spec).lpwstr = propName;
196
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
197
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
198
    ok(var.vt == VT_I4 && U(var).lVal == 2,
199
     "Didn't get expected type or value for property (got type %d, value %d)\n",
200
     var.vt, U(var).lVal);
201 202 203 204
    /* read string value */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PIDSI_AUTHOR;
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
205
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
206 207 208
    ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
     "Didn't get expected type or value for property (got type %d, value %s)\n",
     var.vt, U(var).pszVal);
209
    PropVariantClear(&var);
210

211 212 213 214
    /* read clipboard format */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PIDSI_THUMBNAIL;
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
215
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
216 217 218 219 220 221 222 223 224
    ok(var.vt == VT_CF, "variant type wrong\n");
    ok(U(var).pclipdata->ulClipFmt == CF_ENHMETAFILE,
        "clipboard type wrong\n");
    ok(U(var).pclipdata->cbSize == sizeof clipcontent + sizeof (ULONG),
        "clipboard size wrong\n");
    ok(!memcmp(U(var).pclipdata->pClipData, clipcontent, sizeof clipcontent),
        "clipboard contents wrong\n");
    ok(S_OK == PropVariantClear(&var), "failed to clear variant\n");

225 226
    /* check deleting */
    hr = IPropertyStorage_DeleteMultiple(propertyStorage, 0, NULL);
227
    ok(hr == S_OK, "DeleteMultiple with 0 args failed: 0x%08x\n", hr);
228
    hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, NULL);
229
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
230 231 232 233 234
    /* contrary to what the docs say, you can't delete the dictionary */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_DICTIONARY;
    hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
    ok(hr == STG_E_INVALIDPARAMETER,
235
     "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
236 237 238
    /* now delete the first value.. */
    U(spec).propid = PID_FIRST_USABLE;
    hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec);
239
    ok(hr == S_OK, "DeleteMultiple failed: 0x%08x\n", hr);
240 241
    /* and check that it's no longer readable */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
242
    ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
243

244
    hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
245
    ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
246 247 248 249 250

    /* check reverting */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
251
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
252
    hr = IPropertyStorage_Revert(propertyStorage);
253
    ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
254 255
    /* now check that it's still not there */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
256
    ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr);
257 258 259 260 261 262
    /* set an integer value again */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    var.vt = VT_I4;
    U(var).lVal = 1;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
263
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
264 265
    /* commit it */
    hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
266
    ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);
267 268
    /* set it to a string value */
    var.vt = VT_LPSTR;
269
    U(var).pszVal = val;
270
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
271
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
272 273
    /* revert it */
    hr = IPropertyStorage_Revert(propertyStorage);
274
    ok(hr == S_OK, "Revert failed: 0x%08x\n", hr);
275 276 277 278
    /* Oddly enough, there's no guarantee that a successful revert actually
     * implies the value wasn't saved.  Maybe transactional mode needs to be
     * used for that?
     */
279 280

    IPropertyStorage_Release(propertyStorage);
281
    if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
282
    IStorage_Release(storage);
283
    if(stream) IUnknown_Release(stream);
284 285 286 287

    /* now open it again */
    hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
     NULL, 0, &storage);
288
    ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);
289

290 291 292 293
    if(propSetStorage)
    {
        hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
        ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
294

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
        hr = IPropertySetStorage_Open(*propSetStorage, &FMTID_SummaryInformation,
         STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
        ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
    }
    else
    {
        hr = IStorage_OpenStream(storage, szSummaryInfo,
         0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
        ok(hr == S_OK, "IStorage_OpenStream failed: 0x%08x\n", hr);

        if(!pStgOpenPropStg)
        {
            IStorage_Release(storage);
            IUnknown_Release(stream);
            DeleteFileW(filename);
            return;
        }
        hr = pStgOpenPropStg((IUnknown *)stream, &FMTID_SummaryInformation,
         PROPSETFLAG_DEFAULT, 0, &propertyStorage);
        ok(hr == S_OK, "StgOpenPropStg failed: 0x%08x\n", hr);
    }
316 317 318

    /* check properties again */
    spec.ulKind = PRSPEC_LPWSTR;
319
    U(spec).lpwstr = propName;
320
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
321
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
322
    ok(var.vt == VT_I4 && U(var).lVal == 2,
323
     "Didn't get expected type or value for property (got type %d, value %d)\n",
324 325 326 327
     var.vt, U(var).lVal);
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PIDSI_AUTHOR;
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
328
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
329 330 331
    ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val),
     "Didn't get expected type or value for property (got type %d, value %s)\n",
     var.vt, U(var).pszVal);
332
    PropVariantClear(&var);
333

334
    IPropertyStorage_Release(propertyStorage);
335
    if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
336
    IStorage_Release(storage);
337
    if(stream) IUnknown_Release(stream);
338 339

    DeleteFileW(filename);
340 341 342 343 344 345

    /* Test creating a property set storage with a random GUID */
    hr = StgCreateDocfile(filename,
     STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
    ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);

346
    if(propSetStorage)
347
    {
348 349 350 351 352 353 354 355
        hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
        ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);

        hr = IPropertySetStorage_Create(*propSetStorage,
         &anyOldGuid, NULL, PROPSETFLAG_ANSI,
         STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
         &propertyStorage);
        ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
356
    }
357 358 359 360 361
    else
    {
        hr = IStorage_CreateStream(storage, szSummaryInfo,
         STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
        ok(hr == S_OK, "IStorage_CreateStream failed: 0x%08x\n", hr);
362

363 364 365 366
        hr = pStgCreatePropStg((IUnknown *)stream, &anyOldGuid, NULL,
         PROPSETFLAG_DEFAULT, 0, &propertyStorage);
        ok(hr == S_OK, "StgCreatePropStg failed: 0x%08x\n", hr);
    }
367 368 369

    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
370
    var.vt = VT_I4;
371 372 373 374
    U(var).lVal = 1;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);

375 376 377
    hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT);
    ok(hr == S_OK, "Commit failed: 0x%08x\n", hr);

378
    IPropertyStorage_Release(propertyStorage);
379
    if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
380
    IStorage_Release(storage);
381
    if(stream) IUnknown_Release(stream);
382 383 384 385 386 387

    /* now open it again */
    hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
     NULL, 0, &storage);
    ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr);

388 389 390 391 392 393 394 395 396 397 398 399 400 401
    if(propSetStorage)
    {
        hr = pStgCreatePropSetStg(storage, 0, propSetStorage);
        ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);

        hr = IPropertySetStorage_Open(*propSetStorage, &anyOldGuid,
         STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage);
        ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr);
    }
    else
    {
        hr = IStorage_OpenStream(storage, szSummaryInfo,
         0, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
        ok(hr == S_OK, "IStorage_OpenStream failed: 0x%08x\n", hr);
402

403 404 405 406
        hr = pStgOpenPropStg((IUnknown *)stream, &anyOldGuid,
         PROPSETFLAG_DEFAULT, 0, &propertyStorage);
        ok(hr == S_OK, "StgOpenPropStg failed: 0x%08x\n", hr);
    }
407 408 409 410

    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
411 412 413 414 415
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);

    ok(var.vt == VT_I4 && U(var).lVal == 1,
     "Didn't get expected type or value for property (got type %d, value %d)\n",
     var.vt, U(var).lVal);
416 417

    IPropertyStorage_Release(propertyStorage);
418
    if(propSetStorage) IPropertySetStorage_Release(*propSetStorage);
419
    IStorage_Release(storage);
420
    if(stream) IUnknown_Release(stream);
421 422

    DeleteFileW(filename);
423 424
}

425 426 427 428 429 430 431 432
static void testProps(void)
{
    IPropertySetStorage *propSetStorage = NULL;

    testPropsHelper(&propSetStorage);
    testPropsHelper(NULL);
}

433
static void testCodepage(void)
434 435 436
{
    static const WCHAR szDot[] = { '.',0 };
    static const WCHAR szPrefix[] = { 's','t','g',0 };
437
    static CHAR aval[] = "hi";
438
    static WCHAR wval[] = { 'h','i',0 };
439 440 441 442 443 444 445 446 447 448 449 450 451
    HRESULT hr;
    IStorage *storage = NULL;
    IPropertySetStorage *propSetStorage = NULL;
    IPropertyStorage *propertyStorage = NULL;
    PROPSPEC spec;
    PROPVARIANT var;
    WCHAR fileName[MAX_PATH];

    if(!GetTempFileNameW(szDot, szPrefix, 0, fileName))
        return;

    hr = StgCreateDocfile(fileName,
     STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
452
    ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
453

454 455 456 457 458 459
    if(!pStgCreatePropSetStg)
    {
        IStorage_Release(storage);
        DeleteFileW(fileName);
        return;
    }
460
    hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
461
    ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
462 463 464 465 466

    hr = IPropertySetStorage_Create(propSetStorage,
     &FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT,
     STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
     &propertyStorage);
467
    ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
468 469 470 471 472 473

    PropVariantInit(&var);
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_CODEPAGE;
    /* check code page before it's been explicitly set */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
474
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
475 476 477 478 479 480
    ok(var.vt == VT_I2 && U(var).iVal == 1200,
     "Didn't get expected type or value for property\n");
    /* Set the code page to ascii */
    var.vt = VT_I2;
    U(var).iVal = 1252;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
481
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
482 483
    /* check code page */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
484
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
485 486 487 488 489
    ok(var.vt == VT_I2 && U(var).iVal == 1252,
     "Didn't get expected type or value for property\n");
    /* Set code page to Unicode */
    U(var).iVal = 1200;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
490
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
491 492
    /* check code page */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
493
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
494 495 496 497 498 499
    ok(var.vt == VT_I2 && U(var).iVal == 1200,
     "Didn't get expected type or value for property\n");
    /* Set a string value */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    var.vt = VT_LPSTR;
500
    U(var).pszVal = aval;
501
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
502
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
503
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
504
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
505 506
    ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "hi"),
     "Didn't get expected type or value for property\n");
507
    PropVariantClear(&var);
508 509 510 511 512
    /* This seemingly non-sensical test is to show that the string is indeed
     * interpreted according to the current system code page, not according to
     * the property set's code page.  (If the latter were true, the whole
     * string would be maintained.  As it is, only the first character is.)
     */
513
    var.vt = VT_LPSTR;
514 515
    U(var).pszVal = (LPSTR)wval;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
516
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
517
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
518
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
519 520
    ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "h"),
     "Didn't get expected type or value for property\n");
521 522
    PropVariantClear(&var);

523 524 525 526 527 528 529
    /* now that a property's been set, you can't change the code page */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_CODEPAGE;
    var.vt = VT_I2;
    U(var).iVal = 1200;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
    ok(hr == STG_E_INVALIDPARAMETER,
530
     "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr);
531 532 533 534 535 536 537 538 539 540

    IPropertyStorage_Release(propertyStorage);
    IPropertySetStorage_Release(propSetStorage);
    IStorage_Release(storage);

    DeleteFileW(fileName);

    /* same tests, but with PROPSETFLAG_ANSI */
    hr = StgCreateDocfile(fileName,
     STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage);
541
    ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr);
542

543
    hr = pStgCreatePropSetStg(storage, 0, &propSetStorage);
544
    ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr);
545 546 547 548 549

    hr = IPropertySetStorage_Create(propSetStorage,
     &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI,
     STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
     &propertyStorage);
550
    ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr);
551 552 553

    /* check code page before it's been explicitly set */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
554
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
555
    ok(var.vt == VT_I2, "Didn't get expected type for property (%u)\n", var.vt);
556 557 558
    /* Set code page to Unicode */
    U(var).iVal = 1200;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
559
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
560 561
    /* check code page */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
562
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
563 564 565 566 567 568
    ok(var.vt == VT_I2 && U(var).iVal == 1200,
     "Didn't get expected type or value for property\n");
    /* This test is commented out for documentation.  It fails under Wine,
     * and I expect it would under Windows as well, yet it succeeds.  There's
     * obviously something about string conversion I don't understand.
     */
569
    if(0) {
570
    static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 };
571 572 573
    /* Set code page to 950 (Traditional Chinese) */
    U(var).iVal = 950;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
574
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
575 576 577 578 579 580 581 582
    /* Try writing an invalid string: lead byte 0x81 is unused in Traditional
     * Chinese.
     */
    spec.ulKind = PRSPEC_PROPID;
    U(spec).propid = PID_FIRST_USABLE;
    var.vt = VT_LPSTR;
    U(var).pszVal = (LPSTR)strVal;
    hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0);
583
    ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr);
584 585
    /* Check returned string */
    hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var);
586
    ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr);
587
    ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal),
588
     "Didn't get expected type or value for property\n");
589
    }
590 591 592 593 594 595 596 597

    IPropertyStorage_Release(propertyStorage);
    IPropertySetStorage_Release(propSetStorage);
    IStorage_Release(storage);

    DeleteFileW(fileName);
}

598 599 600 601 602 603 604 605 606 607 608 609 610 611
static void testFmtId(void)
{
    WCHAR szSummaryInfo[] = { 5,'S','u','m','m','a','r','y',
        'I','n','f','o','r','m','a','t','i','o','n',0 };
    WCHAR szDocSummaryInfo[] = { 5,'D','o','c','u','m','e','n','t',
        'S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',
        0 };
    WCHAR szIID_IPropSetStg[] = { 5,'0','j','a','a','a','a','a',
        'a','A','a','a','a','a','a','d','a','A','a','a','a','a','a','a','a','G',
        'c',0 };
    WCHAR name[32];
    FMTID fmtid;
    HRESULT hr;

612 613
    if (pFmtIdToPropStgName) {
    hr = pFmtIdToPropStgName(NULL, name);
614
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
615
    hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, NULL);
616
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
617
    hr = pFmtIdToPropStgName(&FMTID_SummaryInformation, name);
618
    ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
619 620
    ok(!memcmp(name, szSummaryInfo, (lstrlenW(szSummaryInfo) + 1) *
     sizeof(WCHAR)), "Got wrong name for FMTID_SummaryInformation\n");
621
    hr = pFmtIdToPropStgName(&FMTID_DocSummaryInformation, name);
622
    ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
623 624
    ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
     sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
625
    hr = pFmtIdToPropStgName(&FMTID_UserDefinedProperties, name);
626
    ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
627 628
    ok(!memcmp(name, szDocSummaryInfo, (lstrlenW(szDocSummaryInfo) + 1) *
     sizeof(WCHAR)), "Got wrong name for FMTID_DocSummaryInformation\n");
629
    hr = pFmtIdToPropStgName(&IID_IPropertySetStorage, name);
630
    ok(hr == S_OK, "FmtIdToPropStgName failed: 0x%08x\n", hr);
631 632
    ok(!memcmp(name, szIID_IPropSetStg, (lstrlenW(szIID_IPropSetStg) + 1) *
     sizeof(WCHAR)), "Got wrong name for IID_IPropertySetStorage\n");
633
    }
634

635
    if(pPropStgNameToFmtId) {
636
    /* test args first */
637
    hr = pPropStgNameToFmtId(NULL, NULL);
638
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
639
    hr = pPropStgNameToFmtId(NULL, &fmtid);
640
    ok(hr == STG_E_INVALIDNAME, "Expected STG_E_INVALIDNAME, got 0x%08x\n",
641
     hr);
642
    hr = pPropStgNameToFmtId(szDocSummaryInfo, NULL);
643
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr);
644
    /* test the known format IDs */
645
    hr = pPropStgNameToFmtId(szSummaryInfo, &fmtid);
646
    ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
647 648
    ok(!memcmp(&fmtid, &FMTID_SummaryInformation, sizeof(fmtid)),
     "Got unexpected FMTID, expected FMTID_SummaryInformation\n");
649
    hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
650
    ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
651 652 653
    ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
     "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
    /* test another GUID */
654
    hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
655
    ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
656 657 658 659
    ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
     "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
    /* now check case matching */
    CharUpperW(szDocSummaryInfo + 1);
660
    hr = pPropStgNameToFmtId(szDocSummaryInfo, &fmtid);
661
    ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
662 663 664
    ok(!memcmp(&fmtid, &FMTID_DocSummaryInformation, sizeof(fmtid)),
     "Got unexpected FMTID, expected FMTID_DocSummaryInformation\n");
    CharUpperW(szIID_IPropSetStg + 1);
665
    hr = pPropStgNameToFmtId(szIID_IPropSetStg, &fmtid);
666
    ok(hr == S_OK, "PropStgNameToFmtId failed: 0x%08x\n", hr);
667 668
    ok(!memcmp(&fmtid, &IID_IPropertySetStorage, sizeof(fmtid)),
     "Got unexpected FMTID, expected IID_IPropertySetStorage\n");
669
    }
670
}
671

672 673
START_TEST(stg_prop)
{
674
    init_function_pointers();
675
    testProps();
676
    testCodepage();
677
    testFmtId();
678
}