mshtml: Added IHTMLWindow6::get_sessionStorage implementation.
[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 <msidefs.h>
27 #include <msi.h>
28 #include <msiquery.h>
29 #include <srrestoreptapi.h>
30 #include <shlobj.h>
31
32 #include "wine/test.h"
33
34 static BOOL is_wow64;
35 static const char msifile[] = "winetest-package.msi";
36 static char CURR_DIR[MAX_PATH];
37
38 static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR);
39 static INSTALLSTATE (WINAPI *pMsiGetComponentPathExA)(LPCSTR, LPCSTR, LPCSTR, MSIINSTALLCONTEXT, LPSTR, LPDWORD);
40 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
41
42 static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*);
43 static BOOL (WINAPI *pOpenProcessToken)( HANDLE, DWORD, PHANDLE );
44 static LONG (WINAPI *pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
45 static LONG (WINAPI *pRegDeleteKeyExW)(HKEY, LPCWSTR, REGSAM, DWORD);
46 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
47 static void (WINAPI *pGetSystemInfo)(LPSYSTEM_INFO);
48 static void (WINAPI *pGetNativeSystemInfo)(LPSYSTEM_INFO);
49 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR, UINT);
50
51 static BOOL (WINAPI *pSRRemoveRestorePoint)(DWORD);
52 static BOOL (WINAPI *pSRSetRestorePointA)(RESTOREPOINTINFOA*, STATEMGRSTATUS*);
53
54 static void init_functionpointers(void)
55 {
56     HMODULE hmsi = GetModuleHandleA("msi.dll");
57     HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
58     HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
59     HMODULE hshell32 = GetModuleHandleA("shell32.dll");
60     HMODULE hsrclient;
61
62 #define GET_PROC(mod, func) \
63     p ## func = (void*)GetProcAddress(mod, #func);
64
65     GET_PROC(hmsi, MsiApplyMultiplePatchesA);
66     GET_PROC(hmsi, MsiGetComponentPathExA);
67     GET_PROC(hshell32, SHGetFolderPathA);
68
69     GET_PROC(hadvapi32, ConvertSidToStringSidA);
70     GET_PROC(hadvapi32, OpenProcessToken);
71     GET_PROC(hadvapi32, RegDeleteKeyExA)
72     GET_PROC(hadvapi32, RegDeleteKeyExW)
73     GET_PROC(hkernel32, IsWow64Process)
74     GET_PROC(hkernel32, GetNativeSystemInfo)
75     GET_PROC(hkernel32, GetSystemInfo)
76     GET_PROC(hkernel32, GetSystemWow64DirectoryA)
77
78     hsrclient = LoadLibraryA("srclient.dll");
79     GET_PROC(hsrclient, SRRemoveRestorePoint);
80     GET_PROC(hsrclient, SRSetRestorePointA);
81 #undef GET_PROC
82 }
83
84 static BOOL is_process_limited(void)
85 {
86     HANDLE token;
87
88     if (!pOpenProcessToken) return FALSE;
89
90     if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
91     {
92         BOOL ret;
93         TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
94         DWORD size;
95
96         ret = GetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
97         CloseHandle(token);
98         return (ret && type == TokenElevationTypeLimited);
99     }
100     return FALSE;
101 }
102
103 static LONG delete_key( HKEY key, LPCSTR subkey, REGSAM access )
104 {
105     if (pRegDeleteKeyExA)
106         return pRegDeleteKeyExA( key, subkey, access, 0 );
107     return RegDeleteKeyA( key, subkey );
108 }
109
110 static char *get_user_sid(void)
111 {
112     HANDLE token;
113     DWORD size = 0;
114     TOKEN_USER *user;
115     char *usersid = NULL;
116
117     if (!pConvertSidToStringSidA)
118     {
119         win_skip("ConvertSidToStringSidA is not available\n");
120         return NULL;
121     }
122     OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token);
123     GetTokenInformation(token, TokenUser, NULL, size, &size);
124
125     user = HeapAlloc(GetProcessHeap(), 0, size);
126     GetTokenInformation(token, TokenUser, user, size, &size);
127     pConvertSidToStringSidA(user->User.Sid, &usersid);
128     HeapFree(GetProcessHeap(), 0, user);
129
130     CloseHandle(token);
131     return usersid;
132 }
133
134 /* RegDeleteTreeW from dlls/advapi32/registry.c */
135 static LSTATUS package_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey, REGSAM access)
136 {
137     LONG ret;
138     DWORD dwMaxSubkeyLen, dwMaxValueLen;
139     DWORD dwMaxLen, dwSize;
140     WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
141     HKEY hSubKey = hKey;
142
143     if(lpszSubKey)
144     {
145         ret = RegOpenKeyExW(hKey, lpszSubKey, 0, access, &hSubKey);
146         if (ret) return ret;
147     }
148
149     ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
150             &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
151     if (ret) goto cleanup;
152
153     dwMaxSubkeyLen++;
154     dwMaxValueLen++;
155     dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
156     if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
157     {
158         /* Name too big: alloc a buffer for it */
159         if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
160         {
161             ret = ERROR_NOT_ENOUGH_MEMORY;
162             goto cleanup;
163         }
164     }
165
166     /* Recursively delete all the subkeys */
167     while (TRUE)
168     {
169         dwSize = dwMaxLen;
170         if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
171                           NULL, NULL, NULL)) break;
172
173         ret = package_RegDeleteTreeW(hSubKey, lpszName, access);
174         if (ret) goto cleanup;
175     }
176
177     if (lpszSubKey)
178     {
179         if (pRegDeleteKeyExW)
180             ret = pRegDeleteKeyExW(hKey, lpszSubKey, access, 0);
181         else
182             ret = RegDeleteKeyW(hKey, lpszSubKey);
183     }
184     else
185         while (TRUE)
186         {
187             dwSize = dwMaxLen;
188             if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
189                   NULL, NULL, NULL, NULL)) break;
190
191             ret = RegDeleteValueW(hKey, lpszName);
192             if (ret) goto cleanup;
193         }
194
195 cleanup:
196     if (lpszName != szNameBuf)
197         HeapFree(GetProcessHeap(), 0, lpszName);
198     if(lpszSubKey)
199         RegCloseKey(hSubKey);
200     return ret;
201 }
202
203 static BOOL squash_guid(LPCWSTR in, LPWSTR out)
204 {
205     DWORD i,n=1;
206     GUID guid;
207
208     if (FAILED(CLSIDFromString((LPCOLESTR)in, &guid)))
209         return FALSE;
210
211     for(i=0; i<8; i++)
212         out[7-i] = in[n++];
213     n++;
214     for(i=0; i<4; i++)
215         out[11-i] = in[n++];
216     n++;
217     for(i=0; i<4; i++)
218         out[15-i] = in[n++];
219     n++;
220     for(i=0; i<2; i++)
221     {
222         out[17+i*2] = in[n++];
223         out[16+i*2] = in[n++];
224     }
225     n++;
226     for( ; i<8; i++)
227     {
228         out[17+i*2] = in[n++];
229         out[16+i*2] = in[n++];
230     }
231     out[32]=0;
232     return TRUE;
233 }
234
235 static void create_test_guid(LPSTR prodcode, LPSTR squashed)
236 {
237     WCHAR guidW[MAX_PATH];
238     WCHAR squashedW[MAX_PATH];
239     GUID guid;
240     HRESULT hr;
241     int size;
242
243     hr = CoCreateGuid(&guid);
244     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
245
246     size = StringFromGUID2(&guid, guidW, MAX_PATH);
247     ok(size == 39, "Expected 39, got %d\n", hr);
248
249     WideCharToMultiByte(CP_ACP, 0, guidW, size, prodcode, MAX_PATH, NULL, NULL);
250     squash_guid(guidW, squashedW);
251     WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
252 }
253
254 static void set_component_path(LPCSTR filename, MSIINSTALLCONTEXT context,
255                                LPCSTR guid, LPSTR usersid, BOOL dir)
256 {
257     WCHAR guidW[MAX_PATH];
258     WCHAR squashedW[MAX_PATH];
259     CHAR squashed[MAX_PATH];
260     CHAR comppath[MAX_PATH];
261     CHAR prodpath[MAX_PATH];
262     CHAR path[MAX_PATH];
263     LPCSTR prod = NULL;
264     HKEY hkey;
265     REGSAM access = KEY_ALL_ACCESS;
266
267     if (is_wow64)
268         access |= KEY_WOW64_64KEY;
269
270     MultiByteToWideChar(CP_ACP, 0, guid, -1, guidW, MAX_PATH);
271     squash_guid(guidW, squashedW);
272     WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
273
274     if (context == MSIINSTALLCONTEXT_MACHINE)
275     {
276         prod = "3D0DAE300FACA1300AD792060BCDAA92";
277         sprintf(comppath,
278                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
279                 "Installer\\UserData\\S-1-5-18\\Components\\%s", squashed);
280         lstrcpyA(prodpath,
281                  "SOFTWARE\\Classes\\Installer\\"
282                  "Products\\3D0DAE300FACA1300AD792060BCDAA92");
283     }
284     else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
285     {
286         prod = "7D2F387510109040002000060BECB6AB";
287         sprintf(comppath,
288                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
289                 "Installer\\UserData\\%s\\Components\\%s", usersid, squashed);
290         sprintf(prodpath,
291                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
292                 "Installer\\%s\\Installer\\Products\\"
293                 "7D2F387510109040002000060BECB6AB", usersid);
294     }
295     else if (context == MSIINSTALLCONTEXT_USERMANAGED)
296     {
297         prod = "7D2F387510109040002000060BECB6AB";
298         sprintf(comppath,
299                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
300                 "Installer\\UserData\\%s\\Components\\%s", usersid, squashed);
301         sprintf(prodpath,
302                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
303                 "Installer\\Managed\\%s\\Installer\\Products\\"
304                 "7D2F387510109040002000060BECB6AB", usersid);
305     }
306
307     RegCreateKeyExA(HKEY_LOCAL_MACHINE, comppath, 0, NULL, 0, access, NULL, &hkey, NULL);
308
309     lstrcpyA(path, CURR_DIR);
310     lstrcatA(path, "\\");
311     if (!dir) lstrcatA(path, filename);
312
313     RegSetValueExA(hkey, prod, 0, REG_SZ, (LPBYTE)path, lstrlenA(path));
314     RegCloseKey(hkey);
315
316     RegCreateKeyExA(HKEY_LOCAL_MACHINE, prodpath, 0, NULL, 0, access, NULL, &hkey, NULL);
317     RegCloseKey(hkey);
318 }
319
320 static void delete_component_path(LPCSTR guid, MSIINSTALLCONTEXT context, LPSTR usersid)
321 {
322     WCHAR guidW[MAX_PATH];
323     WCHAR squashedW[MAX_PATH];
324     WCHAR substrW[MAX_PATH];
325     CHAR squashed[MAX_PATH];
326     CHAR comppath[MAX_PATH];
327     CHAR prodpath[MAX_PATH];
328     REGSAM access = KEY_ALL_ACCESS;
329
330     if (is_wow64)
331         access |= KEY_WOW64_64KEY;
332
333     MultiByteToWideChar(CP_ACP, 0, guid, -1, guidW, MAX_PATH);
334     squash_guid(guidW, squashedW);
335     WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
336
337     if (context == MSIINSTALLCONTEXT_MACHINE)
338     {
339         sprintf(comppath,
340                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
341                 "Installer\\UserData\\S-1-5-18\\Components\\%s", squashed);
342         lstrcpyA(prodpath,
343                  "SOFTWARE\\Classes\\Installer\\"
344                  "Products\\3D0DAE300FACA1300AD792060BCDAA92");
345     }
346     else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
347     {
348         sprintf(comppath,
349                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
350                 "Installer\\UserData\\%s\\Components\\%s", usersid, squashed);
351         sprintf(prodpath,
352                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
353                 "Installer\\%s\\Installer\\Products\\"
354                 "7D2F387510109040002000060BECB6AB", usersid);
355     }
356     else if (context == MSIINSTALLCONTEXT_USERMANAGED)
357     {
358         sprintf(comppath,
359                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
360                 "Installer\\UserData\\%s\\Components\\%s", usersid, squashed);
361         sprintf(prodpath,
362                 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
363                 "Installer\\Managed\\%s\\Installer\\Products\\"
364                 "7D2F387510109040002000060BECB6AB", usersid);
365     }
366
367     MultiByteToWideChar(CP_ACP, 0, comppath, -1, substrW, MAX_PATH);
368     package_RegDeleteTreeW(HKEY_LOCAL_MACHINE, substrW, access);
369
370     MultiByteToWideChar(CP_ACP, 0, prodpath, -1, substrW, MAX_PATH);
371     package_RegDeleteTreeW(HKEY_LOCAL_MACHINE, substrW, access);
372 }
373
374 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
375 {
376     MSIHANDLE hview = 0;
377     UINT r, ret;
378
379     /* open a select query */
380     r = MsiDatabaseOpenView(hdb, query, &hview);
381     if (r != ERROR_SUCCESS)
382         return r;
383     r = MsiViewExecute(hview, 0);
384     if (r != ERROR_SUCCESS)
385         return r;
386     ret = MsiViewFetch(hview, phrec);
387     r = MsiViewClose(hview);
388     if (r != ERROR_SUCCESS)
389         return r;
390     r = MsiCloseHandle(hview);
391     if (r != ERROR_SUCCESS)
392         return r;
393     return ret;
394 }
395
396 static UINT run_query( MSIHANDLE hdb, const char *query )
397 {
398     MSIHANDLE hview = 0;
399     UINT r;
400
401     r = MsiDatabaseOpenView(hdb, query, &hview);
402     if( r != ERROR_SUCCESS )
403         return r;
404
405     r = MsiViewExecute(hview, 0);
406     if( r == ERROR_SUCCESS )
407         r = MsiViewClose(hview);
408     MsiCloseHandle(hview);
409     return r;
410 }
411
412 static UINT create_component_table( MSIHANDLE hdb )
413 {
414     return run_query( hdb,
415             "CREATE TABLE `Component` ( "
416             "`Component` CHAR(72) NOT NULL, "
417             "`ComponentId` CHAR(38), "
418             "`Directory_` CHAR(72) NOT NULL, "
419             "`Attributes` SHORT NOT NULL, "
420             "`Condition` CHAR(255), "
421             "`KeyPath` CHAR(72) "
422             "PRIMARY KEY `Component`)" );
423 }
424
425 static UINT create_feature_table( MSIHANDLE hdb )
426 {
427     return run_query( hdb,
428             "CREATE TABLE `Feature` ( "
429             "`Feature` CHAR(38) NOT NULL, "
430             "`Feature_Parent` CHAR(38), "
431             "`Title` CHAR(64), "
432             "`Description` CHAR(255), "
433             "`Display` SHORT NOT NULL, "
434             "`Level` SHORT NOT NULL, "
435             "`Directory_` CHAR(72), "
436             "`Attributes` SHORT NOT NULL "
437             "PRIMARY KEY `Feature`)" );
438 }
439
440 static UINT create_feature_components_table( MSIHANDLE hdb )
441 {
442     return run_query( hdb,
443             "CREATE TABLE `FeatureComponents` ( "
444             "`Feature_` CHAR(38) NOT NULL, "
445             "`Component_` CHAR(72) NOT NULL "
446             "PRIMARY KEY `Feature_`, `Component_` )" );
447 }
448
449 static UINT create_file_table( MSIHANDLE hdb )
450 {
451     return run_query( hdb,
452             "CREATE TABLE `File` ("
453             "`File` CHAR(72) NOT NULL, "
454             "`Component_` CHAR(72) NOT NULL, "
455             "`FileName` CHAR(255) NOT NULL, "
456             "`FileSize` LONG NOT NULL, "
457             "`Version` CHAR(72), "
458             "`Language` CHAR(20), "
459             "`Attributes` SHORT, "
460             "`Sequence` SHORT NOT NULL "
461             "PRIMARY KEY `File`)" );
462 }
463
464 static UINT create_remove_file_table( MSIHANDLE hdb )
465 {
466     return run_query( hdb,
467             "CREATE TABLE `RemoveFile` ("
468             "`FileKey` CHAR(72) NOT NULL, "
469             "`Component_` CHAR(72) NOT NULL, "
470             "`FileName` CHAR(255) LOCALIZABLE, "
471             "`DirProperty` CHAR(72) NOT NULL, "
472             "`InstallMode` SHORT NOT NULL "
473             "PRIMARY KEY `FileKey`)" );
474 }
475
476 static UINT create_appsearch_table( MSIHANDLE hdb )
477 {
478     return run_query( hdb,
479             "CREATE TABLE `AppSearch` ("
480             "`Property` CHAR(72) NOT NULL, "
481             "`Signature_` CHAR(72) NOT NULL "
482             "PRIMARY KEY `Property`, `Signature_`)" );
483 }
484
485 static UINT create_reglocator_table( MSIHANDLE hdb )
486 {
487     return run_query( hdb,
488             "CREATE TABLE `RegLocator` ("
489             "`Signature_` CHAR(72) NOT NULL, "
490             "`Root` SHORT NOT NULL, "
491             "`Key` CHAR(255) NOT NULL, "
492             "`Name` CHAR(255), "
493             "`Type` SHORT "
494             "PRIMARY KEY `Signature_`)" );
495 }
496
497 static UINT create_signature_table( MSIHANDLE hdb )
498 {
499     return run_query( hdb,
500             "CREATE TABLE `Signature` ("
501             "`Signature` CHAR(72) NOT NULL, "
502             "`FileName` CHAR(255) NOT NULL, "
503             "`MinVersion` CHAR(20), "
504             "`MaxVersion` CHAR(20), "
505             "`MinSize` LONG, "
506             "`MaxSize` LONG, "
507             "`MinDate` LONG, "
508             "`MaxDate` LONG, "
509             "`Languages` CHAR(255) "
510             "PRIMARY KEY `Signature`)" );
511 }
512
513 static UINT create_launchcondition_table( MSIHANDLE hdb )
514 {
515     return run_query( hdb,
516             "CREATE TABLE `LaunchCondition` ("
517             "`Condition` CHAR(255) NOT NULL, "
518             "`Description` CHAR(255) NOT NULL "
519             "PRIMARY KEY `Condition`)" );
520 }
521
522 static UINT create_property_table( MSIHANDLE hdb )
523 {
524     return run_query( hdb,
525             "CREATE TABLE `Property` ("
526             "`Property` CHAR(72) NOT NULL, "
527             "`Value` CHAR(0) "
528             "PRIMARY KEY `Property`)" );
529 }
530
531 static UINT create_install_execute_sequence_table( MSIHANDLE hdb )
532 {
533     return run_query( hdb,
534             "CREATE TABLE `InstallExecuteSequence` ("
535             "`Action` CHAR(72) NOT NULL, "
536             "`Condition` CHAR(255), "
537             "`Sequence` SHORT "
538             "PRIMARY KEY `Action`)" );
539 }
540
541 static UINT create_media_table( MSIHANDLE hdb )
542 {
543     return run_query( hdb,
544             "CREATE TABLE `Media` ("
545             "`DiskId` SHORT NOT NULL, "
546             "`LastSequence` SHORT NOT NULL, "
547             "`DiskPrompt` CHAR(64), "
548             "`Cabinet` CHAR(255), "
549             "`VolumeLabel` CHAR(32), "
550             "`Source` CHAR(72) "
551             "PRIMARY KEY `DiskId`)" );
552 }
553
554 static UINT create_ccpsearch_table( MSIHANDLE hdb )
555 {
556     return run_query( hdb,
557             "CREATE TABLE `CCPSearch` ("
558             "`Signature_` CHAR(72) NOT NULL "
559             "PRIMARY KEY `Signature_`)" );
560 }
561
562 static UINT create_drlocator_table( MSIHANDLE hdb )
563 {
564     return run_query( hdb,
565             "CREATE TABLE `DrLocator` ("
566             "`Signature_` CHAR(72) NOT NULL, "
567             "`Parent` CHAR(72), "
568             "`Path` CHAR(255), "
569             "`Depth` SHORT "
570             "PRIMARY KEY `Signature_`, `Parent`, `Path`)" );
571 }
572
573 static UINT create_complocator_table( MSIHANDLE hdb )
574 {
575     return run_query( hdb,
576             "CREATE TABLE `CompLocator` ("
577             "`Signature_` CHAR(72) NOT NULL, "
578             "`ComponentId` CHAR(38) NOT NULL, "
579             "`Type` SHORT "
580             "PRIMARY KEY `Signature_`)" );
581 }
582
583 static UINT create_inilocator_table( MSIHANDLE hdb )
584 {
585     return run_query( hdb,
586             "CREATE TABLE `IniLocator` ("
587             "`Signature_` CHAR(72) NOT NULL, "
588             "`FileName` CHAR(255) NOT NULL, "
589             "`Section` CHAR(96)NOT NULL, "
590             "`Key` CHAR(128)NOT NULL, "
591             "`Field` SHORT, "
592             "`Type` SHORT "
593             "PRIMARY KEY `Signature_`)" );
594 }
595
596 #define make_add_entry(type, qtext) \
597     static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
598     { \
599         char insert[] = qtext; \
600         char *query; \
601         UINT sz, r; \
602         sz = strlen(values) + sizeof insert; \
603         query = HeapAlloc(GetProcessHeap(),0,sz); \
604         sprintf(query,insert,values); \
605         r = run_query( hdb, query ); \
606         HeapFree(GetProcessHeap(), 0, query); \
607         return r; \
608     }
609
610 make_add_entry(component,
611                "INSERT INTO `Component`  "
612                "(`Component`, `ComponentId`, `Directory_`, "
613                "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
614
615 make_add_entry(directory,
616                "INSERT INTO `Directory` "
617                "(`Directory`,`Directory_Parent`,`DefaultDir`) VALUES( %s )")
618
619 make_add_entry(feature,
620                "INSERT INTO `Feature` "
621                "(`Feature`, `Feature_Parent`, `Title`, `Description`, "
622                "`Display`, `Level`, `Directory_`, `Attributes`) VALUES( %s )")
623
624 make_add_entry(feature_components,
625                "INSERT INTO `FeatureComponents` "
626                "(`Feature_`, `Component_`) VALUES( %s )")
627
628 make_add_entry(file,
629                "INSERT INTO `File` "
630                "(`File`, `Component_`, `FileName`, `FileSize`, "
631                "`Version`, `Language`, `Attributes`, `Sequence`) VALUES( %s )")
632
633 make_add_entry(appsearch,
634                "INSERT INTO `AppSearch` "
635                "(`Property`, `Signature_`) VALUES( %s )")
636
637 make_add_entry(signature,
638                "INSERT INTO `Signature` "
639                "(`Signature`, `FileName`, `MinVersion`, `MaxVersion`,"
640                " `MinSize`, `MaxSize`, `MinDate`, `MaxDate`, `Languages`) "
641                "VALUES( %s )")
642
643 make_add_entry(launchcondition,
644                "INSERT INTO `LaunchCondition` "
645                "(`Condition`, `Description`) VALUES( %s )")
646
647 make_add_entry(property,
648                "INSERT INTO `Property` (`Property`, `Value`) VALUES( %s )")
649
650 make_add_entry(install_execute_sequence,
651                "INSERT INTO `InstallExecuteSequence` "
652                "(`Action`, `Condition`, `Sequence`) VALUES( %s )")
653
654 make_add_entry(media,
655                "INSERT INTO `Media` "
656                "(`DiskId`, `LastSequence`, `DiskPrompt`, "
657                "`Cabinet`, `VolumeLabel`, `Source`) VALUES( %s )")
658
659 make_add_entry(ccpsearch,
660                "INSERT INTO `CCPSearch` (`Signature_`) VALUES( %s )")
661
662 make_add_entry(drlocator,
663                "INSERT INTO `DrLocator` "
664                "(`Signature_`, `Parent`, `Path`, `Depth`) VALUES( %s )")
665
666 make_add_entry(complocator,
667                "INSERT INTO `CompLocator` "
668                "(`Signature_`, `ComponentId`, `Type`) VALUES( %s )")
669
670 make_add_entry(inilocator,
671                "INSERT INTO `IniLocator` "
672                "(`Signature_`, `FileName`, `Section`, `Key`, `Field`, `Type`) "
673                "VALUES( %s )")
674
675 static UINT add_reglocator_entry( MSIHANDLE hdb, const char *sig, UINT root, const char *path,
676                                   const char *name, UINT type )
677 {
678     const char insert[] =
679         "INSERT INTO `RegLocator` (`Signature_`, `Root`, `Key`, `Name`, `Type`) "
680         "VALUES( '%s', %u, '%s', '%s', %u )";
681     char *query;
682     UINT sz, r;
683
684     sz = strlen( sig ) + 10 + strlen( path ) + strlen( name ) + 10 + sizeof( insert );
685     query = HeapAlloc( GetProcessHeap(), 0, sz );
686     sprintf( query, insert, sig, root, path, name, type );
687     r = run_query( hdb, query );
688     HeapFree( GetProcessHeap(), 0, query );
689     return r;
690 }
691
692 static UINT set_summary_info(MSIHANDLE hdb)
693 {
694     UINT res;
695     MSIHANDLE suminfo;
696
697     /* build summary info */
698     res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
699     ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
700
701     res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
702                         "Installation Database");
703     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
704
705     res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
706                         "Installation Database");
707     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
708
709     res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
710                         "Wine Hackers");
711     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
712
713     res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
714                     ";1033");
715     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
716
717     res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
718                     "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
719     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
720
721     res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
722     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
723
724     res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
725     ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
726
727     res = MsiSummaryInfoPersist(suminfo);
728     ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
729
730     res = MsiCloseHandle( suminfo);
731     ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
732
733     return res;
734 }
735
736
737 static MSIHANDLE create_package_db(void)
738 {
739     MSIHANDLE hdb = 0;
740     UINT res;
741
742     DeleteFile(msifile);
743
744     /* create an empty database */
745     res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
746     ok( res == ERROR_SUCCESS , "Failed to create database %u\n", res );
747     if( res != ERROR_SUCCESS )
748         return hdb;
749
750     res = MsiDatabaseCommit( hdb );
751     ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
752
753     res = set_summary_info(hdb);
754     ok( res == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", res);
755
756     res = run_query( hdb,
757             "CREATE TABLE `Directory` ( "
758             "`Directory` CHAR(255) NOT NULL, "
759             "`Directory_Parent` CHAR(255), "
760             "`DefaultDir` CHAR(255) NOT NULL "
761             "PRIMARY KEY `Directory`)" );
762     ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
763
764     return hdb;
765 }
766
767 static UINT package_from_db(MSIHANDLE hdb, MSIHANDLE *handle)
768 {
769     UINT res;
770     CHAR szPackage[12];
771     MSIHANDLE hPackage;
772
773     sprintf(szPackage, "#%u", hdb);
774     res = MsiOpenPackage(szPackage, &hPackage);
775     if (res != ERROR_SUCCESS)
776     {
777         MsiCloseHandle(hdb);
778         return res;
779     }
780
781     res = MsiCloseHandle(hdb);
782     if (res != ERROR_SUCCESS)
783     {
784         MsiCloseHandle(hPackage);
785         return res;
786     }
787
788     *handle = hPackage;
789     return ERROR_SUCCESS;
790 }
791
792 static void create_test_file(const CHAR *name)
793 {
794     HANDLE file;
795     DWORD written;
796
797     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
798     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
799     WriteFile(file, name, strlen(name), &written, NULL);
800     WriteFile(file, "\n", strlen("\n"), &written, NULL);
801     CloseHandle(file);
802 }
803
804 typedef struct _tagVS_VERSIONINFO
805 {
806     WORD wLength;
807     WORD wValueLength;
808     WORD wType;
809     WCHAR szKey[1];
810     WORD wPadding1[1];
811     VS_FIXEDFILEINFO Value;
812     WORD wPadding2[1];
813     WORD wChildren[1];
814 } VS_VERSIONINFO;
815
816 #define roundoffs(a, b, r) (((BYTE *)(b) - (BYTE *)(a) + ((r) - 1)) & ~((r) - 1))
817 #define roundpos(a, b, r) (((BYTE *)(a)) + roundoffs(a, b, r))
818
819 static BOOL create_file_with_version(const CHAR *name, LONG ms, LONG ls)
820 {
821     VS_VERSIONINFO *pVerInfo;
822     VS_FIXEDFILEINFO *pFixedInfo;
823     LPBYTE buffer, ofs;
824     CHAR path[MAX_PATH];
825     DWORD handle, size;
826     HANDLE resource;
827     BOOL ret = FALSE;
828
829     GetSystemDirectory(path, MAX_PATH);
830     /* Some dlls can't be updated on Vista/W2K8 */
831     lstrcatA(path, "\\version.dll");
832
833     CopyFileA(path, name, FALSE);
834
835     size = GetFileVersionInfoSize(path, &handle);
836     buffer = HeapAlloc(GetProcessHeap(), 0, size);
837
838     GetFileVersionInfoA(path, 0, size, buffer);
839
840     pVerInfo = (VS_VERSIONINFO *)buffer;
841     ofs = (BYTE *)&pVerInfo->szKey[lstrlenW(pVerInfo->szKey) + 1];
842     pFixedInfo = (VS_FIXEDFILEINFO *)roundpos(pVerInfo, ofs, 4);
843
844     pFixedInfo->dwFileVersionMS = ms;
845     pFixedInfo->dwFileVersionLS = ls;
846     pFixedInfo->dwProductVersionMS = ms;
847     pFixedInfo->dwProductVersionLS = ls;
848
849     resource = BeginUpdateResource(name, FALSE);
850     if (!resource)
851         goto done;
852
853     if (!UpdateResource(resource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO),
854                    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), buffer, size))
855         goto done;
856
857     if (!EndUpdateResource(resource, FALSE))
858         goto done;
859
860     ret = TRUE;
861
862 done:
863     HeapFree(GetProcessHeap(), 0, buffer);
864     return ret;
865 }
866
867 static BOOL notify_system_change(DWORD event_type, STATEMGRSTATUS *status)
868 {
869     RESTOREPOINTINFOA spec;
870
871     spec.dwEventType = event_type;
872     spec.dwRestorePtType = APPLICATION_INSTALL;
873     spec.llSequenceNumber = status->llSequenceNumber;
874     lstrcpyA(spec.szDescription, "msitest restore point");
875
876     return pSRSetRestorePointA(&spec, status);
877 }
878
879 static void remove_restore_point(DWORD seq_number)
880 {
881     DWORD res;
882
883     res = pSRRemoveRestorePoint(seq_number);
884     if (res != ERROR_SUCCESS)
885         trace("Failed to remove the restore point : %08x\n", res);
886 }
887
888 static void test_createpackage(void)
889 {
890     MSIHANDLE hPackage = 0;
891     UINT res;
892
893     res = package_from_db(create_package_db(), &hPackage);
894     if (res == ERROR_INSTALL_PACKAGE_REJECTED)
895     {
896         skip("Not enough rights to perform tests\n");
897         DeleteFile(msifile);
898         return;
899     }
900     ok( res == ERROR_SUCCESS, " Failed to create package %u\n", res );
901
902     res = MsiCloseHandle( hPackage);
903     ok( res == ERROR_SUCCESS , "Failed to close package\n" );
904     DeleteFile(msifile);
905 }
906
907 static void test_doaction( void )
908 {
909     MSIHANDLE hpkg;
910     UINT r;
911
912     r = MsiDoAction( -1, NULL );
913     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
914
915     r = package_from_db(create_package_db(), &hpkg);
916     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
917     {
918         skip("Not enough rights to perform tests\n");
919         DeleteFile(msifile);
920         return;
921     }
922     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
923
924     r = MsiDoAction(hpkg, NULL);
925     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
926
927     r = MsiDoAction(0, "boo");
928     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
929
930     r = MsiDoAction(hpkg, "boo");
931     ok( r == ERROR_FUNCTION_NOT_CALLED, "wrong return val\n");
932
933     MsiCloseHandle( hpkg );
934     DeleteFile(msifile);
935 }
936
937 static void test_gettargetpath_bad(void)
938 {
939     static const WCHAR boo[] = {'b','o','o',0};
940     static const WCHAR empty[] = {0};
941     char buffer[0x80];
942     WCHAR bufferW[0x80];
943     MSIHANDLE hpkg;
944     DWORD sz;
945     UINT r;
946
947     r = package_from_db(create_package_db(), &hpkg);
948     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
949     {
950         skip("Not enough rights to perform tests\n");
951         DeleteFile(msifile);
952         return;
953     }
954     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
955
956     r = MsiGetTargetPath( 0, NULL, NULL, NULL );
957     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
958
959     r = MsiGetTargetPath( 0, NULL, NULL, &sz );
960     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
961
962     r = MsiGetTargetPath( 0, "boo", NULL, NULL );
963     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
964
965     r = MsiGetTargetPath( 0, "boo", NULL, NULL );
966     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
967
968     r = MsiGetTargetPath( hpkg, "boo", NULL, NULL );
969     ok( r == ERROR_DIRECTORY, "wrong return val\n");
970
971     r = MsiGetTargetPath( hpkg, "boo", buffer, NULL );
972     ok( r == ERROR_DIRECTORY, "wrong return val\n");
973
974     sz = 0;
975     r = MsiGetTargetPath( hpkg, "", buffer, &sz );
976     ok( r == ERROR_DIRECTORY, "wrong return val\n");
977
978     r = MsiGetTargetPathW( 0, NULL, NULL, NULL );
979     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
980
981     r = MsiGetTargetPathW( 0, NULL, NULL, &sz );
982     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
983
984     r = MsiGetTargetPathW( 0, boo, NULL, NULL );
985     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
986
987     r = MsiGetTargetPathW( 0, boo, NULL, NULL );
988     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
989
990     r = MsiGetTargetPathW( hpkg, boo, NULL, NULL );
991     ok( r == ERROR_DIRECTORY, "wrong return val\n");
992
993     r = MsiGetTargetPathW( hpkg, boo, bufferW, NULL );
994     ok( r == ERROR_DIRECTORY, "wrong return val\n");
995
996     sz = 0;
997     r = MsiGetTargetPathW( hpkg, empty, bufferW, &sz );
998     ok( r == ERROR_DIRECTORY, "wrong return val\n");
999
1000     MsiCloseHandle( hpkg );
1001     DeleteFile(msifile);
1002 }
1003
1004 static void query_file_path(MSIHANDLE hpkg, LPCSTR file, LPSTR buff)
1005 {
1006     UINT r;
1007     DWORD size;
1008     MSIHANDLE rec;
1009
1010     rec = MsiCreateRecord( 1 );
1011     ok(rec, "MsiCreate record failed\n");
1012
1013     r = MsiRecordSetString( rec, 0, file );
1014     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
1015
1016     size = MAX_PATH;
1017     r = MsiFormatRecord( hpkg, rec, buff, &size );
1018     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
1019
1020     MsiCloseHandle( rec );
1021 }
1022
1023 static void test_settargetpath(void)
1024 {
1025     char tempdir[MAX_PATH+8], buffer[MAX_PATH], file[MAX_PATH];
1026     DWORD sz;
1027     MSIHANDLE hpkg;
1028     UINT r;
1029     MSIHANDLE hdb;
1030
1031     hdb = create_package_db();
1032     ok ( hdb, "failed to create package database\n" );
1033
1034     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'" );
1035     ok( r == S_OK, "failed to add directory entry: %d\n" , r );
1036
1037     r = create_component_table( hdb );
1038     ok( r == S_OK, "cannot create Component table: %d\n", r );
1039
1040     r = add_component_entry( hdb, "'RootComp', '{83e2694d-0864-4124-9323-6d37630912a1}', 'TARGETDIR', 8, '', 'RootFile'" );
1041     ok( r == S_OK, "cannot add dummy component: %d\n", r );
1042
1043     r = add_component_entry( hdb, "'TestComp', '{A3FB59C8-C293-4F7E-B8C5-F0E1D8EEE4E5}', 'TestDir', 0, '', 'TestFile'" );
1044     ok( r == S_OK, "cannot add test component: %d\n", r );
1045
1046     r = create_feature_table( hdb );
1047     ok( r == S_OK, "cannot create Feature table: %d\n", r );
1048
1049     r = add_feature_entry( hdb, "'TestFeature', '', '', '', 0, 1, '', 0" );
1050     ok( r == ERROR_SUCCESS, "cannot add TestFeature to Feature table: %d\n", r );
1051
1052     r = create_feature_components_table( hdb );
1053     ok( r == S_OK, "cannot create FeatureComponents table: %d\n", r );
1054
1055     r = add_feature_components_entry( hdb, "'TestFeature', 'RootComp'" );
1056     ok( r == S_OK, "cannot insert component into FeatureComponents table: %d\n", r );
1057
1058     r = add_feature_components_entry( hdb, "'TestFeature', 'TestComp'" );
1059     ok( r == S_OK, "cannot insert component into FeatureComponents table: %d\n", r );
1060
1061     add_directory_entry( hdb, "'TestParent', 'TARGETDIR', 'TestParent'" );
1062     add_directory_entry( hdb, "'TestDir', 'TestParent', 'TestDir'" );
1063
1064     r = create_file_table( hdb );
1065     ok( r == S_OK, "cannot create File table: %d\n", r );
1066
1067     r = add_file_entry( hdb, "'RootFile', 'RootComp', 'rootfile.txt', 0, '', '1033', 8192, 1" );
1068     ok( r == S_OK, "cannot add file to the File table: %d\n", r );
1069
1070     r = add_file_entry( hdb, "'TestFile', 'TestComp', 'testfile.txt', 0, '', '1033', 8192, 1" );
1071     ok( r == S_OK, "cannot add file to the File table: %d\n", r );
1072
1073     r = package_from_db( hdb, &hpkg );
1074     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
1075     {
1076         skip("Not enough rights to perform tests\n");
1077         DeleteFile(msifile);
1078         return;
1079     }
1080     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
1081
1082     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1083
1084     r = MsiDoAction( hpkg, "CostInitialize");
1085     ok( r == ERROR_SUCCESS, "cost init failed\n");
1086
1087     r = MsiDoAction( hpkg, "FileCost");
1088     ok( r == ERROR_SUCCESS, "file cost failed\n");
1089
1090     r = MsiDoAction( hpkg, "CostFinalize");
1091     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
1092
1093     r = MsiSetTargetPath( 0, NULL, NULL );
1094     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1095
1096     r = MsiSetTargetPath( 0, "boo", "C:\\bogusx" );
1097     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
1098
1099     r = MsiSetTargetPath( hpkg, "boo", NULL );
1100     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1101
1102     r = MsiSetTargetPath( hpkg, "boo", "c:\\bogusx" );
1103     ok( r == ERROR_DIRECTORY, "wrong return val\n");
1104
1105     sz = sizeof tempdir - 1;
1106     r = MsiGetTargetPath( hpkg, "TARGETDIR", tempdir, &sz );
1107     sprintf( file, "%srootfile.txt", tempdir );
1108     buffer[0] = 0;
1109     query_file_path( hpkg, "[#RootFile]", buffer );
1110     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1111     ok( !lstrcmp(buffer, file), "Expected %s, got %s\n", file, buffer );
1112
1113     GetTempFileName( tempdir, "_wt", 0, buffer );
1114     sprintf( tempdir, "%s\\subdir", buffer );
1115
1116     r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
1117     ok( r == ERROR_SUCCESS || r == ERROR_DIRECTORY,
1118         "MsiSetTargetPath on file returned %d\n", r );
1119
1120     r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
1121     ok( r == ERROR_SUCCESS || r == ERROR_DIRECTORY,
1122         "MsiSetTargetPath on 'subdir' of file returned %d\n", r );
1123
1124     DeleteFile( buffer );
1125
1126     r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
1127     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
1128
1129     r = GetFileAttributes( buffer );
1130     ok ( r == INVALID_FILE_ATTRIBUTES, "file/directory exists after MsiSetTargetPath. Attributes: %08X\n", r );
1131
1132     r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
1133     ok( r == ERROR_SUCCESS, "MsiSetTargetPath on subsubdir returned %d\n", r );
1134
1135     buffer[0] = 0;
1136     sz = sizeof buffer - 1;
1137     lstrcat( tempdir, "\\" );
1138     r = MsiGetTargetPath( hpkg, "TARGETDIR", buffer, &sz );
1139     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1140     ok( !lstrcmp(buffer, tempdir), "Expected %s, got %s\n", tempdir, buffer);
1141
1142     sprintf( file, "%srootfile.txt", tempdir );
1143     query_file_path( hpkg, "[#RootFile]", buffer );
1144     ok( !lstrcmp(buffer, file), "Expected %s, got %s\n", file, buffer);
1145
1146     buffer[0] = 0;
1147     sz = sizeof(buffer);
1148     r = MsiGetPropertyA( hpkg, "TestParent", buffer, &sz );
1149     ok( r == ERROR_SUCCESS, "MsiGetProperty returned %u\n", r );
1150     lstrcatA( tempdir, "TestParent\\" );
1151     ok( !lstrcmpi(buffer, tempdir), "Expected \"%s\", got \"%s\"\n", tempdir, buffer );
1152
1153     r = MsiSetTargetPath( hpkg, "TestParent", "C:\\one\\two" );
1154     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
1155
1156     buffer[0] = 0;
1157     sz = sizeof(buffer);
1158     r = MsiGetPropertyA( hpkg, "TestParent", buffer, &sz );
1159     ok( r == ERROR_SUCCESS, "MsiGetProperty returned %u\n", r );
1160     ok( lstrcmpi(buffer, "C:\\one\\two\\TestDir\\"),
1161         "Expected \"C:\\one\\two\\TestDir\\\", got \"%s\"\n", buffer );
1162
1163     buffer[0] = 0;
1164     query_file_path( hpkg, "[#TestFile]", buffer );
1165     ok( !lstrcmpi(buffer, "C:\\one\\two\\TestDir\\testfile.txt"),
1166         "Expected C:\\one\\two\\TestDir\\testfile.txt, got %s\n", buffer );
1167
1168     buffer[0] = 0;
1169     sz = sizeof buffer - 1;
1170     r = MsiGetTargetPath( hpkg, "TestParent", buffer, &sz );
1171     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1172     ok( !lstrcmpi(buffer, "C:\\one\\two\\"), "Expected C:\\one\\two\\, got %s\n", buffer);
1173
1174     r = MsiSetTargetPath( hpkg, "TestParent", "C:\\one\\two\\three" );
1175     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
1176
1177     buffer[0] = 0;
1178     sz = sizeof buffer - 1;
1179     r = MsiGetTargetPath( hpkg, "TestParent", buffer, &sz );
1180     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1181     ok( !lstrcmpi(buffer, "C:\\one\\two\\three\\"), "Expected C:\\one\\two\\three\\, got %s\n", buffer);
1182
1183     r = MsiSetTargetPath( hpkg, "TestParent", "C:\\\\one\\\\two  " );
1184     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
1185
1186     buffer[0] = 0;
1187     sz = sizeof buffer - 1;
1188     r = MsiGetTargetPath( hpkg, "TestParent", buffer, &sz );
1189     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1190     ok( !lstrcmpi(buffer, "C:\\one\\two\\"), "Expected \"C:\\one\\two\\\", got %s\n", buffer);
1191
1192     r = MsiSetTargetPath( hpkg, "TestParent", "C:\\\\ Program Files \\\\ " );
1193     ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
1194
1195     buffer[0] = 0;
1196     sz = sizeof buffer - 1;
1197     r = MsiGetTargetPath( hpkg, "TestParent", buffer, &sz );
1198     ok( r == ERROR_SUCCESS, "failed to get target path: %d\n", r);
1199     ok( !lstrcmpi(buffer, "C:\\Program Files\\"), "Expected \"C:\\Program Files\\\", got %s\n", buffer);
1200
1201     MsiCloseHandle( hpkg );
1202 }
1203
1204 static void test_condition(void)
1205 {
1206     static const WCHAR cond1[] = {'\"','a',0x30a,'\"','<','\"',0xe5,'\"',0};
1207     static const WCHAR cond2[] = {'\"','a',0x30a,'\"','>','\"',0xe5,'\"',0};
1208     static const WCHAR cond3[] = {'\"','a',0x30a,'\"','<','>','\"',0xe5,'\"',0};
1209     static const WCHAR cond4[] = {'\"','a',0x30a,'\"','=','\"',0xe5,'\"',0};
1210     MSICONDITION r;
1211     MSIHANDLE hpkg;
1212
1213     r = package_from_db(create_package_db(), &hpkg);
1214     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
1215     {
1216         skip("Not enough rights to perform tests\n");
1217         DeleteFile(msifile);
1218         return;
1219     }
1220     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
1221
1222     r = MsiEvaluateCondition(0, NULL);
1223     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1224
1225     r = MsiEvaluateCondition(hpkg, NULL);
1226     ok( r == MSICONDITION_NONE, "wrong return val\n");
1227
1228     r = MsiEvaluateCondition(hpkg, "");
1229     ok( r == MSICONDITION_NONE, "wrong return val\n");
1230
1231     r = MsiEvaluateCondition(hpkg, "1");
1232     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1233
1234     r = MsiEvaluateCondition(hpkg, "0");
1235     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1236
1237     r = MsiEvaluateCondition(hpkg, "-1");
1238     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1239
1240     r = MsiEvaluateCondition(hpkg, "0 = 0");
1241     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1242
1243     r = MsiEvaluateCondition(hpkg, "0 <> 0");
1244     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1245
1246     r = MsiEvaluateCondition(hpkg, "0 = 1");
1247     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1248
1249     r = MsiEvaluateCondition(hpkg, "0 > 1");
1250     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1251
1252     r = MsiEvaluateCondition(hpkg, "0 ~> 1");
1253     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1254
1255     r = MsiEvaluateCondition(hpkg, "1 > 1");
1256     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1257
1258     r = MsiEvaluateCondition(hpkg, "1 ~> 1");
1259     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1260
1261     r = MsiEvaluateCondition(hpkg, "0 >= 1");
1262     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1263
1264     r = MsiEvaluateCondition(hpkg, "0 ~>= 1");
1265     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1266
1267     r = MsiEvaluateCondition(hpkg, "1 >= 1");
1268     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1269
1270     r = MsiEvaluateCondition(hpkg, "1 ~>= 1");
1271     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1272
1273     r = MsiEvaluateCondition(hpkg, "0 < 1");
1274     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1275
1276     r = MsiEvaluateCondition(hpkg, "0 ~< 1");
1277     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1278
1279     r = MsiEvaluateCondition(hpkg, "1 < 1");
1280     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1281
1282     r = MsiEvaluateCondition(hpkg, "1 ~< 1");
1283     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1284
1285     r = MsiEvaluateCondition(hpkg, "0 <= 1");
1286     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1287
1288     r = MsiEvaluateCondition(hpkg, "0 ~<= 1");
1289     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1290
1291     r = MsiEvaluateCondition(hpkg, "1 <= 1");
1292     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1293
1294     r = MsiEvaluateCondition(hpkg, "1 ~<= 1");
1295     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1296
1297     r = MsiEvaluateCondition(hpkg, "0 >=");
1298     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1299
1300     r = MsiEvaluateCondition(hpkg, " ");
1301     ok( r == MSICONDITION_NONE, "wrong return val\n");
1302
1303     r = MsiEvaluateCondition(hpkg, "LicView <> \"1\"");
1304     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1305
1306     r = MsiEvaluateCondition(hpkg, "LicView <> \"0\"");
1307     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1308
1309     r = MsiEvaluateCondition(hpkg, "LicView <> LicView");
1310     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1311
1312     r = MsiEvaluateCondition(hpkg, "not 0");
1313     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1314
1315     r = MsiEvaluateCondition(hpkg, "not LicView");
1316     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1317
1318     r = MsiEvaluateCondition(hpkg, "\"Testing\" ~<< \"Testing\"");
1319     ok (r == MSICONDITION_TRUE, "wrong return val\n");
1320
1321     r = MsiEvaluateCondition(hpkg, "LicView ~<< \"Testing\"");
1322     ok (r == MSICONDITION_FALSE, "wrong return val\n");
1323
1324     r = MsiEvaluateCondition(hpkg, "Not LicView ~<< \"Testing\"");
1325     ok (r == MSICONDITION_TRUE, "wrong return val\n");
1326
1327     r = MsiEvaluateCondition(hpkg, "not \"A\"");
1328     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1329
1330     r = MsiEvaluateCondition(hpkg, "~not \"A\"");
1331     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1332
1333     r = MsiEvaluateCondition(hpkg, "\"0\"");
1334     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1335
1336     r = MsiEvaluateCondition(hpkg, "1 and 2");
1337     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1338
1339     r = MsiEvaluateCondition(hpkg, "not 0 and 3");
1340     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1341
1342     r = MsiEvaluateCondition(hpkg, "not 0 and 0");
1343     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1344
1345     r = MsiEvaluateCondition(hpkg, "not 0 or 1");
1346     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1347
1348     r = MsiEvaluateCondition(hpkg, "(0)");
1349     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1350
1351     r = MsiEvaluateCondition(hpkg, "(((((1))))))");
1352     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1353
1354     r = MsiEvaluateCondition(hpkg, "(((((1)))))");
1355     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1356
1357     r = MsiEvaluateCondition(hpkg, " \"A\" < \"B\" ");
1358     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1359
1360     r = MsiEvaluateCondition(hpkg, " \"A\" > \"B\" ");
1361     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1362
1363     r = MsiEvaluateCondition(hpkg, " \"1\" > \"12\" ");
1364     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1365
1366     r = MsiEvaluateCondition(hpkg, " \"100\" < \"21\" ");
1367     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1368
1369     r = MsiEvaluateCondition(hpkg, "0 < > 0");
1370     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1371
1372     r = MsiEvaluateCondition(hpkg, "(1<<1) == 2");
1373     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1374
1375     r = MsiEvaluateCondition(hpkg, " \"A\" = \"a\" ");
1376     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1377
1378     r = MsiEvaluateCondition(hpkg, " \"A\" ~ = \"a\" ");
1379     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1380
1381     r = MsiEvaluateCondition(hpkg, " \"A\" ~= \"a\" ");
1382     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1383
1384     r = MsiEvaluateCondition(hpkg, " \"A\" ~= 1 ");
1385     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1386
1387     r = MsiEvaluateCondition(hpkg, " \"A\" = 1 ");
1388     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1389
1390     r = MsiEvaluateCondition(hpkg, " 1 ~= 1 ");
1391     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1392
1393     r = MsiEvaluateCondition(hpkg, " 1 ~= \"1\" ");
1394     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1395
1396     r = MsiEvaluateCondition(hpkg, " 1 = \"1\" ");
1397     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1398
1399     r = MsiEvaluateCondition(hpkg, " 0 = \"1\" ");
1400     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1401
1402     r = MsiEvaluateCondition(hpkg, " 0 < \"100\" ");
1403     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1404
1405     r = MsiEvaluateCondition(hpkg, " 100 > \"0\" ");
1406     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1407
1408     r = MsiEvaluateCondition(hpkg, "1 XOR 1");
1409     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1410
1411     r = MsiEvaluateCondition(hpkg, "1 IMP 1");
1412     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1413
1414     r = MsiEvaluateCondition(hpkg, "1 IMP 0");
1415     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1416
1417     r = MsiEvaluateCondition(hpkg, "0 IMP 0");
1418     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1419
1420     r = MsiEvaluateCondition(hpkg, "0 EQV 0");
1421     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1422
1423     r = MsiEvaluateCondition(hpkg, "0 EQV 1");
1424     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1425
1426     r = MsiEvaluateCondition(hpkg, "1 IMP 1 OR 0");
1427     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1428
1429     r = MsiEvaluateCondition(hpkg, "1 IMPL 1");
1430     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1431
1432     r = MsiEvaluateCondition(hpkg, "\"ASFD\" >< \"S\" ");
1433     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1434
1435     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"s\" ");
1436     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1437
1438     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"\" ");
1439     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1440
1441     r = MsiEvaluateCondition(hpkg, "\"ASFD\" ~>< \"sss\" ");
1442     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1443
1444     MsiSetProperty(hpkg, "mm", "5" );
1445
1446     r = MsiEvaluateCondition(hpkg, "mm = 5");
1447     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1448
1449     r = MsiEvaluateCondition(hpkg, "mm < 6");
1450     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1451
1452     r = MsiEvaluateCondition(hpkg, "mm <= 5");
1453     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1454
1455     r = MsiEvaluateCondition(hpkg, "mm > 4");
1456     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1457
1458     r = MsiEvaluateCondition(hpkg, "mm < 12");
1459     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1460
1461     r = MsiEvaluateCondition(hpkg, "mm = \"5\"");
1462     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1463
1464     r = MsiEvaluateCondition(hpkg, "0 = \"\"");
1465     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1466
1467     r = MsiEvaluateCondition(hpkg, "0 AND \"\"");
1468     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1469
1470     r = MsiEvaluateCondition(hpkg, "1 AND \"\"");
1471     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1472
1473     r = MsiEvaluateCondition(hpkg, "1 AND \"1\"");
1474     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1475
1476     r = MsiEvaluateCondition(hpkg, "3 >< 1");
1477     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1478
1479     r = MsiEvaluateCondition(hpkg, "3 >< 4");
1480     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1481
1482     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 0");
1483     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1484
1485     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 1");
1486     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1487
1488     r = MsiEvaluateCondition(hpkg, "NOT 1 OR 0");
1489     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1490
1491     r = MsiEvaluateCondition(hpkg, "0 AND 1 OR 1");
1492     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1493
1494     r = MsiEvaluateCondition(hpkg, "0 AND 0 OR 1");
1495     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1496
1497     r = MsiEvaluateCondition(hpkg, "NOT 0 AND 1 OR 0");
1498     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1499
1500     r = MsiEvaluateCondition(hpkg, "_1 = _1");
1501     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1502
1503     r = MsiEvaluateCondition(hpkg, "( 1 AND 1 ) = 2");
1504     ok( r == MSICONDITION_ERROR, "wrong return val\n");
1505
1506     r = MsiEvaluateCondition(hpkg, "NOT ( 1 AND 1 )");
1507     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1508
1509     r = MsiEvaluateCondition(hpkg, "NOT A AND (BBBBBBBBBB=2 OR CCC=1) AND Ddddddddd");
1510     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1511
1512     r = MsiEvaluateCondition(hpkg, "Installed<>\"\"");
1513     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1514
1515     r = MsiEvaluateCondition(hpkg, "NOT 1 AND 0");
1516     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1517
1518     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1519     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1520
1521     r = MsiEvaluateCondition(hpkg, "bandalmael<>0");
1522     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1523
1524     r = MsiEvaluateCondition(hpkg, "bandalmael<0");
1525     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1526
1527     r = MsiEvaluateCondition(hpkg, "bandalmael>0");
1528     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1529
1530     r = MsiEvaluateCondition(hpkg, "bandalmael>=0");
1531     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1532
1533     r = MsiEvaluateCondition(hpkg, "bandalmael<=0");
1534     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1535
1536     r = MsiEvaluateCondition(hpkg, "bandalmael~<>0");
1537     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1538
1539     MsiSetProperty(hpkg, "bandalmael", "0" );
1540     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1541     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1542
1543     MsiSetProperty(hpkg, "bandalmael", "" );
1544     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1545     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1546
1547     MsiSetProperty(hpkg, "bandalmael", "asdf" );
1548     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1549     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1550
1551     MsiSetProperty(hpkg, "bandalmael", "0asdf" );
1552     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1553     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1554
1555     MsiSetProperty(hpkg, "bandalmael", "0 " );
1556     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1557     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1558
1559     MsiSetProperty(hpkg, "bandalmael", "-0" );
1560     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1561     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1562
1563     MsiSetProperty(hpkg, "bandalmael", "0000000000000" );
1564     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1565     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1566
1567     MsiSetProperty(hpkg, "bandalmael", "--0" );
1568     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1569     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1570
1571     MsiSetProperty(hpkg, "bandalmael", "0x00" );
1572     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1573     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1574
1575     MsiSetProperty(hpkg, "bandalmael", "-" );
1576     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1577     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1578
1579     MsiSetProperty(hpkg, "bandalmael", "+0" );
1580     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1581     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1582
1583     MsiSetProperty(hpkg, "bandalmael", "0.0" );
1584     r = MsiEvaluateCondition(hpkg, "bandalmael=0");
1585     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1586     r = MsiEvaluateCondition(hpkg, "bandalmael<>0");
1587     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1588
1589     MsiSetProperty(hpkg, "one", "hi");
1590     MsiSetProperty(hpkg, "two", "hithere");
1591     r = MsiEvaluateCondition(hpkg, "one >< two");
1592     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1593
1594     MsiSetProperty(hpkg, "one", "hithere");
1595     MsiSetProperty(hpkg, "two", "hi");
1596     r = MsiEvaluateCondition(hpkg, "one >< two");
1597     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1598
1599     MsiSetProperty(hpkg, "one", "hello");
1600     MsiSetProperty(hpkg, "two", "hi");
1601     r = MsiEvaluateCondition(hpkg, "one >< two");
1602     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1603
1604     MsiSetProperty(hpkg, "one", "hellohithere");
1605     MsiSetProperty(hpkg, "two", "hi");
1606     r = MsiEvaluateCondition(hpkg, "one >< two");
1607     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1608
1609     MsiSetProperty(hpkg, "one", "");
1610     MsiSetProperty(hpkg, "two", "hi");
1611     r = MsiEvaluateCondition(hpkg, "one >< two");
1612     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1613
1614     MsiSetProperty(hpkg, "one", "hi");
1615     MsiSetProperty(hpkg, "two", "");
1616     r = MsiEvaluateCondition(hpkg, "one >< two");
1617     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1618
1619     MsiSetProperty(hpkg, "one", "");
1620     MsiSetProperty(hpkg, "two", "");
1621     r = MsiEvaluateCondition(hpkg, "one >< two");
1622     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1623
1624     MsiSetProperty(hpkg, "one", "1234");
1625     MsiSetProperty(hpkg, "two", "1");
1626     r = MsiEvaluateCondition(hpkg, "one >< two");
1627     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1628
1629     MsiSetProperty(hpkg, "one", "one 1234");
1630     MsiSetProperty(hpkg, "two", "1");
1631     r = MsiEvaluateCondition(hpkg, "one >< two");
1632     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1633
1634     MsiSetProperty(hpkg, "one", "hithere");
1635     MsiSetProperty(hpkg, "two", "hi");
1636     r = MsiEvaluateCondition(hpkg, "one << two");
1637     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1638
1639     MsiSetProperty(hpkg, "one", "hi");
1640     MsiSetProperty(hpkg, "two", "hithere");
1641     r = MsiEvaluateCondition(hpkg, "one << two");
1642     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1643
1644     MsiSetProperty(hpkg, "one", "hi");
1645     MsiSetProperty(hpkg, "two", "hi");
1646     r = MsiEvaluateCondition(hpkg, "one << two");
1647     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1648
1649     MsiSetProperty(hpkg, "one", "abcdhithere");
1650     MsiSetProperty(hpkg, "two", "hi");
1651     r = MsiEvaluateCondition(hpkg, "one << two");
1652     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1653
1654     MsiSetProperty(hpkg, "one", "");
1655     MsiSetProperty(hpkg, "two", "hi");
1656     r = MsiEvaluateCondition(hpkg, "one << two");
1657     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1658
1659     MsiSetProperty(hpkg, "one", "hithere");
1660     MsiSetProperty(hpkg, "two", "");
1661     r = MsiEvaluateCondition(hpkg, "one << two");
1662     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1663
1664     MsiSetProperty(hpkg, "one", "");
1665     MsiSetProperty(hpkg, "two", "");
1666     r = MsiEvaluateCondition(hpkg, "one << two");
1667     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1668
1669     MsiSetProperty(hpkg, "one", "1234");
1670     MsiSetProperty(hpkg, "two", "1");
1671     r = MsiEvaluateCondition(hpkg, "one << two");
1672     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1673
1674     MsiSetProperty(hpkg, "one", "1234 one");
1675     MsiSetProperty(hpkg, "two", "1");
1676     r = MsiEvaluateCondition(hpkg, "one << two");
1677     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1678
1679     MsiSetProperty(hpkg, "one", "hithere");
1680     MsiSetProperty(hpkg, "two", "there");
1681     r = MsiEvaluateCondition(hpkg, "one >> two");
1682     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1683
1684     MsiSetProperty(hpkg, "one", "hithere");
1685     MsiSetProperty(hpkg, "two", "hi");
1686     r = MsiEvaluateCondition(hpkg, "one >> two");
1687     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1688
1689     MsiSetProperty(hpkg, "one", "there");
1690     MsiSetProperty(hpkg, "two", "hithere");
1691     r = MsiEvaluateCondition(hpkg, "one >> two");
1692     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1693
1694     MsiSetProperty(hpkg, "one", "there");
1695     MsiSetProperty(hpkg, "two", "there");
1696     r = MsiEvaluateCondition(hpkg, "one >> two");
1697     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1698
1699     MsiSetProperty(hpkg, "one", "abcdhithere");
1700     MsiSetProperty(hpkg, "two", "hi");
1701     r = MsiEvaluateCondition(hpkg, "one >> two");
1702     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1703
1704     MsiSetProperty(hpkg, "one", "");
1705     MsiSetProperty(hpkg, "two", "there");
1706     r = MsiEvaluateCondition(hpkg, "one >> two");
1707     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1708
1709     MsiSetProperty(hpkg, "one", "there");
1710     MsiSetProperty(hpkg, "two", "");
1711     r = MsiEvaluateCondition(hpkg, "one >> two");
1712     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1713
1714     MsiSetProperty(hpkg, "one", "");
1715     MsiSetProperty(hpkg, "two", "");
1716     r = MsiEvaluateCondition(hpkg, "one >> two");
1717     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1718
1719     MsiSetProperty(hpkg, "one", "1234");
1720     MsiSetProperty(hpkg, "two", "4");
1721     r = MsiEvaluateCondition(hpkg, "one >> two");
1722     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1723
1724     MsiSetProperty(hpkg, "one", "one 1234");
1725     MsiSetProperty(hpkg, "two", "4");
1726     r = MsiEvaluateCondition(hpkg, "one >> two");
1727     ok( r == MSICONDITION_TRUE, "wrong return val\n");
1728
1729     MsiSetProperty(hpkg, "MsiNetAssemblySupport", NULL);  /* make sure it's empty */
1730
1731     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322\"");
1732     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1733
1734     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport > \"1.1.4322\"");
1735     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1736
1737     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport >= \"1.1.4322\"");
1738     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1739
1740     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport <= \"1.1.4322\"");
1741     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1742
1743     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport <> \"1.1.4322\"");
1744     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1745
1746     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport ~< \"1.1.4322\"");
1747     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1748
1749     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"abcd\"");
1750     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1751
1752     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a1.1.4322\"");
1753     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1754
1755     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322a\"");
1756     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1757
1758     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"0000001.1.4322\"");
1759     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1760
1761     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322.1\"");
1762     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1763
1764     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322.1.1\"");
1765     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1766
1767     r = MsiEvaluateCondition(hpkg, "\"2\" < \"1.1");
1768     ok( r == MSICONDITION_ERROR, "wrong return val (%d)\n", r);
1769
1770     r = MsiEvaluateCondition(hpkg, "\"2\" < \"1.1\"");
1771     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1772
1773     r = MsiEvaluateCondition(hpkg, "\"2\" < \"12.1\"");
1774     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1775
1776     r = MsiEvaluateCondition(hpkg, "\"02.1\" < \"2.11\"");
1777     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1778
1779     r = MsiEvaluateCondition(hpkg, "\"02.1.1\" < \"2.1\"");
1780     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1781
1782     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1\"");
1783     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1784
1785     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1\"");
1786     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1787
1788     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"0\"");
1789     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1790
1791     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"-1\"");
1792     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1793
1794     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a\"");
1795     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1796
1797     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"!\"");
1798     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1799
1800     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"!\"");
1801     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1802
1803     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"/\"");
1804     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1805
1806     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \" \"");
1807     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1808
1809     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"azAZ_\"");
1810     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1811
1812     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a[a]\"");
1813     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1814
1815     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a[a]a\"");
1816     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1817
1818     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a]\"");
1819     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1820
1821     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a]a\"");
1822     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1823
1824     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"{a}\"");
1825     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1826
1827     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"{a\"");
1828     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1829
1830     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"[a\"");
1831     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1832
1833     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a{\"");
1834     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1835
1836     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"a]\"");
1837     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1838
1839     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"A\"");
1840     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1841
1842     MsiSetProperty(hpkg, "MsiNetAssemblySupport", "1.1.4322");
1843     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.4322\"");
1844     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1845
1846     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.14322\"");
1847     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1848
1849     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1.5\"");
1850     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1851
1852     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1.1\"");
1853     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1854
1855     r = MsiEvaluateCondition(hpkg, "MsiNetAssemblySupport < \"1\"");
1856     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1857
1858     MsiSetProperty(hpkg, "one", "1");
1859     r = MsiEvaluateCondition(hpkg, "one < \"1\"");
1860     ok( r == MSICONDITION_FALSE, "wrong return val\n");
1861
1862     MsiSetProperty(hpkg, "X", "5.0");
1863
1864     r = MsiEvaluateCondition(hpkg, "X != \"\"");
1865     ok( r == MSICONDITION_ERROR, "wrong return val (%d)\n", r);
1866
1867     r = MsiEvaluateCondition(hpkg, "X =\"5.0\"");
1868     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1869
1870     r = MsiEvaluateCondition(hpkg, "X =\"5.1\"");
1871     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1872
1873     r = MsiEvaluateCondition(hpkg, "X =\"6.0\"");
1874     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1875
1876     r = MsiEvaluateCondition(hpkg, "X =\"5.0\" or X =\"5.1\" or X =\"6.0\"");
1877     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1878
1879     r = MsiEvaluateCondition(hpkg, "(X =\"5.0\" or X =\"5.1\" or X =\"6.0\")");
1880     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1881
1882     r = MsiEvaluateCondition(hpkg, "X !=\"\" and (X =\"5.0\" or X =\"5.1\" or X =\"6.0\")");
1883     ok( r == MSICONDITION_ERROR, "wrong return val (%d)\n", r);
1884
1885     /* feature doesn't exist */
1886     r = MsiEvaluateCondition(hpkg, "&nofeature");
1887     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1888
1889     MsiSetProperty(hpkg, "A", "2");
1890     MsiSetProperty(hpkg, "X", "50");
1891
1892     r = MsiEvaluateCondition(hpkg, "2 <= X");
1893     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1894
1895     r = MsiEvaluateCondition(hpkg, "A <= X");
1896     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1897
1898     r = MsiEvaluateCondition(hpkg, "A <= 50");
1899     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1900
1901     MsiSetProperty(hpkg, "X", "50val");
1902
1903     r = MsiEvaluateCondition(hpkg, "2 <= X");
1904     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1905
1906     r = MsiEvaluateCondition(hpkg, "A <= X");
1907     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1908
1909     MsiSetProperty(hpkg, "A", "7");
1910     MsiSetProperty(hpkg, "X", "50");
1911
1912     r = MsiEvaluateCondition(hpkg, "7 <= X");
1913     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1914
1915     r = MsiEvaluateCondition(hpkg, "A <= X");
1916     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1917
1918     r = MsiEvaluateCondition(hpkg, "A <= 50");
1919     ok( r == MSICONDITION_TRUE, "wrong return val (%d)\n", r);
1920
1921     MsiSetProperty(hpkg, "X", "50val");
1922
1923     r = MsiEvaluateCondition(hpkg, "2 <= X");
1924     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1925
1926     r = MsiEvaluateCondition(hpkg, "A <= X");
1927     ok( r == MSICONDITION_FALSE, "wrong return val (%d)\n", r);
1928
1929     r = MsiEvaluateConditionW(hpkg, cond1);
1930     ok( r == MSICONDITION_TRUE || broken(r == MSICONDITION_FALSE),
1931         "wrong return val (%d)\n", r);
1932
1933     r = MsiEvaluateConditionW(hpkg, cond2);
1934     ok( r == MSICONDITION_FALSE || broken(r == MSICONDITION_TRUE),
1935         "wrong return val (%d)\n", r);
1936
1937     r = MsiEvaluateConditionW(hpkg, cond3);
1938     ok( r == MSICONDITION_TRUE || broken(r == MSICONDITION_FALSE),
1939         "wrong return val (%d)\n", r);
1940
1941     r = MsiEvaluateConditionW(hpkg, cond4);
1942     ok( r == MSICONDITION_FALSE || broken(r == MSICONDITION_TRUE),
1943         "wrong return val (%d)\n", r);
1944
1945     MsiCloseHandle( hpkg );
1946     DeleteFile(msifile);
1947 }
1948
1949 static BOOL check_prop_empty( MSIHANDLE hpkg, const char * prop)
1950 {
1951     UINT r;
1952     DWORD sz;
1953     char buffer[2];
1954
1955     sz = sizeof buffer;
1956     strcpy(buffer,"x");
1957     r = MsiGetProperty( hpkg, prop, buffer, &sz );
1958     return r == ERROR_SUCCESS && buffer[0] == 0 && sz == 0;
1959 }
1960
1961 static void test_props(void)
1962 {
1963     MSIHANDLE hpkg, hdb;
1964     UINT r;
1965     DWORD sz;
1966     char buffer[0x100];
1967
1968     hdb = create_package_db();
1969     r = run_query( hdb,
1970             "CREATE TABLE `Property` ( "
1971             "`Property` CHAR(255) NOT NULL, "
1972             "`Value` CHAR(255) "
1973             "PRIMARY KEY `Property`)" );
1974     ok( r == ERROR_SUCCESS , "Failed\n" );
1975
1976     r = run_query(hdb,
1977             "INSERT INTO `Property` "
1978             "(`Property`, `Value`) "
1979             "VALUES( 'MetadataCompName', 'Photoshop.dll' )");
1980     ok( r == ERROR_SUCCESS , "Failed\n" );
1981
1982     r = package_from_db( hdb, &hpkg );
1983     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
1984     {
1985         skip("Not enough rights to perform tests\n");
1986         DeleteFile(msifile);
1987         return;
1988     }
1989     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
1990
1991     /* test invalid values */
1992     r = MsiGetProperty( 0, NULL, NULL, NULL );
1993     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1994
1995     r = MsiGetProperty( hpkg, NULL, NULL, NULL );
1996     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
1997
1998     r = MsiGetProperty( hpkg, "boo", NULL, NULL );
1999     ok( r == ERROR_SUCCESS, "wrong return val\n");
2000
2001     r = MsiGetProperty( hpkg, "boo", buffer, NULL );
2002     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
2003
2004     /* test retrieving an empty/nonexistent property */
2005     sz = sizeof buffer;
2006     r = MsiGetProperty( hpkg, "boo", NULL, &sz );
2007     ok( r == ERROR_SUCCESS, "wrong return val\n");
2008     ok( sz == 0, "wrong size returned\n");
2009
2010     check_prop_empty( hpkg, "boo");
2011     sz = 0;
2012     strcpy(buffer,"x");
2013     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
2014     ok( r == ERROR_MORE_DATA, "wrong return val\n");
2015     ok( !strcmp(buffer,"x"), "buffer was changed\n");
2016     ok( sz == 0, "wrong size returned\n");
2017
2018     sz = 1;
2019     strcpy(buffer,"x");
2020     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
2021     ok( r == ERROR_SUCCESS, "wrong return val\n");
2022     ok( buffer[0] == 0, "buffer was not changed\n");
2023     ok( sz == 0, "wrong size returned\n");
2024
2025     /* set the property to something */
2026     r = MsiSetProperty( 0, NULL, NULL );
2027     ok( r == ERROR_INVALID_HANDLE, "wrong return val\n");
2028
2029     r = MsiSetProperty( hpkg, NULL, NULL );
2030     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
2031
2032     r = MsiSetProperty( hpkg, "", NULL );
2033     ok( r == ERROR_SUCCESS, "wrong return val\n");
2034
2035     /* try set and get some illegal property identifiers */
2036     r = MsiSetProperty( hpkg, "", "asdf" );
2037     ok( r == ERROR_FUNCTION_FAILED, "wrong return val\n");
2038
2039     r = MsiSetProperty( hpkg, "=", "asdf" );
2040     ok( r == ERROR_SUCCESS, "wrong return val\n");
2041
2042     r = MsiSetProperty( hpkg, " ", "asdf" );
2043     ok( r == ERROR_SUCCESS, "wrong return val\n");
2044
2045     r = MsiSetProperty( hpkg, "'", "asdf" );
2046     ok( r == ERROR_SUCCESS, "wrong return val\n");
2047
2048     sz = sizeof buffer;
2049     buffer[0]=0;
2050     r = MsiGetProperty( hpkg, "'", buffer, &sz );
2051     ok( r == ERROR_SUCCESS, "wrong return val\n");
2052     ok( !strcmp(buffer,"asdf"), "buffer was not changed\n");
2053
2054     /* set empty values */
2055     r = MsiSetProperty( hpkg, "boo", NULL );
2056     ok( r == ERROR_SUCCESS, "wrong return val\n");
2057     ok( check_prop_empty( hpkg, "boo"), "prop wasn't empty\n");
2058
2059     r = MsiSetProperty( hpkg, "boo", "" );
2060     ok( r == ERROR_SUCCESS, "wrong return val\n");
2061     ok( check_prop_empty( hpkg, "boo"), "prop wasn't empty\n");
2062
2063     /* set a non-empty value */
2064     r = MsiSetProperty( hpkg, "boo", "xyz" );
2065     ok( r == ERROR_SUCCESS, "wrong return val\n");
2066
2067     sz = 1;
2068     strcpy(buffer,"x");
2069     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
2070     ok( r == ERROR_MORE_DATA, "wrong return val\n");
2071     ok( buffer[0] == 0, "buffer was not changed\n");
2072     ok( sz == 3, "wrong size returned\n");
2073
2074     sz = 4;
2075     strcpy(buffer,"x");
2076     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
2077     ok( r == ERROR_SUCCESS, "wrong return val\n");
2078     ok( !strcmp(buffer,"xyz"), "buffer was not changed\n");
2079     ok( sz == 3, "wrong size returned\n");
2080
2081     sz = 3;
2082     strcpy(buffer,"x");
2083     r = MsiGetProperty( hpkg, "boo", buffer, &sz );
2084     ok( r == ERROR_MORE_DATA, "wrong return val\n");
2085     ok( !strcmp(buffer,"xy"), "buffer was not changed\n");
2086     ok( sz == 3, "wrong size returned\n");
2087
2088     r = MsiSetProperty(hpkg, "SourceDir", "foo");
2089     ok( r == ERROR_SUCCESS, "wrong return val\n");
2090
2091     sz = 4;
2092     r = MsiGetProperty(hpkg, "SOURCEDIR", buffer, &sz);
2093     ok( r == ERROR_SUCCESS, "wrong return val\n");
2094     ok( !strcmp(buffer,""), "buffer wrong\n");
2095     ok( sz == 0, "wrong size returned\n");
2096
2097     sz = 4;
2098     r = MsiGetProperty(hpkg, "SOMERANDOMNAME", buffer, &sz);
2099     ok( r == ERROR_SUCCESS, "wrong return val\n");
2100     ok( !strcmp(buffer,""), "buffer wrong\n");
2101     ok( sz == 0, "wrong size returned\n");
2102
2103     sz = 4;
2104     r = MsiGetProperty(hpkg, "SourceDir", buffer, &sz);
2105     ok( r == ERROR_SUCCESS, "wrong return val\n");
2106     ok( !strcmp(buffer,"foo"), "buffer wrong\n");
2107     ok( sz == 3, "wrong size returned\n");
2108
2109     r = MsiSetProperty(hpkg, "MetadataCompName", "Photoshop.dll");
2110     ok( r == ERROR_SUCCESS, "wrong return val\n");
2111
2112     sz = 0;
2113     r = MsiGetProperty(hpkg, "MetadataCompName", NULL, &sz );
2114     ok( r == ERROR_SUCCESS, "return wrong\n");
2115     ok( sz == 13, "size wrong (%d)\n", sz);
2116
2117     sz = 13;
2118     r = MsiGetProperty(hpkg, "MetadataCompName", buffer, &sz );
2119     ok( r == ERROR_MORE_DATA, "return wrong\n");
2120     ok( !strcmp(buffer,"Photoshop.dl"), "buffer wrong\n");
2121
2122     r = MsiSetProperty(hpkg, "property", "value");
2123     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2124
2125     sz = 6;
2126     r = MsiGetProperty(hpkg, "property", buffer, &sz);
2127     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2128     ok( !strcmp(buffer, "value"), "Expected value, got %s\n", buffer);
2129
2130     r = MsiSetProperty(hpkg, "property", NULL);
2131     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2132
2133     sz = 6;
2134     r = MsiGetProperty(hpkg, "property", buffer, &sz);
2135     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2136     ok( !strlen(buffer), "Expected empty string, got %s\n", buffer);
2137
2138     MsiCloseHandle( hpkg );
2139     DeleteFile(msifile);
2140 }
2141
2142 static BOOL find_prop_in_property(MSIHANDLE hdb, LPCSTR prop, LPCSTR val)
2143 {
2144     MSIHANDLE hview, hrec;
2145     BOOL found;
2146     CHAR buffer[MAX_PATH];
2147     DWORD sz;
2148     UINT r;
2149
2150     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `_Property`", &hview);
2151     ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
2152     r = MsiViewExecute(hview, 0);
2153     ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
2154
2155     found = FALSE;
2156     while (r == ERROR_SUCCESS && !found)
2157     {
2158         r = MsiViewFetch(hview, &hrec);
2159         if (r != ERROR_SUCCESS) break;
2160
2161         sz = MAX_PATH;
2162         r = MsiRecordGetString(hrec, 1, buffer, &sz);
2163         if (r == ERROR_SUCCESS && !lstrcmpA(buffer, prop))
2164         {
2165             sz = MAX_PATH;
2166             r = MsiRecordGetString(hrec, 2, buffer, &sz);
2167             if (r == ERROR_SUCCESS && !lstrcmpA(buffer, val))
2168                 found = TRUE;
2169         }
2170
2171         MsiCloseHandle(hrec);
2172     }
2173
2174     MsiViewClose(hview);
2175     MsiCloseHandle(hview);
2176
2177     return found;
2178 }
2179
2180 static void test_property_table(void)
2181 {
2182     const char *query;
2183     UINT r;
2184     MSIHANDLE hpkg, hdb, hrec;
2185     char buffer[MAX_PATH], package[10];
2186     DWORD sz;
2187     BOOL found;
2188
2189     hdb = create_package_db();
2190     ok( hdb, "failed to create package\n");
2191
2192     r = package_from_db(hdb, &hpkg);
2193     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
2194     {
2195         skip("Not enough rights to perform tests\n");
2196         DeleteFile(msifile);
2197         return;
2198     }
2199     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
2200
2201     MsiCloseHandle(hdb);
2202
2203     hdb = MsiGetActiveDatabase(hpkg);
2204
2205     query = "CREATE TABLE `_Property` ( "
2206         "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
2207     r = run_query(hdb, query);
2208     ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2209
2210     MsiCloseHandle(hdb);
2211     MsiCloseHandle(hpkg);
2212     DeleteFile(msifile);
2213
2214     hdb = create_package_db();
2215     ok( hdb, "failed to create package\n");
2216
2217     query = "CREATE TABLE `_Property` ( "
2218         "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
2219     r = run_query(hdb, query);
2220     ok(r == ERROR_SUCCESS, "failed to create table\n");
2221
2222     query = "ALTER `_Property` ADD `foo` INTEGER";
2223     r = run_query(hdb, query);
2224     ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add column\n");
2225
2226     query = "ALTER TABLE `_Property` ADD `foo` INTEGER";
2227     r = run_query(hdb, query);
2228     ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add column\n");
2229
2230     query = "ALTER TABLE `_Property` ADD `extra` INTEGER";
2231     r = run_query(hdb, query);
2232     ok(r == ERROR_SUCCESS, "failed to add column\n");
2233
2234     sprintf(package, "#%i", hdb);
2235     r = MsiOpenPackage(package, &hpkg);
2236     todo_wine ok(r != ERROR_SUCCESS, "MsiOpenPackage succeeded\n");
2237     if (r == ERROR_SUCCESS)
2238         MsiCloseHandle(hpkg);
2239
2240     r = MsiCloseHandle(hdb);
2241     ok(r == ERROR_SUCCESS, "MsiCloseHandle failed %u\n", r);
2242
2243     hdb = create_package_db();
2244     ok (hdb, "failed to create package database\n");
2245
2246     r = create_property_table(hdb);
2247     ok(r == ERROR_SUCCESS, "cannot create Property table: %d\n", r);
2248
2249     r = add_property_entry(hdb, "'prop', 'val'");
2250     ok(r == ERROR_SUCCESS, "cannot add property: %d\n", r);
2251
2252     r = package_from_db(hdb, &hpkg);
2253     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
2254
2255     MsiCloseHandle(hdb);
2256
2257     sz = MAX_PATH;
2258     r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2259     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2260     ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2261
2262     hdb = MsiGetActiveDatabase(hpkg);
2263
2264     found = find_prop_in_property(hdb, "prop", "val");
2265     ok(found, "prop should be in the _Property table\n");
2266
2267     r = add_property_entry(hdb, "'dantes', 'mercedes'");
2268     ok(r == ERROR_SUCCESS, "cannot add property: %d\n", r);
2269
2270     query = "SELECT * FROM `_Property` WHERE `Property` = 'dantes'";
2271     r = do_query(hdb, query, &hrec);
2272     ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2273
2274     found = find_prop_in_property(hdb, "dantes", "mercedes");
2275     ok(found == FALSE, "dantes should not be in the _Property table\n");
2276
2277     sz = MAX_PATH;
2278     lstrcpy(buffer, "aaa");
2279     r = MsiGetProperty(hpkg, "dantes", buffer, &sz);
2280     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2281     ok(lstrlenA(buffer) == 0, "Expected empty string, got %s\n", buffer);
2282
2283     r = MsiSetProperty(hpkg, "dantes", "mercedes");
2284     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2285
2286     found = find_prop_in_property(hdb, "dantes", "mercedes");
2287     ok(found == TRUE, "dantes should be in the _Property table\n");
2288
2289     MsiCloseHandle(hdb);
2290     MsiCloseHandle(hpkg);
2291     DeleteFile(msifile);
2292 }
2293
2294 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
2295 {
2296     MSIHANDLE htab = 0;
2297     UINT res;
2298
2299     res = MsiDatabaseOpenView( hdb, szQuery, &htab );
2300     if( res == ERROR_SUCCESS )
2301     {
2302         UINT r;
2303
2304         r = MsiViewExecute( htab, hrec );
2305         if( r != ERROR_SUCCESS )
2306         {
2307             res = r;
2308             fprintf(stderr,"MsiViewExecute failed %08x\n", res);
2309         }
2310
2311         r = MsiViewClose( htab );
2312         if( r != ERROR_SUCCESS )
2313             res = r;
2314
2315         r = MsiCloseHandle( htab );
2316         if( r != ERROR_SUCCESS )
2317             res = r;
2318     }
2319     return res;
2320 }
2321
2322 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
2323 {
2324     return try_query_param( hdb, szQuery, 0 );
2325 }
2326
2327 static void set_summary_str(MSIHANDLE hdb, DWORD pid, LPCSTR value)
2328 {
2329     MSIHANDLE summary;
2330     UINT r;
2331
2332     r = MsiGetSummaryInformationA(hdb, NULL, 1, &summary);
2333     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2334
2335     r = MsiSummaryInfoSetPropertyA(summary, pid, VT_LPSTR, 0, NULL, value);
2336     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2337
2338     r = MsiSummaryInfoPersist(summary);
2339     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2340
2341     MsiCloseHandle(summary);
2342 }
2343
2344 static void set_summary_dword(MSIHANDLE hdb, DWORD pid, DWORD value)
2345 {
2346     MSIHANDLE summary;
2347     UINT r;
2348
2349     r = MsiGetSummaryInformationA(hdb, NULL, 1, &summary);
2350     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2351
2352     r = MsiSummaryInfoSetPropertyA(summary, pid, VT_I4, value, NULL, NULL);
2353     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2354
2355     r = MsiSummaryInfoPersist(summary);
2356     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2357
2358     MsiCloseHandle(summary);
2359 }
2360
2361 static void test_msipackage(void)
2362 {
2363     MSIHANDLE hdb = 0, hpack = 100;
2364     UINT r;
2365     const char *query;
2366     char name[10];
2367
2368     /* NULL szPackagePath */
2369     r = MsiOpenPackage(NULL, &hpack);
2370     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2371
2372     /* empty szPackagePath */
2373     r = MsiOpenPackage("", &hpack);
2374     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
2375     {
2376         skip("Not enough rights to perform tests\n");
2377         return;
2378     }
2379     todo_wine
2380     {
2381         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2382     }
2383
2384     if (r == ERROR_SUCCESS)
2385         MsiCloseHandle(hpack);
2386
2387     /* nonexistent szPackagePath */
2388     r = MsiOpenPackage("nonexistent", &hpack);
2389     ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", r);
2390
2391     /* NULL hProduct */
2392     r = MsiOpenPackage(msifile, NULL);
2393     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2394
2395     name[0]='#';
2396     name[1]=0;
2397     r = MsiOpenPackage(name, &hpack);
2398     ok(r == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", r);
2399
2400     r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2401     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2402
2403     /* database exists, but is emtpy */
2404     sprintf(name, "#%d", hdb);
2405     r = MsiOpenPackage(name, &hpack);
2406     ok(r == ERROR_INSTALL_PACKAGE_INVALID,
2407        "Expected ERROR_INSTALL_PACKAGE_INVALID, got %d\n", r);
2408
2409     query = "CREATE TABLE `Property` ( "
2410             "`Property` CHAR(72), `Value` CHAR(0) "
2411             "PRIMARY KEY `Property`)";
2412     r = try_query(hdb, query);
2413     ok(r == ERROR_SUCCESS, "failed to create Properties table\n");
2414
2415     query = "CREATE TABLE `InstallExecuteSequence` ("
2416             "`Action` CHAR(72), `Condition` CHAR(0), `Sequence` INTEGER "
2417             "PRIMARY KEY `Action`)";
2418     r = try_query(hdb, query);
2419     ok(r == ERROR_SUCCESS, "failed to create InstallExecuteSequence table\n");
2420
2421     /* a few key tables exist */
2422     sprintf(name, "#%d", hdb);
2423     r = MsiOpenPackage(name, &hpack);
2424     ok(r == ERROR_INSTALL_PACKAGE_INVALID,
2425        "Expected ERROR_INSTALL_PACKAGE_INVALID, got %d\n", r);
2426
2427     MsiCloseHandle(hdb);
2428     DeleteFile(msifile);
2429
2430     /* start with a clean database to show what constitutes a valid package */
2431     r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2432     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2433
2434     sprintf(name, "#%d", hdb);
2435
2436     /* The following summary information props must exist:
2437      *  - PID_REVNUMBER
2438      *  - PID_PAGECOUNT
2439      */
2440
2441     set_summary_dword(hdb, PID_PAGECOUNT, 100);
2442     r = MsiOpenPackage(name, &hpack);
2443     ok(r == ERROR_INSTALL_PACKAGE_INVALID,
2444        "Expected ERROR_INSTALL_PACKAGE_INVALID, got %d\n", r);
2445
2446     set_summary_str(hdb, PID_REVNUMBER, "{004757CD-5092-49C2-AD20-28E1CE0DF5F2}");
2447     r = MsiOpenPackage(name, &hpack);
2448     ok(r == ERROR_SUCCESS,
2449        "Expected ERROR_SUCCESS, got %d\n", r);
2450
2451     MsiCloseHandle(hpack);
2452     MsiCloseHandle(hdb);
2453     DeleteFile(msifile);
2454 }
2455
2456 static void test_formatrecord2(void)
2457 {
2458     MSIHANDLE hpkg, hrec ;
2459     char buffer[0x100];
2460     DWORD sz;
2461     UINT r;
2462
2463     r = package_from_db(create_package_db(), &hpkg);
2464     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
2465     {
2466         skip("Not enough rights to perform tests\n");
2467         DeleteFile(msifile);
2468         return;
2469     }
2470     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r);
2471
2472     r = MsiSetProperty(hpkg, "Manufacturer", " " );
2473     ok( r == ERROR_SUCCESS, "set property failed\n");
2474
2475     hrec = MsiCreateRecord(2);
2476     ok(hrec, "create record failed\n");
2477
2478     r = MsiRecordSetString( hrec, 0, "[ProgramFilesFolder][Manufacturer]\\asdf");
2479     ok( r == ERROR_SUCCESS, "format record failed\n");
2480
2481     buffer[0] = 0;
2482     sz = sizeof buffer;
2483     r = MsiFormatRecord( hpkg, hrec, buffer, &sz );
2484     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2485
2486     r = MsiRecordSetString(hrec, 0, "[foo][1]");
2487     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2488     r = MsiRecordSetString(hrec, 1, "hoo");
2489     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2490     sz = sizeof buffer;
2491     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2492     ok( sz == 3, "size wrong\n");
2493     ok( 0 == strcmp(buffer,"hoo"), "wrong output %s\n",buffer);
2494     ok( r == ERROR_SUCCESS, "format failed\n");
2495
2496     r = MsiRecordSetString(hrec, 0, "x[~]x");
2497     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2498     sz = sizeof buffer;
2499     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2500     ok( sz == 3, "size wrong\n");
2501     ok( 0 == strcmp(buffer,"x"), "wrong output %s\n",buffer);
2502     ok( r == ERROR_SUCCESS, "format failed\n");
2503
2504     r = MsiRecordSetString(hrec, 0, "[foo.$%}][1]");
2505     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2506     r = MsiRecordSetString(hrec, 1, "hoo");
2507     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2508     sz = sizeof buffer;
2509     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2510     ok( sz == 3, "size wrong\n");
2511     ok( 0 == strcmp(buffer,"hoo"), "wrong output %s\n",buffer);
2512     ok( r == ERROR_SUCCESS, "format failed\n");
2513
2514     r = MsiRecordSetString(hrec, 0, "[\\[]");
2515     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2516     sz = sizeof buffer;
2517     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2518     ok( sz == 1, "size wrong\n");
2519     ok( 0 == strcmp(buffer,"["), "wrong output %s\n",buffer);
2520     ok( r == ERROR_SUCCESS, "format failed\n");
2521
2522     SetEnvironmentVariable("FOO", "BAR");
2523     r = MsiRecordSetString(hrec, 0, "[%FOO]");
2524     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2525     sz = sizeof buffer;
2526     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2527     ok( sz == 3, "size wrong\n");
2528     ok( 0 == strcmp(buffer,"BAR"), "wrong output %s\n",buffer);
2529     ok( r == ERROR_SUCCESS, "format failed\n");
2530
2531     r = MsiRecordSetString(hrec, 0, "[[1]]");
2532     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2533     r = MsiRecordSetString(hrec, 1, "%FOO");
2534     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
2535     sz = sizeof buffer;
2536     r = MsiFormatRecord(hpkg, hrec, buffer, &sz);
2537     ok( sz == 3, "size wrong\n");
2538     ok( 0 == strcmp(buffer,"BAR"), "wrong output %s\n",buffer);
2539     ok( r == ERROR_SUCCESS, "format failed\n");
2540
2541     MsiCloseHandle( hrec );
2542     MsiCloseHandle( hpkg );
2543     DeleteFile(msifile);
2544 }
2545
2546 static void test_feature_states( UINT line, MSIHANDLE package, const char *feature, UINT error,
2547                                  INSTALLSTATE expected_state, INSTALLSTATE expected_action, int todo )
2548 {
2549     UINT r;
2550     INSTALLSTATE state = 0xdeadbee;
2551     INSTALLSTATE action = 0xdeadbee;
2552
2553     r = MsiGetFeatureState( package, feature, &state, &action );
2554     ok( r == error, "%u: expected %d got %d\n", line, error, r );
2555     if (r == ERROR_SUCCESS)
2556     {
2557         ok( state == expected_state, "%u: expected state %d got %d\n",
2558             line, expected_state, state );
2559         if (todo) todo_wine
2560             ok( action == expected_action, "%u: expected action %d got %d\n",
2561                 line, expected_action, action );
2562         else
2563             ok( action == expected_action, "%u: expected action %d got %d\n",
2564                 line, expected_action, action );
2565     }
2566     else
2567     {
2568         ok( state == 0xdeadbee, "%u: expected state 0xdeadbee got %d\n", line, state );
2569         if (todo) todo_wine
2570             ok( action == 0xdeadbee, "%u: expected action 0xdeadbee got %d\n", line, action );
2571         else
2572             ok( action == 0xdeadbee, "%u: expected action 0xdeadbee got %d\n", line, action );
2573
2574     }
2575 }
2576
2577 static void test_component_states( UINT line, MSIHANDLE package, const char *component, UINT error,
2578                                    INSTALLSTATE expected_state, INSTALLSTATE expected_action, int todo )
2579 {
2580     UINT r;
2581     INSTALLSTATE state = 0xdeadbee;
2582     INSTALLSTATE action = 0xdeadbee;
2583
2584     r = MsiGetComponentState( package, component, &state, &action );
2585     ok( r == error, "%u: expected %d got %d\n", line, error, r );
2586     if (r == ERROR_SUCCESS)
2587     {
2588         ok( state == expected_state, "%u: expected state %d got %d\n",
2589             line, expected_state, state );
2590         if (todo) todo_wine
2591             ok( action == expected_action, "%u: expected action %d got %d\n",
2592                 line, expected_action, action );
2593         else
2594             ok( action == expected_action, "%u: expected action %d got %d\n",
2595                 line, expected_action, action );
2596     }
2597     else
2598     {
2599         ok( state == 0xdeadbee, "%u: expected state 0xdeadbee got %d\n",
2600             line, state );
2601         if (todo) todo_wine
2602             ok( action == 0xdeadbee, "%u: expected action 0xdeadbee got %d\n",
2603                 line, action );
2604         else
2605             ok( action == 0xdeadbee, "%u: expected action 0xdeadbee got %d\n",
2606                 line, action );
2607     }
2608 }
2609
2610 static void test_states(void)
2611 {
2612     static char msifile2[] = "winetest2-package.msi";
2613     static char msifile3[] = "winetest3-package.msi";
2614     static char msifile4[] = "winetest4-package.msi";
2615     MSIHANDLE hpkg;
2616     UINT r;
2617     MSIHANDLE hdb;
2618
2619     if (is_process_limited())
2620     {
2621         skip("process is limited\n");
2622         return;
2623     }
2624
2625     hdb = create_package_db();
2626     ok ( hdb, "failed to create package database\n" );
2627
2628     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
2629     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
2630
2631     r = create_property_table( hdb );
2632     ok( r == ERROR_SUCCESS, "cannot create Property table: %d\n", r );
2633
2634     r = add_property_entry( hdb, "'ProductCode', '{7262AC98-EEBD-4364-8CE3-D654F6A425B9}'" );
2635     ok( r == ERROR_SUCCESS, "cannot add property entry: %d\n", r );
2636
2637     r = add_property_entry( hdb, "'ProductLanguage', '1033'" );
2638     ok( r == ERROR_SUCCESS, "cannot add property entry: %d\n", r );
2639
2640     r = add_property_entry( hdb, "'ProductName', 'MSITEST'" );
2641     ok( r == ERROR_SUCCESS, "cannot add property entry: %d\n", r );
2642
2643     r = add_property_entry( hdb, "'ProductVersion', '1.1.1'" );
2644     ok( r == ERROR_SUCCESS, "cannot add property entry: %d\n", r );
2645
2646     r = add_property_entry( hdb, "'MSIFASTINSTALL', '1'" );
2647     ok( r == ERROR_SUCCESS, "cannot add property entry: %d\n", r );
2648
2649     r = create_install_execute_sequence_table( hdb );
2650     ok( r == ERROR_SUCCESS, "cannot create InstallExecuteSequence table: %d\n", r );
2651
2652     r = add_install_execute_sequence_entry( hdb, "'CostInitialize', '', '800'" );
2653     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2654
2655     r = add_install_execute_sequence_entry( hdb, "'FileCost', '', '900'" );
2656     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2657
2658     r = add_install_execute_sequence_entry( hdb, "'CostFinalize', '', '1000'" );
2659     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2660
2661     r = add_install_execute_sequence_entry( hdb, "'InstallValidate', '', '1400'" );
2662     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2663
2664     r = add_install_execute_sequence_entry( hdb, "'InstallInitialize', '', '1500'" );
2665     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2666
2667     r = add_install_execute_sequence_entry( hdb, "'ProcessComponents', '', '1600'" );
2668     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2669
2670     r = add_install_execute_sequence_entry( hdb, "'UnpublishFeatures', '', '1800'" );
2671     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2672
2673     r = add_install_execute_sequence_entry( hdb, "'RegisterProduct', '', '6100'" );
2674     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2675
2676     r = add_install_execute_sequence_entry( hdb, "'PublishFeatures', '', '6300'" );
2677     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2678
2679     r = add_install_execute_sequence_entry( hdb, "'PublishProduct', '', '6400'" );
2680     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2681
2682     r = add_install_execute_sequence_entry( hdb, "'InstallFinalize', '', '6600'" );
2683     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry: %d\n", r );
2684
2685     r = create_media_table( hdb );
2686     ok( r == ERROR_SUCCESS, "cannot create media table: %d\n", r );
2687
2688     r = add_media_entry( hdb, "'1', '3', '', '', 'DISK1', ''");
2689     ok( r == ERROR_SUCCESS, "cannot add media entry: %d\n", r );
2690
2691     r = create_feature_table( hdb );
2692     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
2693
2694     r = create_component_table( hdb );
2695     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2696
2697     /* msidbFeatureAttributesFavorLocal */
2698     r = add_feature_entry( hdb, "'one', '', '', '', 2, 1, '', 0" );
2699     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2700
2701     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
2702     r = add_component_entry( hdb, "'alpha', '{467EC132-739D-4784-A37B-677AA43DBC94}', 'TARGETDIR', 0, '', 'alpha_file'" );
2703     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2704
2705     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
2706     r = add_component_entry( hdb, "'beta', '{2C1F189C-24A6-4C34-B26B-994A6C026506}', 'TARGETDIR', 1, '', 'beta_file'" );
2707     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2708
2709     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
2710     r = add_component_entry( hdb, "'gamma', '{C271E2A4-DE2E-4F70-86D1-6984AF7DE2CA}', 'TARGETDIR', 2, '', 'gamma_file'" );
2711     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2712
2713     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSharedDllRefCount */
2714     r = add_component_entry( hdb, "'theta', '{4EB3129D-81A8-48D5-9801-75600FED3DD9}', 'TARGETDIR', 8, '', 'theta_file'" );
2715     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2716
2717     /* msidbFeatureAttributesFavorSource */
2718     r = add_feature_entry( hdb, "'two', '', '', '', 2, 1, '', 1" );
2719     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2720
2721     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesLocalOnly */
2722     r = add_component_entry( hdb, "'delta', '{938FD4F2-C648-4259-A03C-7AA3B45643F3}', 'TARGETDIR', 0, '', 'delta_file'" );
2723     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2724
2725     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
2726     r = add_component_entry( hdb, "'epsilon', '{D59713B6-C11D-47F2-A395-1E5321781190}', 'TARGETDIR', 1, '', 'epsilon_file'" );
2727     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2728
2729     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesOptional */
2730     r = add_component_entry( hdb, "'zeta', '{377D33AB-2FAA-42B9-A629-0C0DAE9B9C7A}', 'TARGETDIR', 2, '', 'zeta_file'" );
2731     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2732
2733     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSharedDllRefCount */
2734     r = add_component_entry( hdb, "'iota', '{5D36F871-B5ED-4801-9E0F-C46B9E5C9669}', 'TARGETDIR', 8, '', 'iota_file'" );
2735     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2736
2737     /* msidbFeatureAttributesFavorSource */
2738     r = add_feature_entry( hdb, "'three', '', '', '', 2, 1, '', 1" );
2739     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2740
2741     /* msidbFeatureAttributesFavorLocal */
2742     r = add_feature_entry( hdb, "'four', '', '', '', 2, 1, '', 0" );
2743     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2744
2745     /* disabled */
2746     r = add_feature_entry( hdb, "'five', '', '', '', 2, 0, '', 1" );
2747     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2748
2749     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
2750     r = add_component_entry( hdb, "'eta', '{DD89003F-0DD4-41B8-81C0-3411A7DA2695}', 'TARGETDIR', 1, '', 'eta_file'" );
2751     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2752
2753     /* no feature parent:msidbComponentAttributesLocalOnly */
2754     r = add_component_entry( hdb, "'kappa', '{D6B93DC3-8DA5-4769-9888-42BFE156BB8B}', 'TARGETDIR', 1, '', 'kappa_file'" );
2755     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2756
2757     /* msidbFeatureAttributesFavorLocal:removed */
2758     r = add_feature_entry( hdb, "'six', '', '', '', 2, 1, '', 0" );
2759     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2760
2761     /* msidbFeatureAttributesFavorLocal:removed:msidbComponentAttributesLocalOnly */
2762     r = add_component_entry( hdb, "'lambda', '{6528C5E4-02A4-4636-A214-7A66A6C35B64}', 'TARGETDIR', 0, '', 'lambda_file'" );
2763     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2764
2765     /* msidbFeatureAttributesFavorLocal:removed:msidbComponentAttributesSourceOnly */
2766     r = add_component_entry( hdb, "'mu', '{97014BAB-6C56-4013-9A63-2BF913B42519}', 'TARGETDIR', 1, '', 'mu_file'" );
2767     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2768
2769     /* msidbFeatureAttributesFavorLocal:removed:msidbComponentAttributesOptional */
2770     r = add_component_entry( hdb, "'nu', '{943DD0D8-5808-4954-8526-3B8493FEDDCD}', 'TARGETDIR', 2, '', 'nu_file'" );
2771     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2772
2773     /* msidbFeatureAttributesFavorLocal:removed:msidbComponentAttributesSharedDllRefCount */
2774     r = add_component_entry( hdb, "'xi', '{D6CF9EF7-6FCF-4930-B34B-F938AEFF9BDB}', 'TARGETDIR', 8, '', 'xi_file'" );
2775     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2776
2777     /* msidbFeatureAttributesFavorSource:removed */
2778     r = add_feature_entry( hdb, "'seven', '', '', '', 2, 1, '', 1" );
2779     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2780
2781     /* msidbFeatureAttributesFavorSource:removed:msidbComponentAttributesLocalOnly */
2782     r = add_component_entry( hdb, "'omicron', '{7B57521D-15DB-4141-9AA6-01D934A4433F}', 'TARGETDIR', 0, '', 'omicron_file'" );
2783     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2784
2785     /* msidbFeatureAttributesFavorSource:removed:msidbComponentAttributesSourceOnly */
2786     r = add_component_entry( hdb, "'pi', '{FB85346B-378E-4492-8769-792305471C81}', 'TARGETDIR', 1, '', 'pi_file'" );
2787     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2788
2789     /* msidbFeatureAttributesFavorSource:removed:msidbComponentAttributesOptional */
2790     r = add_component_entry( hdb, "'rho', '{798F2047-7B0C-4783-8BB0-D703E554114B}', 'TARGETDIR', 2, '', 'rho_file'" );
2791     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2792
2793     /* msidbFeatureAttributesFavorSource:removed:msidbComponentAttributesSharedDllRefCount */
2794     r = add_component_entry( hdb, "'sigma', '{5CE9DDA8-B67B-4736-9D93-99D61C5B93E7}', 'TARGETDIR', 8, '', 'sigma_file'" );
2795     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2796
2797     /* msidbFeatureAttributesFavorLocal */
2798     r = add_feature_entry( hdb, "'eight', '', '', '', 2, 1, '', 0" );
2799     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2800
2801     r = add_component_entry( hdb, "'tau', '{07DEB510-677C-4A6F-A0A6-7CD8EFEA77ED}', 'TARGETDIR', 1, '', 'tau_file'" );
2802     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2803
2804     /* msidbFeatureAttributesFavorSource */
2805     r = add_feature_entry( hdb, "'nine', '', '', '', 2, 1, '', 1" );
2806     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2807
2808     r = add_component_entry( hdb, "'phi', '{9F0594C5-35AD-43EA-94DD-8DF73FAA664D}', 'TARGETDIR', 1, '', 'phi_file'" );
2809     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2810
2811     /* msidbFeatureAttributesFavorAdvertise */
2812     r = add_feature_entry( hdb, "'ten', '', '', '', 2, 1, '', 4" );
2813     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2814
2815     r = add_component_entry( hdb, "'chi', '{E6B539AB-5DA9-4236-A2D2-E341A50B4C38}', 'TARGETDIR', 1, '', 'chi_file'" );
2816     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2817
2818     /* msidbFeatureAttributesUIDisallowAbsent */
2819     r = add_feature_entry( hdb, "'eleven', '', '', '', 2, 1, '', 16" );
2820     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
2821
2822     r = add_component_entry( hdb, "'psi', '{A06B23B5-746B-427A-8A6E-FD6AC8F46A95}', 'TARGETDIR', 1, '', 'psi_file'" );
2823     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2824
2825     r = create_feature_components_table( hdb );
2826     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2827
2828     r = add_feature_components_entry( hdb, "'one', 'alpha'" );
2829     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2830
2831     r = add_feature_components_entry( hdb, "'one', 'beta'" );
2832     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2833
2834     r = add_feature_components_entry( hdb, "'one', 'gamma'" );
2835     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2836
2837     r = add_feature_components_entry( hdb, "'one', 'theta'" );
2838     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2839
2840     r = add_feature_components_entry( hdb, "'two', 'delta'" );
2841     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2842
2843     r = add_feature_components_entry( hdb, "'two', 'epsilon'" );
2844     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2845
2846     r = add_feature_components_entry( hdb, "'two', 'zeta'" );
2847     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2848
2849     r = add_feature_components_entry( hdb, "'two', 'iota'" );
2850     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2851
2852     r = add_feature_components_entry( hdb, "'three', 'eta'" );
2853     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2854
2855     r = add_feature_components_entry( hdb, "'four', 'eta'" );
2856     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2857
2858     r = add_feature_components_entry( hdb, "'five', 'eta'" );
2859     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2860
2861     r = add_feature_components_entry( hdb, "'six', 'lambda'" );
2862     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2863
2864     r = add_feature_components_entry( hdb, "'six', 'mu'" );
2865     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2866
2867     r = add_feature_components_entry( hdb, "'six', 'nu'" );
2868     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2869
2870     r = add_feature_components_entry( hdb, "'six', 'xi'" );
2871     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2872
2873     r = add_feature_components_entry( hdb, "'seven', 'omicron'" );
2874     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2875
2876     r = add_feature_components_entry( hdb, "'seven', 'pi'" );
2877     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2878
2879     r = add_feature_components_entry( hdb, "'seven', 'rho'" );
2880     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2881
2882     r = add_feature_components_entry( hdb, "'seven', 'sigma'" );
2883     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2884
2885     r = add_feature_components_entry( hdb, "'eight', 'tau'" );
2886     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2887
2888     r = add_feature_components_entry( hdb, "'nine', 'phi'" );
2889     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2890
2891     r = add_feature_components_entry( hdb, "'ten', 'chi'" );
2892     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2893
2894     r = add_feature_components_entry( hdb, "'eleven', 'psi'" );
2895     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2896
2897     r = create_file_table( hdb );
2898     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
2899
2900     r = add_file_entry( hdb, "'alpha_file', 'alpha', 'alpha.txt', 100, '', '1033', 8192, 1" );
2901     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2902
2903     r = add_file_entry( hdb, "'beta_file', 'beta', 'beta.txt', 0, '', '1033', 8192, 1" );
2904     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2905
2906     r = add_file_entry( hdb, "'gamma_file', 'gamma', 'gamma.txt', 0, '', '1033', 8192, 1" );
2907     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2908
2909     r = add_file_entry( hdb, "'theta_file', 'theta', 'theta.txt', 0, '', '1033', 8192, 1" );
2910     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2911
2912     r = add_file_entry( hdb, "'delta_file', 'delta', 'delta.txt', 0, '', '1033', 8192, 1" );
2913     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2914
2915     r = add_file_entry( hdb, "'epsilon_file', 'epsilon', 'epsilon.txt', 0, '', '1033', 8192, 1" );
2916     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2917
2918     r = add_file_entry( hdb, "'zeta_file', 'zeta', 'zeta.txt', 0, '', '1033', 8192, 1" );
2919     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2920
2921     r = add_file_entry( hdb, "'iota_file', 'iota', 'iota.txt', 0, '', '1033', 8192, 1" );
2922     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2923
2924     /* compressed file */
2925     r = add_file_entry( hdb, "'eta_file', 'eta', 'eta.txt', 0, '', '1033', 16384, 1" );
2926     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2927
2928     r = add_file_entry( hdb, "'kappa_file', 'kappa', 'kappa.txt', 0, '', '1033', 8192, 1" );
2929     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2930
2931     r = add_file_entry( hdb, "'lambda_file', 'lambda', 'lambda.txt', 100, '', '1033', 8192, 1" );
2932     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2933
2934     r = add_file_entry( hdb, "'mu_file', 'mu', 'mu.txt', 100, '', '1033', 8192, 1" );
2935     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2936
2937     r = add_file_entry( hdb, "'nu_file', 'nu', 'nu.txt', 100, '', '1033', 8192, 1" );
2938     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2939
2940     r = add_file_entry( hdb, "'xi_file', 'xi', 'xi.txt', 100, '', '1033', 8192, 1" );
2941     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2942
2943     r = add_file_entry( hdb, "'omicron_file', 'omicron', 'omicron.txt', 100, '', '1033', 8192, 1" );
2944     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2945
2946     r = add_file_entry( hdb, "'pi_file', 'pi', 'pi.txt', 100, '', '1033', 8192, 1" );
2947     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2948
2949     r = add_file_entry( hdb, "'rho_file', 'rho', 'rho.txt', 100, '', '1033', 8192, 1" );
2950     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2951
2952     r = add_file_entry( hdb, "'sigma_file', 'sigma', 'sigma.txt', 100, '', '1033', 8192, 1" );
2953     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2954
2955     r = add_file_entry( hdb, "'tau_file', 'tau', 'tau.txt', 100, '', '1033', 8192, 1" );
2956     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2957
2958     r = add_file_entry( hdb, "'phi_file', 'phi', 'phi.txt', 100, '', '1033', 8192, 1" );
2959     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2960
2961     r = add_file_entry( hdb, "'chi_file', 'chi', 'chi.txt', 100, '', '1033', 8192, 1" );
2962     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2963
2964     r = add_file_entry( hdb, "'psi_file', 'psi', 'psi.txt', 100, '', '1033', 8192, 1" );
2965     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
2966
2967     MsiDatabaseCommit(hdb);
2968
2969     /* these properties must not be in the saved msi file */
2970     r = add_property_entry( hdb, "'ADDLOCAL', 'one,four'");
2971     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
2972
2973     r = add_property_entry( hdb, "'ADDSOURCE', 'two,three'");
2974     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
2975
2976     r = add_property_entry( hdb, "'REMOVE', 'six,seven'");
2977     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
2978
2979     r = add_property_entry( hdb, "'REINSTALL', 'eight,nine,ten'");
2980     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
2981
2982     r = add_property_entry( hdb, "'REINSTALLMODE', 'omus'");
2983     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
2984
2985     r = package_from_db( hdb, &hpkg );
2986     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
2987     {
2988         skip("Not enough rights to perform tests\n");
2989         DeleteFile(msifile);
2990         return;
2991     }
2992     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
2993
2994     MsiCloseHandle(hdb);
2995
2996     CopyFileA(msifile, msifile2, FALSE);
2997     CopyFileA(msifile, msifile3, FALSE);
2998     CopyFileA(msifile, msifile4, FALSE);
2999
3000     test_feature_states( __LINE__, hpkg, "one", ERROR_UNKNOWN_FEATURE, 0, 0, 0 );
3001     test_component_states( __LINE__, hpkg, "alpha", ERROR_UNKNOWN_COMPONENT, 0, 0, 0 );
3002
3003     r = MsiDoAction( hpkg, "CostInitialize");
3004     ok( r == ERROR_SUCCESS, "cost init failed\n");
3005
3006     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3007     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3008
3009     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
3010
3011     r = MsiDoAction( hpkg, "FileCost");
3012     ok( r == ERROR_SUCCESS, "file cost failed\n");
3013
3014     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3015     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3016
3017     r = MsiDoAction( hpkg, "CostFinalize");
3018     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
3019
3020     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3021     test_feature_states( __LINE__, hpkg, "two", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
3022     test_feature_states( __LINE__, hpkg, "three", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3023     test_feature_states( __LINE__, hpkg, "four", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3024     test_feature_states( __LINE__, hpkg, "five", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3025     test_feature_states( __LINE__, hpkg, "six", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3026     test_feature_states( __LINE__, hpkg, "seven", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3027     test_feature_states( __LINE__, hpkg, "eight", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3028     test_feature_states( __LINE__, hpkg, "nine", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3029     test_feature_states( __LINE__, hpkg, "ten", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3030     test_feature_states( __LINE__, hpkg, "eleven", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3031
3032     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3033     test_component_states( __LINE__, hpkg, "beta", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
3034     test_component_states( __LINE__, hpkg, "gamma", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3035     test_component_states( __LINE__, hpkg, "theta", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3036     test_component_states( __LINE__, hpkg, "delta", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3037     test_component_states( __LINE__, hpkg, "epsilon", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
3038     test_component_states( __LINE__, hpkg, "zeta", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
3039     test_component_states( __LINE__, hpkg, "iota", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3040     test_component_states( __LINE__, hpkg, "eta", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
3041     test_component_states( __LINE__, hpkg, "kappa", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3042     test_component_states( __LINE__, hpkg, "lambda", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3043     test_component_states( __LINE__, hpkg, "mu", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3044     test_component_states( __LINE__, hpkg, "nu", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3045     test_component_states( __LINE__, hpkg, "xi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3046     test_component_states( __LINE__, hpkg, "omicron", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3047     test_component_states( __LINE__, hpkg, "pi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3048     test_component_states( __LINE__, hpkg, "rho", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3049     test_component_states( __LINE__, hpkg, "sigma", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3050     test_component_states( __LINE__, hpkg, "tau", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3051     test_component_states( __LINE__, hpkg, "phi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3052     test_component_states( __LINE__, hpkg, "chi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3053     test_component_states( __LINE__, hpkg, "psi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3054
3055     MsiCloseHandle( hpkg );
3056
3057     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
3058
3059     /* publish the features and components */
3060     r = MsiInstallProduct(msifile, "ADDLOCAL=one,four ADDSOURCE=two,three REMOVE=six,seven REINSTALL=eight,nine,ten");
3061     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3062
3063     r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
3064     ok(r == ERROR_SUCCESS, "failed to open database: %d\n", r);
3065
3066     /* these properties must not be in the saved msi file */
3067     r = add_property_entry( hdb, "'ADDLOCAL', 'one,four'");
3068     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3069
3070     r = add_property_entry( hdb, "'ADDSOURCE', 'two,three'");
3071     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3072
3073     r = add_property_entry( hdb, "'REMOVE', 'six,seven'");
3074     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3075
3076     r = add_property_entry( hdb, "'REINSTALL', 'eight,nine,ten'");
3077     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3078
3079     r = package_from_db( hdb, &hpkg );
3080     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3081
3082     MsiCloseHandle(hdb);
3083
3084     test_feature_states( __LINE__, hpkg, "one", ERROR_UNKNOWN_FEATURE, 0, 0, 0 );
3085     test_component_states( __LINE__, hpkg, "alpha", ERROR_UNKNOWN_COMPONENT, 0, 0, 0 );
3086
3087     r = MsiDoAction( hpkg, "CostInitialize");
3088     ok( r == ERROR_SUCCESS, "cost init failed\n");
3089
3090     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3091     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3092
3093     r = MsiDoAction( hpkg, "FileCost");
3094     ok( r == ERROR_SUCCESS, "file cost failed\n");
3095
3096     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3097     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3098
3099     r = MsiDoAction( hpkg, "CostFinalize");
3100     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
3101
3102     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_LOCAL, 0 );
3103     test_feature_states( __LINE__, hpkg, "two", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3104     test_feature_states( __LINE__, hpkg, "three", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3105     test_feature_states( __LINE__, hpkg, "four", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3106     test_feature_states( __LINE__, hpkg, "five", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3107     test_feature_states( __LINE__, hpkg, "six", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3108     test_feature_states( __LINE__, hpkg, "seven", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3109     test_feature_states( __LINE__, hpkg, "eight", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3110     test_feature_states( __LINE__, hpkg, "nine", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3111     test_feature_states( __LINE__, hpkg, "ten", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3112     test_feature_states( __LINE__, hpkg, "eleven", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3113
3114     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3115     test_component_states( __LINE__, hpkg, "beta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3116     test_component_states( __LINE__, hpkg, "gamma", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3117     test_component_states( __LINE__, hpkg, "theta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3118     test_component_states( __LINE__, hpkg, "delta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3119     test_component_states( __LINE__, hpkg, "epsilon", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3120     test_component_states( __LINE__, hpkg, "zeta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3121     test_component_states( __LINE__, hpkg, "iota", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3122     test_component_states( __LINE__, hpkg, "eta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3123     test_component_states( __LINE__, hpkg, "kappa", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3124     test_component_states( __LINE__, hpkg, "lambda", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3125     test_component_states( __LINE__, hpkg, "mu", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3126     test_component_states( __LINE__, hpkg, "nu", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3127     test_component_states( __LINE__, hpkg, "xi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3128     test_component_states( __LINE__, hpkg, "omicron", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3129     test_component_states( __LINE__, hpkg, "pi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3130     test_component_states( __LINE__, hpkg, "rho", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3131     test_component_states( __LINE__, hpkg, "sigma", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3132     test_component_states( __LINE__, hpkg, "tau", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3133     test_component_states( __LINE__, hpkg, "phi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3134     test_component_states( __LINE__, hpkg, "chi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3135     test_component_states( __LINE__, hpkg, "psi", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3136
3137     MsiCloseHandle(hpkg);
3138
3139     /* uninstall the product */
3140     r = MsiInstallProduct(msifile, "REMOVE=ALL");
3141     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3142
3143     /* all features installed locally */
3144     r = MsiInstallProduct(msifile2, "ADDLOCAL=ALL");
3145     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3146
3147     r = MsiOpenDatabase(msifile2, MSIDBOPEN_DIRECT, &hdb);
3148     ok(r == ERROR_SUCCESS, "failed to open database: %d\n", r);
3149
3150     /* these properties must not be in the saved msi file */
3151     r = add_property_entry( hdb, "'ADDLOCAL', 'one,two,three,four,five,six,seven,eight,nine,ten'");
3152     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3153
3154     r = package_from_db( hdb, &hpkg );
3155     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3156
3157     test_feature_states( __LINE__, hpkg, "one", ERROR_UNKNOWN_FEATURE, 0, 0, 0 );
3158     test_component_states( __LINE__, hpkg, "alpha", ERROR_UNKNOWN_COMPONENT, 0, 0, 0 );
3159
3160     r = MsiDoAction( hpkg, "CostInitialize");
3161     ok( r == ERROR_SUCCESS, "cost init failed\n");
3162
3163     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3164     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3165
3166     r = MsiDoAction( hpkg, "CostFinalize");
3167     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
3168
3169     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_LOCAL, 0 );
3170     test_feature_states( __LINE__, hpkg, "two", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_LOCAL, 0 );
3171     test_feature_states( __LINE__, hpkg, "three", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3172     test_feature_states( __LINE__, hpkg, "four", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3173     test_feature_states( __LINE__, hpkg, "five", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3174     test_feature_states( __LINE__, hpkg, "six", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_LOCAL, 0 );
3175     test_feature_states( __LINE__, hpkg, "seven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_LOCAL, 0 );
3176     test_feature_states( __LINE__, hpkg, "eight", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 1 );
3177     test_feature_states( __LINE__, hpkg, "nine", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 1 );
3178     test_feature_states( __LINE__, hpkg, "ten", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 1 );
3179     test_feature_states( __LINE__, hpkg, "eleven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3180
3181     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3182     test_component_states( __LINE__, hpkg, "beta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3183     test_component_states( __LINE__, hpkg, "gamma", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3184     test_component_states( __LINE__, hpkg, "theta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3185     test_component_states( __LINE__, hpkg, "delta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3186     test_component_states( __LINE__, hpkg, "epsilon", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3187     test_component_states( __LINE__, hpkg, "zeta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3188     test_component_states( __LINE__, hpkg, "iota", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3189     test_component_states( __LINE__, hpkg, "eta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3190     test_component_states( __LINE__, hpkg, "kappa", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3191     test_component_states( __LINE__, hpkg, "lambda", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3192     test_component_states( __LINE__, hpkg, "mu", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3193     test_component_states( __LINE__, hpkg, "nu", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3194     test_component_states( __LINE__, hpkg, "xi", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3195     test_component_states( __LINE__, hpkg, "omicron", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3196     test_component_states( __LINE__, hpkg, "pi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3197     test_component_states( __LINE__, hpkg, "rho", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3198     test_component_states( __LINE__, hpkg, "sigma", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3199     test_component_states( __LINE__, hpkg, "tau", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3200     test_component_states( __LINE__, hpkg, "phi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3201     test_component_states( __LINE__, hpkg, "chi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3202     test_component_states( __LINE__, hpkg, "psi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3203
3204     MsiCloseHandle(hpkg);
3205
3206     /* uninstall the product */
3207     r = MsiInstallProduct(msifile2, "REMOVE=ALL");
3208     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3209
3210     /* all features installed from source */
3211     r = MsiInstallProduct(msifile3, "ADDSOURCE=ALL");
3212     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3213
3214     r = MsiOpenDatabase(msifile3, MSIDBOPEN_DIRECT, &hdb);
3215     ok(r == ERROR_SUCCESS, "failed to open database: %d\n", r);
3216
3217     /* this property must not be in the saved msi file */
3218     r = add_property_entry( hdb, "'ADDSOURCE', 'one,two,three,four,five,six,seven,eight,nine,ten'");
3219     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3220
3221     r = package_from_db( hdb, &hpkg );
3222     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3223
3224     test_feature_states( __LINE__, hpkg, "one", ERROR_UNKNOWN_FEATURE, 0, 0, 0 );
3225     test_component_states( __LINE__, hpkg, "alpha", ERROR_UNKNOWN_COMPONENT, 0, 0, 0 );
3226
3227     r = MsiDoAction( hpkg, "CostInitialize");
3228     ok( r == ERROR_SUCCESS, "cost init failed\n");
3229
3230     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3231     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3232
3233     r = MsiDoAction( hpkg, "FileCost");
3234     ok( r == ERROR_SUCCESS, "file cost failed\n");
3235
3236     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3237     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3238
3239     r = MsiDoAction( hpkg, "CostFinalize");
3240     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
3241
3242     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3243     test_feature_states( __LINE__, hpkg, "two", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3244     test_feature_states( __LINE__, hpkg, "three", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3245     test_feature_states( __LINE__, hpkg, "four", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3246     test_feature_states( __LINE__, hpkg, "five", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3247     test_feature_states( __LINE__, hpkg, "six", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3248     test_feature_states( __LINE__, hpkg, "seven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3249     test_feature_states( __LINE__, hpkg, "eight", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3250     test_feature_states( __LINE__, hpkg, "nine", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3251     test_feature_states( __LINE__, hpkg, "ten", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3252     test_feature_states( __LINE__, hpkg, "eleven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3253
3254     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3255     test_component_states( __LINE__, hpkg, "beta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3256     test_component_states( __LINE__, hpkg, "gamma", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3257     test_component_states( __LINE__, hpkg, "theta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3258     test_component_states( __LINE__, hpkg, "delta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3259     test_component_states( __LINE__, hpkg, "epsilon", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3260     test_component_states( __LINE__, hpkg, "zeta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3261     test_component_states( __LINE__, hpkg, "iota", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3262     test_component_states( __LINE__, hpkg, "eta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3263     test_component_states( __LINE__, hpkg, "kappa", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3264     test_component_states( __LINE__, hpkg, "lambda", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3265     test_component_states( __LINE__, hpkg, "mu", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3266     test_component_states( __LINE__, hpkg, "nu", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3267     test_component_states( __LINE__, hpkg, "xi", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3268     test_component_states( __LINE__, hpkg, "omicron", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3269     test_component_states( __LINE__, hpkg, "pi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3270     test_component_states( __LINE__, hpkg, "rho", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3271     test_component_states( __LINE__, hpkg, "sigma", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3272     test_component_states( __LINE__, hpkg, "tau", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3273     test_component_states( __LINE__, hpkg, "phi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3274     test_component_states( __LINE__, hpkg, "chi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3275     test_component_states( __LINE__, hpkg, "psi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3276
3277     MsiCloseHandle(hpkg);
3278
3279     /* reinstall the product */
3280     r = MsiInstallProduct(msifile3, "REINSTALL=ALL");
3281     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3282
3283     r = MsiOpenDatabase(msifile4, MSIDBOPEN_DIRECT, &hdb);
3284     ok(r == ERROR_SUCCESS, "failed to open database: %d\n", r);
3285
3286     /* this property must not be in the saved msi file */
3287     r = add_property_entry( hdb, "'ADDSOURCE', 'one,two,three,four,five,six,seven,eight,nine,ten'");
3288     ok( r == ERROR_SUCCESS, "cannot add property: %d\n", r );
3289
3290     r = package_from_db( hdb, &hpkg );
3291     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3292
3293     test_feature_states( __LINE__, hpkg, "one", ERROR_UNKNOWN_FEATURE, 0, 0, 0 );
3294     test_component_states( __LINE__, hpkg, "alpha", ERROR_UNKNOWN_COMPONENT, 0, 0, 0 );
3295
3296     r = MsiDoAction( hpkg, "CostInitialize");
3297     ok( r == ERROR_SUCCESS, "cost init failed\n");
3298
3299     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3300     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3301
3302     r = MsiDoAction( hpkg, "FileCost");
3303     ok( r == ERROR_SUCCESS, "file cost failed\n");
3304
3305     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3306     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
3307
3308     r = MsiDoAction( hpkg, "CostFinalize");
3309     ok( r == ERROR_SUCCESS, "cost finalize failed: %d\n", r);
3310
3311     test_feature_states( __LINE__, hpkg, "one", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3312     test_feature_states( __LINE__, hpkg, "two", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3313     test_feature_states( __LINE__, hpkg, "three", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3314     test_feature_states( __LINE__, hpkg, "four", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3315     test_feature_states( __LINE__, hpkg, "five", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3316     test_feature_states( __LINE__, hpkg, "six", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3317     test_feature_states( __LINE__, hpkg, "seven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3318     test_feature_states( __LINE__, hpkg, "eight", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3319     test_feature_states( __LINE__, hpkg, "nine", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3320     test_feature_states( __LINE__, hpkg, "ten", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_SOURCE, 0 );
3321     test_feature_states( __LINE__, hpkg, "eleven", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 1 );
3322
3323     test_component_states( __LINE__, hpkg, "alpha", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3324     test_component_states( __LINE__, hpkg, "beta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3325     test_component_states( __LINE__, hpkg, "gamma", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3326     test_component_states( __LINE__, hpkg, "theta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3327     test_component_states( __LINE__, hpkg, "delta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3328     test_component_states( __LINE__, hpkg, "epsilon", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3329     test_component_states( __LINE__, hpkg, "zeta", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3330     test_component_states( __LINE__, hpkg, "iota", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3331     test_component_states( __LINE__, hpkg, "eta", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3332     test_component_states( __LINE__, hpkg, "kappa", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
3333     test_component_states( __LINE__, hpkg, "lambda", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3334     test_component_states( __LINE__, hpkg, "mu", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3335     test_component_states( __LINE__, hpkg, "nu", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3336     test_component_states( __LINE__, hpkg, "xi", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3337     test_component_states( __LINE__, hpkg, "omicron", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3338     test_component_states( __LINE__, hpkg, "pi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3339     test_component_states( __LINE__, hpkg, "rho", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3340     test_component_states( __LINE__, hpkg, "sigma", ERROR_SUCCESS, INSTALLSTATE_LOCAL, INSTALLSTATE_LOCAL, 0 );
3341     test_component_states( __LINE__, hpkg, "tau", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3342     test_component_states( __LINE__, hpkg, "phi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3343     test_component_states( __LINE__, hpkg, "chi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3344     test_component_states( __LINE__, hpkg, "psi", ERROR_SUCCESS, INSTALLSTATE_SOURCE, INSTALLSTATE_UNKNOWN, 0 );
3345
3346     MsiCloseHandle(hpkg);
3347
3348     /* uninstall the product */
3349     r = MsiInstallProduct(msifile4, "REMOVE=ALL");
3350     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3351
3352     DeleteFileA(msifile);
3353     DeleteFileA(msifile2);
3354     DeleteFileA(msifile3);
3355     DeleteFileA(msifile4);
3356 }
3357
3358 static void test_getproperty(void)
3359 {
3360     MSIHANDLE hPackage = 0;
3361     char prop[100];
3362     static CHAR empty[] = "";
3363     DWORD size;
3364     UINT r;
3365
3366     r = package_from_db(create_package_db(), &hPackage);
3367     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
3368     {
3369         skip("Not enough rights to perform tests\n");
3370         DeleteFile(msifile);
3371         return;
3372     }
3373     ok( r == ERROR_SUCCESS, "Failed to create package %u\n", r );
3374
3375     /* set the property */
3376     r = MsiSetProperty(hPackage, "Name", "Value");
3377     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3378
3379     /* retrieve the size, NULL pointer */
3380     size = 0;
3381     r = MsiGetProperty(hPackage, "Name", NULL, &size);
3382     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3383     ok( size == 5, "Expected 5, got %d\n", size);
3384
3385     /* retrieve the size, empty string */
3386     size = 0;
3387     r = MsiGetProperty(hPackage, "Name", empty, &size);
3388     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
3389     ok( size == 5, "Expected 5, got %d\n", size);
3390
3391     /* don't change size */
3392     r = MsiGetProperty(hPackage, "Name", prop, &size);
3393     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
3394     ok( size == 5, "Expected 5, got %d\n", size);
3395     ok( !lstrcmp(prop, "Valu"), "Expected Valu, got %s\n", prop);
3396
3397     /* increase the size by 1 */
3398     size++;
3399     r = MsiGetProperty(hPackage, "Name", prop, &size);
3400     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3401     ok( size == 5, "Expected 5, got %d\n", size);
3402     ok( !lstrcmp(prop, "Value"), "Expected Value, got %s\n", prop);
3403
3404     r = MsiCloseHandle( hPackage);
3405     ok( r == ERROR_SUCCESS , "Failed to close package\n" );
3406     DeleteFile(msifile);
3407 }
3408
3409 static void test_removefiles(void)
3410 {
3411     MSIHANDLE hpkg;
3412     UINT r;
3413     MSIHANDLE hdb;
3414     INSTALLSTATE installed, action;
3415
3416     hdb = create_package_db();
3417     ok ( hdb, "failed to create package database\n" );
3418
3419     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
3420     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
3421
3422     r = create_feature_table( hdb );
3423     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
3424
3425     r = create_component_table( hdb );
3426     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
3427
3428     r = add_feature_entry( hdb, "'one', '', '', '', 2, 1, '', 0" );
3429     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
3430
3431     r = add_component_entry( hdb, "'hydrogen', '', 'TARGETDIR', 0, '', 'hydrogen_file'" );
3432     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3433
3434     r = add_component_entry( hdb, "'helium', '', 'TARGETDIR', 0, '', 'helium_file'" );
3435     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3436
3437     r = add_component_entry( hdb, "'lithium', '', 'TARGETDIR', 0, '', 'lithium_file'" );
3438     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3439
3440     r = add_component_entry( hdb, "'beryllium', '', 'TARGETDIR', 0, '', 'beryllium_file'" );
3441     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3442
3443     r = add_component_entry( hdb, "'boron', '', 'TARGETDIR', 0, '', 'boron_file'" );
3444     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3445
3446     r = add_component_entry( hdb, "'carbon', '', 'TARGETDIR', 0, '', 'carbon_file'" );
3447     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3448
3449     r = add_component_entry( hdb, "'oxygen', '', 'TARGETDIR', 0, '0', 'oxygen_file'" );
3450     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3451
3452     r = create_feature_components_table( hdb );
3453     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
3454
3455     r = add_feature_components_entry( hdb, "'one', 'hydrogen'" );
3456     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3457
3458     r = add_feature_components_entry( hdb, "'one', 'helium'" );
3459     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3460
3461     r = add_feature_components_entry( hdb, "'one', 'lithium'" );
3462     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3463
3464     r = add_feature_components_entry( hdb, "'one', 'beryllium'" );
3465     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3466
3467     r = add_feature_components_entry( hdb, "'one', 'boron'" );
3468     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3469
3470     r = add_feature_components_entry( hdb, "'one', 'carbon'" );
3471     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3472
3473     r = add_feature_components_entry( hdb, "'one', 'oxygen'" );
3474     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3475
3476     r = create_file_table( hdb );
3477     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
3478
3479     r = add_file_entry( hdb, "'hydrogen_file', 'hydrogen', 'hydrogen.txt', 0, '', '1033', 8192, 1" );
3480     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3481
3482     r = add_file_entry( hdb, "'helium_file', 'helium', 'helium.txt', 0, '', '1033', 8192, 1" );
3483     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3484
3485     r = add_file_entry( hdb, "'lithium_file', 'lithium', 'lithium.txt', 0, '', '1033', 8192, 1" );
3486     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3487
3488     r = add_file_entry( hdb, "'beryllium_file', 'beryllium', 'beryllium.txt', 0, '', '1033', 16384, 1" );
3489     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3490
3491     r = add_file_entry( hdb, "'boron_file', 'boron', 'boron.txt', 0, '', '1033', 16384, 1" );
3492     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3493
3494     r = add_file_entry( hdb, "'carbon_file', 'carbon', 'carbon.txt', 0, '', '1033', 16384, 1" );
3495     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3496
3497     r = add_file_entry( hdb, "'oxygen_file', 'oxygen', 'oxygen.txt', 0, '', '1033', 16384, 1" );
3498     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
3499
3500     r = create_remove_file_table( hdb );
3501     ok( r == ERROR_SUCCESS, "cannot create Remove File table: %d\n", r);
3502
3503     r = package_from_db( hdb, &hpkg );
3504     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
3505     {
3506         skip("Not enough rights to perform tests\n");
3507         DeleteFile(msifile);
3508         return;
3509     }
3510     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3511
3512     MsiCloseHandle( hdb );
3513
3514     create_test_file( "hydrogen.txt" );
3515     create_test_file( "helium.txt" );
3516     create_test_file( "lithium.txt" );
3517     create_test_file( "beryllium.txt" );
3518     create_test_file( "boron.txt" );
3519     create_test_file( "carbon.txt" );
3520     create_test_file( "oxygen.txt" );
3521
3522     r = MsiSetProperty( hpkg, "TARGETDIR", CURR_DIR );
3523     ok( r == ERROR_SUCCESS, "set property failed\n");
3524
3525     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
3526
3527     r = MsiGetComponentState( hpkg, "oxygen", &installed, &action );
3528     ok( r == ERROR_UNKNOWN_COMPONENT, "expected ERROR_UNKNOWN_COMPONENT, got %u\n", r );
3529
3530     r = MsiDoAction( hpkg, "CostInitialize");
3531     ok( r == ERROR_SUCCESS, "cost init failed\n");
3532
3533     r = MsiDoAction( hpkg, "FileCost");
3534     ok( r == ERROR_SUCCESS, "file cost failed\n");
3535
3536     installed = action = 0xdeadbeef;
3537     r = MsiGetComponentState( hpkg, "oxygen", &installed, &action );
3538     ok( r == ERROR_SUCCESS, "failed to get component state %u\n", r );
3539     ok( installed == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", installed );
3540     ok( action == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", action );
3541
3542     r = MsiDoAction( hpkg, "CostFinalize");
3543     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
3544
3545     r = MsiDoAction( hpkg, "InstallValidate");
3546     ok( r == ERROR_SUCCESS, "install validate failed\n");
3547
3548     r = MsiSetComponentState( hpkg, "hydrogen", INSTALLSTATE_ABSENT );
3549     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3550
3551     installed = action = 0xdeadbeef;
3552     r = MsiGetComponentState( hpkg, "hydrogen", &installed, &action );
3553     ok( r == ERROR_SUCCESS, "failed to get component state %u\n", r );
3554     ok( installed == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", installed );
3555     todo_wine ok( action == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", action );
3556
3557     r = MsiSetComponentState( hpkg, "helium", INSTALLSTATE_LOCAL );
3558     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3559
3560     r = MsiSetComponentState( hpkg, "lithium", INSTALLSTATE_SOURCE );
3561     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3562
3563     r = MsiSetComponentState( hpkg, "beryllium", INSTALLSTATE_ABSENT );
3564     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3565
3566     r = MsiSetComponentState( hpkg, "boron", INSTALLSTATE_LOCAL );
3567     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3568
3569     r = MsiSetComponentState( hpkg, "carbon", INSTALLSTATE_SOURCE );
3570     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3571
3572     installed = action = 0xdeadbeef;
3573     r = MsiGetComponentState( hpkg, "oxygen", &installed, &action );
3574     ok( r == ERROR_SUCCESS, "failed to get component state %u\n", r );
3575     ok( installed == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", installed );
3576     ok( action == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", action );
3577
3578     r = MsiSetComponentState( hpkg, "oxygen", INSTALLSTATE_ABSENT );
3579     ok( r == ERROR_SUCCESS, "failed to set component state: %d\n", r);
3580
3581     installed = action = 0xdeadbeef;
3582     r = MsiGetComponentState( hpkg, "oxygen", &installed, &action );
3583     ok( r == ERROR_SUCCESS, "failed to get component state %u\n", r );
3584     ok( installed == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", installed );
3585     ok( action == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", action );
3586
3587     r = MsiDoAction( hpkg, "RemoveFiles");
3588     ok( r == ERROR_SUCCESS, "remove files failed\n");
3589
3590     installed = action = 0xdeadbeef;
3591     r = MsiGetComponentState( hpkg, "oxygen", &installed, &action );
3592     ok( r == ERROR_SUCCESS, "failed to get component state %u\n", r );
3593     ok( installed == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", installed );
3594     ok( action == INSTALLSTATE_UNKNOWN, "expected INSTALLSTATE_UNKNOWN, got %d\n", action );
3595
3596     ok(DeleteFileA("hydrogen.txt"), "Expected hydrogen.txt to exist\n");
3597     ok(DeleteFileA("lithium.txt"), "Expected lithium.txt to exist\n");    
3598     ok(DeleteFileA("beryllium.txt"), "Expected beryllium.txt to exist\n");
3599     ok(DeleteFileA("carbon.txt"), "Expected carbon.txt to exist\n");
3600     ok(DeleteFileA("helium.txt"), "Expected helium.txt to exist\n");
3601     ok(DeleteFileA("boron.txt"), "Expected boron.txt to exist\n");
3602     ok(DeleteFileA("oxygen.txt"), "Expected oxygen.txt to exist\n");
3603
3604     MsiCloseHandle( hpkg );
3605     DeleteFileA(msifile);
3606 }
3607
3608 static void test_appsearch(void)
3609 {
3610     MSIHANDLE hpkg;
3611     UINT r;
3612     MSIHANDLE hdb;
3613     CHAR prop[MAX_PATH];
3614     DWORD size;
3615
3616     hdb = create_package_db();
3617     ok ( hdb, "failed to create package database\n" );
3618
3619     r = create_appsearch_table( hdb );
3620     ok( r == ERROR_SUCCESS, "cannot create AppSearch table: %d\n", r );
3621
3622     r = add_appsearch_entry( hdb, "'WEBBROWSERPROG', 'NewSignature1'" );
3623     ok( r == ERROR_SUCCESS, "cannot add entry: %d\n", r );
3624
3625     r = add_appsearch_entry( hdb, "'NOTEPAD', 'NewSignature2'" );
3626     ok( r == ERROR_SUCCESS, "cannot add entry: %d\n", r );
3627
3628     r = create_reglocator_table( hdb );
3629     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
3630
3631     r = add_reglocator_entry( hdb, "NewSignature1", 0, "htmlfile\\shell\\open\\command", "", 1 );
3632     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
3633
3634     r = create_drlocator_table( hdb );
3635     ok( r == ERROR_SUCCESS, "cannot create DrLocator table: %d\n", r );
3636
3637     r = add_drlocator_entry( hdb, "'NewSignature2', 0, 'c:\\windows\\system32', 0" );
3638     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
3639
3640     r = create_signature_table( hdb );
3641     ok( r == ERROR_SUCCESS, "cannot create Signature table: %d\n", r );
3642
3643     r = add_signature_entry( hdb, "'NewSignature1', 'FileName', '', '', '', '', '', '', ''" );
3644     ok( r == ERROR_SUCCESS, "cannot add signature: %d\n", r );
3645
3646     r = add_signature_entry( hdb, "'NewSignature2', 'NOTEPAD.EXE|notepad.exe', '', '', '', '', '', '', ''" );
3647     ok( r == ERROR_SUCCESS, "cannot add signature: %d\n", r );
3648
3649     r = package_from_db( hdb, &hpkg );
3650     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
3651     {
3652         skip("Not enough rights to perform tests\n");
3653         DeleteFile(msifile);
3654         return;
3655     }
3656     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
3657     MsiCloseHandle( hdb );
3658     if (r != ERROR_SUCCESS)
3659         goto done;
3660
3661     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
3662
3663     r = MsiDoAction( hpkg, "AppSearch" );
3664     ok( r == ERROR_SUCCESS, "AppSearch failed: %d\n", r);
3665
3666     size = sizeof(prop);
3667     r = MsiGetPropertyA( hpkg, "WEBBROWSERPROG", prop, &size );
3668     ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
3669     ok( lstrlenA(prop) != 0, "Expected non-zero length\n");
3670
3671     size = sizeof(prop);
3672     r = MsiGetPropertyA( hpkg, "NOTEPAD", prop, &size );
3673     ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
3674
3675 done:
3676     MsiCloseHandle( hpkg );
3677     DeleteFileA(msifile);
3678 }
3679
3680 static void test_appsearch_complocator(void)
3681 {
3682     MSIHANDLE hpkg, hdb;
3683     CHAR path[MAX_PATH];
3684     CHAR prop[MAX_PATH];
3685     LPSTR usersid;
3686     DWORD size;
3687     UINT r;
3688
3689     if (!(usersid = get_user_sid()))
3690         return;
3691
3692     if (is_process_limited())
3693     {
3694         skip("process is limited\n");
3695         return;
3696     }
3697
3698     create_test_file("FileName1");
3699     create_test_file("FileName4");
3700     set_component_path("FileName1", MSIINSTALLCONTEXT_MACHINE,
3701                        "{A8AE6692-96BA-4198-8399-145D7D1D0D0E}", NULL, FALSE);
3702
3703     create_test_file("FileName2");
3704     set_component_path("FileName2", MSIINSTALLCONTEXT_USERUNMANAGED,
3705                        "{1D2CE6F3-E81C-4949-AB81-78D7DAD2AF2E}", usersid, FALSE);
3706
3707     create_test_file("FileName3");
3708     set_component_path("FileName3", MSIINSTALLCONTEXT_USERMANAGED,
3709                        "{19E0B999-85F5-4973-A61B-DBE4D66ECB1D}", usersid, FALSE);
3710
3711     create_test_file("FileName5");
3712     set_component_path("FileName5", MSIINSTALLCONTEXT_MACHINE,
3713                        "{F0CCA976-27A3-4808-9DDD-1A6FD50A0D5A}", NULL, TRUE);
3714
3715     create_test_file("FileName6");
3716     set_component_path("FileName6", MSIINSTALLCONTEXT_MACHINE,
3717                        "{C0ECD96F-7898-4410-9667-194BD8C1B648}", NULL, TRUE);
3718
3719     create_test_file("FileName7");
3720     set_component_path("FileName7", MSIINSTALLCONTEXT_MACHINE,
3721                        "{DB20F535-9C26-4127-9C2B-CC45A8B51DA1}", NULL, FALSE);
3722
3723     /* dir is FALSE, but we're pretending it's a directory */
3724     set_component_path("IDontExist\\", MSIINSTALLCONTEXT_MACHINE,
3725                        "{91B7359B-07F2-4221-AA8D-DE102BB87A5F}", NULL, FALSE);
3726
3727     create_file_with_version("FileName8.dll", MAKELONG(2, 1), MAKELONG(4, 3));
3728     set_component_path("FileName8.dll", MSIINSTALLCONTEXT_MACHINE,
3729                        "{4A2E1B5B-4034-4177-833B-8CC35F1B3EF1}", NULL, FALSE);
3730
3731     create_file_with_version("FileName9.dll", MAKELONG(1, 2), MAKELONG(3, 4));
3732     set_component_path("FileName9.dll", MSIINSTALLCONTEXT_MACHINE,
3733                        "{A204DF48-7346-4635-BA2E-66247DBAC9DF}", NULL, FALSE);
3734
3735     create_file_with_version("FileName10.dll", MAKELONG(2, 1), MAKELONG(4, 3));
3736     set_component_path("FileName10.dll", MSIINSTALLCONTEXT_MACHINE,
3737                        "{EC30CE73-4CF9-4908-BABD-1ED82E1515FD}", NULL, FALSE);
3738
3739     hdb = create_package_db();
3740     ok(hdb, "Expected a valid database handle\n");
3741
3742     r = create_appsearch_table(hdb);
3743     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3744
3745     r = add_appsearch_entry(hdb, "'SIGPROP1', 'NewSignature1'");
3746     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3747
3748     r = add_appsearch_entry(hdb, "'SIGPROP2', 'NewSignature2'");
3749     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3750
3751     r = add_appsearch_entry(hdb, "'SIGPROP3', 'NewSignature3'");
3752     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3753
3754     r = add_appsearch_entry(hdb, "'SIGPROP4', 'NewSignature4'");
3755     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3756
3757     r = add_appsearch_entry(hdb, "'SIGPROP5', 'NewSignature5'");
3758     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3759
3760     r = add_appsearch_entry(hdb, "'SIGPROP6', 'NewSignature6'");
3761     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3762
3763     r = add_appsearch_entry(hdb, "'SIGPROP7', 'NewSignature7'");
3764     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3765
3766     r = add_appsearch_entry(hdb, "'SIGPROP8', 'NewSignature8'");
3767     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3768
3769     r = add_appsearch_entry(hdb, "'SIGPROP9', 'NewSignature9'");
3770     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3771
3772     r = add_appsearch_entry(hdb, "'SIGPROP10', 'NewSignature10'");
3773     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3774
3775     r = add_appsearch_entry(hdb, "'SIGPROP11', 'NewSignature11'");
3776     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3777
3778     r = add_appsearch_entry(hdb, "'SIGPROP12', 'NewSignature12'");
3779     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3780
3781     r = create_complocator_table(hdb);
3782     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3783
3784     /* published component, machine, file, signature, misdbLocatorTypeFile */
3785     r = add_complocator_entry(hdb, "'NewSignature1', '{A8AE6692-96BA-4198-8399-145D7D1D0D0E}', 1");
3786     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3787
3788     /* published component, user-unmanaged, file, signature, misdbLocatorTypeFile */
3789     r = add_complocator_entry(hdb, "'NewSignature2', '{1D2CE6F3-E81C-4949-AB81-78D7DAD2AF2E}', 1");
3790     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3791
3792     /* published component, user-managed, file, signature, misdbLocatorTypeFile */
3793     r = add_complocator_entry(hdb, "'NewSignature3', '{19E0B999-85F5-4973-A61B-DBE4D66ECB1D}', 1");
3794     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3795
3796     /* published component, machine, file, signature, misdbLocatorTypeDirectory */
3797     r = add_complocator_entry(hdb, "'NewSignature4', '{A8AE6692-96BA-4198-8399-145D7D1D0D0E}', 0");
3798     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3799
3800     /* published component, machine, dir, signature, misdbLocatorTypeDirectory */
3801     r = add_complocator_entry(hdb, "'NewSignature5', '{F0CCA976-27A3-4808-9DDD-1A6FD50A0D5A}', 0");
3802     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3803
3804     /* published component, machine, dir, no signature, misdbLocatorTypeDirectory */
3805     r = add_complocator_entry(hdb, "'NewSignature6', '{C0ECD96F-7898-4410-9667-194BD8C1B648}', 0");
3806     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3807
3808     /* published component, machine, file, no signature, misdbLocatorTypeFile */
3809     r = add_complocator_entry(hdb, "'NewSignature7', '{DB20F535-9C26-4127-9C2B-CC45A8B51DA1}', 1");
3810     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3811
3812     /* unpublished component, no signature, misdbLocatorTypeDir */
3813     r = add_complocator_entry(hdb, "'NewSignature8', '{FB671D5B-5083-4048-90E0-481C48D8F3A5}', 0");
3814     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3815
3816     /* published component, no signature, dir does not exist misdbLocatorTypeDir */
3817     r = add_complocator_entry(hdb, "'NewSignature9', '{91B7359B-07F2-4221-AA8D-DE102BB87A5F}', 0");
3818     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3819
3820     /* published component, signature w/ ver, misdbLocatorTypeFile */
3821     r = add_complocator_entry(hdb, "'NewSignature10', '{4A2E1B5B-4034-4177-833B-8CC35F1B3EF1}', 1");
3822     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3823
3824     /* published component, signature w/ ver, ver > max, misdbLocatorTypeFile */
3825     r = add_complocator_entry(hdb, "'NewSignature11', '{A204DF48-7346-4635-BA2E-66247DBAC9DF}', 1");
3826     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3827
3828     /* published component, signature w/ ver, sig->name ignored, misdbLocatorTypeFile */
3829     r = add_complocator_entry(hdb, "'NewSignature12', '{EC30CE73-4CF9-4908-BABD-1ED82E1515FD}', 1");
3830     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3831
3832     r = create_signature_table(hdb);
3833     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3834
3835     r = add_signature_entry(hdb, "'NewSignature1', 'FileName1', '', '', '', '', '', '', ''");
3836     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3837
3838     r = add_signature_entry(hdb, "'NewSignature2', 'FileName2', '', '', '', '', '', '', ''");
3839     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3840
3841     r = add_signature_entry(hdb, "'NewSignature3', 'FileName3', '', '', '', '', '', '', ''");
3842     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3843
3844     r = add_signature_entry(hdb, "'NewSignature4', 'FileName4', '', '', '', '', '', '', ''");
3845     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3846
3847     r = add_signature_entry(hdb, "'NewSignature5', 'FileName5', '', '', '', '', '', '', ''");
3848     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3849
3850     r = add_signature_entry(hdb, "'NewSignature10', 'FileName8.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
3851     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3852
3853     r = add_signature_entry(hdb, "'NewSignature11', 'FileName9.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
3854     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3855
3856     r = add_signature_entry(hdb, "'NewSignature12', 'ignored', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
3857     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3858
3859     r = package_from_db(hdb, &hpkg);
3860     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
3861     {
3862         skip("Not enough rights to perform tests\n");
3863         goto error;
3864     }
3865     ok(r == ERROR_SUCCESS, "Expected a valid package handle %u\n", r);
3866
3867     r = MsiSetPropertyA(hpkg, "SIGPROP8", "october");
3868     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3869
3870     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
3871
3872     r = MsiDoAction(hpkg, "AppSearch");
3873     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3874
3875     size = MAX_PATH;
3876     sprintf(path, "%s\\FileName1", CURR_DIR);
3877     r = MsiGetPropertyA(hpkg, "SIGPROP1", prop, &size);
3878     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3879     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3880
3881     size = MAX_PATH;
3882     sprintf(path, "%s\\FileName2", CURR_DIR);
3883     r = MsiGetPropertyA(hpkg, "SIGPROP2", prop, &size);
3884     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3885     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3886
3887     size = MAX_PATH;
3888     sprintf(path, "%s\\FileName3", CURR_DIR);
3889     r = MsiGetPropertyA(hpkg, "SIGPROP3", prop, &size);
3890     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3891     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3892
3893     size = MAX_PATH;
3894     sprintf(path, "%s\\FileName4", CURR_DIR);
3895     r = MsiGetPropertyA(hpkg, "SIGPROP4", prop, &size);
3896     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3897     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
3898
3899     size = MAX_PATH;
3900     sprintf(path, "%s\\FileName5", CURR_DIR);
3901     r = MsiGetPropertyA(hpkg, "SIGPROP5", prop, &size);
3902     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3903     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3904
3905     size = MAX_PATH;
3906     sprintf(path, "%s\\", CURR_DIR);
3907     r = MsiGetPropertyA(hpkg, "SIGPROP6", prop, &size);
3908     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3909     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3910
3911     size = MAX_PATH;
3912     sprintf(path, "%s\\", CURR_DIR);
3913     r = MsiGetPropertyA(hpkg, "SIGPROP7", prop, &size);
3914     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3915     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3916
3917     size = MAX_PATH;
3918     r = MsiGetPropertyA(hpkg, "SIGPROP8", prop, &size);
3919     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3920     ok(!lstrcmpA(prop, "october"), "Expected \"october\", got \"%s\"\n", prop);
3921
3922     size = MAX_PATH;
3923     r = MsiGetPropertyA(hpkg, "SIGPROP9", prop, &size);
3924     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3925     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
3926
3927     size = MAX_PATH;
3928     sprintf(path, "%s\\FileName8.dll", CURR_DIR);
3929     r = MsiGetPropertyA(hpkg, "SIGPROP10", prop, &size);
3930     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3931     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3932
3933     size = MAX_PATH;
3934     r = MsiGetPropertyA(hpkg, "SIGPROP11", prop, &size);
3935     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3936     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
3937
3938     size = MAX_PATH;
3939     sprintf(path, "%s\\FileName10.dll", CURR_DIR);
3940     r = MsiGetPropertyA(hpkg, "SIGPROP12", prop, &size);
3941     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3942     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
3943
3944     delete_component_path("{A8AE6692-96BA-4198-8399-145D7D1D0D0E}",
3945                           MSIINSTALLCONTEXT_MACHINE, NULL);
3946     delete_component_path("{1D2CE6F3-E81C-4949-AB81-78D7DAD2AF2E}",
3947                           MSIINSTALLCONTEXT_USERUNMANAGED, usersid);
3948     delete_component_path("{19E0B999-85F5-4973-A61B-DBE4D66ECB1D}",
3949                           MSIINSTALLCONTEXT_USERMANAGED, usersid);
3950     delete_component_path("{F0CCA976-27A3-4808-9DDD-1A6FD50A0D5A}",
3951                           MSIINSTALLCONTEXT_MACHINE, NULL);
3952     delete_component_path("{C0ECD96F-7898-4410-9667-194BD8C1B648}",
3953                           MSIINSTALLCONTEXT_MACHINE, NULL);
3954     delete_component_path("{DB20F535-9C26-4127-9C2B-CC45A8B51DA1}",
3955                           MSIINSTALLCONTEXT_MACHINE, NULL);
3956     delete_component_path("{91B7359B-07F2-4221-AA8D-DE102BB87A5F}",
3957                           MSIINSTALLCONTEXT_MACHINE, NULL);
3958     delete_component_path("{4A2E1B5B-4034-4177-833B-8CC35F1B3EF1}",
3959                           MSIINSTALLCONTEXT_MACHINE, NULL);
3960     delete_component_path("{A204DF48-7346-4635-BA2E-66247DBAC9DF}",
3961                           MSIINSTALLCONTEXT_MACHINE, NULL);
3962     delete_component_path("{EC30CE73-4CF9-4908-BABD-1ED82E1515FD}",
3963                           MSIINSTALLCONTEXT_MACHINE, NULL);
3964
3965     MsiCloseHandle(hpkg);
3966
3967 error:
3968     DeleteFileA("FileName1");
3969     DeleteFileA("FileName2");
3970     DeleteFileA("FileName3");
3971     DeleteFileA("FileName4");
3972     DeleteFileA("FileName5");
3973     DeleteFileA("FileName6");
3974     DeleteFileA("FileName7");
3975     DeleteFileA("FileName8.dll");
3976     DeleteFileA("FileName9.dll");
3977     DeleteFileA("FileName10.dll");
3978     DeleteFileA(msifile);
3979     LocalFree(usersid);
3980 }
3981
3982 static void test_appsearch_reglocator(void)
3983 {
3984     MSIHANDLE hpkg, hdb;
3985     CHAR path[MAX_PATH], prop[MAX_PATH];
3986     DWORD binary[2], size, val;
3987     BOOL space, version, is_64bit = sizeof(void *) > sizeof(int);
3988     HKEY hklm, classes, hkcu, users;
3989     LPSTR pathdata, pathvar, ptr;
3990     LPCSTR str;
3991     LONG res;
3992     UINT r, type = 0;
3993     SYSTEM_INFO si;
3994
3995     version = TRUE;
3996     if (!create_file_with_version("test.dll", MAKELONG(2, 1), MAKELONG(4, 3)))
3997         version = FALSE;
3998
3999     DeleteFileA("test.dll");
4000
4001     res = RegCreateKeyA(HKEY_CLASSES_ROOT, "Software\\Wine", &classes);
4002     if (res == ERROR_ACCESS_DENIED)
4003     {
4004         skip("Not enough rights to perform tests\n");
4005         return;
4006     }
4007     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4008
4009     res = RegSetValueExA(classes, "Value1", 0, REG_SZ,
4010                          (const BYTE *)"regszdata", 10);
4011     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4012
4013     res = RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine", &hkcu);
4014     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4015
4016     res = RegSetValueExA(hkcu, "Value1", 0, REG_SZ,
4017                          (const BYTE *)"regszdata", 10);
4018     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4019
4020     users = 0;
4021     res = RegCreateKeyA(HKEY_USERS, "S-1-5-18\\Software\\Wine", &users);
4022     ok(res == ERROR_SUCCESS ||
4023        broken(res == ERROR_INVALID_PARAMETER),
4024        "Expected ERROR_SUCCESS, got %d\n", res);
4025
4026     if (res == ERROR_SUCCESS)
4027     {
4028         res = RegSetValueExA(users, "Value1", 0, REG_SZ,
4029                              (const BYTE *)"regszdata", 10);
4030         ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4031     }
4032
4033     res = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine", &hklm);
4034     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4035
4036     res = RegSetValueA(hklm, NULL, REG_SZ, "defvalue", 8);
4037     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4038
4039     res = RegSetValueExA(hklm, "Value1", 0, REG_SZ,
4040                          (const BYTE *)"regszdata", 10);
4041     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4042
4043     val = 42;
4044     res = RegSetValueExA(hklm, "Value2", 0, REG_DWORD,
4045                          (const BYTE *)&val, sizeof(DWORD));
4046     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4047
4048     val = -42;
4049     res = RegSetValueExA(hklm, "Value3", 0, REG_DWORD,
4050                          (const BYTE *)&val, sizeof(DWORD));
4051     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4052
4053     res = RegSetValueExA(hklm, "Value4", 0, REG_EXPAND_SZ,
4054                          (const BYTE *)"%PATH%", 7);
4055     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4056
4057     res = RegSetValueExA(hklm, "Value5", 0, REG_EXPAND_SZ,
4058                          (const BYTE *)"my%NOVAR%", 10);
4059     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4060
4061     res = RegSetValueExA(hklm, "Value6", 0, REG_MULTI_SZ,
4062                          (const BYTE *)"one\0two\0", 9);
4063     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4064
4065     binary[0] = 0x1234abcd;
4066     binary[1] = 0x567890ef;
4067     res = RegSetValueExA(hklm, "Value7", 0, REG_BINARY,
4068                          (const BYTE *)binary, sizeof(binary));
4069     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4070
4071     res = RegSetValueExA(hklm, "Value8", 0, REG_SZ,
4072                          (const BYTE *)"#regszdata", 11);
4073     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4074
4075     create_test_file("FileName1");
4076     sprintf(path, "%s\\FileName1", CURR_DIR);
4077     res = RegSetValueExA(hklm, "Value9", 0, REG_SZ,
4078                          (const BYTE *)path, lstrlenA(path) + 1);
4079     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4080
4081     sprintf(path, "%s\\FileName2", CURR_DIR);
4082     res = RegSetValueExA(hklm, "Value10", 0, REG_SZ,
4083                          (const BYTE *)path, lstrlenA(path) + 1);
4084     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4085
4086     lstrcpyA(path, CURR_DIR);
4087     res = RegSetValueExA(hklm, "Value11", 0, REG_SZ,
4088                          (const BYTE *)path, lstrlenA(path) + 1);
4089     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4090
4091     res = RegSetValueExA(hklm, "Value12", 0, REG_SZ,
4092                          (const BYTE *)"", 1);
4093     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4094
4095     create_file_with_version("FileName3.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4096     sprintf(path, "%s\\FileName3.dll", CURR_DIR);
4097     res = RegSetValueExA(hklm, "Value13", 0, REG_SZ,
4098                          (const BYTE *)path, lstrlenA(path) + 1);
4099     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4100
4101     create_file_with_version("FileName4.dll", MAKELONG(1, 2), MAKELONG(3, 4));
4102     sprintf(path, "%s\\FileName4.dll", CURR_DIR);
4103     res = RegSetValueExA(hklm, "Value14", 0, REG_SZ,
4104                          (const BYTE *)path, lstrlenA(path) + 1);
4105     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4106
4107     create_file_with_version("FileName5.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4108     sprintf(path, "%s\\FileName5.dll", CURR_DIR);
4109     res = RegSetValueExA(hklm, "Value15", 0, REG_SZ,
4110                          (const BYTE *)path, lstrlenA(path) + 1);
4111     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
4112
4113     sprintf(path, "\"%s\\FileName1\" -option", CURR_DIR);
4114     res = RegSetValueExA(hklm, "value16", 0, REG_SZ,
4115                          (const BYTE *)path, lstrlenA(path) + 1);
4116     ok( res == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", res);
4117
4118     space = strchr(CURR_DIR, ' ') != NULL;
4119     sprintf(path, "%s\\FileName1 -option", CURR_DIR);
4120     res = RegSetValueExA(hklm, "value17", 0, REG_SZ,
4121                          (const BYTE *)path, lstrlenA(path) + 1);
4122     ok( res == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", res);
4123
4124     hdb = create_package_db();
4125     ok(hdb, "Expected a valid database handle\n");
4126
4127     r = create_appsearch_table(hdb);
4128     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4129
4130     r = add_appsearch_entry(hdb, "'SIGPROP1', 'NewSignature1'");
4131     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4132
4133     r = add_appsearch_entry(hdb, "'SIGPROP2', 'NewSignature2'");
4134     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4135
4136     r = add_appsearch_entry(hdb, "'SIGPROP3', 'NewSignature3'");
4137     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4138
4139     r = add_appsearch_entry(hdb, "'SIGPROP4', 'NewSignature4'");
4140     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4141
4142     r = add_appsearch_entry(hdb, "'SIGPROP5', 'NewSignature5'");
4143     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4144
4145     r = add_appsearch_entry(hdb, "'SIGPROP6', 'NewSignature6'");
4146     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4147
4148     r = add_appsearch_entry(hdb, "'SIGPROP7', 'NewSignature7'");
4149     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4150
4151     r = add_appsearch_entry(hdb, "'SIGPROP8', 'NewSignature8'");
4152     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4153
4154     r = add_appsearch_entry(hdb, "'SIGPROP9', 'NewSignature9'");
4155     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4156
4157     r = add_appsearch_entry(hdb, "'SIGPROP10', 'NewSignature10'");
4158     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4159
4160     r = add_appsearch_entry(hdb, "'SIGPROP11', 'NewSignature11'");
4161     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4162
4163     r = add_appsearch_entry(hdb, "'SIGPROP12', 'NewSignature12'");
4164     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4165
4166     r = add_appsearch_entry(hdb, "'SIGPROP13', 'NewSignature13'");
4167     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4168
4169     r = add_appsearch_entry(hdb, "'SIGPROP14', 'NewSignature14'");
4170     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4171
4172     r = add_appsearch_entry(hdb, "'SIGPROP15', 'NewSignature15'");
4173     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4174
4175     r = add_appsearch_entry(hdb, "'SIGPROP16', 'NewSignature16'");
4176     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4177
4178     r = add_appsearch_entry(hdb, "'SIGPROP17', 'NewSignature17'");
4179     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4180
4181     r = add_appsearch_entry(hdb, "'SIGPROP18', 'NewSignature18'");
4182     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4183
4184     r = add_appsearch_entry(hdb, "'SIGPROP19', 'NewSignature19'");
4185     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4186
4187     r = add_appsearch_entry(hdb, "'SIGPROP20', 'NewSignature20'");
4188     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4189
4190     r = add_appsearch_entry(hdb, "'SIGPROP21', 'NewSignature21'");
4191     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4192
4193     r = add_appsearch_entry(hdb, "'SIGPROP22', 'NewSignature22'");
4194     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4195
4196     r = add_appsearch_entry(hdb, "'SIGPROP23', 'NewSignature23'");
4197     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4198
4199     r = add_appsearch_entry(hdb, "'SIGPROP24', 'NewSignature24'");
4200     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4201
4202     r = add_appsearch_entry(hdb, "'SIGPROP25', 'NewSignature25'");
4203     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4204
4205     r = add_appsearch_entry(hdb, "'SIGPROP26', 'NewSignature26'");
4206     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4207
4208     r = add_appsearch_entry(hdb, "'SIGPROP27', 'NewSignature27'");
4209     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4210
4211     r = add_appsearch_entry(hdb, "'SIGPROP28', 'NewSignature28'");
4212     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4213
4214     r = add_appsearch_entry(hdb, "'SIGPROP29', 'NewSignature29'");
4215     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4216
4217     r = add_appsearch_entry(hdb, "'SIGPROP30', 'NewSignature30'");
4218     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4219
4220     r = create_reglocator_table(hdb);
4221     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4222
4223     type = msidbLocatorTypeRawValue;
4224     if (is_64bit)
4225         type |= msidbLocatorType64bit;
4226
4227     /* HKLM, msidbLocatorTypeRawValue, REG_SZ */
4228     r = add_reglocator_entry(hdb, "NewSignature1", 2, "Software\\Wine", "Value1", type);
4229     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4230
4231     /* HKLM, msidbLocatorTypeRawValue, positive DWORD */
4232     r = add_reglocator_entry(hdb, "NewSignature2", 2, "Software\\Wine", "Value2", type);
4233     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4234
4235     /* HKLM, msidbLocatorTypeRawValue, negative DWORD */
4236     r = add_reglocator_entry(hdb, "NewSignature3", 2, "Software\\Wine", "Value3", type);
4237     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4238
4239     /* HKLM, msidbLocatorTypeRawValue, REG_EXPAND_SZ */
4240     r = add_reglocator_entry(hdb, "NewSignature4", 2, "Software\\Wine", "Value4", type);
4241     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4242
4243     /* HKLM, msidbLocatorTypeRawValue, REG_EXPAND_SZ */
4244     r = add_reglocator_entry(hdb, "NewSignature5", 2, "Software\\Wine", "Value5", type);
4245     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4246
4247     /* HKLM, msidbLocatorTypeRawValue, REG_MULTI_SZ */
4248     r = add_reglocator_entry(hdb, "NewSignature6", 2, "Software\\Wine", "Value6", type);
4249     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4250
4251     /* HKLM, msidbLocatorTypeRawValue, REG_BINARY */
4252     r = add_reglocator_entry(hdb, "NewSignature7", 2, "Software\\Wine", "Value7", type);
4253     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4254
4255     /* HKLM, msidbLocatorTypeRawValue, REG_SZ first char is # */
4256     r = add_reglocator_entry(hdb, "NewSignature8", 2, "Software\\Wine", "Value8", type);
4257     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4258
4259     type = msidbLocatorTypeFileName;
4260     if (is_64bit)
4261         type |= msidbLocatorType64bit;
4262
4263     /* HKLM, msidbLocatorTypeFileName, signature, file exists */
4264     r = add_reglocator_entry(hdb, "NewSignature9", 2, "Software\\Wine", "Value9", type);
4265     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4266
4267     /* HKLM, msidbLocatorTypeFileName, signature, file does not exist */
4268     r = add_reglocator_entry(hdb, "NewSignature10", 2, "Software\\Wine", "Value10", type);
4269     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4270
4271     /* HKLM, msidbLocatorTypeFileName, no signature */
4272     r = add_reglocator_entry(hdb, "NewSignature11", 2, "Software\\Wine", "Value9", type);
4273     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4274
4275     type = msidbLocatorTypeDirectory;
4276     if (is_64bit)
4277         type |= msidbLocatorType64bit;
4278
4279     /* HKLM, msidbLocatorTypeDirectory, no signature, file exists */
4280     r = add_reglocator_entry(hdb, "NewSignature12", 2, "Software\\Wine", "Value9", type);
4281     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4282
4283     /* HKLM, msidbLocatorTypeDirectory, no signature, directory exists */
4284     r = add_reglocator_entry(hdb, "NewSignature13", 2, "Software\\Wine", "Value11", type);
4285     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4286
4287     /* HKLM, msidbLocatorTypeDirectory, signature, file exists */
4288     r = add_reglocator_entry(hdb, "NewSignature14", 2, "Software\\Wine", "Value9", type);
4289     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4290
4291     type = msidbLocatorTypeRawValue;
4292     if (is_64bit)
4293         type |= msidbLocatorType64bit;
4294
4295     /* HKCR, msidbLocatorTypeRawValue, REG_SZ */
4296     r = add_reglocator_entry(hdb, "NewSignature15", 0, "Software\\Wine", "Value1", type);
4297     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4298
4299     /* HKCU, msidbLocatorTypeRawValue, REG_SZ */
4300     r = add_reglocator_entry(hdb, "NewSignature16", 1, "Software\\Wine", "Value1", type);
4301     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4302
4303     /* HKU, msidbLocatorTypeRawValue, REG_SZ */
4304     r = add_reglocator_entry(hdb, "NewSignature17", 3, "S-1-5-18\\Software\\Wine", "Value1", type);
4305     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4306
4307     /* HKLM, msidbLocatorTypeRawValue, REG_SZ, NULL Name */
4308     r = add_reglocator_entry(hdb, "NewSignature18", 2, "Software\\Wine", "", type);
4309     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4310
4311     /* HKLM, msidbLocatorTypeRawValue, REG_SZ, key does not exist */
4312     r = add_reglocator_entry(hdb, "NewSignature19", 2, "Software\\IDontExist", "", type);
4313     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4314
4315     /* HKLM, msidbLocatorTypeRawValue, REG_SZ, value is empty */
4316     r = add_reglocator_entry(hdb, "NewSignature20", 2, "Software\\Wine", "Value12", type);
4317     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4318
4319     type = msidbLocatorTypeFileName;
4320     if (is_64bit)
4321         type |= msidbLocatorType64bit;
4322
4323     /* HKLM, msidbLocatorTypeFileName, signature, file exists w/ version */
4324     r = add_reglocator_entry(hdb, "NewSignature21", 2, "Software\\Wine", "Value13", type);
4325     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4326
4327     /* HKLM, msidbLocatorTypeFileName, file exists w/ version, version > max */
4328     r = add_reglocator_entry(hdb, "NewSignature22", 2, "Software\\Wine", "Value14", type);
4329     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4330
4331     /* HKLM, msidbLocatorTypeFileName, file exists w/ version, sig->name ignored */
4332     r = add_reglocator_entry(hdb, "NewSignature23", 2, "Software\\Wine", "Value15", type);
4333     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4334
4335     /* HKLM, msidbLocatorTypeFileName, no signature, directory exists */
4336     r = add_reglocator_entry(hdb, "NewSignature24", 2, "Software\\Wine", "Value11", type);
4337     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4338
4339     /* HKLM, msidbLocatorTypeFileName, no signature, file does not exist */
4340     r = add_reglocator_entry(hdb, "NewSignature25", 2, "Software\\Wine", "Value10", type);
4341     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4342
4343     type = msidbLocatorTypeDirectory;
4344     if (is_64bit)
4345         type |= msidbLocatorType64bit;
4346
4347     /* HKLM, msidbLocatorTypeDirectory, signature, directory exists */
4348     r = add_reglocator_entry(hdb, "NewSignature26", 2, "Software\\Wine", "Value11", type);
4349     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4350
4351     /* HKLM, msidbLocatorTypeDirectory, signature, file does not exist */
4352     r = add_reglocator_entry(hdb, "NewSignature27", 2, "Software\\Wine", "Value10", type);
4353     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4354
4355     /* HKLM, msidbLocatorTypeDirectory, no signature, file does not exist */
4356     r = add_reglocator_entry(hdb, "NewSignature28", 2, "Software\\Wine", "Value10", type);
4357     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4358
4359     type = msidbLocatorTypeFileName;
4360     if (is_64bit)
4361         type |= msidbLocatorType64bit;
4362
4363     /* HKLM, msidbLocatorTypeFile, file exists, in quotes */
4364     r = add_reglocator_entry(hdb, "NewSignature29", 2, "Software\\Wine", "Value16", type);
4365     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4366
4367     /* HKLM, msidbLocatorTypeFile, file exists, no quotes */
4368     r = add_reglocator_entry(hdb, "NewSignature30", 2, "Software\\Wine", "Value17", type);
4369     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4370
4371     r = create_signature_table(hdb);
4372     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4373
4374     str = "'NewSignature9', 'FileName1', '', '', '', '', '', '', ''";
4375     r = add_signature_entry(hdb, str);
4376     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4377
4378     str = "'NewSignature10', 'FileName2', '', '', '', '', '', '', ''";
4379     r = add_signature_entry(hdb, str);
4380     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4381
4382     str = "'NewSignature14', 'FileName1', '', '', '', '', '', '', ''";
4383     r = add_signature_entry(hdb, str);
4384     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4385
4386     str = "'NewSignature21', 'FileName3.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
4387     r = add_signature_entry(hdb, str);
4388     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4389
4390     str = "'NewSignature22', 'FileName4.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
4391     r = add_signature_entry(hdb, str);
4392     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4393
4394     str = "'NewSignature23', 'ignored', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
4395     r = add_signature_entry(hdb, str);
4396     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4397
4398     ptr = strrchr(CURR_DIR, '\\') + 1;
4399     sprintf(path, "'NewSignature26', '%s', '', '', '', '', '', '', ''", ptr);
4400     r = add_signature_entry(hdb, path);
4401     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4402
4403     str = "'NewSignature27', 'FileName2', '', '', '', '', '', '', ''";
4404     r = add_signature_entry(hdb, str);
4405     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4406
4407     str = "'NewSignature29', 'FileName1', '', '', '', '', '', '', ''";
4408     r = add_signature_entry(hdb, str);
4409     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4410
4411     str = "'NewSignature30', 'FileName1', '', '', '', '', '', '', ''";
4412     r = add_signature_entry(hdb, str);
4413     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4414
4415     r = package_from_db(hdb, &hpkg);
4416     ok(r == ERROR_SUCCESS, "Expected a valid package handle %u\n", r);
4417
4418     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
4419
4420     r = MsiDoAction(hpkg, "AppSearch");
4421     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4422
4423     size = MAX_PATH;
4424     r = MsiGetPropertyA(hpkg, "SIGPROP1", prop, &size);
4425     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4426     ok(!lstrcmpA(prop, "regszdata"),
4427        "Expected \"regszdata\", got \"%s\"\n", prop);
4428
4429     size = MAX_PATH;
4430     r = MsiGetPropertyA(hpkg, "SIGPROP2", prop, &size);
4431     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4432     ok(!lstrcmpA(prop, "#42"), "Expected \"#42\", got \"%s\"\n", prop);
4433
4434     size = MAX_PATH;
4435     r = MsiGetPropertyA(hpkg, "SIGPROP3", prop, &size);
4436     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4437     ok(!lstrcmpA(prop, "#-42"), "Expected \"#-42\", got \"%s\"\n", prop);
4438
4439     memset(&si, 0, sizeof(si));
4440     if (pGetNativeSystemInfo) pGetNativeSystemInfo(&si);
4441
4442     if (S(U(si)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
4443     {
4444         size = ExpandEnvironmentStringsA("%PATH%", NULL, 0);
4445         pathvar = HeapAlloc(GetProcessHeap(), 0, size);
4446         ExpandEnvironmentStringsA("%PATH%", pathvar, size);
4447
4448         size = 0;
4449         r = MsiGetPropertyA(hpkg, "SIGPROP4", NULL, &size);
4450         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4451
4452         pathdata = HeapAlloc(GetProcessHeap(), 0, ++size);
4453         r = MsiGetPropertyA(hpkg, "SIGPROP4", pathdata, &size);
4454         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4455         ok(!lstrcmpA(pathdata, pathvar),
4456             "Expected \"%s\", got \"%s\"\n", pathvar, pathdata);
4457
4458         HeapFree(GetProcessHeap(), 0, pathvar);
4459         HeapFree(GetProcessHeap(), 0, pathdata);
4460     }
4461
4462     size = MAX_PATH;
4463     r = MsiGetPropertyA(hpkg, "SIGPROP5", prop, &size);
4464     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4465     ok(!lstrcmpA(prop,
4466        "my%NOVAR%"), "Expected \"my%%NOVAR%%\", got \"%s\"\n", prop);
4467
4468     size = MAX_PATH;
4469     r = MsiGetPropertyA(hpkg, "SIGPROP6", prop, &size);
4470     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4471     todo_wine
4472     {
4473         ok(!memcmp(prop, "\0one\0two\0\0", 10),
4474            "Expected \"\\0one\\0two\\0\\0\"\n");
4475     }
4476
4477     size = MAX_PATH;
4478     lstrcpyA(path, "#xCDAB3412EF907856");
4479     r = MsiGetPropertyA(hpkg, "SIGPROP7", prop, &size);
4480     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4481     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4482
4483     size = MAX_PATH;
4484     r = MsiGetPropertyA(hpkg, "SIGPROP8", prop, &size);
4485     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4486     ok(!lstrcmpA(prop, "##regszdata"),
4487        "Expected \"##regszdata\", got \"%s\"\n", prop);
4488
4489     size = MAX_PATH;
4490     sprintf(path, "%s\\FileName1", CURR_DIR);
4491     r = MsiGetPropertyA(hpkg, "SIGPROP9", prop, &size);
4492     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4493     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4494
4495     size = MAX_PATH;
4496     r = MsiGetPropertyA(hpkg, "SIGPROP10", prop, &size);
4497     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4498     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4499
4500     size = MAX_PATH;
4501     sprintf(path, "%s\\", CURR_DIR);
4502     r = MsiGetPropertyA(hpkg, "SIGPROP11", prop, &size);
4503     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4504     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4505
4506     size = MAX_PATH;
4507     r = MsiGetPropertyA(hpkg, "SIGPROP12", prop, &size);
4508     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4509     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4510
4511     size = MAX_PATH;
4512     sprintf(path, "%s\\", CURR_DIR);
4513     r = MsiGetPropertyA(hpkg, "SIGPROP13", prop, &size);
4514     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4515     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4516
4517     size = MAX_PATH;
4518     r = MsiGetPropertyA(hpkg, "SIGPROP14", prop, &size);
4519     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4520     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4521
4522     size = MAX_PATH;
4523     r = MsiGetPropertyA(hpkg, "SIGPROP15", prop, &size);
4524     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4525     ok(!lstrcmpA(prop, "regszdata"),
4526        "Expected \"regszdata\", got \"%s\"\n", prop);
4527
4528     size = MAX_PATH;
4529     r = MsiGetPropertyA(hpkg, "SIGPROP16", prop, &size);
4530     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4531     ok(!lstrcmpA(prop, "regszdata"),
4532        "Expected \"regszdata\", got \"%s\"\n", prop);
4533
4534     if (users)
4535     {
4536         size = MAX_PATH;
4537         r = MsiGetPropertyA(hpkg, "SIGPROP17", prop, &size);
4538         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4539         ok(!lstrcmpA(prop, "regszdata"),
4540            "Expected \"regszdata\", got \"%s\"\n", prop);
4541     }
4542
4543     size = MAX_PATH;
4544     r = MsiGetPropertyA(hpkg, "SIGPROP18", prop, &size);
4545     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4546     ok(!lstrcmpA(prop, "defvalue"),
4547        "Expected \"defvalue\", got \"%s\"\n", prop);
4548
4549     size = MAX_PATH;
4550     r = MsiGetPropertyA(hpkg, "SIGPROP19", prop, &size);
4551     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4552     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4553
4554     size = MAX_PATH;
4555     r = MsiGetPropertyA(hpkg, "SIGPROP20", prop, &size);
4556     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4557     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4558
4559     if (version)
4560     {
4561         size = MAX_PATH;
4562         sprintf(path, "%s\\FileName3.dll", CURR_DIR);
4563         r = MsiGetPropertyA(hpkg, "SIGPROP21", prop, &size);
4564         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4565         ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4566
4567         size = MAX_PATH;
4568         r = MsiGetPropertyA(hpkg, "SIGPROP22", prop, &size);
4569         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4570         ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4571
4572         size = MAX_PATH;
4573         sprintf(path, "%s\\FileName5.dll", CURR_DIR);
4574         r = MsiGetPropertyA(hpkg, "SIGPROP23", prop, &size);
4575         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4576         ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4577     }
4578
4579     size = MAX_PATH;
4580     lstrcpyA(path, CURR_DIR);
4581     ptr = strrchr(path, '\\') + 1;
4582     *ptr = '\0';
4583     r = MsiGetPropertyA(hpkg, "SIGPROP24", prop, &size);
4584     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4585     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4586
4587     size = MAX_PATH;
4588     sprintf(path, "%s\\", CURR_DIR);
4589     r = MsiGetPropertyA(hpkg, "SIGPROP25", prop, &size);
4590     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4591     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4592
4593     size = MAX_PATH;
4594     r = MsiGetPropertyA(hpkg, "SIGPROP26", prop, &size);
4595     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4596     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4597
4598     size = MAX_PATH;
4599     r = MsiGetPropertyA(hpkg, "SIGPROP27", prop, &size);
4600     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4601     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4602
4603     size = MAX_PATH;
4604     r = MsiGetPropertyA(hpkg, "SIGPROP28", prop, &size);
4605     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4606     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4607
4608     size = MAX_PATH;
4609     sprintf(path, "%s\\FileName1", CURR_DIR);
4610     r = MsiGetPropertyA(hpkg, "SIGPROP29", prop, &size);
4611     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4612     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4613
4614     size = MAX_PATH;
4615     sprintf(path, "%s\\FileName1", CURR_DIR);
4616     r = MsiGetPropertyA(hpkg, "SIGPROP30", prop, &size);
4617     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4618     if (space)
4619         ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4620     else
4621         todo_wine ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4622
4623     RegSetValueA(hklm, NULL, REG_SZ, "", 0);
4624     RegDeleteValueA(hklm, "Value1");
4625     RegDeleteValueA(hklm, "Value2");
4626     RegDeleteValueA(hklm, "Value3");
4627     RegDeleteValueA(hklm, "Value4");
4628     RegDeleteValueA(hklm, "Value5");
4629     RegDeleteValueA(hklm, "Value6");
4630     RegDeleteValueA(hklm, "Value7");
4631     RegDeleteValueA(hklm, "Value8");
4632     RegDeleteValueA(hklm, "Value9");
4633     RegDeleteValueA(hklm, "Value10");
4634     RegDeleteValueA(hklm, "Value11");
4635     RegDeleteValueA(hklm, "Value12");
4636     RegDeleteValueA(hklm, "Value13");
4637     RegDeleteValueA(hklm, "Value14");
4638     RegDeleteValueA(hklm, "Value15");
4639     RegDeleteValueA(hklm, "Value16");
4640     RegDeleteValueA(hklm, "Value17");
4641     RegDeleteKey(hklm, "");
4642     RegCloseKey(hklm);
4643
4644     RegDeleteValueA(classes, "Value1");
4645     RegDeleteKeyA(classes, "");
4646     RegCloseKey(classes);
4647
4648     RegDeleteValueA(hkcu, "Value1");
4649     RegDeleteKeyA(hkcu, "");
4650     RegCloseKey(hkcu);
4651
4652     RegDeleteValueA(users, "Value1");
4653     RegDeleteKeyA(users, "");
4654     RegCloseKey(users);
4655
4656     DeleteFileA("FileName1");
4657     DeleteFileA("FileName3.dll");
4658     DeleteFileA("FileName4.dll");
4659     DeleteFileA("FileName5.dll");
4660     MsiCloseHandle(hpkg);
4661     DeleteFileA(msifile);
4662 }
4663
4664 static void delete_win_ini(LPCSTR file)
4665 {
4666     CHAR path[MAX_PATH];
4667
4668     GetWindowsDirectoryA(path, MAX_PATH);
4669     lstrcatA(path, "\\");
4670     lstrcatA(path, file);
4671
4672     DeleteFileA(path);
4673 }
4674
4675 static void test_appsearch_inilocator(void)
4676 {
4677     MSIHANDLE hpkg, hdb;
4678     CHAR path[MAX_PATH];
4679     CHAR prop[MAX_PATH];
4680     BOOL version;
4681     LPCSTR str;
4682     LPSTR ptr;
4683     DWORD size;
4684     UINT r;
4685
4686     version = TRUE;
4687     if (!create_file_with_version("test.dll", MAKELONG(2, 1), MAKELONG(4, 3)))
4688         version = FALSE;
4689
4690     DeleteFileA("test.dll");
4691
4692     WritePrivateProfileStringA("Section", "Key", "keydata,field2", "IniFile.ini");
4693
4694     create_test_file("FileName1");
4695     sprintf(path, "%s\\FileName1", CURR_DIR);
4696     WritePrivateProfileStringA("Section", "Key2", path, "IniFile.ini");
4697
4698     WritePrivateProfileStringA("Section", "Key3", CURR_DIR, "IniFile.ini");
4699
4700     sprintf(path, "%s\\IDontExist", CURR_DIR);
4701     WritePrivateProfileStringA("Section", "Key4", path, "IniFile.ini");
4702
4703     create_file_with_version("FileName2.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4704     sprintf(path, "%s\\FileName2.dll", CURR_DIR);
4705     WritePrivateProfileStringA("Section", "Key5", path, "IniFile.ini");
4706
4707     create_file_with_version("FileName3.dll", MAKELONG(1, 2), MAKELONG(3, 4));
4708     sprintf(path, "%s\\FileName3.dll", CURR_DIR);
4709     WritePrivateProfileStringA("Section", "Key6", path, "IniFile.ini");
4710
4711     create_file_with_version("FileName4.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4712     sprintf(path, "%s\\FileName4.dll", CURR_DIR);
4713     WritePrivateProfileStringA("Section", "Key7", path, "IniFile.ini");
4714
4715     hdb = create_package_db();
4716     ok(hdb, "Expected a valid database handle\n");
4717
4718     r = create_appsearch_table(hdb);
4719     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4720
4721     r = add_appsearch_entry(hdb, "'SIGPROP1', 'NewSignature1'");
4722     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4723
4724     r = add_appsearch_entry(hdb, "'SIGPROP2', 'NewSignature2'");
4725     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4726
4727     r = add_appsearch_entry(hdb, "'SIGPROP3', 'NewSignature3'");
4728     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4729
4730     r = add_appsearch_entry(hdb, "'SIGPROP4', 'NewSignature4'");
4731     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4732
4733     r = add_appsearch_entry(hdb, "'SIGPROP5', 'NewSignature5'");
4734     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4735
4736     r = add_appsearch_entry(hdb, "'SIGPROP6', 'NewSignature6'");
4737     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4738
4739     r = add_appsearch_entry(hdb, "'SIGPROP7', 'NewSignature7'");
4740     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4741
4742     r = add_appsearch_entry(hdb, "'SIGPROP8', 'NewSignature8'");
4743     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4744
4745     r = add_appsearch_entry(hdb, "'SIGPROP9', 'NewSignature9'");
4746     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4747
4748     r = add_appsearch_entry(hdb, "'SIGPROP10', 'NewSignature10'");
4749     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4750
4751     r = add_appsearch_entry(hdb, "'SIGPROP11', 'NewSignature11'");
4752     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4753
4754     r = add_appsearch_entry(hdb, "'SIGPROP12', 'NewSignature12'");
4755     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4756
4757     r = create_inilocator_table(hdb);
4758     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4759
4760     /* msidbLocatorTypeRawValue, field 1 */
4761     str = "'NewSignature1', 'IniFile.ini', 'Section', 'Key', 1, 2";
4762     r = add_inilocator_entry(hdb, str);
4763     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4764
4765     /* msidbLocatorTypeRawValue, field 2 */
4766     str = "'NewSignature2', 'IniFile.ini', 'Section', 'Key', 2, 2";
4767     r = add_inilocator_entry(hdb, str);
4768     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4769
4770     /* msidbLocatorTypeRawValue, entire field */
4771     str = "'NewSignature3', 'IniFile.ini', 'Section', 'Key', 0, 2";
4772     r = add_inilocator_entry(hdb, str);
4773     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4774
4775     /* msidbLocatorTypeFile */
4776     str = "'NewSignature4', 'IniFile.ini', 'Section', 'Key2', 1, 1";
4777     r = add_inilocator_entry(hdb, str);
4778     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4779
4780     /* msidbLocatorTypeDirectory, file */
4781     str = "'NewSignature5', 'IniFile.ini', 'Section', 'Key2', 1, 0";
4782     r = add_inilocator_entry(hdb, str);
4783     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4784
4785     /* msidbLocatorTypeDirectory, directory */
4786     str = "'NewSignature6', 'IniFile.ini', 'Section', 'Key3', 1, 0";
4787     r = add_inilocator_entry(hdb, str);
4788     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4789
4790     /* msidbLocatorTypeFile, file, no signature */
4791     str = "'NewSignature7', 'IniFile.ini', 'Section', 'Key2', 1, 1";
4792     r = add_inilocator_entry(hdb, str);
4793     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4794
4795     /* msidbLocatorTypeFile, dir, no signature */
4796     str = "'NewSignature8', 'IniFile.ini', 'Section', 'Key3', 1, 1";
4797     r = add_inilocator_entry(hdb, str);
4798     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4799
4800     /* msidbLocatorTypeFile, file does not exist */
4801     str = "'NewSignature9', 'IniFile.ini', 'Section', 'Key4', 1, 1";
4802     r = add_inilocator_entry(hdb, str);
4803     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4804
4805     /* msidbLocatorTypeFile, signature with version */
4806     str = "'NewSignature10', 'IniFile.ini', 'Section', 'Key5', 1, 1";
4807     r = add_inilocator_entry(hdb, str);
4808     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4809
4810     /* msidbLocatorTypeFile, signature with version, ver > max */
4811     str = "'NewSignature11', 'IniFile.ini', 'Section', 'Key6', 1, 1";
4812     r = add_inilocator_entry(hdb, str);
4813     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4814
4815     /* msidbLocatorTypeFile, signature with version, sig->name ignored */
4816     str = "'NewSignature12', 'IniFile.ini', 'Section', 'Key7', 1, 1";
4817     r = add_inilocator_entry(hdb, str);
4818     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4819
4820     r = create_signature_table(hdb);
4821     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4822
4823     r = add_signature_entry(hdb, "'NewSignature4', 'FileName1', '', '', '', '', '', '', ''");
4824     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4825
4826     r = add_signature_entry(hdb, "'NewSignature9', 'IDontExist', '', '', '', '', '', '', ''");
4827     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4828
4829     r = add_signature_entry(hdb, "'NewSignature10', 'FileName2.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
4830     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4831
4832     r = add_signature_entry(hdb, "'NewSignature11', 'FileName3.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
4833     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4834
4835     r = add_signature_entry(hdb, "'NewSignature12', 'ignored', '1.1.1.1', '2.1.1.1', '', '', '', '', ''");
4836     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4837
4838     r = package_from_db(hdb, &hpkg);
4839     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
4840     {
4841         skip("Not enough rights to perform tests\n");
4842         goto error;
4843     }
4844     ok(r == ERROR_SUCCESS, "Expected a valid package handle %u\n", r);
4845
4846     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
4847
4848     r = MsiDoAction(hpkg, "AppSearch");
4849     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4850
4851     size = MAX_PATH;
4852     r = MsiGetPropertyA(hpkg, "SIGPROP1", prop, &size);
4853     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4854     ok(!lstrcmpA(prop, "keydata"), "Expected \"keydata\", got \"%s\"\n", prop);
4855
4856     size = MAX_PATH;
4857     r = MsiGetPropertyA(hpkg, "SIGPROP2", prop, &size);
4858     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4859     ok(!lstrcmpA(prop, "field2"), "Expected \"field2\", got \"%s\"\n", prop);
4860
4861     size = MAX_PATH;
4862     r = MsiGetPropertyA(hpkg, "SIGPROP3", prop, &size);
4863     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4864     ok(!lstrcmpA(prop, "keydata,field2"),
4865        "Expected \"keydata,field2\", got \"%s\"\n", prop);
4866
4867     size = MAX_PATH;
4868     sprintf(path, "%s\\FileName1", CURR_DIR);
4869     r = MsiGetPropertyA(hpkg, "SIGPROP4", prop, &size);
4870     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4871     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4872
4873     size = MAX_PATH;
4874     r = MsiGetPropertyA(hpkg, "SIGPROP5", prop, &size);
4875     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4876     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4877
4878     size = MAX_PATH;
4879     sprintf(path, "%s\\", CURR_DIR);
4880     r = MsiGetPropertyA(hpkg, "SIGPROP6", prop, &size);
4881     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4882     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4883
4884     size = MAX_PATH;
4885     sprintf(path, "%s\\", CURR_DIR);
4886     r = MsiGetPropertyA(hpkg, "SIGPROP7", prop, &size);
4887     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4888     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4889
4890     size = MAX_PATH;
4891     lstrcpyA(path, CURR_DIR);
4892     ptr = strrchr(path, '\\');
4893     *(ptr + 1) = '\0';
4894     r = MsiGetPropertyA(hpkg, "SIGPROP8", prop, &size);
4895     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4896     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4897
4898     size = MAX_PATH;
4899     r = MsiGetPropertyA(hpkg, "SIGPROP9", prop, &size);
4900     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4901     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4902
4903     if (version)
4904     {
4905         size = MAX_PATH;
4906         sprintf(path, "%s\\FileName2.dll", CURR_DIR);
4907         r = MsiGetPropertyA(hpkg, "SIGPROP10", prop, &size);
4908         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4909         ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4910
4911         size = MAX_PATH;
4912         r = MsiGetPropertyA(hpkg, "SIGPROP11", prop, &size);
4913         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4914         ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
4915
4916         size = MAX_PATH;
4917         sprintf(path, "%s\\FileName4.dll", CURR_DIR);
4918         r = MsiGetPropertyA(hpkg, "SIGPROP12", prop, &size);
4919         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4920         ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
4921     }
4922
4923     MsiCloseHandle(hpkg);
4924
4925 error:
4926     delete_win_ini("IniFile.ini");
4927     DeleteFileA("FileName1");
4928     DeleteFileA("FileName2.dll");
4929     DeleteFileA("FileName3.dll");
4930     DeleteFileA("FileName4.dll");
4931     DeleteFileA(msifile);
4932 }
4933
4934 /*
4935  * MSI AppSearch action on DrLocator table always returns absolute paths.
4936  * If a relative path was set, it returns the first absolute path that
4937  * matches or an empty string if it didn't find anything.
4938  * This helper function replicates this behaviour.
4939  */
4940 static void search_absolute_directory(LPSTR absolute, LPCSTR relative)
4941 {
4942     int i, size;
4943     DWORD attr, drives;
4944
4945     size = lstrlenA(relative);
4946     drives = GetLogicalDrives();
4947     lstrcpyA(absolute, "A:\\");
4948     for (i = 0; i < 26; absolute[0] = '\0', i++)
4949     {
4950         if (!(drives & (1 << i)))
4951             continue;
4952
4953         absolute[0] = 'A' + i;
4954         if (GetDriveType(absolute) != DRIVE_FIXED)
4955             continue;
4956
4957         lstrcpynA(absolute + 3, relative, size + 1);
4958         attr = GetFileAttributesA(absolute);
4959         if (attr != INVALID_FILE_ATTRIBUTES &&
4960             (attr & FILE_ATTRIBUTE_DIRECTORY))
4961         {
4962             if (absolute[3 + size - 1] != '\\')
4963                 lstrcatA(absolute, "\\");
4964             break;
4965         }
4966         absolute[3] = '\0';
4967     }
4968 }
4969
4970 static void test_appsearch_drlocator(void)
4971 {
4972     MSIHANDLE hpkg, hdb;
4973     CHAR path[MAX_PATH];
4974     CHAR prop[MAX_PATH];
4975     BOOL version;
4976     LPCSTR str;
4977     DWORD size;
4978     UINT r;
4979
4980     version = TRUE;
4981     if (!create_file_with_version("test.dll", MAKELONG(2, 1), MAKELONG(4, 3)))
4982         version = FALSE;
4983
4984     DeleteFileA("test.dll");
4985
4986     create_test_file("FileName1");
4987     CreateDirectoryA("one", NULL);
4988     CreateDirectoryA("one\\two", NULL);
4989     CreateDirectoryA("one\\two\\three", NULL);
4990     create_test_file("one\\two\\three\\FileName2");
4991     CreateDirectoryA("another", NULL);
4992     create_file_with_version("FileName3.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4993     create_file_with_version("FileName4.dll", MAKELONG(1, 2), MAKELONG(3, 4));
4994     create_file_with_version("FileName5.dll", MAKELONG(2, 1), MAKELONG(4, 3));
4995
4996     hdb = create_package_db();
4997     ok(hdb, "Expected a valid database handle\n");
4998
4999     r = create_appsearch_table(hdb);
5000     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5001
5002     r = add_appsearch_entry(hdb, "'SIGPROP1', 'NewSignature1'");
5003     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5004
5005     r = add_appsearch_entry(hdb, "'SIGPROP2', 'NewSignature2'");
5006     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5007
5008     r = add_appsearch_entry(hdb, "'SIGPROP3', 'NewSignature3'");
5009     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5010
5011     r = add_appsearch_entry(hdb, "'SIGPROP4', 'NewSignature4'");
5012     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5013
5014     r = add_appsearch_entry(hdb, "'SIGPROP5', 'NewSignature5'");
5015     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5016
5017     r = add_appsearch_entry(hdb, "'SIGPROP6', 'NewSignature6'");
5018     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5019
5020     r = add_appsearch_entry(hdb, "'SIGPROP7', 'NewSignature7'");
5021     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5022
5023     r = add_appsearch_entry(hdb, "'SIGPROP8', 'NewSignature8'");
5024     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5025
5026     r = add_appsearch_entry(hdb, "'SIGPROP9', 'NewSignature9'");
5027     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5028
5029     r = add_appsearch_entry(hdb, "'SIGPROP10', 'NewSignature10'");
5030     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5031
5032     r = add_appsearch_entry(hdb, "'SIGPROP11', 'NewSignature11'");
5033     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5034
5035     r = add_appsearch_entry(hdb, "'SIGPROP13', 'NewSignature13'");
5036     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5037
5038     r = create_drlocator_table(hdb);
5039     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5040
5041     /* no parent, full path, depth 0, signature */
5042     sprintf(path, "'NewSignature1', '', '%s', 0", CURR_DIR);
5043     r = add_drlocator_entry(hdb, path);
5044     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5045
5046     /* no parent, full path, depth 0, no signature */
5047     sprintf(path, "'NewSignature2', '', '%s', 0", CURR_DIR);
5048     r = add_drlocator_entry(hdb, path);
5049     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5050
5051     /* no parent, relative path, depth 0, no signature */
5052     sprintf(path, "'NewSignature3', '', '%s', 0", CURR_DIR + 3);
5053     r = add_drlocator_entry(hdb, path);
5054     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5055
5056     /* no parent, full path, depth 2, signature */
5057     sprintf(path, "'NewSignature4', '', '%s', 2", CURR_DIR);
5058     r = add_drlocator_entry(hdb, path);
5059     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5060
5061     /* no parent, full path, depth 3, signature */
5062     sprintf(path, "'NewSignature5', '', '%s', 3", CURR_DIR);
5063     r = add_drlocator_entry(hdb, path);
5064     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5065
5066     /* no parent, full path, depth 1, signature is dir */
5067     sprintf(path, "'NewSignature6', '', '%s', 1", CURR_DIR);
5068     r = add_drlocator_entry(hdb, path);
5069     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5070
5071     /* parent is in DrLocator, relative path, depth 0, signature */
5072     sprintf(path, "'NewSignature7', 'NewSignature1', 'one\\two\\three', 1");
5073     r = add_drlocator_entry(hdb, path);
5074     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5075
5076     /* no parent, full path, depth 0, signature w/ version */
5077     sprintf(path, "'NewSignature8', '', '%s', 0", CURR_DIR);
5078     r = add_drlocator_entry(hdb, path);
5079     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5080
5081     /* no parent, full path, depth 0, signature w/ version, ver > max */
5082     sprintf(path, "'NewSignature9', '', '%s', 0", CURR_DIR);
5083     r = add_drlocator_entry(hdb, path);
5084     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5085
5086     /* no parent, full path, depth 0, signature w/ version, sig->name not ignored */
5087     sprintf(path, "'NewSignature10', '', '%s', 0", CURR_DIR);
5088     r = add_drlocator_entry(hdb, path);
5089     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5090
5091     /* no parent, relative empty path, depth 0, no signature */
5092     sprintf(path, "'NewSignature11', '', '', 0");
5093     r = add_drlocator_entry(hdb, path);
5094     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5095
5096     r = create_reglocator_table(hdb);
5097     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5098
5099     /* parent */
5100     r = add_reglocator_entry(hdb, "NewSignature12", 2, "htmlfile\\shell\\open\\nonexistent", "", 1);
5101     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5102
5103     /* parent is in RegLocator, no path, depth 0, no signature */
5104     sprintf(path, "'NewSignature13', 'NewSignature12', '', 0");
5105     r = add_drlocator_entry(hdb, path);
5106     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5107
5108     r = create_signature_table(hdb);
5109     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5110
5111     str = "'NewSignature1', 'FileName1', '', '', '', '', '', '', ''";
5112     r = add_signature_entry(hdb, str);
5113     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5114
5115     str = "'NewSignature4', 'FileName2', '', '', '', '', '', '', ''";
5116     r = add_signature_entry(hdb, str);
5117     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5118
5119     str = "'NewSignature5', 'FileName2', '', '', '', '', '', '', ''";
5120     r = add_signature_entry(hdb, str);
5121     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5122
5123     str = "'NewSignature6', 'another', '', '', '', '', '', '', ''";
5124     r = add_signature_entry(hdb, str);
5125     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5126
5127     str = "'NewSignature7', 'FileName2', '', '', '', '', '', '', ''";
5128     r = add_signature_entry(hdb, str);
5129     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5130
5131     str = "'NewSignature8', 'FileName3.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
5132     r = add_signature_entry(hdb, str);
5133     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5134
5135     str = "'NewSignature9', 'FileName4.dll', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
5136     r = add_signature_entry(hdb, str);
5137     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5138
5139     str = "'NewSignature10', 'necessary', '1.1.1.1', '2.1.1.1', '', '', '', '', ''";
5140     r = add_signature_entry(hdb, str);
5141     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5142
5143     r = package_from_db(hdb, &hpkg);
5144     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
5145     {
5146         skip("Not enough rights to perform tests\n");
5147         goto error;
5148     }
5149     ok(r == ERROR_SUCCESS, "Expected a valid package handle %u\n", r);
5150
5151     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5152
5153     r = MsiDoAction(hpkg, "AppSearch");
5154     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5155
5156     size = MAX_PATH;
5157     sprintf(path, "%s\\FileName1", CURR_DIR);
5158     r = MsiGetPropertyA(hpkg, "SIGPROP1", prop, &size);
5159     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5160     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5161
5162     size = MAX_PATH;
5163     sprintf(path, "%s\\", CURR_DIR);
5164     r = MsiGetPropertyA(hpkg, "SIGPROP2", prop, &size);
5165     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5166     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5167
5168     size = MAX_PATH;
5169     search_absolute_directory(path, CURR_DIR + 3);
5170     r = MsiGetPropertyA(hpkg, "SIGPROP3", prop, &size);
5171     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5172     ok(!lstrcmpiA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5173
5174     size = MAX_PATH;
5175     r = MsiGetPropertyA(hpkg, "SIGPROP4", prop, &size);
5176     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5177     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
5178
5179     size = MAX_PATH;
5180     sprintf(path, "%s\\one\\two\\three\\FileName2", CURR_DIR);
5181     r = MsiGetPropertyA(hpkg, "SIGPROP5", prop, &size);
5182     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5183     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5184
5185     size = MAX_PATH;
5186     r = MsiGetPropertyA(hpkg, "SIGPROP6", prop, &size);
5187     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5188     ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
5189
5190     size = MAX_PATH;
5191     sprintf(path, "%s\\one\\two\\three\\FileName2", CURR_DIR);
5192     r = MsiGetPropertyA(hpkg, "SIGPROP7", prop, &size);
5193     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5194     ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5195
5196     if (version)
5197     {
5198         size = MAX_PATH;
5199         sprintf(path, "%s\\FileName3.dll", CURR_DIR);
5200         r = MsiGetPropertyA(hpkg, "SIGPROP8", prop, &size);
5201         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5202         ok(!lstrcmpA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5203
5204         size = MAX_PATH;
5205         r = MsiGetPropertyA(hpkg, "SIGPROP9", prop, &size);
5206         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5207         ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
5208
5209         size = MAX_PATH;
5210         r = MsiGetPropertyA(hpkg, "SIGPROP10", prop, &size);
5211         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5212         ok(!lstrcmpA(prop, ""), "Expected \"\", got \"%s\"\n", prop);
5213     }
5214
5215     size = MAX_PATH;
5216     search_absolute_directory(path, "");
5217     r = MsiGetPropertyA(hpkg, "SIGPROP11", prop, &size);
5218     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5219     ok(!lstrcmpiA(prop, path), "Expected \"%s\", got \"%s\"\n", path, prop);
5220
5221     size = MAX_PATH;
5222     strcpy(path, "c:\\");
5223     r = MsiGetPropertyA(hpkg, "SIGPROP13", prop, &size);
5224     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5225     ok(!prop[0], "Expected \"\", got \"%s\"\n", prop);
5226
5227     MsiCloseHandle(hpkg);
5228
5229 error:
5230     DeleteFileA("FileName1");
5231     DeleteFileA("FileName3.dll");
5232     DeleteFileA("FileName4.dll");
5233     DeleteFileA("FileName5.dll");
5234     DeleteFileA("one\\two\\three\\FileName2");
5235     RemoveDirectoryA("one\\two\\three");
5236     RemoveDirectoryA("one\\two");
5237     RemoveDirectoryA("one");
5238     RemoveDirectoryA("another");
5239     DeleteFileA(msifile);
5240 }
5241
5242 static void test_featureparents(void)
5243 {
5244     MSIHANDLE hpkg;
5245     UINT r;
5246     MSIHANDLE hdb;
5247
5248     hdb = create_package_db();
5249     ok ( hdb, "failed to create package database\n" );
5250
5251     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'");
5252     ok( r == ERROR_SUCCESS, "cannot add directory: %d\n", r );
5253
5254     r = create_feature_table( hdb );
5255     ok( r == ERROR_SUCCESS, "cannot create Feature table: %d\n", r );
5256
5257     r = create_component_table( hdb );
5258     ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
5259
5260     r = create_feature_components_table( hdb );
5261     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
5262
5263     r = create_file_table( hdb );
5264     ok( r == ERROR_SUCCESS, "cannot create File table: %d\n", r );
5265
5266     /* msidbFeatureAttributesFavorLocal */
5267     r = add_feature_entry( hdb, "'zodiac', '', '', '', 2, 1, '', 0" );
5268     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5269
5270     /* msidbFeatureAttributesFavorSource */
5271     r = add_feature_entry( hdb, "'perseus', '', '', '', 2, 1, '', 1" );
5272     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5273
5274     /* msidbFeatureAttributesFavorLocal */
5275     r = add_feature_entry( hdb, "'orion', '', '', '', 2, 1, '', 0" );
5276     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5277
5278     /* msidbFeatureAttributesUIDisallowAbsent */
5279     r = add_feature_entry( hdb, "'lyra', '', '', '', 2, 1, '', 16" );
5280     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5281
5282     /* disabled because of install level */
5283     r = add_feature_entry( hdb, "'waters', '', '', '', 15, 101, '', 9" );
5284     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5285
5286     /* child feature of disabled feature */
5287     r = add_feature_entry( hdb, "'bayer', 'waters', '', '', 14, 1, '', 9" );
5288     ok( r == ERROR_SUCCESS, "cannot add feature: %d\n", r );
5289
5290     /* component of disabled feature (install level) */
5291     r = add_component_entry( hdb, "'delphinus', '', 'TARGETDIR', 0, '', 'delphinus_file'" );
5292     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5293
5294     /* component of disabled child feature (install level) */
5295     r = add_component_entry( hdb, "'hydrus', '', 'TARGETDIR', 0, '', 'hydrus_file'" );
5296     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5297
5298     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
5299     r = add_component_entry( hdb, "'leo', '', 'TARGETDIR', 0, '', 'leo_file'" );
5300     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5301
5302     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
5303     r = add_component_entry( hdb, "'virgo', '', 'TARGETDIR', 1, '', 'virgo_file'" );
5304     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5305
5306     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
5307     r = add_component_entry( hdb, "'libra', '', 'TARGETDIR', 2, '', 'libra_file'" );
5308     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5309
5310     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesLocalOnly */
5311     r = add_component_entry( hdb, "'cassiopeia', '', 'TARGETDIR', 0, '', 'cassiopeia_file'" );
5312     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5313
5314     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesSourceOnly */
5315     r = add_component_entry( hdb, "'cepheus', '', 'TARGETDIR', 1, '', 'cepheus_file'" );
5316     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5317
5318     /* msidbFeatureAttributesFavorSource:msidbComponentAttributesOptional */
5319     r = add_component_entry( hdb, "'andromeda', '', 'TARGETDIR', 2, '', 'andromeda_file'" );
5320     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5321
5322     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesLocalOnly */
5323     r = add_component_entry( hdb, "'canis', '', 'TARGETDIR', 0, '', 'canis_file'" );
5324     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5325
5326     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesSourceOnly */
5327     r = add_component_entry( hdb, "'monoceros', '', 'TARGETDIR', 1, '', 'monoceros_file'" );
5328     ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
5329
5330     /* msidbFeatureAttributesFavorLocal:msidbComponentAttributesOptional */
5331     r = add_component_entry( hdb, "'lepus', '', 'TARGETDIR', 2, '', 'lepus_file'" );
5332     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
5333
5334     r = add_feature_components_entry( hdb, "'zodiac', 'leo'" );
5335     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5336
5337     r = add_feature_components_entry( hdb, "'zodiac', 'virgo'" );
5338     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5339
5340     r = add_feature_components_entry( hdb, "'zodiac', 'libra'" );
5341     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5342
5343     r = add_feature_components_entry( hdb, "'perseus', 'cassiopeia'" );
5344     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5345
5346     r = add_feature_components_entry( hdb, "'perseus', 'cepheus'" );
5347     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5348
5349     r = add_feature_components_entry( hdb, "'perseus', 'andromeda'" );
5350     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5351
5352     r = add_feature_components_entry( hdb, "'orion', 'leo'" );
5353     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5354
5355     r = add_feature_components_entry( hdb, "'orion', 'virgo'" );
5356     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5357
5358     r = add_feature_components_entry( hdb, "'orion', 'libra'" );
5359     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5360
5361     r = add_feature_components_entry( hdb, "'orion', 'cassiopeia'" );
5362     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5363
5364     r = add_feature_components_entry( hdb, "'orion', 'cepheus'" );
5365     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5366
5367     r = add_feature_components_entry( hdb, "'orion', 'andromeda'" );
5368     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5369
5370     r = add_feature_components_entry( hdb, "'orion', 'canis'" );
5371     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5372
5373     r = add_feature_components_entry( hdb, "'orion', 'monoceros'" );
5374     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5375
5376     r = add_feature_components_entry( hdb, "'orion', 'lepus'" );
5377     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5378
5379     r = add_feature_components_entry( hdb, "'waters', 'delphinus'" );
5380     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5381
5382     r = add_feature_components_entry( hdb, "'bayer', 'hydrus'" );
5383     ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
5384
5385     r = add_file_entry( hdb, "'leo_file', 'leo', 'leo.txt', 100, '', '1033', 8192, 1" );
5386     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5387
5388     r = add_file_entry( hdb, "'virgo_file', 'virgo', 'virgo.txt', 0, '', '1033', 8192, 1" );
5389     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5390
5391     r = add_file_entry( hdb, "'libra_file', 'libra', 'libra.txt', 0, '', '1033', 8192, 1" );
5392     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5393
5394     r = add_file_entry( hdb, "'cassiopeia_file', 'cassiopeia', 'cassiopeia.txt', 0, '', '1033', 8192, 1" );
5395     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5396
5397     r = add_file_entry( hdb, "'cepheus_file', 'cepheus', 'cepheus.txt', 0, '', '1033', 8192, 1" );
5398     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5399
5400     r = add_file_entry( hdb, "'andromeda_file', 'andromeda', 'andromeda.txt', 0, '', '1033', 8192, 1" );
5401     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5402
5403     r = add_file_entry( hdb, "'canis_file', 'canis', 'canis.txt', 0, '', '1033', 8192, 1" );
5404     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5405
5406     r = add_file_entry( hdb, "'monoceros_file', 'monoceros', 'monoceros.txt', 0, '', '1033', 8192, 1" );
5407     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5408
5409     r = add_file_entry( hdb, "'lepus_file', 'lepus', 'lepus.txt', 0, '', '1033', 8192, 1" );
5410     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5411
5412     r = add_file_entry( hdb, "'delphinus_file', 'delphinus', 'delphinus.txt', 0, '', '1033', 8192, 1" );
5413     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5414
5415     r = add_file_entry( hdb, "'hydrus_file', 'hydrus', 'hydrus.txt', 0, '', '1033', 8192, 1" );
5416     ok( r == ERROR_SUCCESS, "cannot add file: %d\n", r);
5417
5418     r = package_from_db( hdb, &hpkg );
5419     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
5420     {
5421         skip("Not enough rights to perform tests\n");
5422         DeleteFile(msifile);
5423         return;
5424     }
5425     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
5426
5427     MsiCloseHandle( hdb );
5428
5429     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5430
5431     r = MsiDoAction( hpkg, "CostInitialize");
5432     ok( r == ERROR_SUCCESS, "cost init failed\n");
5433
5434     r = MsiDoAction( hpkg, "FileCost");
5435     ok( r == ERROR_SUCCESS, "file cost failed\n");
5436
5437     r = MsiDoAction( hpkg, "CostFinalize");
5438     ok( r == ERROR_SUCCESS, "cost finalize failed\n");
5439
5440     test_feature_states( __LINE__, hpkg, "zodiac", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
5441     test_feature_states( __LINE__, hpkg, "perseus", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
5442     test_feature_states( __LINE__, hpkg, "orion", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
5443     test_feature_states( __LINE__, hpkg, "lyra", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
5444     test_feature_states( __LINE__, hpkg, "waters", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
5445     test_feature_states( __LINE__, hpkg, "bayer", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
5446
5447     test_component_states( __LINE__, hpkg, "leo", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5448     test_component_states( __LINE__, hpkg, "virgo", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5449     test_component_states( __LINE__, hpkg, "libra", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5450     test_component_states( __LINE__, hpkg, "cassiopeia", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5451     test_component_states( __LINE__, hpkg, "cepheus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5452     test_component_states( __LINE__, hpkg, "andromeda", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5453     test_component_states( __LINE__, hpkg, "canis", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5454     test_component_states( __LINE__, hpkg, "monoceros", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5455     test_component_states( __LINE__, hpkg, "lepus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5456     test_component_states( __LINE__, hpkg, "delphinus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5457     test_component_states( __LINE__, hpkg, "hydrus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5458
5459     r = MsiSetFeatureState(hpkg, "orion", INSTALLSTATE_ABSENT);
5460     ok( r == ERROR_SUCCESS, "failed to set feature state: %d\n", r);
5461
5462     r = MsiSetFeatureState(hpkg, "lyra", INSTALLSTATE_ABSENT);
5463     ok( r == ERROR_SUCCESS, "failed to set feature state: %d\n", r);
5464
5465     r = MsiSetFeatureState(hpkg, "nosuchfeature", INSTALLSTATE_ABSENT);
5466     ok( r == ERROR_UNKNOWN_FEATURE, "Expected ERROR_UNKNOWN_FEATURE, got %u\n", r);
5467
5468     test_feature_states( __LINE__, hpkg, "zodiac", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_LOCAL, 0 );
5469     test_feature_states( __LINE__, hpkg, "perseus", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_SOURCE, 0 );
5470     test_feature_states( __LINE__, hpkg, "orion", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_ABSENT, 0 );
5471     test_feature_states( __LINE__, hpkg, "lyra", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_ABSENT, 0 );
5472     test_feature_states( __LINE__, hpkg, "waters", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
5473     test_feature_states( __LINE__, hpkg, "bayer", ERROR_SUCCESS, INSTALLSTATE_ABSENT, INSTALLSTATE_UNKNOWN, 0 );
5474
5475     test_component_states( __LINE__, hpkg, "leo", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5476     test_component_states( __LINE__, hpkg, "virgo", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5477     test_component_states( __LINE__, hpkg, "libra", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5478     test_component_states( __LINE__, hpkg, "cassiopeia", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_LOCAL, 0 );
5479     test_component_states( __LINE__, hpkg, "cepheus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5480     test_component_states( __LINE__, hpkg, "andromeda", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_SOURCE, 0 );
5481     test_component_states( __LINE__, hpkg, "canis", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5482     test_component_states( __LINE__, hpkg, "monoceros", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5483     test_component_states( __LINE__, hpkg, "lepus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5484     test_component_states( __LINE__, hpkg, "delphinus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5485     test_component_states( __LINE__, hpkg, "hydrus", ERROR_SUCCESS, INSTALLSTATE_UNKNOWN, INSTALLSTATE_UNKNOWN, 0 );
5486
5487     MsiCloseHandle(hpkg);
5488     DeleteFileA(msifile);
5489 }
5490
5491 static void test_installprops(void)
5492 {
5493     MSIHANDLE hpkg, hdb;
5494     CHAR path[MAX_PATH], buf[MAX_PATH];
5495     DWORD size, type;
5496     LANGID langid;
5497     HKEY hkey1, hkey2;
5498     int res;
5499     UINT r;
5500     REGSAM access = KEY_ALL_ACCESS;
5501     SYSTEM_INFO si;
5502     INSTALLUILEVEL uilevel;
5503
5504     if (is_wow64)
5505         access |= KEY_WOW64_64KEY;
5506
5507     GetCurrentDirectory(MAX_PATH, path);
5508     lstrcat(path, "\\");
5509     lstrcat(path, msifile);
5510
5511     uilevel = MsiSetInternalUI(INSTALLUILEVEL_BASIC|INSTALLUILEVEL_SOURCERESONLY, NULL);
5512
5513     hdb = create_package_db();
5514     ok( hdb, "failed to create database\n");
5515
5516     r = package_from_db(hdb, &hpkg);
5517     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
5518     {
5519         skip("Not enough rights to perform tests\n");
5520         MsiSetInternalUI(uilevel, NULL);
5521         DeleteFile(msifile);
5522         return;
5523     }
5524     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
5525
5526     MsiCloseHandle(hdb);
5527
5528     buf[0] = 0;
5529     size = MAX_PATH;
5530     r = MsiGetProperty(hpkg, "UILevel", buf, &size);
5531     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5532     ok( !lstrcmp(buf, "3"), "Expected \"3\", got \"%s\"\n", buf);
5533
5534     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5535
5536     buf[0] = 0;
5537     size = MAX_PATH;
5538     r = MsiGetProperty(hpkg, "UILevel", buf, &size);
5539     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5540     ok( !lstrcmp(buf, "3"), "Expected \"3\", got \"%s\"\n", buf);
5541
5542     buf[0] = 0;
5543     size = MAX_PATH;
5544     r = MsiGetProperty(hpkg, "DATABASE", buf, &size);
5545     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5546     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
5547
5548     RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\MS Setup (ACME)\\User Info", &hkey1);
5549     RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, access, &hkey2);
5550
5551     size = MAX_PATH;
5552     type = REG_SZ;
5553     *path = '\0';
5554     if (RegQueryValueEx(hkey1, "DefName", NULL, &type, (LPBYTE)path, &size) != ERROR_SUCCESS)
5555     {
5556         size = MAX_PATH;
5557         type = REG_SZ;
5558         RegQueryValueEx(hkey2, "RegisteredOwner", NULL, &type, (LPBYTE)path, &size);
5559     }
5560
5561     buf[0] = 0;
5562     size = MAX_PATH;
5563     r = MsiGetProperty(hpkg, "USERNAME", buf, &size);
5564     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5565     ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
5566
5567     size = MAX_PATH;
5568     type = REG_SZ;
5569     *path = '\0';
5570     if (RegQueryValueEx(hkey1, "DefCompany", NULL, &type, (LPBYTE)path, &size) != ERROR_SUCCESS)
5571     {
5572         size = MAX_PATH;
5573         type = REG_SZ;
5574         RegQueryValueEx(hkey2, "RegisteredOrganization", NULL, &type, (LPBYTE)path, &size);
5575     }
5576
5577     if (*path)
5578     {
5579         buf[0] = 0;
5580         size = MAX_PATH;
5581         r = MsiGetProperty(hpkg, "COMPANYNAME", buf, &size);
5582         ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5583         ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
5584     }
5585
5586     buf[0] = 0;
5587     size = MAX_PATH;
5588     r = MsiGetProperty(hpkg, "VersionDatabase", buf, &size);
5589     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5590     trace("VersionDatabase = %s\n", buf);
5591
5592     buf[0] = 0;
5593     size = MAX_PATH;
5594     r = MsiGetProperty(hpkg, "VersionMsi", buf, &size);
5595     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5596     trace("VersionMsi = %s\n", buf);
5597
5598     buf[0] = 0;
5599     size = MAX_PATH;
5600     r = MsiGetProperty(hpkg, "Date", buf, &size);
5601     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5602     trace("Date = %s\n", buf);
5603
5604     buf[0] = 0;
5605     size = MAX_PATH;
5606     r = MsiGetProperty(hpkg, "Time", buf, &size);
5607     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5608     trace("Time = %s\n", buf);
5609
5610     buf[0] = 0;
5611     size = MAX_PATH;
5612     r = MsiGetProperty(hpkg, "PackageCode", buf, &size);
5613     ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5614     trace("PackageCode = %s\n", buf);
5615
5616     buf[0] = 0;
5617     size = MAX_PATH;
5618     r = MsiGetProperty(hpkg, "ComputerName", buf, &size);
5619     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
5620     trace("ComputerName = %s\n", buf);
5621
5622     langid = GetUserDefaultLangID();
5623     sprintf(path, "%d", langid);
5624
5625     buf[0] = 0;
5626     size = MAX_PATH;
5627     r = MsiGetProperty(hpkg, "UserLanguageID", buf, &size);
5628     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
5629     ok( !lstrcmpA(buf, path), "Expected \"%s\", got \"%s\"\n", path, buf);
5630
5631     res = GetSystemMetrics(SM_CXSCREEN);
5632     buf[0] = 0;
5633     size = MAX_PATH;
5634     r = MsiGetProperty(hpkg, "ScreenX", buf, &size);
5635     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
5636     ok(atol(buf) == res, "Expected %d, got %ld\n", res, atol(buf));
5637
5638     res = GetSystemMetrics(SM_CYSCREEN);
5639     buf[0] = 0;
5640     size = MAX_PATH;
5641     r = MsiGetProperty(hpkg, "ScreenY", buf, &size);
5642     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS got %d\n", r);
5643     ok(atol(buf) == res, "Expected %d, got %ld\n", res, atol(buf));
5644
5645     if (pGetSystemInfo && pSHGetFolderPathA)
5646     {
5647         pGetSystemInfo(&si);
5648         if (S(U(si)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
5649         {
5650             buf[0] = 0;
5651             size = MAX_PATH;
5652             r = MsiGetProperty(hpkg, "Intel", buf, &size);
5653             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5654             ok(buf[0], "property not set\n");
5655
5656             buf[0] = 0;
5657             size = MAX_PATH;
5658             r = MsiGetProperty(hpkg, "MsiAMD64", buf, &size);
5659             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5660             ok(buf[0], "property not set\n");
5661
5662             buf[0] = 0;
5663             size = MAX_PATH;
5664             r = MsiGetProperty(hpkg, "Msix64", buf, &size);
5665             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5666             ok(buf[0], "property not set\n");
5667
5668             buf[0] = 0;
5669             size = MAX_PATH;
5670             r = MsiGetProperty(hpkg, "System64Folder", buf, &size);
5671             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5672             GetSystemDirectoryA(path, MAX_PATH);
5673             if (size) buf[size - 1] = 0;
5674             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5675
5676             buf[0] = 0;
5677             size = MAX_PATH;
5678             r = MsiGetProperty(hpkg, "SystemFolder", buf, &size);
5679             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5680             pGetSystemWow64DirectoryA(path, MAX_PATH);
5681             if (size) buf[size - 1] = 0;
5682             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5683
5684             buf[0] = 0;
5685             size = MAX_PATH;
5686             r = MsiGetProperty(hpkg, "ProgramFiles64Folder", buf, &size);
5687             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5688             pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES, NULL, 0, path);
5689             if (size) buf[size - 1] = 0;
5690             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5691
5692             buf[0] = 0;
5693             size = MAX_PATH;
5694             r = MsiGetProperty(hpkg, "ProgramFilesFolder", buf, &size);
5695             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5696             pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, path);
5697             if (size) buf[size - 1] = 0;
5698             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5699
5700             buf[0] = 0;
5701             size = MAX_PATH;
5702             r = MsiGetProperty(hpkg, "CommonFiles64Folder", buf, &size);
5703             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5704             pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, path);
5705             if (size) buf[size - 1] = 0;
5706             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5707
5708             buf[0] = 0;
5709             size = MAX_PATH;
5710             r = MsiGetProperty(hpkg, "CommonFilesFolder", buf, &size);
5711             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5712             pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, path);
5713             if (size) buf[size - 1] = 0;
5714             ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5715
5716             buf[0] = 0;
5717             size = MAX_PATH;
5718             r = MsiGetProperty(hpkg, "VersionNT64", buf, &size);
5719             ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5720             ok(buf[0], "property not set\n");
5721         }
5722         else if (S(U(si)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
5723         {
5724             if (!is_wow64)
5725             {
5726                 buf[0] = 0;
5727                 size = MAX_PATH;
5728                 r = MsiGetProperty(hpkg, "Intel", buf, &size);
5729                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5730                 ok(buf[0], "property not set\n");
5731
5732                 buf[0] = 0;
5733                 size = MAX_PATH;
5734                 r = MsiGetProperty(hpkg, "MsiAMD64", buf, &size);
5735                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5736                 ok(!buf[0], "property set\n");
5737
5738                 buf[0] = 0;
5739                 size = MAX_PATH;
5740                 r = MsiGetProperty(hpkg, "Msix64", buf, &size);
5741                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5742                 ok(!buf[0], "property set\n");
5743
5744                 buf[0] = 0;
5745                 size = MAX_PATH;
5746                 r = MsiGetProperty(hpkg, "System64Folder", buf, &size);
5747                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5748                 ok(!buf[0], "property set\n");
5749
5750                 buf[0] = 0;
5751                 size = MAX_PATH;
5752                 r = MsiGetProperty(hpkg, "SystemFolder", buf, &size);
5753                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5754                 GetSystemDirectoryA(path, MAX_PATH);
5755                 if (size) buf[size - 1] = 0;
5756                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5757
5758                 buf[0] = 0;
5759                 size = MAX_PATH;
5760                 r = MsiGetProperty(hpkg, "ProgramFiles64Folder", buf, &size);
5761                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5762                 ok(!buf[0], "property set\n");
5763
5764                 buf[0] = 0;
5765                 size = MAX_PATH;
5766                 r = MsiGetProperty(hpkg, "ProgramFilesFolder", buf, &size);
5767                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5768                 pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES, NULL, 0, path);
5769                 if (size) buf[size - 1] = 0;
5770                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5771
5772                 buf[0] = 0;
5773                 size = MAX_PATH;
5774                 r = MsiGetProperty(hpkg, "CommonFiles64Folder", buf, &size);
5775                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5776                 ok(!buf[0], "property set\n");
5777
5778                 buf[0] = 0;
5779                 size = MAX_PATH;
5780                 r = MsiGetProperty(hpkg, "CommonFilesFolder", buf, &size);
5781                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5782                 pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, path);
5783                 if (size) buf[size - 1] = 0;
5784                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5785
5786                 buf[0] = 0;
5787                 size = MAX_PATH;
5788                 r = MsiGetProperty(hpkg, "VersionNT64", buf, &size);
5789                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5790                 ok(!buf[0], "property set\n");
5791             }
5792             else
5793             {
5794                 buf[0] = 0;
5795                 size = MAX_PATH;
5796                 r = MsiGetProperty(hpkg, "Intel", buf, &size);
5797                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5798                 ok(buf[0], "property not set\n");
5799
5800                 buf[0] = 0;
5801                 size = MAX_PATH;
5802                 r = MsiGetProperty(hpkg, "MsiAMD64", buf, &size);
5803                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5804                 ok(buf[0], "property not set\n");
5805
5806                 buf[0] = 0;
5807                 size = MAX_PATH;
5808                 r = MsiGetProperty(hpkg, "Msix64", buf, &size);
5809                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5810                 ok(buf[0], "property not set\n");
5811
5812                 buf[0] = 0;
5813                 size = MAX_PATH;
5814                 r = MsiGetProperty(hpkg, "System64Folder", buf, &size);
5815                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5816                 GetSystemDirectoryA(path, MAX_PATH);
5817                 if (size) buf[size - 1] = 0;
5818                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5819
5820                 buf[0] = 0;
5821                 size = MAX_PATH;
5822                 r = MsiGetProperty(hpkg, "SystemFolder", buf, &size);
5823                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5824                 pGetSystemWow64DirectoryA(path, MAX_PATH);
5825                 if (size) buf[size - 1] = 0;
5826                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5827
5828                 buf[0] = 0;
5829                 size = MAX_PATH;
5830                 r = MsiGetProperty(hpkg, "ProgramFilesFolder64", buf, &size);
5831                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5832                 ok(!buf[0], "property set\n");
5833
5834                 buf[0] = 0;
5835                 size = MAX_PATH;
5836                 r = MsiGetProperty(hpkg, "ProgramFilesFolder", buf, &size);
5837                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5838                 pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, path);
5839                 if (size) buf[size - 1] = 0;
5840                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5841
5842                 buf[0] = 0;
5843                 size = MAX_PATH;
5844                 r = MsiGetProperty(hpkg, "CommonFilesFolder64", buf, &size);
5845                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5846                 ok(!buf[0], "property set\n");
5847
5848                 buf[0] = 0;
5849                 size = MAX_PATH;
5850                 r = MsiGetProperty(hpkg, "CommonFilesFolder", buf, &size);
5851                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5852                 pSHGetFolderPathA(NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, path);
5853                 if (size) buf[size - 1] = 0;
5854                 ok(!lstrcmpiA(path, buf), "expected \"%s\", got \"%s\"\n", path, buf);
5855
5856                 buf[0] = 0;
5857                 size = MAX_PATH;
5858                 r = MsiGetProperty(hpkg, "VersionNT64", buf, &size);
5859                 ok(r == ERROR_SUCCESS, "failed to get property: %d\n", r);
5860                 ok(buf[0], "property not set\n");
5861             }
5862         }
5863     }
5864
5865     CloseHandle(hkey1);
5866     CloseHandle(hkey2);
5867     MsiCloseHandle(hpkg);
5868     DeleteFile(msifile);
5869     MsiSetInternalUI(uilevel, NULL);
5870 }
5871
5872 static void test_launchconditions(void)
5873 {
5874     MSIHANDLE hpkg;
5875     MSIHANDLE hdb;
5876     UINT r;
5877
5878     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5879
5880     hdb = create_package_db();
5881     ok( hdb, "failed to create package database\n" );
5882
5883     r = create_launchcondition_table( hdb );
5884     ok( r == ERROR_SUCCESS, "cannot create LaunchCondition table: %d\n", r );
5885
5886     r = add_launchcondition_entry( hdb, "'X = \"1\"', 'one'" );
5887     ok( r == ERROR_SUCCESS, "cannot add launch condition: %d\n", r );
5888
5889     /* invalid condition */
5890     r = add_launchcondition_entry( hdb, "'X != \"1\"', 'one'" );
5891     ok( r == ERROR_SUCCESS, "cannot add launch condition: %d\n", r );
5892
5893     r = package_from_db( hdb, &hpkg );
5894     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
5895     {
5896         skip("Not enough rights to perform tests\n");
5897         DeleteFile(msifile);
5898         return;
5899     }
5900     ok( r == ERROR_SUCCESS, "failed to create package %u\n", r );
5901
5902     MsiCloseHandle( hdb );
5903
5904     r = MsiSetProperty( hpkg, "X", "1" );
5905     ok( r == ERROR_SUCCESS, "failed to set property\n" );
5906
5907     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5908
5909     /* invalid conditions are ignored */
5910     r = MsiDoAction( hpkg, "LaunchConditions" );
5911     ok( r == ERROR_SUCCESS, "cost init failed\n" );
5912
5913     /* verify LaunchConditions still does some verification */
5914     r = MsiSetProperty( hpkg, "X", "2" );
5915     ok( r == ERROR_SUCCESS, "failed to set property\n" );
5916
5917     r = MsiDoAction( hpkg, "LaunchConditions" );
5918     ok( r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %d\n", r );
5919
5920     MsiCloseHandle( hpkg );
5921     DeleteFile( msifile );
5922 }
5923
5924 static void test_ccpsearch(void)
5925 {
5926     MSIHANDLE hdb, hpkg;
5927     CHAR prop[MAX_PATH];
5928     DWORD size = MAX_PATH;
5929     UINT r;
5930
5931     hdb = create_package_db();
5932     ok(hdb, "failed to create package database\n");
5933
5934     r = create_ccpsearch_table(hdb);
5935     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5936
5937     r = add_ccpsearch_entry(hdb, "'CCP_random'");
5938     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5939
5940     r = add_ccpsearch_entry(hdb, "'RMCCP_random'");
5941     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5942
5943     r = create_reglocator_table(hdb);
5944     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5945
5946     r = add_reglocator_entry(hdb, "CCP_random", 0, "htmlfile\\shell\\open\\nonexistent", "", 1);
5947     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5948
5949     r = create_drlocator_table(hdb);
5950     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5951
5952     r = add_drlocator_entry(hdb, "'RMCCP_random', '', 'C:\\', '0'");
5953     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5954
5955     r = create_signature_table(hdb);
5956     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5957
5958     r = package_from_db(hdb, &hpkg);
5959     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
5960     {
5961         skip("Not enough rights to perform tests\n");
5962         DeleteFile(msifile);
5963         return;
5964     }
5965     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
5966
5967     MsiCloseHandle(hdb);
5968
5969     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
5970
5971     r = MsiDoAction(hpkg, "CCPSearch");
5972     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5973
5974     r = MsiGetPropertyA(hpkg, "CCP_Success", prop, &size);
5975     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5976     ok(!lstrcmpA(prop, "1"), "Expected 1, got %s\n", prop);
5977
5978     MsiCloseHandle(hpkg);
5979     DeleteFileA(msifile);
5980 }
5981
5982 static void test_complocator(void)
5983 {
5984     MSIHANDLE hdb, hpkg;
5985     UINT r;
5986     CHAR prop[MAX_PATH];
5987     CHAR expected[MAX_PATH];
5988     DWORD size = MAX_PATH;
5989
5990     hdb = create_package_db();
5991     ok(hdb, "failed to create package database\n");
5992
5993     r = create_appsearch_table(hdb);
5994     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5995
5996     r = add_appsearch_entry(hdb, "'ABELISAURUS', 'abelisaurus'");
5997     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5998
5999     r = add_appsearch_entry(hdb, "'BACTROSAURUS', 'bactrosaurus'");
6000     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6001
6002     r = add_appsearch_entry(hdb, "'CAMELOTIA', 'camelotia'");
6003     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6004
6005     r = add_appsearch_entry(hdb, "'DICLONIUS', 'diclonius'");
6006     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6007
6008     r = add_appsearch_entry(hdb, "'ECHINODON', 'echinodon'");
6009     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6010
6011     r = add_appsearch_entry(hdb, "'FALCARIUS', 'falcarius'");
6012     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6013
6014     r = add_appsearch_entry(hdb, "'GALLIMIMUS', 'gallimimus'");
6015     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6016
6017     r = add_appsearch_entry(hdb, "'HAGRYPHUS', 'hagryphus'");
6018     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6019
6020     r = add_appsearch_entry(hdb, "'IGUANODON', 'iguanodon'");
6021     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6022
6023     r = add_appsearch_entry(hdb, "'JOBARIA', 'jobaria'");
6024     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6025
6026     r = add_appsearch_entry(hdb, "'KAKURU', 'kakuru'");
6027     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6028
6029     r = add_appsearch_entry(hdb, "'LABOCANIA', 'labocania'");
6030     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6031
6032     r = add_appsearch_entry(hdb, "'MEGARAPTOR', 'megaraptor'");
6033     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6034
6035     r = add_appsearch_entry(hdb, "'NEOSODON', 'neosodon'");
6036     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6037
6038     r = add_appsearch_entry(hdb, "'OLOROTITAN', 'olorotitan'");
6039     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6040
6041     r = add_appsearch_entry(hdb, "'PANTYDRACO', 'pantydraco'");
6042     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6043
6044     r = create_complocator_table(hdb);
6045     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6046
6047     r = add_complocator_entry(hdb, "'abelisaurus', '{E3619EED-305A-418C-B9C7-F7D7377F0934}', 1");
6048     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6049
6050     r = add_complocator_entry(hdb, "'bactrosaurus', '{D56B688D-542F-42Ef-90FD-B6DA76EE8119}', 0");
6051     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6052
6053     r = add_complocator_entry(hdb, "'camelotia', '{8211BE36-2466-47E3-AFB7-6AC72E51AED2}', 1");
6054     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6055
6056     r = add_complocator_entry(hdb, "'diclonius', '{5C767B20-A33C-45A4-B80B-555E512F01AE}', 0");
6057     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6058
6059     r = add_complocator_entry(hdb, "'echinodon', '{A19E16C5-C75D-4699-8111-C4338C40C3CB}', 1");
6060     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6061
6062     r = add_complocator_entry(hdb, "'falcarius', '{17762FA1-A7AE-4CC6-8827-62873C35361D}', 0");
6063     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6064
6065     r = add_complocator_entry(hdb, "'gallimimus', '{75EBF568-C959-41E0-A99E-9050638CF5FB}', 1");
6066     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6067
6068     r = add_complocator_entry(hdb, "'hagrphus', '{D4969B72-17D9-4AB6-BE49-78F2FEE857AC}', 0");
6069     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6070
6071     r = add_complocator_entry(hdb, "'iguanodon', '{8E0DA02E-F6A7-4A8F-B25D-6F564C492308}', 1");
6072     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6073
6074     r = add_complocator_entry(hdb, "'jobaria', '{243C22B1-8C51-4151-B9D1-1AE5265E079E}', 0");
6075     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6076
6077     r = add_complocator_entry(hdb, "'kakuru', '{5D0F03BA-50BC-44F2-ABB1-72C972F4E514}', 1");
6078     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6079
6080     r = add_complocator_entry(hdb, "'labocania', '{C7DDB60C-7828-4046-A6F8-699D5E92F1ED}', 0");
6081     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6082
6083     r = add_complocator_entry(hdb, "'megaraptor', '{8B1034B7-BD5E-41ac-B52C-0105D3DFD74D}', 1");
6084     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6085
6086     r = add_complocator_entry(hdb, "'neosodon', '{0B499649-197A-48EF-93D2-AF1C17ED6E90}', 0");
6087     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6088
6089     r = add_complocator_entry(hdb, "'olorotitan', '{54E9E91F-AED2-46D5-A25A-7E50AFA24513}', 1");
6090     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6091
6092     r = add_complocator_entry(hdb, "'pantydraco', '{2A989951-5565-4FA7-93A7-E800A3E67D71}', 0");
6093     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6094
6095     r = create_signature_table(hdb);
6096     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6097
6098     r = add_signature_entry(hdb, "'abelisaurus', 'abelisaurus', '', '', '', '', '', '', ''");
6099     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6100
6101     r = add_signature_entry(hdb, "'bactrosaurus', 'bactrosaurus', '', '', '', '', '', '', ''");
6102     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6103
6104     r = add_signature_entry(hdb, "'camelotia', 'camelotia', '', '', '', '', '', '', ''");
6105     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6106
6107     r = add_signature_entry(hdb, "'diclonius', 'diclonius', '', '', '', '', '', '', ''");
6108     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6109
6110     r = add_signature_entry(hdb, "'iguanodon', 'iguanodon', '', '', '', '', '', '', ''");
6111     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6112
6113     r = add_signature_entry(hdb, "'jobaria', 'jobaria', '', '', '', '', '', '', ''");
6114     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6115
6116     r = add_signature_entry(hdb, "'kakuru', 'kakuru', '', '', '', '', '', '', ''");
6117     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6118
6119     r = add_signature_entry(hdb, "'labocania', 'labocania', '', '', '', '', '', '', ''");
6120     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6121
6122     r = package_from_db(hdb, &hpkg);
6123     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
6124     {
6125         skip("Not enough rights to perform tests\n");
6126         DeleteFile(msifile);
6127         return;
6128     }
6129     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
6130
6131     MsiCloseHandle(hdb);
6132
6133     create_test_file("abelisaurus");
6134     create_test_file("bactrosaurus");
6135     create_test_file("camelotia");
6136     create_test_file("diclonius");
6137     create_test_file("echinodon");
6138     create_test_file("falcarius");
6139     create_test_file("gallimimus");
6140     create_test_file("hagryphus");
6141     CreateDirectoryA("iguanodon", NULL);
6142     CreateDirectoryA("jobaria", NULL);
6143     CreateDirectoryA("kakuru", NULL);
6144     CreateDirectoryA("labocania", NULL);
6145     CreateDirectoryA("megaraptor", NULL);
6146     CreateDirectoryA("neosodon", NULL);
6147     CreateDirectoryA("olorotitan", NULL);
6148     CreateDirectoryA("pantydraco", NULL);
6149
6150     set_component_path("abelisaurus", MSIINSTALLCONTEXT_MACHINE,
6151                        "{E3619EED-305A-418C-B9C7-F7D7377F0934}", NULL, FALSE);
6152     set_component_path("bactrosaurus", MSIINSTALLCONTEXT_MACHINE,
6153                        "{D56B688D-542F-42Ef-90FD-B6DA76EE8119}", NULL, FALSE);
6154     set_component_path("echinodon", MSIINSTALLCONTEXT_MACHINE,
6155                        "{A19E16C5-C75D-4699-8111-C4338C40C3CB}", NULL, FALSE);
6156     set_component_path("falcarius", MSIINSTALLCONTEXT_MACHINE,
6157                        "{17762FA1-A7AE-4CC6-8827-62873C35361D}", NULL, FALSE);
6158     set_component_path("iguanodon", MSIINSTALLCONTEXT_MACHINE,
6159                        "{8E0DA02E-F6A7-4A8F-B25D-6F564C492308}", NULL, FALSE);
6160     set_component_path("jobaria", MSIINSTALLCONTEXT_MACHINE,
6161                        "{243C22B1-8C51-4151-B9D1-1AE5265E079E}", NULL, FALSE);
6162     set_component_path("megaraptor", MSIINSTALLCONTEXT_MACHINE,
6163                        "{8B1034B7-BD5E-41ac-B52C-0105D3DFD74D}", NULL, FALSE);
6164     set_component_path("neosodon", MSIINSTALLCONTEXT_MACHINE,
6165                        "{0B499649-197A-48EF-93D2-AF1C17ED6E90}", NULL, FALSE);
6166
6167     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
6168
6169     r = MsiDoAction(hpkg, "AppSearch");
6170     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6171
6172     size = MAX_PATH;
6173     r = MsiGetPropertyA(hpkg, "ABELISAURUS", prop, &size);
6174     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6175
6176     lstrcpyA(expected, CURR_DIR);
6177     lstrcatA(expected, "\\abelisaurus");
6178     ok(!lstrcmpA(prop, expected) || !lstrcmpA(prop, ""),
6179        "Expected %s or empty string, got %s\n", expected, prop);
6180
6181     size = MAX_PATH;
6182     r = MsiGetPropertyA(hpkg, "BACTROSAURUS", prop, &size);
6183     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6184     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6185
6186     size = MAX_PATH;
6187     r = MsiGetPropertyA(hpkg, "CAMELOTIA", prop, &size);
6188     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6189     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6190
6191     size = MAX_PATH;
6192     r = MsiGetPropertyA(hpkg, "DICLONIUS", prop, &size);
6193     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6194     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6195
6196     size = MAX_PATH;
6197     r = MsiGetPropertyA(hpkg, "ECHINODON", prop, &size);
6198     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6199
6200     lstrcpyA(expected, CURR_DIR);
6201     lstrcatA(expected, "\\");
6202     ok(!lstrcmpA(prop, expected) || !lstrcmpA(prop, ""),
6203        "Expected %s or empty string, got %s\n", expected, prop);
6204
6205     size = MAX_PATH;
6206     r = MsiGetPropertyA(hpkg, "FALCARIUS", prop, &size);
6207     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6208     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6209
6210     size = MAX_PATH;
6211     r = MsiGetPropertyA(hpkg, "GALLIMIMUS", prop, &size);
6212     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6213     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6214
6215     size = MAX_PATH;
6216     r = MsiGetPropertyA(hpkg, "HAGRYPHUS", prop, &size);
6217     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6218     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6219
6220     size = MAX_PATH;
6221     r = MsiGetPropertyA(hpkg, "IGUANODON", prop, &size);
6222     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6223     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6224
6225     size = MAX_PATH;
6226     r = MsiGetPropertyA(hpkg, "JOBARIA", prop, &size);
6227     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6228     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6229
6230     size = MAX_PATH;
6231     r = MsiGetPropertyA(hpkg, "KAKURU", prop, &size);
6232     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6233     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6234
6235     size = MAX_PATH;
6236     r = MsiGetPropertyA(hpkg, "LABOCANIA", prop, &size);
6237     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6238     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6239
6240     size = MAX_PATH;
6241     r = MsiGetPropertyA(hpkg, "MEGARAPTOR", prop, &size);
6242     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6243
6244     lstrcpyA(expected, CURR_DIR);
6245     lstrcatA(expected, "\\");
6246     ok(!lstrcmpA(prop, expected) || !lstrcmpA(prop, ""),
6247        "Expected %s or empty string, got %s\n", expected, prop);
6248
6249     size = MAX_PATH;
6250     r = MsiGetPropertyA(hpkg, "NEOSODON", prop, &size);
6251     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6252
6253     lstrcpyA(expected, CURR_DIR);
6254     lstrcatA(expected, "\\neosodon\\");
6255     ok(!lstrcmpA(prop, expected) || !lstrcmpA(prop, ""),
6256        "Expected %s or empty string, got %s\n", expected, prop);
6257
6258     size = MAX_PATH;
6259     r = MsiGetPropertyA(hpkg, "OLOROTITAN", prop, &size);
6260     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6261     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6262
6263     size = MAX_PATH;
6264     r = MsiGetPropertyA(hpkg, "PANTYDRACO", prop, &size);
6265     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6266     ok(!lstrcmpA(prop, ""), "Expected , got %s\n", prop);
6267
6268     MsiCloseHandle(hpkg);
6269     DeleteFileA("abelisaurus");
6270     DeleteFileA("bactrosaurus");
6271     DeleteFileA("camelotia");
6272     DeleteFileA("diclonius");
6273     DeleteFileA("echinodon");
6274     DeleteFileA("falcarius");
6275     DeleteFileA("gallimimus");
6276     DeleteFileA("hagryphus");
6277     RemoveDirectoryA("iguanodon");
6278     RemoveDirectoryA("jobaria");
6279     RemoveDirectoryA("kakuru");
6280     RemoveDirectoryA("labocania");
6281     RemoveDirectoryA("megaraptor");
6282     RemoveDirectoryA("neosodon");
6283     RemoveDirectoryA("olorotitan");
6284     RemoveDirectoryA("pantydraco");
6285     delete_component_path("{E3619EED-305A-418C-B9C7-F7D7377F0934}",
6286                           MSIINSTALLCONTEXT_MACHINE, NULL);
6287     delete_component_path("{D56B688D-542F-42Ef-90FD-B6DA76EE8119}",
6288                           MSIINSTALLCONTEXT_MACHINE, NULL);
6289     delete_component_path("{A19E16C5-C75D-4699-8111-C4338C40C3CB}",
6290                           MSIINSTALLCONTEXT_MACHINE, NULL);
6291     delete_component_path("{17762FA1-A7AE-4CC6-8827-62873C35361D}",
6292                           MSIINSTALLCONTEXT_MACHINE, NULL);
6293     delete_component_path("{8E0DA02E-F6A7-4A8F-B25D-6F564C492308}",
6294                           MSIINSTALLCONTEXT_MACHINE, NULL);
6295     delete_component_path("{243C22B1-8C51-4151-B9D1-1AE5265E079E}",
6296                           MSIINSTALLCONTEXT_MACHINE, NULL);
6297     delete_component_path("{8B1034B7-BD5E-41ac-B52C-0105D3DFD74D}",
6298                           MSIINSTALLCONTEXT_MACHINE, NULL);
6299     delete_component_path("{0B499649-197A-48EF-93D2-AF1C17ED6E90}",
6300                           MSIINSTALLCONTEXT_MACHINE, NULL);
6301     DeleteFileA(msifile);
6302 }
6303
6304 static void set_suminfo_prop(MSIHANDLE db, DWORD prop, DWORD val)
6305 {
6306     MSIHANDLE summary;
6307     UINT r;
6308
6309     r = MsiGetSummaryInformationA(db, NULL, 1, &summary);
6310     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6311
6312     r = MsiSummaryInfoSetPropertyA(summary, prop, VT_I4, val, NULL, NULL);
6313     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6314
6315     r = MsiSummaryInfoPersist(summary);
6316     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
6317
6318     MsiCloseHandle(summary);
6319 }
6320
6321 static void test_MsiGetSourcePath(void)
6322 {
6323     MSIHANDLE hdb, hpkg;
6324     CHAR path[MAX_PATH];
6325     CHAR cwd[MAX_PATH];
6326     CHAR subsrc[MAX_PATH];
6327     CHAR sub2[MAX_PATH];
6328     DWORD size;
6329     UINT r;
6330
6331     lstrcpyA(cwd, CURR_DIR);
6332     lstrcatA(cwd, "\\");
6333
6334     lstrcpyA(subsrc, cwd);
6335     lstrcatA(subsrc, "subsource");
6336     lstrcatA(subsrc, "\\");
6337
6338     lstrcpyA(sub2, subsrc);
6339     lstrcatA(sub2, "sub2");
6340     lstrcatA(sub2, "\\");
6341
6342     /* uncompressed source */
6343
6344     hdb = create_package_db();
6345     ok( hdb, "failed to create database\n");
6346
6347     set_suminfo_prop(hdb, PID_WORDCOUNT, 0);
6348
6349     r = add_directory_entry(hdb, "'TARGETDIR', '', 'SourceDir'");
6350     ok(r == S_OK, "failed\n");
6351
6352     r = add_directory_entry(hdb, "'SubDir', 'TARGETDIR', 'subtarget:subsource'");
6353     ok(r == S_OK, "failed\n");
6354
6355     r = add_directory_entry(hdb, "'SubDir2', 'SubDir', 'sub2'");
6356     ok(r == S_OK, "failed\n");
6357
6358     r = MsiDatabaseCommit(hdb);
6359     ok(r == ERROR_SUCCESS , "Failed to commit database\n");
6360
6361     r = package_from_db(hdb, &hpkg);
6362     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
6363     {
6364         skip("Not enough rights to perform tests\n");
6365         DeleteFile(msifile);
6366         return;
6367     }
6368     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
6369
6370     MsiCloseHandle(hdb);
6371
6372     /* invalid database handle */
6373     size = MAX_PATH;
6374     lstrcpyA(path, "kiwi");
6375     r = MsiGetSourcePath(-1, "TARGETDIR", path, &size);
6376     ok(r == ERROR_INVALID_HANDLE,
6377        "Expected ERROR_INVALID_HANDLE, got %d\n", r);
6378     ok(!lstrcmpA(path, "kiwi"),
6379        "Expected path to be unchanged, got \"%s\"\n", path);
6380     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6381
6382     /* NULL szFolder */
6383     size = MAX_PATH;
6384     lstrcpyA(path, "kiwi");
6385     r = MsiGetSourcePath(hpkg, NULL, path, &size);
6386     ok(r == ERROR_INVALID_PARAMETER,
6387        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
6388     ok(!lstrcmpA(path, "kiwi"),
6389        "Expected path to be unchanged, got \"%s\"\n", path);
6390     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6391
6392     /* empty szFolder */
6393     size = MAX_PATH;
6394     lstrcpyA(path, "kiwi");
6395     r = MsiGetSourcePath(hpkg, "", path, &size);
6396     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6397     ok(!lstrcmpA(path, "kiwi"),
6398        "Expected path to be unchanged, got \"%s\"\n", path);
6399     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6400
6401     /* try TARGETDIR */
6402     size = MAX_PATH;
6403     lstrcpyA(path, "kiwi");
6404     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6405     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6406     ok(!lstrcmpA(path, "kiwi"),
6407        "Expected path to be unchanged, got \"%s\"\n", path);
6408     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6409
6410     size = MAX_PATH;
6411     lstrcpyA(path, "kiwi");
6412     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6413     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6414     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6415     ok(size == 0, "Expected 0, got %d\n", size);
6416
6417     size = MAX_PATH;
6418     lstrcpyA(path, "kiwi");
6419     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6420     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6421     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6422     ok(size == 0, "Expected 0, got %d\n", size);
6423
6424     /* try SourceDir */
6425     size = MAX_PATH;
6426     lstrcpyA(path, "kiwi");
6427     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6428     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6429     ok(!lstrcmpA(path, "kiwi"),
6430        "Expected path to be unchanged, got \"%s\"\n", path);
6431     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6432
6433     /* try SOURCEDIR */
6434     size = MAX_PATH;
6435     lstrcpyA(path, "kiwi");
6436     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6437     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6438     ok(!lstrcmpA(path, "kiwi"),
6439        "Expected path to be unchanged, got \"%s\"\n", path);
6440     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6441
6442     /* source path does not exist, but the property exists */
6443     size = MAX_PATH;
6444     lstrcpyA(path, "kiwi");
6445     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6446     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6447     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6448     ok(size == 0, "Expected 0, got %d\n", size);
6449
6450     size = MAX_PATH;
6451     lstrcpyA(path, "kiwi");
6452     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6453     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6454     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6455     ok(size == 0, "Expected 0, got %d\n", size);
6456
6457     /* try SubDir */
6458     size = MAX_PATH;
6459     lstrcpyA(path, "kiwi");
6460     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6461     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6462     ok(!lstrcmpA(path, "kiwi"),
6463        "Expected path to be unchanged, got \"%s\"\n", path);
6464     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6465
6466     /* try SubDir2 */
6467     size = MAX_PATH;
6468     lstrcpyA(path, "kiwi");
6469     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6470     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6471     ok(!lstrcmpA(path, "kiwi"),
6472        "Expected path to be unchanged, got \"%s\"\n", path);
6473     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6474
6475     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
6476
6477     r = MsiDoAction(hpkg, "CostInitialize");
6478     ok(r == ERROR_SUCCESS, "cost init failed\n");
6479
6480     /* try TARGETDIR after CostInitialize */
6481     size = MAX_PATH;
6482     lstrcpyA(path, "kiwi");
6483     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6484     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6485     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6486     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6487
6488     /* try SourceDir after CostInitialize */
6489     size = MAX_PATH;
6490     lstrcpyA(path, "kiwi");
6491     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6492     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6493     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6494     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6495
6496     /* try SOURCEDIR after CostInitialize */
6497     size = MAX_PATH;
6498     lstrcpyA(path, "kiwi");
6499     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6500     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6501     ok(!lstrcmpA(path, "kiwi"),
6502        "Expected path to be unchanged, got \"%s\"\n", path);
6503     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6504
6505     /* source path does not exist, but the property exists */
6506     size = MAX_PATH;
6507     lstrcpyA(path, "kiwi");
6508     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6509     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6510     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6511     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6512
6513     size = MAX_PATH;
6514     lstrcpyA(path, "kiwi");
6515     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6516     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6517     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6518     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6519
6520     /* try SubDir after CostInitialize */
6521     size = MAX_PATH;
6522     lstrcpyA(path, "kiwi");
6523     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6524     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6525     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
6526     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
6527
6528     /* try SubDir2 after CostInitialize */
6529     size = MAX_PATH;
6530     lstrcpyA(path, "kiwi");
6531     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6532     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6533     ok(!lstrcmpA(path, sub2), "Expected \"%s\", got \"%s\"\n", sub2, path);
6534     ok(size == lstrlenA(sub2), "Expected %d, got %d\n", lstrlenA(sub2), size);
6535
6536     r = MsiDoAction(hpkg, "ResolveSource");
6537     ok(r == ERROR_SUCCESS, "file cost failed\n");
6538
6539     /* try TARGETDIR after ResolveSource */
6540     size = MAX_PATH;
6541     lstrcpyA(path, "kiwi");
6542     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6543     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6544     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6545     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6546
6547     /* try SourceDir after ResolveSource */
6548     size = MAX_PATH;
6549     lstrcpyA(path, "kiwi");
6550     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6551     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6552     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6553     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6554
6555     /* try SOURCEDIR after ResolveSource */
6556     size = MAX_PATH;
6557     lstrcpyA(path, "kiwi");
6558     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6559     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6560     ok(!lstrcmpA(path, "kiwi"),
6561        "Expected path to be unchanged, got \"%s\"\n", path);
6562     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6563
6564     /* source path does not exist, but the property exists */
6565     size = MAX_PATH;
6566     lstrcpyA(path, "kiwi");
6567     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6568     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6569     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6570     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6571
6572     size = MAX_PATH;
6573     lstrcpyA(path, "kiwi");
6574     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6575     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6576     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6577     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6578
6579     /* try SubDir after ResolveSource */
6580     size = MAX_PATH;
6581     lstrcpyA(path, "kiwi");
6582     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6583     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6584     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
6585     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
6586
6587     /* try SubDir2 after ResolveSource */
6588     size = MAX_PATH;
6589     lstrcpyA(path, "kiwi");
6590     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6591     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6592     ok(!lstrcmpA(path, sub2), "Expected \"%s\", got \"%s\"\n", sub2, path);
6593     ok(size == lstrlenA(sub2), "Expected %d, got %d\n", lstrlenA(sub2), size);
6594
6595     r = MsiDoAction(hpkg, "FileCost");
6596     ok(r == ERROR_SUCCESS, "file cost failed\n");
6597
6598     /* try TARGETDIR after FileCost */
6599     size = MAX_PATH;
6600     lstrcpyA(path, "kiwi");
6601     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6602     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6603     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6604     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6605
6606     /* try SourceDir after FileCost */
6607     size = MAX_PATH;
6608     lstrcpyA(path, "kiwi");
6609     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6610     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6611     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6612     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6613
6614     /* try SOURCEDIR after FileCost */
6615     size = MAX_PATH;
6616     lstrcpyA(path, "kiwi");
6617     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6618     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6619     ok(!lstrcmpA(path, "kiwi"),
6620        "Expected path to be unchanged, got \"%s\"\n", path);
6621     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6622
6623     /* source path does not exist, but the property exists */
6624     size = MAX_PATH;
6625     lstrcpyA(path, "kiwi");
6626     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6627     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6628     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6629     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6630
6631     size = MAX_PATH;
6632     lstrcpyA(path, "kiwi");
6633     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6634     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6635     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6636     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6637
6638     /* try SubDir after FileCost */
6639     size = MAX_PATH;
6640     lstrcpyA(path, "kiwi");
6641     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6642     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6643     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
6644     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
6645
6646     /* try SubDir2 after FileCost */
6647     size = MAX_PATH;
6648     lstrcpyA(path, "kiwi");
6649     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6650     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6651     ok(!lstrcmpA(path, sub2), "Expected \"%s\", got \"%s\"\n", sub2, path);
6652     ok(size == lstrlenA(sub2), "Expected %d, got %d\n", lstrlenA(sub2), size);
6653
6654     r = MsiDoAction(hpkg, "CostFinalize");
6655     ok(r == ERROR_SUCCESS, "file cost failed\n");
6656
6657     /* try TARGETDIR after CostFinalize */
6658     size = MAX_PATH;
6659     lstrcpyA(path, "kiwi");
6660     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6661     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6662     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6663     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6664
6665     /* try SourceDir after CostFinalize */
6666     size = MAX_PATH;
6667     lstrcpyA(path, "kiwi");
6668     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6669     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6670     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6671     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6672
6673     /* try SOURCEDIR after CostFinalize */
6674     size = MAX_PATH;
6675     lstrcpyA(path, "kiwi");
6676     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6677     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6678     ok(!lstrcmpA(path, "kiwi"),
6679        "Expected path to be unchanged, got \"%s\"\n", path);
6680     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6681
6682     /* source path does not exist, but the property exists */
6683     size = MAX_PATH;
6684     lstrcpyA(path, "kiwi");
6685     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6686     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6687     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6688     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6689
6690     size = MAX_PATH;
6691     lstrcpyA(path, "kiwi");
6692     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6693     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6694     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6695     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6696
6697     /* try SubDir after CostFinalize */
6698     size = MAX_PATH;
6699     lstrcpyA(path, "kiwi");
6700     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6701     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6702     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
6703     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
6704
6705     /* try SubDir2 after CostFinalize */
6706     size = MAX_PATH;
6707     lstrcpyA(path, "kiwi");
6708     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6709     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6710     ok(!lstrcmpA(path, sub2), "Expected \"%s\", got \"%s\"\n", sub2, path);
6711     ok(size == lstrlenA(sub2), "Expected %d, got %d\n", lstrlenA(sub2), size);
6712
6713     /* nonexistent directory */
6714     size = MAX_PATH;
6715     lstrcpyA(path, "kiwi");
6716     r = MsiGetSourcePath(hpkg, "IDontExist", path, &size);
6717     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6718     ok(!lstrcmpA(path, "kiwi"),
6719        "Expected path to be unchanged, got \"%s\"\n", path);
6720     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6721
6722     /* NULL szPathBuf */
6723     size = MAX_PATH;
6724     r = MsiGetSourcePath(hpkg, "SourceDir", NULL, &size);
6725     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6726     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6727
6728     /* NULL pcchPathBuf */
6729     lstrcpyA(path, "kiwi");
6730     r = MsiGetSourcePath(hpkg, "SourceDir", path, NULL);
6731     ok(r == ERROR_INVALID_PARAMETER,
6732        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
6733     ok(!lstrcmpA(path, "kiwi"),
6734        "Expected path to be unchanged, got \"%s\"\n", path);
6735
6736     /* pcchPathBuf is 0 */
6737     size = 0;
6738     lstrcpyA(path, "kiwi");
6739     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6740     ok(r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
6741     ok(!lstrcmpA(path, "kiwi"),
6742        "Expected path to be unchanged, got \"%s\"\n", path);
6743     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6744
6745     /* pcchPathBuf does not have room for NULL terminator */
6746     size = lstrlenA(cwd);
6747     lstrcpyA(path, "kiwi");
6748     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6749     ok(r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
6750     ok(!strncmp(path, cwd, lstrlenA(cwd) - 1),
6751        "Expected path with no backslash, got \"%s\"\n", path);
6752     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6753
6754     /* pcchPathBuf has room for NULL terminator */
6755     size = lstrlenA(cwd) + 1;
6756     lstrcpyA(path, "kiwi");
6757     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6758     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6759     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6760     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6761
6762     /* remove property */
6763     r = MsiSetProperty(hpkg, "SourceDir", NULL);
6764     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6765
6766     /* try SourceDir again */
6767     size = MAX_PATH;
6768     lstrcpyA(path, "kiwi");
6769     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6770     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6771     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6772     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6773
6774     /* set property to a valid directory */
6775     r = MsiSetProperty(hpkg, "SOURCEDIR", cwd);
6776     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6777
6778     /* try SOURCEDIR again */
6779     size = MAX_PATH;
6780     lstrcpyA(path, "kiwi");
6781     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6782     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6783     ok(!lstrcmpA(path, "kiwi"),
6784        "Expected path to be unchanged, got \"%s\"\n", path);
6785     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6786
6787     MsiCloseHandle(hpkg);
6788
6789     /* compressed source */
6790
6791     r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
6792     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6793
6794     set_suminfo_prop(hdb, PID_WORDCOUNT, msidbSumInfoSourceTypeCompressed);
6795
6796     r = package_from_db(hdb, &hpkg);
6797     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
6798
6799     /* try TARGETDIR */
6800     size = MAX_PATH;
6801     lstrcpyA(path, "kiwi");
6802     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6803     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6804     ok(!lstrcmpA(path, "kiwi"),
6805        "Expected path to be unchanged, got \"%s\"\n", path);
6806     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6807
6808     /* try SourceDir */
6809     size = MAX_PATH;
6810     lstrcpyA(path, "kiwi");
6811     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6812     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6813     ok(!lstrcmpA(path, "kiwi"),
6814        "Expected path to be unchanged, got \"%s\"\n", path);
6815     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6816
6817     /* try SOURCEDIR */
6818     size = MAX_PATH;
6819     lstrcpyA(path, "kiwi");
6820     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6821     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6822     ok(!lstrcmpA(path, "kiwi"),
6823        "Expected path to be unchanged, got \"%s\"\n", path);
6824     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6825
6826     /* source path nor the property exist */
6827     size = MAX_PATH;
6828     lstrcpyA(path, "kiwi");
6829     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6830     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6831     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6832     ok(size == 0, "Expected 0, got %d\n", size);
6833
6834     size = MAX_PATH;
6835     lstrcpyA(path, "kiwi");
6836     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6837     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6838     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
6839     ok(size == 0, "Expected 0, got %d\n", size);
6840
6841     /* try SubDir */
6842     size = MAX_PATH;
6843     lstrcpyA(path, "kiwi");
6844     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6845     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6846     ok(!lstrcmpA(path, "kiwi"),
6847        "Expected path to be unchanged, got \"%s\"\n", path);
6848     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6849
6850     /* try SubDir2 */
6851     size = MAX_PATH;
6852     lstrcpyA(path, "kiwi");
6853     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6854     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
6855     ok(!lstrcmpA(path, "kiwi"),
6856        "Expected path to be unchanged, got \"%s\"\n", path);
6857     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
6858
6859     r = MsiDoAction(hpkg, "CostInitialize");
6860     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6861
6862     /* try TARGETDIR after CostInitialize */
6863     size = MAX_PATH;
6864     lstrcpyA(path, "kiwi");
6865     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6866     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6867     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6868     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6869
6870     /* try SourceDir after CostInitialize */
6871     size = MAX_PATH;
6872     lstrcpyA(path, "kiwi");
6873     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6874     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6875     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6876     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6877
6878     /* try SOURCEDIR after CostInitialize */
6879     size = MAX_PATH;
6880     lstrcpyA(path, "kiwi");
6881     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6882     todo_wine
6883     {
6884         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6885         ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6886         ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6887     }
6888
6889     /* source path does not exist, but the property exists */
6890     size = MAX_PATH;
6891     lstrcpyA(path, "kiwi");
6892     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6893     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6894     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6895     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6896
6897     size = MAX_PATH;
6898     lstrcpyA(path, "kiwi");
6899     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6900     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6901     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6902     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6903
6904     /* try SubDir after CostInitialize */
6905     size = MAX_PATH;
6906     lstrcpyA(path, "kiwi");
6907     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6908     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6909     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6910     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6911
6912     /* try SubDir2 after CostInitialize */
6913     size = MAX_PATH;
6914     lstrcpyA(path, "kiwi");
6915     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6916     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6917     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6918     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6919
6920     r = MsiDoAction(hpkg, "ResolveSource");
6921     ok(r == ERROR_SUCCESS, "file cost failed\n");
6922
6923     /* try TARGETDIR after ResolveSource */
6924     size = MAX_PATH;
6925     lstrcpyA(path, "kiwi");
6926     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6927     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6928     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6929     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6930
6931     /* try SourceDir after ResolveSource */
6932     size = MAX_PATH;
6933     lstrcpyA(path, "kiwi");
6934     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6935     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6936     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6937     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6938
6939     /* try SOURCEDIR after ResolveSource */
6940     size = MAX_PATH;
6941     lstrcpyA(path, "kiwi");
6942     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
6943     todo_wine
6944     {
6945         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6946         ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6947         ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6948     }
6949
6950     /* source path and the property exist */
6951     size = MAX_PATH;
6952     lstrcpyA(path, "kiwi");
6953     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
6954     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6955     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6956     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6957
6958     size = MAX_PATH;
6959     lstrcpyA(path, "kiwi");
6960     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
6961     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6962     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6963     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6964
6965     /* try SubDir after ResolveSource */
6966     size = MAX_PATH;
6967     lstrcpyA(path, "kiwi");
6968     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
6969     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6970     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6971     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6972
6973     /* try SubDir2 after ResolveSource */
6974     size = MAX_PATH;
6975     lstrcpyA(path, "kiwi");
6976     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
6977     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6978     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6979     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6980
6981     r = MsiDoAction(hpkg, "FileCost");
6982     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6983
6984     /* try TARGETDIR after CostFinalize */
6985     size = MAX_PATH;
6986     lstrcpyA(path, "kiwi");
6987     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
6988     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6989     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6990     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6991
6992     /* try SourceDir after CostFinalize */
6993     size = MAX_PATH;
6994     lstrcpyA(path, "kiwi");
6995     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
6996     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6997     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
6998     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
6999
7000     /* try SOURCEDIR after CostFinalize */
7001     size = MAX_PATH;
7002     lstrcpyA(path, "kiwi");
7003     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7004     todo_wine
7005     {
7006         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7007         ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7008         ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7009     }
7010
7011     /* source path and the property exist */
7012     size = MAX_PATH;
7013     lstrcpyA(path, "kiwi");
7014     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7015     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7016     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7017     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7018
7019     size = MAX_PATH;
7020     lstrcpyA(path, "kiwi");
7021     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7022     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7023     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7024     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7025
7026     /* try SubDir after CostFinalize */
7027     size = MAX_PATH;
7028     lstrcpyA(path, "kiwi");
7029     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7030     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7031     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7032     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7033
7034     /* try SubDir2 after CostFinalize */
7035     size = MAX_PATH;
7036     lstrcpyA(path, "kiwi");
7037     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
7038     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7039     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7040     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7041
7042     r = MsiDoAction(hpkg, "CostFinalize");
7043     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7044
7045     /* try TARGETDIR after CostFinalize */
7046     size = MAX_PATH;
7047     lstrcpyA(path, "kiwi");
7048     r = MsiGetSourcePath(hpkg, "TARGETDIR", path, &size);
7049     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7050     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7051     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7052
7053     /* try SourceDir after CostFinalize */
7054     size = MAX_PATH;
7055     lstrcpyA(path, "kiwi");
7056     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
7057     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7058     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7059     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7060
7061     /* try SOURCEDIR after CostFinalize */
7062     size = MAX_PATH;
7063     lstrcpyA(path, "kiwi");
7064     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7065     todo_wine
7066     {
7067         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7068         ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7069         ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7070     }
7071
7072     /* source path and the property exist */
7073     size = MAX_PATH;
7074     lstrcpyA(path, "kiwi");
7075     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7076     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7077     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7078     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7079
7080     size = MAX_PATH;
7081     lstrcpyA(path, "kiwi");
7082     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7083     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7084     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7085     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7086
7087     /* try SubDir after CostFinalize */
7088     size = MAX_PATH;
7089     lstrcpyA(path, "kiwi");
7090     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7091     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7092     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7093     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7094
7095     /* try SubDir2 after CostFinalize */
7096     size = MAX_PATH;
7097     lstrcpyA(path, "kiwi");
7098     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
7099     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7100     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7101     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7102
7103     MsiCloseHandle(hpkg);
7104     DeleteFile(msifile);
7105 }
7106
7107 static void test_shortlongsource(void)
7108 {
7109     MSIHANDLE hdb, hpkg;
7110     CHAR path[MAX_PATH];
7111     CHAR cwd[MAX_PATH];
7112     CHAR subsrc[MAX_PATH];
7113     DWORD size;
7114     UINT r;
7115
7116     lstrcpyA(cwd, CURR_DIR);
7117     lstrcatA(cwd, "\\");
7118
7119     lstrcpyA(subsrc, cwd);
7120     lstrcatA(subsrc, "long");
7121     lstrcatA(subsrc, "\\");
7122
7123     /* long file names */
7124
7125     hdb = create_package_db();
7126     ok( hdb, "failed to create database\n");
7127
7128     set_suminfo_prop(hdb, PID_WORDCOUNT, 0);
7129
7130     r = add_directory_entry(hdb, "'TARGETDIR', '', 'SourceDir'");
7131     ok(r == S_OK, "failed\n");
7132
7133     r = add_directory_entry(hdb, "'SubDir', 'TARGETDIR', 'short|long'");
7134     ok(r == S_OK, "failed\n");
7135
7136     /* CostInitialize:short */
7137     r = add_directory_entry(hdb, "'SubDir2', 'TARGETDIR', 'one|two'");
7138     ok(r == S_OK, "failed\n");
7139
7140     /* CostInitialize:long */
7141     r = add_directory_entry(hdb, "'SubDir3', 'TARGETDIR', 'three|four'");
7142     ok(r == S_OK, "failed\n");
7143
7144     /* FileCost:short */
7145     r = add_directory_entry(hdb, "'SubDir4', 'TARGETDIR', 'five|six'");
7146     ok(r == S_OK, "failed\n");
7147
7148     /* FileCost:long */
7149     r = add_directory_entry(hdb, "'SubDir5', 'TARGETDIR', 'seven|eight'");
7150     ok(r == S_OK, "failed\n");
7151
7152     /* CostFinalize:short */
7153     r = add_directory_entry(hdb, "'SubDir6', 'TARGETDIR', 'nine|ten'");
7154     ok(r == S_OK, "failed\n");
7155
7156     /* CostFinalize:long */
7157     r = add_directory_entry(hdb, "'SubDir7', 'TARGETDIR', 'eleven|twelve'");
7158     ok(r == S_OK, "failed\n");
7159
7160     MsiDatabaseCommit(hdb);
7161
7162     r = package_from_db(hdb, &hpkg);
7163     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
7164     {
7165         skip("Not enough rights to perform tests\n");
7166         DeleteFile(msifile);
7167         return;
7168     }
7169     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
7170
7171     MsiCloseHandle(hdb);
7172
7173     CreateDirectoryA("one", NULL);
7174     CreateDirectoryA("four", NULL);
7175
7176     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
7177
7178     r = MsiDoAction(hpkg, "CostInitialize");
7179     ok(r == ERROR_SUCCESS, "file cost failed\n");
7180
7181     CreateDirectory("five", NULL);
7182     CreateDirectory("eight", NULL);
7183
7184     r = MsiDoAction(hpkg, "FileCost");
7185     ok(r == ERROR_SUCCESS, "file cost failed\n");
7186
7187     CreateDirectory("nine", NULL);
7188     CreateDirectory("twelve", NULL);
7189
7190     r = MsiDoAction(hpkg, "CostFinalize");
7191     ok(r == ERROR_SUCCESS, "file cost failed\n");
7192
7193     /* neither short nor long source directories exist */
7194     size = MAX_PATH;
7195     lstrcpyA(path, "kiwi");
7196     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7197     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7198     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7199     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7200
7201     CreateDirectoryA("short", NULL);
7202
7203     /* short source directory exists */
7204     size = MAX_PATH;
7205     lstrcpyA(path, "kiwi");
7206     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7207     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7208     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7209     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7210
7211     CreateDirectoryA("long", NULL);
7212
7213     /* both short and long source directories exist */
7214     size = MAX_PATH;
7215     lstrcpyA(path, "kiwi");
7216     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7217     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7218     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7219     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7220
7221     lstrcpyA(subsrc, cwd);
7222     lstrcatA(subsrc, "two");
7223     lstrcatA(subsrc, "\\");
7224
7225     /* short dir exists before CostInitialize */
7226     size = MAX_PATH;
7227     lstrcpyA(path, "kiwi");
7228     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
7229     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7230     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7231     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7232
7233     lstrcpyA(subsrc, cwd);
7234     lstrcatA(subsrc, "four");
7235     lstrcatA(subsrc, "\\");
7236
7237     /* long dir exists before CostInitialize */
7238     size = MAX_PATH;
7239     lstrcpyA(path, "kiwi");
7240     r = MsiGetSourcePath(hpkg, "SubDir3", path, &size);
7241     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7242     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7243     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7244
7245     lstrcpyA(subsrc, cwd);
7246     lstrcatA(subsrc, "six");
7247     lstrcatA(subsrc, "\\");
7248
7249     /* short dir exists before FileCost */
7250     size = MAX_PATH;
7251     lstrcpyA(path, "kiwi");
7252     r = MsiGetSourcePath(hpkg, "SubDir4", path, &size);
7253     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7254     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7255     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7256
7257     lstrcpyA(subsrc, cwd);
7258     lstrcatA(subsrc, "eight");
7259     lstrcatA(subsrc, "\\");
7260
7261     /* long dir exists before FileCost */
7262     size = MAX_PATH;
7263     lstrcpyA(path, "kiwi");
7264     r = MsiGetSourcePath(hpkg, "SubDir5", path, &size);
7265     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7266     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7267     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7268
7269     lstrcpyA(subsrc, cwd);
7270     lstrcatA(subsrc, "ten");
7271     lstrcatA(subsrc, "\\");
7272
7273     /* short dir exists before CostFinalize */
7274     size = MAX_PATH;
7275     lstrcpyA(path, "kiwi");
7276     r = MsiGetSourcePath(hpkg, "SubDir6", path, &size);
7277     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7278     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7279     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7280
7281     lstrcpyA(subsrc, cwd);
7282     lstrcatA(subsrc, "twelve");
7283     lstrcatA(subsrc, "\\");
7284
7285     /* long dir exists before CostFinalize */
7286     size = MAX_PATH;
7287     lstrcpyA(path, "kiwi");
7288     r = MsiGetSourcePath(hpkg, "SubDir7", path, &size);
7289     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7290     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7291     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7292
7293     MsiCloseHandle(hpkg);
7294     RemoveDirectoryA("short");
7295     RemoveDirectoryA("long");
7296     RemoveDirectoryA("one");
7297     RemoveDirectoryA("four");
7298     RemoveDirectoryA("five");
7299     RemoveDirectoryA("eight");
7300     RemoveDirectoryA("nine");
7301     RemoveDirectoryA("twelve");
7302
7303     /* short file names */
7304
7305     r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
7306     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7307
7308     set_suminfo_prop(hdb, PID_WORDCOUNT, msidbSumInfoSourceTypeSFN);
7309
7310     r = package_from_db(hdb, &hpkg);
7311     ok(r == ERROR_SUCCESS, "failed to create package %u\n", r);
7312
7313     MsiCloseHandle(hdb);
7314
7315     CreateDirectoryA("one", NULL);
7316     CreateDirectoryA("four", NULL);
7317
7318     r = MsiDoAction(hpkg, "CostInitialize");
7319     ok(r == ERROR_SUCCESS, "file cost failed\n");
7320
7321     CreateDirectory("five", NULL);
7322     CreateDirectory("eight", NULL);
7323
7324     r = MsiDoAction(hpkg, "FileCost");
7325     ok(r == ERROR_SUCCESS, "file cost failed\n");
7326
7327     CreateDirectory("nine", NULL);
7328     CreateDirectory("twelve", NULL);
7329
7330     r = MsiDoAction(hpkg, "CostFinalize");
7331     ok(r == ERROR_SUCCESS, "file cost failed\n");
7332
7333     lstrcpyA(subsrc, cwd);
7334     lstrcatA(subsrc, "short");
7335     lstrcatA(subsrc, "\\");
7336
7337     /* neither short nor long source directories exist */
7338     size = MAX_PATH;
7339     lstrcpyA(path, "kiwi");
7340     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7341     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7342     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7343     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7344
7345     CreateDirectoryA("short", NULL);
7346
7347     /* short source directory exists */
7348     size = MAX_PATH;
7349     lstrcpyA(path, "kiwi");
7350     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7351     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7352     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7353     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7354
7355     CreateDirectoryA("long", NULL);
7356
7357     /* both short and long source directories exist */
7358     size = MAX_PATH;
7359     lstrcpyA(path, "kiwi");
7360     r = MsiGetSourcePath(hpkg, "SubDir", path, &size);
7361     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7362     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7363     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7364
7365     lstrcpyA(subsrc, cwd);
7366     lstrcatA(subsrc, "one");
7367     lstrcatA(subsrc, "\\");
7368
7369     /* short dir exists before CostInitialize */
7370     size = MAX_PATH;
7371     lstrcpyA(path, "kiwi");
7372     r = MsiGetSourcePath(hpkg, "SubDir2", path, &size);
7373     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7374     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7375     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7376
7377     lstrcpyA(subsrc, cwd);
7378     lstrcatA(subsrc, "three");
7379     lstrcatA(subsrc, "\\");
7380
7381     /* long dir exists before CostInitialize */
7382     size = MAX_PATH;
7383     lstrcpyA(path, "kiwi");
7384     r = MsiGetSourcePath(hpkg, "SubDir3", path, &size);
7385     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7386     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7387     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7388
7389     lstrcpyA(subsrc, cwd);
7390     lstrcatA(subsrc, "five");
7391     lstrcatA(subsrc, "\\");
7392
7393     /* short dir exists before FileCost */
7394     size = MAX_PATH;
7395     lstrcpyA(path, "kiwi");
7396     r = MsiGetSourcePath(hpkg, "SubDir4", path, &size);
7397     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7398     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7399     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7400
7401     lstrcpyA(subsrc, cwd);
7402     lstrcatA(subsrc, "seven");
7403     lstrcatA(subsrc, "\\");
7404
7405     /* long dir exists before FileCost */
7406     size = MAX_PATH;
7407     lstrcpyA(path, "kiwi");
7408     r = MsiGetSourcePath(hpkg, "SubDir5", path, &size);
7409     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7410     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7411     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7412
7413     lstrcpyA(subsrc, cwd);
7414     lstrcatA(subsrc, "nine");
7415     lstrcatA(subsrc, "\\");
7416
7417     /* short dir exists before CostFinalize */
7418     size = MAX_PATH;
7419     lstrcpyA(path, "kiwi");
7420     r = MsiGetSourcePath(hpkg, "SubDir6", path, &size);
7421     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7422     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7423     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7424
7425     lstrcpyA(subsrc, cwd);
7426     lstrcatA(subsrc, "eleven");
7427     lstrcatA(subsrc, "\\");
7428
7429     /* long dir exists before CostFinalize */
7430     size = MAX_PATH;
7431     lstrcpyA(path, "kiwi");
7432     r = MsiGetSourcePath(hpkg, "SubDir7", path, &size);
7433     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7434     ok(!lstrcmpA(path, subsrc), "Expected \"%s\", got \"%s\"\n", subsrc, path);
7435     ok(size == lstrlenA(subsrc), "Expected %d, got %d\n", lstrlenA(subsrc), size);
7436
7437     MsiCloseHandle(hpkg);
7438     RemoveDirectoryA("short");
7439     RemoveDirectoryA("long");
7440     RemoveDirectoryA("one");
7441     RemoveDirectoryA("four");
7442     RemoveDirectoryA("five");
7443     RemoveDirectoryA("eight");
7444     RemoveDirectoryA("nine");
7445     RemoveDirectoryA("twelve");
7446     DeleteFileA(msifile);
7447 }
7448
7449 static void test_sourcedir(void)
7450 {
7451     MSIHANDLE hdb, hpkg;
7452     CHAR package[12];
7453     CHAR path[MAX_PATH];
7454     CHAR cwd[MAX_PATH];
7455     CHAR subsrc[MAX_PATH];
7456     DWORD size;
7457     UINT r;
7458
7459     lstrcpyA(cwd, CURR_DIR);
7460     lstrcatA(cwd, "\\");
7461
7462     lstrcpyA(subsrc, cwd);
7463     lstrcatA(subsrc, "long");
7464     lstrcatA(subsrc, "\\");
7465
7466     hdb = create_package_db();
7467     ok( hdb, "failed to create database\n");
7468
7469     r = add_directory_entry(hdb, "'TARGETDIR', '', 'SourceDir'");
7470     ok(r == S_OK, "failed\n");
7471
7472     sprintf(package, "#%u", hdb);
7473     r = MsiOpenPackage(package, &hpkg);
7474     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
7475     {
7476         skip("Not enough rights to perform tests\n");
7477         goto error;
7478     }
7479     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7480
7481     /* properties only */
7482
7483     /* SourceDir prop */
7484     size = MAX_PATH;
7485     lstrcpyA(path, "kiwi");
7486     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7487     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7488     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7489     ok(size == 0, "Expected 0, got %d\n", size);
7490
7491     /* SOURCEDIR prop */
7492     size = MAX_PATH;
7493     lstrcpyA(path, "kiwi");
7494     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7495     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7496     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7497     ok(size == 0, "Expected 0, got %d\n", size);
7498
7499     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
7500
7501     r = MsiDoAction(hpkg, "CostInitialize");
7502     ok(r == ERROR_SUCCESS, "file cost failed\n");
7503
7504     /* SourceDir after CostInitialize */
7505     size = MAX_PATH;
7506     lstrcpyA(path, "kiwi");
7507     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7508     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7509     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7510     ok(size == 0, "Expected 0, got %d\n", size);
7511
7512     /* SOURCEDIR after CostInitialize */
7513     size = MAX_PATH;
7514     lstrcpyA(path, "kiwi");
7515     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7516     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7517     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7518     ok(size == 0, "Expected 0, got %d\n", size);
7519
7520     r = MsiDoAction(hpkg, "FileCost");
7521     ok(r == ERROR_SUCCESS, "file cost failed\n");
7522
7523     /* SourceDir after FileCost */
7524     size = MAX_PATH;
7525     lstrcpyA(path, "kiwi");
7526     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7527     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7528     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7529     ok(size == 0, "Expected 0, got %d\n", size);
7530
7531     /* SOURCEDIR after FileCost */
7532     size = MAX_PATH;
7533     lstrcpyA(path, "kiwi");
7534     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7535     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7536     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7537     ok(size == 0, "Expected 0, got %d\n", size);
7538
7539     r = MsiDoAction(hpkg, "CostFinalize");
7540     ok(r == ERROR_SUCCESS, "file cost failed\n");
7541
7542     /* SourceDir after CostFinalize */
7543     size = MAX_PATH;
7544     lstrcpyA(path, "kiwi");
7545     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7546     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7547     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7548     ok(size == 0, "Expected 0, got %d\n", size);
7549
7550     /* SOURCEDIR after CostFinalize */
7551     size = MAX_PATH;
7552     lstrcpyA(path, "kiwi");
7553     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7554     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7555     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7556     ok(size == 0, "Expected 0, got %d\n", size);
7557
7558     size = MAX_PATH;
7559     lstrcpyA(path, "kiwi");
7560     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7561     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7562     ok(!lstrcmpA(path, "kiwi"), "Expected \"kiwi\", got \"%s\"\n", path);
7563     ok(size == MAX_PATH, "Expected %d, got %d\n", MAX_PATH, size);
7564
7565     /* SOURCEDIR after calling MsiGetSourcePath */
7566     size = MAX_PATH;
7567     lstrcpyA(path, "kiwi");
7568     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7569     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7570     todo_wine {
7571     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7572     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7573     }
7574
7575     r = MsiDoAction(hpkg, "ResolveSource");
7576     ok(r == ERROR_SUCCESS, "file cost failed\n");
7577
7578     /* SourceDir after ResolveSource */
7579     size = MAX_PATH;
7580     lstrcpyA(path, "kiwi");
7581     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7582     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7583     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7584     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7585
7586     /* SOURCEDIR after ResolveSource */
7587     size = MAX_PATH;
7588     lstrcpyA(path, "kiwi");
7589     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7590     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7591     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7592     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7593
7594     /* random casing */
7595     size = MAX_PATH;
7596     lstrcpyA(path, "kiwi");
7597     r = MsiGetProperty(hpkg, "SoUrCeDiR", path, &size);
7598     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7599     ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7600     ok(size == 0, "Expected 0, got %d\n", size);
7601
7602     MsiCloseHandle(hpkg);
7603
7604     /* reset the package state */
7605     sprintf(package, "#%i", hdb);
7606     r = MsiOpenPackage(package, &hpkg);
7607     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7608
7609     /* test how MsiGetSourcePath affects the properties */
7610
7611     /* SourceDir prop */
7612     size = MAX_PATH;
7613     lstrcpyA(path, "kiwi");
7614     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7615     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7616     todo_wine
7617     {
7618         ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7619         ok(size == 0, "Expected 0, got %d\n", size);
7620     }
7621
7622     size = MAX_PATH;
7623     lstrcpyA(path, "kiwi");
7624     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
7625     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7626     ok(!lstrcmpA(path, "kiwi"),
7627        "Expected path to be unchanged, got \"%s\"\n", path);
7628     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7629
7630     /* SourceDir after MsiGetSourcePath */
7631     size = MAX_PATH;
7632     lstrcpyA(path, "kiwi");
7633     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7634     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7635     todo_wine
7636     {
7637         ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7638         ok(size == 0, "Expected 0, got %d\n", size);
7639     }
7640
7641     /* SOURCEDIR prop */
7642     size = MAX_PATH;
7643     lstrcpyA(path, "kiwi");
7644     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7645     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7646     todo_wine
7647     {
7648         ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7649         ok(size == 0, "Expected 0, got %d\n", size);
7650     }
7651
7652     size = MAX_PATH;
7653     lstrcpyA(path, "kiwi");
7654     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7655     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7656     ok(!lstrcmpA(path, "kiwi"),
7657        "Expected path to be unchanged, got \"%s\"\n", path);
7658     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7659
7660     /* SOURCEDIR prop after MsiGetSourcePath */
7661     size = MAX_PATH;
7662     lstrcpyA(path, "kiwi");
7663     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7664     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7665     todo_wine
7666     {
7667         ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7668         ok(size == 0, "Expected 0, got %d\n", size);
7669     }
7670
7671     r = MsiDoAction(hpkg, "CostInitialize");
7672     ok(r == ERROR_SUCCESS, "file cost failed\n");
7673
7674     /* SourceDir after CostInitialize */
7675     size = MAX_PATH;
7676     lstrcpyA(path, "kiwi");
7677     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7678     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7679     todo_wine
7680     {
7681         ok(!lstrcmpA(path, ""), "Expected \"\", got \"%s\"\n", path);
7682         ok(size == 0, "Expected 0, got %d\n", size);
7683     }
7684
7685     size = MAX_PATH;
7686     lstrcpyA(path, "kiwi");
7687     r = MsiGetSourcePath(hpkg, "SourceDir", path, &size);
7688     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7689     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7690     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7691
7692     /* SourceDir after MsiGetSourcePath */
7693     size = MAX_PATH;
7694     lstrcpyA(path, "kiwi");
7695     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7696     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7697     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7698     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7699
7700     /* SOURCEDIR after CostInitialize */
7701     size = MAX_PATH;
7702     lstrcpyA(path, "kiwi");
7703     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7704     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7705     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7706     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7707
7708     /* SOURCEDIR source path still does not exist */
7709     size = MAX_PATH;
7710     lstrcpyA(path, "kiwi");
7711     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7712     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7713     ok(!lstrcmpA(path, "kiwi"),
7714        "Expected path to be unchanged, got \"%s\"\n", path);
7715     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7716
7717     r = MsiDoAction(hpkg, "FileCost");
7718     ok(r == ERROR_SUCCESS, "file cost failed\n");
7719
7720     /* SourceDir after FileCost */
7721     size = MAX_PATH;
7722     lstrcpyA(path, "kiwi");
7723     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7724     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7725     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7726     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7727
7728     /* SOURCEDIR after FileCost */
7729     size = MAX_PATH;
7730     lstrcpyA(path, "kiwi");
7731     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7732     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7733     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7734     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7735
7736     /* SOURCEDIR source path still does not exist */
7737     size = MAX_PATH;
7738     lstrcpyA(path, "kiwi");
7739     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7740     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7741     ok(!lstrcmpA(path, "kiwi"),
7742        "Expected path to be unchanged, got \"%s\"\n", path);
7743     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7744
7745     r = MsiDoAction(hpkg, "CostFinalize");
7746     ok(r == ERROR_SUCCESS, "file cost failed\n");
7747
7748     /* SourceDir after CostFinalize */
7749     size = MAX_PATH;
7750     lstrcpyA(path, "kiwi");
7751     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7752     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7753     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7754     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7755
7756     /* SOURCEDIR after CostFinalize */
7757     size = MAX_PATH;
7758     lstrcpyA(path, "kiwi");
7759     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7760     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7761     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7762     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7763
7764     /* SOURCEDIR source path still does not exist */
7765     size = MAX_PATH;
7766     lstrcpyA(path, "kiwi");
7767     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7768     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7769     ok(!lstrcmpA(path, "kiwi"),
7770        "Expected path to be unchanged, got \"%s\"\n", path);
7771     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7772
7773     r = MsiDoAction(hpkg, "ResolveSource");
7774     ok(r == ERROR_SUCCESS, "file cost failed\n");
7775
7776     /* SourceDir after ResolveSource */
7777     size = MAX_PATH;
7778     lstrcpyA(path, "kiwi");
7779     r = MsiGetProperty(hpkg, "SourceDir", path, &size);
7780     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7781     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7782     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7783
7784     /* SOURCEDIR after ResolveSource */
7785     size = MAX_PATH;
7786     lstrcpyA(path, "kiwi");
7787     r = MsiGetProperty(hpkg, "SOURCEDIR", path, &size);
7788     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7789     ok(!lstrcmpA(path, cwd), "Expected \"%s\", got \"%s\"\n", cwd, path);
7790     ok(size == lstrlenA(cwd), "Expected %d, got %d\n", lstrlenA(cwd), size);
7791
7792     /* SOURCEDIR source path still does not exist */
7793     size = MAX_PATH;
7794     lstrcpyA(path, "kiwi");
7795     r = MsiGetSourcePath(hpkg, "SOURCEDIR", path, &size);
7796     ok(r == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", r);
7797     ok(!lstrcmpA(path, "kiwi"),
7798        "Expected path to be unchanged, got \"%s\"\n", path);
7799     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
7800
7801     MsiCloseHandle(hpkg);
7802
7803 error:
7804     MsiCloseHandle(hdb);
7805     DeleteFileA(msifile);
7806 }
7807
7808 struct access_res
7809 {
7810     BOOL gothandle;
7811     DWORD lasterr;
7812     BOOL ignore;
7813 };
7814
7815 static const struct access_res create[16] =
7816 {
7817     { TRUE, ERROR_SUCCESS, TRUE },
7818     { TRUE, ERROR_SUCCESS, TRUE },
7819     { TRUE, ERROR_SUCCESS, FALSE },
7820     { TRUE, ERROR_SUCCESS, FALSE },
7821     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7822     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7823     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7824     { TRUE, ERROR_SUCCESS, FALSE },
7825     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7826     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7827     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7828     { TRUE, ERROR_SUCCESS, TRUE },
7829     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7830     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7831     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7832     { TRUE, ERROR_SUCCESS, TRUE }
7833 };
7834
7835 static const struct access_res create_commit[16] =
7836 {
7837     { TRUE, ERROR_SUCCESS, TRUE },
7838     { TRUE, ERROR_SUCCESS, TRUE },
7839     { TRUE, ERROR_SUCCESS, FALSE },
7840     { TRUE, ERROR_SUCCESS, FALSE },
7841     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7842     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7843     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7844     { TRUE, ERROR_SUCCESS, FALSE },
7845     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7846     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7847     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7848     { TRUE, ERROR_SUCCESS, TRUE },
7849     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7850     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7851     { FALSE, ERROR_SHARING_VIOLATION, FALSE },
7852     { TRUE, ERROR_SUCCESS, TRUE }
7853 };
7854
7855 static const struct access_res create_close[16] =
7856 {
7857     { TRUE, ERROR_SUCCESS, FALSE },
7858     { TRUE, ERROR_SUCCESS, FALSE },
7859     { TRUE, ERROR_SUCCESS, FALSE },
7860     { TRUE, ERROR_SUCCESS, FALSE },
7861     { TRUE, ERROR_SUCCESS, FALSE },
7862     { TRUE, ERROR_SUCCESS, FALSE },
7863     { TRUE, ERROR_SUCCESS, FALSE },
7864     { TRUE, ERROR_SUCCESS, FALSE },
7865     { TRUE, ERROR_SUCCESS, FALSE },
7866     { TRUE, ERROR_SUCCESS, FALSE },
7867     { TRUE, ERROR_SUCCESS, FALSE },
7868     { TRUE, ERROR_SUCCESS, FALSE },
7869     { TRUE, ERROR_SUCCESS, FALSE },
7870     { TRUE, ERROR_SUCCESS, FALSE },
7871     { TRUE, ERROR_SUCCESS, FALSE },
7872     { TRUE, ERROR_SUCCESS }
7873 };
7874
7875 static void _test_file_access(LPCSTR file, const struct access_res *ares, DWORD line)
7876 {
7877     DWORD access = 0, share = 0;
7878     DWORD lasterr;
7879     HANDLE hfile;
7880     int i, j, idx = 0;
7881
7882     for (i = 0; i < 4; i++)
7883     {
7884         if (i == 0) access = 0;
7885         if (i == 1) access = GENERIC_READ;
7886         if (i == 2) access = GENERIC_WRITE;
7887         if (i == 3) access = GENERIC_READ | GENERIC_WRITE;
7888
7889         for (j = 0; j < 4; j++)
7890         {
7891             if (ares[idx].ignore)
7892                 continue;
7893
7894             if (j == 0) share = 0;
7895             if (j == 1) share = FILE_SHARE_READ;
7896             if (j == 2) share = FILE_SHARE_WRITE;
7897             if (j == 3) share = FILE_SHARE_READ | FILE_SHARE_WRITE;
7898
7899             SetLastError(0xdeadbeef);
7900             hfile = CreateFileA(file, access, share, NULL, OPEN_EXISTING,
7901                                 FILE_ATTRIBUTE_NORMAL, 0);
7902             lasterr = GetLastError();
7903
7904             ok((hfile != INVALID_HANDLE_VALUE) == ares[idx].gothandle,
7905                "(%d, handle, %d): Expected %d, got %d\n",
7906                line, idx, ares[idx].gothandle,
7907                (hfile != INVALID_HANDLE_VALUE));
7908
7909             ok(lasterr == ares[idx].lasterr, "(%d, lasterr, %d): Expected %d, got %d\n",
7910                line, idx, ares[idx].lasterr, lasterr);
7911
7912             CloseHandle(hfile);
7913             idx++;
7914         }
7915     }
7916 }
7917
7918 #define test_file_access(file, ares) _test_file_access(file, ares, __LINE__)
7919
7920 static void test_access(void)
7921 {
7922     MSIHANDLE hdb;
7923     UINT r;
7924
7925     r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
7926     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7927
7928     test_file_access(msifile, create);
7929
7930     r = MsiDatabaseCommit(hdb);
7931     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7932
7933     test_file_access(msifile, create_commit);
7934     MsiCloseHandle(hdb);
7935
7936     test_file_access(msifile, create_close);
7937     DeleteFileA(msifile);
7938
7939     r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
7940     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7941
7942     test_file_access(msifile, create);
7943
7944     r = MsiDatabaseCommit(hdb);
7945     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7946
7947     test_file_access(msifile, create_commit);
7948     MsiCloseHandle(hdb);
7949
7950     test_file_access(msifile, create_close);
7951     DeleteFileA(msifile);
7952 }
7953
7954 static void test_emptypackage(void)
7955 {
7956     MSIHANDLE hpkg = 0, hdb = 0, hsuminfo = 0;
7957     MSIHANDLE hview = 0, hrec = 0;
7958     MSICONDITION condition;
7959     CHAR buffer[MAX_PATH];
7960     DWORD size;
7961     UINT r;
7962
7963     r = MsiOpenPackageA("", &hpkg);
7964     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
7965     {
7966         skip("Not enough rights to perform tests\n");
7967         return;
7968     }
7969     todo_wine
7970     {
7971         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7972     }
7973
7974     hdb = MsiGetActiveDatabase(hpkg);
7975     todo_wine
7976     {
7977         ok(hdb != 0, "Expected a valid database handle\n");
7978     }
7979
7980     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `_Tables`", &hview);
7981     todo_wine
7982     {
7983         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7984     }
7985     r = MsiViewExecute(hview, 0);
7986     todo_wine
7987     {
7988         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7989     }
7990
7991     r = MsiViewFetch(hview, &hrec);
7992     todo_wine
7993     {
7994         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7995     }
7996
7997     buffer[0] = 0;
7998     size = MAX_PATH;
7999     r = MsiRecordGetString(hrec, 1, buffer, &size);
8000     todo_wine
8001     {
8002         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8003         ok(!lstrcmpA(buffer, "_Property"),
8004            "Expected \"_Property\", got \"%s\"\n", buffer);
8005     }
8006
8007     MsiCloseHandle(hrec);
8008
8009     r = MsiViewFetch(hview, &hrec);
8010     todo_wine
8011     {
8012         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8013     }
8014
8015     size = MAX_PATH;
8016     r = MsiRecordGetString(hrec, 1, buffer, &size);
8017     todo_wine
8018     {
8019         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8020         ok(!lstrcmpA(buffer, "#_FolderCache"),
8021            "Expected \"_Property\", got \"%s\"\n", buffer);
8022     }
8023
8024     MsiCloseHandle(hrec);
8025     MsiViewClose(hview);
8026     MsiCloseHandle(hview);
8027
8028     condition = MsiDatabaseIsTablePersistentA(hdb, "_Property");
8029     todo_wine
8030     {
8031         ok(condition == MSICONDITION_FALSE,
8032            "Expected MSICONDITION_FALSE, got %d\n", condition);
8033     }
8034
8035     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `_Property`", &hview);
8036     todo_wine
8037     {
8038         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8039     }
8040     r = MsiViewExecute(hview, 0);
8041     todo_wine
8042     {
8043         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8044     }
8045
8046     /* _Property table is not empty */
8047     r = MsiViewFetch(hview, &hrec);
8048     todo_wine
8049     {
8050         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8051     }
8052
8053     MsiCloseHandle(hrec);
8054     MsiViewClose(hview);
8055     MsiCloseHandle(hview);
8056
8057     condition = MsiDatabaseIsTablePersistentA(hdb, "#_FolderCache");
8058     todo_wine
8059     {
8060         ok(condition == MSICONDITION_FALSE,
8061            "Expected MSICONDITION_FALSE, got %d\n", condition);
8062     }
8063
8064     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `#_FolderCache`", &hview);
8065     todo_wine
8066     {
8067         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8068     }
8069     r = MsiViewExecute(hview, 0);
8070     todo_wine
8071     {
8072         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8073     }
8074
8075     /* #_FolderCache is not empty */
8076     r = MsiViewFetch(hview, &hrec);
8077     todo_wine
8078     {
8079         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8080     }
8081
8082     MsiCloseHandle(hrec);
8083     MsiViewClose(hview);
8084     MsiCloseHandle(hview);
8085
8086     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `_Streams`", &hview);
8087     todo_wine
8088     {
8089         ok(r == ERROR_BAD_QUERY_SYNTAX,
8090            "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8091     }
8092
8093     r = MsiDatabaseOpenView(hdb, "SELECT * FROM `_Storages`", &hview);
8094     todo_wine
8095     {
8096         ok(r == ERROR_BAD_QUERY_SYNTAX,
8097            "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8098     }
8099
8100     r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsuminfo);
8101     todo_wine
8102     {
8103         ok(r == ERROR_INSTALL_PACKAGE_INVALID,
8104            "Expected ERROR_INSTALL_PACKAGE_INVALID, got %d\n", r);
8105     }
8106
8107     MsiCloseHandle(hsuminfo);
8108
8109     r = MsiDatabaseCommit(hdb);
8110     todo_wine
8111     {
8112         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8113     }
8114
8115     MsiCloseHandle(hdb);
8116     MsiCloseHandle(hpkg);
8117 }
8118
8119 static void test_MsiGetProductProperty(void)
8120 {
8121     MSIHANDLE hprod, hdb;
8122     CHAR val[MAX_PATH];
8123     CHAR path[MAX_PATH];
8124     CHAR query[MAX_PATH];
8125     CHAR keypath[MAX_PATH*2];
8126     CHAR prodcode[MAX_PATH];
8127     CHAR prod_squashed[MAX_PATH];
8128     HKEY prodkey, userkey, props;
8129     DWORD size;
8130     LONG res;
8131     UINT r;
8132     REGSAM access = KEY_ALL_ACCESS;
8133
8134     GetCurrentDirectoryA(MAX_PATH, path);
8135     lstrcatA(path, "\\");
8136
8137     create_test_guid(prodcode, prod_squashed);
8138
8139     if (is_wow64)
8140         access |= KEY_WOW64_64KEY;
8141
8142     r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
8143     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8144
8145     r = MsiDatabaseCommit(hdb);
8146     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8147
8148     r = set_summary_info(hdb);
8149     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8150
8151     r = run_query(hdb,
8152             "CREATE TABLE `Directory` ( "
8153             "`Directory` CHAR(255) NOT NULL, "
8154             "`Directory_Parent` CHAR(255), "
8155             "`DefaultDir` CHAR(255) NOT NULL "
8156             "PRIMARY KEY `Directory`)");
8157     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8158
8159     r = run_query(hdb,
8160             "CREATE TABLE `Property` ( "
8161             "`Property` CHAR(72) NOT NULL, "
8162             "`Value` CHAR(255) "
8163             "PRIMARY KEY `Property`)");
8164     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8165
8166     sprintf(query, "INSERT INTO `Property` "
8167             "(`Property`, `Value`) "
8168             "VALUES( 'ProductCode', '%s' )", prodcode);
8169     r = run_query(hdb, query);
8170     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8171
8172     r = MsiDatabaseCommit(hdb);
8173     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8174
8175     MsiCloseHandle(hdb);
8176
8177     lstrcpyA(keypath, "Software\\Classes\\Installer\\Products\\");
8178     lstrcatA(keypath, prod_squashed);
8179
8180     res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
8181     if (res == ERROR_ACCESS_DENIED)
8182     {
8183         skip("Not enough rights to perform tests\n");
8184         DeleteFile(msifile);
8185         return;
8186     }
8187     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8188
8189     lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
8190     lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\");
8191     lstrcatA(keypath, prod_squashed);
8192
8193     res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &userkey, NULL);
8194     if (res == ERROR_ACCESS_DENIED)
8195     {
8196         skip("Not enough rights to perform tests\n");
8197         RegDeleteKeyA(prodkey, "");
8198         RegCloseKey(prodkey);
8199         return;
8200     }
8201     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8202
8203     res = RegCreateKeyExA(userkey, "InstallProperties", 0, NULL, 0, access, NULL, &props, NULL);
8204     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8205
8206     lstrcpyA(val, path);
8207     lstrcatA(val, "\\");
8208     lstrcatA(val, msifile);
8209     res = RegSetValueExA(props, "LocalPackage", 0, REG_SZ,
8210                          (const BYTE *)val, lstrlenA(val) + 1);
8211     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8212
8213     hprod = 0xdeadbeef;
8214     r = MsiOpenProductA(prodcode, &hprod);
8215     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8216     ok(hprod != 0 && hprod != 0xdeadbeef, "Expected a valid product handle\n");
8217
8218     /* hProduct is invalid */
8219     size = MAX_PATH;
8220     lstrcpyA(val, "apple");
8221     r = MsiGetProductPropertyA(0xdeadbeef, "ProductCode", val, &size);
8222     ok(r == ERROR_INVALID_HANDLE,
8223        "Expected ERROR_INVALID_HANDLE, got %d\n", r);
8224     ok(!lstrcmpA(val, "apple"),
8225        "Expected val to be unchanged, got \"%s\"\n", val);
8226     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
8227
8228     /* szProperty is NULL */
8229     size = MAX_PATH;
8230     lstrcpyA(val, "apple");
8231     r = MsiGetProductPropertyA(hprod, NULL, val, &size);
8232     ok(r == ERROR_INVALID_PARAMETER,
8233        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
8234     ok(!lstrcmpA(val, "apple"),
8235        "Expected val to be unchanged, got \"%s\"\n", val);
8236     ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size);
8237
8238     /* szProperty is empty */
8239     size = MAX_PATH;
8240     lstrcpyA(val, "apple");
8241     r = MsiGetProductPropertyA(hprod, "", val, &size);
8242     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8243     ok(!lstrcmpA(val, ""), "Expected \"\", got \"%s\"\n", val);
8244     ok(size == 0, "Expected 0, got %d\n", size);
8245
8246     /* get the property */
8247     size = MAX_PATH;
8248     lstrcpyA(val, "apple");
8249     r = MsiGetProductPropertyA(hprod, "ProductCode", val, &size);
8250     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8251     ok(!lstrcmpA(val, prodcode),
8252        "Expected \"%s\", got \"%s\"\n", prodcode, val);
8253     ok(size == lstrlenA(prodcode),
8254        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8255
8256     /* lpValueBuf is NULL */
8257     size = MAX_PATH;
8258     r = MsiGetProductPropertyA(hprod, "ProductCode", NULL, &size);
8259     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8260     ok(size == lstrlenA(prodcode),
8261        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8262
8263     /* pcchValueBuf is NULL */
8264     lstrcpyA(val, "apple");
8265     r = MsiGetProductPropertyA(hprod, "ProductCode", val, NULL);
8266     ok(r == ERROR_INVALID_PARAMETER,
8267        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
8268     ok(!lstrcmpA(val, "apple"),
8269        "Expected val to be unchanged, got \"%s\"\n", val);
8270     ok(size == lstrlenA(prodcode),
8271        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8272
8273     /* pcchValueBuf is too small */
8274     size = 4;
8275     lstrcpyA(val, "apple");
8276     r = MsiGetProductPropertyA(hprod, "ProductCode", val, &size);
8277     ok(r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
8278     ok(!strncmp(val, prodcode, 3),
8279        "Expected first 3 chars of \"%s\", got \"%s\"\n", prodcode, val);
8280     ok(size == lstrlenA(prodcode),
8281        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8282
8283     /* pcchValueBuf does not leave room for NULL terminator */
8284     size = lstrlenA(prodcode);
8285     lstrcpyA(val, "apple");
8286     r = MsiGetProductPropertyA(hprod, "ProductCode", val, &size);
8287     ok(r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", r);
8288     ok(!strncmp(val, prodcode, lstrlenA(prodcode) - 1),
8289        "Expected first 37 chars of \"%s\", got \"%s\"\n", prodcode, val);
8290     ok(size == lstrlenA(prodcode),
8291        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8292
8293     /* pcchValueBuf has enough room for NULL terminator */
8294     size = lstrlenA(prodcode) + 1;
8295     lstrcpyA(val, "apple");
8296     r = MsiGetProductPropertyA(hprod, "ProductCode", val, &size);
8297     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8298     ok(!lstrcmpA(val, prodcode),
8299        "Expected \"%s\", got \"%s\"\n", prodcode, val);
8300     ok(size == lstrlenA(prodcode),
8301        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8302
8303     /* nonexistent property */
8304     size = MAX_PATH;
8305     lstrcpyA(val, "apple");
8306     r = MsiGetProductPropertyA(hprod, "IDontExist", val, &size);
8307     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8308     ok(!lstrcmpA(val, ""), "Expected \"\", got \"%s\"\n", val);
8309     ok(size == 0, "Expected 0, got %d\n", size);
8310
8311     r = MsiSetPropertyA(hprod, "NewProperty", "value");
8312     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8313
8314     /* non-product property set */
8315     size = MAX_PATH;
8316     lstrcpyA(val, "apple");
8317     r = MsiGetProductPropertyA(hprod, "NewProperty", val, &size);
8318     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8319     ok(!lstrcmpA(val, ""), "Expected \"\", got \"%s\"\n", val);
8320     ok(size == 0, "Expected 0, got %d\n", size);
8321
8322     r = MsiSetPropertyA(hprod, "ProductCode", "value");
8323     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8324
8325     /* non-product property that is also a product property set */
8326     size = MAX_PATH;
8327     lstrcpyA(val, "apple");
8328     r = MsiGetProductPropertyA(hprod, "ProductCode", val, &size);
8329     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8330     ok(!lstrcmpA(val, prodcode),
8331        "Expected \"%s\", got \"%s\"\n", prodcode, val);
8332     ok(size == lstrlenA(prodcode),
8333        "Expected %d, got %d\n", lstrlenA(prodcode), size);
8334
8335     MsiCloseHandle(hprod);
8336
8337     RegDeleteValueA(props, "LocalPackage");
8338     delete_key(props, "", access);
8339     RegCloseKey(props);
8340     delete_key(userkey, "", access);
8341     RegCloseKey(userkey);
8342     delete_key(prodkey, "", access);
8343     RegCloseKey(prodkey);
8344     DeleteFileA(msifile);
8345 }
8346
8347 static void test_MsiSetProperty(void)
8348 {
8349     MSIHANDLE hpkg, hdb, hrec;
8350     CHAR buf[MAX_PATH];
8351     LPCSTR query;
8352     DWORD size;
8353     UINT r;
8354
8355     r = package_from_db(create_package_db(), &hpkg);
8356     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
8357     {
8358         skip("Not enough rights to perform tests\n");
8359         DeleteFile(msifile);
8360         return;
8361     }
8362     ok(r == ERROR_SUCCESS, "Expected a valid package %u\n", r);
8363
8364     /* invalid hInstall */
8365     r = MsiSetPropertyA(0, "Prop", "Val");
8366     ok(r == ERROR_INVALID_HANDLE,
8367        "Expected ERROR_INVALID_HANDLE, got %d\n", r);
8368
8369     /* invalid hInstall */
8370     r = MsiSetPropertyA(0xdeadbeef, "Prop", "Val");
8371     ok(r == ERROR_INVALID_HANDLE,
8372        "Expected ERROR_INVALID_HANDLE, got %d\n", r);
8373
8374     /* szName is NULL */
8375     r = MsiSetPropertyA(hpkg, NULL, "Val");
8376     ok(r == ERROR_INVALID_PARAMETER,
8377        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
8378
8379     /* both szName and szValue are NULL */
8380     r = MsiSetPropertyA(hpkg, NULL, NULL);
8381     ok(r == ERROR_INVALID_PARAMETER,
8382        "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
8383
8384     /* szName is empty */
8385     r = MsiSetPropertyA(hpkg, "", "Val");
8386     ok(r == ERROR_FUNCTION_FAILED,
8387        "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8388
8389     /* szName is empty and szValue is NULL */
8390     r = MsiSetPropertyA(hpkg, "", NULL);
8391     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8392
8393     /* set a property */
8394     r = MsiSetPropertyA(hpkg, "Prop", "Val");
8395     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8396
8397     /* get the property */
8398     size = MAX_PATH;
8399     r = MsiGetPropertyA(hpkg, "Prop", buf, &size);
8400     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8401     ok(!lstrcmpA(buf, "Val"), "Expected \"Val\", got \"%s\"\n", buf);
8402     ok(size == 3, "Expected 3, got %d\n", size);
8403
8404     /* update the property */
8405     r = MsiSetPropertyA(hpkg, "Prop", "Nuvo");
8406     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8407
8408     /* get the property */
8409     size = MAX_PATH;
8410     r = MsiGetPropertyA(hpkg, "Prop", buf, &size);
8411     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8412     ok(!lstrcmpA(buf, "Nuvo"), "Expected \"Nuvo\", got \"%s\"\n", buf);
8413     ok(size == 4, "Expected 4, got %d\n", size);
8414
8415     hdb = MsiGetActiveDatabase(hpkg);
8416     ok(hdb != 0, "Expected a valid database handle\n");
8417
8418     /* set prop is not in the _Property table */
8419     query = "SELECT * FROM `_Property` WHERE `Property` = 'Prop'";
8420     r = do_query(hdb, query, &hrec);
8421     ok(r == ERROR_BAD_QUERY_SYNTAX,
8422        "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8423
8424     /* set prop is not in the Property table */
8425     query = "SELECT * FROM `Property` WHERE `Property` = 'Prop'";
8426     r = do_query(hdb, query, &hrec);
8427     ok(r == ERROR_BAD_QUERY_SYNTAX,
8428        "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8429
8430     MsiCloseHandle(hdb);
8431
8432     /* szValue is an empty string */
8433     r = MsiSetPropertyA(hpkg, "Prop", "");
8434     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8435
8436     /* try to get the property */
8437     size = MAX_PATH;
8438     r = MsiGetPropertyA(hpkg, "Prop", buf, &size);
8439     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8440     ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
8441     ok(size == 0, "Expected 0, got %d\n", size);
8442
8443     /* reset the property */
8444     r = MsiSetPropertyA(hpkg, "Prop", "BlueTap");
8445     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8446
8447     /* delete the property */
8448     r = MsiSetPropertyA(hpkg, "Prop", NULL);
8449     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8450
8451     /* try to get the property */
8452     size = MAX_PATH;
8453     r = MsiGetPropertyA(hpkg, "Prop", buf, &size);
8454     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8455     ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
8456     ok(size == 0, "Expected 0, got %d\n", size);
8457
8458     MsiCloseHandle(hpkg);
8459     DeleteFileA(msifile);
8460 }
8461
8462 static void test_MsiApplyMultiplePatches(void)
8463 {
8464     UINT r, type = GetDriveType(NULL);
8465
8466     if (!pMsiApplyMultiplePatchesA) {
8467         win_skip("MsiApplyMultiplePatchesA not found\n");
8468         return;
8469     }
8470
8471     r = pMsiApplyMultiplePatchesA(NULL, NULL, NULL);
8472     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r);
8473
8474     r = pMsiApplyMultiplePatchesA("", NULL, NULL);
8475     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r);
8476
8477     r = pMsiApplyMultiplePatchesA(";", NULL, NULL);
8478     if (type == DRIVE_FIXED)
8479         todo_wine ok(r == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %u\n", r);
8480     else
8481         ok(r == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %u\n", r);
8482
8483     r = pMsiApplyMultiplePatchesA("  ;", NULL, NULL);
8484     if (type == DRIVE_FIXED)
8485         todo_wine ok(r == ERROR_PATCH_PACKAGE_OPEN_FAILED, "Expected ERROR_PATCH_PACKAGE_OPEN_FAILED, got %u\n", r);
8486     else
8487         ok(r == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %u\n", r);
8488
8489     r = pMsiApplyMultiplePatchesA(";;", NULL, NULL);
8490     if (type == DRIVE_FIXED)
8491         todo_wine ok(r == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %u\n", r);
8492     else
8493         ok(r == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %u\n", r);
8494
8495     r = pMsiApplyMultiplePatchesA("nosuchpatchpackage;", NULL, NULL);
8496     todo_wine ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %u\n", r);
8497
8498     r = pMsiApplyMultiplePatchesA(";nosuchpatchpackage", NULL, NULL);
8499     if (type == DRIVE_FIXED)
8500         todo_wine ok(r == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %u\n", r);
8501     else
8502         ok(r == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %u\n", r);
8503
8504     r = pMsiApplyMultiplePatchesA("nosuchpatchpackage;nosuchpatchpackage", NULL, NULL);
8505     todo_wine ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %u\n", r);
8506
8507     r = pMsiApplyMultiplePatchesA("  nosuchpatchpackage  ;  nosuchpatchpackage  ", NULL, NULL);
8508     todo_wine ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %u\n", r);
8509 }
8510
8511 static void test_MsiApplyPatch(void)
8512 {
8513     UINT r;
8514
8515     r = MsiApplyPatch(NULL, NULL, INSTALLTYPE_DEFAULT, NULL);
8516     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r);
8517
8518     r = MsiApplyPatch("", NULL, INSTALLTYPE_DEFAULT, NULL);
8519     ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r);
8520 }
8521
8522 static void test_MsiEnumComponentCosts(void)
8523 {
8524     MSIHANDLE hdb, hpkg;
8525     char package[12], drive[3];
8526     DWORD len;
8527     UINT r;
8528     int cost, temp;
8529
8530     hdb = create_package_db();
8531     ok( hdb, "failed to create database\n" );
8532
8533     r = create_property_table( hdb );
8534     ok( r == ERROR_SUCCESS, "cannot create Property table %u\n", r );
8535
8536     r = add_property_entry( hdb, "'ProductCode', '{379B1C47-40C1-42FA-A9BB-BEBB6F1B0172}'" );
8537     ok( r == ERROR_SUCCESS, "cannot add property entry %u\n", r );
8538
8539     r = add_property_entry( hdb, "'MSIFASTINSTALL', '1'" );
8540     ok( r == ERROR_SUCCESS, "cannot add property entry %u\n", r );
8541
8542     r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'" );
8543     ok( r == ERROR_SUCCESS, "failed to add directory entry %u\n" , r );
8544
8545     r = create_media_table( hdb );
8546     ok( r == ERROR_SUCCESS, "cannot create Media table %u\n", r );
8547
8548     r = add_media_entry( hdb, "'1', '2', 'cabinet', '', '', ''");
8549     ok( r == ERROR_SUCCESS, "cannot add media entry %u\n", r );
8550
8551     r = create_file_table( hdb );
8552     ok( r == ERROR_SUCCESS, "cannot create File table %u\n", r );
8553
8554     r = add_file_entry( hdb, "'one.txt', 'one', 'one.txt', 4096, '', '', 8192, 1" );
8555     ok( r == ERROR_SUCCESS, "cannot add file %u\n", r );
8556
8557     r = create_component_table( hdb );
8558     ok( r == ERROR_SUCCESS, "cannot create Component table %u\n", r );
8559
8560     r = add_component_entry( hdb, "'one', '{B2F86B9D-8447-4BC5-8883-750C45AA31CA}', 'TARGETDIR', 0, '', 'one.txt'" );
8561     ok( r == ERROR_SUCCESS, "cannot add component %u\n", r );
8562
8563     r = add_component_entry( hdb, "'two', '{62A09F6E-0B74-4829-BDB7-CAB66F42CCE8}', 'TARGETDIR', 0, '', ''" );
8564     ok( r == ERROR_SUCCESS, "cannot add component %u\n", r );
8565
8566     r = create_feature_table( hdb );
8567     ok( r == ERROR_SUCCESS, "cannot create Feature table %u\n", r );
8568
8569     r = add_feature_entry( hdb, "'one', '', '', '', 0, 1, '', 0" );
8570     ok( r == ERROR_SUCCESS, "cannot add feature %u\n", r );
8571
8572     r = add_feature_entry( hdb, "'two', '', '', '', 0, 1, '', 0" );
8573     ok( r == ERROR_SUCCESS, "cannot add feature %u\n", r );
8574
8575     r = create_feature_components_table( hdb );
8576     ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table %u\n", r );
8577
8578     r = add_feature_components_entry( hdb, "'one', 'one'" );
8579     ok( r == ERROR_SUCCESS, "cannot add feature/component pair %u\n", r );
8580
8581     r = add_feature_components_entry( hdb, "'two', 'two'" );
8582     ok( r == ERROR_SUCCESS, "cannot add feature/component pair %u\n", r );
8583
8584     r = create_install_execute_sequence_table( hdb );
8585     ok( r == ERROR_SUCCESS, "cannot create InstallExecuteSequence table %u\n", r );
8586
8587     r = add_install_execute_sequence_entry( hdb, "'CostInitialize', '', '800'" );
8588     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry %u\n", r );
8589
8590     r = add_install_execute_sequence_entry( hdb, "'FileCost', '', '900'" );
8591     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry %u\n", r );
8592
8593     r = add_install_execute_sequence_entry( hdb, "'CostFinalize', '', '1000'" );
8594     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry %u\n", r );
8595
8596     r = add_install_execute_sequence_entry( hdb, "'InstallValidate', '', '1100'" );
8597     ok( r == ERROR_SUCCESS, "cannot add install execute sequence entry %u\n", r );
8598
8599     MsiDatabaseCommit( hdb );
8600
8601     sprintf( package, "#%u", hdb );
8602     r = MsiOpenPackageA( package, &hpkg );
8603     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
8604     {
8605         skip("Not enough rights to perform tests\n");
8606         goto error;
8607     }
8608     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8609
8610     r = MsiEnumComponentCostsA( 0, NULL, 0, INSTALLSTATE_UNKNOWN, NULL, NULL, NULL, NULL );
8611     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8612
8613     r = MsiEnumComponentCostsA( hpkg, NULL, 0, INSTALLSTATE_UNKNOWN, NULL, NULL, NULL, NULL );
8614     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8615
8616     r = MsiEnumComponentCostsA( hpkg, NULL, 0, INSTALLSTATE_UNKNOWN, NULL, NULL, NULL, NULL );
8617     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8618
8619     r = MsiEnumComponentCostsA( hpkg, "", 0, INSTALLSTATE_UNKNOWN, NULL, NULL, NULL, NULL );
8620     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8621
8622     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_UNKNOWN, NULL, NULL, NULL, NULL );
8623     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8624
8625     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, NULL, NULL, NULL, NULL );
8626     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8627
8628     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, NULL, NULL, NULL );
8629     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8630
8631     len = sizeof(drive);
8632     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, NULL, NULL );
8633     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8634
8635     len = sizeof(drive);
8636     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, NULL );
8637     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8638
8639     len = sizeof(drive);
8640     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8641     todo_wine ok( r == ERROR_INVALID_HANDLE_STATE, "Expected ERROR_INVALID_HANDLE_STATE, got %u\n", r );
8642
8643     len = sizeof(drive);
8644     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, NULL, &len, &cost, &temp );
8645     ok( r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r );
8646
8647     MsiSetInternalUI( INSTALLUILEVEL_NONE, NULL );
8648
8649     r = MsiDoAction( hpkg, "CostInitialize" );
8650     ok( r == ERROR_SUCCESS, "CostInitialize failed %u\n", r );
8651
8652     r = MsiDoAction( hpkg, "FileCost" );
8653     ok( r == ERROR_SUCCESS, "FileCost failed %u\n", r );
8654
8655     len = sizeof(drive);
8656     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8657     ok( r == ERROR_FUNCTION_NOT_CALLED, "Expected ERROR_FUNCTION_NOT_CALLED, got %u\n", r );
8658
8659     r = MsiDoAction( hpkg, "CostFinalize" );
8660     ok( r == ERROR_SUCCESS, "CostFinalize failed %u\n", r );
8661
8662     /* contrary to what msdn says InstallValidate must be called too */
8663     len = sizeof(drive);
8664     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8665     todo_wine ok( r == ERROR_FUNCTION_NOT_CALLED, "Expected ERROR_FUNCTION_NOT_CALLED, got %u\n", r );
8666
8667     r = MsiDoAction( hpkg, "InstallValidate" );
8668     ok( r == ERROR_SUCCESS, "InstallValidate failed %u\n", r );
8669
8670     len = 0;
8671     r = MsiEnumComponentCostsA( hpkg, "three", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8672     ok( r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %u\n", r );
8673
8674     len = 0;
8675     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8676     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %u\n", r );
8677     ok( len == 2, "expected len == 2, got %u\n", len );
8678
8679     len = 2;
8680     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8681     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %u\n", r );
8682     ok( len == 2, "expected len == 2, got %u\n", len );
8683
8684     len = 2;
8685     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_UNKNOWN, drive, &len, &cost, &temp );
8686     ok( r == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %u\n", r );
8687     ok( len == 2, "expected len == 2, got %u\n", len );
8688
8689     /* install state doesn't seem to matter */
8690     len = sizeof(drive);
8691     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_UNKNOWN, drive, &len, &cost, &temp );
8692     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8693
8694     len = sizeof(drive);
8695     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_ABSENT, drive, &len, &cost, &temp );
8696     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8697
8698     len = sizeof(drive);
8699     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_SOURCE, drive, &len, &cost, &temp );
8700     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8701
8702     len = sizeof(drive);
8703     drive[0] = 0;
8704     cost = temp = 0xdead;
8705     r = MsiEnumComponentCostsA( hpkg, "one", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8706     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8707     ok( len == 2, "expected len == 2, got %u\n", len );
8708     ok( drive[0], "expected a drive\n" );
8709     ok( cost && cost != 0xdead, "expected cost > 0, got %d\n", cost );
8710     ok( !temp, "expected temp == 0, got %d\n", temp );
8711
8712     len = sizeof(drive);
8713     drive[0] = 0;
8714     cost = temp = 0xdead;
8715     r = MsiEnumComponentCostsA( hpkg, "two", 0, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8716     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8717     ok( len == 2, "expected len == 2, got %u\n", len );
8718     ok( drive[0], "expected a drive\n" );
8719     ok( !cost, "expected cost == 0, got %d\n", cost );
8720     ok( !temp, "expected temp == 0, got %d\n", temp );
8721
8722     len = sizeof(drive);
8723     drive[0] = 0;
8724     cost = temp = 0xdead;
8725     r = MsiEnumComponentCostsA( hpkg, "", 0, INSTALLSTATE_UNKNOWN, drive, &len, &cost, &temp );
8726     ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r );
8727     ok( len == 2, "expected len == 2, got %u\n", len );
8728     ok( drive[0], "expected a drive\n" );
8729     ok( !cost, "expected cost == 0, got %d\n", cost );
8730     ok( temp && temp != 0xdead, "expected temp > 0, got %d\n", temp );
8731
8732     /* increased index */
8733     len = sizeof(drive);
8734     r = MsiEnumComponentCostsA( hpkg, "one", 1, INSTALLSTATE_LOCAL, drive, &len, &cost, &temp );
8735     ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %u\n", r );
8736
8737     len = sizeof(drive);
8738     r = MsiEnumComponentCostsA( hpkg, "", 1, INSTALLSTATE_UNKNOWN, drive, &len, &cost, &temp );
8739     ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %u\n", r );
8740
8741     MsiCloseHandle( hpkg );
8742 error:
8743     MsiCloseHandle( hdb );
8744     DeleteFileA( msifile );
8745 }
8746
8747 static void test_MsiDatabaseCommit(void)
8748 {
8749     UINT r;
8750     MSIHANDLE hdb, hpkg = 0;
8751     char buf[32], package[12];
8752     DWORD sz;
8753
8754     hdb = create_package_db();
8755     ok( hdb, "failed to create database\n" );
8756
8757     r = create_property_table( hdb );
8758     ok( r == ERROR_SUCCESS, "can't create Property table %u\n", r );
8759
8760     sprintf( package, "#%u", hdb );
8761     r = MsiOpenPackage( package, &hpkg );
8762     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
8763     {
8764         skip("Not enough rights to perform tests\n");
8765         goto error;
8766     }
8767     ok( r == ERROR_SUCCESS, "got %u\n", r );
8768
8769     r = MsiSetPropertyA( hpkg, "PROP", "value" );
8770     ok( r == ERROR_SUCCESS, "got %u\n", r );
8771
8772     buf[0] = 0;
8773     sz = sizeof(buf);
8774     r = MsiGetPropertyA( hpkg, "PROP", buf, &sz );
8775     ok( r == ERROR_SUCCESS, "MsiGetPropertyA returned %u\n", r );
8776     ok( !lstrcmpA( buf, "value" ), "got \"%s\"\n", buf );
8777
8778     r = MsiDatabaseCommit( hdb );
8779     ok( r == ERROR_SUCCESS, "MsiDatabaseCommit returned %u\n", r );
8780
8781     buf[0] = 0;
8782     sz = sizeof(buf);
8783     r = MsiGetPropertyA( hpkg, "PROP", buf, &sz );
8784     ok( r == ERROR_SUCCESS, "MsiGetPropertyA returned %u\n", r );
8785     ok( !lstrcmpA( buf, "value" ), "got \"%s\"\n", buf );
8786
8787     MsiCloseHandle( hpkg );
8788 error:
8789     MsiCloseHandle( hdb );
8790     DeleteFileA( msifile );
8791 }
8792
8793 START_TEST(package)
8794 {
8795     STATEMGRSTATUS status;
8796     BOOL ret = FALSE;
8797
8798     init_functionpointers();
8799
8800     if (pIsWow64Process)
8801         pIsWow64Process(GetCurrentProcess(), &is_wow64);
8802
8803     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
8804
8805     /* Create a restore point ourselves so we circumvent the multitude of restore points
8806      * that would have been created by all the installation and removal tests.
8807      *
8808      * This is not needed on version 5.0 where setting MSIFASTINSTALL prevents the
8809      * creation of restore points.
8810      */
8811     if (pSRSetRestorePointA && !pMsiGetComponentPathExA)
8812     {
8813         memset(&status, 0, sizeof(status));
8814         ret = notify_system_change(BEGIN_NESTED_SYSTEM_CHANGE, &status);
8815     }
8816
8817     test_createpackage();
8818     test_doaction();
8819     test_gettargetpath_bad();
8820     test_settargetpath();
8821     test_props();
8822     test_property_table();
8823     test_condition();
8824     test_msipackage();
8825     test_formatrecord2();
8826     test_states();
8827     test_getproperty();
8828     test_removefiles();
8829     test_appsearch();
8830     test_appsearch_complocator();
8831     test_appsearch_reglocator();
8832     test_appsearch_inilocator();
8833     test_appsearch_drlocator();
8834     test_featureparents();
8835     test_installprops();
8836     test_launchconditions();
8837     test_ccpsearch();
8838     test_complocator();
8839     test_MsiGetSourcePath();
8840     test_shortlongsource();
8841     test_sourcedir();
8842     test_access();
8843     test_emptypackage();
8844     test_MsiGetProductProperty();
8845     test_MsiSetProperty();
8846     test_MsiApplyMultiplePatches();
8847     test_MsiApplyPatch();
8848     test_MsiEnumComponentCosts();
8849     test_MsiDatabaseCommit();
8850
8851     if (pSRSetRestorePointA && !pMsiGetComponentPathExA && ret)
8852     {
8853         ret = notify_system_change(END_NESTED_SYSTEM_CHANGE, &status);
8854         if (ret)
8855             remove_restore_point(status.llSequenceNumber);
8856     }
8857 }