kernel32: GlobalMemoryStatusEx: return the size of physical memory + swapsize in...
[wine] / dlls / msi / tests / package.c
1 /*
2  * tests for Microsoft Installer functionality
3  *
4  * Copyright 2005 Mike McCormack for CodeWeavers
5  * Copyright 2005 Aric Stewart for CodeWeavers
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 #define COBJMACROS
23
24 #include <stdio.h>
25 #include <windows.h>
26 #include <msi.h>
27 #include <msiquery.h>
28
29 #include "wine/test.h"
30
31 static const char msifile[] = "winetest.msi";
32
33 static UINT run_query( MSIHANDLE hdb, const char *query )
34 {
35     MSIHANDLE hview = 0;
36     UINT r;
37
38     r = MsiDatabaseOpenView(hdb, query, &hview);
39     if( r != ERROR_SUCCESS )
40         return r;
41
42     r = MsiViewExecute(hview, 0);
43     if( r == ERROR_SUCCESS )
44         r = MsiViewClose(hview);
45     MsiCloseHandle(hview);
46     return r;
47 }
48
49 static UINT create_component_table( MSIHANDLE hdb )
50 {
51     return run_query( hdb,
52             "CREATE TABLE `Component` ( "
53             "`Component` CHAR(72) NOT NULL, "
54             "`ComponentId` CHAR(38), "
55             "`Directory_` CHAR(72) NOT NULL, "
56             "`Attributes` SHORT NOT NULL, "
57             "`Condition` CHAR(255), "
58             "`KeyPath` CHAR(72) "
59             "PRIMARY KEY `Component`)" );
60 }
61
62 static UINT create_feature_table( MSIHANDLE hdb )
63 {
64     return run_query( hdb,
65             "CREATE TABLE `Feature` ( "
66             "`Feature` CHAR(38) NOT NULL, "
67             "`Feature_Parent` CHAR(38), "
68             "`Title` CHAR(64), "
69             "`Description` CHAR(255), "
70             "`Display` SHORT NOT NULL, "
71             "`Level` SHORT NOT NULL, "
72             "`Directory_` CHAR(72), "
73             "`Attributes` SHORT NOT NULL "
74             "PRIMARY KEY `Feature`)" );
75 }
76
77 static UINT create_feature_components_table( MSIHANDLE hdb )
78 {
79     return run_query( hdb,
80             "CREATE TABLE `FeatureComponents` ( "
81             "`Feature_` CHAR(38) NOT NULL, "
82             "`Component_` CHAR(72) NOT NULL "
83             "PRIMARY KEY `Feature_`, `Component_` )" );
84 }
85
86 static UINT create_file_table( MSIHANDLE hdb )
87 {
88     return run_query( hdb,
89             "CREATE TABLE `File` ("
90             "`File` CHAR(72) NOT NULL, "
91             "`Component_` CHAR(72) NOT NULL, "
92             "`FileName` CHAR(255) NOT NULL, "
93             "`FileSize` LONG NOT NULL, "
94             "`Version` CHAR(72), "
95             "`Language` CHAR(20), "
96             "`Attributes` SHORT, "
97             "`Sequence` SHORT NOT NULL "
98             "PRIMARY KEY `File`)" );
99 }
100
101 static UINT create_remove_file_table( MSIHANDLE hdb )
102 {
103     return run_query( hdb,
104             "CREATE TABLE `RemoveFile` ("
105             "`FileKey` CHAR(72) NOT NULL, "
106             "`Component_` CHAR(72) NOT NULL, "
107             "`FileName` CHAR(255) LOCALIZABLE, "
108             "`DirProperty` CHAR(72) NOT NULL, "
109             "`InstallMode` SHORT NOT NULL "
110             "PRIMARY KEY `FileKey`)" );
111 }
112
113 static UINT create_appsearch_table( MSIHANDLE hdb )
114 {
115     return run_query( hdb,
116             "CREATE TABLE `AppSearch` ("
117             "`Property` CHAR(72) NOT NULL, "
118             "`Signature_` CHAR(72) NOT NULL "
119             "PRIMARY KEY `Property`, `Signature_`)" );
120 }
121
122 static UINT create_reglocator_table( MSIHANDLE hdb )
123 {
124     return run_query( hdb,
125             "CREATE TABLE `RegLocator` ("
126             "`Signature_` CHAR(72) NOT NULL, "
127             "`Root` SHORT NOT NULL, "
128             "`Key` CHAR(255) NOT NULL, "
129             "`Name` CHAR(255), "
130             "`Type` SHORT "
131             "PRIMARY KEY `Signature_`)" );
132 }
133
134 static UINT create_signature_table( MSIHANDLE hdb )
135 {
136     return run_query( hdb,
137             "CREATE TABLE `Signature` ("
138             "`Signature` CHAR(72) NOT NULL, "
139             "`FileName` CHAR(255) NOT NULL, "
140             "`MinVersion` CHAR(20), "
141             "`MaxVersion` CHAR(20), "
142             "`MinSize` LONG, "
143             "`MaxSize` LONG, "
144             "`MinDate` LONG, "
145             "`MaxDate` LONG, "
146             "`Languages` CHAR(255) "
147             "PRIMARY KEY `Signature`)" );
148 }
149
150 static UINT add_component_entry( MSIHANDLE hdb, const char *values )
151 {
152     char insert[] = "INSERT INTO `Component`  "
153             "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
154             "VALUES( %s )";
155     char *query;
156     UINT sz, r;
157
158     sz = strlen(values) + sizeof insert;
159     query = HeapAlloc(GetProcessHeap(),0,sz);
160     sprintf(query,insert,values);
161     r = run_query( hdb, query );
162     HeapFree(GetProcessHeap(), 0, query);
163     return r;
164 }
165
166 static UINT add_feature_entry( MSIHANDLE hdb, const char *values )
167 {
168     char insert[] = "INSERT INTO `Feature` (`Feature`, `Feature_Parent`, "
169                     "`Title`, `Description`, `Display`, `Level`, `Directory_`, `Attributes`) VALUES( %s )";
170     char *query;
171     UINT sz, r;
172
173     sz = strlen(values) + sizeof insert;
174     query = HeapAlloc(GetProcessHeap(),0,sz);
175     sprintf(query,insert,values);
176     r = run_query( hdb, query );
177     HeapFree(GetProcessHeap(), 0, query);
178     return r;
179 }
180
181 static UINT add_feature_components_entry( MSIHANDLE hdb, const char *values )
182 {
183     char insert[] = "INSERT INTO `FeatureComponents` "
184             "(`Feature_`, `Component_`) "
185             "VALUES( %s )";
186     char *query;
187     UINT sz, r;
188
189     sz = strlen(values) + sizeof insert;
190     query = HeapAlloc(GetProcessHeap(),0,sz);
191     sprintf(query,insert,values);
192     r = run_query( hdb, query );
193     HeapFree(GetProcessHeap(), 0, query);
194     return r;
195 }
196
197 static UINT add_file_entry( MSIHANDLE hdb, const char *values )
198 {
199     char insert[] = "INSERT INTO `File` "
200             "(`File`, `Component_`, `FileName`, `FileSize`, `Version`, `Language`, `Attributes`, `Sequence`) "
201             "VALUES( %s )";
202     char *query;
203     UINT sz, r;
204
205     sz = strlen(values) + sizeof insert;
206     query = HeapAlloc(GetProcessHeap(),0,sz);
207     sprintf(query,insert,values);
208     r = run_query( hdb, query );
209     HeapFree(GetProcessHeap(), 0, query);
210     return r;
211 }
212
213 static UINT add_appsearch_entry( MSIHANDLE hdb, const char *values )
214 {
215     char insert[] = "INSERT INTO `AppSearch` "
216             "(`Property`, `Signature_`) "
217             "VALUES( %s )";
218     char *query;
219     UINT sz, r;
220
221     sz = strlen(values) + sizeof insert;
222     query = HeapAlloc(GetProcessHeap(),0,sz);
223     sprintf(query,insert,values);
224     r = run_query( hdb, query );
225     HeapFree(GetProcessHeap(), 0, query);
226     return r;
227 }
228
229 static UINT add_reglocator_entry( MSIHANDLE hdb, const char *values )
230 {
231     char insert[] = "INSERT INTO `RegLocator` "
232             "(`Signature_`, `Root`, `Key`, `Name`, `Type`) "
233             "VALUES( %s )";
234     char *query;
235     UINT sz, r;
236
237     sz = strlen(values) + sizeof insert;
238     query = HeapAlloc(GetProcessHeap(),0,sz);
239     sprintf(query,insert,values);
240     r = run_query( hdb, query );
241     HeapFree(GetProcessHeap(), 0, query);
242     return r;
243 }
244
245 static UINT add_signature_entry( MSIHANDLE hdb, const char *values )
246 {
247     char insert[] = "INSERT INTO `Signature` "
248             "(`Signature`, `FileName`, `MinVersion`, `MaxVersion`,"
249             " `MinSize`, `MaxSize`, `MinDate`, `MaxDate`, `Languages`) "
250             "VALUES( %s )";
251     char *query;
252     UINT sz, r;
253
254     sz = strlen(values) + sizeof insert;
255     query = HeapAlloc(GetProcessHeap(),0,sz);
256     sprintf(query,insert,values);
257     r = run_query( hdb, query );
258     HeapFree(GetProcessHeap(), 0, query);
259     return r;
260 }
261
262 static UINT set_summary_info(MSIHANDLE hdb)
263 {
264     UINT res;
265     MSIHANDLE suminfo;
266
267     /* build summmary info */
268     res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
269     ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
270
271     res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
272                         "Installation Database");
273     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
274
275     res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
276                         "Installation Database");
277     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
278
279     res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
280                         "Wine Hackers");
281     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
282
283     res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
284                     ";1033");
285     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
286
287     res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
288                     "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
289     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
290
291     res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
292     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
293
294     res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
295     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
296
297     res = MsiSummaryInfoPersist(suminfo);
298     ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
299
300     res = MsiCloseHandle( suminfo);
301     ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
302
303     return res;
304 }
305
306
307 static MSIHANDLE create_package_db(void)
308 {
309     MSIHANDLE hdb = 0;
310     UINT res;
311
312     DeleteFile(msifile);
313
314     /* create an empty database */
315     res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
316     ok( res == ERROR_SUCCESS , "Failed to create database\n" );
317     if( res != ERROR_SUCCESS )
318         return hdb;
319
320     res = MsiDatabaseCommit( hdb );
321     ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
322
323     res = set_summary_info(hdb);
324
325     res = run_query( hdb,
326             "CREATE TABLE `Directory` ( "
327             "`Directory` CHAR(255) NOT NULL, "
328             "`Directory_Parent` CHAR(255), "
329             "`DefaultDir` CHAR(255) NOT NULL "
330             "PRIMARY KEY `Directory`)" );
331     ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
332
333     return hdb;
334 }
335
336 static MSIHANDLE package_from_db(MSIHANDLE hdb)
337 {
338     UINT res;
339     CHAR szPackage[10];
340     MSIHANDLE hPackage;
341
342     sprintf(szPackage,"#%li",hdb);
343     res = MsiOpenPackage(szPackage,&hPackage);
344     ok( res == ERROR_SUCCESS , "Failed to open package\n" );
345
346     res = MsiCloseHandle(hdb);
347     ok( res == ERROR_SUCCESS , "Failed to close db handle\n" );
348
349     return hPackage;
350 }
351
352 static void create_test_file(const CHAR *name)
353 {
354     HANDLE file;
355     DWORD written;
356
357     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
358     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
359     WriteFile(file, name, strlen(name), &written, NULL);
360     WriteFile(file, "\n", strlen("\n"), &written, NULL);
361     CloseHandle(file);
362 }
363
364 static void test_createpackage(void)
365 {
366     MSIHANDLE hPackage = 0;
367     UINT res;
368
369     hPackage = package_from_db(create_package_db());
370     ok( hPackage != 0, " Failed to create package\n");
371
372     res = MsiCloseHandle( hPackage);
373     ok( res == ERROR_SUCCESS , "Failed to close package\n" );
374     DeleteFile(msifile);
375 }
376
377 static void test_getsourcepath_bad( void )
378 {
379     static const char str[] = { 0 };
380     char buffer[0x80];
381     DWORD sz;
382     UINT r;
383
384     r = MsiGetSourcePath( -1, NULL, NULL, NULL );
385     ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
386
387     sz = 0;
388     r = MsiGetSourcePath( -1, NULL, buffer, &sz );
389     ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
390
391     sz = 0;
392     r = MsiGetSourcePath( -1, str, NULL, &sz );
393     ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
394
395     sz = 0;
396     r = MsiGetSourcePath( -1, str, NULL, NULL );
397     ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
398
399     sz = 0;
400     r = MsiGetSourcePath( -1, str, buffer, &sz );
401     ok( r == ERROR_INVALID_HANDLE, "return value wrong\n");
402 }
403
404 static UINT add_directory_entry( MSIHANDLE hdb, const char *values )
405 {
406     char insert[] = "INSERT INTO `Directory` (`Directory`,`Directory_Parent`,`DefaultDir`) VALUES( %s )";
407     char *query;
408     UINT sz, r;
409
410     sz = strlen(values) + sizeof insert;
411     query = HeapAlloc(GetProcessHeap(),0,sz);
412     sprintf(query,insert,values);
413     r = run_query( hdb, query );
414     HeapFree(GetProcessHeap(), 0, query);
415     return r;
416 }
417
418 static void test_getsourcepath( void )
419 {
420     static const char str[] = { 0 };
421     char buffer[0x80];
422     DWORD sz;
423     UINT r;
424     MSIHANDLE hpkg, hdb;
425
426     hpkg = package_from_db(create_package_db());
427     ok( hpkg, "failed to create package\n");
428
429     sz = 0;
430     buffer[0] = 'x';
431     r = MsiGetSourcePath( hpkg, str, buffer, &sz );
432     ok( r == ERROR_DIRECTORY, "return value wrong\n");
433     ok( buffer[0] == 'x', "buffer modified\n");
434
435     sz = 1;
436     buffer[0] = 'x';
437     r = MsiGetSourcePath( hpkg, str, buffer, &sz );
438     ok( r == ERROR_DIRECTORY, "return value wrong\n");
439     ok( buffer[0] == 'x', "buffer modified\n");
440
441     MsiCloseHandle( hpkg );
442
443
444     /* another test but try create a directory this time */
445     hdb = create_package_db();
446     ok( hdb, "failed to create database\n");
447
448     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
449     ok( r == S_OK, "failed\n");
450
451     hpkg = package_from_db(hdb);
452     ok( hpkg, "failed to create package\n");
453
454     sz = sizeof buffer -1;
455     strcpy(buffer,"x bad");
456     r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
457     ok( r == ERROR_DIRECTORY, "return value wrong\n");
458
459     r = MsiDoAction( hpkg, "CostInitialize");
460     ok( r == ERROR_SUCCESS, "cost init failed\n");
461     r = MsiDoAction( hpkg, "CostFinalize");
462     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
463
464     sz = sizeof buffer -1;
465     buffer[0] = 'x';
466     r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
467     ok( r == ERROR_SUCCESS, "return value wrong\n");
468     ok( sz == strlen(buffer), "returned length wrong\n");
469
470     sz = 0;
471     strcpy(buffer,"x bad");
472     r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
473     ok( r == ERROR_MORE_DATA, "return value wrong\n");
474     ok( buffer[0] == 'x', "buffer modified\n");
475
476     r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, NULL );
477     ok( r == ERROR_SUCCESS, "return value wrong\n");
478
479     r = MsiGetSourcePath( hpkg, "TARGETDIR ", NULL, NULL );
480     ok( r == ERROR_DIRECTORY, "return value wrong\n");
481
482     r = MsiGetSourcePath( hpkg, "targetdir", NULL, NULL );
483     ok( r == ERROR_DIRECTORY, "return value wrong\n");
484
485     r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, NULL );
486     ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
487
488     r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, &sz );
489     ok( r == ERROR_SUCCESS, "return value wrong\n");
490
491     MsiCloseHandle( hpkg );
492     DeleteFile(msifile);
493 }
494
495 static void test_doaction( void )
496 {
497     MSIHANDLE hpkg;
498     UINT r;
499
500     r = MsiDoAction( -1, NULL );
501     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
502
503     hpkg = package_from_db(create_package_db());
504     ok( hpkg, "failed to create package\n");
505
506     r = MsiDoAction(hpkg, NULL);
507     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
508
509     r = MsiDoAction(0, "boo");
510     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
511
512     r = MsiDoAction(hpkg, "boo");
513     ok( r == ERROR_FUNCTION_NOT_CALLED, "wrong return val\n");
514
515     MsiCloseHandle( hpkg );
516     DeleteFile(msifile);
517 }
518
519 static void test_gettargetpath_bad(void)
520 {
521     char buffer[0x80];
522     MSIHANDLE hpkg;
523     DWORD sz;
524     UINT r;
525
526     hpkg = package_from_db(create_package_db());
527     ok( hpkg, "failed to create package\n");
528
529     r = MsiGetTargetPath( 0, NULL, NULL, NULL );
530     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
531
532     r = MsiGetTargetPath( 0, NULL, NULL, &sz );
533     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
534
535     r = MsiGetTargetPath( 0, "boo", NULL, NULL );
536     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
537
538     r = MsiGetTargetPath( 0, "boo", NULL, NULL );
539     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
540
541     r = MsiGetTargetPath( hpkg, "boo", NULL, NULL );
542     ok( r == ERROR_DIRECTORY, "wrong return val\n");
543
544     r = MsiGetTargetPath( hpkg, "boo", buffer, NULL );
545     ok( r == ERROR_DIRECTORY, "wrong return val\n");
546
547     MsiCloseHandle( hpkg );
548     DeleteFile(msifile);
549 }
550
551 static void query_file_path(MSIHANDLE hpkg, LPCSTR file, LPSTR buff)
552 {
553     UINT r;
554     DWORD size;
555     MSIHANDLE rec;
556
557     rec = MsiCreateRecord( 1 );
558     ok(rec, "MsiCreate record failed\n");
559
560     r = MsiRecordSetString( rec, 0, file );
561     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
562
563     size = MAX_PATH;
564     r = MsiFormatRecord( hpkg, rec, buff, &size );
565     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
566
567     MsiCloseHandle( rec );
568 }
569
570 static void test_settargetpath(void)
571 {
572     char tempdir[MAX_PATH+8], buffer[MAX_PATH], file[MAX_PATH];
573     DWORD sz;
574     MSIHANDLE hpkg;
575     UINT r;
576     MSIHANDLE hdb;
577
578     hdb = create_package_db();
579     ok ( hdb, "failed to create package database\n" );
580
581     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'" );
582     ok( r == S_OK, "failed to add directory entry: %d\n" , r );
583
584     r = create_component_table( hdb );
585     ok( r == S_OK, "cannot create Component table: %d\n", r );
586
587     r = add_component_entry( hdb, "'RootComp', '{83e2694d-0864-4124-9323-6d37630912a1}', 'TARGETDIR', 8, '', 'RootFile'" );
588     ok( r == S_OK, "cannot add dummy component: %d\n", r );
589
590     r = add_component_entry( hdb, "'TestComp', '{A3FB59C8-C293-4F7E-B8C5-F0E1D8EEE4E5}', 'TestDir', 0, '', 'TestFile'" );
591     ok( r == S_OK, "cannot add test component: %d\n", r );
592
593     r = create_feature_table( hdb );
594     ok( r == S_OK, "cannot create Feature table: %d\n", r );
595
596     r = add_feature_entry( hdb, "'TestFeature', '', '', '', 0, 1, '', 0" );
597     ok( r == ERROR_SUCCESS, "cannot add TestFeature to Feature table: %d\n", r );
598
599     r = create_feature_components_table( hdb );
600     ok( r == S_OK, "cannot create FeatureComponents table: %d\n", r );
601
602     r = add_feature_components_entry( hdb, "'TestFeature', 'RootComp'" );
603     ok( r == S_OK, "cannot insert component into FeatureComponents table: %d\n", r );
604
605     r = add_feature_components_entry( hdb, "'TestFeature', 'TestComp'" );
606     ok( r == S_OK, "cannot insert component into FeatureComponents table: %d\n", r );
607
608     add_directory_entry( hdb, "'TestParent', 'TARGETDIR', 'TestParent'" );
609     add_directory_entry( hdb, "'TestDir', 'TestParent', 'TestDir'" );
610
611     r = create_file_table( hdb );
612     ok( r == S_OK, "cannot create File table: %d\n", r );
613
614     r = add_file_entry( hdb, "'RootFile', 'RootComp', 'rootfile.txt', 0, '', '1033', 8192, 1" );
615     ok( r == S_OK, "cannot add file to the File table: %d\n", r );
616
617     r = add_file_entry( hdb, "'TestFile', 'TestComp', 'testfile.txt', 0, '', '1033', 8192, 1" );
618     ok( r == S_OK, "cannot add file to the File table: %d\n", r );
619
620     hpkg = package_from_db( hdb );
621     ok( hpkg, "failed to create package\n");
622
623     r = MsiDoAction( hpkg, "CostInitialize");
624     ok( r == ERROR_SUCCESS, "cost init failed\n");
625
626     r = MsiDoAction( hpkg, "FileCost");
627     ok( r == ERROR_SUCCESS, "file cost failed\n");
628
629     r = MsiDoAction( hpkg, "CostFinalize");
630     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
631
632     r = MsiSetTargetPath( 0, NULL, NULL );
633     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
634
635     r = MsiSetTargetPath( 0, "boo", "C:\\bogusx" );
636     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
637
638     r = MsiSetTargetPath( hpkg, "boo", NULL );
639     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
640
641     r = MsiSetTargetPath( hpkg, "boo", "c:\\bogusx" );
642     ok( r == ERROR_DIRECTORY, "wrong return val\n");
643
644     sz = sizeof tempdir - 1;
645     r = MsiGetTargetPath( hpkg, "TARGETDIR", tempdir, &sz );
646     sprintf( file, "%srootfile.txt", tempdir );
647     query_file_path( hpkg, "[#RootFile]", buffer );
648     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
649     ok( !lstrcmp(buffer, file), "Expected %s, got %s\n", file, buffer );
650
651     GetTempFileName( tempdir, "_wt", 0, buffer );
652     sprintf( tempdir, "%s\\subdir", buffer );
653
654     r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
655     ok( r == ERROR_SUCCESS, "MsiSetTargetPath on file returned %d\n", r );
656
657     r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
658     ok( r == ERROR_SUCCESS, "MsiSetTargetPath on 'subdir' of file returned %d\n", r );
659
660     DeleteFile( buffer );
661
662     r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
663     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
664
665     r = GetFileAttributes( buffer );
666     ok ( r == INVALID_FILE_ATTRIBUTES, "file/directory exists after MsiSetTargetPath. Attributes: %08X\n", r );
667
668     r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
669     ok( r == ERROR_SUCCESS, "MsiSetTargetPath on subsubdir returned %d\n", r );
670
671     sz = sizeof buffer - 1;
672     lstrcat( tempdir, "\\" );
673     r = MsiGetTargetPath( hpkg, "TARGETDIR", buffer, &sz );
674     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
675     ok( !lstrcmp(buffer, tempdir), "Expected %s, got %s\n", tempdir, buffer);
676
677     sprintf( file, "%srootfile.txt", tempdir );
678     query_file_path( hpkg, "[#RootFile]", buffer );
679     ok( !lstrcmp(buffer, file), "Expected %s, got %s\n", file, buffer);
680
681     r = MsiSetTargetPath( hpkg, "TestParent", "C:\\one\\two" );
682     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
683
684     query_file_path( hpkg, "[#TestFile]", buffer );
685     ok( !lstrcmp(buffer, "C:\\one\\two\\TestDir\\testfile.txt"),
686         "Expected C:\\one\\two\\TestDir\\testfile.txt, got %s\n", buffer );
687
688     sz = sizeof buffer - 1;
689     r = MsiGetTargetPath( hpkg, "TestParent", buffer, &sz );
690     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
691     ok( !lstrcmp(buffer, "C:\\one\\two\\"), "Expected C:\\one\\two\\, got %s\n", buffer);
692
693     MsiCloseHandle( hpkg );
694 }
695
696 static void test_condition(void)
697 {
698     MSICONDITION r;
699     MSIHANDLE hpkg;
700
701     hpkg = package_from_db(create_package_db());
702     ok( hpkg, "failed to create package\n");
703
704     r = MsiEvaluateCondition(0, NULL);
705     ok( r == MSICONDITION_ERROR, "wrong return val\n");
706
707     r = MsiEvaluateCondition(hpkg, NULL);
708     ok( r == MSICONDITION_NONE, "wrong return val\n");
709
710     r = MsiEvaluateCondition(hpkg, "");
711     ok( r == MSICONDITION_NONE, "wrong return val\n");
712
713     r = MsiEvaluateCondition(hpkg, "1");
714     ok( r == MSICONDITION_TRUE, "wrong return val\n");
715
716     r = MsiEvaluateCondition(hpkg, "0");
717     ok( r == MSICONDITION_FALSE, "wrong return val\n");
718
719     r = MsiEvaluateCondition(hpkg, "0 = 0");
720     ok( r == MSICONDITION_TRUE, "wrong return val\n");
721
722     r = MsiEvaluateCondition(hpkg, "0 <> 0");
723     ok( r == MSICONDITION_FALSE, "wrong return val\n");
724
725     r = MsiEvaluateCondition(hpkg, "0 = 1");
726     ok( r == MSICONDITION_FALSE, "wrong return val\n");
727
728     r = MsiEvaluateCondition(hpkg, "0 > 1");
729     ok( r == MSICONDITION_FALSE, "wrong return val\n");
730
731     r = MsiEvaluateCondition(hpkg, "0 ~> 1");
732     ok( r == MSICONDITION_FALSE, "wrong return val\n");
733
734     r = MsiEvaluateCondition(hpkg, "1 > 1");
735     ok( r == MSICONDITION_FALSE, "wrong return val\n");
736
737     r = MsiEvaluateCondition(hpkg, "1 ~> 1");
738     ok( r == MSICONDITION_FALSE, "wrong return val\n");
739
740     r = MsiEvaluateCondition(hpkg, "0 >= 1");
741     ok( r == MSICONDITION_FALSE, "wrong return val\n");
742
743     r = MsiEvaluateCondition(hpkg, "0 ~>= 1");
744     ok( r == MSICONDITION_FALSE, "wrong return val\n");
745
746     r = MsiEvaluateCondition(hpkg, "1 >= 1");
747     ok( r == MSICONDITION_TRUE, "wrong return val\n");
748
749     r = MsiEvaluateCondition(hpkg, "1 ~>= 1");
750     ok( r == MSICONDITION_TRUE, "wrong return val\n");
751
752     r = MsiEvaluateCondition(hpkg, "0 < 1");
753     ok( r == MSICONDITION_TRUE, "wrong return val\n");
754
755     r = MsiEvaluateCondition(hpkg, "0 ~< 1");
756     ok( r == MSICONDITION_TRUE, "wrong return val\n");
757
758     r = MsiEvaluateCondition(hpkg, "1 < 1");
759     ok( r == MSICONDITION_FALSE, "wrong return val\n");
760
761     r = MsiEvaluateCondition(hpkg, "1 ~< 1");
762     ok( r == MSICONDITION_FALSE, "wrong return val\n");
763
764     r = MsiEvaluateCondition(hpkg, "0 <= 1");
765     ok( r == MSICONDITION_TRUE, "wrong return val\n");
766
767     r = MsiEvaluateCondition(hpkg, "0 ~<= 1");
768     ok( r == MSICONDITION_TRUE, "wrong return val\n");
769
770     r = MsiEvaluateCondition(hpkg, "1 <= 1");
771     ok( r == MSICONDITION_TRUE, "wrong return val\n");
772
773     r = MsiEvaluateCondition(hpkg, "1 ~<= 1");
774     ok( r == MSICONDITION_TRUE, "wrong return val\n");
775
776     r = MsiEvaluateCondition(hpkg, "0 >=");
777     ok( r == MSICONDITION_ERROR, "wrong return val\n");
778
779     r = MsiEvaluateCondition(hpkg, " ");
780     ok( r == MSICONDITION_NONE, "wrong return val\n");
781
782     r = MsiEvaluateCondition(hpkg, "LicView <> \"1\"");
783     ok( r == MSICONDITION_TRUE, "wrong return val\n");
784
785     r = MsiEvaluateCondition(hpkg, "LicView <> \"0\"");
786     ok( r == MSICONDITION_TRUE, "wrong return val\n");
787
788     r = MsiEvaluateCondition(hpkg, "LicView <> LicView");
789     ok( r == MSICONDITION_FALSE, "wrong return val\n");
790
791     r = MsiEvaluateCondition(hpkg, "not 0");
792     ok( r == MSICONDITION_TRUE, "wrong return val\n");
793
794     r = MsiEvaluateCondition(hpkg, "not LicView");
795     ok( r == MSICONDITION_TRUE, "wrong return val\n");
796
797     r = MsiEvaluateCondition(hpkg, "not \"A\"");
798     ok( r == MSICONDITION_FALSE, "wrong return val\n");
799
800     r = MsiEvaluateCondition(hpkg, "~not \"A\"");
801     ok( r == MSICONDITION_ERROR, "wrong return val\n");
802
803     r = MsiEvaluateCondition(hpkg, "\"0\"");
804     ok( r == MSICONDITION_TRUE, "wrong return val\n");
805
806     r = MsiEvaluateCondition(hpkg, "1 and 2");
807     ok( r == MSICONDITION_TRUE, "wrong return val\n");
808
809     r = MsiEvaluateCondition(hpkg, "not 0 and 3");
810     ok( r == MSICONDITION_TRUE, "wrong return val\n");
811
812     r = MsiEvaluateCondition(hpkg, "not 0 and 0");
813     ok( r == MSICONDITION_FALSE, "wrong return val\n");
814
815     r = MsiEvaluateCondition(hpkg, "not 0 or 1");
816     ok( r == MSICONDITION_TRUE, "wrong return val\n");
817
818     r = MsiEvaluateCondition(hpkg, "(0)");
819     ok( r == MSICONDITION_FALSE, "wrong return val\n");
820
821     r = MsiEvaluateCondition(hpkg, "(((((1))))))");
822     ok( r == MSICONDITION_ERROR, "wrong return val\n");
823
824     r = MsiEvaluateCondition(hpkg, "(((((1)))))");
825     ok( r == MSICONDITION_TRUE, "wrong return val\n");
826
827     r = MsiEvaluateCondition(hpkg, " \"A\" < \"B\" ");
828     ok( r == MSICONDITION_TRUE, "wrong return val\n");
829
830     r = MsiEvaluateCondition(hpkg, " \"A\" > \"B\" ");
831     ok( r == MSICONDITION_FALSE, "wrong return val\n");
832
833     r = MsiEvaluateCondition(hpkg, " \"1\" > \"12\" ");
834     ok( r == MSICONDITION_FALSE, "wrong return val\n");
835
836     r = MsiEvaluateCondition(hpkg, " \"100\" < \"21\" ");
837     ok( r == MSICONDITION_TRUE, "wrong return val\n");
838
839     r = MsiEvaluateCondition(hpkg, "0 < > 0");
840     ok( r == MSICONDITION_ERROR, "wrong return val\n");
841
842     r = MsiEvaluateCondition(hpkg, "(1<<1) == 2");
843     ok( r == MSICONDITION_ERROR, "wrong return val\n");
844
845     r = MsiEvaluateCondition(hpkg, " \"A\" = \"a\" ");
846     ok( r == MSICONDITION_FALSE, "wrong return val\n");
847
848     r = MsiEvaluateCondition(hpkg, " \"A\" ~ = \"a\" ");
849     ok( r == MSICONDITION_ERROR, "wrong return val\n");
850
851     r = MsiEvaluateCondition(hpkg, " \"A\" ~= \"a\" ");
852     ok( r == MSICONDITION_TRUE, "wrong return val\n");
853
854     r = MsiEvaluateCondition(hpkg, " \"A\" ~= 1 ");
855     ok( r == MSICONDITION_FALSE, "wrong return val\n");
856
857     r = MsiEvaluateCondition(hpkg, " \"A\" = 1 ");
858     ok( r == MSICONDITION_FALSE, "wrong return val\n");
859
860     r = MsiEvaluateCondition(hpkg, " 1 ~= 1 ");
861     ok( r == MSICONDITION_TRUE, "wrong return val\n");
862
863     r = MsiEvaluateCondition(hpkg, " 1 ~= \"1\" ");
864     ok( r == MSICONDITION_FALSE, "wrong return val\n");
865
866     r = MsiEvaluateCondition(hpkg, " 1 = \"1\" ");
867     ok( r == MSICONDITION_FALSE, "wrong return val\n");
868
869     r = MsiEvaluateCondition(hpkg, " 0 = \"1\" ");
870     ok( r == MSICONDITION_FALSE, "wrong return val\n");
871
872     r = MsiEvaluateCondition(hpkg, " 0 < \"100\" ");
873     ok( r == MSICONDITION_FALSE, "wrong return val\n");
874
875     r = MsiEvaluateCondition(hpkg, " 100 > \"0\" ");
876     ok( r == MSICONDITION_FALSE, "wrong return val\n");
877
878     r = MsiEvaluateCondition(hpkg, "1 XOR 1");
879     ok( r == MSICONDITION_FALSE, "wrong return val\n");
880
881     r = MsiEvaluateCondition(hpkg, "1 IMP 1");
882     ok( r == MSICONDITION_TRUE, "wrong return val\n");
883
884     r = MsiEvaluateCondition(hpkg, "1 IMP 0");
885     ok( r == MSICONDITION_FALSE, "wrong return val\n");
886
887     r = MsiEvaluateCondition(hpkg, "0 IMP 0");
888     ok( r == MSICONDITION_TRUE, "wrong return val\n");
889
890     r = MsiEvaluateCondition(hpkg, "0 EQV 0");
891     ok( r == MSICONDITION_TRUE, "wrong return val\n");
892
893     r = MsiEvaluateCondition(hpkg, "0 EQV 1");
894     ok( r == MSICONDITION_FALSE, "wrong return val\n");
895
896     r = MsiEvaluateCondition(hpkg, "1 IMP 1 OR 0");
897     ok( r == MSICONDITION_TRUE, "wrong return val\n");
898
899     r = MsiEvaluateCondition(hpkg, "1 IMPL 1");
900     ok( r == MSICONDITION_ERROR, "wrong return val\n");
901
902     r = MsiEvaluateCondition(hpkg, "\"ASFD\" >< \"S\" ");
903     ok( r == MSICONDITION_TRUE, "wrong return val\n");
904
905     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"s\" ");
906     ok( r == MSICONDITION_TRUE, "wrong return val\n");
907
908     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"\" ");
909     ok( r == MSICONDITION_TRUE, "wrong return val\n");
910
911     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"sss\" ");
912     ok( r == MSICONDITION_FALSE, "wrong return val\n");
913
914     MsiSetProperty(hpkg, "mm", "5" );
915
916     r = MsiEvaluateCondition(hpkg, "mm = 5");
917     ok( r == MSICONDITION_TRUE, "wrong return val\n");
918
919     r = MsiEvaluateCondition(hpkg, "mm < 6");
920     ok( r == MSICONDITION_TRUE, "wrong return val\n");
921
922     r = MsiEvaluateCondition(hpkg, "mm <= 5");
923     ok( r == MSICONDITION_TRUE, "wrong return val\n");
924
925     r = MsiEvaluateCondition(hpkg, "mm > 4");
926     ok( r == MSICONDITION_TRUE, "wrong return val\n");
927
928     r = MsiEvaluateCondition(hpkg, "mm < 12");
929     ok( r == MSICONDITION_TRUE, "wrong return val\n");
930
931     r = MsiEvaluateCondition(hpkg, "mm = \"5\"");
932     ok( r == MSICONDITION_TRUE, "wrong return val\n");
933
934     r = MsiEvaluateCondition(hpkg, "0 = \"\"");
935     ok( r == MSICONDITION_FALSE, "wrong return val\n");
936
937     r = MsiEvaluateCondition(hpkg, "0 AND \"\"");
938     ok( r == MSICONDITION_FALSE, "wrong return val\n");
939
940     r = MsiEvaluateCondition(hpkg, "1 AND \"\"");
941     ok( r == MSICONDITION_FALSE, "wrong return val\n");
942
943     r = MsiEvaluateCondition(hpkg, "1 AND \"1\"");
944     ok( r == MSICONDITION_TRUE, "wrong return val\n");
945
946     r = MsiEvaluateCondition(hpkg, "3 >< 1");
947     ok( r == MSICONDITION_TRUE, "wrong return val\n");
948
949     r = MsiEvaluateCondition(hpkg, "3 >< 4");
950     ok( r == MSICONDITION_FALSE, "wrong return val\n");
951
952     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 0");
953     ok( r == MSICONDITION_FALSE, "wrong return val\n");
954
955     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 1");
956     ok( r == MSICONDITION_TRUE, "wrong return val\n");
957
958     r = MsiEvaluateCondition(hpkg, "NOT 1 OR 0");
959     ok( r == MSICONDITION_FALSE, "wrong return val\n");
960
961     r = MsiEvaluateCondition(hpkg, "0 AND 1 OR 1");
962     ok( r == MSICONDITION_TRUE, "wrong return val\n");
963
964     r = MsiEvaluateCondition(hpkg, "0 AND 0 OR 1");
965     ok( r == MSICONDITION_TRUE, "wrong return val\n");
966
967     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 1 OR 0");
968     ok( r == MSICONDITION_TRUE, "wrong return val\n");
969
970     r = MsiEvaluateCondition(hpkg, "_1 = _1");
971     ok( r == MSICONDITION_TRUE, "wrong return val\n");
972
973     r = MsiEvaluateCondition(hpkg, "( 1 AND 1 ) = 2");
974     ok( r == MSICONDITION_ERROR, "wrong return val\n");
975
976     r = MsiEvaluateCondition(hpkg, "NOT ( 1 AND 1 )");
977     ok( r == MSICONDITION_FALSE, "wrong return val\n");
978
979     r = MsiEvaluateCondition(hpkg, "NOT A AND (BBBBBBBBBB=2 OR CCC=1) AND Ddddddddd");
980     ok( r == MSICONDITION_FALSE, "wrong return val\n");
981
982     r = MsiEvaluateCondition(hpkg, "Installed<>\"\"");
983     ok( r == MSICONDITION_FALSE, "wrong return val\n");
984
985     r = MsiEvaluateCondition(hpkg, "NOT 1 AND 0");
986     ok( r == MSICONDITION_FALSE, "wrong return val\n");
987
988     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
989     ok( r == MSICONDITION_FALSE, "wrong return val\n");
990
991     r = MsiEvaluateCondition(hpkg, "bandalmael<>0");
992     ok( r == MSICONDITION_TRUE, "wrong return val\n");
993
994     r = MsiEvaluateCondition(hpkg, "bandalmael<0");
995     ok( r == MSICONDITION_FALSE, "wrong return val\n");
996
997     r = MsiEvaluateCondition(hpkg, "bandalmael>0");
998     ok( r == MSICONDITION_FALSE, "wrong return val\n");
999
1000     r = MsiEvaluateCondition(hpkg, "bandalmael>=0");
1001     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1002
1003     r = MsiEvaluateCondition(hpkg, "bandalmael<=0");
1004     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1005
1006     r = MsiEvaluateCondition(hpkg, "bandalmael~<>0");
1007     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1008
1009     MsiSetProperty(hpkg, "bandalmael", "0" );
1010     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1011     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1012
1013     MsiSetProperty(hpkg, "bandalmael", "" );
1014     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1015     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1016
1017     MsiSetProperty(hpkg, "bandalmael", "asdf" );
1018     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1019     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1020
1021     MsiSetProperty(hpkg, "bandalmael", "0asdf" );
1022     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1023     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1024
1025     MsiSetProperty(hpkg, "bandalmael", "0 " );
1026     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1027     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1028
1029     MsiSetProperty(hpkg, "bandalmael", "-0" );
1030     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1031     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1032
1033     MsiSetProperty(hpkg, "bandalmael", "0000000000000" );
1034     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1035     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1036
1037     MsiSetProperty(hpkg, "bandalmael", "--0" );
1038     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1039     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1040
1041     MsiSetProperty(hpkg, "bandalmael", "0x00" );
1042     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1043     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1044
1045     MsiSetProperty(hpkg, "bandalmael", "-" );
1046     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1047     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1048
1049     MsiSetProperty(hpkg, "bandalmael", "+0" );
1050     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1051     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1052
1053     MsiSetProperty(hpkg, "bandalmael", "0.0" );
1054     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1055     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1056     r = MsiEvaluateCondition(hpkg, "bandalmael<>0");
1057     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1058
1059     MsiSetProperty(hpkg, "one", "hi");
1060     MsiSetProperty(hpkg, "two", "hithere");
1061     r = MsiEvaluateCondition(hpkg, "one >< two");
1062     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1063
1064     MsiSetProperty(hpkg, "one", "hithere");
1065     MsiSetProperty(hpkg, "two", "hi");
1066     r = MsiEvaluateCondition(hpkg, "one >< two");
1067     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1068
1069     MsiSetProperty(hpkg, "one", "hello");
1070     MsiSetProperty(hpkg, "two", "hi");
1071     r = MsiEvaluateCondition(hpkg, "one >< two");
1072     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1073
1074     MsiSetProperty(hpkg, "one", "hellohithere");
1075     MsiSetProperty(hpkg, "two", "hi");
1076     r = MsiEvaluateCondition(hpkg, "one >< two");
1077     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1078
1079     MsiSetProperty(hpkg, "one", "");
1080     MsiSetProperty(hpkg, "two", "hi");
1081     r = MsiEvaluateCondition(hpkg, "one >< two");
1082     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1083
1084     MsiSetProperty(hpkg, "one", "hi");
1085     MsiSetProperty(hpkg, "two", "");
1086     r = MsiEvaluateCondition(hpkg, "one >< two");
1087     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1088
1089     MsiSetProperty(hpkg, "one", "");
1090     MsiSetProperty(hpkg, "two", "");
1091     r = MsiEvaluateCondition(hpkg, "one >< two");
1092     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1093
1094     MsiSetProperty(hpkg, "one", "1234");
1095     MsiSetProperty(hpkg, "two", "1");
1096     r = MsiEvaluateCondition(hpkg, "one >< two");
1097     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1098
1099     MsiSetProperty(hpkg, "one", "one 1234");
1100     MsiSetProperty(hpkg, "two", "1");
1101     r = MsiEvaluateCondition(hpkg, "one >< two");
1102     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1103
1104     MsiSetProperty(hpkg, "one", "hithere");
1105     MsiSetProperty(hpkg, "two", "hi");
1106     r = MsiEvaluateCondition(hpkg, "one << two");
1107     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1108
1109     MsiSetProperty(hpkg, "one", "hi");
1110     MsiSetProperty(hpkg, "two", "hithere");
1111     r = MsiEvaluateCondition(hpkg, "one << two");
1112     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1113
1114     MsiSetProperty(hpkg, "one", "hi");
1115     MsiSetProperty(hpkg, "two", "hi");
1116     r = MsiEvaluateCondition(hpkg, "one << two");
1117     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1118
1119     MsiSetProperty(hpkg, "one", "abcdhithere");
1120     MsiSetProperty(hpkg, "two", "hi");
1121     r = MsiEvaluateCondition(hpkg, "one << two");
1122     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1123
1124     MsiSetProperty(hpkg, "one", "");
1125     MsiSetProperty(hpkg, "two", "hi");
1126     r = MsiEvaluateCondition(hpkg, "one << two");
1127     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1128
1129     MsiSetProperty(hpkg, "one", "hithere");
1130     MsiSetProperty(hpkg, "two", "");
1131     r = MsiEvaluateCondition(hpkg, "one << two");
1132     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1133
1134     MsiSetProperty(hpkg, "one", "");
1135     MsiSetProperty(hpkg, "two", "");
1136     r = MsiEvaluateCondition(hpkg, "one << two");
1137     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1138
1139     MsiSetProperty(hpkg, "one", "1234");
1140     MsiSetProperty(hpkg, "two", "1");
1141     r = MsiEvaluateCondition(hpkg, "one << two");
1142     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1143
1144     MsiSetProperty(hpkg, "one", "1234 one");
1145     MsiSetProperty(hpkg, "two", "1");
1146     r = MsiEvaluateCondition(hpkg, "one << two");
1147     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1148
1149     MsiSetProperty(hpkg, "one", "hithere");
1150     MsiSetProperty(hpkg, "two", "there");
1151     r = MsiEvaluateCondition(hpkg, "one >> two");
1152     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1153
1154     MsiSetProperty(hpkg, "one", "hithere");
1155     MsiSetProperty(hpkg, "two", "hi");
1156     r = MsiEvaluateCondition(hpkg, "one >> two");
1157     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1158
1159     MsiSetProperty(hpkg, "one", "there");
1160     MsiSetProperty(hpkg, "two", "hithere");
1161     r = MsiEvaluateCondition(hpkg, "one >> two");
1162     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1163
1164     MsiSetProperty(hpkg, "one", "there");
1165     MsiSetProperty(hpkg, "two", "there");
1166     r = MsiEvaluateCondition(hpkg, "one >> two");
1167     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1168
1169     MsiSetProperty(hpkg, "one", "abcdhithere");
1170     MsiSetProperty(hpkg, "two", "hi");
1171     r = MsiEvaluateCondition(hpkg, "one >> two");
1172     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1173
1174     MsiSetProperty(hpkg, "one", "");
1175     MsiSetProperty(hpkg, "two", "there");
1176     r = MsiEvaluateCondition(hpkg, "one >> two");
1177     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1178
1179     MsiSetProperty(hpkg, "one", "there");
1180     MsiSetProperty(hpkg, "two", "");
1181     r = MsiEvaluateCondition(hpkg, "one >> two");
1182     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1183
1184     MsiSetProperty(hpkg, "one", "");
1185     MsiSetProperty(hpkg, "two", "");
1186     r = MsiEvaluateCondition(hpkg, "one >> two");
1187     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1188
1189     MsiSetProperty(hpkg, "one", "1234");
1190     MsiSetProperty(hpkg, "two", "4");
1191     r = MsiEvaluateCondition(hpkg, "one >> two");
1192     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1193
1194     MsiSetProperty(hpkg, "one", "one 1234");
1195     MsiSetProperty(hpkg, "two", "4");
1196     r = MsiEvaluateCondition(hpkg, "one >> two");
1197     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1198
1199     MsiSetProperty(hpkg, "MsiNetAssemblySupport", NULL);  /* make sure it's empty */
1200
1201     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322\"");
1202     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1203
1204     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport > \"1.1.4322\"");
1205     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1206
1207     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport >= \"1.1.4322\"");
1208     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1209
1210     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport <= \"1.1.4322\"");
1211     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1212
1213     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport <> \"1.1.4322\"");
1214     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1215
1216     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport ~< \"1.1.4322\"");
1217     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1218
1219     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"abcd\"");
1220     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1221
1222     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a1.1.4322\"");
1223     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1224
1225     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322a\"");
1226     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1227
1228     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"0000001.1.4322\"");
1229     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1230
1231     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322.1\"");
1232     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1233
1234     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322.1.1\"");
1235     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1236
1237     r = MsiEvaluateCondition(hpkg, "\"2\" < \"1.1");
1238     ok( r == MSICONDITION_ERROR, "wrong return val (%d)\n", r);
1239
1240     r = MsiEvaluateCondition(hpkg, "\"2\" < \"1.1\"");
1241     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1242
1243     r = MsiEvaluateCondition(hpkg, "\"2\" < \"12.1\"");
1244     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1245
1246     r = MsiEvaluateCondition(hpkg, "\"02.1\" < \"2.11\"");
1247     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1248
1249     r = MsiEvaluateCondition(hpkg, "\"02.1.1\" < \"2.1\"");
1250     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1251
1252     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1\"");
1253     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1254
1255     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1\"");
1256     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1257
1258     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"0\"");
1259     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1260
1261     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"-1\"");
1262     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1263
1264     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a\"");
1265     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1266
1267     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"!\"");
1268     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1269
1270     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"!\"");
1271     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1272
1273     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"/\"");
1274     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1275
1276     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \" \"");
1277     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1278
1279     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"azAZ_\"");
1280     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1281
1282     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a[a]\"");
1283     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1284
1285     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a[a]a\"");
1286     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1287
1288     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a]\"");
1289     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1290
1291     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a]a\"");
1292     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1293
1294     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"{a}\"");
1295     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1296
1297     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"{a\"");
1298     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1299
1300     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a\"");
1301     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1302
1303     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a{\"");
1304     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1305
1306     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a]\"");
1307     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1308
1309     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"A\"");
1310     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1311
1312     MsiSetProperty(hpkg, "MsiNetAssemblySupport", "1.1.4322");
1313     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322\"");
1314     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1315
1316     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.14322\"");
1317     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1318
1319     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.5\"");
1320     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1321
1322     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1\"");
1323     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1324
1325     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1\"");
1326     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1327
1328     MsiSetProperty(hpkg, "one", "1");
1329     r = MsiEvaluateCondition(hpkg, "one < \"1\"");
1330     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1331
1332     MsiCloseHandle( hpkg );
1333     DeleteFile(msifile);
1334 }
1335
1336 static BOOL check_prop_empty( MSIHANDLE hpkg, const char * prop)
1337 {
1338     UINT r;
1339     DWORD sz;
1340     char buffer[2];
1341
1342     sz = sizeof buffer;
1343     strcpy(buffer,"x");
1344     r = MsiGetProperty( hpkg, prop, buffer, &sz );
1345     return r == ERROR_SUCCESS && buffer[0] == 0 && sz == 0;
1346 }
1347
1348 static void test_props(void)
1349 {
1350     MSIHANDLE hpkg, hdb;
1351     UINT r;
1352     DWORD sz;
1353     char buffer[0x100];
1354
1355     hdb = create_package_db();
1356     r = run_query( hdb,
1357             "CREATE TABLE `Property` ( "
1358             "`Property` CHAR(255) NOT NULL, "
1359             "`Value` CHAR(255) "
1360             "PRIMARY KEY `Property`)" );
1361     ok( r == ERROR_SUCCESS , "Failed\n" );
1362
1363     r = run_query(hdb,
1364             "INSERT INTO `Property` "
1365             "(`Property`, `Value`) "
1366             "VALUES( 'MetadataCompName', 'Photoshop.dll' )");
1367     ok( r == ERROR_SUCCESS , "Failed\n" );
1368
1369     hpkg = package_from_db( hdb );
1370     ok( hpkg, "failed to create package\n");
1371
1372     /* test invalid values */
1373     r = MsiGetProperty( 0, NULL, NULL, NULL );
1374     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1375
1376     r = MsiGetProperty( hpkg, NULL, NULL, NULL );
1377     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1378
1379     r = MsiGetProperty( hpkg, "boo", NULL, NULL );
1380     ok( r == ERROR_SUCCESS, "wrong return val\n");
1381
1382     r = MsiGetProperty( hpkg, "boo", buffer, NULL );
1383     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1384
1385     /* test retrieving an empty/nonexistent property */
1386     sz = sizeof buffer;
1387     r = MsiGetProperty( hpkg, "boo", NULL, &sz );
1388     ok( r == ERROR_SUCCESS, "wrong return val\n");
1389     ok( sz == 0, "wrong size returned\n");
1390
1391     check_prop_empty( hpkg, "boo");
1392     sz = 0;
1393     strcpy(buffer,"x");
1394     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
1395     ok( r == ERROR_MORE_DATA, "wrong return val\n");
1396     ok( !strcmp(buffer,"x"), "buffer was changed\n");
1397     ok( sz == 0, "wrong size returned\n");
1398
1399     sz = 1;
1400     strcpy(buffer,"x");
1401     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
1402     ok( r == ERROR_SUCCESS, "wrong return val\n");
1403     ok( buffer[0] == 0, "buffer was not changed\n");
1404     ok( sz == 0, "wrong size returned\n");
1405
1406     /* set the property to something */
1407     r = MsiSetProperty( 0, NULL, NULL );
1408     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
1409
1410     r = MsiSetProperty( hpkg, NULL, NULL );
1411     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1412
1413     r = MsiSetProperty( hpkg, "", NULL );
1414     ok( r == ERROR_SUCCESS, "wrong return val\n");
1415
1416     /* try set and get some illegal property identifiers */
1417     r = MsiSetProperty( hpkg, "", "asdf" );
1418     ok( r == ERROR_FUNCTION_FAILED, "wrong return val\n");
1419
1420     r = MsiSetProperty( hpkg, "=", "asdf" );
1421     ok( r == ERROR_SUCCESS, "wrong return val\n");
1422
1423     r = MsiSetProperty( hpkg, " ", "asdf" );
1424     ok( r == ERROR_SUCCESS, "wrong return val\n");
1425
1426     r = MsiSetProperty( hpkg, "'", "asdf" );
1427     ok( r == ERROR_SUCCESS, "wrong return val\n");
1428
1429     sz = sizeof buffer;
1430     buffer[0]=0;
1431     r = MsiGetProperty( hpkg, "'", buffer, &sz );
1432     ok( r == ERROR_SUCCESS, "wrong return val\n");
1433     ok( !strcmp(buffer,"asdf"), "buffer was not changed\n");
1434
1435     /* set empty values */
1436     r = MsiSetProperty( hpkg, "boo", NULL );
1437     ok( r == ERROR_SUCCESS, "wrong return val\n");
1438     ok( check_prop_empty( hpkg, "boo"), "prop wasn't empty\n");
1439
1440     r = MsiSetProperty( hpkg, "boo", "" );
1441     ok( r == ERROR_SUCCESS, "wrong return val\n");
1442     ok( check_prop_empty( hpkg, "boo"), "prop wasn't empty\n");
1443
1444     /* set a non-empty value */
1445     r = MsiSetProperty( hpkg, "boo", "xyz" );
1446     ok( r == ERROR_SUCCESS, "wrong return val\n");
1447
1448     sz = 1;
1449     strcpy(buffer,"x");
1450     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
1451     ok( r == ERROR_MORE_DATA, "wrong return val\n");
1452     ok( buffer[0] == 0, "buffer was not changed\n");
1453     ok( sz == 3, "wrong size returned\n");
1454
1455     sz = 4;
1456     strcpy(buffer,"x");
1457     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
1458     ok( r == ERROR_SUCCESS, "wrong return val\n");
1459     ok( !strcmp(buffer,"xyz"), "buffer was not changed\n");
1460     ok( sz == 3, "wrong size returned\n");
1461
1462     sz = 3;
1463     strcpy(buffer,"x");
1464     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
1465     ok( r == ERROR_MORE_DATA, "wrong return val\n");
1466     ok( !strcmp(buffer,"xy"), "buffer was not changed\n");
1467     ok( sz == 3, "wrong size returned\n");
1468
1469     r = MsiSetProperty(hpkg, "SourceDir", "foo");
1470     ok( r == ERROR_SUCCESS, "wrong return val\n");
1471
1472     sz = 4;
1473     r = MsiGetProperty(hpkg, "SOURCEDIR", buffer, &sz);
1474     ok( r == ERROR_SUCCESS, "wrong return val\n");
1475     ok( !strcmp(buffer,""), "buffer wrong\n");
1476     ok( sz == 0, "wrong size returned\n");
1477
1478     sz = 4;
1479     r = MsiGetProperty(hpkg, "SOMERANDOMNAME", buffer, &sz);
1480     ok( r == ERROR_SUCCESS, "wrong return val\n");
1481     ok( !strcmp(buffer,""), "buffer wrong\n");
1482     ok( sz == 0, "wrong size returned\n");
1483
1484     sz = 4;
1485     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
1486     ok( r == ERROR_SUCCESS, "wrong return val\n");
1487     ok( !strcmp(buffer,"foo"), "buffer wrong\n");
1488     ok( sz == 3, "wrong size returned\n");
1489
1490     r = MsiSetProperty(hpkg, "MetadataCompName", "Photoshop.dll");
1491     ok( r == ERROR_SUCCESS, "wrong return val\n");
1492
1493     sz = 0;
1494     r = MsiGetProperty(hpkg, "MetadataCompName", NULL, &sz );
1495     ok( r == ERROR_SUCCESS, "return wrong\n");
1496     ok( sz == 13, "size wrong (%d)\n", sz);
1497
1498     sz = 13;
1499     r = MsiGetProperty(hpkg, "MetadataCompName", buffer, &sz );
1500     ok( r == ERROR_MORE_DATA, "return wrong\n");
1501     ok( !strcmp(buffer,"Photoshop.dl"), "buffer wrong\n");
1502
1503     MsiCloseHandle( hpkg );
1504     DeleteFile(msifile);
1505 }
1506
1507 static void test_properties_table(void)
1508 {
1509     const char *query;
1510     UINT r;
1511     MSIHANDLE hpkg, hdb;
1512     char buffer[0x10];
1513     DWORD sz;
1514
1515     hdb = create_package_db();
1516     ok( hdb, "failed to create package\n");
1517
1518     hpkg = package_from_db(hdb);
1519     ok( hpkg, "failed to create package\n");
1520
1521     query = "CREATE TABLE `_Properties` ( "
1522         "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
1523     r = run_query(hdb, query);
1524     ok(r == ERROR_INVALID_HANDLE, "failed to create table\n");
1525
1526     MsiCloseHandle( hpkg );
1527     DeleteFile(msifile);
1528
1529     hdb = create_package_db();
1530     ok( hdb, "failed to create package\n");
1531
1532     query = "CREATE TABLE `_Properties` ( "
1533         "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
1534     r = run_query(hdb, query);
1535     ok(r == ERROR_SUCCESS, "failed to create table\n");
1536
1537     query = "ALTER `_Properties` ADD `foo` INTEGER";
1538     r = run_query(hdb, query);
1539     ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add column\n");
1540
1541     query = "ALTER TABLE `_Properties` ADD `foo` INTEGER";
1542     r = run_query(hdb, query);
1543     ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add column\n");
1544
1545     query = "ALTER TABLE `_Properties` ADD `extra` INTEGER";
1546     r = run_query(hdb, query);
1547     todo_wine ok(r == ERROR_SUCCESS, "failed to add column\n");
1548
1549     hpkg = package_from_db(hdb);
1550     ok( hpkg, "failed to create package\n");
1551
1552     r = MsiSetProperty( hpkg, "foo", "bar");
1553     ok(r == ERROR_SUCCESS, "failed to create table\n");
1554
1555     sz = sizeof buffer;
1556     r = MsiGetProperty( hpkg, "foo", buffer, &sz);
1557     ok(r == ERROR_SUCCESS, "failed to create table\n");
1558
1559     MsiCloseHandle( hpkg );
1560     DeleteFile(msifile);
1561 }
1562
1563 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
1564 {
1565     MSIHANDLE htab = 0;
1566     UINT res;
1567
1568     res = MsiDatabaseOpenView( hdb, szQuery, &htab );
1569     if( res == ERROR_SUCCESS )
1570     {
1571         UINT r;
1572
1573         r = MsiViewExecute( htab, hrec );
1574         if( r != ERROR_SUCCESS )
1575         {
1576             res = r;
1577             fprintf(stderr,"MsiViewExecute failed %08x\n", res);
1578         }
1579
1580         r = MsiViewClose( htab );
1581         if( r != ERROR_SUCCESS )
1582             res = r;
1583
1584         r = MsiCloseHandle( htab );
1585         if( r != ERROR_SUCCESS )
1586             res = r;
1587     }
1588     return res;
1589 }
1590
1591 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
1592 {
1593     return try_query_param( hdb, szQuery, 0 );
1594 }
1595
1596 static void test_msipackage(void)
1597 {
1598     MSIHANDLE hdb = 0, hpack = 100;
1599     UINT r;
1600     const char *query;
1601     char name[10];
1602
1603     DeleteFile(msifile);
1604
1605     todo_wine {
1606     name[0] = 0;
1607     r = MsiOpenPackage(name, &hpack);
1608     ok(r == ERROR_SUCCESS, "failed to open package with no name\n");
1609     r = MsiCloseHandle(hpack);
1610     ok(r == ERROR_SUCCESS, "failed to close package\n");
1611     }
1612
1613     /* just MsiOpenDatabase should not create a file */
1614     r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1615     ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1616
1617     name[0]='#';
1618     name[1]=0;
1619     r = MsiOpenPackage(name, &hpack);
1620     ok(r == ERROR_INVALID_HANDLE, "MsiOpenPackage returned wrong code\n");
1621
1622     todo_wine {
1623     /* now try again with our empty database */
1624     sprintf(name, "#%ld", hdb);
1625     r = MsiOpenPackage(name, &hpack);
1626     ok(r == ERROR_INSTALL_PACKAGE_INVALID, "MsiOpenPackage returned wrong code\n");
1627     if (!r)    MsiCloseHandle(hpack);
1628     }
1629
1630     /* create a table */
1631     query = "CREATE TABLE `Property` ( "
1632             "`Property` CHAR(72), `Value` CHAR(0) "
1633             "PRIMARY KEY `Property`)";
1634     r = try_query(hdb, query);
1635     ok(r == ERROR_SUCCESS, "failed to create Properties table\n");
1636
1637     query = "CREATE TABLE `InstallExecuteSequence` ("
1638             "`Action` CHAR(72), `Condition` CHAR(0), `Sequence` INTEGER "
1639             "PRIMARY KEY `Action`)";
1640     r = try_query(hdb, query);
1641     ok(r == ERROR_SUCCESS, "failed to create InstallExecuteSequence table\n");
1642
1643     todo_wine {
1644     sprintf(name, "#%ld", hdb);
1645     r = MsiOpenPackage(name, &hpack);
1646     ok(r == ERROR_INSTALL_PACKAGE_INVALID, "MsiOpenPackage returned wrong code\n");
1647     if (!r)    MsiCloseHandle(hpack);
1648     }
1649
1650     r = MsiCloseHandle(hdb);
1651     ok(r == ERROR_SUCCESS, "MsiCloseHandle(database) failed\n");
1652     DeleteFile(msifile);
1653 }
1654
1655 static void test_formatrecord2(void)
1656 {
1657     MSIHANDLE hpkg, hrec ;
1658     char buffer[0x100];
1659     DWORD sz;
1660     UINT r;
1661
1662     hpkg = package_from_db(create_package_db());
1663     ok( hpkg, "failed to create package\n");
1664
1665     r = MsiSetProperty(hpkg, "Manufacturer", " " );
1666     ok( r == ERROR_SUCCESS, "set property failed\n");
1667
1668     hrec = MsiCreateRecord(2);
1669     ok(hrec, "create record failed\n");
1670
1671     r = MsiRecordSetString( hrec, 0, "[ProgramFilesFolder][Manufacturer]\\asdf");
1672     ok( r == ERROR_SUCCESS, "format record failed\n");
1673
1674     buffer[0] = 0;
1675     sz = sizeof buffer;
1676     r = MsiFormatRecord( hpkg, hrec, buffer, &sz );
1677
1678     r = MsiRecordSetString(hrec, 0, "[foo][1]");
1679     r = MsiRecordSetString(hrec, 1, "hoo");
1680     sz = sizeof buffer;
1681     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1682     ok( sz == 3, "size wrong\n");
1683     ok( 0 == strcmp(buffer,"hoo"), "wrong output %s\n",buffer);
1684     ok( r == ERROR_SUCCESS, "format failed\n");
1685
1686     r = MsiRecordSetString(hrec, 0, "x[~]x");
1687     sz = sizeof buffer;
1688     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1689     ok( sz == 3, "size wrong\n");
1690     ok( 0 == strcmp(buffer,"x"), "wrong output %s\n",buffer);
1691     ok( r == ERROR_SUCCESS, "format failed\n");
1692
1693     r = MsiRecordSetString(hrec, 0, "[foo.$%}][1]");
1694     r = MsiRecordSetString(hrec, 1, "hoo");
1695     sz = sizeof buffer;
1696     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1697     ok( sz == 3, "size wrong\n");
1698     ok( 0 == strcmp(buffer,"hoo"), "wrong output %s\n",buffer);
1699     ok( r == ERROR_SUCCESS, "format failed\n");
1700
1701     r = MsiRecordSetString(hrec, 0, "[\\[]");
1702     sz = sizeof buffer;
1703     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1704     ok( sz == 1, "size wrong\n");
1705     ok( 0 == strcmp(buffer,"["), "wrong output %s\n",buffer);
1706     ok( r == ERROR_SUCCESS, "format failed\n");
1707
1708     SetEnvironmentVariable("FOO", "BAR");
1709     r = MsiRecordSetString(hrec, 0, "[%FOO]");
1710     sz = sizeof buffer;
1711     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1712     ok( sz == 3, "size wrong\n");
1713     ok( 0 == strcmp(buffer,"BAR"), "wrong output %s\n",buffer);
1714     ok( r == ERROR_SUCCESS, "format failed\n");
1715
1716     r = MsiRecordSetString(hrec, 0, "[[1]]");
1717     r = MsiRecordSetString(hrec, 1, "%FOO");
1718     sz = sizeof buffer;
1719     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
1720     ok( sz == 3, "size wrong\n");
1721     ok( 0 == strcmp(buffer,"BAR"), "wrong output %s\n",buffer);
1722     ok( r == ERROR_SUCCESS, "format failed\n");
1723
1724     MsiCloseHandle( hrec );
1725     MsiCloseHandle( hpkg );
1726     DeleteFile(msifile);
1727 }
1728
1729 static void test_states(void)
1730 {
1731     MSIHANDLE hpkg;
1732     UINT r;
1733     MSIHANDLE hdb;
1734     INSTALLSTATE state, action;
1735
1736     hdb = create_package_db();
1737     ok ( hdb, "failed to create package database\n" );
1738
1739     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
1740     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
1741
1742     r = create_feature_table( hdb );
1743     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
1744
1745     r = create_component_table( hdb );
1746     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
1747
1748     /* msidbFeatureAttributesFavorLocal */
1749     r = add_feature_entry( hdb, "'one', '', '', '', 2, 1, '', 0" );
1750     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
1751
1752     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
1753     r = add_component_entry( hdb, "'alpha', '{467EC132-739D-4784-A37B-677AA43DBC94}', 'TARGETDIR', 0, '', 'alpha_file'" );
1754     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1755
1756     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
1757     r = add_component_entry( hdb, "'beta', '{2C1F189C-24A6-4C34-B26B-994A6C026506}', 'TARGETDIR', 1, '', 'beta_file'" );
1758     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1759
1760     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
1761     r = add_component_entry( hdb, "'gamma', '{C271E2A4-DE2E-4F70-86D1-6984AF7DE2CA}', 'TARGETDIR', 2, '', 'gamma_file'" );
1762     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1763
1764     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSharedDllRefCount */
1765     r = add_component_entry( hdb, "'theta', '{4EB3129D-81A8-48D5-9801-75600FED3DD9}', 'TARGETDIR', 8, '', 'theta_file'" );
1766     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1767
1768     /* msidbFeatureAttributesFavorSource */
1769     r = add_feature_entry( hdb, "'two', '', '', '', 2, 1, '', 1" );
1770     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
1771
1772     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesLocalOnly */
1773     r = add_component_entry( hdb, "'delta', '{938FD4F2-C648-4259-A03C-7AA3B45643F3}', 'TARGETDIR', 0, '', 'delta_file'" );
1774     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1775
1776     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
1777     r = add_component_entry( hdb, "'epsilon', '{D59713B6-C11D-47F2-A395-1E5321781190}', 'TARGETDIR', 1, '', 'epsilon_file'" );
1778     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1779
1780     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesOptional */
1781     r = add_component_entry( hdb, "'zeta', '{377D33AB-2FAA-42B9-A629-0C0DAE9B9C7A}', 'TARGETDIR', 2, '', 'zeta_file'" );
1782     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1783
1784     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSharedDllRefCount */
1785     r = add_component_entry( hdb, "'iota', '{5D36F871-B5ED-4801-9E0F-C46B9E5C9669}', 'TARGETDIR', 8, '', 'iota_file'" );
1786     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1787
1788     /* msidbFeatureAttributesFavorSource */
1789     r = add_feature_entry( hdb, "'three', '', '', '', 2, 1, '', 1" );
1790     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
1791
1792     /* msidbFeatureAttributesFavorLocal */
1793     r = add_feature_entry( hdb, "'four', '', '', '', 2, 1, '', 0" );
1794     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
1795
1796     /* disabled */
1797     r = add_feature_entry( hdb, "'five', '', '', '', 2, 0, '', 1" );
1798     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
1799
1800     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
1801     r = add_component_entry( hdb, "'eta', '{DD89003F-0DD4-41B8-81C0-3411A7DA2695}', 'TARGETDIR', 1, '', 'eta_file'" );
1802     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1803
1804     /* no feature parent:msidbComponentAttributesLocalOnly */
1805     r = add_component_entry( hdb, "'kappa', '{D6B93DC3-8DA5-4769-9888-42BFE156BB8B}', 'TARGETDIR', 1, '', 'kappa_file'" );
1806     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1807
1808     r = create_feature_components_table( hdb );
1809     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
1810
1811     r = add_feature_components_entry( hdb, "'one', 'alpha'" );
1812     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1813
1814     r = add_feature_components_entry( hdb, "'one', 'beta'" );
1815     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1816
1817     r = add_feature_components_entry( hdb, "'one', 'gamma'" );
1818     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1819
1820     r = add_feature_components_entry( hdb, "'one', 'theta'" );
1821     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1822
1823     r = add_feature_components_entry( hdb, "'two', 'delta'" );
1824     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1825
1826     r = add_feature_components_entry( hdb, "'two', 'epsilon'" );
1827     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1828
1829     r = add_feature_components_entry( hdb, "'two', 'zeta'" );
1830     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1831
1832     r = add_feature_components_entry( hdb, "'two', 'iota'" );
1833     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1834
1835     r = add_feature_components_entry( hdb, "'three', 'eta'" );
1836     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1837
1838     r = add_feature_components_entry( hdb, "'four', 'eta'" );
1839     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1840
1841     r = add_feature_components_entry( hdb, "'five', 'eta'" );
1842     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1843
1844     r = create_file_table( hdb );
1845     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
1846
1847     r = add_file_entry( hdb, "'alpha_file', 'alpha', 'alpha.txt', 100, '', '1033', 8192, 1" );
1848     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1849
1850     r = add_file_entry( hdb, "'beta_file', 'beta', 'beta.txt', 0, '', '1033', 8192, 1" );
1851     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1852
1853     r = add_file_entry( hdb, "'gamma_file', 'gamma', 'gamma.txt', 0, '', '1033', 8192, 1" );
1854     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1855
1856     r = add_file_entry( hdb, "'theta_file', 'theta', 'theta.txt', 0, '', '1033', 8192, 1" );
1857     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1858
1859     r = add_file_entry( hdb, "'delta_file', 'delta', 'delta.txt', 0, '', '1033', 8192, 1" );
1860     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1861
1862     r = add_file_entry( hdb, "'epsilon_file', 'epsilon', 'epsilon.txt', 0, '', '1033', 8192, 1" );
1863     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1864
1865     r = add_file_entry( hdb, "'zeta_file', 'zeta', 'zeta.txt', 0, '', '1033', 8192, 1" );
1866     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1867
1868     r = add_file_entry( hdb, "'iota_file', 'iota', 'iota.txt', 0, '', '1033', 8192, 1" );
1869     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1870
1871     /* compressed file */
1872     r = add_file_entry( hdb, "'eta_file', 'eta', 'eta.txt', 0, '', '1033', 16384, 1" );
1873     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1874
1875     r = add_file_entry( hdb, "'kappa_file', 'kappa', 'kappa.txt', 0, '', '1033', 8192, 1" );
1876     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
1877
1878     hpkg = package_from_db( hdb );
1879     ok( hpkg, "failed to create package\n");
1880
1881     MsiCloseHandle( hdb );
1882
1883     state = 0xdeadbee;
1884     action = 0xdeadbee;
1885     r = MsiGetFeatureState(hpkg, "one", &state, &action);
1886     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %d\n", r );
1887     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1888     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1889
1890     state = 0xdeadbee;
1891     action = 0xdeadbee;
1892     r = MsiGetFeatureState(hpkg, "two", &state, &action);
1893     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %d\n", r );
1894     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1895     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1896
1897     state = 0xdeadbee;
1898     action = 0xdeadbee;
1899     r = MsiGetFeatureState(hpkg, "three", &state, &action);
1900     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %d\n", r );
1901     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1902     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1903
1904     state = 0xdeadbee;
1905     action = 0xdeadbee;
1906     r = MsiGetFeatureState(hpkg, "four", &state, &action);
1907     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %d\n", r );
1908     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1909     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1910
1911     state = 0xdeadbee;
1912     action = 0xdeadbee;
1913     r = MsiGetFeatureState(hpkg, "five", &state, &action);
1914     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %d\n", r );
1915     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1916     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1917
1918     state = 0xdeadbee;
1919     action = 0xdeadbee;
1920     r = MsiGetComponentState(hpkg, "alpha", &state, &action);
1921     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1922     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1923     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1924
1925     state = 0xdeadbee;
1926     action = 0xdeadbee;
1927     r = MsiGetComponentState(hpkg, "beta", &state, &action);
1928     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1929     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1930     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1931
1932     state = 0xdeadbee;
1933     action = 0xdeadbee;
1934     r = MsiGetComponentState(hpkg, "gamma", &state, &action);
1935     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1936     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1937     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1938
1939     state = 0xdeadbee;
1940     action = 0xdeadbee;
1941     r = MsiGetComponentState(hpkg, "theta", &state, &action);
1942     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1943     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1944     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1945
1946     state = 0xdeadbee;
1947     action = 0xdeadbee;
1948     r = MsiGetComponentState(hpkg, "delta", &state, &action);
1949     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1950     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1951     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1952
1953     state = 0xdeadbee;
1954     action = 0xdeadbee;
1955     r = MsiGetComponentState(hpkg, "epsilon", &state, &action);
1956     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1957     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1958     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1959
1960     state = 0xdeadbee;
1961     action = 0xdeadbee;
1962     r = MsiGetComponentState(hpkg, "zeta", &state, &action);
1963     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1964     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1965     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1966
1967     state = 0xdeadbee;
1968     action = 0xdeadbee;
1969     r = MsiGetComponentState(hpkg, "iota", &state, &action);
1970     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1971     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1972     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1973
1974     state = 0xdeadbee;
1975     action = 0xdeadbee;
1976     r = MsiGetComponentState(hpkg, "eta", &state, &action);
1977     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1978     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1979     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1980
1981     state = 0xdeadbee;
1982     action = 0xdeadbee;
1983     r = MsiGetComponentState(hpkg, "kappa", &state, &action);
1984     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r );
1985     ok( state == 0xdeadbee, "Expected 0xdeadbee, got %d\n", state);
1986     ok( action == 0xdeadbee, "Expected 0xdeadbee, got %d\n", action);
1987
1988     r = MsiDoAction( hpkg, "CostInitialize");
1989     ok( r == ERROR_SUCCESS, "cost init failed\n");
1990
1991     state = 0xdeadbee;
1992     action = 0xdeadbee;
1993     r = MsiGetFeatureState(hpkg, "one", &state, &action);
1994     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
1995     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1996     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
1997
1998     state = 0xdeadbee;
1999     action = 0xdeadbee;
2000     r = MsiGetFeatureState(hpkg, "two", &state, &action);
2001     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2002     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2003     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2004
2005     state = 0xdeadbee;
2006     action = 0xdeadbee;
2007     r = MsiGetFeatureState(hpkg, "three", &state, &action);
2008     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2009     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2010     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2011
2012     state = 0xdeadbee;
2013     action = 0xdeadbee;
2014     r = MsiGetFeatureState(hpkg, "four", &state, &action);
2015     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2016     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2017     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2018
2019     state = 0xdeadbee;
2020     action = 0xdeadbee;
2021     r = MsiGetFeatureState(hpkg, "five", &state, &action);
2022     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2023     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2024     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2025
2026     state = 0xdeadbee;
2027     action = 0xdeadbee;
2028     r = MsiGetComponentState(hpkg, "alpha", &state, &action);
2029     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2030     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2031     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2032
2033     state = 0xdeadbee;
2034     action = 0xdeadbee;
2035     r = MsiGetComponentState(hpkg, "beta", &state, &action);
2036     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2037     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2038     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2039
2040     state = 0xdeadbee;
2041     action = 0xdeadbee;
2042     r = MsiGetComponentState(hpkg, "gamma", &state, &action);
2043     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2044     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2045     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2046
2047     state = 0xdeadbee;
2048     action = 0xdeadbee;
2049     r = MsiGetComponentState(hpkg, "theta", &state, &action);
2050     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2051     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2052     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2053
2054     state = 0xdeadbee;
2055     action = 0xdeadbee;
2056     r = MsiGetComponentState(hpkg, "delta", &state, &action);
2057     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2058     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2059     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2060
2061     state = 0xdeadbee;
2062     action = 0xdeadbee;
2063     r = MsiGetComponentState(hpkg, "epsilon", &state, &action);
2064     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2065     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2066     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2067
2068     state = 0xdeadbee;
2069     action = 0xdeadbee;
2070     r = MsiGetComponentState(hpkg, "zeta", &state, &action);
2071     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2072     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2073     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2074
2075     state = 0xdeadbee;
2076     action = 0xdeadbee;
2077     r = MsiGetComponentState(hpkg, "iota", &state, &action);
2078     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2079     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2080     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2081
2082     state = 0xdeadbee;
2083     action = 0xdeadbee;
2084     r = MsiGetComponentState(hpkg, "eta", &state, &action);
2085     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2086     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2087     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2088
2089     state = 0xdeadbee;
2090     action = 0xdeadbee;
2091     r = MsiGetComponentState(hpkg, "kappa", &state, &action);
2092     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2093     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2094     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2095
2096     r = MsiDoAction( hpkg, "FileCost");
2097     ok( r == ERROR_SUCCESS, "file cost failed\n");
2098
2099     state = 0xdeadbee;
2100     action = 0xdeadbee;
2101     r = MsiGetFeatureState(hpkg, "one", &state, &action);
2102     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2103     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2104     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2105
2106     state = 0xdeadbee;
2107     action = 0xdeadbee;
2108     r = MsiGetFeatureState(hpkg, "two", &state, &action);
2109     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2110     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2111     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2112
2113     state = 0xdeadbee;
2114     action = 0xdeadbee;
2115     r = MsiGetFeatureState(hpkg, "three", &state, &action);
2116     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2117     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2118     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2119
2120     state = 0xdeadbee;
2121     action = 0xdeadbee;
2122     r = MsiGetFeatureState(hpkg, "four", &state, &action);
2123     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2124     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2125     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2126
2127     state = 0xdeadbee;
2128     action = 0xdeadbee;
2129     r = MsiGetFeatureState(hpkg, "five", &state, &action);
2130     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2131     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2132     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2133
2134     state = 0xdeadbee;
2135     action = 0xdeadbee;
2136     r = MsiGetComponentState(hpkg, "alpha", &state, &action);
2137     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2138     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2139     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2140
2141     state = 0xdeadbee;
2142     action = 0xdeadbee;
2143     r = MsiGetComponentState(hpkg, "beta", &state, &action);
2144     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2145     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2146     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2147
2148     state = 0xdeadbee;
2149     action = 0xdeadbee;
2150     r = MsiGetComponentState(hpkg, "gamma", &state, &action);
2151     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2152     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2153     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2154
2155     state = 0xdeadbee;
2156     action = 0xdeadbee;
2157     r = MsiGetComponentState(hpkg, "theta", &state, &action);
2158     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2159     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2160     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2161
2162     state = 0xdeadbee;
2163     action = 0xdeadbee;
2164     r = MsiGetComponentState(hpkg, "delta", &state, &action);
2165     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2166     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2167     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2168
2169     state = 0xdeadbee;
2170     action = 0xdeadbee;
2171     r = MsiGetComponentState(hpkg, "epsilon", &state, &action);
2172     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2173     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2174     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2175
2176     state = 0xdeadbee;
2177     action = 0xdeadbee;
2178     r = MsiGetComponentState(hpkg, "zeta", &state, &action);
2179     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2180     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2181     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2182
2183     state = 0xdeadbee;
2184     action = 0xdeadbee;
2185     r = MsiGetComponentState(hpkg, "iota", &state, &action);
2186     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2187     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2188     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2189
2190     state = 0xdeadbee;
2191     action = 0xdeadbee;
2192     r = MsiGetComponentState(hpkg, "eta", &state, &action);
2193     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2194     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2195     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2196
2197     state = 0xdeadbee;
2198     action = 0xdeadbee;
2199     r = MsiGetComponentState(hpkg, "kappa", &state, &action);
2200     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2201     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2202     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2203
2204     r = MsiDoAction( hpkg, "CostFinalize");
2205     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
2206
2207     state = 0xdeadbee;
2208     action = 0xdeadbee;
2209     r = MsiGetFeatureState(hpkg, "one", &state, &action);
2210     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2211     ok( state == INSTALLSTATE_ABSENT, "Expected one INSTALLSTATE_ABSENT, got %d\n", state);
2212     ok( action == INSTALLSTATE_LOCAL, "Expected one INSTALLSTATE_LOCAL, got %d\n", action);
2213
2214     state = 0xdeadbee;
2215     action = 0xdeadbee;
2216     r = MsiGetFeatureState(hpkg, "two", &state, &action);
2217     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2218     ok( state == INSTALLSTATE_ABSENT, "Expected two INSTALLSTATE_ABSENT, got %d\n", state);
2219     ok( action == INSTALLSTATE_SOURCE, "Expected two INSTALLSTATE_SOURCE, got %d\n", action);
2220
2221     state = 0xdeadbee;
2222     action = 0xdeadbee;
2223     r = MsiGetFeatureState(hpkg, "three", &state, &action);
2224     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2225     ok( state == INSTALLSTATE_ABSENT, "Expected three INSTALLSTATE_ABSENT, got %d\n", state);
2226     ok( action == INSTALLSTATE_LOCAL, "Expected three INSTALLSTATE_LOCAL, got %d\n", action);
2227
2228     state = 0xdeadbee;
2229     action = 0xdeadbee;
2230     r = MsiGetFeatureState(hpkg, "four", &state, &action);
2231     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2232     ok( state == INSTALLSTATE_ABSENT, "Expected four INSTALLSTATE_ABSENT, got %d\n", state);
2233     ok( action == INSTALLSTATE_LOCAL, "Expected four INSTALLSTATE_LOCAL, got %d\n", action);
2234
2235     state = 0xdeadbee;
2236     action = 0xdeadbee;
2237     r = MsiGetFeatureState(hpkg, "five", &state, &action);
2238     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2239     ok( state == INSTALLSTATE_ABSENT, "Expected five INSTALLSTATE_ABSENT, got %d\n", state);
2240     ok( action == INSTALLSTATE_UNKNOWN, "Expected five INSTALLSTATE_UNKNOWN, got %d\n", action);
2241
2242     state = 0xdeadbee;
2243     action = 0xdeadbee;
2244     r = MsiGetComponentState(hpkg, "alpha", &state, &action);
2245     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2246     ok( state == INSTALLSTATE_ABSENT, "Expected alpha INSTALLSTATE_ABSENT, got %d\n", state);
2247     ok( action == INSTALLSTATE_LOCAL, "Expected alpha INSTALLSTATE_LOCAL, got %d\n", action);
2248
2249     state = 0xdeadbee;
2250     action = 0xdeadbee;
2251     r = MsiGetComponentState(hpkg, "beta", &state, &action);
2252     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2253     ok( state == INSTALLSTATE_ABSENT, "Expected beta INSTALLSTATE_ABSENT, got %d\n", state);
2254     ok( action == INSTALLSTATE_SOURCE, "Expected beta INSTALLSTATE_SOURCE, got %d\n", action);
2255
2256     state = 0xdeadbee;
2257     action = 0xdeadbee;
2258     r = MsiGetComponentState(hpkg, "gamma", &state, &action);
2259     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2260     ok( state == INSTALLSTATE_ABSENT, "Expected gamma INSTALLSTATE_ABSENT, got %d\n", state);
2261     ok( action == INSTALLSTATE_LOCAL, "Expected gamma INSTALLSTATE_LOCAL, got %d\n", action);
2262
2263     state = 0xdeadbee;
2264     action = 0xdeadbee;
2265     r = MsiGetComponentState(hpkg, "theta", &state, &action);
2266     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2267     ok( state == INSTALLSTATE_ABSENT, "Expected theta INSTALLSTATE_ABSENT, got %d\n", state);
2268     ok( action == INSTALLSTATE_LOCAL, "Expected theta INSTALLSTATE_LOCAL, got %d\n", action);
2269
2270     state = 0xdeadbee;
2271     action = 0xdeadbee;
2272     r = MsiGetComponentState(hpkg, "delta", &state, &action);
2273     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2274     ok( state == INSTALLSTATE_ABSENT, "Expected delta INSTALLSTATE_ABSENT, got %d\n", state);
2275     ok( action == INSTALLSTATE_LOCAL, "Expected delta INSTALLSTATE_LOCAL, got %d\n", action);
2276
2277     state = 0xdeadbee;
2278     action = 0xdeadbee;
2279     r = MsiGetComponentState(hpkg, "epsilon", &state, &action);
2280     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2281     ok( state == INSTALLSTATE_ABSENT, "Expected epsilon INSTALLSTATE_ABSENT, got %d\n", state);
2282     ok( action == INSTALLSTATE_SOURCE, "Expected epsilon INSTALLSTATE_SOURCE, got %d\n", action);
2283
2284     state = 0xdeadbee;
2285     action = 0xdeadbee;
2286     r = MsiGetComponentState(hpkg, "zeta", &state, &action);
2287     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2288     ok( state == INSTALLSTATE_ABSENT, "Expected zeta INSTALLSTATE_ABSENT, got %d\n", state);
2289     ok( action == INSTALLSTATE_SOURCE, "Expected zeta INSTALLSTATE_SOURCE, got %d\n", action);
2290
2291     state = 0xdeadbee;
2292     action = 0xdeadbee;
2293     r = MsiGetComponentState(hpkg, "iota", &state, &action);
2294     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2295     ok( state == INSTALLSTATE_ABSENT, "Expected iota INSTALLSTATE_ABSENT, got %d\n", state);
2296     ok( action == INSTALLSTATE_LOCAL, "Expected iota INSTALLSTATE_LOCAL, got %d\n", action);
2297
2298     state = 0xdeadbee;
2299     action = 0xdeadbee;
2300     r = MsiGetComponentState(hpkg, "eta", &state, &action);
2301     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2302     ok( state == INSTALLSTATE_ABSENT, "Expected eta INSTALLSTATE_ABSENT, got %d\n", state);
2303     ok( action == INSTALLSTATE_LOCAL, "Expected eta INSTALLSTATE_LOCAL, got %d\n", action);
2304
2305     state = 0xdeadbee;
2306     action = 0xdeadbee;
2307     r = MsiGetComponentState(hpkg, "kappa", &state, &action);
2308     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2309     ok( state == INSTALLSTATE_ABSENT, "Expected kappa INSTALLSTATE_ABSENT, got %d\n", state);
2310     ok( action == INSTALLSTATE_UNKNOWN, "Expected kappa INSTALLSTATE_UNKNOWN, got %d\n", action);
2311
2312     MsiCloseHandle( hpkg );
2313     DeleteFileA( msifile );
2314 }
2315
2316 static void test_getproperty(void)
2317 {
2318     MSIHANDLE hPackage = 0;
2319     char prop[100];
2320     static CHAR empty[] = "";
2321     DWORD size;
2322     UINT r;
2323
2324     hPackage = package_from_db(create_package_db());
2325     ok( hPackage != 0, " Failed to create package\n");
2326
2327     /* set the property */
2328     r = MsiSetProperty(hPackage, "Name", "Value");
2329     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2330
2331     /* retrieve the size, NULL pointer */
2332     size = 0;
2333     r = MsiGetProperty(hPackage, "Name", NULL, &size);
2334     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2335     ok( size == 5, "Expected 5, got %d\n", size);
2336
2337     /* retrieve the size, empty string */
2338     size = 0;
2339     r = MsiGetProperty(hPackage, "Name", empty, &size);
2340     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
2341     ok( size == 5, "Expected 5, got %d\n", size);
2342
2343     /* don't change size */
2344     r = MsiGetProperty(hPackage, "Name", prop, &size);
2345     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
2346     ok( size == 5, "Expected 5, got %d\n", size);
2347     ok( !lstrcmp(prop, "Valu"), "Expected Valu, got %s\n", prop);
2348
2349     /* increase the size by 1 */
2350     size++;
2351     r = MsiGetProperty(hPackage, "Name", prop, &size);
2352     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2353     ok( size == 5, "Expected 5, got %d\n", size);
2354     ok( !lstrcmp(prop, "Value"), "Expected Value, got %s\n", prop);
2355
2356     r = MsiCloseHandle( hPackage);
2357     ok( r == ERROR_SUCCESS , "Failed to close package\n" );
2358     DeleteFile(msifile);
2359 }
2360
2361 static void test_removefiles(void)
2362 {
2363     MSIHANDLE hpkg;
2364     UINT r;
2365     MSIHANDLE hdb;
2366     char CURR_DIR[MAX_PATH];
2367
2368     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2369
2370     hdb = create_package_db();
2371     ok ( hdb, "failed to create package database\n" );
2372
2373     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
2374     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
2375
2376     r = create_feature_table( hdb );
2377     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
2378
2379     r = create_component_table( hdb );
2380     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2381
2382     r = add_feature_entry( hdb, "'one', '', '', '', 2, 1, '', 0" );
2383     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2384
2385     r = add_component_entry( hdb, "'hydrogen', '', 'TARGETDIR', 0, '', 'hydrogen_file'" );
2386     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2387
2388     r = add_component_entry( hdb, "'helium', '', 'TARGETDIR', 0, '', 'helium_file'" );
2389     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2390
2391     r = add_component_entry( hdb, "'lithium', '', 'TARGETDIR', 0, '', 'lithium_file'" );
2392     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2393
2394     r = add_component_entry( hdb, "'beryllium', '', 'TARGETDIR', 0, '', 'beryllium_file'" );
2395     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2396
2397     r = add_component_entry( hdb, "'boron', '', 'TARGETDIR', 0, '', 'boron_file'" );
2398     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2399
2400     r = add_component_entry( hdb, "'carbon', '', 'TARGETDIR', 0, '', 'carbon_file'" );
2401     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2402
2403     r = create_feature_components_table( hdb );
2404     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2405
2406     r = add_feature_components_entry( hdb, "'one', 'hydrogen'" );
2407     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2408
2409     r = add_feature_components_entry( hdb, "'one', 'helium'" );
2410     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2411
2412     r = add_feature_components_entry( hdb, "'one', 'lithium'" );
2413     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2414
2415     r = add_feature_components_entry( hdb, "'one', 'beryllium'" );
2416     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2417
2418     r = add_feature_components_entry( hdb, "'one', 'boron'" );
2419     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2420
2421     r = add_feature_components_entry( hdb, "'one', 'carbon'" );
2422     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2423
2424     r = create_file_table( hdb );
2425     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
2426
2427     r = add_file_entry( hdb, "'hydrogen_file', 'hydrogen', 'hydrogen.txt', 0, '', '1033', 8192, 1" );
2428     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2429
2430     r = add_file_entry( hdb, "'helium_file', 'helium', 'helium.txt', 0, '', '1033', 8192, 1" );
2431     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2432
2433     r = add_file_entry( hdb, "'lithium_file', 'lithium', 'lithium.txt', 0, '', '1033', 8192, 1" );
2434     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2435
2436     r = add_file_entry( hdb, "'beryllium_file', 'beryllium', 'beryllium.txt', 0, '', '1033', 16384, 1" );
2437     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2438
2439     r = add_file_entry( hdb, "'boron_file', 'boron', 'boron.txt', 0, '', '1033', 16384, 1" );
2440     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2441
2442     r = add_file_entry( hdb, "'carbon_file', 'carbon', 'carbon.txt', 0, '', '1033', 16384, 1" );
2443     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2444
2445     r = create_remove_file_table( hdb );
2446     ok( r == ERROR_SUCCESS, "cannot create Remove File table: %d\n", r);
2447
2448     hpkg = package_from_db( hdb );
2449     ok( hpkg, "failed to create package\n");
2450
2451     MsiCloseHandle( hdb );
2452
2453     create_test_file( "hydrogen.txt" );
2454     create_test_file( "helium.txt" );
2455     create_test_file( "lithium.txt" );
2456     create_test_file( "beryllium.txt" );
2457     create_test_file( "boron.txt" );
2458     create_test_file( "carbon.txt" );
2459
2460     r = MsiSetProperty( hpkg, "TARGETDIR", CURR_DIR );
2461     ok( r == ERROR_SUCCESS, "set property failed\n");
2462
2463     r = MsiDoAction( hpkg, "CostInitialize");
2464     ok( r == ERROR_SUCCESS, "cost init failed\n");
2465
2466     r = MsiDoAction( hpkg, "FileCost");
2467     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
2468
2469     r = MsiDoAction( hpkg, "CostFinalize");
2470     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
2471
2472     r = MsiDoAction( hpkg, "InstallValidate");
2473     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
2474
2475     r = MsiSetComponentState( hpkg, "hydrogen", INSTALLSTATE_ABSENT );
2476     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2477
2478     r = MsiSetComponentState( hpkg, "helium", INSTALLSTATE_LOCAL );
2479     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2480
2481     r = MsiSetComponentState( hpkg, "lithium", INSTALLSTATE_SOURCE );
2482     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2483
2484     r = MsiSetComponentState( hpkg, "beryllium", INSTALLSTATE_ABSENT );
2485     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2486
2487     r = MsiSetComponentState( hpkg, "boron", INSTALLSTATE_LOCAL );
2488     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2489
2490     r = MsiSetComponentState( hpkg, "carbon", INSTALLSTATE_SOURCE );
2491     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
2492
2493     r = MsiDoAction( hpkg, "RemoveFiles");
2494     ok( r == ERROR_SUCCESS, "remove files failed\n");
2495
2496     ok(DeleteFileA("hydrogen.txt"), "Expected hydrogen.txt to exist\n");
2497     ok(DeleteFileA("lithium.txt"), "Expected lithium.txt to exist\n");    
2498     ok(DeleteFileA("beryllium.txt"), "Expected beryllium.txt to exist\n");
2499     ok(DeleteFileA("carbon.txt"), "Expected carbon.txt to exist\n");
2500     ok(DeleteFileA("helium.txt"), "Expected helium.txt to exist\n");
2501     ok(DeleteFileA("boron.txt"), "Expected boron.txt to exist\n");
2502
2503     MsiCloseHandle( hpkg );
2504     DeleteFileA(msifile);
2505 }
2506
2507 static void test_appsearch(void)
2508 {
2509     MSIHANDLE hpkg;
2510     UINT r;
2511     MSIHANDLE hdb;
2512     CHAR prop[MAX_PATH];
2513     DWORD size = MAX_PATH;
2514
2515     hdb = create_package_db();
2516     ok ( hdb, "failed to create package database\n" );
2517
2518     r = create_appsearch_table( hdb );
2519     ok( r == ERROR_SUCCESS, "cannot create AppSearch table: %d\n", r );
2520
2521     r = add_appsearch_entry( hdb, "'WEBBROWSERPROG', 'NewSignature1'" );
2522     ok( r == ERROR_SUCCESS, "cannot add entry: %d\n", r );
2523
2524     r = create_reglocator_table( hdb );
2525     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
2526
2527     r = add_reglocator_entry( hdb, "'NewSignature1', 0, 'htmlfile\\shell\\open\\command', '', 1" );
2528     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
2529
2530     r = create_signature_table( hdb );
2531     ok( r == ERROR_SUCCESS, "cannot create Signature table: %d\n", r );
2532
2533     r = add_signature_entry( hdb, "'NewSignature1', 'FileName', '', '', '', '', '', '', ''" );
2534     ok( r == ERROR_SUCCESS, "cannot create Signature table: %d\n", r );
2535
2536     hpkg = package_from_db( hdb );
2537     ok( hpkg, "failed to create package\n");
2538
2539     MsiCloseHandle( hdb );
2540
2541     r = MsiDoAction( hpkg, "AppSearch" );
2542     ok( r == ERROR_SUCCESS, "AppSearch failed: %d\n", r);
2543
2544     r = MsiGetPropertyA( hpkg, "WEBBROWSERPROG", prop, &size );
2545     ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
2546     ok( lstrlenA(prop) != 0, "Expected non-zero length\n");
2547
2548     MsiCloseHandle( hpkg );
2549     DeleteFileA(msifile);
2550 }
2551
2552 static void test_featureparents(void)
2553 {
2554     MSIHANDLE hpkg;
2555     UINT r;
2556     MSIHANDLE hdb;
2557     INSTALLSTATE state, action;
2558
2559     hdb = create_package_db();
2560     ok ( hdb, "failed to create package database\n" );
2561
2562     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
2563     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
2564
2565     r = create_feature_table( hdb );
2566     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
2567
2568     r = create_component_table( hdb );
2569     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2570
2571     r = create_feature_components_table( hdb );
2572     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2573
2574     r = create_file_table( hdb );
2575     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
2576
2577     /* msidbFeatureAttributesFavorLocal */
2578     r = add_feature_entry( hdb, "'zodiac', '', '', '', 2, 1, '', 0" );
2579     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2580
2581     /* msidbFeatureAttributesFavorSource */
2582     r = add_feature_entry( hdb, "'perseus', '', '', '', 2, 1, '', 1" );
2583     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2584
2585     /* msidbFeatureAttributesFavorLocal */
2586     r = add_feature_entry( hdb, "'orion', '', '', '', 2, 1, '', 0" );
2587     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2588
2589     /* disabled because of install level */
2590     r = add_feature_entry( hdb, "'waters', '', '', '', 15, 101, '', 9" );
2591     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2592
2593     /* child feature of disabled feature */
2594     r = add_feature_entry( hdb, "'bayer', 'waters', '', '', 14, 1, '', 9" );
2595     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2596
2597     /* component of disabled feature (install level) */
2598     r = add_component_entry( hdb, "'delphinus', '', 'TARGETDIR', 0, '', 'delphinus_file'" );
2599     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2600
2601     /* component of disabled child feature (install level) */
2602     r = add_component_entry( hdb, "'hydrus', '', 'TARGETDIR', 0, '', 'hydrus_file'" );
2603     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2604
2605     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
2606     r = add_component_entry( hdb, "'leo', '', 'TARGETDIR', 0, '', 'leo_file'" );
2607     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2608
2609     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
2610     r = add_component_entry( hdb, "'virgo', '', 'TARGETDIR', 1, '', 'virgo_file'" );
2611     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2612
2613     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
2614     r = add_component_entry( hdb, "'libra', '', 'TARGETDIR', 2, '', 'libra_file'" );
2615     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2616
2617     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesLocalOnly */
2618     r = add_component_entry( hdb, "'cassiopeia', '', 'TARGETDIR', 0, '', 'cassiopeia_file'" );
2619     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2620
2621     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
2622     r = add_component_entry( hdb, "'cepheus', '', 'TARGETDIR', 1, '', 'cepheus_file'" );
2623     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2624
2625     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesOptional */
2626     r = add_component_entry( hdb, "'andromeda', '', 'TARGETDIR', 2, '', 'andromeda_file'" );
2627     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2628
2629     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
2630     r = add_component_entry( hdb, "'canis', '', 'TARGETDIR', 0, '', 'canis_file'" );
2631     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2632
2633     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
2634     r = add_component_entry( hdb, "'monoceros', '', 'TARGETDIR', 1, '', 'monoceros_file'" );
2635     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2636
2637     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
2638     r = add_component_entry( hdb, "'lepus', '', 'TARGETDIR', 2, '', 'lepus_file'" );
2639
2640     r = add_feature_components_entry( hdb, "'zodiac', 'leo'" );
2641     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2642
2643     r = add_feature_components_entry( hdb, "'zodiac', 'virgo'" );
2644     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2645
2646     r = add_feature_components_entry( hdb, "'zodiac', 'libra'" );
2647     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2648
2649     r = add_feature_components_entry( hdb, "'perseus', 'cassiopeia'" );
2650     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2651
2652     r = add_feature_components_entry( hdb, "'perseus', 'cepheus'" );
2653     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2654
2655     r = add_feature_components_entry( hdb, "'perseus', 'andromeda'" );
2656     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2657
2658     r = add_feature_components_entry( hdb, "'orion', 'leo'" );
2659     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2660
2661     r = add_feature_components_entry( hdb, "'orion', 'virgo'" );
2662     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2663
2664     r = add_feature_components_entry( hdb, "'orion', 'libra'" );
2665     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2666
2667     r = add_feature_components_entry( hdb, "'orion', 'cassiopeia'" );
2668     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2669
2670     r = add_feature_components_entry( hdb, "'orion', 'cepheus'" );
2671     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2672
2673     r = add_feature_components_entry( hdb, "'orion', 'andromeda'" );
2674     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2675
2676     r = add_feature_components_entry( hdb, "'orion', 'canis'" );
2677     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2678
2679     r = add_feature_components_entry( hdb, "'orion', 'monoceros'" );
2680     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2681
2682     r = add_feature_components_entry( hdb, "'orion', 'lepus'" );
2683     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2684
2685     r = add_feature_components_entry( hdb, "'waters', 'delphinus'" );
2686     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2687
2688     r = add_feature_components_entry( hdb, "'bayer', 'hydrus'" );
2689     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2690
2691     r = add_file_entry( hdb, "'leo_file', 'leo', 'leo.txt', 100, '', '1033', 8192, 1" );
2692     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2693
2694     r = add_file_entry( hdb, "'virgo_file', 'virgo', 'virgo.txt', 0, '', '1033', 8192, 1" );
2695     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2696
2697     r = add_file_entry( hdb, "'libra_file', 'libra', 'libra.txt', 0, '', '1033', 8192, 1" );
2698     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2699
2700     r = add_file_entry( hdb, "'cassiopeia_file', 'cassiopeia', 'cassiopeia.txt', 0, '', '1033', 8192, 1" );
2701     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2702
2703     r = add_file_entry( hdb, "'cepheus_file', 'cepheus', 'cepheus.txt', 0, '', '1033', 8192, 1" );
2704     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2705
2706     r = add_file_entry( hdb, "'andromeda_file', 'andromeda', 'andromeda.txt', 0, '', '1033', 8192, 1" );
2707     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2708
2709     r = add_file_entry( hdb, "'canis_file', 'canis', 'canis.txt', 0, '', '1033', 8192, 1" );
2710     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2711
2712     r = add_file_entry( hdb, "'monoceros_file', 'monoceros', 'monoceros.txt', 0, '', '1033', 8192, 1" );
2713     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2714
2715     r = add_file_entry( hdb, "'lepus_file', 'lepus', 'lepus.txt', 0, '', '1033', 8192, 1" );
2716     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2717
2718     r = add_file_entry( hdb, "'delphinus_file', 'delphinus', 'delphinus.txt', 0, '', '1033', 8192, 1" );
2719     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2720
2721     r = add_file_entry( hdb, "'hydrus_file', 'hydrus', 'hydrus.txt', 0, '', '1033', 8192, 1" );
2722     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2723
2724     hpkg = package_from_db( hdb );
2725     ok( hpkg, "failed to create package\n");
2726
2727     MsiCloseHandle( hdb );
2728
2729     r = MsiDoAction( hpkg, "CostInitialize");
2730     ok( r == ERROR_SUCCESS, "cost init failed\n");
2731
2732     r = MsiDoAction( hpkg, "FileCost");
2733     ok( r == ERROR_SUCCESS, "file cost failed\n");
2734
2735     r = MsiDoAction( hpkg, "CostFinalize");
2736     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
2737
2738     state = 0xdeadbee;
2739     action = 0xdeadbee;
2740     r = MsiGetFeatureState(hpkg, "zodiac", &state, &action);
2741     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2742     ok( state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2743     ok( action == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", action);
2744
2745     state = 0xdeadbee;
2746     action = 0xdeadbee;
2747     r = MsiGetFeatureState(hpkg, "perseus", &state, &action);
2748     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2749     ok( state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2750     ok( action == INSTALLSTATE_SOURCE, "Expected INSTALLSTATE_SOURCE, got %d\n", action);
2751
2752     state = 0xdeadbee;
2753     action = 0xdeadbee;
2754     r = MsiGetFeatureState(hpkg, "orion", &state, &action);
2755     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2756     ok( state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2757     ok( action == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", action);
2758
2759     state = 0xdeadbee;
2760     action = 0xdeadbee;
2761     r = MsiGetFeatureState(hpkg, "waters", &state, &action);
2762     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2763     ok( state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2764     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2765
2766     state = 0xdeadbee;
2767     action = 0xdeadbee;
2768     r = MsiGetFeatureState(hpkg, "bayer", &state, &action);
2769     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2770     ok( state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2771     ok( action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
2772
2773     state = 0xdeadbee;
2774     action = 0xdeadbee;
2775     r = MsiGetComponentState(hpkg, "leo", &state, &action);
2776     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2777     ok( state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2778     ok( action == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", action);
2779
2780     state = 0xdeadbee;
2781     action = 0xdeadbee;
2782     r = MsiGetComponentState(hpkg, "virgo", &state, &action);
2783     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2784     ok( state == INSTALLSTATE_UNKNOWN, "Expected virgo INSTALLSTATE_UNKNOWN, got %d\n", state);
2785     ok( action == INSTALLSTATE_SOURCE, "Expected virgo INSTALLSTATE_SOURCE, got %d\n", action);
2786
2787     state = 0xdeadbee;
2788     action = 0xdeadbee;
2789     r = MsiGetComponentState(hpkg, "libra", &state, &action);
2790     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2791     ok( state == INSTALLSTATE_UNKNOWN, "Expected libra INSTALLSTATE_UNKNOWN, got %d\n", state);
2792     ok( action == INSTALLSTATE_LOCAL, "Expected libra INSTALLSTATE_LOCAL, got %d\n", action);
2793
2794     state = 0xdeadbee;
2795     action = 0xdeadbee;
2796     r = MsiGetComponentState(hpkg, "cassiopeia", &state, &action);
2797     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2798     ok( state == INSTALLSTATE_UNKNOWN, "Expected cassiopeia INSTALLSTATE_UNKNOWN, got %d\n", state);
2799     ok( action == INSTALLSTATE_LOCAL, "Expected cassiopeia INSTALLSTATE_LOCAL, got %d\n", action);
2800
2801     state = 0xdeadbee;
2802     action = 0xdeadbee;
2803     r = MsiGetComponentState(hpkg, "cepheus", &state, &action);
2804     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2805     ok( state == INSTALLSTATE_UNKNOWN, "Expected cepheus INSTALLSTATE_UNKNOWN, got %d\n", state);
2806     ok( action == INSTALLSTATE_SOURCE, "Expected cepheus INSTALLSTATE_SOURCE, got %d\n", action);
2807
2808     state = 0xdeadbee;
2809     action = 0xdeadbee;
2810     r = MsiGetComponentState(hpkg, "andromeda", &state, &action);
2811     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2812     ok( state == INSTALLSTATE_UNKNOWN, "Expected andromeda INSTALLSTATE_UNKNOWN, got %d\n", state);
2813     ok( action == INSTALLSTATE_LOCAL, "Expected andromeda INSTALLSTATE_LOCAL, got %d\n", action);
2814
2815     state = 0xdeadbee;
2816     action = 0xdeadbee;
2817     r = MsiGetComponentState(hpkg, "canis", &state, &action);
2818     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2819     ok( state == INSTALLSTATE_UNKNOWN, "Expected canis INSTALLSTATE_UNKNOWN, got %d\n", state);
2820     ok( action == INSTALLSTATE_LOCAL, "Expected canis INSTALLSTATE_LOCAL, got %d\n", action);
2821
2822     state = 0xdeadbee;
2823     action = 0xdeadbee;
2824     r = MsiGetComponentState(hpkg, "monoceros", &state, &action);
2825     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2826     ok( state == INSTALLSTATE_UNKNOWN, "Expected monoceros INSTALLSTATE_UNKNOWN, got %d\n", state);
2827     ok( action == INSTALLSTATE_SOURCE, "Expected monoceros INSTALLSTATE_SOURCE, got %d\n", action);
2828
2829     state = 0xdeadbee;
2830     action = 0xdeadbee;
2831     r = MsiGetComponentState(hpkg, "lepus", &state, &action);
2832     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2833     ok( state == INSTALLSTATE_UNKNOWN, "Expected lepus INSTALLSTATE_UNKNOWN, got %d\n", state);
2834     ok( action == INSTALLSTATE_LOCAL, "Expected lepus INSTALLSTATE_LOCAL, got %d\n", action);
2835
2836     state = 0xdeadbee;
2837     action = 0xdeadbee;
2838     r = MsiGetComponentState(hpkg, "delphinus", &state, &action);
2839     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2840     ok( state == INSTALLSTATE_UNKNOWN, "Expected delphinus INSTALLSTATE_UNKNOWN, got %d\n", state);
2841     ok( action == INSTALLSTATE_UNKNOWN, "Expected delphinus INSTALLSTATE_UNKNOWN, got %d\n", action);
2842
2843     state = 0xdeadbee;
2844     action = 0xdeadbee;
2845     r = MsiGetComponentState(hpkg, "hydrus", &state, &action);
2846     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2847     ok( state == INSTALLSTATE_UNKNOWN, "Expected hydrus INSTALLSTATE_UNKNOWN, got %d\n", state);
2848     ok( action == INSTALLSTATE_UNKNOWN, "Expected hydrus INSTALLSTATE_UNKNOWN, got %d\n", action);
2849
2850     r = MsiSetFeatureState(hpkg, "orion", INSTALLSTATE_ABSENT);
2851     ok( r == ERROR_SUCCESS, "failed to set feature state: %d\n", r);
2852
2853     state = 0xdeadbee;
2854     action = 0xdeadbee;
2855     r = MsiGetFeatureState(hpkg, "zodiac", &state, &action);
2856     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2857     ok( state == INSTALLSTATE_ABSENT, "Expected zodiac INSTALLSTATE_ABSENT, got %d\n", state);
2858     ok( action == INSTALLSTATE_LOCAL, "Expected zodiac INSTALLSTATE_LOCAL, got %d\n", action);
2859
2860     state = 0xdeadbee;
2861     action = 0xdeadbee;
2862     r = MsiGetFeatureState(hpkg, "perseus", &state, &action);
2863     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2864     ok( state == INSTALLSTATE_ABSENT, "Expected perseus INSTALLSTATE_ABSENT, got %d\n", state);
2865     ok( action == INSTALLSTATE_SOURCE, "Expected perseus INSTALLSTATE_SOURCE, got %d\n", action);
2866
2867     state = 0xdeadbee;
2868     action = 0xdeadbee;
2869     r = MsiGetFeatureState(hpkg, "orion", &state, &action);
2870     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2871     ok( state == INSTALLSTATE_ABSENT, "Expected orion INSTALLSTATE_ABSENT, got %d\n", state);
2872     ok( action == INSTALLSTATE_ABSENT, "Expected orion INSTALLSTATE_ABSENT, got %d\n", action);
2873
2874     state = 0xdeadbee;
2875     action = 0xdeadbee;
2876     r = MsiGetComponentState(hpkg, "leo", &state, &action);
2877     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2878     ok( state == INSTALLSTATE_UNKNOWN, "Expected leo INSTALLSTATE_UNKNOWN, got %d\n", state);
2879     ok( action == INSTALLSTATE_LOCAL, "Expected leo INSTALLSTATE_LOCAL, got %d\n", action);
2880
2881     state = 0xdeadbee;
2882     action = 0xdeadbee;
2883     r = MsiGetComponentState(hpkg, "virgo", &state, &action);
2884     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2885     ok( state == INSTALLSTATE_UNKNOWN, "Expected virgo INSTALLSTATE_UNKNOWN, got %d\n", state);
2886     ok( action == INSTALLSTATE_SOURCE, "Expected virgo INSTALLSTATE_SOURCE, got %d\n", action);
2887
2888     state = 0xdeadbee;
2889     action = 0xdeadbee;
2890     r = MsiGetComponentState(hpkg, "libra", &state, &action);
2891     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2892     ok( state == INSTALLSTATE_UNKNOWN, "Expected libra INSTALLSTATE_UNKNOWN, got %d\n", state);
2893     ok( action == INSTALLSTATE_LOCAL, "Expected libra INSTALLSTATE_LOCAL, got %d\n", action);
2894
2895     state = 0xdeadbee;
2896     action = 0xdeadbee;
2897     r = MsiGetComponentState(hpkg, "cassiopeia", &state, &action);
2898     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2899     ok( state == INSTALLSTATE_UNKNOWN, "Expected cassiopeia INSTALLSTATE_UNKNOWN, got %d\n", state);
2900     ok( action == INSTALLSTATE_LOCAL, "Expected cassiopeia INSTALLSTATE_LOCAL, got %d\n", action);
2901
2902     state = 0xdeadbee;
2903     action = 0xdeadbee;
2904     r = MsiGetComponentState(hpkg, "cepheus", &state, &action);
2905     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2906     ok( state == INSTALLSTATE_UNKNOWN, "Expected cepheus INSTALLSTATE_UNKNOWN, got %d\n", state);
2907     ok( action == INSTALLSTATE_SOURCE, "Expected cepheus INSTALLSTATE_SOURCE, got %d\n", action);
2908
2909     state = 0xdeadbee;
2910     action = 0xdeadbee;
2911     r = MsiGetComponentState(hpkg, "andromeda", &state, &action);
2912     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2913     ok( state == INSTALLSTATE_UNKNOWN, "Expected andromeda INSTALLSTATE_UNKNOWN, got %d\n", state);
2914     ok( action == INSTALLSTATE_SOURCE, "Expected andromeda INSTALLSTATE_SOURCE, got %d\n", action);
2915
2916     state = 0xdeadbee;
2917     action = 0xdeadbee;
2918     r = MsiGetComponentState(hpkg, "canis", &state, &action);
2919     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2920     ok( state == INSTALLSTATE_UNKNOWN, "Expected canis INSTALLSTATE_UNKNOWN, got %d\n", state);
2921     ok( action == INSTALLSTATE_UNKNOWN, "Expected canis INSTALLSTATE_UNKNOWN, got %d\n", action);
2922
2923     state = 0xdeadbee;
2924     action = 0xdeadbee;
2925     r = MsiGetComponentState(hpkg, "monoceros", &state, &action);
2926     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2927     ok( state == INSTALLSTATE_UNKNOWN, "Expected monoceros INSTALLSTATE_UNKNOWN, got %d\n", state);
2928     ok( action == INSTALLSTATE_UNKNOWN, "Expected monoceros INSTALLSTATE_UNKNOWN, got %d\n", action);
2929
2930     state = 0xdeadbee;
2931     action = 0xdeadbee;
2932     r = MsiGetComponentState(hpkg, "lepus", &state, &action);
2933     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2934     ok( state == INSTALLSTATE_UNKNOWN, "Expected lepus INSTALLSTATE_UNKNOWN, got %d\n", state);
2935     ok( action == INSTALLSTATE_UNKNOWN, "Expected lepus INSTALLSTATE_UNKNOWN, got %d\n", action);
2936
2937     state = 0xdeadbee;
2938     action = 0xdeadbee;
2939     r = MsiGetComponentState(hpkg, "delphinus", &state, &action);
2940     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2941     ok( state == INSTALLSTATE_UNKNOWN, "Expected delphinus INSTALLSTATE_UNKNOWN, got %d\n", state);
2942     ok( action == INSTALLSTATE_UNKNOWN, "Expected delphinus INSTALLSTATE_UNKNOWN, got %d\n", action);
2943
2944     state = 0xdeadbee;
2945     action = 0xdeadbee;
2946     r = MsiGetComponentState(hpkg, "hydrus", &state, &action);
2947     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r );
2948     ok( state == INSTALLSTATE_UNKNOWN, "Expected hydrus INSTALLSTATE_UNKNOWN, got %d\n", state);
2949     ok( action == INSTALLSTATE_UNKNOWN, "Expected hydrus INSTALLSTATE_UNKNOWN, got %d\n", action);
2950     
2951     MsiCloseHandle(hpkg);
2952     DeleteFileA(msifile);
2953 }
2954
2955 static void test_installprops(void)
2956 {
2957     MSIHANDLE hpkg, hdb;
2958     CHAR path[MAX_PATH];
2959     CHAR buf[MAX_PATH];
2960     DWORD size, type;
2961     HKEY hkey;
2962     UINT r;
2963
2964     GetCurrentDirectory(MAX_PATH, path);
2965     lstrcat(path, "\\");
2966     lstrcat(path, msifile);
2967
2968     hdb = create_package_db();
2969     ok( hdb, "failed to create database\n");
2970
2971     hpkg = package_from_db(hdb);
2972     ok( hpkg, "failed to create package\n");
2973
2974     MsiCloseHandle(hdb);
2975
2976     size = MAX_PATH;
2977     r = MsiGetProperty(hpkg, "DATABASE", buf, &size);
2978     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
2979     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
2980
2981     RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hkey);
2982
2983     size = MAX_PATH;
2984     type = REG_SZ;
2985     RegQueryValueEx(hkey, "RegisteredOwner", NULL, &type, (LPBYTE)path, &size);
2986
2987     size = MAX_PATH;
2988     r = MsiGetProperty(hpkg, "USERNAME", buf, &size);
2989     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
2990     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
2991
2992     size = MAX_PATH;
2993     type = REG_SZ;
2994     RegQueryValueEx(hkey, "RegisteredOrganization", NULL, &type, (LPBYTE)path, &size);
2995
2996     size = MAX_PATH;
2997     r = MsiGetProperty(hpkg, "COMPANYNAME", buf, &size);
2998     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
2999     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
3000
3001     size = MAX_PATH;
3002     r = MsiGetProperty(hpkg, "VersionDatabase", buf, &size);
3003     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3004     trace("VersionDatabase = %s\n", buf);
3005
3006     size = MAX_PATH;
3007     r = MsiGetProperty(hpkg, "VersionMsi", buf, &size);
3008     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3009     trace("VersionMsi = %s\n", buf);
3010
3011     size = MAX_PATH;
3012     r = MsiGetProperty(hpkg, "Date", buf, &size);
3013     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3014     trace("Date = %s\n", buf);
3015
3016     size = MAX_PATH;
3017     r = MsiGetProperty(hpkg, "Time", buf, &size);
3018     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3019     trace("Time = %s\n", buf);
3020
3021     size = MAX_PATH;
3022     r = MsiGetProperty(hpkg, "PackageCode", buf, &size);
3023     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3024     trace("PackageCode = %s\n", buf);
3025
3026     CloseHandle(hkey);
3027     MsiCloseHandle(hpkg);
3028     DeleteFile(msifile);
3029 }
3030
3031 static void test_sourcedirprop(void)
3032 {
3033     MSIHANDLE hpkg, hdb;
3034     CHAR source_dir[MAX_PATH];
3035     CHAR path[MAX_PATH];
3036     DWORD size;
3037     UINT r;
3038
3039     hdb = create_package_db();
3040     ok ( hdb, "failed to create package database\n" );
3041
3042     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
3043     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
3044
3045     hpkg = package_from_db( hdb );
3046     ok( hpkg, "failed to create package\n");
3047
3048     MsiCloseHandle( hdb );
3049
3050     size = MAX_PATH;
3051     r = MsiGetProperty( hpkg, "SourceDir", source_dir, &size );
3052     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3053     ok( !lstrlenA(source_dir), "Expected emtpy source dir, got %s\n", source_dir);
3054
3055     size = MAX_PATH;
3056     r = MsiGetProperty( hpkg, "SOURCEDIR", source_dir, &size );
3057     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3058     ok( !lstrlenA(source_dir), "Expected emtpy source dir, got %s\n", source_dir);
3059
3060     r = MsiDoAction( hpkg, "CostInitialize");
3061     ok( r == ERROR_SUCCESS, "cost init failed\n");
3062
3063     size = MAX_PATH;
3064     r = MsiGetProperty( hpkg, "SourceDir", source_dir, &size );
3065     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3066     ok( !lstrlenA(source_dir), "Expected emtpy source dir, got %s\n", source_dir);
3067
3068     size = MAX_PATH;
3069     r = MsiGetProperty( hpkg, "SOURCEDIR", source_dir, &size );
3070     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3071     ok( !lstrlenA(source_dir), "Expected emtpy source dir, got %s\n", source_dir);
3072
3073     r = MsiDoAction( hpkg, "ResolveSource");
3074     ok( r == ERROR_SUCCESS, "file cost failed\n");
3075
3076     GetCurrentDirectory(MAX_PATH, path);
3077     lstrcatA(path, "\\");
3078
3079     size = MAX_PATH;
3080     r = MsiGetProperty( hpkg, "SourceDir", source_dir, &size );
3081     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3082     ok( !lstrcmpA(source_dir, path), "Expected %s, got %s\n", path, source_dir);
3083
3084     size = MAX_PATH;
3085     r = MsiGetProperty( hpkg, "SOURCEDIR", source_dir, &size );
3086     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3087     ok( !lstrcmpA(source_dir, path), "Expected %s, got %s\n", path, source_dir);
3088
3089     size = MAX_PATH;
3090     r = MsiGetProperty( hpkg, "SoUrCeDiR", source_dir, &size );
3091     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
3092     ok( !lstrlenA(source_dir), "Expected emtpy source dir, got %s\n", source_dir);
3093
3094     MsiCloseHandle(hpkg);
3095     DeleteFileA(msifile);
3096 }
3097
3098 static void test_prop_path(void)
3099 {
3100     MSIHANDLE hpkg, hdb;
3101     char buffer[MAX_PATH], cwd[MAX_PATH];
3102     DWORD sz;
3103     UINT r;
3104
3105     GetCurrentDirectory(MAX_PATH, cwd);
3106     strcat(cwd, "\\");
3107
3108     hdb = create_package_db();
3109     ok( hdb, "failed to create database\n");
3110
3111     r = add_directory_entry( hdb, "'TARGETDIR','','SourceDir'" );
3112     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
3113
3114     r = add_directory_entry( hdb, "'foo','TARGETDIR','foosrc:footgt'" );
3115     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
3116
3117     hpkg = package_from_db(hdb);
3118     ok( hpkg, "failed to create package\n");
3119
3120     r = MsiGetSourcePath(hpkg, "SourceDir", buffer, &sz );
3121     ok( r == ERROR_DIRECTORY, "failed to get source path\n");
3122
3123     r = MsiGetSourcePath(hpkg, "SOURCEDIR", buffer, &sz );
3124     ok( r == ERROR_DIRECTORY, "failed to get source path\n");
3125
3126     r = MsiDoAction( hpkg, "CostInitialize");
3127     ok( r == ERROR_SUCCESS, "cost init failed\n");
3128
3129     sz = sizeof buffer;
3130     buffer[0] = 0;
3131     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
3132     ok( r == ERROR_SUCCESS, "property not set\n");
3133     ok( !buffer[0], "SourceDir should be empty\n");
3134
3135     sz = sizeof buffer;
3136     buffer[0] = 0;
3137     r = MsiGetProperty(hpkg, "SOURCEDIR", buffer, &sz);
3138     ok( r == ERROR_SUCCESS, "property not set\n");
3139     ok( !buffer[0], "SourceDir should be empty\n");
3140
3141     sz = sizeof buffer;
3142     buffer[0] = 0;
3143     r = MsiGetSourcePath(hpkg, "SourceDir", buffer, &sz );
3144     ok( r == ERROR_SUCCESS, "failed to get source path\n");
3145     ok( !lstrcmpi(cwd, buffer), "SourceDir (%s) should be current dir (%s)\n", buffer, cwd);
3146
3147     sz = sizeof buffer;
3148     buffer[0] = 0;
3149     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
3150     ok( r == ERROR_SUCCESS, "property not set\n");
3151     todo_wine {
3152     ok( !lstrcmpi(cwd, buffer), "SourceDir (%s) should be current dir (%s)\n", buffer, cwd);
3153     }
3154
3155     sz = sizeof buffer;
3156     buffer[0] = 0;
3157     r = MsiGetSourcePath(hpkg, "SOURCEDIR", buffer, &sz );
3158     ok( r == ERROR_DIRECTORY, "failed to get source path\n");
3159
3160     sz = sizeof buffer;
3161     buffer[0] = 0;
3162     r = MsiGetProperty(hpkg, "SOURCEDIR", buffer, &sz);
3163     ok( r == ERROR_SUCCESS, "property not set\n");
3164     todo_wine {
3165     ok( !lstrcmpi(cwd, buffer), "SourceDir (%s) should be current dir (%s)\n", buffer, cwd);
3166     }
3167
3168     r = MsiSetProperty(hpkg, "SourceDir", "goo");
3169     ok( r == ERROR_SUCCESS, "property not set\n");
3170
3171     sz = sizeof buffer;
3172     buffer[0] = 0;
3173     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
3174     ok( r == ERROR_SUCCESS, "property not set\n");
3175     ok( !lstrcmpi(buffer, "goo"), "SourceDir (%s) should be goo\n", buffer);
3176
3177     sz = sizeof buffer;
3178     buffer[0] = 0;
3179     r = MsiGetSourcePath(hpkg, "SourceDir", buffer, &sz );
3180     ok( r == ERROR_SUCCESS, "failed to get source path\n");
3181     ok( !lstrcmpi(buffer, cwd), "SourceDir (%s) should be goo\n", buffer);
3182
3183     sz = sizeof buffer;
3184     buffer[0] = 0;
3185     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
3186     ok( r == ERROR_SUCCESS, "property not set\n");
3187     ok( !lstrcmpi(buffer, "goo"), "SourceDir (%s) should be goo\n", buffer);
3188
3189     MsiCloseHandle( hpkg );
3190     DeleteFile(msifile);
3191 }
3192
3193 START_TEST(package)
3194 {
3195     test_createpackage();
3196     test_getsourcepath_bad();
3197     test_getsourcepath();
3198     test_doaction();
3199     test_gettargetpath_bad();
3200     test_settargetpath();
3201     test_props();
3202     test_properties_table();
3203     test_condition();
3204     test_msipackage();
3205     test_formatrecord2();
3206     test_states();
3207     test_getproperty();
3208     test_removefiles();
3209     test_appsearch();
3210     test_featureparents();
3211     test_installprops();
3212     test_sourcedirprop();
3213     test_prop_path();
3214 }