msi: Implement the remaining contexts for MsiQueryComponentState.
[wine] / dlls / msi / tests / install.c
1 /*
2  * Copyright (C) 2006 James Hawkins
3  *
4  * A test program for installing MSI products.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define _WIN32_MSI 300
22 #define COBJMACROS
23
24 #include <stdio.h>
25
26 #include <windows.h>
27 #include <msiquery.h>
28 #include <msidefs.h>
29 #include <msi.h>
30 #include <fci.h>
31 #include <objidl.h>
32
33 #include "wine/test.h"
34
35 static const char *msifile = "msitest.msi";
36 static const char *msifile2 = "winetest2.msi";
37 static const char *mstfile = "winetest.mst";
38 CHAR CURR_DIR[MAX_PATH];
39 CHAR PROG_FILES_DIR[MAX_PATH];
40
41 /* msi database data */
42
43 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
44                                     "s72\tS38\ts72\ti2\tS255\tS72\n"
45                                     "Component\tComponent\n"
46                                     "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
47                                     "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
48                                     "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
49                                     "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
50                                     "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
51                                     "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
52                                     "component\t\tMSITESTDIR\t0\t1\tfile\n"
53                                     "service_comp\t\tMSITESTDIR\t0\t1\tservice_file";
54
55 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
56                                     "s72\tS72\tl255\n"
57                                     "Directory\tDirectory\n"
58                                     "CABOUTDIR\tMSITESTDIR\tcabout\n"
59                                     "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
60                                     "FIRSTDIR\tMSITESTDIR\tfirst\n"
61                                     "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
62                                     "NEWDIR\tCABOUTDIR\tnew\n"
63                                     "ProgramFilesFolder\tTARGETDIR\t.\n"
64                                     "TARGETDIR\t\tSourceDir";
65
66 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
67                                   "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
68                                   "Feature\tFeature\n"
69                                   "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
70                                   "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
71                                   "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
72                                   "Three\t\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
73                                   "Two\t\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
74                                   "feature\t\t\t\t2\t1\tTARGETDIR\t0\n"
75                                   "service_feature\t\t\t\t2\t1\tTARGETDIR\t0";
76
77 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
78                                        "s38\ts72\n"
79                                        "FeatureComponents\tFeature_\tComponent_\n"
80                                        "Five\tFive\n"
81                                        "Four\tFour\n"
82                                        "One\tOne\n"
83                                        "Three\tThree\n"
84                                        "Two\tTwo\n"
85                                        "feature\tcomponent\n"
86                                        "service_feature\tservice_comp\n";
87
88 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
89                                "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
90                                "File\tFile\n"
91                                "five.txt\tFive\tfive.txt\t1000\t\t\t16384\t5\n"
92                                "four.txt\tFour\tfour.txt\t1000\t\t\t16384\t4\n"
93                                "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
94                                "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
95                                "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
96                                "file\tcomponent\tfilename\t100\t\t\t8192\t1\n"
97                                "service_file\tservice_comp\tservice.exe\t100\t\t\t8192\t1";
98
99 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
100                                            "s72\tS255\tI2\n"
101                                            "InstallExecuteSequence\tAction\n"
102                                            "AllocateRegistrySpace\tNOT Installed\t1550\n"
103                                            "CostFinalize\t\t1000\n"
104                                            "CostInitialize\t\t800\n"
105                                            "FileCost\t\t900\n"
106                                            "InstallFiles\t\t4000\n"
107                                            "InstallServices\t\t5000\n"
108                                            "InstallFinalize\t\t6600\n"
109                                            "InstallInitialize\t\t1500\n"
110                                            "InstallValidate\t\t1400\n"
111                                            "LaunchConditions\t\t100\n"
112                                            "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
113
114 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
115                                 "i2\ti4\tL64\tS255\tS32\tS72\n"
116                                 "Media\tDiskId\n"
117                                 "1\t3\t\t\tDISK1\t\n"
118                                 "2\t5\t\tmsitest.cab\tDISK2\t\n";
119
120 static const CHAR property_dat[] = "Property\tValue\n"
121                                    "s72\tl0\n"
122                                    "Property\tProperty\n"
123                                    "DefaultUIFont\tDlgFont8\n"
124                                    "HASUIRUN\t0\n"
125                                    "INSTALLLEVEL\t3\n"
126                                    "InstallMode\tTypical\n"
127                                    "Manufacturer\tWine\n"
128                                    "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
129                                    "ProductCode\t{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}\n"
130                                    "ProductID\tnone\n"
131                                    "ProductLanguage\t1033\n"
132                                    "ProductName\tMSITEST\n"
133                                    "ProductVersion\t1.1.1\n"
134                                    "PROMPTROLLBACKCOST\tP\n"
135                                    "Setup\tSetup\n"
136                                    "UpgradeCode\t{4C0EAA15-0264-4E5A-8758-609EF142B92D}\n"
137                                    "AdminProperties\tPOSTADMIN\n";
138
139 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
140                                    "s72\ti2\tl255\tL255\tL0\ts72\n"
141                                    "Registry\tRegistry\n"
142                                    "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
143                                    "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
144                                    "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
145                                    "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
146
147 static const CHAR service_install_dat[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
148                                           "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
149                                           "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
150                                           "ServiceInstall\tServiceInstall\n"
151                                           "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
152
153 static const CHAR service_control_dat[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
154                                           "s72\tl255\ti2\tL255\tI2\ts72\n"
155                                           "ServiceControl\tServiceControl\n"
156                                           "ServiceControl\tTestService\t8\t\t0\tservice_comp";
157
158 /* tables for test_continuouscabs */
159 static const CHAR cc_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
160                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
161                                        "Component\tComponent\n"
162                                        "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
163                                        "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
164                                        "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
165
166 static const CHAR cc_feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
167                                      "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
168                                      "Feature\tFeature\n"
169                                      "feature\t\t\t\t2\t1\tTARGETDIR\t0";
170
171 static const CHAR cc_feature_comp_dat[] = "Feature_\tComponent_\n"
172                                           "s38\ts72\n"
173                                           "FeatureComponents\tFeature_\tComponent_\n"
174                                           "feature\tmaximus\n"
175                                           "feature\taugustus\n"
176                                           "feature\tcaesar";
177
178 static const CHAR cc_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
179                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
180                                   "File\tFile\n"
181                                   "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
182                                   "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
183                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12";
184
185 static const CHAR cc_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
186                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
187                                    "Media\tDiskId\n"
188                                    "1\t10\t\ttest1.cab\tDISK1\t\n"
189                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
190                                    "3\t12\t\ttest3.cab\tDISK3\t\n";
191
192 static const CHAR co_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
193                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
194                                   "File\tFile\n"
195                                   "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
196                                   "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
197                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
198
199 static const CHAR co_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
200                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
201                                    "Media\tDiskId\n"
202                                    "1\t10\t\ttest1.cab\tDISK1\t\n"
203                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
204                                    "3\t3\t\ttest3.cab\tDISK3\t\n";
205
206 static const CHAR co2_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
207                                     "i2\ti4\tL64\tS255\tS32\tS72\n"
208                                     "Media\tDiskId\n"
209                                     "1\t10\t\ttest1.cab\tDISK1\t\n"
210                                     "2\t12\t\ttest3.cab\tDISK3\t\n"
211                                     "3\t2\t\ttest2.cab\tDISK2\t\n";
212
213 static const CHAR mm_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
214                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
215                                   "File\tFile\n"
216                                   "maximus\tmaximus\tmaximus\t500\t\t\t512\t1\n"
217                                   "augustus\taugustus\taugustus\t500\t\t\t512\t2\n"
218                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
219
220 static const CHAR mm_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
221                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
222                                    "Media\tDiskId\n"
223                                    "1\t3\t\ttest1.cab\tDISK1\t\n";
224
225 static const CHAR ss_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
226                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
227                                    "Media\tDiskId\n"
228                                    "1\t2\t\ttest1.cab\tDISK1\t\n"
229                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
230                                    "3\t12\t\ttest3.cab\tDISK3\t\n";
231
232 /* tables for test_uiLevelFlags */
233 static const CHAR ui_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
234                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
235                                        "Component\tComponent\n"
236                                        "maximus\t\tMSITESTDIR\t0\tHASUIRUN=1\tmaximus\n"
237                                        "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
238                                        "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
239
240 static const CHAR ui_install_ui_seq_dat[] = "Action\tCondition\tSequence\n"
241                                            "s72\tS255\tI2\n"
242                                            "InstallUISequence\tAction\n"
243                                            "SetUIProperty\t\t5\n"
244                                            "ExecuteAction\t\t1100\n";
245
246 static const CHAR ui_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
247                                            "s72\ti2\tS64\tS0\tS255\n"
248                                            "CustomAction\tAction\n"
249                                            "SetUIProperty\t51\tHASUIRUN\t1\t\n";
250
251 static const CHAR rof_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
252                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
253                                         "Component\tComponent\n"
254                                         "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n";
255
256 static const CHAR rof_feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
257                                       "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
258                                       "Feature\tFeature\n"
259                                       "feature\t\tFeature\tFeature\t2\t1\tTARGETDIR\t0\n"
260                                       "montecristo\t\tFeature\tFeature\t2\t1\tTARGETDIR\t0";
261
262 static const CHAR rof_feature_comp_dat[] = "Feature_\tComponent_\n"
263                                            "s38\ts72\n"
264                                            "FeatureComponents\tFeature_\tComponent_\n"
265                                            "feature\tmaximus\n"
266                                            "montecristo\tmaximus";
267
268 static const CHAR rof_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
269                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
270                                    "File\tFile\n"
271                                    "maximus\tmaximus\tmaximus\t500\t\t\t8192\t1";
272
273 static const CHAR rof_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
274                                     "i2\ti4\tL64\tS255\tS32\tS72\n"
275                                     "Media\tDiskId\n"
276                                     "1\t1\t\t\tDISK1\t\n";
277
278 static const CHAR sdp_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
279                                                "s72\tS255\tI2\n"
280                                                "InstallExecuteSequence\tAction\n"
281                                                "AllocateRegistrySpace\tNOT Installed\t1550\n"
282                                                "CostFinalize\t\t1000\n"
283                                                "CostInitialize\t\t800\n"
284                                                "FileCost\t\t900\n"
285                                                "InstallFiles\t\t4000\n"
286                                                "InstallFinalize\t\t6600\n"
287                                                "InstallInitialize\t\t1500\n"
288                                                "InstallValidate\t\t1400\n"
289                                                "LaunchConditions\t\t100\n"
290                                                "SetDirProperty\t\t950";
291
292 static const CHAR sdp_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
293                                             "s72\ti2\tS64\tS0\tS255\n"
294                                             "CustomAction\tAction\n"
295                                             "SetDirProperty\t51\tMSITESTDIR\t[CommonFilesFolder]msitest\\\t\n";
296
297 static const CHAR cie_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
298                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
299                                         "Component\tComponent\n"
300                                         "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
301                                         "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
302                                         "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n"
303                                         "gaius\t\tMSITESTDIR\t0\t1\tgaius\n";
304
305 static const CHAR cie_feature_comp_dat[] = "Feature_\tComponent_\n"
306                                            "s38\ts72\n"
307                                            "FeatureComponents\tFeature_\tComponent_\n"
308                                            "feature\tmaximus\n"
309                                            "feature\taugustus\n"
310                                            "feature\tcaesar\n"
311                                            "feature\tgaius";
312
313 static const CHAR cie_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
314                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
315                                    "File\tFile\n"
316                                    "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
317                                    "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
318                                    "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12\n"
319                                    "gaius\tgaius\tgaius\t500\t\t\t8192\t11";
320
321 static const CHAR cie_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
322                                     "i2\ti4\tL64\tS255\tS32\tS72\n"
323                                     "Media\tDiskId\n"
324                                     "1\t1\t\ttest1.cab\tDISK1\t\n"
325                                     "2\t2\t\ttest2.cab\tDISK2\t\n"
326                                     "3\t12\t\ttest3.cab\tDISK3\t\n";
327
328 static const CHAR ci_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
329                                               "s72\tS255\tI2\n"
330                                               "InstallExecuteSequence\tAction\n"
331                                               "CostFinalize\t\t1000\n"
332                                               "CostInitialize\t\t800\n"
333                                               "FileCost\t\t900\n"
334                                               "InstallFiles\t\t4000\n"
335                                               "InstallServices\t\t5000\n"
336                                               "InstallFinalize\t\t6600\n"
337                                               "InstallInitialize\t\t1500\n"
338                                               "RunInstall\t\t1600\n"
339                                               "InstallValidate\t\t1400\n"
340                                               "LaunchConditions\t\t100";
341
342 static const CHAR ci_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
343                                             "s72\ti2\tS64\tS0\tS255\n"
344                                             "CustomAction\tAction\n"
345                                             "RunInstall\t23\tmsitest\\concurrent.msi\tMYPROP=[UILevel]\t\n";
346
347 static const CHAR ci_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
348                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
349                                        "Component\tComponent\n"
350                                        "maximus\t{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}\tMSITESTDIR\t0\tUILevel=5\tmaximus\n";
351
352 static const CHAR ci2_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
353                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
354                                         "Component\tComponent\n"
355                                         "augustus\t\tMSITESTDIR\t0\tUILevel=3 AND MYPROP=5\taugustus\n";
356
357 static const CHAR ci2_feature_comp_dat[] = "Feature_\tComponent_\n"
358                                            "s38\ts72\n"
359                                            "FeatureComponents\tFeature_\tComponent_\n"
360                                            "feature\taugustus";
361
362 static const CHAR ci2_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
363                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
364                                    "File\tFile\n"
365                                    "augustus\taugustus\taugustus\t500\t\t\t8192\t1";
366
367 static const CHAR spf_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
368                                             "s72\ti2\tS64\tS0\tS255\n"
369                                             "CustomAction\tAction\n"
370                                             "SetFolderProp\t51\tMSITESTDIR\t[ProgramFilesFolder]\\msitest\\added\t\n";
371
372 static const CHAR spf_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
373                                                "s72\tS255\tI2\n"
374                                                "InstallExecuteSequence\tAction\n"
375                                                "CostFinalize\t\t1000\n"
376                                                "CostInitialize\t\t800\n"
377                                                "FileCost\t\t900\n"
378                                                "SetFolderProp\t\t950\n"
379                                                "InstallFiles\t\t4000\n"
380                                                "InstallServices\t\t5000\n"
381                                                "InstallFinalize\t\t6600\n"
382                                                "InstallInitialize\t\t1500\n"
383                                                "InstallValidate\t\t1400\n"
384                                                "LaunchConditions\t\t100";
385
386 static const CHAR spf_install_ui_seq_dat[] = "Action\tCondition\tSequence\n"
387                                              "s72\tS255\tI2\n"
388                                              "InstallUISequence\tAction\n"
389                                              "CostInitialize\t\t800\n"
390                                              "FileCost\t\t900\n"
391                                              "CostFinalize\t\t1000\n"
392                                              "ExecuteAction\t\t1100\n";
393
394 static const CHAR pp_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
395                                               "s72\tS255\tI2\n"
396                                               "InstallExecuteSequence\tAction\n"
397                                               "ValidateProductID\t\t700\n"
398                                               "CostInitialize\t\t800\n"
399                                               "FileCost\t\t900\n"
400                                               "CostFinalize\t\t1000\n"
401                                               "InstallValidate\t\t1400\n"
402                                               "InstallInitialize\t\t1500\n"
403                                               "ProcessComponents\tPROCESS_COMPONENTS=1 Or FULL=1\t1600\n"
404                                               "UnpublishFeatures\tUNPUBLISH_FEATURES=1 Or FULL=1\t1800\n"
405                                               "RemoveFiles\t\t3500\n"
406                                               "InstallFiles\t\t4000\n"
407                                               "RegisterUser\t\t6000\n"
408                                               "RegisterProduct\tREGISTER_PRODUCT=1 Or FULL=1\t6100\n"
409                                               "PublishFeatures\tPUBLISH_FEATURES=1 Or FULL=1\t6300\n"
410                                               "PublishProduct\tPUBLISH_PRODUCT=1 Or FULL=1\t6400\n"
411                                               "InstallFinalize\t\t6600";
412
413 static const CHAR tp_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
414                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
415                                        "Component\tComponent\n"
416                                        "augustus\t\tMSITESTDIR\t0\tprop=\"val\"\taugustus\n";
417
418 static const CHAR cwd_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
419                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
420                                         "Component\tComponent\n"
421                                         "augustus\t\tMSITESTDIR\t0\t\taugustus\n";
422
423 static const CHAR adm_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
424                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
425                                         "Component\tComponent\n"
426                                         "augustus\t\tMSITESTDIR\t0\tPOSTADMIN=1\taugustus";
427
428 static const CHAR adm_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
429                                             "s72\ti2\tS64\tS0\tS255\n"
430                                             "CustomAction\tAction\n"
431                                             "SetPOSTADMIN\t51\tPOSTADMIN\t1\t";
432
433 static const CHAR adm_admin_exec_seq_dat[] = "Action\tCondition\tSequence\n"
434                                              "s72\tS255\tI2\n"
435                                              "AdminExecuteSequence\tAction\n"
436                                              "CostFinalize\t\t1000\n"
437                                              "CostInitialize\t\t800\n"
438                                              "FileCost\t\t900\n"
439                                              "SetPOSTADMIN\t\t950\n"
440                                              "InstallFiles\t\t4000\n"
441                                              "InstallFinalize\t\t6600\n"
442                                              "InstallInitialize\t\t1500\n"
443                                              "InstallValidate\t\t1400\n"
444                                              "LaunchConditions\t\t100";
445
446 static const CHAR amp_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
447                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
448                                         "Component\tComponent\n"
449                                         "augustus\t\tMSITESTDIR\t0\tMYPROP=2718\taugustus\n";
450
451 typedef struct _msi_table
452 {
453     const CHAR *filename;
454     const CHAR *data;
455     int size;
456 } msi_table;
457
458 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
459
460 static const msi_table tables[] =
461 {
462     ADD_TABLE(component),
463     ADD_TABLE(directory),
464     ADD_TABLE(feature),
465     ADD_TABLE(feature_comp),
466     ADD_TABLE(file),
467     ADD_TABLE(install_exec_seq),
468     ADD_TABLE(media),
469     ADD_TABLE(property),
470     ADD_TABLE(registry),
471     ADD_TABLE(service_install),
472     ADD_TABLE(service_control)
473 };
474
475 static const msi_table cc_tables[] =
476 {
477     ADD_TABLE(cc_component),
478     ADD_TABLE(directory),
479     ADD_TABLE(cc_feature),
480     ADD_TABLE(cc_feature_comp),
481     ADD_TABLE(cc_file),
482     ADD_TABLE(install_exec_seq),
483     ADD_TABLE(cc_media),
484     ADD_TABLE(property),
485 };
486
487 static const msi_table co_tables[] =
488 {
489     ADD_TABLE(cc_component),
490     ADD_TABLE(directory),
491     ADD_TABLE(cc_feature),
492     ADD_TABLE(cc_feature_comp),
493     ADD_TABLE(co_file),
494     ADD_TABLE(install_exec_seq),
495     ADD_TABLE(co_media),
496     ADD_TABLE(property),
497 };
498
499 static const msi_table co2_tables[] =
500 {
501     ADD_TABLE(cc_component),
502     ADD_TABLE(directory),
503     ADD_TABLE(cc_feature),
504     ADD_TABLE(cc_feature_comp),
505     ADD_TABLE(cc_file),
506     ADD_TABLE(install_exec_seq),
507     ADD_TABLE(co2_media),
508     ADD_TABLE(property),
509 };
510
511 static const msi_table mm_tables[] =
512 {
513     ADD_TABLE(cc_component),
514     ADD_TABLE(directory),
515     ADD_TABLE(cc_feature),
516     ADD_TABLE(cc_feature_comp),
517     ADD_TABLE(mm_file),
518     ADD_TABLE(install_exec_seq),
519     ADD_TABLE(mm_media),
520     ADD_TABLE(property),
521 };
522
523 static const msi_table ss_tables[] =
524 {
525     ADD_TABLE(cc_component),
526     ADD_TABLE(directory),
527     ADD_TABLE(cc_feature),
528     ADD_TABLE(cc_feature_comp),
529     ADD_TABLE(cc_file),
530     ADD_TABLE(install_exec_seq),
531     ADD_TABLE(ss_media),
532     ADD_TABLE(property),
533 };
534
535 static const msi_table ui_tables[] =
536 {
537     ADD_TABLE(ui_component),
538     ADD_TABLE(directory),
539     ADD_TABLE(cc_feature),
540     ADD_TABLE(cc_feature_comp),
541     ADD_TABLE(cc_file),
542     ADD_TABLE(install_exec_seq),
543     ADD_TABLE(ui_install_ui_seq),
544     ADD_TABLE(ui_custom_action),
545     ADD_TABLE(cc_media),
546     ADD_TABLE(property),
547 };
548
549 static const msi_table rof_tables[] =
550 {
551     ADD_TABLE(rof_component),
552     ADD_TABLE(directory),
553     ADD_TABLE(rof_feature),
554     ADD_TABLE(rof_feature_comp),
555     ADD_TABLE(rof_file),
556     ADD_TABLE(install_exec_seq),
557     ADD_TABLE(rof_media),
558     ADD_TABLE(property),
559 };
560
561 static const msi_table sdp_tables[] =
562 {
563     ADD_TABLE(rof_component),
564     ADD_TABLE(directory),
565     ADD_TABLE(rof_feature),
566     ADD_TABLE(rof_feature_comp),
567     ADD_TABLE(rof_file),
568     ADD_TABLE(sdp_install_exec_seq),
569     ADD_TABLE(sdp_custom_action),
570     ADD_TABLE(rof_media),
571     ADD_TABLE(property),
572 };
573
574 static const msi_table cie_tables[] =
575 {
576     ADD_TABLE(cie_component),
577     ADD_TABLE(directory),
578     ADD_TABLE(cc_feature),
579     ADD_TABLE(cie_feature_comp),
580     ADD_TABLE(cie_file),
581     ADD_TABLE(install_exec_seq),
582     ADD_TABLE(cie_media),
583     ADD_TABLE(property),
584 };
585
586 static const msi_table ci_tables[] =
587 {
588     ADD_TABLE(ci_component),
589     ADD_TABLE(directory),
590     ADD_TABLE(rof_feature),
591     ADD_TABLE(rof_feature_comp),
592     ADD_TABLE(rof_file),
593     ADD_TABLE(ci_install_exec_seq),
594     ADD_TABLE(rof_media),
595     ADD_TABLE(property),
596     ADD_TABLE(ci_custom_action),
597 };
598
599 static const msi_table ci2_tables[] =
600 {
601     ADD_TABLE(ci2_component),
602     ADD_TABLE(directory),
603     ADD_TABLE(rof_feature),
604     ADD_TABLE(ci2_feature_comp),
605     ADD_TABLE(ci2_file),
606     ADD_TABLE(install_exec_seq),
607     ADD_TABLE(rof_media),
608     ADD_TABLE(property),
609 };
610
611 static const msi_table spf_tables[] =
612 {
613     ADD_TABLE(ci_component),
614     ADD_TABLE(directory),
615     ADD_TABLE(rof_feature),
616     ADD_TABLE(rof_feature_comp),
617     ADD_TABLE(rof_file),
618     ADD_TABLE(spf_install_exec_seq),
619     ADD_TABLE(rof_media),
620     ADD_TABLE(property),
621     ADD_TABLE(spf_custom_action),
622     ADD_TABLE(spf_install_ui_seq),
623 };
624
625 static const msi_table pp_tables[] =
626 {
627     ADD_TABLE(ci_component),
628     ADD_TABLE(directory),
629     ADD_TABLE(rof_feature),
630     ADD_TABLE(rof_feature_comp),
631     ADD_TABLE(rof_file),
632     ADD_TABLE(pp_install_exec_seq),
633     ADD_TABLE(rof_media),
634     ADD_TABLE(property),
635 };
636
637 static const msi_table tp_tables[] =
638 {
639     ADD_TABLE(tp_component),
640     ADD_TABLE(directory),
641     ADD_TABLE(rof_feature),
642     ADD_TABLE(ci2_feature_comp),
643     ADD_TABLE(ci2_file),
644     ADD_TABLE(install_exec_seq),
645     ADD_TABLE(rof_media),
646     ADD_TABLE(property),
647 };
648
649 static const msi_table cwd_tables[] =
650 {
651     ADD_TABLE(cwd_component),
652     ADD_TABLE(directory),
653     ADD_TABLE(rof_feature),
654     ADD_TABLE(ci2_feature_comp),
655     ADD_TABLE(ci2_file),
656     ADD_TABLE(install_exec_seq),
657     ADD_TABLE(rof_media),
658     ADD_TABLE(property),
659 };
660
661 static const msi_table adm_tables[] =
662 {
663     ADD_TABLE(adm_component),
664     ADD_TABLE(directory),
665     ADD_TABLE(rof_feature),
666     ADD_TABLE(ci2_feature_comp),
667     ADD_TABLE(ci2_file),
668     ADD_TABLE(install_exec_seq),
669     ADD_TABLE(rof_media),
670     ADD_TABLE(property),
671     ADD_TABLE(adm_custom_action),
672     ADD_TABLE(adm_admin_exec_seq),
673 };
674
675 static const msi_table amp_tables[] =
676 {
677     ADD_TABLE(amp_component),
678     ADD_TABLE(directory),
679     ADD_TABLE(rof_feature),
680     ADD_TABLE(ci2_feature_comp),
681     ADD_TABLE(ci2_file),
682     ADD_TABLE(install_exec_seq),
683     ADD_TABLE(rof_media),
684     ADD_TABLE(property),
685 };
686
687 /* cabinet definitions */
688
689 /* make the max size large so there is only one cab file */
690 #define MEDIA_SIZE          0x7FFFFFFF
691 #define FOLDER_THRESHOLD    900000
692
693 /* the FCI callbacks */
694
695 static void *mem_alloc(ULONG cb)
696 {
697     return HeapAlloc(GetProcessHeap(), 0, cb);
698 }
699
700 static void mem_free(void *memory)
701 {
702     HeapFree(GetProcessHeap(), 0, memory);
703 }
704
705 static BOOL get_next_cabinet(PCCAB pccab, ULONG  cbPrevCab, void *pv)
706 {
707     sprintf(pccab->szCab, pv, pccab->iCab);
708     return TRUE;
709 }
710
711 static long progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
712 {
713     return 0;
714 }
715
716 static int file_placed(PCCAB pccab, char *pszFile, long cbFile,
717                        BOOL fContinuation, void *pv)
718 {
719     return 0;
720 }
721
722 static INT_PTR fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
723 {
724     HANDLE handle;
725     DWORD dwAccess = 0;
726     DWORD dwShareMode = 0;
727     DWORD dwCreateDisposition = OPEN_EXISTING;
728     
729     dwAccess = GENERIC_READ | GENERIC_WRITE;
730     /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
731     dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
732
733     if (GetFileAttributesA(pszFile) != INVALID_FILE_ATTRIBUTES)
734         dwCreateDisposition = OPEN_EXISTING;
735     else
736         dwCreateDisposition = CREATE_NEW;
737
738     handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
739                          dwCreateDisposition, 0, NULL);
740
741     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
742
743     return (INT_PTR)handle;
744 }
745
746 static UINT fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
747 {
748     HANDLE handle = (HANDLE)hf;
749     DWORD dwRead;
750     BOOL res;
751     
752     res = ReadFile(handle, memory, cb, &dwRead, NULL);
753     ok(res, "Failed to ReadFile\n");
754
755     return dwRead;
756 }
757
758 static UINT fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
759 {
760     HANDLE handle = (HANDLE)hf;
761     DWORD dwWritten;
762     BOOL res;
763
764     res = WriteFile(handle, memory, cb, &dwWritten, NULL);
765     ok(res, "Failed to WriteFile\n");
766
767     return dwWritten;
768 }
769
770 static int fci_close(INT_PTR hf, int *err, void *pv)
771 {
772     HANDLE handle = (HANDLE)hf;
773     ok(CloseHandle(handle), "Failed to CloseHandle\n");
774
775     return 0;
776 }
777
778 static long fci_seek(INT_PTR hf, long dist, int seektype, int *err, void *pv)
779 {
780     HANDLE handle = (HANDLE)hf;
781     DWORD ret;
782     
783     ret = SetFilePointer(handle, dist, NULL, seektype);
784     ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
785
786     return ret;
787 }
788
789 static int fci_delete(char *pszFile, int *err, void *pv)
790 {
791     BOOL ret = DeleteFileA(pszFile);
792     ok(ret, "Failed to DeleteFile %s\n", pszFile);
793
794     return 0;
795 }
796
797 static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
798 {
799     CHAR buffer[0x20];
800     UINT r;
801     DWORD sz;
802
803     sz = sizeof buffer;
804     r = MsiRecordGetString(rec, field, buffer, &sz);
805     return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
806 }
807
808 static BOOL get_temp_file(char *pszTempName, int cbTempName, void *pv)
809 {
810     LPSTR tempname;
811
812     tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
813     GetTempFileNameA(".", "xx", 0, tempname);
814
815     if (tempname && (strlen(tempname) < (unsigned)cbTempName))
816     {
817         lstrcpyA(pszTempName, tempname);
818         HeapFree(GetProcessHeap(), 0, tempname);
819         return TRUE;
820     }
821
822     HeapFree(GetProcessHeap(), 0, tempname);
823
824     return FALSE;
825 }
826
827 static INT_PTR get_open_info(char *pszName, USHORT *pdate, USHORT *ptime,
828                              USHORT *pattribs, int *err, void *pv)
829 {
830     BY_HANDLE_FILE_INFORMATION finfo;
831     FILETIME filetime;
832     HANDLE handle;
833     DWORD attrs;
834     BOOL res;
835
836     handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
837                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
838
839     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
840
841     res = GetFileInformationByHandle(handle, &finfo);
842     ok(res, "Expected GetFileInformationByHandle to succeed\n");
843    
844     FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime);
845     FileTimeToDosDateTime(&filetime, pdate, ptime);
846
847     attrs = GetFileAttributes(pszName);
848     ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
849
850     return (INT_PTR)handle;
851 }
852
853 static BOOL add_file(HFCI hfci, const char *file, TCOMP compress)
854 {
855     char path[MAX_PATH];
856     char filename[MAX_PATH];
857
858     lstrcpyA(path, CURR_DIR);
859     lstrcatA(path, "\\");
860     lstrcatA(path, file);
861
862     lstrcpyA(filename, file);
863
864     return FCIAddFile(hfci, path, filename, FALSE, get_next_cabinet,
865                       progress, get_open_info, compress);
866 }
867
868 static void set_cab_parameters(PCCAB pCabParams, const CHAR *name, DWORD max_size)
869 {
870     ZeroMemory(pCabParams, sizeof(CCAB));
871
872     pCabParams->cb = max_size;
873     pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
874     pCabParams->setID = 0xbeef;
875     pCabParams->iCab = 1;
876     lstrcpyA(pCabParams->szCabPath, CURR_DIR);
877     lstrcatA(pCabParams->szCabPath, "\\");
878     lstrcpyA(pCabParams->szCab, name);
879 }
880
881 static void create_cab_file(const CHAR *name, DWORD max_size, const CHAR *files)
882 {
883     CCAB cabParams;
884     LPCSTR ptr;
885     HFCI hfci;
886     ERF erf;
887     BOOL res;
888
889     set_cab_parameters(&cabParams, name, max_size);
890
891     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
892                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
893                       get_temp_file, &cabParams, NULL);
894
895     ok(hfci != NULL, "Failed to create an FCI context\n");
896
897     ptr = files;
898     while (*ptr)
899     {
900         res = add_file(hfci, ptr, tcompTYPE_MSZIP);
901         ok(res, "Failed to add file: %s\n", ptr);
902         ptr += lstrlen(ptr) + 1;
903     }
904
905     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
906     ok(res, "Failed to flush the cabinet\n");
907
908     res = FCIDestroy(hfci);
909     ok(res, "Failed to destroy the cabinet\n");
910 }
911
912 static BOOL get_program_files_dir(LPSTR buf)
913 {
914     HKEY hkey;
915     DWORD type = REG_EXPAND_SZ, size;
916
917     if (RegOpenKey(HKEY_LOCAL_MACHINE,
918                    "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
919         return FALSE;
920
921     size = MAX_PATH;
922     if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
923         return FALSE;
924
925     RegCloseKey(hkey);
926     return TRUE;
927 }
928
929 static void create_file(const CHAR *name, DWORD size)
930 {
931     HANDLE file;
932     DWORD written, left;
933
934     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
935     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
936     WriteFile(file, name, strlen(name), &written, NULL);
937     WriteFile(file, "\n", strlen("\n"), &written, NULL);
938
939     left = size - lstrlen(name) - 1;
940
941     SetFilePointer(file, left, NULL, FILE_CURRENT);
942     SetEndOfFile(file);
943     
944     CloseHandle(file);
945 }
946
947 static void create_test_files(void)
948 {
949     CreateDirectoryA("msitest", NULL);
950     create_file("msitest\\one.txt", 100);
951     CreateDirectoryA("msitest\\first", NULL);
952     create_file("msitest\\first\\two.txt", 100);
953     CreateDirectoryA("msitest\\second", NULL);
954     create_file("msitest\\second\\three.txt", 100);
955
956     create_file("four.txt", 100);
957     create_file("five.txt", 100);
958     create_cab_file("msitest.cab", MEDIA_SIZE, "four.txt\0five.txt\0");
959
960     create_file("msitest\\filename", 100);
961     create_file("msitest\\service.exe", 100);
962
963     DeleteFileA("four.txt");
964     DeleteFileA("five.txt");
965 }
966
967 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
968 {
969     CHAR path[MAX_PATH];
970
971     lstrcpyA(path, PROG_FILES_DIR);
972     lstrcatA(path, "\\");
973     lstrcatA(path, rel_path);
974
975     if (is_file)
976         return DeleteFileA(path);
977     else
978         return RemoveDirectoryA(path);
979 }
980
981 static void delete_test_files(void)
982 {
983     DeleteFileA("msitest.msi");
984     DeleteFileA("msitest.cab");
985     DeleteFileA("msitest\\second\\three.txt");
986     DeleteFileA("msitest\\first\\two.txt");
987     DeleteFileA("msitest\\one.txt");
988     DeleteFileA("msitest\\service.exe");
989     DeleteFileA("msitest\\filename");
990     RemoveDirectoryA("msitest\\second");
991     RemoveDirectoryA("msitest\\first");
992     RemoveDirectoryA("msitest");
993 }
994
995 static void write_file(const CHAR *filename, const char *data, int data_size)
996 {
997     DWORD size;
998
999     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1000                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1001
1002     WriteFile(hf, data, data_size, &size, NULL);
1003     CloseHandle(hf);
1004 }
1005
1006 static void write_msi_summary_info(MSIHANDLE db)
1007 {
1008     MSIHANDLE summary;
1009     UINT r;
1010
1011     r = MsiGetSummaryInformationA(db, NULL, 5, &summary);
1012     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1013
1014     r = MsiSummaryInfoSetPropertyA(summary, PID_TEMPLATE, VT_LPSTR, 0, NULL, ";1033");
1015     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1016
1017     r = MsiSummaryInfoSetPropertyA(summary, PID_REVNUMBER, VT_LPSTR, 0, NULL,
1018                                    "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
1019     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1020
1021     r = MsiSummaryInfoSetPropertyA(summary, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
1022     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1023
1024     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 0, NULL, NULL);
1025     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1026
1027     r = MsiSummaryInfoSetPropertyA(summary, PID_TITLE, VT_LPSTR, 0, NULL, "MSITEST");
1028     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1029
1030     /* write the summary changes back to the stream */
1031     r = MsiSummaryInfoPersist(summary);
1032     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1033
1034     MsiCloseHandle(summary);
1035 }
1036
1037 static void create_database(const CHAR *name, const msi_table *tables, int num_tables)
1038 {
1039     MSIHANDLE db;
1040     UINT r;
1041     int j;
1042
1043     r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
1044     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1045
1046     /* import the tables into the database */
1047     for (j = 0; j < num_tables; j++)
1048     {
1049         const msi_table *table = &tables[j];
1050
1051         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
1052
1053         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
1054         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1055
1056         DeleteFileA(table->filename);
1057     }
1058
1059     write_msi_summary_info(db);
1060
1061     r = MsiDatabaseCommit(db);
1062     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1063
1064     MsiCloseHandle(db);
1065 }
1066
1067 static void check_service_is_installed(void)
1068 {
1069     SC_HANDLE scm, service;
1070     BOOL res;
1071
1072     scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
1073     ok(scm != NULL, "Failed to open the SC Manager\n");
1074
1075     service = OpenService(scm, "TestService", SC_MANAGER_ALL_ACCESS);
1076     ok(service != NULL, "Failed to open TestService\n");
1077
1078     res = DeleteService(service);
1079     ok(res, "Failed to delete TestService\n");
1080 }
1081
1082 static void test_MsiInstallProduct(void)
1083 {
1084     UINT r;
1085     CHAR path[MAX_PATH];
1086     LONG res;
1087     HKEY hkey;
1088     DWORD num, size, type;
1089
1090     create_test_files();
1091     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1092
1093     r = MsiInstallProductA(msifile, NULL);
1094     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1095
1096     ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
1097     ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
1098     ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
1099     ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
1100     ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
1101     ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
1102     ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
1103     ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
1104     ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
1105     ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
1106     ok(delete_pf("msitest\\service.exe", TRUE), "File not installed\n");
1107     ok(delete_pf("msitest", FALSE), "File not installed\n");
1108
1109     res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
1110     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
1111
1112     size = MAX_PATH;
1113     type = REG_SZ;
1114     res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
1115     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
1116     ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
1117
1118     size = MAX_PATH;
1119     type = REG_SZ;
1120     res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
1121     ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
1122
1123     size = sizeof(num);
1124     type = REG_DWORD;
1125     res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
1126     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
1127     ok(num == 314, "Expected 314, got %d\n", num);
1128
1129     size = MAX_PATH;
1130     type = REG_SZ;
1131     res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
1132     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
1133     ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
1134
1135     check_service_is_installed();
1136
1137     RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
1138
1139     delete_test_files();
1140 }
1141
1142 static void test_MsiSetComponentState(void)
1143 {
1144     INSTALLSTATE installed, action;
1145     MSIHANDLE package;
1146     char path[MAX_PATH];
1147     UINT r;
1148
1149     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1150
1151     CoInitialize(NULL);
1152
1153     lstrcpy(path, CURR_DIR);
1154     lstrcat(path, "\\");
1155     lstrcat(path, msifile);
1156
1157     r = MsiOpenPackage(path, &package);
1158     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1159
1160     r = MsiDoAction(package, "CostInitialize");
1161     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1162
1163     r = MsiDoAction(package, "FileCost");
1164     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1165
1166     r = MsiDoAction(package, "CostFinalize");
1167     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1168
1169     r = MsiGetComponentState(package, "dangler", &installed, &action);
1170     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1171     ok(installed == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", installed);
1172     ok(action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
1173
1174     r = MsiSetComponentState(package, "dangler", INSTALLSTATE_SOURCE);
1175     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1176
1177     MsiCloseHandle(package);
1178     CoUninitialize();
1179
1180     DeleteFileA(msifile);
1181 }
1182
1183 static void test_packagecoltypes(void)
1184 {
1185     MSIHANDLE hdb, view, rec;
1186     char path[MAX_PATH];
1187     LPCSTR query;
1188     UINT r, count;
1189
1190     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1191
1192     CoInitialize(NULL);
1193
1194     lstrcpy(path, CURR_DIR);
1195     lstrcat(path, "\\");
1196     lstrcat(path, msifile);
1197
1198     r = MsiOpenDatabase(path, MSIDBOPEN_READONLY, &hdb);
1199     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1200
1201     query = "SELECT * FROM `Media`";
1202     r = MsiDatabaseOpenView( hdb, query, &view );
1203     ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1204
1205     r = MsiViewGetColumnInfo( view, MSICOLINFO_NAMES, &rec );
1206     count = MsiRecordGetFieldCount( rec );
1207     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
1208     ok(count == 6, "Expected 6, got %d\n", count);
1209     ok(check_record(rec, 1, "DiskId"), "wrong column label\n");
1210     ok(check_record(rec, 2, "LastSequence"), "wrong column label\n");
1211     ok(check_record(rec, 3, "DiskPrompt"), "wrong column label\n");
1212     ok(check_record(rec, 4, "Cabinet"), "wrong column label\n");
1213     ok(check_record(rec, 5, "VolumeLabel"), "wrong column label\n");
1214     ok(check_record(rec, 6, "Source"), "wrong column label\n");
1215     MsiCloseHandle(rec);
1216
1217     r = MsiViewGetColumnInfo( view, MSICOLINFO_TYPES, &rec );
1218     count = MsiRecordGetFieldCount( rec );
1219     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
1220     ok(count == 6, "Expected 6, got %d\n", count);
1221     ok(check_record(rec, 1, "i2"), "wrong column label\n");
1222     ok(check_record(rec, 2, "i4"), "wrong column label\n");
1223     ok(check_record(rec, 3, "L64"), "wrong column label\n");
1224     ok(check_record(rec, 4, "S255"), "wrong column label\n");
1225     ok(check_record(rec, 5, "S32"), "wrong column label\n");
1226     ok(check_record(rec, 6, "S72"), "wrong column label\n");
1227
1228     MsiCloseHandle(rec);
1229     MsiCloseHandle(view);
1230     MsiCloseHandle(hdb);
1231     DeleteFile(msifile);
1232 }
1233
1234 static void create_cc_test_files(void)
1235 {
1236     CCAB cabParams;
1237     HFCI hfci;
1238     ERF erf;
1239     static CHAR cab_context[] = "test%d.cab";
1240     BOOL res;
1241
1242     create_file("maximus", 500);
1243     create_file("augustus", 50000);
1244     create_file("caesar", 500);
1245
1246     set_cab_parameters(&cabParams, "test1.cab", 200);
1247
1248     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
1249                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
1250                       get_temp_file, &cabParams, cab_context);
1251     ok(hfci != NULL, "Failed to create an FCI context\n");
1252
1253     res = add_file(hfci, "maximus", tcompTYPE_MSZIP);
1254     ok(res, "Failed to add file maximus\n");
1255
1256     res = add_file(hfci, "augustus", tcompTYPE_MSZIP);
1257     ok(res, "Failed to add file augustus\n");
1258
1259     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
1260     ok(res, "Failed to flush the cabinet\n");
1261
1262     res = FCIDestroy(hfci);
1263     ok(res, "Failed to destroy the cabinet\n");
1264
1265     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1266
1267     DeleteFile("maximus");
1268     DeleteFile("augustus");
1269     DeleteFile("caesar");
1270 }
1271
1272 static void delete_cab_files(void)
1273 {
1274     SHFILEOPSTRUCT shfl;
1275     CHAR path[MAX_PATH+10];
1276
1277     lstrcpyA(path, CURR_DIR);
1278     lstrcatA(path, "\\*.cab");
1279     path[strlen(path) + 1] = '\0';
1280
1281     shfl.hwnd = NULL;
1282     shfl.wFunc = FO_DELETE;
1283     shfl.pFrom = path;
1284     shfl.pTo = NULL;
1285     shfl.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_NORECURSION | FOF_SILENT;
1286
1287     SHFileOperation(&shfl);
1288 }
1289
1290 static void test_continuouscabs(void)
1291 {
1292     UINT r;
1293
1294     create_cc_test_files();
1295     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
1296
1297     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1298
1299     r = MsiInstallProductA(msifile, NULL);
1300     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1301     todo_wine
1302     {
1303         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1304         ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1305         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1306     }
1307     ok(delete_pf("msitest", FALSE), "File not installed\n");
1308
1309     delete_cab_files();
1310     DeleteFile(msifile);
1311 }
1312
1313 static void test_caborder(void)
1314 {
1315     UINT r;
1316
1317     create_file("imperator", 100);
1318     create_file("maximus", 500);
1319     create_file("augustus", 50000);
1320     create_file("caesar", 500);
1321
1322     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
1323
1324     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1325
1326     create_cab_file("test1.cab", MEDIA_SIZE, "maximus\0");
1327     create_cab_file("test2.cab", MEDIA_SIZE, "augustus\0");
1328     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1329
1330     r = MsiInstallProductA(msifile, NULL);
1331     ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1332     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1333     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1334     todo_wine
1335     {
1336         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1337         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1338     }
1339
1340     delete_cab_files();
1341
1342     create_cab_file("test1.cab", MEDIA_SIZE, "imperator\0");
1343     create_cab_file("test2.cab", MEDIA_SIZE, "maximus\0augustus\0");
1344     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1345
1346     r = MsiInstallProductA(msifile, NULL);
1347     ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1348     ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1349     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1350     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1351     todo_wine
1352     {
1353         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1354     }
1355
1356     delete_cab_files();
1357     DeleteFile(msifile);
1358
1359     create_cc_test_files();
1360     create_database(msifile, co_tables, sizeof(co_tables) / sizeof(msi_table));
1361
1362     r = MsiInstallProductA(msifile, NULL);
1363     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1364     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1365     ok(!delete_pf("msitest", FALSE), "File is installed\n");
1366     todo_wine
1367     {
1368         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1369         ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1370     }
1371
1372     delete_cab_files();
1373     DeleteFile(msifile);
1374
1375     create_cc_test_files();
1376     create_database(msifile, co2_tables, sizeof(co2_tables) / sizeof(msi_table));
1377
1378     r = MsiInstallProductA(msifile, NULL);
1379     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1380     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1381     todo_wine
1382     {
1383         ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1384         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1385         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1386     }
1387
1388     delete_cab_files();
1389     DeleteFile("imperator");
1390     DeleteFile("maximus");
1391     DeleteFile("augustus");
1392     DeleteFile("caesar");
1393     DeleteFile(msifile);
1394 }
1395
1396 static void test_mixedmedia(void)
1397 {
1398     UINT r;
1399
1400     CreateDirectoryA("msitest", NULL);
1401     create_file("msitest\\maximus", 500);
1402     create_file("msitest\\augustus", 500);
1403     create_file("caesar", 500);
1404
1405     create_database(msifile, mm_tables, sizeof(mm_tables) / sizeof(msi_table));
1406
1407     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1408
1409     create_cab_file("test1.cab", MEDIA_SIZE, "caesar\0");
1410
1411     r = MsiInstallProductA(msifile, NULL);
1412     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1413     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1414     ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1415     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1416     ok(delete_pf("msitest", FALSE), "File not installed\n");
1417
1418     /* Delete the files in the temp (current) folder */
1419     DeleteFile("msitest\\maximus");
1420     DeleteFile("msitest\\augustus");
1421     RemoveDirectory("msitest");
1422     DeleteFile("caesar");
1423     DeleteFile("test1.cab");
1424     DeleteFile(msifile);
1425 }
1426
1427 static void test_samesequence(void)
1428 {
1429     UINT r;
1430
1431     create_cc_test_files();
1432     create_database(msifile, ss_tables, sizeof(ss_tables) / sizeof(msi_table));
1433
1434     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1435
1436     r = MsiInstallProductA(msifile, NULL);
1437     todo_wine
1438     {
1439         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1440         ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1441         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1442     }
1443     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1444     ok(delete_pf("msitest", FALSE), "File not installed\n");
1445
1446     delete_cab_files();
1447     DeleteFile(msifile);
1448 }
1449
1450 static void test_uiLevelFlags(void)
1451 {
1452     UINT r;
1453
1454     create_cc_test_files();
1455     create_database(msifile, ui_tables, sizeof(ui_tables) / sizeof(msi_table));
1456
1457     MsiSetInternalUI(INSTALLUILEVEL_NONE | INSTALLUILEVEL_SOURCERESONLY, NULL);
1458
1459     r = MsiInstallProductA(msifile, NULL);
1460     ok(!delete_pf("msitest\\maximus", TRUE), "UI install occurred, but execute-only was requested.\n");
1461     todo_wine
1462     {
1463         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1464         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1465     }
1466     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1467     ok(delete_pf("msitest", FALSE), "File not installed\n");
1468
1469     delete_cab_files();
1470     DeleteFile(msifile);
1471 }
1472
1473 static BOOL file_matches(LPSTR path)
1474 {
1475     CHAR buf[MAX_PATH];
1476     HANDLE file;
1477     DWORD size;
1478
1479     file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
1480                       NULL, OPEN_EXISTING, 0, NULL);
1481
1482     ZeroMemory(buf, MAX_PATH);
1483     ReadFile(file, buf, 15, &size, NULL);
1484     CloseHandle(file);
1485
1486     return !lstrcmp(buf, "msitest\\maximus");
1487 }
1488
1489 static void test_readonlyfile(void)
1490 {
1491     UINT r;
1492     DWORD size;
1493     HANDLE file;
1494     CHAR path[MAX_PATH];
1495
1496     CreateDirectoryA("msitest", NULL);
1497     create_file("msitest\\maximus", 500);
1498     create_database(msifile, rof_tables, sizeof(rof_tables) / sizeof(msi_table));
1499
1500     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1501
1502     lstrcpy(path, PROG_FILES_DIR);
1503     lstrcat(path, "\\msitest");
1504     CreateDirectory(path, NULL);
1505
1506     lstrcat(path, "\\maximus");
1507     file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
1508                       NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
1509
1510     WriteFile(file, "readonlyfile", 20, &size, NULL);
1511     CloseHandle(file);
1512
1513     r = MsiInstallProductA(msifile, NULL);
1514     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1515     ok(file_matches(path), "Expected file to be overwritten\n");
1516     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1517     ok(delete_pf("msitest", FALSE), "File not installed\n");
1518
1519     /* Delete the files in the temp (current) folder */
1520     DeleteFile("msitest\\maximus");
1521     RemoveDirectory("msitest");
1522     DeleteFile(msifile);
1523 }
1524
1525 static void test_setdirproperty(void)
1526 {
1527     UINT r;
1528
1529     CreateDirectoryA("msitest", NULL);
1530     create_file("msitest\\maximus", 500);
1531     create_database(msifile, sdp_tables, sizeof(sdp_tables) / sizeof(msi_table));
1532
1533     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1534
1535     r = MsiInstallProductA(msifile, NULL);
1536     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1537     ok(delete_pf("Common Files\\msitest\\maximus", TRUE), "File not installed\n");
1538     ok(delete_pf("Common Files\\msitest", FALSE), "File not installed\n");
1539
1540     /* Delete the files in the temp (current) folder */
1541     DeleteFile(msifile);
1542     DeleteFile("msitest\\maximus");
1543     RemoveDirectory("msitest");
1544 }
1545
1546 static void test_cabisextracted(void)
1547 {
1548     UINT r;
1549
1550     CreateDirectoryA("msitest", NULL);
1551     create_file("msitest\\gaius", 500);
1552     create_file("maximus", 500);
1553     create_file("augustus", 500);
1554     create_file("caesar", 500);
1555
1556     create_cab_file("test1.cab", MEDIA_SIZE, "maximus\0");
1557     create_cab_file("test2.cab", MEDIA_SIZE, "augustus\0");
1558     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1559
1560     create_database(msifile, cie_tables, sizeof(cie_tables) / sizeof(msi_table));
1561
1562     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1563
1564     r = MsiInstallProductA(msifile, NULL);
1565     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1566     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1567     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1568     ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1569     ok(delete_pf("msitest\\gaius", TRUE), "File not installed\n");
1570     ok(delete_pf("msitest", FALSE), "File not installed\n");
1571
1572     /* Delete the files in the temp (current) folder */
1573     delete_cab_files();
1574     DeleteFile(msifile);
1575     DeleteFile("maximus");
1576     DeleteFile("augustus");
1577     DeleteFile("caesar");
1578     DeleteFile("msitest\\gaius");
1579     RemoveDirectory("msitest");
1580 }
1581
1582 static void test_concurrentinstall(void)
1583 {
1584     UINT r;
1585     CHAR path[MAX_PATH];
1586
1587     CreateDirectoryA("msitest", NULL);
1588     CreateDirectoryA("msitest\\msitest", NULL);
1589     create_file("msitest\\maximus", 500);
1590     create_file("msitest\\msitest\\augustus", 500);
1591
1592     create_database(msifile, ci_tables, sizeof(ci_tables) / sizeof(msi_table));
1593
1594     lstrcpyA(path, CURR_DIR);
1595     lstrcatA(path, "\\msitest\\concurrent.msi");
1596     create_database(path, ci2_tables, sizeof(ci2_tables) / sizeof(msi_table));
1597
1598     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
1599
1600     r = MsiInstallProductA(msifile, NULL);
1601     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1602     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1603     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1604     ok(delete_pf("msitest", FALSE), "File not installed\n");
1605
1606     /* Delete the files in the temp (current) folder */
1607     DeleteFile(msifile);
1608     DeleteFile(path);
1609     DeleteFile("msitest\\msitest\\augustus");
1610     DeleteFile("msitest\\maximus");
1611     RemoveDirectory("msitest\\msitest");
1612     RemoveDirectory("msitest");
1613 }
1614
1615 static void test_setpropertyfolder(void)
1616 {
1617     UINT r;
1618
1619     CreateDirectoryA("msitest", NULL);
1620     create_file("msitest\\maximus", 500);
1621
1622     create_database(msifile, spf_tables, sizeof(spf_tables) / sizeof(msi_table));
1623
1624     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
1625
1626     r = MsiInstallProductA(msifile, NULL);
1627     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1628     ok(delete_pf("msitest\\added\\maximus", TRUE), "File not installed\n");
1629     ok(delete_pf("msitest\\added", FALSE), "File not installed\n");
1630     ok(delete_pf("msitest", FALSE), "File not installed\n");
1631
1632     /* Delete the files in the temp (current) folder */
1633     DeleteFile(msifile);
1634     DeleteFile("msitest\\maximus");
1635     RemoveDirectory("msitest");
1636 }
1637
1638 static BOOL file_exists(LPCSTR file)
1639 {
1640     return GetFileAttributes(file) != INVALID_FILE_ATTRIBUTES;
1641 }
1642
1643 static BOOL pf_exists(LPCSTR file)
1644 {
1645     CHAR path[MAX_PATH];
1646
1647     lstrcpyA(path, PROG_FILES_DIR);
1648     lstrcatA(path, "\\");
1649     lstrcatA(path, file);
1650
1651     return file_exists(path);
1652 }
1653
1654 static void delete_pfmsitest_files(void)
1655 {
1656     SHFILEOPSTRUCT shfl;
1657     CHAR path[MAX_PATH+10];
1658
1659     lstrcpyA(path, PROG_FILES_DIR);
1660     lstrcatA(path, "\\msitest\\*");
1661     path[strlen(path) + 1] = '\0';
1662
1663     shfl.hwnd = NULL;
1664     shfl.wFunc = FO_DELETE;
1665     shfl.pFrom = path;
1666     shfl.pTo = NULL;
1667     shfl.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_NORECURSION | FOF_SILENT;
1668
1669     SHFileOperation(&shfl);
1670
1671     lstrcpyA(path, PROG_FILES_DIR);
1672     lstrcatA(path, "\\msitest");
1673     RemoveDirectoryA(path);
1674 }
1675
1676 static void test_publish(void)
1677 {
1678     UINT r;
1679     INSTALLSTATE state;
1680     CHAR prodcode[] = "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}";
1681
1682     CreateDirectoryA("msitest", NULL);
1683     create_file("msitest\\maximus", 500);
1684
1685     create_database(msifile, pp_tables, sizeof(pp_tables) / sizeof(msi_table));
1686
1687     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
1688
1689     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1690     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1691
1692     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1693     if (state != INSTALLSTATE_UNKNOWN)
1694     {
1695         skip("Install database not in a clean state\n");
1696         return;
1697     }
1698
1699     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1700
1701     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1702     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1703
1704     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1705                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1706     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1707     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1708
1709     /* nothing published */
1710     r = MsiInstallProductA(msifile, NULL);
1711     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1712     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1713     ok(pf_exists("msitest"), "File not installed\n");
1714
1715     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1716     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1717
1718     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1719     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1720
1721     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1722     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1723
1724     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1725                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1726     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1727     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1728
1729     /* install again */
1730     r = MsiInstallProductA(msifile, NULL);
1731     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1732     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1733     ok(pf_exists("msitest"), "File not installed\n");
1734
1735     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1736     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1737
1738     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1739     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1740
1741     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1742     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1743
1744     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1745                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1746     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1747     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1748
1749     /* try to uninstall */
1750     r = MsiInstallProductA(msifile, "REMOVE=ALL");
1751     todo_wine
1752     {
1753         ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1754     }
1755     ok(pf_exists("msitest\\maximus"), "File deleted\n");
1756     ok(pf_exists("msitest"), "File deleted\n");
1757
1758     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1759     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1760
1761     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1762     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1763
1764     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1765     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1766
1767     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1768                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1769     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1770     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1771
1772     /* PublishProduct */
1773     r = MsiInstallProductA(msifile, "PUBLISH_PRODUCT=1");
1774     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1775     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1776     ok(pf_exists("msitest"), "File not installed\n");
1777
1778     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1779     ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1780
1781     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1782     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1783
1784     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1785                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1786     todo_wine
1787     {
1788         ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
1789     }
1790     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1791
1792     /* try to uninstall after PublishProduct */
1793     r = MsiInstallProductA(msifile, "REMOVE=ALL");
1794     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1795     ok(pf_exists("msitest\\maximus"), "File deleted\n");
1796     ok(pf_exists("msitest"), "File deleted\n");
1797
1798     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1799     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1800
1801     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1802     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1803
1804     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1805     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1806
1807     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1808                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1809     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1810     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1811
1812     /* PublishProduct and RegisterProduct */
1813     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1");
1814     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1815     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1816     ok(pf_exists("msitest"), "File not installed\n");
1817
1818     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1819     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1820
1821     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1822     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1823
1824     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1825     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1826
1827     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1828                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1829     todo_wine
1830     {
1831         ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
1832     }
1833     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1834
1835     /* try it again */
1836     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1");
1837     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1838     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1839     ok(pf_exists("msitest"), "File not installed\n");
1840
1841     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1842     todo_wine
1843     {
1844         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1845     }
1846
1847     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1848     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1849
1850     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1851     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1852
1853     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1854                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1855     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1856     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1857
1858     /* uninstall has a problem with this */
1859     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
1860     todo_wine
1861     {
1862         ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1863     }
1864     ok(pf_exists("msitest\\maximus"), "File deleted\n");
1865     ok(pf_exists("msitest"), "File deleted\n");
1866
1867     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1868     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1869
1870     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1871     todo_wine
1872     {
1873         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1874     }
1875
1876     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1877                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1878     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1879     todo_wine
1880     {
1881         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1882     }
1883
1884     /* PublishProduct and RegisterProduct and ProcessComponents */
1885     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1 PROCESS_COMPONENTS=1");
1886     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1887     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1888     ok(pf_exists("msitest"), "File not installed\n");
1889
1890     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1891     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1892
1893     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1894     todo_wine
1895     {
1896         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1897     }
1898
1899     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1900     todo_wine
1901     {
1902         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1903     }
1904
1905     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1906                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1907     todo_wine
1908     {
1909         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1910         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1911     }
1912
1913     /* complete uninstall */
1914     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
1915     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1916     ok(pf_exists("msitest\\maximus"), "File deleted\n");
1917     ok(pf_exists("msitest"), "File deleted\n");
1918
1919     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1920     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1921
1922     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1923     todo_wine
1924     {
1925         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1926     }
1927
1928     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1929     todo_wine
1930     {
1931         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1932     }
1933
1934     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1935                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1936     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1937     todo_wine
1938     {
1939         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1940     }
1941
1942     /* PublishProduct, RegisterProduct, ProcessComponents, PublishFeatures */
1943     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1 PROCESS_COMPONENTS=1 PUBLISH_FEATURES=1");
1944     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1945     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1946     ok(pf_exists("msitest"), "File not installed\n");
1947
1948     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1949     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1950
1951     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1952     todo_wine
1953     {
1954         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1955     }
1956
1957     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1958     todo_wine
1959     {
1960         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1961     }
1962
1963     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1964                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1965     todo_wine
1966     {
1967         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1968         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1969     }
1970
1971     /* complete uninstall */
1972     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
1973     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1974     todo_wine
1975     {
1976         ok(!pf_exists("msitest\\maximus"), "File deleted\n");
1977         ok(!pf_exists("msitest"), "File deleted\n");
1978     }
1979
1980     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1981     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1982
1983     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");\
1984     todo_wine
1985     {
1986         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1987     }
1988
1989     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1990     todo_wine
1991     {
1992         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1993     }
1994
1995     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1996                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1997     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1998     todo_wine
1999     {
2000         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2001     }
2002
2003     /* complete install */
2004     r = MsiInstallProductA(msifile, "FULL=1");
2005     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2006     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2007     ok(pf_exists("msitest"), "File not installed\n");
2008
2009     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2010     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2011
2012     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2013     todo_wine
2014     {
2015         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2016     }
2017
2018     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2019     todo_wine
2020     {
2021         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2022     }
2023
2024     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2025                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2026     todo_wine
2027     {
2028         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2029         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2030     }
2031
2032     /* no UnpublishFeatures */
2033     r = MsiInstallProductA(msifile, "REMOVE=ALL");
2034     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2035     todo_wine
2036     {
2037         ok(!pf_exists("msitest\\maximus"), "File deleted\n");
2038         ok(!pf_exists("msitest"), "File deleted\n");
2039     }
2040
2041     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2042     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2043
2044     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2045     todo_wine
2046     {
2047         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2048     }
2049
2050     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2051     todo_wine
2052     {
2053         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2054     }
2055
2056     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2057                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2058     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2059     todo_wine
2060     {
2061         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2062     }
2063
2064     /* complete install */
2065     r = MsiInstallProductA(msifile, "FULL=1");
2066     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2067     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2068     ok(pf_exists("msitest"), "File not installed\n");
2069
2070     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2071     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2072
2073     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2074     todo_wine
2075     {
2076         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2077     }
2078
2079     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2080     todo_wine
2081     {
2082         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2083     }
2084
2085     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2086                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2087     todo_wine
2088     {
2089         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2090         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2091     }
2092
2093     /* UnpublishFeatures, only feature removed.  Only works when entire product is removed */
2094     r = MsiInstallProductA(msifile, "UNPUBLISH_FEATURES=1 REMOVE=feature");
2095     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2096     ok(pf_exists("msitest\\maximus"), "File deleted\n");
2097     ok(pf_exists("msitest"), "File deleted\n");
2098
2099     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2100     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2101
2102     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2103     todo_wine
2104     {
2105         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2106     }
2107
2108     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2109     todo_wine
2110     {
2111         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2112     }
2113
2114     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2115                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2116     todo_wine
2117     {
2118         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2119         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2120     }
2121
2122     /* complete install */
2123     r = MsiInstallProductA(msifile, "FULL=1");
2124     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2125     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2126     ok(pf_exists("msitest"), "File not installed\n");
2127
2128     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2129     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2130
2131     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2132     todo_wine
2133     {
2134         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2135     }
2136
2137     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2138     todo_wine
2139     {
2140         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2141     }
2142
2143     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2144                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2145     todo_wine
2146     {
2147         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2148         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2149     }
2150
2151     /* UnpublishFeatures, both features removed */
2152     r = MsiInstallProductA(msifile, "UNPUBLISH_FEATURES=1 REMOVE=feature,montecristo");
2153     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2154     todo_wine
2155     {
2156         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2157         ok(!pf_exists("msitest"), "File not deleted\n");
2158     }
2159
2160     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2161     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2162
2163     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2164     todo_wine
2165     {
2166         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2167     }
2168
2169     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2170     todo_wine
2171     {
2172         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2173     }
2174
2175     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2176                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2177     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2178     todo_wine
2179     {
2180         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2181     }
2182
2183     /* complete install */
2184     r = MsiInstallProductA(msifile, "FULL=1");
2185     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2186     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2187     ok(pf_exists("msitest"), "File not installed\n");
2188
2189     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2190     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2191
2192     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2193     todo_wine
2194     {
2195         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2196     }
2197
2198     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2199     todo_wine
2200     {
2201         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2202     }
2203
2204     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2205                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2206     todo_wine
2207     {
2208         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2209         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2210     }
2211
2212     /* complete uninstall */
2213     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
2214     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2215     todo_wine
2216     {
2217         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2218         ok(!pf_exists("msitest"), "File not deleted\n");
2219     }
2220
2221     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2222     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2223
2224     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2225     todo_wine
2226     {
2227         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2228     }
2229
2230     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2231     todo_wine
2232     {
2233         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2234     }
2235
2236     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2237                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2238     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2239     todo_wine
2240     {
2241         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2242     }
2243
2244     /* make sure 'Program Files\msitest' is removed */
2245     delete_pfmsitest_files();
2246
2247     DeleteFile(msifile);
2248     DeleteFile("msitest\\maximus");
2249     RemoveDirectory("msitest");
2250 }
2251
2252 static void test_publishsourcelist(void)
2253 {
2254     UINT r;
2255     DWORD size;
2256     CHAR value[MAX_PATH];
2257     CHAR prodcode[] = "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}";
2258
2259     CreateDirectoryA("msitest", NULL);
2260     create_file("msitest\\maximus", 500);
2261
2262     create_database(msifile, pp_tables, sizeof(pp_tables) / sizeof(msi_table));
2263
2264     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
2265
2266     r = MsiInstallProductA(msifile, NULL);
2267     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2268     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2269     ok(pf_exists("msitest"), "File not installed\n");
2270
2271     /* nothing published */
2272     size = 0xdeadbeef;
2273     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2274                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2275     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2276     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2277
2278     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1");
2279     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2280     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2281     ok(pf_exists("msitest"), "File not installed\n");
2282
2283     /* after RegisterProduct */
2284     size = 0xdeadbeef;
2285     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2286                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2287     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2288     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2289
2290     r = MsiInstallProductA(msifile, "PROCESS_COMPONENTS=1");
2291     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2292     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2293     ok(pf_exists("msitest"), "File not installed\n");
2294
2295     /* after ProcessComponents */
2296     size = 0xdeadbeef;
2297     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2298                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2299     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2300     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2301
2302     r = MsiInstallProductA(msifile, "PUBLISH_FEATURES=1");
2303     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2304     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2305     ok(pf_exists("msitest"), "File not installed\n");
2306
2307     /* after PublishFeatures */
2308     size = 0xdeadbeef;
2309     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2310                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2311     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2312     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2313
2314     r = MsiInstallProductA(msifile, "PUBLISH_PRODUCT=1");
2315     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2316     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2317     ok(pf_exists("msitest"), "File not installed\n");
2318
2319     /* after PublishProduct */
2320     size = MAX_PATH;
2321     lstrcpyA(value, "aaa");
2322     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2323                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, value, &size);
2324     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2325     ok(!lstrcmpA(value, "msitest.msi"), "Expected 'msitest.msi', got %s\n", value);
2326     ok(size == 11, "Expected 11, got %d\n", size);
2327
2328     /* complete uninstall */
2329     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
2330     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2331     todo_wine
2332     {
2333         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2334         ok(!pf_exists("msitest"), "File not deleted\n");
2335     }
2336
2337     /* make sure 'Program Files\msitest' is removed */
2338     delete_pfmsitest_files();
2339
2340     DeleteFile(msifile);
2341     DeleteFile("msitest\\maximus");
2342     RemoveDirectory("msitest");
2343 }
2344
2345 static UINT run_query(MSIHANDLE hdb, MSIHANDLE hrec, const char *query)
2346 {
2347     MSIHANDLE hview = 0;
2348     UINT r;
2349
2350     r = MsiDatabaseOpenView(hdb, query, &hview);
2351     if(r != ERROR_SUCCESS)
2352         return r;
2353
2354     r = MsiViewExecute(hview, hrec);
2355     if(r == ERROR_SUCCESS)
2356         r = MsiViewClose(hview);
2357     MsiCloseHandle(hview);
2358     return r;
2359 }
2360
2361 static void set_transform_summary_info(void)
2362 {
2363     UINT r;
2364     MSIHANDLE suminfo;
2365
2366     /* build summmary info */
2367     r = MsiGetSummaryInformation(0, mstfile, 3, &suminfo);
2368     todo_wine
2369     {
2370         ok(r == ERROR_SUCCESS , "Failed to open summaryinfo\n");
2371     }
2372
2373     r = MsiSummaryInfoSetProperty(suminfo, PID_TITLE, VT_LPSTR, 0, NULL, "MSITEST");
2374     todo_wine
2375     {
2376         ok(r == ERROR_SUCCESS, "Failed to set summary info\n");
2377     }
2378
2379     r = MsiSummaryInfoSetProperty(suminfo, PID_REVNUMBER, VT_LPSTR, 0, NULL,
2380                         "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}1.1.1;"
2381                         "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}1.1.1;"
2382                         "{4C0EAA15-0264-4E5A-8758-609EF142B92D}");
2383     todo_wine
2384     {
2385         ok(r == ERROR_SUCCESS , "Failed to set summary info\n");
2386     }
2387
2388     r = MsiSummaryInfoSetProperty(suminfo, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
2389     todo_wine
2390     {
2391         ok(r == ERROR_SUCCESS, "Failed to set summary info\n");
2392     }
2393
2394     r = MsiSummaryInfoPersist(suminfo);
2395     todo_wine
2396     {
2397         ok(r == ERROR_SUCCESS , "Failed to make summary info persist\n");
2398     }
2399
2400     r = MsiCloseHandle(suminfo);
2401     todo_wine
2402     {
2403         ok(r == ERROR_SUCCESS , "Failed to close suminfo\n");
2404     }
2405 }
2406
2407 static void generate_transform(void)
2408 {
2409     MSIHANDLE hdb1, hdb2;
2410     LPCSTR query;
2411     UINT r;
2412
2413     /* start with two identical databases */
2414     CopyFile(msifile, msifile2, FALSE);
2415
2416     r = MsiOpenDatabase(msifile2, MSIDBOPEN_TRANSACT, &hdb1);
2417     ok(r == ERROR_SUCCESS , "Failed to create database\n");
2418
2419     r = MsiDatabaseCommit(hdb1);
2420     ok(r == ERROR_SUCCESS , "Failed to commit database\n");
2421
2422     r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb2);
2423     ok(r == ERROR_SUCCESS , "Failed to create database\n");
2424
2425     query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2426     r = run_query(hdb1, 0, query);
2427     ok(r == ERROR_SUCCESS, "failed to add property\n");
2428
2429     /* database needs to be committed */
2430     MsiDatabaseCommit(hdb1);
2431
2432     r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2433     ok(r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r);
2434
2435 #if 0  /* not implemented in wine yet */
2436     r = MsiCreateTransformSummaryInfo(hdb2, hdb2, mstfile, 0, 0);
2437     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2438 #endif
2439
2440     MsiCloseHandle(hdb1);
2441     MsiCloseHandle(hdb2);
2442 }
2443
2444 /* data for generating a transform */
2445
2446 /* tables transform names - encoded as they would be in an msi database file */
2447 static const WCHAR name1[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2448 static const WCHAR name2[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2449 static const WCHAR name3[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2450
2451 /* data in each table */
2452 static const char data1[] = /* _StringData */
2453     "propval";  /* all the strings squashed together */
2454
2455 static const WCHAR data2[] = { /* _StringPool */
2456 /*  len, refs */
2457     0,   0,    /* string 0 ''     */
2458     4,   1,    /* string 1 'prop' */
2459     3,   1,    /* string 2 'val'  */
2460 };
2461
2462 static const WCHAR data3[] = { /* Property */
2463     0x0201, 0x0001, 0x0002,
2464 };
2465
2466 static const struct {
2467     LPCWSTR name;
2468     const void *data;
2469     DWORD size;
2470 } table_transform_data[] =
2471 {
2472     { name1, data1, sizeof data1 - 1 },
2473     { name2, data2, sizeof data2 },
2474     { name3, data3, sizeof data3 },
2475 };
2476
2477 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2478
2479 static void generate_transform_manual(void)
2480 {
2481     IStorage *stg = NULL;
2482     IStream *stm;
2483     WCHAR name[0x20];
2484     HRESULT r;
2485     DWORD i, count;
2486     const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2487
2488     const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2489
2490     MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2491
2492     r = StgCreateDocfile(name, mode, 0, &stg);
2493     ok(r == S_OK, "failed to create storage\n");
2494     if (!stg)
2495         return;
2496
2497     r = IStorage_SetClass(stg, &CLSID_MsiTransform);
2498     ok(r == S_OK, "failed to set storage type\n");
2499
2500     for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2501     {
2502         r = IStorage_CreateStream(stg, table_transform_data[i].name,
2503                             STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
2504         if (FAILED(r))
2505         {
2506             ok(0, "failed to create stream %08x\n", r);
2507             continue;
2508         }
2509
2510         r = IStream_Write(stm, table_transform_data[i].data,
2511                           table_transform_data[i].size, &count);
2512         if (FAILED(r) || count != table_transform_data[i].size)
2513             ok(0, "failed to write stream\n");
2514         IStream_Release(stm);
2515     }
2516
2517     IStorage_Release(stg);
2518
2519     set_transform_summary_info();
2520 }
2521
2522 static void test_transformprop(void)
2523 {
2524     UINT r;
2525
2526     CreateDirectoryA("msitest", NULL);
2527     create_file("msitest\\augustus", 500);
2528
2529     create_database(msifile, tp_tables, sizeof(tp_tables) / sizeof(msi_table));
2530
2531     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2532
2533     r = MsiInstallProductA(msifile, NULL);
2534     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2535     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2536     ok(!delete_pf("msitest", FALSE), "File installed\n");
2537
2538     if (0)
2539         generate_transform();
2540     else
2541         generate_transform_manual();
2542
2543     r = MsiInstallProductA(msifile, "TRANSFORMS=winetest.mst");
2544     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2545     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
2546     ok(delete_pf("msitest", FALSE), "File not installed\n");
2547
2548     /* Delete the files in the temp (current) folder */
2549     DeleteFile(msifile);
2550     DeleteFile(msifile2);
2551     DeleteFile(mstfile);
2552     DeleteFile("msitest\\augustus");
2553     RemoveDirectory("msitest");
2554 }
2555
2556 static void test_currentworkingdir(void)
2557 {
2558     UINT r;
2559     CHAR path[MAX_PATH];
2560     LPSTR ptr, ptr2;
2561
2562     CreateDirectoryA("msitest", NULL);
2563     create_file("msitest\\augustus", 500);
2564
2565     create_database(msifile, cwd_tables, sizeof(cwd_tables) / sizeof(msi_table));
2566
2567     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2568
2569     CreateDirectoryA("diffdir", NULL);
2570     SetCurrentDirectoryA("diffdir");
2571
2572     sprintf(path, "..\\%s", msifile);
2573     r = MsiInstallProductA(path, NULL);
2574     todo_wine
2575     {
2576         ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %u\n", r);
2577         ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2578         ok(!delete_pf("msitest", FALSE), "File installed\n");
2579     }
2580
2581     sprintf(path, "%s\\%s", CURR_DIR, msifile);
2582     r = MsiInstallProductA(path, NULL);
2583     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2584     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
2585     ok(delete_pf("msitest", FALSE), "File not installed\n");
2586
2587     lstrcpyA(path, CURR_DIR);
2588     if (path[lstrlenA(path) - 1] != '\\')
2589         lstrcatA(path, "\\");
2590     lstrcatA(path, "msitest.msi");
2591
2592     ptr2 = strrchr(path, '\\');
2593     *ptr2 = '\0';
2594     ptr = strrchr(path, '\\');
2595     *ptr2 = '\\';
2596     *(ptr++) = '\0';
2597
2598     SetCurrentDirectoryA(path);
2599
2600     r = MsiInstallProductA(ptr, NULL);
2601     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2602     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
2603     ok(delete_pf("msitest", FALSE), "File not installed\n");
2604
2605     SetCurrentDirectoryA(CURR_DIR);
2606
2607     DeleteFile(msifile);
2608     DeleteFile("msitest\\augustus");
2609     RemoveDirectory("msitest");
2610     RemoveDirectory("diffdir");
2611 }
2612
2613 static void set_admin_summary_info(const CHAR *name)
2614 {
2615     MSIHANDLE db, summary;
2616     UINT r;
2617
2618     r = MsiOpenDatabaseA(name, MSIDBOPEN_DIRECT, &db);
2619     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2620
2621     r = MsiGetSummaryInformationA(db, NULL, 1, &summary);
2622     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2623
2624     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 5, NULL, NULL);
2625     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2626
2627     /* write the summary changes back to the stream */
2628     r = MsiSummaryInfoPersist(summary);
2629     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2630
2631     MsiCloseHandle(summary);
2632
2633     r = MsiDatabaseCommit(db);
2634     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2635
2636     MsiCloseHandle(db);
2637 }
2638
2639 static void test_admin(void)
2640 {
2641     UINT r;
2642
2643     CreateDirectoryA("msitest", NULL);
2644     create_file("msitest\\augustus", 500);
2645
2646     create_database(msifile, adm_tables, sizeof(adm_tables) / sizeof(msi_table));
2647     set_admin_summary_info(msifile);
2648
2649     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2650
2651     r = MsiInstallProductA(msifile, NULL);
2652     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2653     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2654     ok(!delete_pf("msitest", FALSE), "File installed\n");
2655     ok(!DeleteFile("c:\\msitest\\augustus"), "File installed\n");
2656     ok(!RemoveDirectory("c:\\msitest"), "File installed\n");
2657
2658     r = MsiInstallProductA(msifile, "ACTION=ADMIN");
2659     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2660     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2661     ok(!delete_pf("msitest", FALSE), "File installed\n");
2662     todo_wine
2663     {
2664         ok(DeleteFile("c:\\msitest\\augustus"), "File not installed\n");
2665         ok(RemoveDirectory("c:\\msitest"), "File not installed\n");
2666     }
2667
2668     DeleteFile(msifile);
2669     DeleteFile("msitest\\augustus");
2670     RemoveDirectory("msitest");
2671 }
2672
2673 static void set_admin_property_stream(LPCSTR file)
2674 {
2675     IStorage *stg;
2676     IStream *stm;
2677     WCHAR fileW[MAX_PATH];
2678     HRESULT hr;
2679     DWORD count;
2680     const DWORD mode = STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
2681
2682     /* AdminProperties */
2683     static const WCHAR stmname[] = {0x41ca,0x4330,0x3e71,0x44b5,0x4233,0x45f5,0x422c,0x4836,0};
2684     static const WCHAR data[] = {'M','Y','P','R','O','P','=','2','7','1','8',0};
2685
2686     MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, MAX_PATH);
2687
2688     hr = StgOpenStorage(fileW, NULL, mode, NULL, 0, &stg);
2689     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2690     if (!stg)
2691         return;
2692
2693     hr = IStorage_CreateStream(stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
2694     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2695
2696     hr = IStream_Write(stm, data, sizeof(data) - 1, &count);
2697     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2698
2699     IStream_Release(stm);
2700     IStorage_Release(stg);
2701 }
2702
2703 static void test_adminprops(void)
2704 {
2705     UINT r;
2706
2707     CreateDirectoryA("msitest", NULL);
2708     create_file("msitest\\augustus", 500);
2709
2710     create_database(msifile, amp_tables, sizeof(amp_tables) / sizeof(msi_table));
2711     set_admin_summary_info(msifile);
2712     set_admin_property_stream(msifile);
2713
2714     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2715
2716     r = MsiInstallProductA(msifile, NULL);
2717     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2718     ok(delete_pf("msitest\\augustus", TRUE), "File installed\n");
2719     ok(delete_pf("msitest", FALSE), "File installed\n");
2720
2721     DeleteFile(msifile);
2722     DeleteFile("msitest\\augustus");
2723     RemoveDirectory("msitest");
2724 }
2725
2726 START_TEST(install)
2727 {
2728     DWORD len;
2729     char temp_path[MAX_PATH], prev_path[MAX_PATH];
2730
2731     GetCurrentDirectoryA(MAX_PATH, prev_path);
2732     GetTempPath(MAX_PATH, temp_path);
2733     SetCurrentDirectoryA(temp_path);
2734
2735     lstrcpyA(CURR_DIR, temp_path);
2736     len = lstrlenA(CURR_DIR);
2737
2738     if(len && (CURR_DIR[len - 1] == '\\'))
2739         CURR_DIR[len - 1] = 0;
2740
2741     get_program_files_dir(PROG_FILES_DIR);
2742
2743     test_MsiInstallProduct();
2744     test_MsiSetComponentState();
2745     test_packagecoltypes();
2746     test_continuouscabs();
2747     test_caborder();
2748     test_mixedmedia();
2749     test_samesequence();
2750     test_uiLevelFlags();
2751     test_readonlyfile();
2752     test_setdirproperty();
2753     test_cabisextracted();
2754     test_concurrentinstall();
2755     test_setpropertyfolder();
2756     test_publish();
2757     test_publishsourcelist();
2758     test_transformprop();
2759     test_currentworkingdir();
2760     test_admin();
2761     test_adminprops();
2762
2763     SetCurrentDirectoryA(prev_path);
2764 }