2 * Copyright (C) 2005 Mike McCormack for CodeWeavers
3 * Copyright (C) 2005 Aric Stewart for CodeWeavers
5 * A test program for MSI record formatting
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/test.h"
29 static MSIHANDLE
helper_createpackage( const char *szName
)
39 /* create an empty database */
40 res
= MsiOpenDatabase(szName
, MSIDBOPEN_CREATE
, &hdb
);
41 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
43 res
= MsiDatabaseCommit( hdb
);
44 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
46 /* build summmary info */
47 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
48 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
50 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
51 "Installation Database");
52 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
54 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
55 "Installation Database");
56 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
58 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
60 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
62 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
64 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
66 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
67 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
68 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
70 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
71 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
73 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
74 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
76 res
= MsiSummaryInfoPersist(suminfo
);
77 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
79 res
= MsiCloseHandle( suminfo
);
80 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
82 sprintf(szPackage
,"#%li",(DWORD
)hdb
);
83 res
= MsiOpenPackage(szPackage
,&hPackage
);
84 ok( res
== ERROR_SUCCESS
, "Failed to open package\n" );
86 res
= MsiCloseHandle( hdb
);
87 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
92 static void test_createpackage(void)
94 static const CHAR filename
[] = "winetest.msi";
95 MSIHANDLE hPackage
= 0;
98 hPackage
= helper_createpackage( filename
);
99 ok ( hPackage
!= 0, " Failed to create package\n");
101 res
= MsiCloseHandle( hPackage
);
102 ok( res
== ERROR_SUCCESS
, "Failed to close package\n" );
104 DeleteFile( filename
);
107 static void test_formatrecord(void)
114 r
= MsiFormatRecord(0, 0, NULL
, NULL
);
115 ok( r
== ERROR_INVALID_HANDLE
, "wrong error\n");
117 hrec
= MsiCreateRecord(4);
118 ok( hrec
, "failed to create record\n");
120 /* format an empty record */
121 r
= MsiFormatRecord(0, hrec
, NULL
, NULL
);
122 ok( r
== ERROR_SUCCESS
, "format failed\n");
125 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
126 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer\n");
127 ok( sz
== 16, "size wrong\n");
128 ok( 0 == strcmp(buffer
,"1: 2: 3: 4: "), "wrong output\n");
130 r
= MsiCloseHandle(hrec
);
131 ok(r
==ERROR_SUCCESS
, "Unable to close record\n");
133 hrec
= MsiCreateRecord(6);
134 ok( hrec
, "failed to create record\n");
139 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
140 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer\n");
141 ok( sz
== 24, "size wrong\n");
142 ok( 0 == strcmp(buffer
,"1: 2: 3: 4: 5: 6: "), "wrong output\n");
145 /* format a format string with everything else empty */
146 r
= MsiRecordSetString(hrec
, 0, "%1");
147 ok( r
== ERROR_SUCCESS
, "set string failed\n");
148 r
= MsiFormatRecord(0, hrec
, NULL
, NULL
);
149 ok( r
== ERROR_SUCCESS
, "format failed\n");
150 r
= MsiFormatRecord(0, hrec
, buffer
, NULL
);
151 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error\n");
154 r
= MsiFormatRecord(0, hrec
, NULL
, &sz
);
155 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer\n");
156 ok( sz
== 2, "size wrong (%li)\n",sz
);
160 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
161 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer\n");
162 ok( sz
== 2, "size wrong\n");
163 ok( 0 == strcmp(buffer
,"%1"), "wrong output\n");
165 /* make the buffer too small */
169 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
170 ok( r
== ERROR_MORE_DATA
, "format failed with empty buffer\n");
171 ok( sz
== 2, "size wrong\n");
172 ok( 0 == strcmp(buffer
,"x"), "wrong output\n");
174 /* make the buffer a little bit bigger */
178 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
179 ok( r
== ERROR_MORE_DATA
, "format failed with empty buffer\n");
180 ok( sz
== 2, "size wrong\n");
181 ok( 0 == strcmp(buffer
,""), "wrong output (%s)\n",buffer
);
187 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
188 ok( r
== ERROR_MORE_DATA
, "format failed with empty buffer\n");
189 ok( sz
== 2, "size wrong\n");
190 ok( 0 == strcmp(buffer
,"%"), "wrong output\n");
196 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
197 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer\n");
198 ok( sz
== 2, "size wrong\n");
199 ok( 0 == strcmp(buffer
,"%1"), "wrong output\n");
201 /* now try a real format string */
202 r
= MsiRecordSetString(hrec
, 0, "[1]");
203 ok( r
== ERROR_SUCCESS
, "set string failed\n");
205 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
206 ok( r
== ERROR_SUCCESS
, "format failed\n");
207 ok( sz
== 0, "size wrong\n");
208 ok( 0 == strcmp(buffer
,""), "wrong output\n");
210 /* now put something in the first field */
211 r
= MsiRecordSetString(hrec
, 1, "boo hoo");
212 ok( r
== ERROR_SUCCESS
, "set string failed\n");
214 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
215 ok( r
== ERROR_SUCCESS
, "format failed\n");
216 ok( sz
== 7, "size wrong\n");
217 ok( 0 == strcmp(buffer
,"boo hoo"), "wrong output\n");
219 /* now put something in the first field */
220 r
= MsiRecordSetString(hrec
, 0, "[1] [2]");
221 r
= MsiRecordSetString(hrec
, 1, "boo");
222 r
= MsiRecordSetString(hrec
, 2, "hoo");
223 ok( r
== ERROR_SUCCESS
, "set string failed\n");
225 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
226 ok( r
== ERROR_SUCCESS
, "format failed\n");
227 ok( sz
== 7, "size wrong\n");
228 ok( 0 == strcmp(buffer
,"boo hoo"), "wrong output\n");
232 r
= MsiRecordSetString(hrec
, 0, "");
234 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
235 ok( r
== ERROR_SUCCESS
, "format failed\n");
236 ok( sz
== 30, "size wrong %li\n",sz
);
237 ok( 0 == strcmp(buffer
,"1: boo 2: hoo 3: 4: 5: 6: "),
238 "wrong output(%s)\n",buffer
);
240 /* play games with recursive lookups */
241 r
= MsiRecordSetString(hrec
, 0, "[[1]] [2]");
242 r
= MsiRecordSetString(hrec
, 1, "2");
243 r
= MsiRecordSetString(hrec
, 2, "hey");
244 ok( r
== ERROR_SUCCESS
, "set string failed\n");
246 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
247 ok( r
== ERROR_SUCCESS
, "format failed\n");
248 ok( sz
== 7, "size wrong,(%li)\n",sz
);
249 ok( 0 == strcmp(buffer
,"hey hey"), "wrong output (%s)\n",buffer
);
251 r
= MsiRecordSetString(hrec
, 0, "[[1]] [2]");
252 r
= MsiRecordSetString(hrec
, 1, "[2]");
253 r
= MsiRecordSetString(hrec
, 2, "hey");
254 ok( r
== ERROR_SUCCESS
, "set string failed\n");
256 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
257 ok( r
== ERROR_SUCCESS
, "format failed\n");
258 ok( sz
== 9, "size wrong,(%li)\n",sz
);
259 ok( 0 == strcmp(buffer
,"[[2]] hey"), "wrong output (%s)\n",buffer
);
261 r
= MsiRecordSetString(hrec
, 0, "[[[3]]] [2]");
262 r
= MsiRecordSetString(hrec
, 1, "2");
263 r
= MsiRecordSetString(hrec
, 2, "hey");
264 r
= MsiRecordSetString(hrec
, 3, "1");
265 ok( r
== ERROR_SUCCESS
, "set string failed\n");
267 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
268 ok( r
== ERROR_SUCCESS
, "format failed\n");
269 ok( sz
== 7, "size wrong,(%li)\n",sz
);
270 ok( 0 == strcmp(buffer
,"hey hey"), "wrong output (%s)\n",buffer
);
272 r
= MsiCloseHandle(hrec
);
273 ok(r
==ERROR_SUCCESS
, "Unable to close record\n");
274 hrec
= MsiCreateRecord(12);
275 ok( hrec
, "failed to create record\n");
277 r
= MsiRecordSetString(hrec
, 0, "[[3][1]] [2]");
278 r
= MsiRecordSetString(hrec
, 1, "2");
279 r
= MsiRecordSetString(hrec
, 2, "hey");
280 r
= MsiRecordSetString(hrec
, 3, "1");
281 r
= MsiRecordSetString(hrec
, 12, "big");
282 ok( r
== ERROR_SUCCESS
, "set string failed\n");
284 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
285 ok( r
== ERROR_SUCCESS
, "format failed\n");
286 ok( sz
== 7, "size wrong,(%li)\n",sz
);
287 ok( 0 == strcmp(buffer
,"big hey"), "wrong output (%s)\n",buffer
);
289 r
= MsiRecordSetString(hrec
, 0, "[[3][4][1]] [2]");
290 r
= MsiRecordSetString(hrec
, 1, "2");
291 r
= MsiRecordSetString(hrec
, 2, "hey");
292 r
= MsiRecordSetString(hrec
, 3, "1");
293 r
= MsiRecordSetString(hrec
, 4, NULL
);
294 r
= MsiRecordSetString(hrec
, 12, "big");
295 ok( r
== ERROR_SUCCESS
, "set string failed\n");
297 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
298 ok( r
== ERROR_SUCCESS
, "format failed\n");
299 ok( sz
== 7, "size wrong,(%li)\n",sz
);
300 ok( 0 == strcmp(buffer
,"big hey"), "wrong output (%s)\n",buffer
);
302 r
= MsiRecordSetString(hrec
, 0, "[[3][[4]][1]] [2]");
303 r
= MsiRecordSetString(hrec
, 1, "2");
304 r
= MsiRecordSetString(hrec
, 2, "hey");
305 r
= MsiRecordSetString(hrec
, 3, "1");
306 r
= MsiRecordSetString(hrec
, 4, NULL
);
307 r
= MsiRecordSetString(hrec
, 12, "big");
308 ok( r
== ERROR_SUCCESS
, "set string failed\n");
310 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
311 ok( r
== ERROR_SUCCESS
, "format failed\n");
312 ok( sz
== 10, "size wrong,(%li)\n",sz
);
313 ok( 0 == strcmp(buffer
,"[1[]2] hey"), "wrong output (%s)\n",buffer
);
315 /* incorrect formats */
316 r
= MsiRecordSetString(hrec
, 0, "[[[3][[4]][1]] [2]");
317 r
= MsiRecordSetString(hrec
, 1, "2");
318 r
= MsiRecordSetString(hrec
, 2, "hey");
319 r
= MsiRecordSetString(hrec
, 3, "1");
320 r
= MsiRecordSetString(hrec
, 4, NULL
);
321 r
= MsiRecordSetString(hrec
, 12, "big");
322 ok( r
== ERROR_SUCCESS
, "set string failed\n");
324 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
325 ok( r
== ERROR_SUCCESS
, "format failed\n");
326 ok( sz
== 18, "size wrong,(%li)\n",sz
);
327 ok( 0 == strcmp(buffer
,"[[[3][[4]][1]] [2]"), "wrong output (%s)\n",buffer
);
329 r
= MsiRecordSetString(hrec
, 0, "[[3][[4]][1]] [2]]");
330 r
= MsiRecordSetString(hrec
, 1, "2");
331 r
= MsiRecordSetString(hrec
, 2, "hey");
332 r
= MsiRecordSetString(hrec
, 3, "1");
333 r
= MsiRecordSetString(hrec
, 4, NULL
);
334 r
= MsiRecordSetString(hrec
, 12, "big");
335 ok( r
== ERROR_SUCCESS
, "set string failed\n");
337 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
338 ok( r
== ERROR_SUCCESS
, "format failed\n");
339 ok( sz
== 11, "size wrong,(%li)\n",sz
);
340 ok( 0 == strcmp(buffer
,"[1[]2] hey]"), "wrong output (%s)\n",buffer
);
343 /* play games with {} */
345 r
= MsiRecordSetString(hrec
, 0, "{[3][1]} [2]");
346 r
= MsiRecordSetString(hrec
, 1, "2");
347 r
= MsiRecordSetString(hrec
, 2, "hey");
348 r
= MsiRecordSetString(hrec
, 3, "1");
349 r
= MsiRecordSetString(hrec
, 4, NULL
);
350 r
= MsiRecordSetString(hrec
, 12, "big");
351 ok( r
== ERROR_SUCCESS
, "set string failed\n");
353 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
354 ok( r
== ERROR_SUCCESS
, "format failed\n");
355 ok( sz
== 6, "size wrong,(%li)\n",sz
);
356 ok( 0 == strcmp(buffer
,"12 hey"), "wrong output (%s)\n",buffer
);
358 r
= MsiRecordSetString(hrec
, 0, "[{[3][1]}] [2]");
359 r
= MsiRecordSetString(hrec
, 1, "2");
360 r
= MsiRecordSetString(hrec
, 2, "hey");
361 r
= MsiRecordSetString(hrec
, 3, "1");
362 r
= MsiRecordSetString(hrec
, 4, NULL
);
363 r
= MsiRecordSetString(hrec
, 12, "big");
364 ok( r
== ERROR_SUCCESS
, "set string failed\n");
366 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
367 ok( r
== ERROR_SUCCESS
, "format failed\n");
368 ok( sz
== 8, "size wrong,(%li)\n",sz
);
369 ok( 0 == strcmp(buffer
,"[12] hey"), "wrong output (%s)\n",buffer
);
372 r
= MsiRecordSetString(hrec
, 0, "{test} [2]");
373 r
= MsiRecordSetString(hrec
, 1, "2");
374 r
= MsiRecordSetString(hrec
, 2, "hey");
375 r
= MsiRecordSetString(hrec
, 3, "1");
376 r
= MsiRecordSetString(hrec
, 4, NULL
);
377 r
= MsiRecordSetString(hrec
, 12, "big");
378 ok( r
== ERROR_SUCCESS
, "set string failed\n");
380 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
381 ok( r
== ERROR_SUCCESS
, "format failed\n");
382 ok( sz
== 10, "size wrong,(%li)\n",sz
);
383 ok( 0 == strcmp(buffer
,"{test} hey"), "wrong output (%s)\n",buffer
);
385 r
= MsiRecordSetString(hrec
, 0, "{[test]} [2]");
386 r
= MsiRecordSetString(hrec
, 1, "2");
387 r
= MsiRecordSetString(hrec
, 2, "hey");
388 r
= MsiRecordSetString(hrec
, 3, "1");
389 r
= MsiRecordSetString(hrec
, 4, NULL
);
390 r
= MsiRecordSetString(hrec
, 12, "big");
391 ok( r
== ERROR_SUCCESS
, "set string failed\n");
393 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
394 ok( r
== ERROR_SUCCESS
, "format failed\n");
395 ok( sz
== 12, "size wrong,(%li)\n",sz
);
396 ok( 0 == strcmp(buffer
,"{[test]} hey"), "wrong output (%s)\n",buffer
);
398 r
= MsiRecordSetString(hrec
, 0, "{[1][2][3][4]} [2]");
399 r
= MsiRecordSetString(hrec
, 1, "2");
400 r
= MsiRecordSetString(hrec
, 2, "hey");
401 r
= MsiRecordSetString(hrec
, 3, "1");
402 r
= MsiRecordSetString(hrec
, 4, NULL
);
403 r
= MsiRecordSetString(hrec
, 12, "big");
404 ok( r
== ERROR_SUCCESS
, "set string failed\n");
406 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
407 ok( r
== ERROR_SUCCESS
, "format failed\n");
408 ok( sz
== 4, "size wrong,(%li)\n",sz
);
409 ok( 0 == strcmp(buffer
," hey"), "wrong output (%s)\n",buffer
);
411 r
= MsiRecordSetString(hrec
, 0, "{[1][2][3][dummy]} [2]");
412 r
= MsiRecordSetString(hrec
, 1, "2");
413 r
= MsiRecordSetString(hrec
, 2, "hey");
414 r
= MsiRecordSetString(hrec
, 3, "1");
415 r
= MsiRecordSetString(hrec
, 4, NULL
);
416 r
= MsiRecordSetString(hrec
, 12, "big");
417 ok( r
== ERROR_SUCCESS
, "set string failed\n");
419 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
420 ok( r
== ERROR_SUCCESS
, "format failed\n");
421 ok( sz
== 18, "size wrong,(%li)\n",sz
);
422 ok( 0 == strcmp(buffer
,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer
);
424 r
= MsiRecordSetString(hrec
, 0, "{[1][2][3][4][dummy]} [2]");
425 r
= MsiRecordSetString(hrec
, 1, "2");
426 r
= MsiRecordSetString(hrec
, 2, "hey");
427 r
= MsiRecordSetString(hrec
, 3, "1");
428 r
= MsiRecordSetString(hrec
, 4, NULL
);
429 r
= MsiRecordSetString(hrec
, 12, "big");
430 ok( r
== ERROR_SUCCESS
, "set string failed\n");
432 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
433 ok( r
== ERROR_SUCCESS
, "format failed\n");
434 ok( sz
== 18, "size wrong,(%li)\n",sz
);
435 ok( 0 == strcmp(buffer
,"{2hey1[dummy]} hey"), "wrong output (%s)\n",buffer
);
437 r
= MsiRecordSetString(hrec
, 0, "{{[1][2]}[3][4][dummy]}");
438 r
= MsiRecordSetString(hrec
, 1, "2");
439 r
= MsiRecordSetString(hrec
, 2, "hey");
440 r
= MsiRecordSetString(hrec
, 3, "1");
441 r
= MsiRecordSetString(hrec
, 4, NULL
);
442 r
= MsiRecordSetString(hrec
, 12, "big");
443 ok( r
== ERROR_SUCCESS
, "set string failed\n");
445 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
446 ok( r
== ERROR_SUCCESS
, "format failed\n");
449 ok( sz
== 16, "size wrong,(%li)\n",sz
);
450 ok( 0 == strcmp(buffer
,"{{2hey}1[dummy]}"), "wrong output (%s)\n",buffer
);
453 r
= MsiRecordSetString(hrec
, 0, "{{[1][2]}[3]{[4][dummy]}}");
454 r
= MsiRecordSetString(hrec
, 1, "2");
455 r
= MsiRecordSetString(hrec
, 2, "hey");
456 r
= MsiRecordSetString(hrec
, 3, "1");
457 r
= MsiRecordSetString(hrec
, 4, NULL
);
458 r
= MsiRecordSetString(hrec
, 12, "big");
459 ok( r
== ERROR_SUCCESS
, "set string failed\n");
461 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
462 ok( r
== ERROR_SUCCESS
, "format failed\n");
464 ok( sz
== 0, "size wrong,(%li)\n",sz
);
465 ok( 0 == strcmp(buffer
,""), "wrong output (%s)\n",buffer
);
468 r
= MsiRecordSetString(hrec
, 0, "{{[1][2]}[3]} {[1][2]}");
469 r
= MsiRecordSetString(hrec
, 1, "1");
470 r
= MsiRecordSetString(hrec
, 2, "2");
471 r
= MsiRecordSetString(hrec
, 3, "3");
472 r
= MsiRecordSetString(hrec
, 4, NULL
);
473 r
= MsiRecordSetString(hrec
, 12, "big");
474 ok( r
== ERROR_SUCCESS
, "set string failed\n");
476 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
477 ok( r
== ERROR_SUCCESS
, "format failed\n");
479 ok( sz
== 12, "size wrong,(%li)\n",sz
);
480 ok( 0 == strcmp(buffer
,"{{12}3} {12}"), "wrong output (%s)\n",buffer
);
483 r
= MsiRecordSetString(hrec
, 0, "{[1][2]} {{[1][2]}[3]} {[1][2]}");
484 r
= MsiRecordSetString(hrec
, 1, "1");
485 r
= MsiRecordSetString(hrec
, 2, "2");
486 r
= MsiRecordSetString(hrec
, 3, "3");
487 r
= MsiRecordSetString(hrec
, 4, NULL
);
488 r
= MsiRecordSetString(hrec
, 12, "big");
489 ok( r
== ERROR_SUCCESS
, "set string failed\n");
491 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
492 ok( r
== ERROR_SUCCESS
, "format failed\n");
494 ok( sz
== 15, "size wrong,(%li)\n",sz
);
495 ok( 0 == strcmp(buffer
,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer
);
498 r
= MsiRecordSetString(hrec
, 0, "{[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
499 r
= MsiRecordSetString(hrec
, 1, "1");
500 r
= MsiRecordSetString(hrec
, 2, "2");
501 r
= MsiRecordSetString(hrec
, 3, "3");
502 r
= MsiRecordSetString(hrec
, 4, NULL
);
503 r
= MsiRecordSetString(hrec
, 12, "big");
504 ok( r
== ERROR_SUCCESS
, "set string failed\n");
506 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
507 ok( r
== ERROR_SUCCESS
, "format failed\n");
509 ok( sz
== 15, "size wrong,(%li)\n",sz
);
510 ok( 0 == strcmp(buffer
,"12 {{12}3} {12}"), "wrong output (%s)\n",buffer
);
514 r
= MsiRecordSetString(hrec
, 0, "{blah} {[4]}{[1][2]} {{[1][2]}[3]} {[1][2]}");
515 r
= MsiRecordSetString(hrec
, 1, "1");
516 r
= MsiRecordSetString(hrec
, 2, "2");
517 r
= MsiRecordSetString(hrec
, 3, "3");
518 r
= MsiRecordSetString(hrec
, 4, NULL
);
519 r
= MsiRecordSetString(hrec
, 12, "big");
520 ok( r
== ERROR_SUCCESS
, "set string failed\n");
522 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
523 ok( r
== ERROR_SUCCESS
, "format failed\n");
525 ok( sz
== 22, "size wrong,(%li)\n",sz
);
526 ok( 0 == strcmp(buffer
,"{blah} 12 {{12}3} {12}"), "wrong output (%s)\n",buffer
);
529 r
= MsiRecordSetString(hrec
, 0, "{{[1]}[2]} {[4]}{[1][2]}");
530 r
= MsiRecordSetString(hrec
, 1, "1");
531 r
= MsiRecordSetString(hrec
, 2, "2");
532 r
= MsiRecordSetString(hrec
, 3, "3");
533 r
= MsiRecordSetString(hrec
, 4, NULL
);
534 r
= MsiRecordSetString(hrec
, 12, "big");
535 ok( r
== ERROR_SUCCESS
, "set string failed\n");
537 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
538 ok( r
== ERROR_SUCCESS
, "format failed\n");
540 ok( sz
== 13, "size wrong,(%li)\n",sz
);
541 ok( 0 == strcmp(buffer
,"{{1}2} {}{12}"), "wrong output (%s)\n",buffer
);
544 r
= MsiRecordSetString(hrec
, 0, "{{[1]}} {[4]}{[1][2]}");
545 r
= MsiRecordSetString(hrec
, 1, "1");
546 r
= MsiRecordSetString(hrec
, 2, "2");
547 r
= MsiRecordSetString(hrec
, 3, "3");
548 r
= MsiRecordSetString(hrec
, 4, NULL
);
549 r
= MsiRecordSetString(hrec
, 12, "big");
550 ok( r
== ERROR_SUCCESS
, "set string failed\n");
552 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
553 ok( r
== ERROR_SUCCESS
, "format failed\n");
555 ok( sz
== 3, "size wrong,(%li)\n",sz
);
556 ok( 0 == strcmp(buffer
," 12"), "wrong output (%s)\n",buffer
);
559 r
= MsiRecordSetString(hrec
, 0, "{{{[1]}} {[4]}{[1][2]}");
560 r
= MsiRecordSetString(hrec
, 1, "1");
561 r
= MsiRecordSetString(hrec
, 2, "2");
562 r
= MsiRecordSetString(hrec
, 3, "3");
563 r
= MsiRecordSetString(hrec
, 4, NULL
);
564 r
= MsiRecordSetString(hrec
, 12, "big");
565 ok( r
== ERROR_SUCCESS
, "set string failed\n");
567 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
568 ok( r
== ERROR_SUCCESS
, "format failed\n");
570 ok( sz
== 3, "size wrong,(%li)\n",sz
);
571 ok( 0 == strcmp(buffer
," 12"), "wrong output (%s)\n",buffer
);
574 /* now put play games with escaping */
575 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [\\3asdf]");
576 r
= MsiRecordSetString(hrec
, 1, "boo");
577 r
= MsiRecordSetString(hrec
, 2, "hoo");
578 ok( r
== ERROR_SUCCESS
, "set string failed\n");
580 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
581 ok( r
== ERROR_SUCCESS
, "format failed\n");
582 ok( sz
== 16, "size wrong\n");
583 ok( 0 == strcmp(buffer
,"boo hoo [\\3asdf]"), "wrong output\n");
585 /* now put play games with escaping */
586 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [\\x]");
587 r
= MsiRecordSetString(hrec
, 1, "boo");
588 r
= MsiRecordSetString(hrec
, 2, "hoo");
589 ok( r
== ERROR_SUCCESS
, "set string failed\n");
591 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
592 ok( r
== ERROR_SUCCESS
, "format failed\n");
593 ok( sz
== 12, "size wrong\n");
594 ok( 0 == strcmp(buffer
,"boo hoo [\\x]"), "wrong output\n");
596 /* now try other formats without a package */
597 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [property]");
598 r
= MsiRecordSetString(hrec
, 1, "boo");
599 r
= MsiRecordSetString(hrec
, 2, "hoo");
600 ok( r
== ERROR_SUCCESS
, "set string failed\n");
602 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
603 ok( r
== ERROR_SUCCESS
, "format failed\n");
604 ok( sz
== 18, "size wrong\n");
605 ok( 0 == strcmp(buffer
,"boo hoo [property]"), "wrong output\n");
607 r
= MsiRecordSetString(hrec
, 0, "[1] [~] [2]");
608 r
= MsiRecordSetString(hrec
, 1, "boo");
609 r
= MsiRecordSetString(hrec
, 2, "hoo");
610 ok( r
== ERROR_SUCCESS
, "set string failed\n");
612 r
= MsiFormatRecord(0, hrec
, buffer
, &sz
);
613 ok( r
== ERROR_SUCCESS
, "format failed\n");
614 ok( sz
== 11, "size wrong\n");
615 ok( 0 == strcmp(buffer
,"boo [~] hoo"), "wrong output (%s)\n",buffer
);
616 MsiCloseHandle(hrec
);
619 static void test_formatrecord_package(void)
621 static const CHAR filename
[] = "winetest.msi";
628 package
= helper_createpackage( filename
);
629 ok(package
!=0, "Unable to create package\n");
631 hrec
= MsiCreateRecord(12);
632 ok( hrec
, "failed to create record\n");
634 r
= MsiFormatRecord(package
, 0, NULL
, NULL
);
635 ok( r
== ERROR_INVALID_HANDLE
, "wrong error\n");
637 r
= MsiFormatRecord(package
, hrec
, NULL
, NULL
);
638 ok( r
== ERROR_SUCCESS
, "format failed\n");
640 r
= MsiRecordSetString(hrec
,0,NULL
);
641 r
= MsiRecordSetString(hrec
,1,NULL
);
642 r
= MsiRecordSetString(hrec
,2,NULL
);
643 r
= MsiRecordSetString(hrec
,3,NULL
);
644 r
= MsiRecordSetString(hrec
,4,NULL
);
645 r
= MsiRecordSetString(hrec
,5,NULL
);
646 r
= MsiRecordSetString(hrec
,6,NULL
);
647 r
= MsiRecordSetString(hrec
,7,NULL
);
648 r
= MsiRecordSetString(hrec
,8,NULL
);
649 r
= MsiRecordSetString(hrec
,9,NULL
);
650 r
= MsiRecordSetString(hrec
,10,NULL
);
651 r
= MsiRecordSetString(hrec
,11,NULL
);
652 r
= MsiRecordSetString(hrec
,12,NULL
);
653 ok( r
== ERROR_SUCCESS
, "set string failed\n");
656 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
657 ok( r
== ERROR_SUCCESS
, "format failed with empty buffer (%i)\n",r
);
658 ok( sz
== 51, "size wrong (%li)\n",sz
);
659 ok( 0 == strcmp(buffer
,"1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: "), "wrong output(%s)\n",buffer
);
661 /* now put play games with escaping */
662 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [\\3asdf]");
663 r
= MsiRecordSetString(hrec
, 1, "boo");
664 r
= MsiRecordSetString(hrec
, 2, "hoo");
665 ok( r
== ERROR_SUCCESS
, "set string failed\n");
667 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
668 ok( r
== ERROR_SUCCESS
, "format failed\n");
669 ok( sz
== 9, "size wrong(%li)\n",sz
);
670 ok( 0 == strcmp(buffer
,"boo hoo 3"), "wrong output (%s)\n",buffer
);
672 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [\\x]");
673 r
= MsiRecordSetString(hrec
, 1, "boo");
674 r
= MsiRecordSetString(hrec
, 2, "hoo");
675 ok( r
== ERROR_SUCCESS
, "set string failed\n");
677 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
678 ok( r
== ERROR_SUCCESS
, "format failed\n");
679 ok( sz
== 9, "size wrong(%li)\n",sz
);
680 ok( 0 == strcmp(buffer
,"boo hoo x"), "wrong output (%s)\n",buffer
);
682 /* null characters */
683 r
= MsiRecordSetString(hrec
, 0, "[1] [~] [2]");
684 r
= MsiRecordSetString(hrec
, 1, "boo");
685 r
= MsiRecordSetString(hrec
, 2, "hoo");
686 ok( r
== ERROR_SUCCESS
, "set string failed\n");
688 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
689 ok( r
== ERROR_SUCCESS
, "format failed\n");
690 ok( sz
== 9, "size wrong\n");
691 ok( 0 == strcmp(buffer
,"boo "), "wrong output\n");
694 r
= MsiSetProperty(package
,"dummy","Bork");
695 ok( r
== ERROR_SUCCESS
, "set property failed\n");
696 r
= MsiRecordSetString(hrec
, 0, "[1] [dummy] [2]");
697 r
= MsiRecordSetString(hrec
, 1, "boo");
698 r
= MsiRecordSetString(hrec
, 2, "hoo");
699 ok( r
== ERROR_SUCCESS
, "set string failed\n");
701 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
702 ok( r
== ERROR_SUCCESS
, "format failed\n");
703 ok( sz
== 12, "size wrong\n");
704 ok( 0 == strcmp(buffer
,"boo Bork hoo"), "wrong output\n");
706 r
= MsiRecordSetString(hrec
, 0, "[1] [invalid] [2]");
707 r
= MsiRecordSetString(hrec
, 1, "boo");
708 r
= MsiRecordSetString(hrec
, 2, "hoo");
709 ok( r
== ERROR_SUCCESS
, "set string failed\n");
711 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
712 ok( r
== ERROR_SUCCESS
, "format failed\n");
713 ok( sz
== 8, "size wrong\n");
714 ok( 0 == strcmp(buffer
,"boo hoo"), "wrong output\n");
718 r
= MsiSetProperty(package
,"dummya","foo");
719 r
= MsiSetProperty(package
,"dummyb","baa");
720 r
= MsiSetProperty(package
,"adummyc","whoa");
721 ok( r
== ERROR_SUCCESS
, "set property failed\n");
722 r
= MsiRecordSetString(hrec
, 0, "[dummy[1]] [dummy[2]] [[1]dummy[3]]");
723 r
= MsiRecordSetString(hrec
, 1, "a");
724 r
= MsiRecordSetString(hrec
, 2, "b");
725 r
= MsiRecordSetString(hrec
, 3, "c");
726 ok( r
== ERROR_SUCCESS
, "set string failed\n");
728 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
729 ok( r
== ERROR_SUCCESS
, "format failed\n");
730 ok( sz
== 12, "size wrong(%li)\n",sz
);
731 ok( 0 == strcmp(buffer
,"foo baa whoa"), "wrong output (%s)\n",buffer
);
734 r
= MsiSetProperty(package
,"dummya","1");
735 r
= MsiSetProperty(package
,"dummyb","[2]");
736 ok( r
== ERROR_SUCCESS
, "set property failed\n");
737 r
= MsiRecordSetString(hrec
, 0, "[dummya] [[dummya]] [dummyb]");
738 r
= MsiRecordSetString(hrec
, 1, "aaa");
739 r
= MsiRecordSetString(hrec
, 2, "bbb");
740 r
= MsiRecordSetString(hrec
, 3, "ccc");
741 ok( r
== ERROR_SUCCESS
, "set string failed\n");
743 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
744 ok( r
== ERROR_SUCCESS
, "format failed\n");
745 ok( sz
== 9, "size wrong(%li)\n",sz
);
746 ok( 0 == strcmp(buffer
,"1 [1] [2]"), "wrong output (%s)\n",buffer
);
748 r
= MsiSetProperty(package
,"dummya","1");
749 r
= MsiSetProperty(package
,"dummyb","a");
750 r
= MsiSetProperty(package
,"dummyc","\\blath");
751 r
= MsiSetProperty(package
,"dummyd","[\\blath]");
752 ok( r
== ERROR_SUCCESS
, "set property failed\n");
753 r
= MsiRecordSetString(hrec
, 0, "[dummyc] [[dummyc]] [dummy[dummyb]]");
754 r
= MsiRecordSetString(hrec
, 1, "aaa");
755 r
= MsiRecordSetString(hrec
, 2, "bbb");
756 r
= MsiRecordSetString(hrec
, 3, "ccc");
757 ok( r
== ERROR_SUCCESS
, "set string failed\n");
759 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
760 ok( r
== ERROR_SUCCESS
, "format failed\n");
761 ok( sz
== 10, "size wrong(%li)\n",sz
);
762 ok( 0 == strcmp(buffer
,"\\blath b 1"), "wrong output (%s)\n",buffer
);
764 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [[\\3asdf]]");
765 r
= MsiRecordSetString(hrec
, 1, "boo");
766 r
= MsiRecordSetString(hrec
, 2, "hoo");
767 r
= MsiRecordSetString(hrec
, 3, "yeah");
768 ok( r
== ERROR_SUCCESS
, "set string failed\n");
770 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
771 ok( r
== ERROR_SUCCESS
, "format failed\n");
772 ok( sz
== 11, "size wrong(%li)\n",sz
);
773 ok( 0 == strcmp(buffer
,"boo hoo [3]"), "wrong output (%s)\n",buffer
);
775 r
= MsiRecordSetString(hrec
, 0, "[1] [2] [[3]]");
776 r
= MsiRecordSetString(hrec
, 1, "boo");
777 r
= MsiRecordSetString(hrec
, 2, "hoo");
778 r
= MsiRecordSetString(hrec
, 3, "\\help");
779 ok( r
== ERROR_SUCCESS
, "set string failed\n");
781 r
= MsiFormatRecord(package
, hrec
, buffer
, &sz
);
782 ok( r
== ERROR_SUCCESS
, "format failed\n");
783 ok( sz
== 9, "size wrong(%li)\n",sz
);
784 ok( 0 == strcmp(buffer
,"boo hoo h"), "wrong output (%s)\n",buffer
);
786 MsiCloseHandle(hrec
);
788 r
= MsiCloseHandle(package
);
789 ok(r
==ERROR_SUCCESS
, "Unable to close package\n");
791 DeleteFile( filename
);
796 test_createpackage();
798 test_formatrecord_package();