format.c 107 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (C) 2005 Mike McCormack for CodeWeavers
 * Copyright (C) 2005 Aric Stewart for CodeWeavers
 *
 * A test program for MSI record formatting
 *
 * 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
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23
 */

#include <stdio.h>
#include <windows.h>
24
#include <shlwapi.h>
25 26 27 28 29
#include <msi.h>
#include <msiquery.h>

#include "wine/test.h"

30
static const char msifile[] = "winetest-format.msi";
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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

static UINT run_query( MSIHANDLE hdb, const char *query )
{
    MSIHANDLE hview = 0;
    UINT r;

    r = MsiDatabaseOpenView(hdb, query, &hview);
    if( r != ERROR_SUCCESS )
        return r;

    r = MsiViewExecute(hview, 0);
    if( r == ERROR_SUCCESS )
        r = MsiViewClose(hview);
    MsiCloseHandle(hview);
    return r;
}

static UINT create_feature_table( MSIHANDLE hdb )
{
    return run_query( hdb,
            "CREATE TABLE `Feature` ( "
            "`Feature` CHAR(38) NOT NULL, "
            "`Feature_Parent` CHAR(38), "
            "`Title` CHAR(64), "
            "`Description` CHAR(255), "
            "`Display` SHORT NOT NULL, "
            "`Level` SHORT NOT NULL, "
            "`Directory_` CHAR(72), "
            "`Attributes` SHORT NOT NULL "
            "PRIMARY KEY `Feature`)" );
}

static UINT create_component_table( MSIHANDLE hdb )
{
    return run_query( hdb,
            "CREATE TABLE `Component` ( "
            "`Component` CHAR(72) NOT NULL, "
            "`ComponentId` CHAR(38), "
            "`Directory_` CHAR(72) NOT NULL, "
            "`Attributes` SHORT NOT NULL, "
            "`Condition` CHAR(255), "
            "`KeyPath` CHAR(72) "
            "PRIMARY KEY `Component`)" );
}

static UINT create_feature_components_table( MSIHANDLE hdb )
{
    return run_query( hdb,
            "CREATE TABLE `FeatureComponents` ( "
            "`Feature_` CHAR(38) NOT NULL, "
            "`Component_` CHAR(72) NOT NULL "
            "PRIMARY KEY `Feature_`, `Component_` )" );
}

static UINT create_file_table( MSIHANDLE hdb )
{
    return run_query( hdb,
            "CREATE TABLE `File` ("
            "`File` CHAR(72) NOT NULL, "
            "`Component_` CHAR(72) NOT NULL, "
            "`FileName` CHAR(255) NOT NULL, "
            "`FileSize` LONG NOT NULL, "
            "`Version` CHAR(72), "
            "`Language` CHAR(20), "
            "`Attributes` SHORT, "
            "`Sequence` SHORT NOT NULL "
            "PRIMARY KEY `File`)" );
}

static UINT create_custom_action_table( MSIHANDLE hdb )
{
    return run_query( hdb,
            "CREATE TABLE `CustomAction` ("
            "`Action` CHAR(72) NOT NULL, "
            "`Type` SHORT NOT NULL, "
            "`Source` CHAR(75), "
            "`Target` CHAR(255) "
            "PRIMARY KEY `Action`)" );
}

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
#define make_add_entry(type, qtext) \
    static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
    { \
        char insert[] = qtext; \
        char *query; \
        UINT sz, r; \
        sz = strlen(values) + sizeof insert; \
        query = HeapAlloc(GetProcessHeap(),0,sz); \
        sprintf(query,insert,values); \
        r = run_query( hdb, query ); \
        HeapFree(GetProcessHeap(), 0, query); \
        return r; \
    }

make_add_entry(feature,
               "INSERT INTO `Feature` "
               "(`Feature`, `Feature_Parent`, `Title`, `Description`, "
               "`Display`, `Level`, `Directory_`, `Attributes`) VALUES( %s )")

make_add_entry(component,
               "INSERT INTO `Component`  "
               "(`Component`, `ComponentId`, `Directory_`, "
               "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")

make_add_entry(feature_components,
               "INSERT INTO `FeatureComponents` "
               "(`Feature_`, `Component_`) VALUES( %s )")

make_add_entry(file,
               "INSERT INTO `File` "
               "(`File`, `Component_`, `FileName`, `FileSize`, "
               "`Version`, `Language`, `Attributes`, `Sequence`) VALUES( %s )")

make_add_entry(directory,
               "INSERT INTO `Directory` "
               "(`Directory`,`Directory_Parent`,`DefaultDir`) VALUES( %s )")

make_add_entry(custom_action,
               "INSERT INTO `CustomAction`  "
               "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
151 152 153 154 155 156

static UINT set_summary_info(MSIHANDLE hdb)
{
    UINT res;
    MSIHANDLE suminfo;

Austin English's avatar
Austin English committed
157
    /* build summary info */
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
    ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );

    res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
                        "Installation Database");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
                        "Installation Database");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
                        "Wine Hackers");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
                    ";1033");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
                    "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoPersist(suminfo);
    ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );

    res = MsiCloseHandle( suminfo);
    ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );

    return res;
}

static MSIHANDLE create_package_db(void)
{
    MSIHANDLE hdb = 0;
    UINT res;

    DeleteFile(msifile);

    /* create an empty database */
204 205
    res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATEDIRECT, &hdb );
    ok( res == ERROR_SUCCESS , "Failed to create database %u\n", res );
206
    if( res != ERROR_SUCCESS )
207
        return 0;
208 209 210

    res = MsiDatabaseCommit( hdb );
    ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
211 212
    if( res != ERROR_SUCCESS )
        return 0;
213 214

    res = set_summary_info(hdb);
215 216 217
    ok( res == ERROR_SUCCESS , "Failed to set summary info %u\n", res );
    if( res != ERROR_SUCCESS )
        return 0;
218 219 220 221 222 223 224

    res = run_query( hdb,
            "CREATE TABLE `Directory` ( "
            "`Directory` CHAR(255) NOT NULL, "
            "`Directory_Parent` CHAR(255), "
            "`DefaultDir` CHAR(255) NOT NULL "
            "PRIMARY KEY `Directory`)" );
225
    ok( res == ERROR_SUCCESS , "Failed to create directory table %u\n", res );
226 227 228 229

    return hdb;
}

230
static UINT package_from_db(MSIHANDLE hdb, MSIHANDLE *handle)
231 232
{
    UINT res;
233
    CHAR szPackage[12];
234 235
    MSIHANDLE hPackage;

236 237 238 239
    sprintf(szPackage, "#%u", hdb);
    res = MsiOpenPackage(szPackage, &hPackage);
    if (res != ERROR_SUCCESS)
        return res;
240 241

    res = MsiCloseHandle(hdb);
242 243 244 245 246
    if (res != ERROR_SUCCESS)
    {
        MsiCloseHandle(hPackage);
        return res;
    }
247

248 249
    *handle = hPackage;
    return ERROR_SUCCESS;
250 251 252 253 254 255 256 257 258 259 260 261 262 263
}

static void create_test_file(const CHAR *name)
{
    HANDLE file;
    DWORD written;

    file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
    ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
    WriteFile(file, name, strlen(name), &written, NULL);
    WriteFile(file, "\n", strlen("\n"), &written, NULL);
    CloseHandle(file);
}

264
static UINT helper_createpackage( const char *szName, MSIHANDLE *handle )
265
{
266
    MSIHANDLE hPackage, suminfo, hdb = 0;
267 268 269 270 271
    UINT res;

    DeleteFile(szName);

    /* create an empty database */
272 273 274 275
    res = MsiOpenDatabase(szName, MSIDBOPEN_CREATEDIRECT, &hdb );
    ok( res == ERROR_SUCCESS , "Failed to create database %u\n", res );
    if (res != ERROR_SUCCESS)
        return res;
276 277

    res = MsiDatabaseCommit( hdb );
278
    ok( res == ERROR_SUCCESS , "Failed to commit database %u\n", res );
279

Austin English's avatar
Austin English committed
280
    /* build summary info */
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
    res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
    ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );

    res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
                        "Installation Database");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
                        "Installation Database");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
                        "Wine Hackers");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
                    ";1033");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
                    "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
    ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );

    res = MsiSummaryInfoPersist(suminfo);
    ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );

    res = MsiCloseHandle( suminfo);
    ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );

316
    res = package_from_db( hdb, &hPackage );
317 318 319 320 321 322
    MsiCloseHandle(hdb);

    if (res != ERROR_SUCCESS)
        DeleteFileA( szName );
    else
        *handle = hPackage;
323

324
    return res;
325 326 327 328 329 330 331
}

static void test_createpackage(void)
{
    MSIHANDLE hPackage = 0;
    UINT res;

332
    res = helper_createpackage( msifile, &hPackage );
333 334 335 336 337
    if (res == ERROR_INSTALL_PACKAGE_REJECTED)
    {
        skip("Not enough rights to perform tests\n");
        return;
    }
338
    ok( res == ERROR_SUCCESS, "Failed to create package %u\n", res );
339

340 341
    res = MsiCloseHandle( hPackage );
    ok( res == ERROR_SUCCESS , "Failed to close package %u\n", res );
342

343
    DeleteFile( msifile );
344 345 346 347 348 349 350
}

static void test_formatrecord(void)
{
    char buffer[100];
    MSIHANDLE hrec;
    UINT r;
351
    DWORD sz;
352 353 354 355

    r = MsiFormatRecord(0, 0, NULL, NULL );
    ok( r == ERROR_INVALID_HANDLE, "wrong error\n");

356 357 358 359 360 361 362 363 364 365 366
    hrec = MsiCreateRecord(0);
    ok( hrec, "failed to create record\n");

    /* format an empty record on a record with no parameters */
    sz = sizeof(buffer);
    r = MsiFormatRecordA(0, hrec, buffer, &sz );
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 0, "size wrong\n");

    MsiCloseHandle( hrec );

367 368 369 370 371 372 373 374
    hrec = MsiCreateRecord(4);
    ok( hrec, "failed to create record\n");

    /* format an empty record */
    r = MsiFormatRecord(0, hrec, NULL, NULL );
    ok( r == ERROR_SUCCESS, "format failed\n");
    buffer[0] = 'x';
    buffer[1] = 0;
375 376 377 378 379
    sz=0;
    r = MsiFormatRecord(0, hrec, buffer+1, &sz);
    ok( r == ERROR_MORE_DATA && buffer[0] == 'x', "format failed measuring with buffer\n");
    ok( sz == 16, "size wrong\n");
    sz=100;
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
    ok( sz == 16, "size wrong\n");
    ok( 0 == strcmp(buffer,"1:  2:  3:  4:  "), "wrong output\n");

    r = MsiCloseHandle(hrec);
    ok(r==ERROR_SUCCESS, "Unable to close record\n");

    hrec = MsiCreateRecord(6);
    ok( hrec, "failed to create record\n");

    sz = 100;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
    ok( sz == 24, "size wrong\n");
    ok( 0 == strcmp(buffer,"1:  2:  3:  4:  5:  6:  "), "wrong output\n");


    /* format a format string with everything else empty */
    r = MsiRecordSetString(hrec, 0, "%1");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiFormatRecord(0, hrec, NULL, NULL );
    ok( r == ERROR_SUCCESS, "format failed\n");
    r = MsiFormatRecord(0, hrec, buffer, NULL);
    ok( r == ERROR_INVALID_PARAMETER, "wrong error\n");

    sz = 123;
    r = MsiFormatRecord(0, hrec, NULL, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
411
    ok( sz == 2, "size wrong (%i)\n",sz);
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
    sz = sizeof buffer;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"%1"), "wrong output\n");

    /* make the buffer too small */
    sz = 0;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"x"), "wrong output\n");

    /* make the buffer a little bit bigger */
    sz = 1;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);

    /* and again */
    sz = 2;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"%"), "wrong output\n");

    /* and again */
    sz = 3;
    buffer[0] = 'x';
    buffer[1] = 0;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"%1"), "wrong output\n");

    /* now try a real format string */
    r = MsiRecordSetString(hrec, 0, "[1]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");

    /* now put something in the first field */
    r = MsiRecordSetString(hrec, 1, "boo hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");

    /* now put something in the first field */
    r = MsiRecordSetString(hrec, 0, "[1] [2]");
476
    ok( r == ERROR_SUCCESS, "set string failed\n");
477
    r = MsiRecordSetString(hrec, 1, "boo");
478
    ok( r == ERROR_SUCCESS, "set string failed\n");
479 480 481 482 483 484 485 486 487 488
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");

    /* empty string */
    r = MsiRecordSetString(hrec, 0, "");
489
    ok( r == ERROR_SUCCESS, "set string failed\n");
490 491 492
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
493
    ok( sz == 30, "size wrong %i\n",sz);
494 495 496 497 498
    ok( 0 == strcmp(buffer,"1: boo 2: hoo 3:  4:  5:  6:  "), 
                    "wrong output(%s)\n",buffer);

    /* play games with recursive lookups */
    r = MsiRecordSetString(hrec, 0, "[[1]] [2]");
499
    ok( r == ERROR_SUCCESS, "set string failed\n");
500
    r = MsiRecordSetString(hrec, 1, "2");
501
    ok( r == ERROR_SUCCESS, "set string failed\n");
502 503 504 505 506
    r = MsiRecordSetString(hrec, 2, "hey");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
507
    ok( sz == 7, "size wrong,(%i)\n",sz);
508 509 510
    ok( 0 == strcmp(buffer,"hey hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[[1]] [2]");
511
    ok( r == ERROR_SUCCESS, "set string failed\n");
512
    r = MsiRecordSetString(hrec, 1, "[2]");
513
    ok( r == ERROR_SUCCESS, "set string failed\n");
514 515 516 517 518
    r = MsiRecordSetString(hrec, 2, "hey");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
519
    ok( sz == 9, "size wrong,(%i)\n",sz);
520 521 522
    ok( 0 == strcmp(buffer,"[[2]] hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[[[3]]] [2]");
523
    ok( r == ERROR_SUCCESS, "set string failed\n");
524
    r = MsiRecordSetString(hrec, 1, "2");
525
    ok( r == ERROR_SUCCESS, "set string failed\n");
526
    r = MsiRecordSetString(hrec, 2, "hey");
527
    ok( r == ERROR_SUCCESS, "set string failed\n");
528 529 530 531 532
    r = MsiRecordSetString(hrec, 3, "1");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
533
    ok( sz == 7, "size wrong,(%i)\n",sz);
534 535 536 537 538 539 540 541
    ok( 0 == strcmp(buffer,"hey hey"), "wrong output (%s)\n",buffer);

    r = MsiCloseHandle(hrec);
    ok(r==ERROR_SUCCESS, "Unable to close record\n");
    hrec = MsiCreateRecord(12);
    ok( hrec, "failed to create record\n");

    r = MsiRecordSetString(hrec, 0, "[[3][1]] [2]");
542
    ok( r == ERROR_SUCCESS, "set string failed\n");
543
    r = MsiRecordSetString(hrec, 1, "2");
544
    ok( r == ERROR_SUCCESS, "set string failed\n");
545
    r = MsiRecordSetString(hrec, 2, "hey");
546
    ok( r == ERROR_SUCCESS, "set string failed\n");
547
    r = MsiRecordSetString(hrec, 3, "1");
548
    ok( r == ERROR_SUCCESS, "set string failed\n");
549 550 551 552 553
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
554
    ok( sz == 7, "size wrong,(%i)\n",sz);
555 556 557
    ok( 0 == strcmp(buffer,"big hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[[3][4][1]] [2]");
558
    ok( r == ERROR_SUCCESS, "set string failed\n");
559
    r = MsiRecordSetString(hrec, 1, "2");
560
    ok( r == ERROR_SUCCESS, "set string failed\n");
561
    r = MsiRecordSetString(hrec, 2, "hey");
562
    ok( r == ERROR_SUCCESS, "set string failed\n");
563
    r = MsiRecordSetString(hrec, 3, "1");
564
    ok( r == ERROR_SUCCESS, "set string failed\n");
565
    r = MsiRecordSetString(hrec, 4, NULL);
566
    ok( r == ERROR_SUCCESS, "set string failed\n");
567 568 569 570 571
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
572
    ok( sz == 7, "size wrong,(%i)\n",sz);
573 574 575
    ok( 0 == strcmp(buffer,"big hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[[3][[4]][1]] [2]");
576
    ok( r == ERROR_SUCCESS, "set string failed\n");
577
    r = MsiRecordSetString(hrec, 1, "2");
578
    ok( r == ERROR_SUCCESS, "set string failed\n");
579
    r = MsiRecordSetString(hrec, 2, "hey");
580
    ok( r == ERROR_SUCCESS, "set string failed\n");
581
    r = MsiRecordSetString(hrec, 3, "1");
582
    ok( r == ERROR_SUCCESS, "set string failed\n");
583
    r = MsiRecordSetString(hrec, 4, NULL);
584
    ok( r == ERROR_SUCCESS, "set string failed\n");
585 586 587 588 589
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
590
    ok( sz == 10, "size wrong,(%i)\n",sz);
591 592 593 594
    ok( 0 == strcmp(buffer,"[1[]2] hey"), "wrong output (%s)\n",buffer);

    /* incorrect  formats */
    r = MsiRecordSetString(hrec, 0, "[[[3][[4]][1]] [2]");
595
    ok( r == ERROR_SUCCESS, "set string failed\n");
596
    r = MsiRecordSetString(hrec, 1, "2");
597
    ok( r == ERROR_SUCCESS, "set string failed\n");
598
    r = MsiRecordSetString(hrec, 2, "hey");
599
    ok( r == ERROR_SUCCESS, "set string failed\n");
600
    r = MsiRecordSetString(hrec, 3, "1");
601
    ok( r == ERROR_SUCCESS, "set string failed\n");
602
    r = MsiRecordSetString(hrec, 4, NULL);
603
    ok( r == ERROR_SUCCESS, "set string failed\n");
604 605 606 607 608
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
609
    ok( sz == 18, "size wrong,(%i)\n",sz);
610 611 612
    ok( 0 == strcmp(buffer,"[[[3][[4]][1]] [2]"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[[3][[4]][1]] [2]]");
613
    ok( r == ERROR_SUCCESS, "set string failed\n");
614
    r = MsiRecordSetString(hrec, 1, "2");
615
    ok( r == ERROR_SUCCESS, "set string failed\n");
616
    r = MsiRecordSetString(hrec, 2, "hey");
617
    ok( r == ERROR_SUCCESS, "set string failed\n");
618
    r = MsiRecordSetString(hrec, 3, "1");
619
    ok( r == ERROR_SUCCESS, "set string failed\n");
620
    r = MsiRecordSetString(hrec, 4, NULL);
621
    ok( r == ERROR_SUCCESS, "set string failed\n");
622 623 624 625 626
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
627
    ok( sz == 11, "size wrong,(%i)\n",sz);
628 629 630 631 632 633
    ok( 0 == strcmp(buffer,"[1[]2] hey]"), "wrong output (%s)\n",buffer);


    /* play games with {} */

    r = MsiRecordSetString(hrec, 0, "{[3][1]} [2]");
634
    ok( r == ERROR_SUCCESS, "set string failed\n");
635
    r = MsiRecordSetString(hrec, 1, "2");
636
    ok( r == ERROR_SUCCESS, "set string failed\n");
637
    r = MsiRecordSetString(hrec, 2, "hey");
638
    ok( r == ERROR_SUCCESS, "set string failed\n");
639
    r = MsiRecordSetString(hrec, 3, "1");
640
    ok( r == ERROR_SUCCESS, "set string failed\n");
641
    r = MsiRecordSetString(hrec, 4, NULL);
642
    ok( r == ERROR_SUCCESS, "set string failed\n");
643 644 645 646 647
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
648
    ok( sz == 6, "size wrong,(%i)\n",sz);
649 650 651
    ok( 0 == strcmp(buffer,"12 hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[{[3][1]}] [2]");
652
    ok( r == ERROR_SUCCESS, "set string failed\n");
653
    r = MsiRecordSetString(hrec, 1, "2");
654
    ok( r == ERROR_SUCCESS, "set string failed\n");
655
    r = MsiRecordSetString(hrec, 2, "hey");
656
    ok( r == ERROR_SUCCESS, "set string failed\n");
657
    r = MsiRecordSetString(hrec, 3, "1");
658
    ok( r == ERROR_SUCCESS, "set string failed\n");
659
    r = MsiRecordSetString(hrec, 4, NULL);
660
    ok( r == ERROR_SUCCESS, "set string failed\n");
661 662 663 664 665
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
666
    ok( sz == 8, "size wrong,(%i)\n",sz);
667 668 669 670
    ok( 0 == strcmp(buffer,"[12] hey"), "wrong output (%s)\n",buffer);


    r = MsiRecordSetString(hrec, 0, "{test} [2]");
671
    ok( r == ERROR_SUCCESS, "set string failed\n");
672
    r = MsiRecordSetString(hrec, 1, "2");
673
    ok( r == ERROR_SUCCESS, "set string failed\n");
674
    r = MsiRecordSetString(hrec, 2, "hey");
675
    ok( r == ERROR_SUCCESS, "set string failed\n");
676
    r = MsiRecordSetString(hrec, 3, "1");
677
    ok( r == ERROR_SUCCESS, "set string failed\n");
678
    r = MsiRecordSetString(hrec, 4, NULL);
679
    ok( r == ERROR_SUCCESS, "set string failed\n");
680 681 682 683 684
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
685
    ok( sz == 10, "size wrong,(%i)\n",sz);
686 687 688
    ok( 0 == strcmp(buffer,"{test} hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[test]} [2]");
689
    ok( r == ERROR_SUCCESS, "set string failed\n");
690
    r = MsiRecordSetString(hrec, 1, "2");
691
    ok( r == ERROR_SUCCESS, "set string failed\n");
692
    r = MsiRecordSetString(hrec, 2, "hey");
693
    ok( r == ERROR_SUCCESS, "set string failed\n");
694
    r = MsiRecordSetString(hrec, 3, "1");
695
    ok( r == ERROR_SUCCESS, "set string failed\n");
696
    r = MsiRecordSetString(hrec, 4, NULL);
697
    ok( r == ERROR_SUCCESS, "set string failed\n");
698 699 700 701 702
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
703
    ok( sz == 12, "size wrong,(%i)\n",sz);
704 705 706
    ok( 0 == strcmp(buffer,"{[test]} hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[1][2][3][4]} [2]");
707
    ok( r == ERROR_SUCCESS, "set string failed\n");
708
    r = MsiRecordSetString(hrec, 1, "2");
709
    ok( r == ERROR_SUCCESS, "set string failed\n");
710
    r = MsiRecordSetString(hrec, 2, "hey");
711
    ok( r == ERROR_SUCCESS, "set string failed\n");
712
    r = MsiRecordSetString(hrec, 3, "1");
713
    ok( r == ERROR_SUCCESS, "set string failed\n");
714
    r = MsiRecordSetString(hrec, 4, NULL);
715
    ok( r == ERROR_SUCCESS, "set string failed\n");
716 717 718 719 720
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
721
    ok( sz == 4, "size wrong,(%i)\n",sz);
722 723 724
    ok( 0 == strcmp(buffer," hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[1][2][3][dummy]} [2]");
725
    ok( r == ERROR_SUCCESS, "set string failed\n");
726
    r = MsiRecordSetString(hrec, 1, "2");
727
    ok( r == ERROR_SUCCESS, "set string failed\n");
728
    r = MsiRecordSetString(hrec, 2, "hey");
729
    ok( r == ERROR_SUCCESS, "set string failed\n");
730
    r = MsiRecordSetString(hrec, 3, "1");
731
    ok( r == ERROR_SUCCESS, "set string failed\n");
732
    r = MsiRecordSetString(hrec, 4, NULL);
733
    ok( r == ERROR_SUCCESS, "set string failed\n");
734 735 736 737 738
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
739
    ok( sz == 18, "size wrong,(%i)\n",sz);
740 741 742
    ok( 0 == strcmp(buffer,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[1][2][3][4][dummy]} [2]");
743
    ok( r == ERROR_SUCCESS, "set string failed\n");
744
    r = MsiRecordSetString(hrec, 1, "2");
745
    ok( r == ERROR_SUCCESS, "set string failed\n");
746
    r = MsiRecordSetString(hrec, 2, "hey");
747
    ok( r == ERROR_SUCCESS, "set string failed\n");
748
    r = MsiRecordSetString(hrec, 3, "1");
749
    ok( r == ERROR_SUCCESS, "set string failed\n");
750
    r = MsiRecordSetString(hrec, 4, NULL);
751
    ok( r == ERROR_SUCCESS, "set string failed\n");
752 753 754 755 756
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
757
    ok( sz == 18, "size wrong,(%i)\n",sz);
758 759 760
    ok( 0 == strcmp(buffer,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{[1][2]}[3][4][dummy]}");
761
    ok( r == ERROR_SUCCESS, "set string failed\n");
762
    r = MsiRecordSetString(hrec, 1, "2");
763
    ok( r == ERROR_SUCCESS, "set string failed\n");
764
    r = MsiRecordSetString(hrec, 2, "hey");
765
    ok( r == ERROR_SUCCESS, "set string failed\n");
766
    r = MsiRecordSetString(hrec, 3, "1");
767
    ok( r == ERROR_SUCCESS, "set string failed\n");
768
    r = MsiRecordSetString(hrec, 4, NULL);
769
    ok( r == ERROR_SUCCESS, "set string failed\n");
770 771 772 773 774
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
775
    ok( sz == 16, "size wrong,(%i)\n",sz);
776 777 778
    ok( 0 == strcmp(buffer,"{{2hey}1[dummy]}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{[1][2]}[3]{[4][dummy]}}");
779
    ok( r == ERROR_SUCCESS, "set string failed\n");
780
    r = MsiRecordSetString(hrec, 1, "2");
781
    ok( r == ERROR_SUCCESS, "set string failed\n");
782
    r = MsiRecordSetString(hrec, 2, "hey");
783
    ok( r == ERROR_SUCCESS, "set string failed\n");
784
    r = MsiRecordSetString(hrec, 3, "1");
785
    ok( r == ERROR_SUCCESS, "set string failed\n");
786
    r = MsiRecordSetString(hrec, 4, NULL);
787
    ok( r == ERROR_SUCCESS, "set string failed\n");
788 789 790 791 792
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
793
    ok( sz == 0, "size wrong,(%i)\n",sz);
794 795 796
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{[1][2]}[3]} {[1][2]}");
797
    ok( r == ERROR_SUCCESS, "set string failed\n");
798
    r = MsiRecordSetString(hrec, 1, "1");
799
    ok( r == ERROR_SUCCESS, "set string failed\n");
800
    r = MsiRecordSetString(hrec, 2, "2");
801
    ok( r == ERROR_SUCCESS, "set string failed\n");
802
    r = MsiRecordSetString(hrec, 3, "3");
803
    ok( r == ERROR_SUCCESS, "set string failed\n");
804
    r = MsiRecordSetString(hrec, 4, NULL);
805
    ok( r == ERROR_SUCCESS, "set string failed\n");
806 807 808 809 810
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
811
    ok( sz == 12, "size wrong,(%i)\n",sz);
812 813 814
    ok( 0 == strcmp(buffer,"{{12}3} {12}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[1][2]} {{[1][2]}[3]} {[1][2]}");
815
    ok( r == ERROR_SUCCESS, "set string failed\n");
816
    r = MsiRecordSetString(hrec, 1, "1");
817
    ok( r == ERROR_SUCCESS, "set string failed\n");
818
    r = MsiRecordSetString(hrec, 2, "2");
819
    ok( r == ERROR_SUCCESS, "set string failed\n");
820
    r = MsiRecordSetString(hrec, 3, "3");
821
    ok( r == ERROR_SUCCESS, "set string failed\n");
822
    r = MsiRecordSetString(hrec, 4, NULL);
823
    ok( r == ERROR_SUCCESS, "set string failed\n");
824 825 826 827 828
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
829
    ok( sz == 15, "size wrong,(%i)\n",sz);
830 831 832
    ok( 0 == strcmp(buffer,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
833
    ok( r == ERROR_SUCCESS, "set string failed\n");
834
    r = MsiRecordSetString(hrec, 1, "1");
835
    ok( r == ERROR_SUCCESS, "set string failed\n");
836
    r = MsiRecordSetString(hrec, 2, "2");
837
    ok( r == ERROR_SUCCESS, "set string failed\n");
838
    r = MsiRecordSetString(hrec, 3, "3");
839
    ok( r == ERROR_SUCCESS, "set string failed\n");
840
    r = MsiRecordSetString(hrec, 4, NULL);
841
    ok( r == ERROR_SUCCESS, "set string failed\n");
842 843 844 845 846
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
847
    ok( sz == 15, "size wrong,(%i)\n",sz);
848 849 850
    ok( 0 == strcmp(buffer,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{blah} {[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
851
    ok( r == ERROR_SUCCESS, "set string failed\n");
852
    r = MsiRecordSetString(hrec, 1, "1");
853
    ok( r == ERROR_SUCCESS, "set string failed\n");
854
    r = MsiRecordSetString(hrec, 2, "2");
855
    ok( r == ERROR_SUCCESS, "set string failed\n");
856
    r = MsiRecordSetString(hrec, 3, "3");
857
    ok( r == ERROR_SUCCESS, "set string failed\n");
858
    r = MsiRecordSetString(hrec, 4, NULL);
859
    ok( r == ERROR_SUCCESS, "set string failed\n");
860 861 862 863 864
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
865
    ok( sz == 22, "size wrong,(%i)\n",sz);
866 867 868
    ok( 0 == strcmp(buffer,"{blah} 12 {{12}3} {12}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{[1]}[2]} {[4]}{[1][2]}");
869
    ok( r == ERROR_SUCCESS, "set string failed\n");
870
    r = MsiRecordSetString(hrec, 1, "1");
871
    ok( r == ERROR_SUCCESS, "set string failed\n");
872
    r = MsiRecordSetString(hrec, 2, "2");
873
    ok( r == ERROR_SUCCESS, "set string failed\n");
874
    r = MsiRecordSetString(hrec, 3, "3");
875
    ok( r == ERROR_SUCCESS, "set string failed\n");
876
    r = MsiRecordSetString(hrec, 4, NULL);
877
    ok( r == ERROR_SUCCESS, "set string failed\n");
878 879 880 881 882
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
883
    ok( sz == 13, "size wrong,(%i)\n",sz);
884 885 886
    ok( 0 == strcmp(buffer,"{{1}2} {}{12}"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{[1]}} {[4]}{[1][2]}");
887
    ok( r == ERROR_SUCCESS, "set string failed\n");
888
    r = MsiRecordSetString(hrec, 1, "1");
889
    ok( r == ERROR_SUCCESS, "set string failed\n");
890
    r = MsiRecordSetString(hrec, 2, "2");
891
    ok( r == ERROR_SUCCESS, "set string failed\n");
892
    r = MsiRecordSetString(hrec, 3, "3");
893
    ok( r == ERROR_SUCCESS, "set string failed\n");
894
    r = MsiRecordSetString(hrec, 4, NULL);
895
    ok( r == ERROR_SUCCESS, "set string failed\n");
896 897 898 899 900
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
901
    ok( sz == 3, "size wrong,(%i)\n",sz);
902 903 904
    ok( 0 == strcmp(buffer," 12"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "{{{[1]}} {[4]}{[1][2]}");
905
    ok( r == ERROR_SUCCESS, "set string failed\n");
906
    r = MsiRecordSetString(hrec, 1, "1");
907
    ok( r == ERROR_SUCCESS, "set string failed\n");
908
    r = MsiRecordSetString(hrec, 2, "2");
909
    ok( r == ERROR_SUCCESS, "set string failed\n");
910
    r = MsiRecordSetString(hrec, 3, "3");
911
    ok( r == ERROR_SUCCESS, "set string failed\n");
912
    r = MsiRecordSetString(hrec, 4, NULL);
913
    ok( r == ERROR_SUCCESS, "set string failed\n");
914 915 916 917 918 919
    r = MsiRecordSetString(hrec, 12, "big");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    todo_wine{
920
    ok( sz == 3, "size wrong,(%i)\n",sz);
921 922 923 924 925
    ok( 0 == strcmp(buffer," 12"), "wrong output (%s)\n",buffer);
    }
    
    /* now put play games with escaping */
    r = MsiRecordSetString(hrec, 0, "[1] [2] [\\3asdf]");
926
    ok( r == ERROR_SUCCESS, "set string failed\n");
927
    r = MsiRecordSetString(hrec, 1, "boo");
928
    ok( r == ERROR_SUCCESS, "set string failed\n");
929 930 931 932 933 934 935 936 937 938
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 16, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo [\\3asdf]"), "wrong output\n");

    /* now put play games with escaping */
    r = MsiRecordSetString(hrec, 0, "[1] [2] [\\x]");
939
    ok( r == ERROR_SUCCESS, "set string failed\n");
940
    r = MsiRecordSetString(hrec, 1, "boo");
941
    ok( r == ERROR_SUCCESS, "set string failed\n");
942 943 944 945 946 947 948 949
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 12, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo [\\x]"), "wrong output\n");

950 951
    r = MsiRecordSetString(hrec, 0, "[\\x]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
952 953 954
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
955
    ok( sz == 4, "size wrong: %d\n", sz);
956 957
    ok( 0 == strcmp(buffer,"[\\x]"), "wrong output: %s\n", buffer);

958 959
    r = MsiRecordSetString(hrec, 0, "{\\x}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
960 961 962
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
963
    ok( sz == 4, "size wrong: %d\n", sz);
964 965
    ok( 0 == strcmp(buffer,"{\\x}"), "wrong output: %s\n", buffer);

966 967
    r = MsiRecordSetString(hrec, 0, "[abc\\x]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
968 969 970
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
971
    ok( sz == 7, "size wrong: %d\n", sz);
972 973
    ok( 0 == strcmp(buffer,"[abc\\x]"), "wrong output: %s\n", buffer);

974 975
    r = MsiRecordSetString(hrec, 0, "[\\[]Bracket Text[\\]]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
976 977 978
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
979
    ok( sz == 20, "size wrong: %d\n", sz);
980 981
    ok( 0 == strcmp(buffer,"[\\[]Bracket Text[\\]]"), "wrong output: %s\n", buffer);

982 983
    /* now try other formats without a package */
    r = MsiRecordSetString(hrec, 0, "[1] [2] [property]");
984
    ok( r == ERROR_SUCCESS, "set string failed\n");
985
    r = MsiRecordSetString(hrec, 1, "boo");
986
    ok( r == ERROR_SUCCESS, "set string failed\n");
987 988 989 990 991 992 993 994 995
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 18, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo [property]"), "wrong output\n");

    r = MsiRecordSetString(hrec, 0, "[1] [~] [2]");
996
    ok( r == ERROR_SUCCESS, "set string failed\n");
997
    r = MsiRecordSetString(hrec, 1, "boo");
998
    ok( r == ERROR_SUCCESS, "set string failed\n");
999 1000 1001 1002 1003 1004 1005
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 11, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo [~] hoo"), "wrong output (%s)\n",buffer);
1006 1007

    r = MsiRecordSetString(hrec, 0, "[1]");
1008
    ok( r == ERROR_SUCCESS, "set string failed\n");
1009 1010 1011 1012 1013 1014 1015 1016
    r = MsiRecordSetInteger(hrec, 1, 123456);
    ok( r == ERROR_SUCCESS, "set integer failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 6, "size wrong\n");
    ok( 0 == strcmp(buffer,"123456"), "wrong output (%s)\n",buffer);

1017
    r = MsiRecordSetString(hrec, 0, "[~]");
1018
    ok( r == ERROR_SUCCESS, "set string failed\n");
1019 1020 1021 1022 1023 1024 1025
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"[~]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[]");
1026
    ok( r == ERROR_SUCCESS, "set string failed\n");
1027 1028 1029 1030 1031 1032 1033 1034
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"[]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    /* MsiFormatRecord doesn't seem to handle a negative too well */
    r = MsiRecordSetString(hrec, 0, "[-1]");
1035
    ok( r == ERROR_SUCCESS, "set string failed\n");
1036 1037 1038 1039 1040 1041 1042
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"[-1]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[]}");
1043
    ok( r == ERROR_SUCCESS, "set string failed\n");
1044 1045 1046 1047 1048 1049 1050
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"{[]}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[0]");
1051
    ok( r == ERROR_SUCCESS, "set string failed\n");
1052 1053 1054 1055 1056 1057 1058
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"[0]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[100]");
1059
    ok( r == ERROR_SUCCESS, "set string failed\n");
1060 1061 1062 1063 1064 1065 1066
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1] [2]}");
1067
    ok( r == ERROR_SUCCESS, "set string failed\n");
1068
    r = MsiRecordSetString(hrec, 1, "boo");
1069
    ok( r == ERROR_SUCCESS, "set string failed\n");
1070
    r = MsiRecordSetString(hrec, 2, "hoo");
1071
    ok( r == ERROR_SUCCESS, "set string failed\n");
1072 1073 1074 1075 1076 1077 1078
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{}");
1079
    ok( r == ERROR_SUCCESS, "set string failed\n");
1080 1081 1082 1083 1084 1085 1086
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{foo}");
1087
    ok( r == ERROR_SUCCESS, "set string failed\n");
1088 1089 1090 1091 1092 1093 1094
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 5, "size wrong\n");
    ok( 0 == strcmp(buffer,"{foo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{boo [1]}");
1095
    ok( r == ERROR_SUCCESS, "set string failed\n");
1096
    r = MsiRecordSetString(hrec, 1, "hoo");
1097
    ok( r == ERROR_SUCCESS, "set string failed\n");
1098 1099 1100 1101 1102 1103 1104
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{[1]}}");
1105
    ok( r == ERROR_SUCCESS, "set string failed\n");
1106
    r = MsiRecordSetString(hrec, 1, "hoo");
1107
    ok( r == ERROR_SUCCESS, "set string failed\n");
1108 1109 1110 1111 1112 1113 1114
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{ {[1]}}");
1115
    ok( r == ERROR_SUCCESS, "set string failed\n");
1116
    r = MsiRecordSetString(hrec, 1, "hoo");
1117
    ok( r == ERROR_SUCCESS, "set string failed\n");
1118 1119
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1120 1121 1122 1123 1124
    todo_wine
    {
        ok( 0 == strcmp(buffer," {hoo}"), "wrong output\n");
        ok( sz == 6, "size wrong\n");
    }
1125 1126 1127
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{[1]} }");
1128
    ok( r == ERROR_SUCCESS, "set string failed\n");
1129
    r = MsiRecordSetString(hrec, 1, "hoo");
1130
    ok( r == ERROR_SUCCESS, "set string failed\n");
1131 1132 1133 1134 1135 1136 1137
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 8, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{hoo} }"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ [1]}}");
1138
    ok( r == ERROR_SUCCESS, "set string failed\n");
1139
    r = MsiRecordSetString(hrec, 1, "hoo");
1140
    ok( r == ERROR_SUCCESS, "set string failed\n");
1141 1142 1143 1144 1145 1146 1147
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{[1] }}");
1148
    ok( r == ERROR_SUCCESS, "set string failed\n");
1149
    r = MsiRecordSetString(hrec, 1, "hoo");
1150
    ok( r == ERROR_SUCCESS, "set string failed\n");
1151 1152 1153 1154 1155 1156 1157
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{a}{b}{c }{ d}{any text}}");
1158
    ok( r == ERROR_SUCCESS, "set string failed\n");
1159 1160 1161 1162 1163 1164 1165
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{a} }");
1166
    ok( r == ERROR_SUCCESS, "set string failed\n");
1167 1168 1169 1170 1171 1172 1173
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 6, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{a} }"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{a} {b}}");
1174
    ok( r == ERROR_SUCCESS, "set string failed\n");
1175 1176 1177 1178 1179 1180 1181
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{a} b}}");
1182
    ok( r == ERROR_SUCCESS, "set string failed\n");
1183 1184
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1185 1186
    todo_wine ok( sz == 0, "size wrong\n");
    todo_wine ok( 0 == strcmp(buffer,""), "wrong output\n");
1187 1188 1189
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{a b}}");
1190
    ok( r == ERROR_SUCCESS, "set string failed\n");
1191 1192 1193 1194 1195 1196 1197
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 0, "size wrong\n");
    ok( 0 == strcmp(buffer,""), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{ }");
1198
    ok( r == ERROR_SUCCESS, "set string failed\n");
1199 1200 1201 1202 1203 1204 1205
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"{ }"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, " {{a}}}");
1206
    ok( r == ERROR_SUCCESS, "set string failed\n");
1207 1208 1209 1210 1211 1212 1213
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer," }"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ almost {{ any }} text }}");
1214
    ok( r == ERROR_SUCCESS, "set string failed\n");
1215 1216
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1217 1218
    todo_wine ok( sz == 8, "size wrong\n");
    todo_wine ok( 0 == strcmp(buffer," text }}"), "wrong output\n");
1219 1220 1221
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ } { hidden ][ [ }}");
1222
    ok( r == ERROR_SUCCESS, "set string failed\n");
1223 1224
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1225 1226
    todo_wine ok( sz == 0, "size wrong\n");
    todo_wine ok( 0 == strcmp(buffer,""), "wrong output\n");
1227 1228 1229
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[ 1]");
1230
    ok( r == ERROR_SUCCESS, "set string failed\n");
1231
    r = MsiRecordSetString(hrec, 1, "hoo");
1232
    ok( r == ERROR_SUCCESS, "set string failed\n");
1233 1234 1235 1236 1237 1238 1239
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"[ 1]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[01]");
1240
    ok( r == ERROR_SUCCESS, "set string failed\n");
1241
    r = MsiRecordSetString(hrec, 1, "hoo");
1242
    ok( r == ERROR_SUCCESS, "set string failed\n");
1243 1244 1245 1246 1247 1248 1249
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"hoo"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{test}} [01");
1250
    ok( r == ERROR_SUCCESS, "set string failed\n");
1251
    r = MsiRecordSetString(hrec, 1, "hoo");
1252
    ok( r == ERROR_SUCCESS, "set string failed\n");
1253 1254
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1255 1256
    todo_wine ok( sz == 4, "size wrong\n");
    todo_wine ok( 0 == strcmp(buffer," [01"), "wrong output\n");
1257 1258 1259
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[\\[]");
1260
    ok( r == ERROR_SUCCESS, "set string failed\n");
1261
    r = MsiRecordSetString(hrec, 1, "hoo");
1262
    ok( r == ERROR_SUCCESS, "set string failed\n");
1263 1264 1265 1266 1267 1268
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"[\\[]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

1269 1270 1271 1272
    r = MsiRecordSetString(hrec, 0, "[\\[]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 1, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1273 1274 1275 1276 1277 1278
    sz = sizeof(buffer);
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 4, "Expected 4, got %d\n", sz);
    ok(!lstrcmpA(buffer, "[\\[]"), "Expected \"[\\[]\", got \"%s\"\n", buffer);

1279
    r = MsiRecordSetString(hrec, 0, "[foo]");
1280
    ok( r == ERROR_SUCCESS, "set string failed\n");
1281
    r = MsiRecordSetString(hrec, 1, "hoo");
1282
    ok( r == ERROR_SUCCESS, "set string failed\n");
1283 1284 1285 1286 1287 1288 1289
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 5, "size wrong\n");
    ok( 0 == strcmp(buffer,"[foo]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[01.]");
1290
    ok( r == ERROR_SUCCESS, "set string failed\n");
1291
    r = MsiRecordSetString(hrec, 1, "hoo");
1292
    ok( r == ERROR_SUCCESS, "set string failed\n");
1293 1294 1295 1296 1297 1298 1299 1300
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 5, "size wrong\n");
    ok( 0 == strcmp(buffer,"[01.]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    SetEnvironmentVariable("FOO", "BAR");
    r = MsiRecordSetString(hrec, 0, "[%FOO]");
1301
    ok( r == ERROR_SUCCESS, "set string failed\n");
1302 1303 1304 1305 1306 1307 1308
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 6, "size wrong\n");
    ok( 0 == strcmp(buffer,"[%FOO]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{[1]}");
1309
    ok( r == ERROR_SUCCESS, "set string failed\n");
1310
    r = MsiRecordSetString(hrec, 1, "hoo");
1311
    ok( r == ERROR_SUCCESS, "set string failed\n");
1312 1313 1314 1315 1316 1317 1318
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 6, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{hoo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ {[1]}");
1319
    ok( r == ERROR_SUCCESS, "set string failed\n");
1320
    r = MsiRecordSetString(hrec, 1, "hoo");
1321
    ok( r == ERROR_SUCCESS, "set string failed\n");
1322 1323 1324 1325 1326 1327 1328
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 8, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{ {hoo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ {[1]}");
1329
    ok( r == ERROR_SUCCESS, "set string failed\n");
1330
    r = MsiRecordSetString(hrec, 1, "hoo");
1331
    ok( r == ERROR_SUCCESS, "set string failed\n");
1332 1333 1334 1335 1336 1337 1338
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 8, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{ {hoo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ {{[1]}");
1339
    ok( r == ERROR_SUCCESS, "set string failed\n");
1340
    r = MsiRecordSetString(hrec, 1, "hoo");
1341
    ok( r == ERROR_SUCCESS, "set string failed\n");
1342 1343 1344 1345 1346 1347 1348
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 9, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{ {{hoo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[1]}");
1349
    ok( r == ERROR_SUCCESS, "set string failed\n");
1350
    r = MsiRecordSetString(hrec, 1, "hoo");
1351
    ok( r == ERROR_SUCCESS, "set string failed\n");
1352 1353 1354 1355 1356 1357 1358
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"hoo}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ {{a}");
1359
    ok( r == ERROR_SUCCESS, "set string failed\n");
1360 1361 1362 1363 1364 1365 1366
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{ {{a}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{ {{a}");
1367
    ok( r == ERROR_SUCCESS, "set string failed\n");
1368 1369 1370 1371 1372 1373 1374
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 7, "size wrong\n");
    ok( 0 == strcmp(buffer,"{{ {{a}"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "0{1{2{3{4[1]5}6}7}8}9");
1375
    ok( r == ERROR_SUCCESS, "set string failed\n");
1376
    r = MsiRecordSetString(hrec, 1, "hoo");
1377
    ok( r == ERROR_SUCCESS, "set string failed\n");
1378 1379
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1380 1381 1382 1383 1384
    todo_wine
    {
        ok( sz == 19, "size wrong\n");
        ok( 0 == strcmp(buffer,"01{2{3{4hoo56}7}8}9"), "wrong output\n");
    }
1385 1386 1387
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "0{1{2[1]3}4");
1388
    ok( r == ERROR_SUCCESS, "set string failed\n");
1389
    r = MsiRecordSetString(hrec, 1, "hoo");
1390
    ok( r == ERROR_SUCCESS, "set string failed\n");
1391 1392
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1393 1394 1395 1396 1397
    todo_wine
    {
        ok( sz == 9, "size wrong\n");
        ok( 0 == strcmp(buffer,"01{2hoo34"), "wrong output\n");
    }
1398 1399 1400
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "0{1{2[1]3}4");
1401
    ok( r == ERROR_SUCCESS, "set string failed\n");
1402
    r = MsiRecordSetString(hrec, 1, "hoo");
1403
    ok( r == ERROR_SUCCESS, "set string failed\n");
1404 1405
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1406 1407 1408 1409 1410
    todo_wine
    {
        ok( sz == 9, "size wrong\n");
        ok( 0 == strcmp(buffer,"01{2hoo34"), "wrong output\n");
    }
1411 1412 1413
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1.} [1]");
1414
    ok( r == ERROR_SUCCESS, "set string failed\n");
1415
    r = MsiRecordSetString(hrec, 1, "hoo");
1416
    ok( r == ERROR_SUCCESS, "set string failed\n");
1417 1418 1419
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 9, "size wrong\n");
1420 1421 1422 1423
    todo_wine
    {
        ok( 0 == strcmp(buffer,"{[1.} hoo"), "wrong output\n");
    }
1424 1425 1426
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[{[1]}]}");
1427
    ok( r == ERROR_SUCCESS, "set string failed\n");
1428
    r = MsiRecordSetString(hrec, 1, "2");
1429
    ok( r == ERROR_SUCCESS, "set string failed\n");
1430
    r = MsiRecordSetString(hrec, 2, "foo");
1431
    ok( r == ERROR_SUCCESS, "set string failed\n");
1432 1433
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1434 1435 1436 1437 1438
    todo_wine
    {
        ok( sz == 9, "size wrong\n");
        ok( 0 == strcmp(buffer,"{[{[1]}]}"), "wrong output\n");
    }
1439 1440 1441
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1][}");
1442
    ok( r == ERROR_SUCCESS, "set string failed\n");
1443
    r = MsiRecordSetString(hrec, 1, "2");
1444
    ok( r == ERROR_SUCCESS, "set string failed\n");
1445
    r = MsiRecordSetString(hrec, 2, "foo");
1446
    ok( r == ERROR_SUCCESS, "set string failed\n");
1447 1448
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1449 1450 1451 1452 1453
    todo_wine
    {
        ok( sz == 2, "size wrong\n");
        ok( 0 == strcmp(buffer,"2["), "wrong output\n");
    }
1454 1455 1456
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[1]");
1457
    ok( r == ERROR_SUCCESS, "set string failed\n");
1458
    r = MsiRecordSetString(hrec, 1, "[2]");
1459
    ok( r == ERROR_SUCCESS, "set string failed\n");
1460
    r = MsiRecordSetString(hrec, 2, "foo");
1461
    ok( r == ERROR_SUCCESS, "set string failed\n");
1462 1463 1464 1465 1466 1467 1468
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"[2]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[{{boo}}1]");
1469
    ok( r == ERROR_SUCCESS, "set string failed\n");
1470
    r = MsiRecordSetString(hrec, 1, "hoo");
1471
    ok( r == ERROR_SUCCESS, "set string failed\n");
1472 1473
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1474
    ok( r == ERROR_SUCCESS, "format failed\n");
1475
    ok( sz == 3, "size wrong\n");
1476 1477 1478
    todo_wine
    {
        ok( 0 == strcmp(buffer,"[1]"), "wrong output: %s\n", buffer);
1479 1480 1481
    }

    r = MsiRecordSetString(hrec, 0, "[{{boo}}1]");
1482
    ok( r == ERROR_SUCCESS, "set string failed\n");
1483
    r = MsiRecordSetString(hrec, 0, "[1{{boo}}]");
1484
    ok( r == ERROR_SUCCESS, "set string failed\n");
1485
    r = MsiRecordSetString(hrec, 1, "hoo");
1486
    ok( r == ERROR_SUCCESS, "set string failed\n");
1487 1488 1489 1490 1491 1492 1493
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 3, "size wrong\n");
    ok( 0 == strcmp(buffer,"[1]"), "wrong output\n");
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1]{{boo} }}");
1494
    ok( r == ERROR_SUCCESS, "set string failed\n");
1495
    r = MsiRecordSetString(hrec, 1, "hoo");
1496
    ok( r == ERROR_SUCCESS, "set string failed\n");
1497 1498
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1499 1500 1501 1502 1503
    todo_wine
    {
        ok( sz == 11, "size wrong\n");
        ok( 0 == strcmp(buffer,"hoo{{boo }}"), "wrong output\n");
    }
1504 1505 1506
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1{{boo}}]}");
1507
    ok( r == ERROR_SUCCESS, "set string failed\n");
1508
    r = MsiRecordSetString(hrec, 1, "hoo");
1509
    ok( r == ERROR_SUCCESS, "set string failed\n");
1510 1511
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1512 1513 1514 1515 1516
    todo_wine
    {
        ok( sz == 12, "size wrong: got %u, expected 12\n", sz);
        ok( 0 == strcmp(buffer,"{[1{{boo}}]}"), "wrong output: got %s, expected [1]\n", buffer);
    }
1517 1518 1519
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{{[1]}");
1520
    ok( r == ERROR_SUCCESS, "set string failed\n");
1521
    r = MsiRecordSetString(hrec, 1, "hoo");
1522
    ok( r == ERROR_SUCCESS, "set string failed\n");
1523 1524
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1525
    ok( sz == 6, "size wrong: got %u, expected 3\n", sz);
1526
    ok( 0 == strcmp(buffer,"{{hoo}"), "wrong output: got %s, expected [1]\n", buffer);
1527 1528 1529
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1{{bo}o}}]}");
1530
    ok( r == ERROR_SUCCESS, "set string failed\n");
1531
    r = MsiRecordSetString(hrec, 1, "hoo");
1532
    ok( r == ERROR_SUCCESS, "set string failed\n");
1533 1534 1535
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 13, "size wrong\n");
1536
    ok( 0 == strcmp(buffer,"{[1{{bo}o}}]}"), "wrong output %s\n",buffer);
1537 1538 1539
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1{{b{o}o}}]}");
1540
    ok( r == ERROR_SUCCESS, "set string failed\n");
1541 1542
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1543 1544 1545 1546 1547
    todo_wine
    {
        ok( sz == 14, "size wrong\n");
        ok( 0 == strcmp(buffer,"{[1{{b{o}o}}]}"), "wrong output %s\n",buffer);
    }
1548 1549 1550
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{ {[1]}");
1551
    ok( r == ERROR_SUCCESS, "set string failed\n");
1552
    r = MsiRecordSetString(hrec, 1, "hoo");
1553
    ok( r == ERROR_SUCCESS, "set string failed\n");
1554 1555
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1556 1557 1558 1559 1560
    todo_wine
    {
        ok( sz == 5, "size wrong\n");
        ok( 0 == strcmp(buffer," {hoo"), "wrong output %s\n",buffer);
    }
1561 1562 1563 1564
    ok( r == ERROR_SUCCESS, "format failed\n");

    /* {} inside a substitution does strange things... */
    r = MsiRecordSetString(hrec, 0, "[[1]{}]");
1565
    ok( r == ERROR_SUCCESS, "set string failed\n");
1566
    r = MsiRecordSetString(hrec, 1, "2");
1567
    ok( r == ERROR_SUCCESS, "set string failed\n");
1568 1569
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1570 1571 1572 1573 1574
    todo_wine
    {
        ok( sz == 5, "size wrong\n");
        ok( 0 == strcmp(buffer,"[[1]]"), "wrong output %s\n",buffer);
    }
1575 1576 1577
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[[1]{}[1]]");
1578
    ok( r == ERROR_SUCCESS, "set string failed\n");
1579
    r = MsiRecordSetString(hrec, 1, "2");
1580
    ok( r == ERROR_SUCCESS, "set string failed\n");
1581 1582
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1583 1584 1585 1586 1587
    todo_wine
    {
        ok( sz == 6, "size wrong\n");
        ok( 0 == strcmp(buffer,"[[1]2]"), "wrong output %s\n",buffer);
    }
1588 1589 1590
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[a[1]b[1]c{}d[1]e]");
1591
    ok( r == ERROR_SUCCESS, "set string failed\n");
1592
    r = MsiRecordSetString(hrec, 1, "2");
1593
    ok( r == ERROR_SUCCESS, "set string failed\n");
1594 1595
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1596 1597 1598 1599 1600
    todo_wine
    {
        ok( sz == 14, "size wrong\n");
        ok( 0 == strcmp(buffer,"[a[1]b[1]cd2e]"), "wrong output %s\n",buffer);
    }
1601 1602 1603
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[a[1]b");
1604
    ok( r == ERROR_SUCCESS, "set string failed\n");
1605
    r = MsiRecordSetString(hrec, 1, "2");
1606
    ok( r == ERROR_SUCCESS, "set string failed\n");
1607 1608 1609 1610 1611 1612 1613
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 6, "size wrong\n");
    ok( 0 == strcmp(buffer,"[a[1]b"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "a[1]b]");
1614
    ok( r == ERROR_SUCCESS, "set string failed\n");
1615
    r = MsiRecordSetString(hrec, 1, "2");
1616
    ok( r == ERROR_SUCCESS, "set string failed\n");
1617 1618 1619 1620
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"a2b]"), "wrong output %s\n",buffer);
1621 1622
    ok( r == ERROR_SUCCESS, "format failed\n");

1623
    r = MsiRecordSetString(hrec, 0, "]a[1]b");
1624
    ok( r == ERROR_SUCCESS, "set string failed\n");
1625
    r = MsiRecordSetString(hrec, 1, "2");
1626
    ok( r == ERROR_SUCCESS, "set string failed\n");
1627 1628 1629 1630 1631 1632 1633
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"]a2b"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "]a[1]b");
1634
    ok( r == ERROR_SUCCESS, "set string failed\n");
1635
    r = MsiRecordSetString(hrec, 1, "2");
1636
    ok( r == ERROR_SUCCESS, "set string failed\n");
1637 1638 1639 1640 1641 1642 1643
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 4, "size wrong\n");
    ok( 0 == strcmp(buffer,"]a2b"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "\\[1]");
1644
    ok( r == ERROR_SUCCESS, "set string failed\n");
1645
    r = MsiRecordSetString(hrec, 1, "2");
1646
    ok( r == ERROR_SUCCESS, "set string failed\n");
1647 1648 1649 1650 1651 1652 1653
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"\\2"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "\\{[1]}");
1654
    ok( r == ERROR_SUCCESS, "set string failed\n");
1655
    r = MsiRecordSetString(hrec, 1, "2");
1656
    ok( r == ERROR_SUCCESS, "set string failed\n");
1657 1658 1659 1660 1661 1662 1663
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"\\2"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "a{b[1]c}d");
1664
    ok( r == ERROR_SUCCESS, "set string failed\n");
1665
    r = MsiRecordSetString(hrec, 1, NULL);
1666
    ok( r == ERROR_SUCCESS, "set string failed\n");
1667 1668 1669 1670 1671 1672 1673
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 2, "size wrong\n");
    ok( 0 == strcmp(buffer,"ad"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{a[0]b}");
1674
    ok( r == ERROR_SUCCESS, "set string failed\n");
1675
    r = MsiRecordSetString(hrec, 1, "foo");
1676
    ok( r == ERROR_SUCCESS, "set string failed\n");
1677 1678 1679 1680 1681 1682 1683
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 9, "size wrong\n");
    ok( 0 == strcmp(buffer,"a{a[0]b}b"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "[foo]");
1684
    ok( r == ERROR_SUCCESS, "set string failed\n");
1685 1686 1687 1688 1689 1690 1691
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( sz == 5, "size wrong\n");
    ok( 0 == strcmp(buffer,"[foo]"), "wrong output %s\n",buffer);
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec, 0, "{[1][-1][1]}");
1692
    ok( r == ERROR_SUCCESS, "set string failed\n");
1693
    r = MsiRecordSetString(hrec, 1, "foo");
1694
    ok( r == ERROR_SUCCESS, "set string failed\n");
1695 1696
    sz = sizeof buffer;
    r = MsiFormatRecord(0, hrec, buffer, &sz);
1697 1698 1699 1700 1701
    todo_wine
    {
        ok( sz == 12, "size wrong\n");
        ok( 0 == strcmp(buffer,"{foo[-1]foo}"), "wrong output %s\n",buffer);
    }
1702
    ok( r == ERROR_SUCCESS, "format failed\n");
1703

1704 1705
    /* nested braces */
    sz = sizeof buffer;
1706 1707
    r = MsiRecordSetString(hrec, 0, "{abcd}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1708 1709
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1710
    ok( sz == 6, "size wrong(%i)\n",sz);
1711 1712 1713
    ok( 0 == strcmp(buffer,"{abcd}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1714 1715
    r = MsiRecordSetString(hrec, 0, "{a[one]bc[two]de[one]f}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1716 1717
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1718
    ok( sz == 23, "size wrong(%i)\n",sz);
1719 1720 1721
    ok( 0 == strcmp(buffer,"{a[one]bc[two]de[one]f}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1722 1723
    r = MsiRecordSetString(hrec, 0, "{a[one]bc[bad]de[two]f}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1724 1725
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1726
    ok( sz == 23, "size wrong(%i)\n",sz);
1727 1728 1729
    ok( 0 == strcmp(buffer,"{a[one]bc[bad]de[two]f}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1730 1731
    r = MsiRecordSetString(hrec, 0, "{[bad]}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1732 1733
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1734
    ok( sz == 7, "size wrong(%i)\n",sz);
1735 1736 1737
    ok( 0 == strcmp(buffer,"{[bad]}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1738 1739
    r = MsiRecordSetString(hrec, 0, "{abc{d[one]ef}"); /* missing final brace */
    ok( r == ERROR_SUCCESS, "set string failed\n");
1740 1741
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1742
    ok( sz == 14, "size wrong(%i)\n",sz);
1743 1744 1745
    ok( 0 == strcmp(buffer,"{abc{d[one]ef}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1746 1747
    r = MsiRecordSetString(hrec, 0, "{abc{d[one]ef}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1748 1749
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1750
    ok( sz == 15, "size wrong(%i)\n",sz);
1751 1752 1753
    ok( 0 == strcmp(buffer,"{abc{d[one]ef}}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1754 1755
    r = MsiRecordSetString(hrec, 0, "{abc}{{def}hi{j[one]k}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1756 1757
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1758 1759
    ok( sz == 5, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,"{abc}"), "wrong output (%s)\n",buffer);
1760 1761

    sz = sizeof buffer;
1762 1763
    r = MsiRecordSetString(hrec, 0, "{{def}hi{j[one]k}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1764 1765
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1766 1767
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1768 1769

    sz = sizeof buffer;
1770 1771
    r = MsiRecordSetString(hrec, 0, "{{def}hi{jk}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1772 1773
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1774 1775
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1776 1777

    sz = sizeof buffer;
1778 1779
    r = MsiRecordSetString(hrec, 0, "{{{def}}hi{jk}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1780 1781 1782 1783
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    todo_wine
    {
1784
        ok( sz == 7, "size wrong(%i)\n",sz);
1785 1786 1787 1788
        ok( 0 == strcmp(buffer,"hi{jk}}"), "wrong output (%s)\n",buffer);
    }

    sz = sizeof buffer;
1789 1790
    r = MsiRecordSetString(hrec, 0, "{{def}hi{{jk}}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1791 1792 1793 1794
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    todo_wine
    {
1795
        ok( sz == 1, "size wrong(%i)\n",sz);
1796 1797 1798 1799
        ok( 0 == strcmp(buffer,"}"), "wrong output (%s)\n",buffer);
    }

    sz = sizeof buffer;
1800 1801
    r = MsiRecordSetString(hrec, 0, "{{def}{jk}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1802 1803
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1804 1805
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1806 1807

    sz = sizeof buffer;
1808 1809
    r = MsiRecordSetString(hrec, 0, "{{def}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1810 1811
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1812 1813
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1814 1815

    sz = sizeof buffer;
1816 1817
    r = MsiRecordSetString(hrec, 0, "{a{b}c}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1818 1819
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1820
    ok( sz == 7, "size wrong(%i)\n",sz);
1821 1822 1823
    ok( 0 == strcmp(buffer,"{a{b}c}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1824 1825
    r = MsiRecordSetString(hrec, 0, "{a{b}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1826 1827
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1828
    ok( sz == 6, "size wrong(%i)\n",sz);
1829 1830 1831
    ok( 0 == strcmp(buffer,"{a{b}}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1832 1833
    r = MsiRecordSetString(hrec, 0, "{{b}c}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1834 1835
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1836
    ok( sz == 6, "size wrong(%i)\n",sz);
1837 1838 1839
    ok( 0 == strcmp(buffer,"{{b}c}"), "wrong output (%s)\n",buffer);

    sz = sizeof buffer;
1840 1841
    r = MsiRecordSetString(hrec, 0, "{{{{}}}}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1842 1843 1844 1845
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    todo_wine
    {
1846
        ok( sz == 2, "size wrong(%i)\n",sz);
1847 1848 1849
        ok( 0 == strcmp(buffer,"}}"), "wrong output (%s)\n",buffer);
    }

1850 1851 1852
    sz = sizeof buffer;
    MsiRecordSetInteger(hrec, 1, 100);
    MsiRecordSetInteger(hrec, 2, -100);
1853 1854
    r = MsiRecordSetString(hrec, 0, "[1] [2]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1855 1856 1857 1858 1859
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 8, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,"100 -100"), "wrong output (%s)\n",buffer);

1860
    sz = sizeof(buffer);
1861 1862 1863 1864
    r = MsiRecordSetString(hrec, 0, "[1] {[noprop] [twoprop]} {abcdef}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 1, "one");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1865 1866 1867
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 33, "Expected 33, got %d\n",sz);
1868 1869
    ok(!lstrcmpA(buffer, "one {[noprop] [twoprop]} {abcdef}"),
       "Expected \"one {[noprop] [twoprop]} {abcdef}\", got \"%s\"\n", buffer);
1870 1871

    sz = sizeof(buffer);
1872 1873 1874 1875
    r = MsiRecordSetString(hrec, 0, "[1] {[noprop] [one]} {abcdef}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 1, "one");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1876 1877 1878
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 29, "Expected 29, got %d\n",sz);
1879 1880
    ok(!lstrcmpA(buffer, "one {[noprop] [one]} {abcdef}"),
       "Expected \"one {[noprop] [one]} {abcdef}\", got \"%s\"\n", buffer);
1881 1882

    sz = sizeof(buffer);
1883 1884 1885 1886
    r = MsiRecordSetString(hrec, 0, "[1] {[one]} {abcdef}");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 1, "one");
    ok( r == ERROR_SUCCESS, "set string failed\n");
1887 1888 1889
    r = MsiFormatRecord(0, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 20, "Expected 20, got %d\n",sz);
1890 1891
    ok(!lstrcmpA(buffer, "one {[one]} {abcdef}"),
       "Expected \"one {[one]} {abcdef}\", got \"%s\"\n", buffer);
1892

1893
    MsiCloseHandle( hrec );
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
}

static void test_formatrecord_package(void)
{
    char buffer[100];
    MSIHANDLE hrec;
    MSIHANDLE package;
    UINT r;
    DWORD sz=100;

1904
    r = helper_createpackage( msifile, &package );
1905 1906 1907 1908 1909
    if (r == ERROR_INSTALL_PACKAGE_REJECTED)
    {
        skip("Not enough rights to perform tests\n");
        return;
    }
1910
    ok( r == ERROR_SUCCESS, "Unable to create package %u\n", r );
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921

    hrec = MsiCreateRecord(12);
    ok( hrec, "failed to create record\n");

    r = MsiFormatRecord(package, 0, NULL, NULL );
    ok( r == ERROR_INVALID_HANDLE, "wrong error\n");

    r = MsiFormatRecord(package, hrec, NULL, NULL );
    ok( r == ERROR_SUCCESS, "format failed\n");

    r = MsiRecordSetString(hrec,0,NULL);
1922
    ok( r == ERROR_SUCCESS, "set string failed\n");
1923
    r = MsiRecordSetString(hrec,1,NULL);
1924
    ok( r == ERROR_SUCCESS, "set string failed\n");
1925
    r = MsiRecordSetString(hrec,2,NULL);
1926
    ok( r == ERROR_SUCCESS, "set string failed\n");
1927
    r = MsiRecordSetString(hrec,3,NULL);
1928
    ok( r == ERROR_SUCCESS, "set string failed\n");
1929
    r = MsiRecordSetString(hrec,4,NULL);
1930
    ok( r == ERROR_SUCCESS, "set string failed\n");
1931
    r = MsiRecordSetString(hrec,5,NULL);
1932
    ok( r == ERROR_SUCCESS, "set string failed\n");
1933
    r = MsiRecordSetString(hrec,6,NULL);
1934
    ok( r == ERROR_SUCCESS, "set string failed\n");
1935
    r = MsiRecordSetString(hrec,7,NULL);
1936
    ok( r == ERROR_SUCCESS, "set string failed\n");
1937
    r = MsiRecordSetString(hrec,8,NULL);
1938
    ok( r == ERROR_SUCCESS, "set string failed\n");
1939
    r = MsiRecordSetString(hrec,9,NULL);
1940
    ok( r == ERROR_SUCCESS, "set string failed\n");
1941
    r = MsiRecordSetString(hrec,10,NULL);
1942
    ok( r == ERROR_SUCCESS, "set string failed\n");
1943
    r = MsiRecordSetString(hrec,11,NULL);
1944
    ok( r == ERROR_SUCCESS, "set string failed\n");
1945 1946 1947 1948 1949 1950
    r = MsiRecordSetString(hrec,12,NULL);
    ok( r == ERROR_SUCCESS, "set string failed\n");

    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer (%i)\n",r);
1951
    ok( sz == 51, "size wrong (%i)\n",sz);
1952 1953
    ok( 0 == strcmp(buffer,"1:  2:  3:  4:  5:  6:  7:  8:  9:  10:  11:  12:  "), "wrong output(%s)\n",buffer);

1954 1955 1956 1957
    r = MsiSetProperty(package, "prop", "val");
    ok( r == ERROR_SUCCESS, "failed to set propertY: %d\n", r);

    r = MsiRecordSetString(hrec, 0, NULL);
1958
    ok( r == ERROR_SUCCESS, "set string failed\n");
1959
    r = MsiRecordSetString(hrec, 1, "[2]");
1960
    ok( r == ERROR_SUCCESS, "set string failed\n");
1961
    r = MsiRecordSetString(hrec, 2, "stuff");
1962
    ok( r == ERROR_SUCCESS, "set string failed\n");
1963
    r = MsiRecordSetString(hrec, 3, "prop");
1964
    ok( r == ERROR_SUCCESS, "set string failed\n");
1965
    r = MsiRecordSetString(hrec, 4, "[prop]");
1966
    ok( r == ERROR_SUCCESS, "set string failed\n");
1967
    r = MsiRecordSetString(hrec, 5, "[noprop]");
1968
    ok( r == ERROR_SUCCESS, "set string failed\n");
1969 1970 1971 1972 1973
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed with empty buffer (%i)\n",r);
    todo_wine
    {
1974
        ok( sz == 66, "size wrong (%i)\n",sz);
1975 1976 1977
        ok( !lstrcmpA(buffer,
            "1: [2] 2: stuff 3: prop 4: val 5:  6:  7:  8:  9:  10:  11:  12:  "),
            "wrong output(%s)\n",buffer);
1978 1979
    }

1980 1981
    /* now put play games with escaping */
    r = MsiRecordSetString(hrec, 0, "[1] [2] [\\3asdf]");
1982
    ok( r == ERROR_SUCCESS, "set string failed\n");
1983
    r = MsiRecordSetString(hrec, 1, "boo");
1984
    ok( r == ERROR_SUCCESS, "set string failed\n");
1985 1986 1987 1988 1989
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
1990
    ok( sz == 9, "size wrong(%i)\n",sz);
1991 1992 1993
    ok( 0 == strcmp(buffer,"boo hoo 3"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[1] [2] [\\x]");
1994
    ok( r == ERROR_SUCCESS, "set string failed\n");
1995
    r = MsiRecordSetString(hrec, 1, "boo");
1996
    ok( r == ERROR_SUCCESS, "set string failed\n");
1997 1998 1999 2000 2001
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2002
    ok( sz == 9, "size wrong(%i)\n",sz);
2003 2004
    ok( 0 == strcmp(buffer,"boo hoo x"), "wrong output (%s)\n",buffer);

2005 2006 2007 2008
    MsiRecordSetString(hrec, 0, "[\\x]");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2009
    ok( sz == 1, "size wrong: %d\n", sz);
2010 2011 2012 2013 2014 2015
    ok( 0 == strcmp(buffer,"x"), "wrong output: %s\n", buffer);

    MsiRecordSetString(hrec, 0, "{\\x}");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2016
    ok( sz == 4, "size wrong: %d\n", sz);
2017 2018 2019 2020 2021 2022
    ok( 0 == strcmp(buffer,"{\\x}"), "wrong output: %s\n", buffer);

    MsiRecordSetString(hrec, 0, "[abc\\x]");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2023
    ok( sz == 0, "size wrong: %d\n", sz);
2024 2025 2026 2027 2028 2029
    ok( 0 == strcmp(buffer,""), "wrong output: %s\n", buffer);

    MsiRecordSetString(hrec, 0, "[abc\\xdef]");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2030
    ok( sz == 0, "size wrong: %d\n", sz);
2031 2032
    ok( 0 == strcmp(buffer,""), "wrong output: %s\n", buffer);

2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
    MsiRecordSetString(hrec, 0, "\\x");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 2, "Expected 2, got %d\n", sz);
    ok(!lstrcmpA(buffer, "\\x"), "Expected \"\\x\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\[");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 3, "Expected 3, got %d\n", sz);
    ok(!lstrcmpA(buffer, "[\\["), "Expected \"[\\[\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\[]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 1, "Expected 1, got %d\n", sz);
    ok(!lstrcmpA(buffer, "["), "Expected \"[\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[[]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 3, "Expected 3, got %d\n", sz);
    ok(!lstrcmpA(buffer, "[[]"), "Expected \"[]\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\[]]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 2, "Expected 2, got %d\n", sz);
    ok(!lstrcmpA(buffer, "[]"), "Expected \"[]\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\[a]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 1, "Expected 1, got %d\n", sz);
    ok(!lstrcmpA(buffer, "["), "Expected \"[\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\a[]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    todo_wine
    {
        ok(sz == 1, "Expected 1, got %d\n", sz);
        ok(!lstrcmpA(buffer, "a"), "Expected \"a\", got \"%s\"\n", buffer);
    }

    MsiRecordSetString(hrec, 0, "[prop]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 3, "Expected 3, got %d\n", sz);
    ok(!lstrcmpA(buffer, "val"), "Expected \"val\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[prop] [pro\\pblah] [prop]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 8, "Expected 8, got %d\n", sz);
    ok(!lstrcmpA(buffer, "val  val"), "Expected \"val  val\", got \"%s\"\n", buffer);

    MsiSetPropertyA(package, "b", "ball");
    MsiRecordSetString(hrec, 0, "[\\b]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 1, "Expected 1, got %d\n", sz);
    ok(!lstrcmpA(buffer, "b"), "Expected \"b\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\c]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 1, "Expected 1, got %d\n", sz);
    ok(!lstrcmpA(buffer, "c"), "Expected \"c\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\[]prop]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 6, "Expected 6, got %d\n", sz);
    ok(!lstrcmpA(buffer, "[prop]"), "Expected \"[prop]\", got \"%s\"\n", buffer);

    MsiRecordSetString(hrec, 0, "[\\a]prop]");
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 6, "Expected 6, got %d\n", sz);
    ok(!lstrcmpA(buffer, "aprop]"), "Expected \"aprop]\", got \"%s\"\n", buffer);

2128 2129 2130 2131
    MsiRecordSetString(hrec, 0, "[\\[]Bracket Text[\\]]");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2132
    ok( sz == 14, "size wrong: %d\n", sz);
2133 2134
    ok( 0 == strcmp(buffer,"[Bracket Text]"), "wrong output: %s\n", buffer);

2135 2136
    /* null characters */
    r = MsiRecordSetString(hrec, 0, "[1] [~] [2]");
2137
    ok( r == ERROR_SUCCESS, "set string failed\n");
2138
    r = MsiRecordSetString(hrec, 1, "boo");
2139
    ok( r == ERROR_SUCCESS, "set string failed\n");
2140 2141 2142 2143 2144
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2145 2146 2147 2148
    ok( sz == 9, "size wrong: %d\n", sz);
    ok( 0 == strcmp(buffer,"boo "), "wrong output: %s\n", buffer);
    ok(!lstrcmpA(&buffer[5], " hoo"),
       "Expected \" hoo\", got \"%s\"\n", &buffer[5]);
2149

2150 2151 2152 2153 2154 2155
    r = MsiRecordSetString(hrec, 0, "[1] [~abc] [2]");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 1, "boo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
2156 2157 2158
    sz = sizeof(buffer);
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2159 2160
    ok(sz == 8, "Expected 8, got %d\n", sz);
    ok(!lstrcmpA(buffer, "boo  hoo"), "Expected \"boo  hoo\", got \"%s\"\n", buffer);
2161

2162 2163 2164 2165
    /* properties */
    r = MsiSetProperty(package,"dummy","Bork");
    ok( r == ERROR_SUCCESS, "set property failed\n");
    r = MsiRecordSetString(hrec, 0, "[1] [dummy] [2]");
2166
    ok( r == ERROR_SUCCESS, "set string failed\n");
2167
    r = MsiRecordSetString(hrec, 1, "boo");
2168
    ok( r == ERROR_SUCCESS, "set string failed\n");
2169 2170 2171 2172 2173 2174 2175 2176 2177
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 12, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo Bork hoo"), "wrong output\n");

    r = MsiRecordSetString(hrec, 0, "[1] [invalid] [2]");
2178
    ok( r == ERROR_SUCCESS, "set string failed\n");
2179
    r = MsiRecordSetString(hrec, 1, "boo");
2180
    ok( r == ERROR_SUCCESS, "set string failed\n");
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
    r = MsiRecordSetString(hrec, 2, "hoo");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
    ok( sz == 8, "size wrong\n");
    ok( 0 == strcmp(buffer,"boo  hoo"), "wrong output\n");

    /* nesting tests */
    r = MsiSetProperty(package,"dummya","foo");
2191
    ok( r == ERROR_SUCCESS, "set string failed\n");
2192
    r = MsiSetProperty(package,"dummyb","baa");
2193
    ok( r == ERROR_SUCCESS, "set string failed\n");
2194 2195 2196
    r = MsiSetProperty(package,"adummyc","whoa");
    ok( r == ERROR_SUCCESS, "set property failed\n");
    r = MsiRecordSetString(hrec, 0, "[dummy[1]] [dummy[2]] [[1]dummy[3]]");
2197
    ok( r == ERROR_SUCCESS, "set string failed\n");
2198
    r = MsiRecordSetString(hrec, 1, "a");
2199
    ok( r == ERROR_SUCCESS, "set string failed\n");
2200
    r = MsiRecordSetString(hrec, 2, "b");
2201
    ok( r == ERROR_SUCCESS, "set string failed\n");
2202 2203 2204 2205 2206
    r = MsiRecordSetString(hrec, 3, "c");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2207
    ok( sz == 12, "size wrong(%i)\n",sz);
2208 2209 2210
    ok( 0 == strcmp(buffer,"foo baa whoa"), "wrong output (%s)\n",buffer);

    r = MsiSetProperty(package,"dummya","1");
2211
    ok( r == ERROR_SUCCESS, "set property failed\n");
2212 2213 2214
    r = MsiSetProperty(package,"dummyb","[2]");
    ok( r == ERROR_SUCCESS, "set property failed\n");
    r = MsiRecordSetString(hrec, 0, "[dummya] [[dummya]] [dummyb]");
2215
    ok( r == ERROR_SUCCESS, "set string failed\n");
2216
    r = MsiRecordSetString(hrec, 1, "aaa");
2217
    ok( r == ERROR_SUCCESS, "set string failed\n");
2218
    r = MsiRecordSetString(hrec, 2, "bbb");
2219
    ok( r == ERROR_SUCCESS, "set string failed\n");
2220 2221 2222 2223 2224
    r = MsiRecordSetString(hrec, 3, "ccc");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2225 2226 2227 2228 2229
    todo_wine
    {
        ok( sz == 9, "size wrong(%i)\n",sz);
        ok( 0 == strcmp(buffer,"1 [1] [2]"), "wrong output (%s)\n",buffer);
    }
2230 2231

    r = MsiSetProperty(package,"dummya","1");
2232
    ok( r == ERROR_SUCCESS, "set property failed\n");
2233
    r = MsiSetProperty(package,"dummyb","a");
2234
    ok( r == ERROR_SUCCESS, "set property failed\n");
2235
    r = MsiSetProperty(package,"dummyc","\\blath");
2236
    ok( r == ERROR_SUCCESS, "set property failed\n");
2237 2238 2239
    r = MsiSetProperty(package,"dummyd","[\\blath]");
    ok( r == ERROR_SUCCESS, "set property failed\n");
    r = MsiRecordSetString(hrec, 0, "[dummyc] [[dummyc]] [dummy[dummyb]]");
2240
    ok( r == ERROR_SUCCESS, "set string failed\n");
2241
    r = MsiRecordSetString(hrec, 1, "aaa");
2242
    ok( r == ERROR_SUCCESS, "set string failed\n");
2243
    r = MsiRecordSetString(hrec, 2, "bbb");
2244
    ok( r == ERROR_SUCCESS, "set string failed\n");
2245 2246 2247 2248 2249
    r = MsiRecordSetString(hrec, 3, "ccc");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2250
    ok( sz == 10, "size wrong(%i)\n",sz);
2251 2252 2253
    ok( 0 == strcmp(buffer,"\\blath b 1"), "wrong output (%s)\n",buffer);

    r = MsiRecordSetString(hrec, 0, "[1] [2] [[\\3asdf]]");
2254
    ok( r == ERROR_SUCCESS, "set string failed\n");
2255
    r = MsiRecordSetString(hrec, 1, "boo");
2256
    ok( r == ERROR_SUCCESS, "set string failed\n");
2257
    r = MsiRecordSetString(hrec, 2, "hoo");
2258
    ok( r == ERROR_SUCCESS, "set string failed\n");
2259 2260 2261 2262 2263
    r = MsiRecordSetString(hrec, 3, "yeah");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2264 2265 2266 2267 2268
    todo_wine
    {
        ok( sz == 11, "size wrong(%i)\n",sz);
        ok( 0 == strcmp(buffer,"boo hoo [3]"), "wrong output (%s)\n",buffer);
    }
2269 2270

    r = MsiRecordSetString(hrec, 0, "[1] [2] [[3]]");
2271
    ok( r == ERROR_SUCCESS, "set string failed\n");
2272
    r = MsiRecordSetString(hrec, 1, "boo");
2273
    ok( r == ERROR_SUCCESS, "set string failed\n");
2274
    r = MsiRecordSetString(hrec, 2, "hoo");
2275
    ok( r == ERROR_SUCCESS, "set string failed\n");
2276 2277 2278 2279 2280
    r = MsiRecordSetString(hrec, 3, "\\help");
    ok( r == ERROR_SUCCESS, "set string failed\n");
    sz = sizeof buffer;
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2281
    ok( sz == 9, "size wrong(%i)\n",sz);
2282 2283
    ok( 0 == strcmp(buffer,"boo hoo h"), "wrong output (%s)\n",buffer);

2284 2285 2286 2287 2288 2289 2290 2291
    /* nested properties */
    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "[PropA]");
    MsiSetProperty(package, "PropC", "[PropB]");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[PropC]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2292
    ok( sz == 7, "size wrong(%i)\n",sz);
2293 2294 2295 2296 2297 2298 2299 2300 2301
    ok( 0 == strcmp(buffer,"[PropB]"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "PropA");
    MsiSetProperty(package, "PropC", "PropB");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[PropC]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2302
    ok( sz == 5, "size wrong(%i)\n",sz);
2303 2304 2305 2306 2307 2308 2309 2310 2311
    ok( 0 == strcmp(buffer,"PropB"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "[PropA]");
    MsiSetProperty(package, "PropC", "[PropB]");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[[PropC]]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2312
    ok( sz == 0, "size wrong(%i)\n",sz);
2313 2314 2315 2316 2317 2318 2319 2320 2321
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "[PropA]");
    MsiSetProperty(package, "PropC", "PropB");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[[PropC]]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2322
    ok( sz == 7, "size wrong(%i)\n",sz);
2323 2324 2325 2326 2327 2328 2329 2330 2331
    ok( 0 == strcmp(buffer,"[PropA]"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "PropA");
    MsiSetProperty(package, "PropC", "PropB");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[[PropC]]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2332
    ok( sz == 5, "size wrong(%i)\n",sz);
2333 2334 2335 2336 2337 2338 2339 2340 2341
    ok( 0 == strcmp(buffer,"PropA"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "PropA", "surprise");
    MsiSetProperty(package, "PropB", "PropA");
    MsiSetProperty(package, "PropC", "PropB");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "[[[PropC]]]");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2342
    ok( sz == 8, "size wrong(%i)\n",sz);
2343 2344 2345 2346 2347 2348 2349
    ok( 0 == strcmp(buffer,"surprise"), "wrong output (%s)\n",buffer);

    /* properties inside braces */
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{abcd}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2350
    ok( sz == 6, "size wrong(%i)\n",sz);
2351 2352 2353 2354 2355 2356 2357
    ok( 0 == strcmp(buffer,"{abcd}"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "one", "mercury");
    MsiSetProperty(package, "two", "venus");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{a[one]bc[two]de[one]f}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
2358
    ok( r == ERROR_SUCCESS, "format failed: %d\n", r);
2359
    ok( sz == 25, "size wrong(%i)\n",sz);
2360 2361 2362 2363 2364 2365 2366 2367 2368
    ok( 0 == strcmp(buffer,"amercurybcvenusdemercuryf"), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "one", "mercury");
    MsiSetProperty(package, "two", "venus");
    MsiSetProperty(package, "bad", "");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{a[one]bc[bad]de[two]f}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2369 2370
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2371 2372 2373 2374 2375 2376

    MsiSetProperty(package, "bad", "");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{[bad]}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2377
    ok( sz == 0, "size wrong(%i)\n",sz);
2378 2379 2380 2381 2382 2383 2384
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);

    MsiSetProperty(package, "one", "mercury");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{abc{d[one]ef}"); /* missing final brace */
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2385 2386 2387 2388 2389
    todo_wine
    {
        ok( sz == 14, "size wrong(%i)\n",sz);
        ok( 0 == strcmp(buffer,"abc{dmercuryef"), "wrong output (%s)\n",buffer);
    }
2390 2391 2392 2393 2394 2395

    MsiSetProperty(package, "one", "mercury");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{abc{d[one]ef}}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2396 2397 2398 2399 2400
    todo_wine
    {
        ok( sz == 15, "size wrong(%i)\n",sz);
        ok( 0 == strcmp(buffer,"abc{dmercuryef}"), "wrong output (%s)\n",buffer);
    }
2401 2402 2403 2404 2405 2406

    MsiSetProperty(package, "one", "mercury");
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{abc}{{def}hi{j[one]k}}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2407 2408
    ok( sz == 5, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,"{abc}"), "wrong output (%s)\n",buffer);
2409 2410

    MsiSetProperty(package, "one", "mercury");
2411

2412 2413 2414 2415
    sz = sizeof buffer;
    MsiRecordSetString(hrec, 0, "{{def}hi{j[one]k}}");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok( r == ERROR_SUCCESS, "format failed\n");
2416 2417
    ok( sz == 0, "size wrong(%i)\n",sz);
    ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2418

2419 2420 2421 2422 2423 2424
    sz = sizeof(buffer);
    MsiRecordSetString(hrec, 0, "[1] {[noprop] [twoprop]} {abcdef}");
    MsiRecordSetString(hrec, 1, "one");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 13, "Expected 13, got %d\n",sz);
2425 2426
    ok(!lstrcmpA(buffer, "one  {abcdef}"),
       "Expected \"one  {abcdef}\", got \"%s\"\n", buffer);
2427 2428 2429 2430 2431 2432 2433

    sz = sizeof(buffer);
    MsiRecordSetString(hrec, 0, "[1] {[noprop] [one]} {abcdef}");
    MsiRecordSetString(hrec, 1, "one");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 13, "Expected 13, got %d\n",sz);
2434 2435
    ok(!lstrcmpA(buffer, "one  {abcdef}"),
       "Expected \"one  {abcdef}\", got \"%s\"\n", buffer);
2436 2437 2438 2439 2440 2441 2442

    sz = sizeof(buffer);
    MsiRecordSetString(hrec, 0, "[1] {[one]} {abcdef}");
    MsiRecordSetString(hrec, 1, "one");
    r = MsiFormatRecord(package, hrec, buffer, &sz);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
    ok(sz == 20, "Expected 20, got %d\n",sz);
2443 2444
    ok(!lstrcmpA(buffer, "one mercury {abcdef}"),
       "Expected \"one mercury {abcdef}\", got \"%s\"\n", buffer);
2445

2446 2447
    MsiCloseHandle(hrec);

2448 2449 2450
    r = MsiCloseHandle(package);
    ok(r==ERROR_SUCCESS, "Unable to close package\n");

2451
    DeleteFile( msifile );
2452 2453
}

2454 2455
static void test_formatrecord_tables(void)
{
2456
    MSIHANDLE hdb, hrec, hpkg = 0;
2457 2458 2459
    CHAR buf[MAX_PATH];
    CHAR curr_dir[MAX_PATH];
    CHAR expected[MAX_PATH];
2460
    CHAR root[MAX_PATH];
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
    DWORD size;
    UINT r;

    GetCurrentDirectory( MAX_PATH, curr_dir );

    hdb = create_package_db();
    ok ( hdb, "failed to create package database\n");

    r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'" );
    ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r);

    r = add_directory_entry( hdb, "'ReallyLongDir', 'TARGETDIR', "
                             "'I am a really long directory'" );
    ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r);

    r = create_feature_table( hdb );
    ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r);

    r = add_feature_entry( hdb, "'occipitofrontalis', '', '', '', 2, 1, '', 0" );
    ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );

    r = create_component_table( hdb );
    ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r);

    r = add_component_entry( hdb, "'frontal', '', 'TARGETDIR', 0, '', 'frontal_file'" );
    ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r);

    r = add_component_entry( hdb, "'parietal', '', 'TARGETDIR', 1, '', 'parietal_file'" );
    ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r);

    r = add_component_entry( hdb, "'temporal', '', 'ReallyLongDir', 0, '', 'temporal_file'" );
    ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r);

    r = create_feature_components_table( hdb );
    ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r);

    r = add_feature_components_entry( hdb, "'occipitofrontalis', 'frontal'" );
    ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r);

    r = add_feature_components_entry( hdb, "'occipitofrontalis', 'parietal'" );
    ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r);

    r = add_feature_components_entry( hdb, "'occipitofrontalis', 'temporal'" );
    ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r);

    r = create_file_table( hdb );
    ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r);

    r = add_file_entry( hdb, "'frontal_file', 'frontal', 'frontal.txt', 0, '', '1033', 8192, 1" );
    ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);

    r = add_file_entry( hdb, "'parietal_file', 'parietal', 'parietal.txt', 0, '', '1033', 8192, 1" );
    ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);

    r = add_file_entry( hdb, "'temporal_file', 'temporal', 'temporal.txt', 0, '', '1033', 8192, 1" );
    ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);

    r = create_custom_action_table( hdb );
    ok( r == ERROR_SUCCESS, "cannot create CustomAction table: %d\n", r);

    r = add_custom_action_entry( hdb, "'MyCustom', 51, 'prop', '[!temporal_file]'" );
2522
    ok( r == ERROR_SUCCESS, "cannot add custom action: %d\n", r);
2523

2524
    r = add_custom_action_entry( hdb, "'EscapeIt1', 51, 'prop', '[\\[]Bracket Text[\\]]'" );
2525
    ok( r == ERROR_SUCCESS, "cannot add custom action: %d\n", r);
2526 2527

    r = add_custom_action_entry( hdb, "'EscapeIt2', 51, 'prop', '[\\xabcd]'" );
2528
    ok( r == ERROR_SUCCESS, "cannot add custom action: %d\n", r);
2529 2530

    r = add_custom_action_entry( hdb, "'EscapeIt3', 51, 'prop', '[abcd\\xefgh]'" );
2531
    ok( r == ERROR_SUCCESS, "cannot add custom action: %d\n", r);
2532

2533
    r = package_from_db( hdb, &hpkg );
2534 2535 2536 2537 2538 2539 2540
    if (r == ERROR_INSTALL_PACKAGE_REJECTED)
    {
        skip("Not enough rights to perform tests\n");
        MsiCloseHandle( hdb );
        DeleteFile( msifile );
        return;
    }
2541
    ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551

    MsiCloseHandle( hdb );

    r = MsiSetPropertyA( hpkg, "imaprop", "ringer" );
    ok( r == ERROR_SUCCESS, "cannot set property: %d\n", r);

    hrec = MsiCreateRecord( 1 );

    /* property doesn't exist */
    size = MAX_PATH;
2552
    /*MsiRecordSetString( hrec, 0, "[1]" ); */
2553 2554 2555
    MsiRecordSetString( hrec, 1, "[idontexist]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2556
    ok( !lstrcmp( buf, "1:  " ), "Expected '1:  ', got %s\n", buf );
2557 2558 2559 2560 2561 2562

    /* property exists */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[imaprop]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2563
    ok( !lstrcmp( buf, "1: ringer " ), "Expected '1: ringer ', got %s\n", buf );
2564 2565 2566 2567 2568 2569

    /* environment variable doesn't exist */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[%idontexist]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2570
    ok( !lstrcmp( buf, "1:  " ), "Expected '1:  ', got %s\n", buf );
2571 2572 2573 2574 2575 2576 2577

    /* environment variable exists */
    size = MAX_PATH;
    SetEnvironmentVariable( "crazyvar", "crazyval" );
    MsiRecordSetString( hrec, 1, "[%crazyvar]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2578
    ok( !lstrcmp( buf, "1: crazyval " ), "Expected '1: crazyval ', got %s\n", buf );
2579 2580 2581 2582 2583 2584

    /* file key before CostInitialize */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[#frontal_file]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2585
    ok( !lstrcmp( buf, "1:  " ), "Expected '1:  ', got %s\n", buf );
2586

2587 2588
    MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);

2589 2590 2591 2592 2593 2594 2595 2596 2597
    r = MsiDoAction(hpkg, "CostInitialize");
    ok( r == ERROR_SUCCESS, "CostInitialize failed: %d\n", r);

    r = MsiDoAction(hpkg, "FileCost");
    ok( r == ERROR_SUCCESS, "FileCost failed: %d\n", r);

    r = MsiDoAction(hpkg, "CostFinalize");
    ok( r == ERROR_SUCCESS, "CostFinalize failed: %d\n", r);

2598 2599 2600 2601 2602
    size = MAX_PATH;
    MsiGetProperty( hpkg, "ROOTDRIVE", root, &size );

    sprintf( expected, "1: %sfrontal.txt ", root);

2603 2604 2605 2606 2607
    /* frontal full file key */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[#frontal_file]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2608
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);
2609 2610 2611 2612 2613 2614

    /* frontal short file key */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[!frontal_file]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2615 2616 2617
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);

    sprintf( expected, "1: %sI am a really long directory\\temporal.txt ", root);
2618 2619 2620 2621 2622 2623

    /* temporal full file key */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[#temporal_file]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2624
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);
2625 2626 2627 2628 2629 2630

    /* temporal short file key */
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[!temporal_file]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2631
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);
2632 2633 2634 2635 2636

    /* custom action 51, files don't exist */
    r = MsiDoAction( hpkg, "MyCustom" );
    ok( r == ERROR_SUCCESS, "MyCustom failed: %d\n", r);

2637 2638
    sprintf( expected, "%sI am a really long directory\\temporal.txt", root);

2639 2640 2641
    size = MAX_PATH;
    r = MsiGetProperty( hpkg, "prop", buf, &size );
    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
2642 2643 2644 2645
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);

    sprintf( buf, "%sI am a really long directory", root );
    CreateDirectory( buf, NULL );
2646

2647 2648
    lstrcat( buf, "\\temporal.txt" );
    create_test_file( buf );
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658

    /* custom action 51, files exist */
    r = MsiDoAction( hpkg, "MyCustom" );
    ok( r == ERROR_SUCCESS, "MyCustom failed: %d\n", r);

    size = MAX_PATH;
    r = MsiGetProperty( hpkg, "prop", buf, &size );
    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
    todo_wine
    {
2659
        ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);
2660 2661
    }

2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688
    /* custom action 51, escaped text 1 */
    r = MsiDoAction( hpkg, "EscapeIt1" );
    ok( r == ERROR_SUCCESS, "EscapeIt failed: %d\n", r);

    size = MAX_PATH;
    r = MsiGetProperty( hpkg, "prop", buf, &size );
    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
    ok( !lstrcmp( buf, "[Bracket Text]" ), "Expected '[Bracket Text]', got %s\n", buf);

    /* custom action 51, escaped text 2 */
    r = MsiDoAction( hpkg, "EscapeIt2" );
    ok( r == ERROR_SUCCESS, "EscapeIt failed: %d\n", r);

    size = MAX_PATH;
    r = MsiGetProperty( hpkg, "prop", buf, &size );
    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
    ok( !lstrcmp( buf, "x" ), "Expected 'x', got %s\n", buf);

    /* custom action 51, escaped text 3 */
    r = MsiDoAction( hpkg, "EscapeIt3" );
    ok( r == ERROR_SUCCESS, "EscapeIt failed: %d\n", r);

    size = MAX_PATH;
    r = MsiGetProperty( hpkg, "prop", buf, &size );
    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
    ok( !lstrcmp( buf, "" ), "Expected '', got %s\n", buf);

2689 2690
    sprintf( expected, "1: %sI am a really long directory\\ ", root);

2691 2692
    /* component with INSTALLSTATE_LOCAL */
    size = MAX_PATH;
2693
    MsiRecordSetString( hrec, 1, "[$temporal]" );
2694 2695
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2696
    ok( !lstrcmp( buf, expected ), "Expected \"%s\", got \"%s\"\n", expected, buf);
2697 2698 2699 2700 2701 2702 2703

    r = MsiSetComponentState( hpkg, "temporal", INSTALLSTATE_SOURCE );
    ok( r == ERROR_SUCCESS, "failed to set install state: %d\n", r);

    /* component with INSTALLSTATE_SOURCE */
    lstrcpy( expected, "1: " );
    lstrcat( expected, curr_dir );
2704 2705 2706
    if (strlen(curr_dir) > 3)
        lstrcat( expected, "\\" );
    lstrcat( expected, " " );
2707 2708 2709 2710
    size = MAX_PATH;
    MsiRecordSetString( hrec, 1, "[$parietal]" );
    r = MsiFormatRecord( hpkg, hrec, buf, &size );
    ok( r == ERROR_SUCCESS, "format record failed: %d\n", r);
2711
    ok( !lstrcmp( buf, expected ), "Expected '%s', got '%s'\n", expected, buf);
2712

2713 2714 2715 2716 2717
    sprintf( buf, "%sI am a really long directory\\temporal.txt", root );
    DeleteFile( buf );

    sprintf( buf, "%sI am a really long directory", root );
    RemoveDirectory( buf );
2718

2719
    MsiCloseHandle( hrec );
2720 2721 2722 2723
    MsiCloseHandle( hpkg );
    DeleteFile( msifile );
}

2724 2725
static void test_processmessage(void)
{
2726 2727
    MSIHANDLE hrec, package;
    UINT r;
2728

2729 2730
    MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);

2731
    r = helper_createpackage( msifile, &package );
2732 2733 2734 2735 2736
    if (r == ERROR_INSTALL_PACKAGE_REJECTED)
    {
        skip("Not enough rights to perform tests\n");
        return;
    }
2737
    ok( r == ERROR_SUCCESS, "Unable to create package %u\n", r );
2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750

    hrec = MsiCreateRecord(3);
    ok( hrec, "failed to create record\n");

    r = MsiRecordSetString(hrec, 1, "");
    ok( r == ERROR_SUCCESS, "set string failed\n");

    r = MsiProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, hrec);
    ok( r == IDOK, "expected IDOK, got %i\n", r);

    MsiCloseHandle(hrec);
    MsiCloseHandle(package);

2751
    DeleteFile(msifile);
2752 2753
}

2754 2755 2756 2757 2758
START_TEST(format)
{
    test_createpackage();
    test_formatrecord();
    test_formatrecord_package();
2759
    test_formatrecord_tables();
2760
    test_processmessage();
2761
}