1 /*
2  * Copyright (C) 2005 Mike McCormack for CodeWeavers
3  * Copyright (C) 2005 Aric Stewart for CodeWeavers
4  *
5  * A test program for MSI record formatting
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * 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 #include <stdio.h>
23 #include <windows.h>
24 #include <shlwapi.h>
25 #include <msi.h>
26 #include <msiquery.h>
27 
28 #include "wine/test.h"
29 
30 static const char msifile[] = "winetest-format.msi";
31 
32 static UINT package_from_db(MSIHANDLE hdb, MSIHANDLE *handle)
33 {
34     UINT res;
35     CHAR szPackage[12];
36     MSIHANDLE hPackage;
37 
38     sprintf(szPackage, "#%u", hdb);
39     res = MsiOpenPackageA(szPackage, &hPackage);
40     if (res != ERROR_SUCCESS)
41         return res;
42 
43     res = MsiCloseHandle(hdb);
44     if (res != ERROR_SUCCESS)
45     {
46         MsiCloseHandle(hPackage);
47         return res;
48     }
49 
50     *handle = hPackage;
51     return ERROR_SUCCESS;
52 }
53 
54 static UINT helper_createpackage( const char *szName, MSIHANDLE *handle )
55 {
56     MSIHANDLE hPackage, suminfo, hdb = 0;
57     UINT res;
58     WCHAR *nameW;
59     int len;
60 
61     DeleteFileA(szName);
62 
63     len = MultiByteToWideChar( CP_ACP, 0, szName, -1, NULL, 0 );
64     if (!(nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
65         return ERROR_OUTOFMEMORY;
66     MultiByteToWideChar( CP_ACP, 0, szName, -1, nameW, len );
67 
68     /* create an empty database */
69     res = MsiOpenDatabaseW( nameW, MSIDBOPEN_CREATEDIRECT, &hdb );
70     HeapFree( GetProcessHeap(), 0, nameW );
71     ok( res == ERROR_SUCCESS , "Failed to create database %u\n", res );
72     if (res != ERROR_SUCCESS)
73         return res;
74 
75     res = MsiDatabaseCommit( hdb );
76     ok( res == ERROR_SUCCESS , "Failed to commit database %u\n", res );
77 
78     /* build summary info */
79     res = MsiGetSummaryInformationA(hdb, NULL, 7, &suminfo);
80     ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
81 
82     res = MsiSummaryInfoSetPropertyA(suminfo,2, VT_LPSTR, 0,NULL,
83                         "Installation Database");
84     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
85 
86     res = MsiSummaryInfoSetPropertyA(suminfo,3, VT_LPSTR, 0,NULL,
87                         "Installation Database");
88     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
89 
90     res = MsiSummaryInfoSetPropertyA(suminfo,4, VT_LPSTR, 0,NULL,
91                         "Wine Hackers");
92     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
93 
94     res = MsiSummaryInfoSetPropertyA(suminfo,7, VT_LPSTR, 0,NULL,
95                     ";1033");
96     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
97 
98     res = MsiSummaryInfoSetPropertyA(suminfo,9, VT_LPSTR, 0,NULL,
99                     "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
100     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
101 
102     res = MsiSummaryInfoSetPropertyA(suminfo, 14, VT_I4, 100, NULL, NULL);
103     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
104 
105     res = MsiSummaryInfoSetPropertyA(suminfo, 15, VT_I4, 0, NULL, NULL);
106     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
107 
108     res = MsiSummaryInfoPersist(suminfo);
109     ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
110 
111     res = MsiCloseHandle( suminfo);
112     ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
113 
114     res = package_from_db( hdb, &hPackage );
115     MsiCloseHandle(hdb);
116 
117     if (res != ERROR_SUCCESS)
118         DeleteFileA( szName );
119     else
120         *handle = hPackage;
121 
122     return res;
123 }
124 
125 static void test_createpackage(void)
126 {
127     MSIHANDLE hPackage = 0;
128     UINT res;
129 
130     res = helper_createpackage( msifile, &hPackage );
131     if (res == ERROR_INSTALL_PACKAGE_REJECTED)
132     {
133         skip("Not enough rights to perform tests\n");
134         return;
135     }
136     ok( res == ERROR_SUCCESS, "Failed to create package %u\n", res );
137 
138     res = MsiCloseHandle( hPackage );
139     ok( res == ERROR_SUCCESS , "Failed to close package %u\n", res );
140 
141     DeleteFileA( msifile );
142 }
143 
144 static void test_formatrecord(void)
145 {
146     char buffer[100];
147     MSIHANDLE hrec;
148     UINT r;
149     DWORD sz;
150 
151     r = MsiFormatRecordA(0, 0, NULL, NULL );
152     ok( r == ERROR_INVALID_HANDLE, "wrong error\n");
153 
154     hrec = MsiCreateRecord(0);
155     ok( hrec, "failed to create record\n");
156 
157     /* format an empty record on a record with no parameters */
158     sz = sizeof(buffer);
159     r = MsiFormatRecordA(0, hrec, buffer, &sz );
160     ok( r == ERROR_SUCCESS, "format failed\n");
161     ok( sz == 0, "size wrong\n");
162 
163     MsiCloseHandle( hrec );
164 
165     hrec = MsiCreateRecord(4);
166     ok( hrec, "failed to create record\n");
167 
168     /* format an empty record */
169     r = MsiFormatRecordA(0, hrec, NULL, NULL );
170     ok( r == ERROR_SUCCESS, "format failed\n");
171     buffer[0] = 'x';
172     buffer[1] = 0;
173     sz=0;
174     r = MsiFormatRecordA(0, hrec, buffer+1, &sz);
175     ok( r == ERROR_MORE_DATA && buffer[0] == 'x', "format failed measuring with buffer\n");
176     ok( sz == 16, "size wrong\n");
177     sz=100;
178     r = MsiFormatRecordA(0, hrec, buffer, &sz);
179     ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
180     ok( sz == 16, "size wrong\n");
181     ok( 0 == strcmp(buffer,"1:  2:  3:  4:  "), "wrong output\n");
182 
183     r = MsiCloseHandle(hrec);
184     ok(r==ERROR_SUCCESS, "Unable to close record\n");
185 
186     hrec = MsiCreateRecord(6);
187     ok( hrec, "failed to create record\n");
188 
189     sz = 100;
190     buffer[0] = 'x';
191     buffer[1] = 0;
192     r = MsiFormatRecordA(0, hrec, buffer, &sz);
193     ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
194     ok( sz == 24, "size wrong\n");
195     ok( 0 == strcmp(buffer,"1:  2:  3:  4:  5:  6:  "), "wrong output\n");
196 
197 
198     /* format a format string with everything else empty */
199     r = MsiRecordSetStringA(hrec, 0, "%1");
200     ok( r == ERROR_SUCCESS, "set string failed\n");
201     r = MsiFormatRecordA(0, hrec, NULL, NULL );
202     ok( r == ERROR_SUCCESS, "format failed\n");
203     r = MsiFormatRecordA(0, hrec, buffer, NULL);
204     ok( r == ERROR_INVALID_PARAMETER, "wrong error\n");
205 
206     sz = 123;
207     r = MsiFormatRecordA(0, hrec, NULL, &sz);
208     ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
209     ok( sz == 2, "size wrong (%i)\n",sz);
210     sz = sizeof buffer;
211     buffer[0] = 'x';
212     buffer[1] = 0;
213     r = MsiFormatRecordA(0, hrec, buffer, &sz);
214     ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
215     ok( sz == 2, "size wrong\n");
216     ok( 0 == strcmp(buffer,"%1"), "wrong output\n");
217 
218     /* make the buffer too small */
219     sz = 0;
220     buffer[0] = 'x';
221     buffer[1] = 0;
222     r = MsiFormatRecordA(0, hrec, buffer, &sz);
223     ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
224     ok( sz == 2, "size wrong\n");
225     ok( 0 == strcmp(buffer,"x"), "wrong output\n");
226 
227     /* make the buffer a little bit bigger */
228     sz = 1;
229     buffer[0] = 'x';
230     buffer[1] = 0;
231     r = MsiFormatRecordA(0, hrec, buffer, &sz);
232     ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
233     ok( sz == 2, "size wrong\n");
234     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
235 
236     /* and again */
237     sz = 2;
238     buffer[0] = 'x';
239     buffer[1] = 0;
240     r = MsiFormatRecordA(0, hrec, buffer, &sz);
241     ok( r == ERROR_MORE_DATA, "format failed with empty buffer\n");
242     ok( sz == 2, "size wrong\n");
243     ok( 0 == strcmp(buffer,"%"), "wrong output\n");
244 
245     /* and again */
246     sz = 3;
247     buffer[0] = 'x';
248     buffer[1] = 0;
249     r = MsiFormatRecordA(0, hrec, buffer, &sz);
250     ok( r == ERROR_SUCCESS, "format failed with empty buffer\n");
251     ok( sz == 2, "size wrong\n");
252     ok( 0 == strcmp(buffer,"%1"), "wrong output\n");
253 
254     /* now try a real format string */
255     r = MsiRecordSetStringA(hrec, 0, "[1]");
256     ok( r == ERROR_SUCCESS, "set string failed\n");
257     sz = sizeof buffer;
258     r = MsiFormatRecordA(0, hrec, buffer, &sz);
259     ok( r == ERROR_SUCCESS, "format failed\n");
260     ok( sz == 0, "size wrong\n");
261     ok( 0 == strcmp(buffer,""), "wrong output\n");
262 
263     /* now put something in the first field */
264     r = MsiRecordSetStringA(hrec, 1, "boo hoo");
265     ok( r == ERROR_SUCCESS, "set string failed\n");
266     sz = sizeof buffer;
267     r = MsiFormatRecordA(0, hrec, buffer, &sz);
268     ok( r == ERROR_SUCCESS, "format failed\n");
269     ok( sz == 7, "size wrong\n");
270     ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
271 
272     /* now put something in the first field */
273     r = MsiRecordSetStringA(hrec, 0, "[1] [2]");
274     ok( r == ERROR_SUCCESS, "set string failed\n");
275     r = MsiRecordSetStringA(hrec, 1, "boo");
276     ok( r == ERROR_SUCCESS, "set string failed\n");
277     r = MsiRecordSetStringA(hrec, 2, "hoo");
278     ok( r == ERROR_SUCCESS, "set string failed\n");
279     sz = sizeof buffer;
280     r = MsiFormatRecordA(0, hrec, buffer, &sz);
281     ok( r == ERROR_SUCCESS, "format failed\n");
282     ok( sz == 7, "size wrong\n");
283     ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
284 
285     /* self-referential format field */
286     r = MsiRecordSetStringA(hrec, 0, "[1] test [0]");
287     ok( r == ERROR_SUCCESS, "set string failed\n");
288     sz = sizeof buffer;
289     r = MsiFormatRecordA(0, hrec, buffer, &sz);
290     ok( r == ERROR_SUCCESS, "format failed\n");
291     ok( sz == 21, "size wrong\n");
292     ok( 0 == strcmp(buffer,"boo test [1] test [0]"), "wrong output\n");
293 
294     /* empty string */
295     r = MsiRecordSetStringA(hrec, 0, "");
296     ok( r == ERROR_SUCCESS, "set string failed\n");
297     sz = sizeof buffer;
298     r = MsiFormatRecordA(0, hrec, buffer, &sz);
299     ok( r == ERROR_SUCCESS, "format failed\n");
300     ok( sz == 30, "size wrong %i\n",sz);
301     ok( 0 == strcmp(buffer,"1: boo 2: hoo 3:  4:  5:  6:  "),
302                     "wrong output(%s)\n",buffer);
303 
304     /* empty string with numbers */
305     r = MsiRecordSetStringA(hrec, 1, "123");
306     ok( r == ERROR_SUCCESS, "set string failed\n");
307     r = MsiRecordSetInteger(hrec, 2, 4567);
308     ok( r == ERROR_SUCCESS, "set string failed\n");
309     sz = sizeof buffer;
310     r = MsiFormatRecordA(0, hrec, buffer, &sz);
311     ok( r == ERROR_SUCCESS, "format failed\n");
312     ok( sz == 31, "size wrong %i\n",sz);
313     ok( 0 == strcmp(buffer,"1: 123 2: 4567 3:  4:  5:  6:  "),
314                     "wrong output(%s)\n",buffer);
315 
316     /* play games with recursive lookups */
317     r = MsiRecordSetStringA(hrec, 0, "[[1]] [2]");
318     ok( r == ERROR_SUCCESS, "set string failed\n");
319     r = MsiRecordSetStringA(hrec, 1, "2");
320     ok( r == ERROR_SUCCESS, "set string failed\n");
321     r = MsiRecordSetStringA(hrec, 2, "hey");
322     ok( r == ERROR_SUCCESS, "set string failed\n");
323     sz = sizeof buffer;
324     r = MsiFormatRecordA(0, hrec, buffer, &sz);
325     ok( r == ERROR_SUCCESS, "format failed\n");
326     ok( sz == 7, "size wrong,(%i)\n",sz);
327     ok( 0 == strcmp(buffer,"hey hey"), "wrong output (%s)\n",buffer);
328 
329     r = MsiRecordSetStringA(hrec, 0, "[[1]] [2]");
330     ok( r == ERROR_SUCCESS, "set string failed\n");
331     r = MsiRecordSetStringA(hrec, 1, "[2]");
332     ok( r == ERROR_SUCCESS, "set string failed\n");
333     r = MsiRecordSetStringA(hrec, 2, "hey");
334     ok( r == ERROR_SUCCESS, "set string failed\n");
335     sz = sizeof buffer;
336     r = MsiFormatRecordA(0, hrec, buffer, &sz);
337     ok( r == ERROR_SUCCESS, "format failed\n");
338     ok( sz == 9, "size wrong,(%i)\n",sz);
339     ok( 0 == strcmp(buffer,"[[2]] hey"), "wrong output (%s)\n",buffer);
340 
341     r = MsiRecordSetStringA(hrec, 0, "[[[3]]] [2]");
342     ok( r == ERROR_SUCCESS, "set string failed\n");
343     r = MsiRecordSetStringA(hrec, 1, "2");
344     ok( r == ERROR_SUCCESS, "set string failed\n");
345     r = MsiRecordSetStringA(hrec, 2, "hey");
346     ok( r == ERROR_SUCCESS, "set string failed\n");
347     r = MsiRecordSetStringA(hrec, 3, "1");
348     ok( r == ERROR_SUCCESS, "set string failed\n");
349     sz = sizeof buffer;
350     r = MsiFormatRecordA(0, hrec, buffer, &sz);
351     ok( r == ERROR_SUCCESS, "format failed\n");
352     ok( sz == 7, "size wrong,(%i)\n",sz);
353     ok( 0 == strcmp(buffer,"hey hey"), "wrong output (%s)\n",buffer);
354 
355     r = MsiCloseHandle(hrec);
356     ok(r==ERROR_SUCCESS, "Unable to close record\n");
357     hrec = MsiCreateRecord(12);
358     ok( hrec, "failed to create record\n");
359 
360     r = MsiRecordSetStringA(hrec, 0, "[[3][1]] [2]");
361     ok( r == ERROR_SUCCESS, "set string failed\n");
362     r = MsiRecordSetStringA(hrec, 1, "2");
363     ok( r == ERROR_SUCCESS, "set string failed\n");
364     r = MsiRecordSetStringA(hrec, 2, "hey");
365     ok( r == ERROR_SUCCESS, "set string failed\n");
366     r = MsiRecordSetStringA(hrec, 3, "1");
367     ok( r == ERROR_SUCCESS, "set string failed\n");
368     r = MsiRecordSetStringA(hrec, 12, "big");
369     ok( r == ERROR_SUCCESS, "set string failed\n");
370     sz = sizeof buffer;
371     r = MsiFormatRecordA(0, hrec, buffer, &sz);
372     ok( r == ERROR_SUCCESS, "format failed\n");
373     ok( sz == 7, "size wrong,(%i)\n",sz);
374     ok( 0 == strcmp(buffer,"big hey"), "wrong output (%s)\n",buffer);
375 
376     r = MsiRecordSetStringA(hrec, 0, "[[3][4][1]] [2]");
377     ok( r == ERROR_SUCCESS, "set string failed\n");
378     r = MsiRecordSetStringA(hrec, 1, "2");
379     ok( r == ERROR_SUCCESS, "set string failed\n");
380     r = MsiRecordSetStringA(hrec, 2, "hey");
381     ok( r == ERROR_SUCCESS, "set string failed\n");
382     r = MsiRecordSetStringA(hrec, 3, "1");
383     ok( r == ERROR_SUCCESS, "set string failed\n");
384     r = MsiRecordSetStringA(hrec, 4, NULL);
385     ok( r == ERROR_SUCCESS, "set string failed\n");
386     r = MsiRecordSetStringA(hrec, 12, "big");
387     ok( r == ERROR_SUCCESS, "set string failed\n");
388     sz = sizeof buffer;
389     r = MsiFormatRecordA(0, hrec, buffer, &sz);
390     ok( r == ERROR_SUCCESS, "format failed\n");
391     ok( sz == 7, "size wrong,(%i)\n",sz);
392     ok( 0 == strcmp(buffer,"big hey"), "wrong output (%s)\n",buffer);
393 
394     r = MsiRecordSetStringA(hrec, 0, "[[3][[4]][1]] [2]");
395     ok( r == ERROR_SUCCESS, "set string failed\n");
396     r = MsiRecordSetStringA(hrec, 1, "2");
397     ok( r == ERROR_SUCCESS, "set string failed\n");
398     r = MsiRecordSetStringA(hrec, 2, "hey");
399     ok( r == ERROR_SUCCESS, "set string failed\n");
400     r = MsiRecordSetStringA(hrec, 3, "1");
401     ok( r == ERROR_SUCCESS, "set string failed\n");
402     r = MsiRecordSetStringA(hrec, 4, NULL);
403     ok( r == ERROR_SUCCESS, "set string failed\n");
404     r = MsiRecordSetStringA(hrec, 12, "big");
405     ok( r == ERROR_SUCCESS, "set string failed\n");
406     sz = sizeof buffer;
407     r = MsiFormatRecordA(0, hrec, buffer, &sz);
408     ok( r == ERROR_SUCCESS, "format failed\n");
409     ok( sz == 10, "size wrong,(%i)\n",sz);
410     ok( 0 == strcmp(buffer,"[1[]2] hey"), "wrong output (%s)\n",buffer);
411 
412     /* incorrect  formats */
413     r = MsiRecordSetStringA(hrec, 0, "[[[3][[4]][1]] [2]");
414     ok( r == ERROR_SUCCESS, "set string failed\n");
415     r = MsiRecordSetStringA(hrec, 1, "2");
416     ok( r == ERROR_SUCCESS, "set string failed\n");
417     r = MsiRecordSetStringA(hrec, 2, "hey");
418     ok( r == ERROR_SUCCESS, "set string failed\n");
419     r = MsiRecordSetStringA(hrec, 3, "1");
420     ok( r == ERROR_SUCCESS, "set string failed\n");
421     r = MsiRecordSetStringA(hrec, 4, NULL);
422     ok( r == ERROR_SUCCESS, "set string failed\n");
423     r = MsiRecordSetStringA(hrec, 12, "big");
424     ok( r == ERROR_SUCCESS, "set string failed\n");
425     sz = sizeof buffer;
426     r = MsiFormatRecordA(0, hrec, buffer, &sz);
427     ok( r == ERROR_SUCCESS, "format failed\n");
428     ok( sz == 18, "size wrong,(%i)\n",sz);
429     ok( 0 == strcmp(buffer,"[[[3][[4]][1]] [2]"), "wrong output (%s)\n",buffer);
430 
431     r = MsiRecordSetStringA(hrec, 0, "[[3][[4]][1]] [2]]");
432     ok( r == ERROR_SUCCESS, "set string failed\n");
433     r = MsiRecordSetStringA(hrec, 1, "2");
434     ok( r == ERROR_SUCCESS, "set string failed\n");
435     r = MsiRecordSetStringA(hrec, 2, "hey");
436     ok( r == ERROR_SUCCESS, "set string failed\n");
437     r = MsiRecordSetStringA(hrec, 3, "1");
438     ok( r == ERROR_SUCCESS, "set string failed\n");
439     r = MsiRecordSetStringA(hrec, 4, NULL);
440     ok( r == ERROR_SUCCESS, "set string failed\n");
441     r = MsiRecordSetStringA(hrec, 12, "big");
442     ok( r == ERROR_SUCCESS, "set string failed\n");
443     sz = sizeof buffer;
444     r = MsiFormatRecordA(0, hrec, buffer, &sz);
445     ok( r == ERROR_SUCCESS, "format failed\n");
446     ok( sz == 11, "size wrong,(%i)\n",sz);
447     ok( 0 == strcmp(buffer,"[1[]2] hey]"), "wrong output (%s)\n",buffer);
448 
449 
450     /* play games with {} */
451 
452     r = MsiRecordSetStringA(hrec, 0, "{[3][1]} [2]");
453     ok( r == ERROR_SUCCESS, "set string failed\n");
454     r = MsiRecordSetStringA(hrec, 1, "2");
455     ok( r == ERROR_SUCCESS, "set string failed\n");
456     r = MsiRecordSetStringA(hrec, 2, "hey");
457     ok( r == ERROR_SUCCESS, "set string failed\n");
458     r = MsiRecordSetStringA(hrec, 3, "1");
459     ok( r == ERROR_SUCCESS, "set string failed\n");
460     r = MsiRecordSetStringA(hrec, 4, NULL);
461     ok( r == ERROR_SUCCESS, "set string failed\n");
462     r = MsiRecordSetStringA(hrec, 12, "big");
463     ok( r == ERROR_SUCCESS, "set string failed\n");
464     sz = sizeof buffer;
465     r = MsiFormatRecordA(0, hrec, buffer, &sz);
466     ok( r == ERROR_SUCCESS, "format failed\n");
467     ok( sz == 6, "size wrong,(%i)\n",sz);
468     ok( 0 == strcmp(buffer,"12 hey"), "wrong output (%s)\n",buffer);
469 
470     r = MsiRecordSetStringA(hrec, 0, "[{[3][1]}] [2]");
471     ok( r == ERROR_SUCCESS, "set string failed\n");
472     r = MsiRecordSetStringA(hrec, 1, "2");
473     ok( r == ERROR_SUCCESS, "set string failed\n");
474     r = MsiRecordSetStringA(hrec, 2, "hey");
475     ok( r == ERROR_SUCCESS, "set string failed\n");
476     r = MsiRecordSetStringA(hrec, 3, "1");
477     ok( r == ERROR_SUCCESS, "set string failed\n");
478     r = MsiRecordSetStringA(hrec, 4, NULL);
479     ok( r == ERROR_SUCCESS, "set string failed\n");
480     r = MsiRecordSetStringA(hrec, 12, "big");
481     ok( r == ERROR_SUCCESS, "set string failed\n");
482     sz = sizeof buffer;
483     r = MsiFormatRecordA(0, hrec, buffer, &sz);
484     ok( r == ERROR_SUCCESS, "format failed\n");
485     ok( sz == 8, "size wrong,(%i)\n",sz);
486     ok( 0 == strcmp(buffer,"[12] hey"), "wrong output (%s)\n",buffer);
487 
488 
489     r = MsiRecordSetStringA(hrec, 0, "{test} [2]");
490     ok( r == ERROR_SUCCESS, "set string failed\n");
491     r = MsiRecordSetStringA(hrec, 1, "2");
492     ok( r == ERROR_SUCCESS, "set string failed\n");
493     r = MsiRecordSetStringA(hrec, 2, "hey");
494     ok( r == ERROR_SUCCESS, "set string failed\n");
495     r = MsiRecordSetStringA(hrec, 3, "1");
496     ok( r == ERROR_SUCCESS, "set string failed\n");
497     r = MsiRecordSetStringA(hrec, 4, NULL);
498     ok( r == ERROR_SUCCESS, "set string failed\n");
499     r = MsiRecordSetStringA(hrec, 12, "big");
500     ok( r == ERROR_SUCCESS, "set string failed\n");
501     sz = sizeof buffer;
502     r = MsiFormatRecordA(0, hrec, buffer, &sz);
503     ok( r == ERROR_SUCCESS, "format failed\n");
504     ok( sz == 10, "size wrong,(%i)\n",sz);
505     ok( 0 == strcmp(buffer,"{test} hey"), "wrong output (%s)\n",buffer);
506 
507     r = MsiRecordSetStringA(hrec, 0, "{[test]} [2]");
508     ok( r == ERROR_SUCCESS, "set string failed\n");
509     r = MsiRecordSetStringA(hrec, 1, "2");
510     ok( r == ERROR_SUCCESS, "set string failed\n");
511     r = MsiRecordSetStringA(hrec, 2, "hey");
512     ok( r == ERROR_SUCCESS, "set string failed\n");
513     r = MsiRecordSetStringA(hrec, 3, "1");
514     ok( r == ERROR_SUCCESS, "set string failed\n");
515     r = MsiRecordSetStringA(hrec, 4, NULL);
516     ok( r == ERROR_SUCCESS, "set string failed\n");
517     r = MsiRecordSetStringA(hrec, 12, "big");
518     ok( r == ERROR_SUCCESS, "set string failed\n");
519     sz = sizeof buffer;
520     r = MsiFormatRecordA(0, hrec, buffer, &sz);
521     ok( r == ERROR_SUCCESS, "format failed\n");
522     ok( sz == 12, "size wrong,(%i)\n",sz);
523     ok( 0 == strcmp(buffer,"{[test]} hey"), "wrong output (%s)\n",buffer);
524 
525     r = MsiRecordSetStringA(hrec, 0, "{[1][2][3][4]} [2]");
526     ok( r == ERROR_SUCCESS, "set string failed\n");
527     r = MsiRecordSetStringA(hrec, 1, "2");
528     ok( r == ERROR_SUCCESS, "set string failed\n");
529     r = MsiRecordSetStringA(hrec, 2, "hey");
530     ok( r == ERROR_SUCCESS, "set string failed\n");
531     r = MsiRecordSetStringA(hrec, 3, "1");
532     ok( r == ERROR_SUCCESS, "set string failed\n");
533     r = MsiRecordSetStringA(hrec, 4, NULL);
534     ok( r == ERROR_SUCCESS, "set string failed\n");
535     r = MsiRecordSetStringA(hrec, 12, "big");
536     ok( r == ERROR_SUCCESS, "set string failed\n");
537     sz = sizeof buffer;
538     r = MsiFormatRecordA(0, hrec, buffer, &sz);
539     ok( r == ERROR_SUCCESS, "format failed\n");
540     ok( sz == 4, "size wrong,(%i)\n",sz);
541     ok( 0 == strcmp(buffer," hey"), "wrong output (%s)\n",buffer);
542 
543     r = MsiRecordSetStringA(hrec, 0, "{[1][2][3][dummy]} [2]");
544     ok( r == ERROR_SUCCESS, "set string failed\n");
545     r = MsiRecordSetStringA(hrec, 1, "2");
546     ok( r == ERROR_SUCCESS, "set string failed\n");
547     r = MsiRecordSetStringA(hrec, 2, "hey");
548     ok( r == ERROR_SUCCESS, "set string failed\n");
549     r = MsiRecordSetStringA(hrec, 3, "1");
550     ok( r == ERROR_SUCCESS, "set string failed\n");
551     r = MsiRecordSetStringA(hrec, 4, NULL);
552     ok( r == ERROR_SUCCESS, "set string failed\n");
553     r = MsiRecordSetStringA(hrec, 12, "big");
554     ok( r == ERROR_SUCCESS, "set string failed\n");
555     sz = sizeof buffer;
556     r = MsiFormatRecordA(0, hrec, buffer, &sz);
557     ok( r == ERROR_SUCCESS, "format failed\n");
558     ok( sz == 18, "size wrong,(%i)\n",sz);
559     ok( 0 == strcmp(buffer,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer);
560 
561     r = MsiRecordSetStringA(hrec, 0, "{[1][2][3][4][dummy]} [2]");
562     ok( r == ERROR_SUCCESS, "set string failed\n");
563     r = MsiRecordSetStringA(hrec, 1, "2");
564     ok( r == ERROR_SUCCESS, "set string failed\n");
565     r = MsiRecordSetStringA(hrec, 2, "hey");
566     ok( r == ERROR_SUCCESS, "set string failed\n");
567     r = MsiRecordSetStringA(hrec, 3, "1");
568     ok( r == ERROR_SUCCESS, "set string failed\n");
569     r = MsiRecordSetStringA(hrec, 4, NULL);
570     ok( r == ERROR_SUCCESS, "set string failed\n");
571     r = MsiRecordSetStringA(hrec, 12, "big");
572     ok( r == ERROR_SUCCESS, "set string failed\n");
573     sz = sizeof buffer;
574     r = MsiFormatRecordA(0, hrec, buffer, &sz);
575     ok( r == ERROR_SUCCESS, "format failed\n");
576     ok( sz == 18, "size wrong,(%i)\n",sz);
577     ok( 0 == strcmp(buffer,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer);
578 
579     r = MsiRecordSetStringA(hrec, 0, "{{[1][2]}[3][4][dummy]}");
580     ok( r == ERROR_SUCCESS, "set string failed\n");
581     r = MsiRecordSetStringA(hrec, 1, "2");
582     ok( r == ERROR_SUCCESS, "set string failed\n");
583     r = MsiRecordSetStringA(hrec, 2, "hey");
584     ok( r == ERROR_SUCCESS, "set string failed\n");
585     r = MsiRecordSetStringA(hrec, 3, "1");
586     ok( r == ERROR_SUCCESS, "set string failed\n");
587     r = MsiRecordSetStringA(hrec, 4, NULL);
588     ok( r == ERROR_SUCCESS, "set string failed\n");
589     r = MsiRecordSetStringA(hrec, 12, "big");
590     ok( r == ERROR_SUCCESS, "set string failed\n");
591     sz = sizeof buffer;
592     r = MsiFormatRecordA(0, hrec, buffer, &sz);
593     ok( r == ERROR_SUCCESS, "format failed\n");
594     ok( sz == 16, "size wrong,(%i)\n",sz);
595     ok( 0 == strcmp(buffer,"{{2hey}1[dummy]}"), "wrong output (%s)\n",buffer);
596 
597     r = MsiRecordSetStringA(hrec, 0, "{{[1][2]}[3]{[4][dummy]}}");
598     ok( r == ERROR_SUCCESS, "set string failed\n");
599     r = MsiRecordSetStringA(hrec, 1, "2");
600     ok( r == ERROR_SUCCESS, "set string failed\n");
601     r = MsiRecordSetStringA(hrec, 2, "hey");
602     ok( r == ERROR_SUCCESS, "set string failed\n");
603     r = MsiRecordSetStringA(hrec, 3, "1");
604     ok( r == ERROR_SUCCESS, "set string failed\n");
605     r = MsiRecordSetStringA(hrec, 4, NULL);
606     ok( r == ERROR_SUCCESS, "set string failed\n");
607     r = MsiRecordSetStringA(hrec, 12, "big");
608     ok( r == ERROR_SUCCESS, "set string failed\n");
609     sz = sizeof buffer;
610     r = MsiFormatRecordA(0, hrec, buffer, &sz);
611     ok( r == ERROR_SUCCESS, "format failed\n");
612     ok( sz == 0, "size wrong,(%i)\n",sz);
613     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
614 
615     r = MsiRecordSetStringA(hrec, 0, "{{[1][2]}[3]} {[1][2]}");
616     ok( r == ERROR_SUCCESS, "set string failed\n");
617     r = MsiRecordSetStringA(hrec, 1, "1");
618     ok( r == ERROR_SUCCESS, "set string failed\n");
619     r = MsiRecordSetStringA(hrec, 2, "2");
620     ok( r == ERROR_SUCCESS, "set string failed\n");
621     r = MsiRecordSetStringA(hrec, 3, "3");
622     ok( r == ERROR_SUCCESS, "set string failed\n");
623     r = MsiRecordSetStringA(hrec, 4, NULL);
624     ok( r == ERROR_SUCCESS, "set string failed\n");
625     r = MsiRecordSetStringA(hrec, 12, "big");
626     ok( r == ERROR_SUCCESS, "set string failed\n");
627     sz = sizeof buffer;
628     r = MsiFormatRecordA(0, hrec, buffer, &sz);
629     ok( r == ERROR_SUCCESS, "format failed\n");
630     ok( sz == 12, "size wrong,(%i)\n",sz);
631     ok( 0 == strcmp(buffer,"{{12}3} {12}"), "wrong output (%s)\n",buffer);
632 
633     r = MsiRecordSetStringA(hrec, 0, "{[1][2]} {{[1][2]}[3]} {[1][2]}");
634     ok( r == ERROR_SUCCESS, "set string failed\n");
635     r = MsiRecordSetStringA(hrec, 1, "1");
636     ok( r == ERROR_SUCCESS, "set string failed\n");
637     r = MsiRecordSetStringA(hrec, 2, "2");
638     ok( r == ERROR_SUCCESS, "set string failed\n");
639     r = MsiRecordSetStringA(hrec, 3, "3");
640     ok( r == ERROR_SUCCESS, "set string failed\n");
641     r = MsiRecordSetStringA(hrec, 4, NULL);
642     ok( r == ERROR_SUCCESS, "set string failed\n");
643     r = MsiRecordSetStringA(hrec, 12, "big");
644     ok( r == ERROR_SUCCESS, "set string failed\n");
645     sz = sizeof buffer;
646     r = MsiFormatRecordA(0, hrec, buffer, &sz);
647     ok( r == ERROR_SUCCESS, "format failed\n");
648     ok( sz == 15, "size wrong,(%i)\n",sz);
649     ok( 0 == strcmp(buffer,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer);
650 
651     r = MsiRecordSetStringA(hrec, 0, "{[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
652     ok( r == ERROR_SUCCESS, "set string failed\n");
653     r = MsiRecordSetStringA(hrec, 1, "1");
654     ok( r == ERROR_SUCCESS, "set string failed\n");
655     r = MsiRecordSetStringA(hrec, 2, "2");
656     ok( r == ERROR_SUCCESS, "set string failed\n");
657     r = MsiRecordSetStringA(hrec, 3, "3");
658     ok( r == ERROR_SUCCESS, "set string failed\n");
659     r = MsiRecordSetStringA(hrec, 4, NULL);
660     ok( r == ERROR_SUCCESS, "set string failed\n");
661     r = MsiRecordSetStringA(hrec, 12, "big");
662     ok( r == ERROR_SUCCESS, "set string failed\n");
663     sz = sizeof buffer;
664     r = MsiFormatRecordA(0, hrec, buffer, &sz);
665     ok( r == ERROR_SUCCESS, "format failed\n");
666     ok( sz == 15, "size wrong,(%i)\n",sz);
667     ok( 0 == strcmp(buffer,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer);
668 
669     r = MsiRecordSetStringA(hrec, 0, "{blah} {[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
670     ok( r == ERROR_SUCCESS, "set string failed\n");
671     r = MsiRecordSetStringA(hrec, 1, "1");
672     ok( r == ERROR_SUCCESS, "set string failed\n");
673     r = MsiRecordSetStringA(hrec, 2, "2");
674     ok( r == ERROR_SUCCESS, "set string failed\n");
675     r = MsiRecordSetStringA(hrec, 3, "3");
676     ok( r == ERROR_SUCCESS, "set string failed\n");
677     r = MsiRecordSetStringA(hrec, 4, NULL);
678     ok( r == ERROR_SUCCESS, "set string failed\n");
679     r = MsiRecordSetStringA(hrec, 12, "big");
680     ok( r == ERROR_SUCCESS, "set string failed\n");
681     sz = sizeof buffer;
682     r = MsiFormatRecordA(0, hrec, buffer, &sz);
683     ok( r == ERROR_SUCCESS, "format failed\n");
684     ok( sz == 22, "size wrong,(%i)\n",sz);
685     ok( 0 == strcmp(buffer,"{blah} 12 {{12}3} {12}"), "wrong output (%s)\n",buffer);
686 
687     r = MsiRecordSetStringA(hrec, 0, "{{[1]}[2]} {[4]}{[1][2]}");
688     ok( r == ERROR_SUCCESS, "set string failed\n");
689     r = MsiRecordSetStringA(hrec, 1, "1");
690     ok( r == ERROR_SUCCESS, "set string failed\n");
691     r = MsiRecordSetStringA(hrec, 2, "2");
692     ok( r == ERROR_SUCCESS, "set string failed\n");
693     r = MsiRecordSetStringA(hrec, 3, "3");
694     ok( r == ERROR_SUCCESS, "set string failed\n");
695     r = MsiRecordSetStringA(hrec, 4, NULL);
696     ok( r == ERROR_SUCCESS, "set string failed\n");
697     r = MsiRecordSetStringA(hrec, 12, "big");
698     ok( r == ERROR_SUCCESS, "set string failed\n");
699     sz = sizeof buffer;
700     r = MsiFormatRecordA(0, hrec, buffer, &sz);
701     ok( r == ERROR_SUCCESS, "format failed\n");
702     ok( sz == 13, "size wrong,(%i)\n",sz);
703     ok( 0 == strcmp(buffer,"{{1}2} {}{12}"), "wrong output (%s)\n",buffer);
704 
705     r = MsiRecordSetStringA(hrec, 0, "{{[1]}} {[4]}{[1][2]}");
706     ok( r == ERROR_SUCCESS, "set string failed\n");
707     r = MsiRecordSetStringA(hrec, 1, "1");
708     ok( r == ERROR_SUCCESS, "set string failed\n");
709     r = MsiRecordSetStringA(hrec, 2, "2");
710     ok( r == ERROR_SUCCESS, "set string failed\n");
711     r = MsiRecordSetStringA(hrec, 3, "3");
712     ok( r == ERROR_SUCCESS, "set string failed\n");
713     r = MsiRecordSetStringA(hrec, 4, NULL);
714     ok( r == ERROR_SUCCESS, "set string failed\n");
715     r = MsiRecordSetStringA(hrec, 12, "big");
716     ok( r == ERROR_SUCCESS, "set string failed\n");
717     sz = sizeof buffer;
718     r = MsiFormatRecordA(0, hrec, buffer, &sz);
719     ok( r == ERROR_SUCCESS, "format failed\n");
720     ok( sz == 3, "size wrong,(%i)\n",sz);
721     ok( 0 == strcmp(buffer," 12"), "wrong output (%s)\n",buffer);
722 
723     r = MsiRecordSetStringA(hrec, 0, "{{{[1]}} {[4]}{[1][2]}");
724     ok( r == ERROR_SUCCESS, "set string failed\n");
725     r = MsiRecordSetStringA(hrec, 1, "1");
726     ok( r == ERROR_SUCCESS, "set string failed\n");
727     r = MsiRecordSetStringA(hrec, 2, "2");
728     ok( r == ERROR_SUCCESS, "set string failed\n");
729     r = MsiRecordSetStringA(hrec, 3, "3");
730     ok( r == ERROR_SUCCESS, "set string failed\n");
731     r = MsiRecordSetStringA(hrec, 4, NULL);
732     ok( r == ERROR_SUCCESS, "set string failed\n");
733     r = MsiRecordSetStringA(hrec, 12, "big");
734     ok( r == ERROR_SUCCESS, "set string failed\n");
735     sz = sizeof buffer;
736     r = MsiFormatRecordA(0, hrec, buffer, &sz);
737     ok( r == ERROR_SUCCESS, "format failed\n");
738     todo_wine{
739     ok( sz == 3, "size wrong,(%i)\n",sz);
740     ok( 0 == strcmp(buffer," 12"), "wrong output (%s)\n",buffer);
741     }
742 
743     /* now put play games with escaping */
744     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [\\3asdf]");
745     ok( r == ERROR_SUCCESS, "set string failed\n");
746     r = MsiRecordSetStringA(hrec, 1, "boo");
747     ok( r == ERROR_SUCCESS, "set string failed\n");
748     r = MsiRecordSetStringA(hrec, 2, "hoo");
749     ok( r == ERROR_SUCCESS, "set string failed\n");
750     sz = sizeof buffer;
751     r = MsiFormatRecordA(0, hrec, buffer, &sz);
752     ok( r == ERROR_SUCCESS, "format failed\n");
753     ok( sz == 16, "size wrong\n");
754     ok( 0 == strcmp(buffer,"boo hoo [\\3asdf]"), "wrong output\n");
755 
756     /* now put play games with escaping */
757     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [\\x]");
758     ok( r == ERROR_SUCCESS, "set string failed\n");
759     r = MsiRecordSetStringA(hrec, 1, "boo");
760     ok( r == ERROR_SUCCESS, "set string failed\n");
761     r = MsiRecordSetStringA(hrec, 2, "hoo");
762     ok( r == ERROR_SUCCESS, "set string failed\n");
763     sz = sizeof buffer;
764     r = MsiFormatRecordA(0, hrec, buffer, &sz);
765     ok( r == ERROR_SUCCESS, "format failed\n");
766     ok( sz == 12, "size wrong\n");
767     ok( 0 == strcmp(buffer,"boo hoo [\\x]"), "wrong output\n");
768 
769     r = MsiRecordSetStringA(hrec, 0, "[\\x]");
770     ok( r == ERROR_SUCCESS, "set string failed\n");
771     sz = sizeof buffer;
772     r = MsiFormatRecordA(0, hrec, buffer, &sz);
773     ok( r == ERROR_SUCCESS, "format failed\n");
774     ok( sz == 4, "size wrong: %d\n", sz);
775     ok( 0 == strcmp(buffer,"[\\x]"), "wrong output: %s\n", buffer);
776 
777     r = MsiRecordSetStringA(hrec, 0, "{\\x}");
778     ok( r == ERROR_SUCCESS, "set string failed\n");
779     sz = sizeof buffer;
780     r = MsiFormatRecordA(0, hrec, buffer, &sz);
781     ok( r == ERROR_SUCCESS, "format failed\n");
782     ok( sz == 4, "size wrong: %d\n", sz);
783     ok( 0 == strcmp(buffer,"{\\x}"), "wrong output: %s\n", buffer);
784 
785     r = MsiRecordSetStringA(hrec, 0, "[abc\\x]");
786     ok( r == ERROR_SUCCESS, "set string failed\n");
787     sz = sizeof buffer;
788     r = MsiFormatRecordA(0, hrec, buffer, &sz);
789     ok( r == ERROR_SUCCESS, "format failed\n");
790     ok( sz == 7, "size wrong: %d\n", sz);
791     ok( 0 == strcmp(buffer,"[abc\\x]"), "wrong output: %s\n", buffer);
792 
793     r = MsiRecordSetStringA(hrec, 0, "[\\[]Bracket Text[\\]]");
794     ok( r == ERROR_SUCCESS, "set string failed\n");
795     sz = sizeof buffer;
796     r = MsiFormatRecordA(0, hrec, buffer, &sz);
797     ok( r == ERROR_SUCCESS, "format failed\n");
798     ok( sz == 20, "size wrong: %d\n", sz);
799     ok( 0 == strcmp(buffer,"[\\[]Bracket Text[\\]]"), "wrong output: %s\n", buffer);
800 
801     /* now try other formats without a package */
802     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [property]");
803     ok( r == ERROR_SUCCESS, "set string failed\n");
804     r = MsiRecordSetStringA(hrec, 1, "boo");
805     ok( r == ERROR_SUCCESS, "set string failed\n");
806     r = MsiRecordSetStringA(hrec, 2, "hoo");
807     ok( r == ERROR_SUCCESS, "set string failed\n");
808     sz = sizeof buffer;
809     r = MsiFormatRecordA(0, hrec, buffer, &sz);
810     ok( r == ERROR_SUCCESS, "format failed\n");
811     ok( sz == 18, "size wrong\n");
812     ok( 0 == strcmp(buffer,"boo hoo [property]"), "wrong output\n");
813 
814     r = MsiRecordSetStringA(hrec, 0, "[1] [~] [2]");
815     ok( r == ERROR_SUCCESS, "set string failed\n");
816     r = MsiRecordSetStringA(hrec, 1, "boo");
817     ok( r == ERROR_SUCCESS, "set string failed\n");
818     r = MsiRecordSetStringA(hrec, 2, "hoo");
819     ok( r == ERROR_SUCCESS, "set string failed\n");
820     sz = sizeof buffer;
821     r = MsiFormatRecordA(0, hrec, buffer, &sz);
822     ok( r == ERROR_SUCCESS, "format failed\n");
823     ok( sz == 11, "size wrong\n");
824     ok( 0 == strcmp(buffer,"boo [~] hoo"), "wrong output (%s)\n",buffer);
825 
826     r = MsiRecordSetStringA(hrec, 0, "[1]");
827     ok( r == ERROR_SUCCESS, "set string failed\n");
828     r = MsiRecordSetInteger(hrec, 1, 123456);
829     ok( r == ERROR_SUCCESS, "set integer failed\n");
830     sz = sizeof buffer;
831     r = MsiFormatRecordA(0, hrec, buffer, &sz);
832     ok( r == ERROR_SUCCESS, "format failed\n");
833     ok( sz == 6, "size wrong\n");
834     ok( 0 == strcmp(buffer,"123456"), "wrong output (%s)\n",buffer);
835 
836     r = MsiRecordSetStringA(hrec, 0, "[~]");
837     ok( r == ERROR_SUCCESS, "set string failed\n");
838     sz = sizeof buffer;
839     r = MsiFormatRecordA(0, hrec, buffer, &sz);
840     ok( sz == 3, "size wrong\n");
841     ok( 0 == strcmp(buffer,"[~]"), "wrong output\n");
842     ok( r == ERROR_SUCCESS, "format failed\n");
843 
844     r = MsiRecordSetStringA(hrec, 0, "[]");
845     ok( r == ERROR_SUCCESS, "set string failed\n");
846     sz = sizeof buffer;
847     r = MsiFormatRecordA(0, hrec, buffer, &sz);
848     ok( sz == 2, "size wrong\n");
849     ok( 0 == strcmp(buffer,"[]"), "wrong output\n");
850     ok( r == ERROR_SUCCESS, "format failed\n");
851 
852     /* MsiFormatRecordA doesn't seem to handle a negative too well */
853     r = MsiRecordSetStringA(hrec, 0, "[-1]");
854     ok( r == ERROR_SUCCESS, "set string failed\n");
855     sz = sizeof buffer;
856     r = MsiFormatRecordA(0, hrec, buffer, &sz);
857     ok( sz == 4, "size wrong\n");
858     ok( 0 == strcmp(buffer,"[-1]"), "wrong output\n");
859     ok( r == ERROR_SUCCESS, "format failed\n");
860 
861     r = MsiRecordSetStringA(hrec, 0, "{[]}");
862     ok( r == ERROR_SUCCESS, "set string failed\n");
863     sz = sizeof buffer;
864     r = MsiFormatRecordA(0, hrec, buffer, &sz);
865     ok( sz == 4, "size wrong\n");
866     ok( 0 == strcmp(buffer,"{[]}"), "wrong output\n");
867     ok( r == ERROR_SUCCESS, "format failed\n");
868 
869     r = MsiRecordSetStringA(hrec, 0, "[0]");
870     ok( r == ERROR_SUCCESS, "set string failed\n");
871     sz = sizeof buffer;
872     r = MsiFormatRecordA(0, hrec, buffer, &sz);
873     ok( sz == 3, "size wrong\n");
874     ok( 0 == strcmp(buffer,"[0]"), "wrong output\n");
875     ok( r == ERROR_SUCCESS, "format failed\n");
876 
877     r = MsiRecordSetStringA(hrec, 0, "[100]");
878     ok( r == ERROR_SUCCESS, "set string failed\n");
879     sz = sizeof buffer;
880     r = MsiFormatRecordA(0, hrec, buffer, &sz);
881     ok( sz == 0, "size wrong\n");
882     ok( 0 == strcmp(buffer,""), "wrong output\n");
883     ok( r == ERROR_SUCCESS, "format failed\n");
884 
885     r = MsiRecordSetStringA(hrec, 0, "{[1] [2]}");
886     ok( r == ERROR_SUCCESS, "set string failed\n");
887     r = MsiRecordSetStringA(hrec, 1, "boo");
888     ok( r == ERROR_SUCCESS, "set string failed\n");
889     r = MsiRecordSetStringA(hrec, 2, "hoo");
890     ok( r == ERROR_SUCCESS, "set string failed\n");
891     sz = sizeof buffer;
892     r = MsiFormatRecordA(0, hrec, buffer, &sz);
893     ok( sz == 7, "size wrong\n");
894     ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
895     ok( r == ERROR_SUCCESS, "format failed\n");
896 
897     r = MsiRecordSetStringA(hrec, 0, "{}");
898     ok( r == ERROR_SUCCESS, "set string failed\n");
899     sz = sizeof buffer;
900     r = MsiFormatRecordA(0, hrec, buffer, &sz);
901     ok( sz == 0, "size wrong\n");
902     ok( 0 == strcmp(buffer,""), "wrong output\n");
903     ok( r == ERROR_SUCCESS, "format failed\n");
904 
905     r = MsiRecordSetStringA(hrec, 0, "{foo}");
906     ok( r == ERROR_SUCCESS, "set string failed\n");
907     sz = sizeof buffer;
908     r = MsiFormatRecordA(0, hrec, buffer, &sz);
909     ok( sz == 5, "size wrong\n");
910     ok( 0 == strcmp(buffer,"{foo}"), "wrong output\n");
911     ok( r == ERROR_SUCCESS, "format failed\n");
912 
913     r = MsiRecordSetStringA(hrec, 0, "{boo [1]}");
914     ok( r == ERROR_SUCCESS, "set string failed\n");
915     r = MsiRecordSetStringA(hrec, 1, "hoo");
916     ok( r == ERROR_SUCCESS, "set string failed\n");
917     sz = sizeof buffer;
918     r = MsiFormatRecordA(0, hrec, buffer, &sz);
919     ok( sz == 7, "size wrong\n");
920     ok( 0 == strcmp(buffer,"boo hoo"), "wrong output\n");
921     ok( r == ERROR_SUCCESS, "format failed\n");
922 
923     r = MsiRecordSetStringA(hrec, 0, "{{[1]}}");
924     ok( r == ERROR_SUCCESS, "set string failed\n");
925     r = MsiRecordSetStringA(hrec, 1, "hoo");
926     ok( r == ERROR_SUCCESS, "set string failed\n");
927     sz = sizeof buffer;
928     r = MsiFormatRecordA(0, hrec, buffer, &sz);
929     ok( sz == 0, "size wrong\n");
930     ok( 0 == strcmp(buffer,""), "wrong output\n");
931     ok( r == ERROR_SUCCESS, "format failed\n");
932 
933     r = MsiRecordSetStringA(hrec, 0, "{ {[1]}}");
934     ok( r == ERROR_SUCCESS, "set string failed\n");
935     r = MsiRecordSetStringA(hrec, 1, "hoo");
936     ok( r == ERROR_SUCCESS, "set string failed\n");
937     sz = sizeof buffer;
938     r = MsiFormatRecordA(0, hrec, buffer, &sz);
939     todo_wine
940     {
941         ok( 0 == strcmp(buffer," {hoo}"), "wrong output\n");
942         ok( sz == 6, "size wrong\n");
943     }
944     ok( r == ERROR_SUCCESS, "format failed\n");
945 
946     r = MsiRecordSetStringA(hrec, 0, "{{[1]} }");
947     ok( r == ERROR_SUCCESS, "set string failed\n");
948     r = MsiRecordSetStringA(hrec, 1, "hoo");
949     ok( r == ERROR_SUCCESS, "set string failed\n");
950     sz = sizeof buffer;
951     r = MsiFormatRecordA(0, hrec, buffer, &sz);
952     ok( sz == 8, "size wrong\n");
953     ok( 0 == strcmp(buffer,"{{hoo} }"), "wrong output\n");
954     ok( r == ERROR_SUCCESS, "format failed\n");
955 
956     r = MsiRecordSetStringA(hrec, 0, "{{ [1]}}");
957     ok( r == ERROR_SUCCESS, "set string failed\n");
958     r = MsiRecordSetStringA(hrec, 1, "hoo");
959     ok( r == ERROR_SUCCESS, "set string failed\n");
960     sz = sizeof buffer;
961     r = MsiFormatRecordA(0, hrec, buffer, &sz);
962     ok( sz == 0, "size wrong\n");
963     ok( 0 == strcmp(buffer,""), "wrong output\n");
964     ok( r == ERROR_SUCCESS, "format failed\n");
965 
966     r = MsiRecordSetStringA(hrec, 0, "{{[1] }}");
967     ok( r == ERROR_SUCCESS, "set string failed\n");
968     r = MsiRecordSetStringA(hrec, 1, "hoo");
969     ok( r == ERROR_SUCCESS, "set string failed\n");
970     sz = sizeof buffer;
971     r = MsiFormatRecordA(0, hrec, buffer, &sz);
972     ok( sz == 0, "size wrong\n");
973     ok( 0 == strcmp(buffer,""), "wrong output\n");
974     ok( r == ERROR_SUCCESS, "format failed\n");
975 
976     r = MsiRecordSetStringA(hrec, 0, "{{a}{b}{c }{ d}{any text}}");
977     ok( r == ERROR_SUCCESS, "set string failed\n");
978     sz = sizeof buffer;
979     r = MsiFormatRecordA(0, hrec, buffer, &sz);
980     ok( sz == 0, "size wrong\n");
981     ok( 0 == strcmp(buffer,""), "wrong output\n");
982     ok( r == ERROR_SUCCESS, "format failed\n");
983 
984     r = MsiRecordSetStringA(hrec, 0, "{{a} }");
985     ok( r == ERROR_SUCCESS, "set string failed\n");
986     sz = sizeof buffer;
987     r = MsiFormatRecordA(0, hrec, buffer, &sz);
988     ok( sz == 6, "size wrong\n");
989     ok( 0 == strcmp(buffer,"{{a} }"), "wrong output\n");
990     ok( r == ERROR_SUCCESS, "format failed\n");
991 
992     r = MsiRecordSetStringA(hrec, 0, "{{a} {b}}");
993     ok( r == ERROR_SUCCESS, "set string failed\n");
994     sz = sizeof buffer;
995     r = MsiFormatRecordA(0, hrec, buffer, &sz);
996     ok( sz == 0, "size wrong\n");
997     ok( 0 == strcmp(buffer,""), "wrong output\n");
998     ok( r == ERROR_SUCCESS, "format failed\n");
999 
1000     r = MsiRecordSetStringA(hrec, 0, "{{a} b}}");
1001     ok( r == ERROR_SUCCESS, "set string failed\n");
1002     sz = sizeof buffer;
1003     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1004     todo_wine ok( sz == 0, "size wrong\n");
1005     todo_wine ok( 0 == strcmp(buffer,""), "wrong output\n");
1006     ok( r == ERROR_SUCCESS, "format failed\n");
1007 
1008     r = MsiRecordSetStringA(hrec, 0, "{{a b}}");
1009     ok( r == ERROR_SUCCESS, "set string failed\n");
1010     sz = sizeof buffer;
1011     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1012     ok( sz == 0, "size wrong\n");
1013     ok( 0 == strcmp(buffer,""), "wrong output\n");
1014     ok( r == ERROR_SUCCESS, "format failed\n");
1015 
1016     r = MsiRecordSetStringA(hrec, 0, "{ }");
1017     ok( r == ERROR_SUCCESS, "set string failed\n");
1018     sz = sizeof buffer;
1019     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1020     ok( sz == 3, "size wrong\n");
1021     ok( 0 == strcmp(buffer,"{ }"), "wrong output\n");
1022     ok( r == ERROR_SUCCESS, "format failed\n");
1023 
1024     r = MsiRecordSetStringA(hrec, 0, " {{a}}}");
1025     ok( r == ERROR_SUCCESS, "set string failed\n");
1026     sz = sizeof buffer;
1027     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1028     ok( sz == 2, "size wrong\n");
1029     ok( 0 == strcmp(buffer," }"), "wrong output\n");
1030     ok( r == ERROR_SUCCESS, "format failed\n");
1031 
1032     r = MsiRecordSetStringA(hrec, 0, "{{ almost {{ any }} text }}");
1033     ok( r == ERROR_SUCCESS, "set string failed\n");
1034     sz = sizeof buffer;
1035     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1036     todo_wine ok( sz == 8, "size wrong\n");
1037     todo_wine ok( 0 == strcmp(buffer," text }}"), "wrong output\n");
1038     ok( r == ERROR_SUCCESS, "format failed\n");
1039 
1040     r = MsiRecordSetStringA(hrec, 0, "{{ } { hidden ][ [ }}");
1041     ok( r == ERROR_SUCCESS, "set string failed\n");
1042     sz = sizeof buffer;
1043     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1044     todo_wine ok( sz == 0, "size wrong\n");
1045     todo_wine ok( 0 == strcmp(buffer,""), "wrong output\n");
1046     ok( r == ERROR_SUCCESS, "format failed\n");
1047 
1048     r = MsiRecordSetStringA(hrec, 0, "[ 1]");
1049     ok( r == ERROR_SUCCESS, "set string failed\n");
1050     r = MsiRecordSetStringA(hrec, 1, "hoo");
1051     ok( r == ERROR_SUCCESS, "set string failed\n");
1052     sz = sizeof buffer;
1053     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1054     ok( sz == 4, "size wrong\n");
1055     ok( 0 == strcmp(buffer,"[ 1]"), "wrong output\n");
1056     ok( r == ERROR_SUCCESS, "format failed\n");
1057 
1058     r = MsiRecordSetStringA(hrec, 0, "[01]");
1059     ok( r == ERROR_SUCCESS, "set string failed\n");
1060     r = MsiRecordSetStringA(hrec, 1, "hoo");
1061     ok( r == ERROR_SUCCESS, "set string failed\n");
1062     sz = sizeof buffer;
1063     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1064     ok( sz == 3, "size wrong\n");
1065     ok( 0 == strcmp(buffer,"hoo"), "wrong output\n");
1066     ok( r == ERROR_SUCCESS, "format failed\n");
1067 
1068     r = MsiRecordSetStringA(hrec, 0, "{{test}} [01");
1069     ok( r == ERROR_SUCCESS, "set string failed\n");
1070     r = MsiRecordSetStringA(hrec, 1, "hoo");
1071     ok( r == ERROR_SUCCESS, "set string failed\n");
1072     sz = sizeof buffer;
1073     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1074     todo_wine ok( sz == 4, "size wrong\n");
1075     todo_wine ok( 0 == strcmp(buffer," [01"), "wrong output\n");
1076     ok( r == ERROR_SUCCESS, "format failed\n");
1077 
1078     r = MsiRecordSetStringA(hrec, 0, "[\\[]");
1079     ok( r == ERROR_SUCCESS, "set string failed\n");
1080     r = MsiRecordSetStringA(hrec, 1, "hoo");
1081     ok( r == ERROR_SUCCESS, "set string failed\n");
1082     sz = sizeof buffer;
1083     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1084     ok( sz == 4, "size wrong\n");
1085     ok( 0 == strcmp(buffer,"[\\[]"), "wrong output\n");
1086     ok( r == ERROR_SUCCESS, "format failed\n");
1087 
1088     r = MsiRecordSetStringA(hrec, 0, "[\\[]");
1089     ok( r == ERROR_SUCCESS, "set string failed\n");
1090     r = MsiRecordSetStringA(hrec, 1, "hoo");
1091     ok( r == ERROR_SUCCESS, "set string failed\n");
1092     sz = sizeof(buffer);
1093     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1094     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1095     ok(sz == 4, "Expected 4, got %d\n", sz);
1096     ok(!lstrcmpA(buffer, "[\\[]"), "Expected \"[\\[]\", got \"%s\"\n", buffer);
1097 
1098     r = MsiRecordSetStringA(hrec, 0, "[foo]");
1099     ok( r == ERROR_SUCCESS, "set string failed\n");
1100     r = MsiRecordSetStringA(hrec, 1, "hoo");
1101     ok( r == ERROR_SUCCESS, "set string failed\n");
1102     sz = sizeof buffer;
1103     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1104     ok( sz == 5, "size wrong\n");
1105     ok( 0 == strcmp(buffer,"[foo]"), "wrong output\n");
1106     ok( r == ERROR_SUCCESS, "format failed\n");
1107 
1108     r = MsiRecordSetStringA(hrec, 0, "[01.]");
1109     ok( r == ERROR_SUCCESS, "set string failed\n");
1110     r = MsiRecordSetStringA(hrec, 1, "hoo");
1111     ok( r == ERROR_SUCCESS, "set string failed\n");
1112     sz = sizeof buffer;
1113     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1114     ok( sz == 5, "size wrong\n");
1115     ok( 0 == strcmp(buffer,"[01.]"), "wrong output\n");
1116     ok( r == ERROR_SUCCESS, "format failed\n");
1117 
1118     SetEnvironmentVariableA("FOO", "BAR");
1119     r = MsiRecordSetStringA(hrec, 0, "[%FOO]");
1120     ok( r == ERROR_SUCCESS, "set string failed\n");
1121     sz = sizeof buffer;
1122     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1123     ok( sz == 6, "size wrong\n");
1124     ok( 0 == strcmp(buffer,"[%FOO]"), "wrong output\n");
1125     ok( r == ERROR_SUCCESS, "format failed\n");
1126 
1127     r = MsiRecordSetStringA(hrec, 0, "{{[1]}");
1128     ok( r == ERROR_SUCCESS, "set string failed\n");
1129     r = MsiRecordSetStringA(hrec, 1, "hoo");
1130     ok( r == ERROR_SUCCESS, "set string failed\n");
1131     sz = sizeof buffer;
1132     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1133     ok( sz == 6, "size wrong\n");
1134     ok( 0 == strcmp(buffer,"{{hoo}"), "wrong output\n");
1135     ok( r == ERROR_SUCCESS, "format failed\n");
1136 
1137     r = MsiRecordSetStringA(hrec, 0, "{{ {[1]}");
1138     ok( r == ERROR_SUCCESS, "set string failed\n");
1139     r = MsiRecordSetStringA(hrec, 1, "hoo");
1140     ok( r == ERROR_SUCCESS, "set string failed\n");
1141     sz = sizeof buffer;
1142     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1143     ok( sz == 8, "size wrong\n");
1144     ok( 0 == strcmp(buffer,"{{ {hoo}"), "wrong output\n");
1145     ok( r == ERROR_SUCCESS, "format failed\n");
1146 
1147     r = MsiRecordSetStringA(hrec, 0, "{{ {[1]}");
1148     ok( r == ERROR_SUCCESS, "set string failed\n");
1149     r = MsiRecordSetStringA(hrec, 1, "hoo");
1150     ok( r == ERROR_SUCCESS, "set string failed\n");
1151     sz = sizeof buffer;
1152     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1153     ok( sz == 8, "size wrong\n");
1154     ok( 0 == strcmp(buffer,"{{ {hoo}"), "wrong output\n");
1155     ok( r == ERROR_SUCCESS, "format failed\n");
1156 
1157     r = MsiRecordSetStringA(hrec, 0, "{{ {{[1]}");
1158     ok( r == ERROR_SUCCESS, "set string failed\n");
1159     r = MsiRecordSetStringA(hrec, 1, "hoo");
1160     ok( r == ERROR_SUCCESS, "set string failed\n");
1161     sz = sizeof buffer;
1162     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1163     ok( sz == 9, "size wrong\n");
1164     ok( 0 == strcmp(buffer,"{{ {{hoo}"), "wrong output\n");
1165     ok( r == ERROR_SUCCESS, "format failed\n");
1166 
1167     r = MsiRecordSetStringA(hrec, 0, "[1]}");
1168     ok( r == ERROR_SUCCESS, "set string failed\n");
1169     r = MsiRecordSetStringA(hrec, 1, "hoo");
1170     ok( r == ERROR_SUCCESS, "set string failed\n");
1171     sz = sizeof buffer;
1172     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1173     ok( sz == 4, "size wrong\n");
1174     ok( 0 == strcmp(buffer,"hoo}"), "wrong output\n");
1175     ok( r == ERROR_SUCCESS, "format failed\n");
1176 
1177     r = MsiRecordSetStringA(hrec, 0, "{{ {{a}");
1178     ok( r == ERROR_SUCCESS, "set string failed\n");
1179     sz = sizeof buffer;
1180     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1181     ok( sz == 7, "size wrong\n");
1182     ok( 0 == strcmp(buffer,"{{ {{a}"), "wrong output\n");
1183     ok( r == ERROR_SUCCESS, "format failed\n");
1184 
1185     r = MsiRecordSetStringA(hrec, 0, "{{ {{a}");
1186     ok( r == ERROR_SUCCESS, "set string failed\n");
1187     sz = sizeof buffer;
1188     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1189     ok( sz == 7, "size wrong\n");
1190     ok( 0 == strcmp(buffer,"{{ {{a}"), "wrong output\n");
1191     ok( r == ERROR_SUCCESS, "format failed\n");
1192 
1193     r = MsiRecordSetStringA(hrec, 0, "0{1{2{3{4[1]5}6}7}8}9");
1194     ok( r == ERROR_SUCCESS, "set string failed\n");
1195     r = MsiRecordSetStringA(hrec, 1, "hoo");
1196     ok( r == ERROR_SUCCESS, "set string failed\n");
1197     sz = sizeof buffer;
1198     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1199     todo_wine
1200     {
1201         ok( sz == 19, "size wrong\n");
1202         ok( 0 == strcmp(buffer,"01{2{3{4hoo56}7}8}9"), "wrong output\n");
1203     }
1204     ok( r == ERROR_SUCCESS, "format failed\n");
1205 
1206     r = MsiRecordSetStringA(hrec, 0, "0{1{2[1]3}4");
1207     ok( r == ERROR_SUCCESS, "set string failed\n");
1208     r = MsiRecordSetStringA(hrec, 1, "hoo");
1209     ok( r == ERROR_SUCCESS, "set string failed\n");
1210     sz = sizeof buffer;
1211     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1212     todo_wine
1213     {
1214         ok( sz == 9, "size wrong\n");
1215         ok( 0 == strcmp(buffer,"01{2hoo34"), "wrong output\n");
1216     }
1217     ok( r == ERROR_SUCCESS, "format failed\n");
1218 
1219     r = MsiRecordSetStringA(hrec, 0, "0{1{2[1]3}4");
1220     ok( r == ERROR_SUCCESS, "set string failed\n");
1221     r = MsiRecordSetStringA(hrec, 1, "hoo");
1222     ok( r == ERROR_SUCCESS, "set string failed\n");
1223     sz = sizeof buffer;
1224     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1225     todo_wine
1226     {
1227         ok( sz == 9, "size wrong\n");
1228         ok( 0 == strcmp(buffer,"01{2hoo34"), "wrong output\n");
1229     }
1230     ok( r == ERROR_SUCCESS, "format failed\n");
1231 
1232     r = MsiRecordSetStringA(hrec, 0, "{[1.} [1]");
1233     ok( r == ERROR_SUCCESS, "set string failed\n");
1234     r = MsiRecordSetStringA(hrec, 1, "hoo");
1235     ok( r == ERROR_SUCCESS, "set string failed\n");
1236     sz = sizeof buffer;
1237     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1238     ok( sz == 9, "size wrong\n");
1239     todo_wine
1240     {
1241         ok( 0 == strcmp(buffer,"{[1.} hoo"), "wrong output\n");
1242     }
1243     ok( r == ERROR_SUCCESS, "format failed\n");
1244 
1245     r = MsiRecordSetStringA(hrec, 0, "{[{[1]}]}");
1246     ok( r == ERROR_SUCCESS, "set string failed\n");
1247     r = MsiRecordSetStringA(hrec, 1, "2");
1248     ok( r == ERROR_SUCCESS, "set string failed\n");
1249     r = MsiRecordSetStringA(hrec, 2, "foo");
1250     ok( r == ERROR_SUCCESS, "set string failed\n");
1251     sz = sizeof buffer;
1252     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1253     todo_wine
1254     {
1255         ok( sz == 9, "size wrong\n");
1256         ok( 0 == strcmp(buffer,"{[{[1]}]}"), "wrong output\n");
1257     }
1258     ok( r == ERROR_SUCCESS, "format failed\n");
1259 
1260     r = MsiRecordSetStringA(hrec, 0, "{[1][}");
1261     ok( r == ERROR_SUCCESS, "set string failed\n");
1262     r = MsiRecordSetStringA(hrec, 1, "2");
1263     ok( r == ERROR_SUCCESS, "set string failed\n");
1264     r = MsiRecordSetStringA(hrec, 2, "foo");
1265     ok( r == ERROR_SUCCESS, "set string failed\n");
1266     sz = sizeof buffer;
1267     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1268     todo_wine
1269     {
1270         ok( sz == 2, "size wrong\n");
1271         ok( 0 == strcmp(buffer,"2["), "wrong output\n");
1272     }
1273     ok( r == ERROR_SUCCESS, "format failed\n");
1274 
1275     r = MsiRecordSetStringA(hrec, 0, "[1]");
1276     ok( r == ERROR_SUCCESS, "set string failed\n");
1277     r = MsiRecordSetStringA(hrec, 1, "[2]");
1278     ok( r == ERROR_SUCCESS, "set string failed\n");
1279     r = MsiRecordSetStringA(hrec, 2, "foo");
1280     ok( r == ERROR_SUCCESS, "set string failed\n");
1281     sz = sizeof buffer;
1282     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1283     ok( sz == 3, "size wrong\n");
1284     ok( 0 == strcmp(buffer,"[2]"), "wrong output\n");
1285     ok( r == ERROR_SUCCESS, "format failed\n");
1286 
1287     r = MsiRecordSetStringA(hrec, 0, "[{{boo}}1]");
1288     ok( r == ERROR_SUCCESS, "set string failed\n");
1289     r = MsiRecordSetStringA(hrec, 1, "hoo");
1290     ok( r == ERROR_SUCCESS, "set string failed\n");
1291     sz = sizeof buffer;
1292     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1293     ok( r == ERROR_SUCCESS, "format failed\n");
1294     ok( sz == 3, "size wrong\n");
1295     todo_wine
1296     {
1297         ok( 0 == strcmp(buffer,"[1]"), "wrong output: %s\n", buffer);
1298     }
1299 
1300     r = MsiRecordSetStringA(hrec, 0, "[{{boo}}1]");
1301     ok( r == ERROR_SUCCESS, "set string failed\n");
1302     r = MsiRecordSetStringA(hrec, 0, "[1{{boo}}]");
1303     ok( r == ERROR_SUCCESS, "set string failed\n");
1304     r = MsiRecordSetStringA(hrec, 1, "hoo");
1305     ok( r == ERROR_SUCCESS, "set string failed\n");
1306     sz = sizeof buffer;
1307     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1308     ok( sz == 3, "size wrong\n");
1309     ok( 0 == strcmp(buffer,"[1]"), "wrong output\n");
1310     ok( r == ERROR_SUCCESS, "format failed\n");
1311 
1312     r = MsiRecordSetStringA(hrec, 0, "{[1]{{boo} }}");
1313     ok( r == ERROR_SUCCESS, "set string failed\n");
1314     r = MsiRecordSetStringA(hrec, 1, "hoo");
1315     ok( r == ERROR_SUCCESS, "set string failed\n");
1316     sz = sizeof buffer;
1317     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1318     todo_wine
1319     {
1320         ok( sz == 11, "size wrong\n");
1321         ok( 0 == strcmp(buffer,"hoo{{boo }}"), "wrong output\n");
1322     }
1323     ok( r == ERROR_SUCCESS, "format failed\n");
1324 
1325     r = MsiRecordSetStringA(hrec, 0, "{[1{{boo}}]}");
1326     ok( r == ERROR_SUCCESS, "set string failed\n");
1327     r = MsiRecordSetStringA(hrec, 1, "hoo");
1328     ok( r == ERROR_SUCCESS, "set string failed\n");
1329     sz = sizeof buffer;
1330     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1331     todo_wine
1332     {
1333         ok( sz == 12, "size wrong: got %u, expected 12\n", sz);
1334         ok( 0 == strcmp(buffer,"{[1{{boo}}]}"), "wrong output: got %s, expected [1]\n", buffer);
1335     }
1336     ok( r == ERROR_SUCCESS, "format failed\n");
1337 
1338     r = MsiRecordSetStringA(hrec, 0, "{{[1]}");
1339     ok( r == ERROR_SUCCESS, "set string failed\n");
1340     r = MsiRecordSetStringA(hrec, 1, "hoo");
1341     ok( r == ERROR_SUCCESS, "set string failed\n");
1342     sz = sizeof buffer;
1343     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1344     ok( sz == 6, "size wrong: got %u, expected 3\n", sz);
1345     ok( 0 == strcmp(buffer,"{{hoo}"), "wrong output: got %s, expected [1]\n", buffer);
1346     ok( r == ERROR_SUCCESS, "format failed\n");
1347 
1348     r = MsiRecordSetStringA(hrec, 0, "{[1{{bo}o}}]}");
1349     ok( r == ERROR_SUCCESS, "set string failed\n");
1350     r = MsiRecordSetStringA(hrec, 1, "hoo");
1351     ok( r == ERROR_SUCCESS, "set string failed\n");
1352     sz = sizeof buffer;
1353     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1354     ok( sz == 13, "size wrong\n");
1355     ok( 0 == strcmp(buffer,"{[1{{bo}o}}]}"), "wrong output %s\n",buffer);
1356     ok( r == ERROR_SUCCESS, "format failed\n");
1357 
1358     r = MsiRecordSetStringA(hrec, 0, "{[1{{b{o}o}}]}");
1359     ok( r == ERROR_SUCCESS, "set string failed\n");
1360     sz = sizeof buffer;
1361     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1362     todo_wine
1363     {
1364         ok( sz == 14, "size wrong\n");
1365         ok( 0 == strcmp(buffer,"{[1{{b{o}o}}]}"), "wrong output %s\n",buffer);
1366     }
1367     ok( r == ERROR_SUCCESS, "format failed\n");
1368 
1369     r = MsiRecordSetStringA(hrec, 0, "{ {[1]}");
1370     ok( r == ERROR_SUCCESS, "set string failed\n");
1371     r = MsiRecordSetStringA(hrec, 1, "hoo");
1372     ok( r == ERROR_SUCCESS, "set string failed\n");
1373     sz = sizeof buffer;
1374     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1375     todo_wine
1376     {
1377         ok( sz == 5, "size wrong\n");
1378         ok( 0 == strcmp(buffer," {hoo"), "wrong output %s\n",buffer);
1379     }
1380     ok( r == ERROR_SUCCESS, "format failed\n");
1381 
1382     /* {} inside a substitution does strange things... */
1383     r = MsiRecordSetStringA(hrec, 0, "[[1]{}]");
1384     ok( r == ERROR_SUCCESS, "set string failed\n");
1385     r = MsiRecordSetStringA(hrec, 1, "2");
1386     ok( r == ERROR_SUCCESS, "set string failed\n");
1387     sz = sizeof buffer;
1388     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1389     todo_wine
1390     {
1391         ok( sz == 5, "size wrong\n");
1392         ok( 0 == strcmp(buffer,"[[1]]"), "wrong output %s\n",buffer);
1393     }
1394     ok( r == ERROR_SUCCESS, "format failed\n");
1395 
1396     r = MsiRecordSetStringA(hrec, 0, "[[1]{}[1]]");
1397     ok( r == ERROR_SUCCESS, "set string failed\n");
1398     r = MsiRecordSetStringA(hrec, 1, "2");
1399     ok( r == ERROR_SUCCESS, "set string failed\n");
1400     sz = sizeof buffer;
1401     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1402     todo_wine
1403     {
1404         ok( sz == 6, "size wrong\n");
1405         ok( 0 == strcmp(buffer,"[[1]2]"), "wrong output %s\n",buffer);
1406     }
1407     ok( r == ERROR_SUCCESS, "format failed\n");
1408 
1409     r = MsiRecordSetStringA(hrec, 0, "[a[1]b[1]c{}d[1]e]");
1410     ok( r == ERROR_SUCCESS, "set string failed\n");
1411     r = MsiRecordSetStringA(hrec, 1, "2");
1412     ok( r == ERROR_SUCCESS, "set string failed\n");
1413     sz = sizeof buffer;
1414     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1415     todo_wine
1416     {
1417         ok( sz == 14, "size wrong\n");
1418         ok( 0 == strcmp(buffer,"[a[1]b[1]cd2e]"), "wrong output %s\n",buffer);
1419     }
1420     ok( r == ERROR_SUCCESS, "format failed\n");
1421 
1422     r = MsiRecordSetStringA(hrec, 0, "[a[1]b");
1423     ok( r == ERROR_SUCCESS, "set string failed\n");
1424     r = MsiRecordSetStringA(hrec, 1, "2");
1425     ok( r == ERROR_SUCCESS, "set string failed\n");
1426     sz = sizeof buffer;
1427     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1428     ok( sz == 6, "size wrong\n");
1429     ok( 0 == strcmp(buffer,"[a[1]b"), "wrong output %s\n",buffer);
1430     ok( r == ERROR_SUCCESS, "format failed\n");
1431 
1432     r = MsiRecordSetStringA(hrec, 0, "a[1]b]");
1433     ok( r == ERROR_SUCCESS, "set string failed\n");
1434     r = MsiRecordSetStringA(hrec, 1, "2");
1435     ok( r == ERROR_SUCCESS, "set string failed\n");
1436     sz = sizeof buffer;
1437     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1438     ok( sz == 4, "size wrong\n");
1439     ok( 0 == strcmp(buffer,"a2b]"), "wrong output %s\n",buffer);
1440     ok( r == ERROR_SUCCESS, "format failed\n");
1441 
1442     r = MsiRecordSetStringA(hrec, 0, "]a[1]b");
1443     ok( r == ERROR_SUCCESS, "set string failed\n");
1444     r = MsiRecordSetStringA(hrec, 1, "2");
1445     ok( r == ERROR_SUCCESS, "set string failed\n");
1446     sz = sizeof buffer;
1447     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1448     ok( sz == 4, "size wrong\n");
1449     ok( 0 == strcmp(buffer,"]a2b"), "wrong output %s\n",buffer);
1450     ok( r == ERROR_SUCCESS, "format failed\n");
1451 
1452     r = MsiRecordSetStringA(hrec, 0, "]a[1]b");
1453     ok( r == ERROR_SUCCESS, "set string failed\n");
1454     r = MsiRecordSetStringA(hrec, 1, "2");
1455     ok( r == ERROR_SUCCESS, "set string failed\n");
1456     sz = sizeof buffer;
1457     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1458     ok( sz == 4, "size wrong\n");
1459     ok( 0 == strcmp(buffer,"]a2b"), "wrong output %s\n",buffer);
1460     ok( r == ERROR_SUCCESS, "format failed\n");
1461 
1462     r = MsiRecordSetStringA(hrec, 0, "\\[1]");
1463     ok( r == ERROR_SUCCESS, "set string failed\n");
1464     r = MsiRecordSetStringA(hrec, 1, "2");
1465     ok( r == ERROR_SUCCESS, "set string failed\n");
1466     sz = sizeof buffer;
1467     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1468     ok( sz == 2, "size wrong\n");
1469     ok( 0 == strcmp(buffer,"\\2"), "wrong output %s\n",buffer);
1470     ok( r == ERROR_SUCCESS, "format failed\n");
1471 
1472     r = MsiRecordSetStringA(hrec, 0, "\\{[1]}");
1473     ok( r == ERROR_SUCCESS, "set string failed\n");
1474     r = MsiRecordSetStringA(hrec, 1, "2");
1475     ok( r == ERROR_SUCCESS, "set string failed\n");
1476     sz = sizeof buffer;
1477     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1478     ok( sz == 2, "size wrong\n");
1479     ok( 0 == strcmp(buffer,"\\2"), "wrong output %s\n",buffer);
1480     ok( r == ERROR_SUCCESS, "format failed\n");
1481 
1482     r = MsiRecordSetStringA(hrec, 0, "a{b[1]c}d");
1483     ok( r == ERROR_SUCCESS, "set string failed\n");
1484     r = MsiRecordSetStringA(hrec, 1, NULL);
1485     ok( r == ERROR_SUCCESS, "set string failed\n");
1486     sz = sizeof buffer;
1487     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1488     ok( sz == 2, "size wrong\n");
1489     ok( 0 == strcmp(buffer,"ad"), "wrong output %s\n",buffer);
1490     ok( r == ERROR_SUCCESS, "format failed\n");
1491 
1492     r = MsiRecordSetStringA(hrec, 0, "{a[0]b}");
1493     ok( r == ERROR_SUCCESS, "set string failed\n");
1494     r = MsiRecordSetStringA(hrec, 1, "foo");
1495     ok( r == ERROR_SUCCESS, "set string failed\n");
1496     sz = sizeof buffer;
1497     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1498     ok( sz == 9, "size wrong\n");
1499     ok( 0 == strcmp(buffer,"a{a[0]b}b"), "wrong output %s\n",buffer);
1500     ok( r == ERROR_SUCCESS, "format failed\n");
1501 
1502     r = MsiRecordSetStringA(hrec, 0, "[foo]");
1503     ok( r == ERROR_SUCCESS, "set string failed\n");
1504     sz = sizeof buffer;
1505     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1506     ok( sz == 5, "size wrong\n");
1507     ok( 0 == strcmp(buffer,"[foo]"), "wrong output %s\n",buffer);
1508     ok( r == ERROR_SUCCESS, "format failed\n");
1509 
1510     r = MsiRecordSetStringA(hrec, 0, "{[1][-1][1]}");
1511     ok( r == ERROR_SUCCESS, "set string failed\n");
1512     r = MsiRecordSetStringA(hrec, 1, "foo");
1513     ok( r == ERROR_SUCCESS, "set string failed\n");
1514     sz = sizeof buffer;
1515     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1516     todo_wine
1517     {
1518         ok( sz == 12, "size wrong\n");
1519         ok( 0 == strcmp(buffer,"{foo[-1]foo}"), "wrong output %s\n",buffer);
1520     }
1521     ok( r == ERROR_SUCCESS, "format failed\n");
1522 
1523     /* nested braces */
1524     sz = sizeof buffer;
1525     r = MsiRecordSetStringA(hrec, 0, "{abcd}");
1526     ok( r == ERROR_SUCCESS, "set string failed\n");
1527     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1528     ok( r == ERROR_SUCCESS, "format failed\n");
1529     ok( sz == 6, "size wrong(%i)\n",sz);
1530     ok( 0 == strcmp(buffer,"{abcd}"), "wrong output (%s)\n",buffer);
1531 
1532     sz = sizeof buffer;
1533     r = MsiRecordSetStringA(hrec, 0, "{a[one]bc[two]de[one]f}");
1534     ok( r == ERROR_SUCCESS, "set string failed\n");
1535     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1536     ok( r == ERROR_SUCCESS, "format failed\n");
1537     ok( sz == 23, "size wrong(%i)\n",sz);
1538     ok( 0 == strcmp(buffer,"{a[one]bc[two]de[one]f}"), "wrong output (%s)\n",buffer);
1539 
1540     sz = sizeof buffer;
1541     r = MsiRecordSetStringA(hrec, 0, "{a[one]bc[bad]de[two]f}");
1542     ok( r == ERROR_SUCCESS, "set string failed\n");
1543     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1544     ok( r == ERROR_SUCCESS, "format failed\n");
1545     ok( sz == 23, "size wrong(%i)\n",sz);
1546     ok( 0 == strcmp(buffer,"{a[one]bc[bad]de[two]f}"), "wrong output (%s)\n",buffer);
1547 
1548     sz = sizeof buffer;
1549     r = MsiRecordSetStringA(hrec, 0, "{[bad]}");
1550     ok( r == ERROR_SUCCESS, "set string failed\n");
1551     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1552     ok( r == ERROR_SUCCESS, "format failed\n");
1553     ok( sz == 7, "size wrong(%i)\n",sz);
1554     ok( 0 == strcmp(buffer,"{[bad]}"), "wrong output (%s)\n",buffer);
1555 
1556     sz = sizeof buffer;
1557     r = MsiRecordSetStringA(hrec, 0, "{abc{d[one]ef}"); /* missing final brace */
1558     ok( r == ERROR_SUCCESS, "set string failed\n");
1559     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1560     ok( r == ERROR_SUCCESS, "format failed\n");
1561     ok( sz == 14, "size wrong(%i)\n",sz);
1562     ok( 0 == strcmp(buffer,"{abc{d[one]ef}"), "wrong output (%s)\n",buffer);
1563 
1564     sz = sizeof buffer;
1565     r = MsiRecordSetStringA(hrec, 0, "{abc{d[one]ef}}");
1566     ok( r == ERROR_SUCCESS, "set string failed\n");
1567     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1568     ok( r == ERROR_SUCCESS, "format failed\n");
1569     ok( sz == 15, "size wrong(%i)\n",sz);
1570     ok( 0 == strcmp(buffer,"{abc{d[one]ef}}"), "wrong output (%s)\n",buffer);
1571 
1572     sz = sizeof buffer;
1573     r = MsiRecordSetStringA(hrec, 0, "{abc}{{def}hi{j[one]k}}");
1574     ok( r == ERROR_SUCCESS, "set string failed\n");
1575     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1576     ok( r == ERROR_SUCCESS, "format failed\n");
1577     ok( sz == 5, "size wrong(%i)\n",sz);
1578     ok( 0 == strcmp(buffer,"{abc}"), "wrong output (%s)\n",buffer);
1579 
1580     sz = sizeof buffer;
1581     r = MsiRecordSetStringA(hrec, 0, "{{def}hi{j[one]k}}");
1582     ok( r == ERROR_SUCCESS, "set string failed\n");
1583     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1584     ok( r == ERROR_SUCCESS, "format failed\n");
1585     ok( sz == 0, "size wrong(%i)\n",sz);
1586     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1587 
1588     sz = sizeof buffer;
1589     r = MsiRecordSetStringA(hrec, 0, "{{def}hi{jk}}");
1590     ok( r == ERROR_SUCCESS, "set string failed\n");
1591     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1592     ok( r == ERROR_SUCCESS, "format failed\n");
1593     ok( sz == 0, "size wrong(%i)\n",sz);
1594     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1595 
1596     sz = sizeof buffer;
1597     r = MsiRecordSetStringA(hrec, 0, "{{{def}}hi{jk}}");
1598     ok( r == ERROR_SUCCESS, "set string failed\n");
1599     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1600     ok( r == ERROR_SUCCESS, "format failed\n");
1601     todo_wine
1602     {
1603         ok( sz == 7, "size wrong(%i)\n",sz);
1604         ok( 0 == strcmp(buffer,"hi{jk}}"), "wrong output (%s)\n",buffer);
1605     }
1606 
1607     sz = sizeof buffer;
1608     r = MsiRecordSetStringA(hrec, 0, "{{def}hi{{jk}}}");
1609     ok( r == ERROR_SUCCESS, "set string failed\n");
1610     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1611     ok( r == ERROR_SUCCESS, "format failed\n");
1612     todo_wine
1613     {
1614         ok( sz == 1, "size wrong(%i)\n",sz);
1615         ok( 0 == strcmp(buffer,"}"), "wrong output (%s)\n",buffer);
1616     }
1617 
1618     sz = sizeof buffer;
1619     r = MsiRecordSetStringA(hrec, 0, "{{def}{jk}}");
1620     ok( r == ERROR_SUCCESS, "set string failed\n");
1621     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1622     ok( r == ERROR_SUCCESS, "format failed\n");
1623     ok( sz == 0, "size wrong(%i)\n",sz);
1624     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1625 
1626     sz = sizeof buffer;
1627     r = MsiRecordSetStringA(hrec, 0, "{{def}}");
1628     ok( r == ERROR_SUCCESS, "set string failed\n");
1629     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1630     ok( r == ERROR_SUCCESS, "format failed\n");
1631     ok( sz == 0, "size wrong(%i)\n",sz);
1632     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
1633 
1634     sz = sizeof buffer;
1635     r = MsiRecordSetStringA(hrec, 0, "{a{b}c}");
1636     ok( r == ERROR_SUCCESS, "set string failed\n");
1637     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1638     ok( r == ERROR_SUCCESS, "format failed\n");
1639     ok( sz == 7, "size wrong(%i)\n",sz);
1640     ok( 0 == strcmp(buffer,"{a{b}c}"), "wrong output (%s)\n",buffer);
1641 
1642     sz = sizeof buffer;
1643     r = MsiRecordSetStringA(hrec, 0, "{a{b}}");
1644     ok( r == ERROR_SUCCESS, "set string failed\n");
1645     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1646     ok( r == ERROR_SUCCESS, "format failed\n");
1647     ok( sz == 6, "size wrong(%i)\n",sz);
1648     ok( 0 == strcmp(buffer,"{a{b}}"), "wrong output (%s)\n",buffer);
1649 
1650     sz = sizeof buffer;
1651     r = MsiRecordSetStringA(hrec, 0, "{{b}c}");
1652     ok( r == ERROR_SUCCESS, "set string failed\n");
1653     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1654     ok( r == ERROR_SUCCESS, "format failed\n");
1655     ok( sz == 6, "size wrong(%i)\n",sz);
1656     ok( 0 == strcmp(buffer,"{{b}c}"), "wrong output (%s)\n",buffer);
1657 
1658     sz = sizeof buffer;
1659     r = MsiRecordSetStringA(hrec, 0, "{{{{}}}}");
1660     ok( r == ERROR_SUCCESS, "set string failed\n");
1661     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1662     ok( r == ERROR_SUCCESS, "format failed\n");
1663     todo_wine
1664     {
1665         ok( sz == 2, "size wrong(%i)\n",sz);
1666         ok( 0 == strcmp(buffer,"}}"), "wrong output (%s)\n",buffer);
1667     }
1668 
1669     sz = sizeof buffer;
1670     MsiRecordSetInteger(hrec, 1, 100);
1671     MsiRecordSetInteger(hrec, 2, -100);
1672     r = MsiRecordSetStringA(hrec, 0, "[1] [2]");
1673     ok( r == ERROR_SUCCESS, "set string failed\n");
1674     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1675     ok( r == ERROR_SUCCESS, "format failed\n");
1676     ok( sz == 8, "size wrong(%i)\n",sz);
1677     ok( 0 == strcmp(buffer,"100 -100"), "wrong output (%s)\n",buffer);
1678 
1679     sz = sizeof(buffer);
1680     r = MsiRecordSetStringA(hrec, 0, "[1] {[noprop] [twoprop]} {abcdef}");
1681     ok( r == ERROR_SUCCESS, "set string failed\n");
1682     r = MsiRecordSetStringA(hrec, 1, "one");
1683     ok( r == ERROR_SUCCESS, "set string failed\n");
1684     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1685     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1686     ok(sz == 33, "Expected 33, got %d\n",sz);
1687     ok(!lstrcmpA(buffer, "one {[noprop] [twoprop]} {abcdef}"),
1688        "Expected \"one {[noprop] [twoprop]} {abcdef}\", got \"%s\"\n", buffer);
1689 
1690     sz = sizeof(buffer);
1691     r = MsiRecordSetStringA(hrec, 0, "[1] {[noprop] [one]} {abcdef}");
1692     ok( r == ERROR_SUCCESS, "set string failed\n");
1693     r = MsiRecordSetStringA(hrec, 1, "one");
1694     ok( r == ERROR_SUCCESS, "set string failed\n");
1695     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1696     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1697     ok(sz == 29, "Expected 29, got %d\n",sz);
1698     ok(!lstrcmpA(buffer, "one {[noprop] [one]} {abcdef}"),
1699        "Expected \"one {[noprop] [one]} {abcdef}\", got \"%s\"\n", buffer);
1700 
1701     sz = sizeof(buffer);
1702     r = MsiRecordSetStringA(hrec, 0, "[1] {[one]} {abcdef}");
1703     ok( r == ERROR_SUCCESS, "set string failed\n");
1704     r = MsiRecordSetStringA(hrec, 1, "one");
1705     ok( r == ERROR_SUCCESS, "set string failed\n");
1706     r = MsiFormatRecordA(0, hrec, buffer, &sz);
1707     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1708     ok(sz == 20, "Expected 20, got %d\n",sz);
1709     ok(!lstrcmpA(buffer, "one {[one]} {abcdef}"),
1710        "Expected \"one {[one]} {abcdef}\", got \"%s\"\n", buffer);
1711 
1712     MsiCloseHandle( hrec );
1713 }
1714 
1715 static void test_formatrecord_package(void)
1716 {
1717     char buffer[100];
1718     MSIHANDLE hrec;
1719     MSIHANDLE package;
1720     UINT r;
1721     DWORD sz=100;
1722 
1723     r = helper_createpackage( msifile, &package );
1724     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
1725     {
1726         skip("Not enough rights to perform tests\n");
1727         return;
1728     }
1729     ok( r == ERROR_SUCCESS, "Unable to create package %u\n", r );
1730 
1731     hrec = MsiCreateRecord(12);
1732     ok( hrec, "failed to create record\n");
1733 
1734     r = MsiFormatRecordA(package, 0, NULL, NULL );
1735     ok( r == ERROR_INVALID_HANDLE, "wrong error\n");
1736 
1737     r = MsiFormatRecordA(package, hrec, NULL, NULL );
1738     ok( r == ERROR_SUCCESS, "format failed\n");
1739 
1740     r = MsiRecordSetStringA(hrec,0,NULL);
1741     ok( r == ERROR_SUCCESS, "set string failed\n");
1742     r = MsiRecordSetStringA(hrec,1,NULL);
1743     ok( r == ERROR_SUCCESS, "set string failed\n");
1744     r = MsiRecordSetStringA(hrec,2,NULL);
1745     ok( r == ERROR_SUCCESS, "set string failed\n");
1746     r = MsiRecordSetStringA(hrec,3,NULL);
1747     ok( r == ERROR_SUCCESS, "set string failed\n");
1748     r = MsiRecordSetStringA(hrec,4,NULL);
1749     ok( r == ERROR_SUCCESS, "set string failed\n");
1750     r = MsiRecordSetStringA(hrec,5,NULL);
1751     ok( r == ERROR_SUCCESS, "set string failed\n");
1752     r = MsiRecordSetStringA(hrec,6,NULL);
1753     ok( r == ERROR_SUCCESS, "set string failed\n");
1754     r = MsiRecordSetStringA(hrec,7,NULL);
1755     ok( r == ERROR_SUCCESS, "set string failed\n");
1756     r = MsiRecordSetStringA(hrec,8,NULL);
1757     ok( r == ERROR_SUCCESS, "set string failed\n");
1758     r = MsiRecordSetStringA(hrec,9,NULL);
1759     ok( r == ERROR_SUCCESS, "set string failed\n");
1760     r = MsiRecordSetStringA(hrec,10,NULL);
1761     ok( r == ERROR_SUCCESS, "set string failed\n");
1762     r = MsiRecordSetStringA(hrec,11,NULL);
1763     ok( r == ERROR_SUCCESS, "set string failed\n");
1764     r = MsiRecordSetStringA(hrec,12,NULL);
1765     ok( r == ERROR_SUCCESS, "set string failed\n");
1766 
1767     sz = sizeof buffer;
1768     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1769     ok( r == ERROR_SUCCESS, "format failed with empty buffer (%i)\n",r);
1770     ok( sz == 51, "size wrong (%i)\n",sz);
1771     ok( 0 == strcmp(buffer,"1:  2:  3:  4:  5:  6:  7:  8:  9:  10:  11:  12:  "), "wrong output(%s)\n",buffer);
1772 
1773     r = MsiSetPropertyA(package, "prop", "val");
1774     ok( r == ERROR_SUCCESS, "failed to set propertY: %d\n", r);
1775 
1776     r = MsiRecordSetStringA(hrec, 0, NULL);
1777     ok( r == ERROR_SUCCESS, "set string failed\n");
1778     r = MsiRecordSetStringA(hrec, 1, "[2]");
1779     ok( r == ERROR_SUCCESS, "set string failed\n");
1780     r = MsiRecordSetStringA(hrec, 2, "stuff");
1781     ok( r == ERROR_SUCCESS, "set string failed\n");
1782     r = MsiRecordSetStringA(hrec, 3, "prop");
1783     ok( r == ERROR_SUCCESS, "set string failed\n");
1784     r = MsiRecordSetStringA(hrec, 4, "[prop]");
1785     ok( r == ERROR_SUCCESS, "set string failed\n");
1786     r = MsiRecordSetStringA(hrec, 5, "[noprop]");
1787     ok( r == ERROR_SUCCESS, "set string failed\n");
1788     sz = sizeof buffer;
1789     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1790     ok( r == ERROR_SUCCESS, "format failed with empty buffer (%i)\n",r);
1791     todo_wine
1792     {
1793         ok( sz == 66, "size wrong (%i)\n",sz);
1794         ok( !lstrcmpA(buffer,
1795             "1: [2] 2: stuff 3: prop 4: val 5:  6:  7:  8:  9:  10:  11:  12:  "),
1796             "wrong output(%s)\n",buffer);
1797     }
1798 
1799     /* now put play games with escaping */
1800     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [\\3asdf]");
1801     ok( r == ERROR_SUCCESS, "set string failed\n");
1802     r = MsiRecordSetStringA(hrec, 1, "boo");
1803     ok( r == ERROR_SUCCESS, "set string failed\n");
1804     r = MsiRecordSetStringA(hrec, 2, "hoo");
1805     ok( r == ERROR_SUCCESS, "set string failed\n");
1806     sz = sizeof buffer;
1807     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1808     ok( r == ERROR_SUCCESS, "format failed\n");
1809     ok( sz == 9, "size wrong(%i)\n",sz);
1810     ok( 0 == strcmp(buffer,"boo hoo 3"), "wrong output (%s)\n",buffer);
1811 
1812     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [\\x]");
1813     ok( r == ERROR_SUCCESS, "set string failed\n");
1814     r = MsiRecordSetStringA(hrec, 1, "boo");
1815     ok( r == ERROR_SUCCESS, "set string failed\n");
1816     r = MsiRecordSetStringA(hrec, 2, "hoo");
1817     ok( r == ERROR_SUCCESS, "set string failed\n");
1818     sz = sizeof buffer;
1819     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1820     ok( r == ERROR_SUCCESS, "format failed\n");
1821     ok( sz == 9, "size wrong(%i)\n",sz);
1822     ok( 0 == strcmp(buffer,"boo hoo x"), "wrong output (%s)\n",buffer);
1823 
1824     MsiRecordSetStringA(hrec, 0, "[\\x]");
1825     sz = sizeof buffer;
1826     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1827     ok( r == ERROR_SUCCESS, "format failed\n");
1828     ok( sz == 1, "size wrong: %d\n", sz);
1829     ok( 0 == strcmp(buffer,"x"), "wrong output: %s\n", buffer);
1830 
1831     MsiRecordSetStringA(hrec, 0, "{\\x}");
1832     sz = sizeof buffer;
1833     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1834     ok( r == ERROR_SUCCESS, "format failed\n");
1835     ok( sz == 4, "size wrong: %d\n", sz);
1836     ok( 0 == strcmp(buffer,"{\\x}"), "wrong output: %s\n", buffer);
1837 
1838     MsiRecordSetStringA(hrec, 0, "[abc\\x]");
1839     sz = sizeof buffer;
1840     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1841     ok( r == ERROR_SUCCESS, "format failed\n");
1842     ok( sz == 0, "size wrong: %d\n", sz);
1843     ok( 0 == strcmp(buffer,""), "wrong output: %s\n", buffer);
1844 
1845     MsiRecordSetStringA(hrec, 0, "[abc\\xdef]");
1846     sz = sizeof buffer;
1847     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1848     ok( r == ERROR_SUCCESS, "format failed\n");
1849     ok( sz == 0, "size wrong: %d\n", sz);
1850     ok( 0 == strcmp(buffer,""), "wrong output: %s\n", buffer);
1851 
1852     MsiRecordSetStringA(hrec, 0, "\\x");
1853     sz = sizeof(buffer);
1854     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1855     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1856     ok(sz == 2, "Expected 2, got %d\n", sz);
1857     ok(!lstrcmpA(buffer, "\\x"), "Expected \"\\x\", got \"%s\"\n", buffer);
1858 
1859     MsiRecordSetStringA(hrec, 0, "[\\[");
1860     sz = sizeof(buffer);
1861     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1862     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1863     ok(sz == 3, "Expected 3, got %d\n", sz);
1864     ok(!lstrcmpA(buffer, "[\\["), "Expected \"[\\[\", got \"%s\"\n", buffer);
1865 
1866     MsiRecordSetStringA(hrec, 0, "[\\[]");
1867     sz = sizeof(buffer);
1868     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1869     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1870     ok(sz == 1, "Expected 1, got %d\n", sz);
1871     ok(!lstrcmpA(buffer, "["), "Expected \"[\", got \"%s\"\n", buffer);
1872 
1873     MsiRecordSetStringA(hrec, 0, "[[]");
1874     sz = sizeof(buffer);
1875     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1876     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1877     ok(sz == 3, "Expected 3, got %d\n", sz);
1878     ok(!lstrcmpA(buffer, "[[]"), "Expected \"[]\", got \"%s\"\n", buffer);
1879 
1880     MsiRecordSetStringA(hrec, 0, "[\\[]]");
1881     sz = sizeof(buffer);
1882     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1883     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1884     ok(sz == 2, "Expected 2, got %d\n", sz);
1885     ok(!lstrcmpA(buffer, "[]"), "Expected \"[]\", got \"%s\"\n", buffer);
1886 
1887     MsiRecordSetStringA(hrec, 0, "[\\[a]");
1888     sz = sizeof(buffer);
1889     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1890     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1891     ok(sz == 1, "Expected 1, got %d\n", sz);
1892     ok(!lstrcmpA(buffer, "["), "Expected \"[\", got \"%s\"\n", buffer);
1893 
1894     MsiRecordSetStringA(hrec, 0, "[\\a[]");
1895     sz = sizeof(buffer);
1896     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1897     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1898     todo_wine
1899     {
1900         ok(sz == 1, "Expected 1, got %d\n", sz);
1901         ok(!lstrcmpA(buffer, "a"), "Expected \"a\", got \"%s\"\n", buffer);
1902     }
1903 
1904     MsiRecordSetStringA(hrec, 0, "[prop]");
1905     sz = sizeof(buffer);
1906     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1907     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1908     ok(sz == 3, "Expected 3, got %d\n", sz);
1909     ok(!lstrcmpA(buffer, "val"), "Expected \"val\", got \"%s\"\n", buffer);
1910 
1911     MsiRecordSetStringA(hrec, 0, "[prop] [pro\\pblah] [prop]");
1912     sz = sizeof(buffer);
1913     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1914     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1915     ok(sz == 8, "Expected 8, got %d\n", sz);
1916     ok(!lstrcmpA(buffer, "val  val"), "Expected \"val  val\", got \"%s\"\n", buffer);
1917 
1918     MsiSetPropertyA(package, "b", "ball");
1919     MsiRecordSetStringA(hrec, 0, "[\\b]");
1920     sz = sizeof(buffer);
1921     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1922     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1923     ok(sz == 1, "Expected 1, got %d\n", sz);
1924     ok(!lstrcmpA(buffer, "b"), "Expected \"b\", got \"%s\"\n", buffer);
1925 
1926     MsiRecordSetStringA(hrec, 0, "[\\c]");
1927     sz = sizeof(buffer);
1928     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1929     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1930     ok(sz == 1, "Expected 1, got %d\n", sz);
1931     ok(!lstrcmpA(buffer, "c"), "Expected \"c\", got \"%s\"\n", buffer);
1932 
1933     MsiRecordSetStringA(hrec, 0, "[\\[]prop]");
1934     sz = sizeof(buffer);
1935     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1936     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1937     ok(sz == 6, "Expected 6, got %d\n", sz);
1938     ok(!lstrcmpA(buffer, "[prop]"), "Expected \"[prop]\", got \"%s\"\n", buffer);
1939 
1940     MsiRecordSetStringA(hrec, 0, "[\\a]prop]");
1941     sz = sizeof(buffer);
1942     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1943     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1944     ok(sz == 6, "Expected 6, got %d\n", sz);
1945     ok(!lstrcmpA(buffer, "aprop]"), "Expected \"aprop]\", got \"%s\"\n", buffer);
1946 
1947     MsiRecordSetStringA(hrec, 0, "[\\[]Bracket Text[\\]]");
1948     sz = sizeof buffer;
1949     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1950     ok( r == ERROR_SUCCESS, "format failed\n");
1951     ok( sz == 14, "size wrong: %d\n", sz);
1952     ok( 0 == strcmp(buffer,"[Bracket Text]"), "wrong output: %s\n", buffer);
1953 
1954     /* null characters */
1955     r = MsiRecordSetStringA(hrec, 0, "[1] [~] [2]");
1956     ok( r == ERROR_SUCCESS, "set string failed\n");
1957     r = MsiRecordSetStringA(hrec, 1, "boo");
1958     ok( r == ERROR_SUCCESS, "set string failed\n");
1959     r = MsiRecordSetStringA(hrec, 2, "hoo");
1960     ok( r == ERROR_SUCCESS, "set string failed\n");
1961     sz = sizeof buffer;
1962     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1963     ok( r == ERROR_SUCCESS, "format failed\n");
1964     ok( sz == 9, "size wrong: %d\n", sz);
1965     ok( 0 == strcmp(buffer,"boo "), "wrong output: %s\n", buffer);
1966     ok(!lstrcmpA(&buffer[5], " hoo"),
1967        "Expected \" hoo\", got \"%s\"\n", &buffer[5]);
1968 
1969     r = MsiRecordSetStringA(hrec, 0, "[1] [~abc] [2]");
1970     ok( r == ERROR_SUCCESS, "set string failed\n");
1971     r = MsiRecordSetStringA(hrec, 1, "boo");
1972     ok( r == ERROR_SUCCESS, "set string failed\n");
1973     r = MsiRecordSetStringA(hrec, 2, "hoo");
1974     ok( r == ERROR_SUCCESS, "set string failed\n");
1975     sz = sizeof(buffer);
1976     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1977     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1978     ok(sz == 8, "Expected 8, got %d\n", sz);
1979     ok(!lstrcmpA(buffer, "boo  hoo"), "Expected \"boo  hoo\", got \"%s\"\n", buffer);
1980 
1981     /* properties */
1982     r = MsiSetPropertyA(package,"dummy","Bork");
1983     ok( r == ERROR_SUCCESS, "set property failed\n");
1984     r = MsiRecordSetStringA(hrec, 0, "[1] [dummy] [2]");
1985     ok( r == ERROR_SUCCESS, "set string failed\n");
1986     r = MsiRecordSetStringA(hrec, 1, "boo");
1987     ok( r == ERROR_SUCCESS, "set string failed\n");
1988     r = MsiRecordSetStringA(hrec, 2, "hoo");
1989     ok( r == ERROR_SUCCESS, "set string failed\n");
1990     sz = sizeof buffer;
1991     r = MsiFormatRecordA(package, hrec, buffer, &sz);
1992     ok( r == ERROR_SUCCESS, "format failed\n");
1993     ok( sz == 12, "size wrong\n");
1994     ok( 0 == strcmp(buffer,"boo Bork hoo"), "wrong output\n");
1995 
1996     r = MsiRecordSetStringA(hrec, 0, "[1] [invalid] [2]");
1997     ok( r == ERROR_SUCCESS, "set string failed\n");
1998     r = MsiRecordSetStringA(hrec, 1, "boo");
1999     ok( r == ERROR_SUCCESS, "set string failed\n");
2000     r = MsiRecordSetStringA(hrec, 2, "hoo");
2001     ok( r == ERROR_SUCCESS, "set string failed\n");
2002     sz = sizeof buffer;
2003     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2004     ok( r == ERROR_SUCCESS, "format failed\n");
2005     ok( sz == 8, "size wrong\n");
2006     ok( 0 == strcmp(buffer,"boo  hoo"), "wrong output\n");
2007 
2008     /* nesting tests */
2009     r = MsiSetPropertyA(package,"dummya","foo");
2010     ok( r == ERROR_SUCCESS, "set string failed\n");
2011     r = MsiSetPropertyA(package,"dummyb","baa");
2012     ok( r == ERROR_SUCCESS, "set string failed\n");
2013     r = MsiSetPropertyA(package,"adummyc","whoa");
2014     ok( r == ERROR_SUCCESS, "set property failed\n");
2015     r = MsiRecordSetStringA(hrec, 0, "[dummy[1]] [dummy[2]] [[1]dummy[3]]");
2016     ok( r == ERROR_SUCCESS, "set string failed\n");
2017     r = MsiRecordSetStringA(hrec, 1, "a");
2018     ok( r == ERROR_SUCCESS, "set string failed\n");
2019     r = MsiRecordSetStringA(hrec, 2, "b");
2020     ok( r == ERROR_SUCCESS, "set string failed\n");
2021     r = MsiRecordSetStringA(hrec, 3, "c");
2022     ok( r == ERROR_SUCCESS, "set string failed\n");
2023     sz = sizeof buffer;
2024     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2025     ok( r == ERROR_SUCCESS, "format failed\n");
2026     ok( sz == 12, "size wrong(%i)\n",sz);
2027     ok( 0 == strcmp(buffer,"foo baa whoa"), "wrong output (%s)\n",buffer);
2028 
2029     r = MsiSetPropertyA(package,"dummya","1");
2030     ok( r == ERROR_SUCCESS, "set property failed\n");
2031     r = MsiSetPropertyA(package,"dummyb","[2]");
2032     ok( r == ERROR_SUCCESS, "set property failed\n");
2033     r = MsiRecordSetStringA(hrec, 0, "[dummya] [[dummya]] [dummyb]");
2034     ok( r == ERROR_SUCCESS, "set string failed\n");
2035     r = MsiRecordSetStringA(hrec, 1, "aaa");
2036     ok( r == ERROR_SUCCESS, "set string failed\n");
2037     r = MsiRecordSetStringA(hrec, 2, "bbb");
2038     ok( r == ERROR_SUCCESS, "set string failed\n");
2039     r = MsiRecordSetStringA(hrec, 3, "ccc");
2040     ok( r == ERROR_SUCCESS, "set string failed\n");
2041     sz = sizeof buffer;
2042     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2043     ok( r == ERROR_SUCCESS, "format failed\n");
2044     todo_wine
2045     {
2046         ok( sz == 9, "size wrong(%i)\n",sz);
2047         ok( 0 == strcmp(buffer,"1 [1] [2]"), "wrong output (%s)\n",buffer);
2048     }
2049 
2050     r = MsiSetPropertyA(package,"dummya","1");
2051     ok( r == ERROR_SUCCESS, "set property failed\n");
2052     r = MsiSetPropertyA(package,"dummyb","a");
2053     ok( r == ERROR_SUCCESS, "set property failed\n");
2054     r = MsiSetPropertyA(package,"dummyc","\\blath");
2055     ok( r == ERROR_SUCCESS, "set property failed\n");
2056     r = MsiSetPropertyA(package,"dummyd","[\\blath]");
2057     ok( r == ERROR_SUCCESS, "set property failed\n");
2058     r = MsiRecordSetStringA(hrec, 0, "[dummyc] [[dummyc]] [dummy[dummyb]]");
2059     ok( r == ERROR_SUCCESS, "set string failed\n");
2060     r = MsiRecordSetStringA(hrec, 1, "aaa");
2061     ok( r == ERROR_SUCCESS, "set string failed\n");
2062     r = MsiRecordSetStringA(hrec, 2, "bbb");
2063     ok( r == ERROR_SUCCESS, "set string failed\n");
2064     r = MsiRecordSetStringA(hrec, 3, "ccc");
2065     ok( r == ERROR_SUCCESS, "set string failed\n");
2066     sz = sizeof buffer;
2067     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2068     ok( r == ERROR_SUCCESS, "format failed\n");
2069     ok( sz == 10, "size wrong(%i)\n",sz);
2070     ok( 0 == strcmp(buffer,"\\blath b 1"), "wrong output (%s)\n",buffer);
2071 
2072     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [[\\3asdf]]");
2073     ok( r == ERROR_SUCCESS, "set string failed\n");
2074     r = MsiRecordSetStringA(hrec, 1, "boo");
2075     ok( r == ERROR_SUCCESS, "set string failed\n");
2076     r = MsiRecordSetStringA(hrec, 2, "hoo");
2077     ok( r == ERROR_SUCCESS, "set string failed\n");
2078     r = MsiRecordSetStringA(hrec, 3, "yeah");
2079     ok( r == ERROR_SUCCESS, "set string failed\n");
2080     sz = sizeof buffer;
2081     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2082     ok( r == ERROR_SUCCESS, "format failed\n");
2083     todo_wine
2084     {
2085         ok( sz == 11, "size wrong(%i)\n",sz);
2086         ok( 0 == strcmp(buffer,"boo hoo [3]"), "wrong output (%s)\n",buffer);
2087     }
2088 
2089     r = MsiRecordSetStringA(hrec, 0, "[1] [2] [[3]]");
2090     ok( r == ERROR_SUCCESS, "set string failed\n");
2091     r = MsiRecordSetStringA(hrec, 1, "boo");
2092     ok( r == ERROR_SUCCESS, "set string failed\n");
2093     r = MsiRecordSetStringA(hrec, 2, "hoo");
2094     ok( r == ERROR_SUCCESS, "set string failed\n");
2095     r = MsiRecordSetStringA(hrec, 3, "\\help");
2096     ok( r == ERROR_SUCCESS, "set string failed\n");
2097     sz = sizeof buffer;
2098     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2099     ok( r == ERROR_SUCCESS, "format failed\n");
2100     ok( sz == 9, "size wrong(%i)\n",sz);
2101     ok( 0 == strcmp(buffer,"boo hoo h"), "wrong output (%s)\n",buffer);
2102 
2103     /* nested properties */
2104     MsiSetPropertyA(package, "PropA", "surprise");
2105     MsiSetPropertyA(package, "PropB", "[PropA]");
2106     MsiSetPropertyA(package, "PropC", "[PropB]");
2107     sz = sizeof buffer;
2108     MsiRecordSetStringA(hrec, 0, "[PropC]");
2109     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2110     ok( r == ERROR_SUCCESS, "format failed\n");
2111     ok( sz == 7, "size wrong(%i)\n",sz);
2112     ok( 0 == strcmp(buffer,"[PropB]"), "wrong output (%s)\n",buffer);
2113 
2114     MsiSetPropertyA(package, "PropA", "surprise");
2115     MsiSetPropertyA(package, "PropB", "PropA");
2116     MsiSetPropertyA(package, "PropC", "PropB");
2117     sz = sizeof buffer;
2118     MsiRecordSetStringA(hrec, 0, "[PropC]");
2119     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2120     ok( r == ERROR_SUCCESS, "format failed\n");
2121     ok( sz == 5, "size wrong(%i)\n",sz);
2122     ok( 0 == strcmp(buffer,"PropB"), "wrong output (%s)\n",buffer);
2123 
2124     MsiSetPropertyA(package, "PropA", "surprise");
2125     MsiSetPropertyA(package, "PropB", "[PropA]");
2126     MsiSetPropertyA(package, "PropC", "[PropB]");
2127     sz = sizeof buffer;
2128     MsiRecordSetStringA(hrec, 0, "[[PropC]]");
2129     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2130     ok( r == ERROR_SUCCESS, "format failed\n");
2131     ok( sz == 0, "size wrong(%i)\n",sz);
2132     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2133 
2134     MsiSetPropertyA(package, "PropA", "surprise");
2135     MsiSetPropertyA(package, "PropB", "[PropA]");
2136     MsiSetPropertyA(package, "PropC", "PropB");
2137     sz = sizeof buffer;
2138     MsiRecordSetStringA(hrec, 0, "[[PropC]]");
2139     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2140     ok( r == ERROR_SUCCESS, "format failed\n");
2141     ok( sz == 7, "size wrong(%i)\n",sz);
2142     ok( 0 == strcmp(buffer,"[PropA]"), "wrong output (%s)\n",buffer);
2143 
2144     MsiSetPropertyA(package, "PropA", "surprise");
2145     MsiSetPropertyA(package, "PropB", "PropA");
2146     MsiSetPropertyA(package, "PropC", "PropB");
2147     sz = sizeof buffer;
2148     MsiRecordSetStringA(hrec, 0, "[[PropC]]");
2149     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2150     ok( r == ERROR_SUCCESS, "format failed\n");
2151     ok( sz == 5, "size wrong(%i)\n",sz);
2152     ok( 0 == strcmp(buffer,"PropA"), "wrong output (%s)\n",buffer);
2153 
2154     MsiSetPropertyA(package, "PropA", "surprise");
2155     MsiSetPropertyA(package, "PropB", "PropA");
2156     MsiSetPropertyA(package, "PropC", "PropB");
2157     sz = sizeof buffer;
2158     MsiRecordSetStringA(hrec, 0, "[[[PropC]]]");
2159     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2160     ok( r == ERROR_SUCCESS, "format failed\n");
2161     ok( sz == 8, "size wrong(%i)\n",sz);
2162     ok( 0 == strcmp(buffer,"surprise"), "wrong output (%s)\n",buffer);
2163 
2164     /* properties inside braces */
2165     sz = sizeof buffer;
2166     MsiRecordSetStringA(hrec, 0, "{abcd}");
2167     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2168     ok( r == ERROR_SUCCESS, "format failed\n");
2169     ok( sz == 6, "size wrong(%i)\n",sz);
2170     ok( 0 == strcmp(buffer,"{abcd}"), "wrong output (%s)\n",buffer);
2171 
2172     MsiSetPropertyA(package, "one", "mercury");
2173     MsiSetPropertyA(package, "two", "venus");
2174     sz = sizeof buffer;
2175     MsiRecordSetStringA(hrec, 0, "{a[one]bc[two]de[one]f}");
2176     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2177     ok( r == ERROR_SUCCESS, "format failed: %d\n", r);
2178     ok( sz == 25, "size wrong(%i)\n",sz);
2179     ok( 0 == strcmp(buffer,"amercurybcvenusdemercuryf"), "wrong output (%s)\n",buffer);
2180 
2181     MsiSetPropertyA(package, "one", "mercury");
2182     MsiSetPropertyA(package, "two", "venus");
2183     MsiSetPropertyA(package, "bad", "");
2184     sz = sizeof buffer;
2185     MsiRecordSetStringA(hrec, 0, "{a[one]bc[bad]de[two]f}");
2186     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2187     ok( r == ERROR_SUCCESS, "format failed\n");
2188     ok( sz == 0, "size wrong(%i)\n",sz);
2189     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2190 
2191     MsiSetPropertyA(package, "bad", "");
2192     sz = sizeof buffer;
2193     MsiRecordSetStringA(hrec, 0, "{[bad]}");
2194     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2195     ok( r == ERROR_SUCCESS, "format failed\n");
2196     ok( sz == 0, "size wrong(%i)\n",sz);
2197     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2198 
2199     MsiSetPropertyA(package, "one", "mercury");
2200     sz = sizeof buffer;
2201     MsiRecordSetStringA(hrec, 0, "{abc{d[one]ef}"); /* missing final brace */
2202     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2203     ok( r == ERROR_SUCCESS, "format failed\n");
2204     todo_wine
2205     {
2206         ok( sz == 14, "size wrong(%i)\n",sz);
2207         ok( 0 == strcmp(buffer,"abc{dmercuryef"), "wrong output (%s)\n",buffer);
2208     }
2209 
2210     MsiSetPropertyA(package, "one", "mercury");
2211     sz = sizeof buffer;
2212     MsiRecordSetStringA(hrec, 0, "{abc{d[one]ef}}");
2213     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2214     ok( r == ERROR_SUCCESS, "format failed\n");
2215     todo_wine
2216     {
2217         ok( sz == 15, "size wrong(%i)\n",sz);
2218         ok( 0 == strcmp(buffer,"abc{dmercuryef}"), "wrong output (%s)\n",buffer);
2219     }
2220 
2221     MsiSetPropertyA(package, "one", "mercury");
2222     sz = sizeof buffer;
2223     MsiRecordSetStringA(hrec, 0, "{abc}{{def}hi{j[one]k}}");
2224     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2225     ok( r == ERROR_SUCCESS, "format failed\n");
2226     ok( sz == 5, "size wrong(%i)\n",sz);
2227     ok( 0 == strcmp(buffer,"{abc}"), "wrong output (%s)\n",buffer);
2228 
2229     MsiSetPropertyA(package, "one", "mercury");
2230 
2231     sz = sizeof buffer;
2232     MsiRecordSetStringA(hrec, 0, "{{def}hi{j[one]k}}");
2233     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2234     ok( r == ERROR_SUCCESS, "format failed\n");
2235     ok( sz == 0, "size wrong(%i)\n",sz);
2236     ok( 0 == strcmp(buffer,""), "wrong output (%s)\n",buffer);
2237 
2238     sz = sizeof(buffer);
2239     MsiRecordSetStringA(hrec, 0, "[1] {[noprop] [twoprop]} {abcdef}");
2240     MsiRecordSetStringA(hrec, 1, "one");
2241     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2242     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2243     ok(sz == 13, "Expected 13, got %d\n",sz);
2244     ok(!lstrcmpA(buffer, "one  {abcdef}"),
2245        "Expected \"one  {abcdef}\", got \"%s\"\n", buffer);
2246 
2247     sz = sizeof(buffer);
2248     MsiRecordSetStringA(hrec, 0, "[1] {[noprop] [one]} {abcdef}");
2249     MsiRecordSetStringA(hrec, 1, "one");
2250     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2251     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2252     ok(sz == 13, "Expected 13, got %d\n",sz);
2253     ok(!lstrcmpA(buffer, "one  {abcdef}"),
2254        "Expected \"one  {abcdef}\", got \"%s\"\n", buffer);
2255 
2256     sz = sizeof(buffer);
2257     MsiRecordSetStringA(hrec, 0, "[1] {[one]} {abcdef}");
2258     MsiRecordSetStringA(hrec, 1, "one");
2259     r = MsiFormatRecordA(package, hrec, buffer, &sz);
2260     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2261     ok(sz == 20, "Expected 20, got %d\n",sz);
2262     ok(!lstrcmpA(buffer, "one mercury {abcdef}"),
2263        "Expected \"one mercury {abcdef}\", got \"%s\"\n", buffer);
2264 
2265     MsiCloseHandle(hrec);
2266 
2267     r = MsiCloseHandle(package);
2268     ok(r==ERROR_SUCCESS, "Unable to close package\n");
2269 
2270     DeleteFileA( msifile );
2271 }
2272 
2273 static void test_processmessage(void)
2274 {
2275     MSIHANDLE hrec, package;
2276     UINT r;
2277 
2278     MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
2279 
2280     r = helper_createpackage( msifile, &package );
2281     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
2282     {
2283         skip("Not enough rights to perform tests\n");
2284         return;
2285     }
2286     ok( r == ERROR_SUCCESS, "Unable to create package %u\n", r );
2287 
2288     hrec = MsiCreateRecord(3);
2289     ok( hrec, "failed to create record\n");
2290 
2291     r = MsiRecordSetStringA(hrec, 1, "");
2292     ok( r == ERROR_SUCCESS, "set string failed\n");
2293 
2294     r = MsiProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, hrec);
2295     ok( r == IDOK, "expected IDOK, got %i\n", r);
2296 
2297     r = MsiProcessMessage(package, INSTALLMESSAGE_PROGRESS, hrec);
2298     ok( r == IDOK, "expected IDOK, got %i\n", r);
2299 
2300     r = MsiProcessMessage(package, INSTALLMESSAGE_INFO, hrec);
2301     ok( r == 0, "expected 0, got %i\n", r);
2302 
2303     r = MsiProcessMessage(package, INSTALLMESSAGE_INITIALIZE, hrec);
2304     ok( r == -1, "expected -1, got %i\n", r);
2305 
2306     r = MsiRecordSetInteger(hrec, 1, 2);
2307     ok( r == ERROR_SUCCESS, "set integer failed\n");
2308     r = MsiRecordSetInteger(hrec, 2, 1);
2309     ok( r == ERROR_SUCCESS, "set integer failed\n");
2310     r = MsiProcessMessage(package, INSTALLMESSAGE_COMMONDATA, hrec);
2311     todo_wine
2312     ok( r == IDOK, "expected IDOK, got %i\n", r);
2313 
2314     r = MsiRecordSetInteger(hrec, 2, 2);
2315     ok( r == ERROR_SUCCESS, "set integer failed\n");
2316     r = MsiProcessMessage(package, INSTALLMESSAGE_COMMONDATA, hrec);
2317     todo_wine
2318     ok( r == IDOK, "expected IDOK, got %i\n", r);
2319 
2320     r = MsiRecordSetInteger(hrec, 1, 1);
2321     ok( r == ERROR_SUCCESS, "set integer failed\n");
2322     r = MsiProcessMessage(package, INSTALLMESSAGE_COMMONDATA, hrec);
2323     ok( r == -1, "expected -1, got %i\n", r);
2324 
2325     MsiCloseHandle(package);
2326 
2327     MsiSetInternalUI(INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY, NULL);
2328     helper_createpackage(msifile, &package);
2329 
2330     r = MsiProcessMessage(package, INSTALLMESSAGE_ERROR, hrec);
2331     ok( r == 0, "expected 0, got %i\n", r);
2332 
2333     MsiCloseHandle(hrec);
2334     MsiCloseHandle(package);
2335 
2336     DeleteFileA(msifile);
2337 }
2338 
2339 START_TEST(format)
2340 {
2341     test_createpackage();
2342     test_formatrecord();
2343     test_formatrecord_package();
2344     test_processmessage();
2345 }
2346