mcicda: Exclude unused headers.
[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 #include <stdio.h>
22
23 #include <windows.h>
24 #include <msiquery.h>
25 #include <msidefs.h>
26 #include <msi.h>
27 #include <fci.h>
28
29 #include "wine/test.h"
30
31 static const char *msifile = "msitest.msi";
32 CHAR CURR_DIR[MAX_PATH];
33 CHAR PROG_FILES_DIR[MAX_PATH];
34
35 /* msi database data */
36
37 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
38                                     "s72\tS38\ts72\ti2\tS255\tS72\n"
39                                     "Component\tComponent\n"
40                                     "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
41                                     "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
42                                     "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
43                                     "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
44                                     "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
45                                     "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
46                                     "component\t\tMSITESTDIR\t0\t1\tfile\n"
47                                     "service_comp\t\tMSITESTDIR\t0\t1\tservice_file";
48
49 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
50                                     "s72\tS72\tl255\n"
51                                     "Directory\tDirectory\n"
52                                     "CABOUTDIR\tMSITESTDIR\tcabout\n"
53                                     "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
54                                     "FIRSTDIR\tMSITESTDIR\tfirst\n"
55                                     "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
56                                     "NEWDIR\tCABOUTDIR\tnew\n"
57                                     "ProgramFilesFolder\tTARGETDIR\t.\n"
58                                     "TARGETDIR\t\tSourceDir";
59
60 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
61                                   "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
62                                   "Feature\tFeature\n"
63                                   "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
64                                   "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
65                                   "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
66                                   "Three\t\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
67                                   "Two\t\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
68                                   "feature\t\t\t\t2\t1\tTARGETDIR\t0\n"
69                                   "service_feature\t\t\t\t2\t1\tTARGETDIR\t0";
70
71 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
72                                        "s38\ts72\n"
73                                        "FeatureComponents\tFeature_\tComponent_\n"
74                                        "Five\tFive\n"
75                                        "Four\tFour\n"
76                                        "One\tOne\n"
77                                        "Three\tThree\n"
78                                        "Two\tTwo\n"
79                                        "feature\tcomponent\n"
80                                        "service_feature\tservice_comp\n";
81
82 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
83                                "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
84                                "File\tFile\n"
85                                "five.txt\tFive\tfive.txt\t1000\t\t\t16384\t5\n"
86                                "four.txt\tFour\tfour.txt\t1000\t\t\t16384\t4\n"
87                                "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
88                                "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
89                                "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
90                                "file\tcomponent\tfilename\t100\t\t\t8192\t1\n"
91                                "service_file\tservice_comp\tservice.exe\t100\t\t\t8192\t1";
92
93 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
94                                            "s72\tS255\tI2\n"
95                                            "InstallExecuteSequence\tAction\n"
96                                            "AllocateRegistrySpace\tNOT Installed\t1550\n"
97                                            "CostFinalize\t\t1000\n"
98                                            "CostInitialize\t\t800\n"
99                                            "FileCost\t\t900\n"
100                                            "InstallFiles\t\t4000\n"
101                                            "InstallServices\t\t5000\n"
102                                            "InstallFinalize\t\t6600\n"
103                                            "InstallInitialize\t\t1500\n"
104                                            "InstallValidate\t\t1400\n"
105                                            "LaunchConditions\t\t100\n"
106                                            "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
107
108 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
109                                 "i2\ti4\tL64\tS255\tS32\tS72\n"
110                                 "Media\tDiskId\n"
111                                 "1\t3\t\t\tDISK1\t\n"
112                                 "2\t5\t\tmsitest.cab\tDISK2\t\n";
113
114 static const CHAR property_dat[] = "Property\tValue\n"
115                                    "s72\tl0\n"
116                                    "Property\tProperty\n"
117                                    "DefaultUIFont\tDlgFont8\n"
118                                    "HASUIRUN\t0\n"
119                                    "INSTALLLEVEL\t3\n"
120                                    "InstallMode\tTypical\n"
121                                    "Manufacturer\tWine\n"
122                                    "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
123                                    "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
124                                    "ProductID\tnone\n"
125                                    "ProductLanguage\t1033\n"
126                                    "ProductName\tMSITEST\n"
127                                    "ProductVersion\t1.1.1\n"
128                                    "PROMPTROLLBACKCOST\tP\n"
129                                    "Setup\tSetup\n"
130                                    "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
131
132 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
133                                    "s72\ti2\tl255\tL255\tL0\ts72\n"
134                                    "Registry\tRegistry\n"
135                                    "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
136                                    "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
137                                    "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
138                                    "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
139
140 static const CHAR service_install_dat[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
141                                           "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
142                                           "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
143                                           "ServiceInstall\tServiceInstall\n"
144                                           "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
145
146 static const CHAR service_control_dat[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
147                                           "s72\tl255\ti2\tL255\tI2\ts72\n"
148                                           "ServiceControl\tServiceControl\n"
149                                           "ServiceControl\tTestService\t8\t\t0\tservice_comp";
150
151 /* tables for test_continuouscabs */
152 static const CHAR cc_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
153                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
154                                        "Component\tComponent\n"
155                                        "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
156                                        "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
157                                        "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
158
159 static const CHAR cc_feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
160                                      "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
161                                      "Feature\tFeature\n"
162                                      "feature\t\t\t\t2\t1\tTARGETDIR\t0";
163
164 static const CHAR cc_feature_comp_dat[] = "Feature_\tComponent_\n"
165                                           "s38\ts72\n"
166                                           "FeatureComponents\tFeature_\tComponent_\n"
167                                           "feature\tmaximus\n"
168                                           "feature\taugustus\n"
169                                           "feature\tcaesar";
170
171 static const CHAR cc_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
172                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
173                                   "File\tFile\n"
174                                   "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
175                                   "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
176                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12";
177
178 static const CHAR cc_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
179                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
180                                    "Media\tDiskId\n"
181                                    "1\t10\t\ttest1.cab\tDISK1\t\n"
182                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
183                                    "3\t12\t\ttest3.cab\tDISK3\t\n";
184
185 static const CHAR co_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
186                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
187                                   "File\tFile\n"
188                                   "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
189                                   "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
190                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
191
192 static const CHAR co_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
193                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
194                                    "Media\tDiskId\n"
195                                    "1\t10\t\ttest1.cab\tDISK1\t\n"
196                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
197                                    "3\t3\t\ttest3.cab\tDISK3\t\n";
198
199 static const CHAR co2_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\t12\t\ttest3.cab\tDISK3\t\n"
204                                     "3\t2\t\ttest2.cab\tDISK2\t\n";
205
206 static const CHAR mm_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
207                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
208                                   "File\tFile\n"
209                                   "maximus\tmaximus\tmaximus\t500\t\t\t512\t1\n"
210                                   "augustus\taugustus\taugustus\t500\t\t\t512\t2\n"
211                                   "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
212
213 static const CHAR mm_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
214                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
215                                    "Media\tDiskId\n"
216                                    "1\t3\t\ttest1.cab\tDISK1\t\n";
217
218 static const CHAR ss_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
219                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
220                                    "Media\tDiskId\n"
221                                    "1\t2\t\ttest1.cab\tDISK1\t\n"
222                                    "2\t2\t\ttest2.cab\tDISK2\t\n"
223                                    "3\t12\t\ttest3.cab\tDISK3\t\n";
224
225 /* tables for test_uiLevelFlags */
226 static const CHAR ui_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
227                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
228                                        "Component\tComponent\n"
229                                        "maximus\t\tMSITESTDIR\t0\tHASUIRUN=1\tmaximus\n"
230                                        "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
231                                        "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
232
233 static const CHAR ui_install_ui_seq_dat[] = "Action\tCondition\tSequence\n"
234                                            "s72\tS255\tI2\n"
235                                            "InstallUISequence\tAction\n"
236                                            "SetUIProperty\t\t5\n"
237                                            "ExecuteAction\t\t1100\n";
238
239 static const CHAR ui_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
240                                            "s72\ti2\tS64\tS0\tS255\n"
241                                            "CustomAction\tAction\n"
242                                            "SetUIProperty\t51\tHASUIRUN\t1\t\n";
243
244 static const CHAR rof_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
245                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
246                                         "Component\tComponent\n"
247                                         "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n";
248
249 static const CHAR rof_feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
250                                       "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
251                                       "Feature\tFeature\n"
252                                       "feature\t\t\t\t2\t1\tTARGETDIR\t0";
253
254 static const CHAR rof_feature_comp_dat[] = "Feature_\tComponent_\n"
255                                            "s38\ts72\n"
256                                            "FeatureComponents\tFeature_\tComponent_\n"
257                                            "feature\tmaximus";
258
259 static const CHAR rof_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
260                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
261                                    "File\tFile\n"
262                                    "maximus\tmaximus\tmaximus\t500\t\t\t8192\t1";
263
264 static const CHAR rof_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
265                                     "i2\ti4\tL64\tS255\tS32\tS72\n"
266                                     "Media\tDiskId\n"
267                                     "1\t1\t\t\tDISK1\t\n";
268
269 static const CHAR sdp_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
270                                                "s72\tS255\tI2\n"
271                                                "InstallExecuteSequence\tAction\n"
272                                                "AllocateRegistrySpace\tNOT Installed\t1550\n"
273                                                "CostFinalize\t\t1000\n"
274                                                "CostInitialize\t\t800\n"
275                                                "FileCost\t\t900\n"
276                                                "InstallFiles\t\t4000\n"
277                                                "InstallFinalize\t\t6600\n"
278                                                "InstallInitialize\t\t1500\n"
279                                                "InstallValidate\t\t1400\n"
280                                                "LaunchConditions\t\t100\n"
281                                                "SetDirProperty\t\t950";
282
283 static const CHAR sdp_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
284                                             "s72\ti2\tS64\tS0\tS255\n"
285                                             "CustomAction\tAction\n"
286                                             "SetDirProperty\t51\tMSITESTDIR\t[CommonFilesFolder]msitest\\\t\n";
287
288 static const CHAR cie_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
289                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
290                                         "Component\tComponent\n"
291                                         "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
292                                         "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
293                                         "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n"
294                                         "gaius\t\tMSITESTDIR\t0\t1\tgaius\n";
295
296 static const CHAR cie_feature_comp_dat[] = "Feature_\tComponent_\n"
297                                            "s38\ts72\n"
298                                            "FeatureComponents\tFeature_\tComponent_\n"
299                                            "feature\tmaximus\n"
300                                            "feature\taugustus\n"
301                                            "feature\tcaesar\n"
302                                            "feature\tgaius";
303
304 static const CHAR cie_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
305                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
306                                    "File\tFile\n"
307                                    "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
308                                    "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
309                                    "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12\n"
310                                    "gaius\tgaius\tgaius\t500\t\t\t8192\t11";
311
312 static const CHAR cie_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
313                                     "i2\ti4\tL64\tS255\tS32\tS72\n"
314                                     "Media\tDiskId\n"
315                                     "1\t1\t\ttest1.cab\tDISK1\t\n"
316                                     "2\t2\t\ttest2.cab\tDISK2\t\n"
317                                     "3\t12\t\ttest3.cab\tDISK3\t\n";
318
319 static const CHAR ci_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
320                                               "s72\tS255\tI2\n"
321                                               "InstallExecuteSequence\tAction\n"
322                                               "CostFinalize\t\t1000\n"
323                                               "CostInitialize\t\t800\n"
324                                               "FileCost\t\t900\n"
325                                               "InstallFiles\t\t4000\n"
326                                               "InstallServices\t\t5000\n"
327                                               "InstallFinalize\t\t6600\n"
328                                               "InstallInitialize\t\t1500\n"
329                                               "RunInstall\t\t1600\n"
330                                               "InstallValidate\t\t1400\n"
331                                               "LaunchConditions\t\t100";
332
333 static const CHAR ci_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
334                                             "s72\ti2\tS64\tS0\tS255\n"
335                                             "CustomAction\tAction\n"
336                                             "RunInstall\t23\tmsitest\\concurrent.msi\tMYPROP=[UILevel]\t\n";
337
338 static const CHAR ci_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
339                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
340                                        "Component\tComponent\n"
341                                        "maximus\t\tMSITESTDIR\t0\tUILevel=5\tmaximus\n";
342
343 static const CHAR ci2_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
344                                         "s72\tS38\ts72\ti2\tS255\tS72\n"
345                                         "Component\tComponent\n"
346                                         "augustus\t\tMSITESTDIR\t0\tUILevel=3 AND MYPROP=5\taugustus\n";
347
348 static const CHAR ci2_feature_comp_dat[] = "Feature_\tComponent_\n"
349                                            "s38\ts72\n"
350                                            "FeatureComponents\tFeature_\tComponent_\n"
351                                            "feature\taugustus";
352
353 static const CHAR ci2_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
354                                    "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
355                                    "File\tFile\n"
356                                    "augustus\taugustus\taugustus\t500\t\t\t8192\t1";
357
358 static const CHAR spf_custom_action_dat[] = "Action\tType\tSource\tTarget\tISComments\n"
359                                             "s72\ti2\tS64\tS0\tS255\n"
360                                             "CustomAction\tAction\n"
361                                             "SetFolderProp\t51\tMSITESTDIR\t[ProgramFilesFolder]\\msitest\\added\t\n";
362
363 static const CHAR spf_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
364                                                "s72\tS255\tI2\n"
365                                                "InstallExecuteSequence\tAction\n"
366                                                "CostFinalize\t\t1000\n"
367                                                "CostInitialize\t\t800\n"
368                                                "FileCost\t\t900\n"
369                                                "SetFolderProp\t\t950\n"
370                                                "InstallFiles\t\t4000\n"
371                                                "InstallServices\t\t5000\n"
372                                                "InstallFinalize\t\t6600\n"
373                                                "InstallInitialize\t\t1500\n"
374                                                "InstallValidate\t\t1400\n"
375                                                "LaunchConditions\t\t100";
376
377 static const CHAR spf_install_ui_seq_dat[] = "Action\tCondition\tSequence\n"
378                                              "s72\tS255\tI2\n"
379                                              "InstallUISequence\tAction\n"
380                                              "CostInitialize\t\t800\n"
381                                              "FileCost\t\t900\n"
382                                              "CostFinalize\t\t1000\n"
383                                              "ExecuteAction\t\t1100\n";
384
385 typedef struct _msi_table
386 {
387     const CHAR *filename;
388     const CHAR *data;
389     int size;
390 } msi_table;
391
392 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
393
394 static const msi_table tables[] =
395 {
396     ADD_TABLE(component),
397     ADD_TABLE(directory),
398     ADD_TABLE(feature),
399     ADD_TABLE(feature_comp),
400     ADD_TABLE(file),
401     ADD_TABLE(install_exec_seq),
402     ADD_TABLE(media),
403     ADD_TABLE(property),
404     ADD_TABLE(registry),
405     ADD_TABLE(service_install),
406     ADD_TABLE(service_control)
407 };
408
409 static const msi_table cc_tables[] =
410 {
411     ADD_TABLE(cc_component),
412     ADD_TABLE(directory),
413     ADD_TABLE(cc_feature),
414     ADD_TABLE(cc_feature_comp),
415     ADD_TABLE(cc_file),
416     ADD_TABLE(install_exec_seq),
417     ADD_TABLE(cc_media),
418     ADD_TABLE(property),
419 };
420
421 static const msi_table co_tables[] =
422 {
423     ADD_TABLE(cc_component),
424     ADD_TABLE(directory),
425     ADD_TABLE(cc_feature),
426     ADD_TABLE(cc_feature_comp),
427     ADD_TABLE(co_file),
428     ADD_TABLE(install_exec_seq),
429     ADD_TABLE(co_media),
430     ADD_TABLE(property),
431 };
432
433 static const msi_table co2_tables[] =
434 {
435     ADD_TABLE(cc_component),
436     ADD_TABLE(directory),
437     ADD_TABLE(cc_feature),
438     ADD_TABLE(cc_feature_comp),
439     ADD_TABLE(cc_file),
440     ADD_TABLE(install_exec_seq),
441     ADD_TABLE(co2_media),
442     ADD_TABLE(property),
443 };
444
445 static const msi_table mm_tables[] =
446 {
447     ADD_TABLE(cc_component),
448     ADD_TABLE(directory),
449     ADD_TABLE(cc_feature),
450     ADD_TABLE(cc_feature_comp),
451     ADD_TABLE(mm_file),
452     ADD_TABLE(install_exec_seq),
453     ADD_TABLE(mm_media),
454     ADD_TABLE(property),
455 };
456
457 static const msi_table ss_tables[] =
458 {
459     ADD_TABLE(cc_component),
460     ADD_TABLE(directory),
461     ADD_TABLE(cc_feature),
462     ADD_TABLE(cc_feature_comp),
463     ADD_TABLE(cc_file),
464     ADD_TABLE(install_exec_seq),
465     ADD_TABLE(ss_media),
466     ADD_TABLE(property),
467 };
468
469 static const msi_table ui_tables[] =
470 {
471     ADD_TABLE(ui_component),
472     ADD_TABLE(directory),
473     ADD_TABLE(cc_feature),
474     ADD_TABLE(cc_feature_comp),
475     ADD_TABLE(cc_file),
476     ADD_TABLE(install_exec_seq),
477     ADD_TABLE(ui_install_ui_seq),
478     ADD_TABLE(ui_custom_action),
479     ADD_TABLE(cc_media),
480     ADD_TABLE(property),
481 };
482
483 static const msi_table rof_tables[] =
484 {
485     ADD_TABLE(rof_component),
486     ADD_TABLE(directory),
487     ADD_TABLE(rof_feature),
488     ADD_TABLE(rof_feature_comp),
489     ADD_TABLE(rof_file),
490     ADD_TABLE(install_exec_seq),
491     ADD_TABLE(rof_media),
492     ADD_TABLE(property),
493 };
494
495 static const msi_table sdp_tables[] =
496 {
497     ADD_TABLE(rof_component),
498     ADD_TABLE(directory),
499     ADD_TABLE(rof_feature),
500     ADD_TABLE(rof_feature_comp),
501     ADD_TABLE(rof_file),
502     ADD_TABLE(sdp_install_exec_seq),
503     ADD_TABLE(sdp_custom_action),
504     ADD_TABLE(rof_media),
505     ADD_TABLE(property),
506 };
507
508 static const msi_table cie_tables[] =
509 {
510     ADD_TABLE(cie_component),
511     ADD_TABLE(directory),
512     ADD_TABLE(cc_feature),
513     ADD_TABLE(cie_feature_comp),
514     ADD_TABLE(cie_file),
515     ADD_TABLE(install_exec_seq),
516     ADD_TABLE(cie_media),
517     ADD_TABLE(property),
518 };
519
520 static const msi_table ci_tables[] =
521 {
522     ADD_TABLE(ci_component),
523     ADD_TABLE(directory),
524     ADD_TABLE(rof_feature),
525     ADD_TABLE(rof_feature_comp),
526     ADD_TABLE(rof_file),
527     ADD_TABLE(ci_install_exec_seq),
528     ADD_TABLE(rof_media),
529     ADD_TABLE(property),
530     ADD_TABLE(ci_custom_action),
531 };
532
533 static const msi_table ci2_tables[] =
534 {
535     ADD_TABLE(ci2_component),
536     ADD_TABLE(directory),
537     ADD_TABLE(rof_feature),
538     ADD_TABLE(ci2_feature_comp),
539     ADD_TABLE(ci2_file),
540     ADD_TABLE(install_exec_seq),
541     ADD_TABLE(rof_media),
542     ADD_TABLE(property),
543 };
544
545 static const msi_table spf_tables[] =
546 {
547     ADD_TABLE(ci_component),
548     ADD_TABLE(directory),
549     ADD_TABLE(rof_feature),
550     ADD_TABLE(rof_feature_comp),
551     ADD_TABLE(rof_file),
552     ADD_TABLE(spf_install_exec_seq),
553     ADD_TABLE(rof_media),
554     ADD_TABLE(property),
555     ADD_TABLE(spf_custom_action),
556     ADD_TABLE(spf_install_ui_seq),
557 };
558
559 /* cabinet definitions */
560
561 /* make the max size large so there is only one cab file */
562 #define MEDIA_SIZE          0x7FFFFFFF
563 #define FOLDER_THRESHOLD    900000
564
565 /* the FCI callbacks */
566
567 static void *mem_alloc(ULONG cb)
568 {
569     return HeapAlloc(GetProcessHeap(), 0, cb);
570 }
571
572 static void mem_free(void *memory)
573 {
574     HeapFree(GetProcessHeap(), 0, memory);
575 }
576
577 static BOOL get_next_cabinet(PCCAB pccab, ULONG  cbPrevCab, void *pv)
578 {
579     sprintf(pccab->szCab, pv, pccab->iCab);
580     return TRUE;
581 }
582
583 static long progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
584 {
585     return 0;
586 }
587
588 static int file_placed(PCCAB pccab, char *pszFile, long cbFile,
589                        BOOL fContinuation, void *pv)
590 {
591     return 0;
592 }
593
594 static INT_PTR fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
595 {
596     HANDLE handle;
597     DWORD dwAccess = 0;
598     DWORD dwShareMode = 0;
599     DWORD dwCreateDisposition = OPEN_EXISTING;
600     
601     dwAccess = GENERIC_READ | GENERIC_WRITE;
602     /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
603     dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
604
605     if (GetFileAttributesA(pszFile) != INVALID_FILE_ATTRIBUTES)
606         dwCreateDisposition = OPEN_EXISTING;
607     else
608         dwCreateDisposition = CREATE_NEW;
609
610     handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
611                          dwCreateDisposition, 0, NULL);
612
613     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
614
615     return (INT_PTR)handle;
616 }
617
618 static UINT fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
619 {
620     HANDLE handle = (HANDLE)hf;
621     DWORD dwRead;
622     BOOL res;
623     
624     res = ReadFile(handle, memory, cb, &dwRead, NULL);
625     ok(res, "Failed to ReadFile\n");
626
627     return dwRead;
628 }
629
630 static UINT fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
631 {
632     HANDLE handle = (HANDLE)hf;
633     DWORD dwWritten;
634     BOOL res;
635
636     res = WriteFile(handle, memory, cb, &dwWritten, NULL);
637     ok(res, "Failed to WriteFile\n");
638
639     return dwWritten;
640 }
641
642 static int fci_close(INT_PTR hf, int *err, void *pv)
643 {
644     HANDLE handle = (HANDLE)hf;
645     ok(CloseHandle(handle), "Failed to CloseHandle\n");
646
647     return 0;
648 }
649
650 static long fci_seek(INT_PTR hf, long dist, int seektype, int *err, void *pv)
651 {
652     HANDLE handle = (HANDLE)hf;
653     DWORD ret;
654     
655     ret = SetFilePointer(handle, dist, NULL, seektype);
656     ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
657
658     return ret;
659 }
660
661 static int fci_delete(char *pszFile, int *err, void *pv)
662 {
663     BOOL ret = DeleteFileA(pszFile);
664     ok(ret, "Failed to DeleteFile %s\n", pszFile);
665
666     return 0;
667 }
668
669 static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
670 {
671     CHAR buffer[0x20];
672     UINT r;
673     DWORD sz;
674
675     sz = sizeof buffer;
676     r = MsiRecordGetString(rec, field, buffer, &sz);
677     return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
678 }
679
680 static BOOL get_temp_file(char *pszTempName, int cbTempName, void *pv)
681 {
682     LPSTR tempname;
683
684     tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
685     GetTempFileNameA(".", "xx", 0, tempname);
686
687     if (tempname && (strlen(tempname) < (unsigned)cbTempName))
688     {
689         lstrcpyA(pszTempName, tempname);
690         HeapFree(GetProcessHeap(), 0, tempname);
691         return TRUE;
692     }
693
694     HeapFree(GetProcessHeap(), 0, tempname);
695
696     return FALSE;
697 }
698
699 static INT_PTR get_open_info(char *pszName, USHORT *pdate, USHORT *ptime,
700                              USHORT *pattribs, int *err, void *pv)
701 {
702     BY_HANDLE_FILE_INFORMATION finfo;
703     FILETIME filetime;
704     HANDLE handle;
705     DWORD attrs;
706     BOOL res;
707
708     handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
709                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
710
711     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
712
713     res = GetFileInformationByHandle(handle, &finfo);
714     ok(res, "Expected GetFileInformationByHandle to succeed\n");
715    
716     FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime);
717     FileTimeToDosDateTime(&filetime, pdate, ptime);
718
719     attrs = GetFileAttributes(pszName);
720     ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
721
722     return (INT_PTR)handle;
723 }
724
725 static BOOL add_file(HFCI hfci, const char *file, TCOMP compress)
726 {
727     char path[MAX_PATH];
728     char filename[MAX_PATH];
729
730     lstrcpyA(path, CURR_DIR);
731     lstrcatA(path, "\\");
732     lstrcatA(path, file);
733
734     lstrcpyA(filename, file);
735
736     return FCIAddFile(hfci, path, filename, FALSE, get_next_cabinet,
737                       progress, get_open_info, compress);
738 }
739
740 static void set_cab_parameters(PCCAB pCabParams, const CHAR *name, DWORD max_size)
741 {
742     ZeroMemory(pCabParams, sizeof(CCAB));
743
744     pCabParams->cb = max_size;
745     pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
746     pCabParams->setID = 0xbeef;
747     pCabParams->iCab = 1;
748     lstrcpyA(pCabParams->szCabPath, CURR_DIR);
749     lstrcatA(pCabParams->szCabPath, "\\");
750     lstrcpyA(pCabParams->szCab, name);
751 }
752
753 static void create_cab_file(const CHAR *name, DWORD max_size, const CHAR *files)
754 {
755     CCAB cabParams;
756     LPCSTR ptr;
757     HFCI hfci;
758     ERF erf;
759     BOOL res;
760
761     set_cab_parameters(&cabParams, name, max_size);
762
763     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
764                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
765                       get_temp_file, &cabParams, NULL);
766
767     ok(hfci != NULL, "Failed to create an FCI context\n");
768
769     ptr = files;
770     while (*ptr)
771     {
772         res = add_file(hfci, ptr, tcompTYPE_MSZIP);
773         ok(res, "Failed to add file: %s\n", ptr);
774         ptr += lstrlen(ptr) + 1;
775     }
776
777     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
778     ok(res, "Failed to flush the cabinet\n");
779
780     res = FCIDestroy(hfci);
781     ok(res, "Failed to destroy the cabinet\n");
782 }
783
784 static BOOL get_program_files_dir(LPSTR buf)
785 {
786     HKEY hkey;
787     DWORD type = REG_EXPAND_SZ, size;
788
789     if (RegOpenKey(HKEY_LOCAL_MACHINE,
790                    "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
791         return FALSE;
792
793     size = MAX_PATH;
794     if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
795         return FALSE;
796
797     RegCloseKey(hkey);
798     return TRUE;
799 }
800
801 static void create_file(const CHAR *name, DWORD size)
802 {
803     HANDLE file;
804     DWORD written, left;
805
806     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
807     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
808     WriteFile(file, name, strlen(name), &written, NULL);
809     WriteFile(file, "\n", strlen("\n"), &written, NULL);
810
811     left = size - lstrlen(name) - 1;
812
813     SetFilePointer(file, left, NULL, FILE_CURRENT);
814     SetEndOfFile(file);
815     
816     CloseHandle(file);
817 }
818
819 static void create_test_files(void)
820 {
821     CreateDirectoryA("msitest", NULL);
822     create_file("msitest\\one.txt", 100);
823     CreateDirectoryA("msitest\\first", NULL);
824     create_file("msitest\\first\\two.txt", 100);
825     CreateDirectoryA("msitest\\second", NULL);
826     create_file("msitest\\second\\three.txt", 100);
827
828     create_file("four.txt", 100);
829     create_file("five.txt", 100);
830     create_cab_file("msitest.cab", MEDIA_SIZE, "four.txt\0five.txt\0");
831
832     create_file("msitest\\filename", 100);
833     create_file("msitest\\service.exe", 100);
834
835     DeleteFileA("four.txt");
836     DeleteFileA("five.txt");
837 }
838
839 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
840 {
841     CHAR path[MAX_PATH];
842
843     lstrcpyA(path, PROG_FILES_DIR);
844     lstrcatA(path, "\\");
845     lstrcatA(path, rel_path);
846
847     if (is_file)
848         return DeleteFileA(path);
849     else
850         return RemoveDirectoryA(path);
851 }
852
853 static void delete_test_files(void)
854 {
855     DeleteFileA("msitest.msi");
856     DeleteFileA("msitest.cab");
857     DeleteFileA("msitest\\second\\three.txt");
858     DeleteFileA("msitest\\first\\two.txt");
859     DeleteFileA("msitest\\one.txt");
860     DeleteFileA("msitest\\service.exe");
861     DeleteFileA("msitest\\filename");
862     RemoveDirectoryA("msitest\\second");
863     RemoveDirectoryA("msitest\\first");
864     RemoveDirectoryA("msitest");
865 }
866
867 static void write_file(const CHAR *filename, const char *data, int data_size)
868 {
869     DWORD size;
870
871     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
872                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
873
874     WriteFile(hf, data, data_size, &size, NULL);
875     CloseHandle(hf);
876 }
877
878 static void write_msi_summary_info(MSIHANDLE db)
879 {
880     MSIHANDLE summary;
881     UINT r;
882
883     r = MsiGetSummaryInformationA(db, NULL, 4, &summary);
884     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
885
886     r = MsiSummaryInfoSetPropertyA(summary, PID_TEMPLATE, VT_LPSTR, 0, NULL, ";1033");
887     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
888
889     r = MsiSummaryInfoSetPropertyA(summary, PID_REVNUMBER, VT_LPSTR, 0, NULL,
890                                    "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
891     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
892
893     r = MsiSummaryInfoSetPropertyA(summary, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
894     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
895
896     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 0, NULL, NULL);
897     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
898
899     /* write the summary changes back to the stream */
900     r = MsiSummaryInfoPersist(summary);
901     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
902
903     MsiCloseHandle(summary);
904 }
905
906 static void create_database(const CHAR *name, const msi_table *tables, int num_tables)
907 {
908     MSIHANDLE db;
909     UINT r;
910     int j;
911
912     r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
913     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
914
915     /* import the tables into the database */
916     for (j = 0; j < num_tables; j++)
917     {
918         const msi_table *table = &tables[j];
919
920         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
921
922         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
923         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
924
925         DeleteFileA(table->filename);
926     }
927
928     write_msi_summary_info(db);
929
930     r = MsiDatabaseCommit(db);
931     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
932
933     MsiCloseHandle(db);
934 }
935
936 static void check_service_is_installed(void)
937 {
938     SC_HANDLE scm, service;
939     BOOL res;
940
941     scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
942     ok(scm != NULL, "Failed to open the SC Manager\n");
943
944     service = OpenService(scm, "TestService", SC_MANAGER_ALL_ACCESS);
945     ok(service != NULL, "Failed to open TestService\n");
946
947     res = DeleteService(service);
948     ok(res, "Failed to delete TestService\n");
949 }
950
951 static void test_MsiInstallProduct(void)
952 {
953     UINT r;
954     CHAR path[MAX_PATH];
955     LONG res;
956     HKEY hkey;
957     DWORD num, size, type;
958
959     create_test_files();
960     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
961
962     r = MsiInstallProductA(msifile, NULL);
963     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
964
965     ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
966     ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
967     ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
968     ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
969     ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
970     ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
971     ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
972     ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
973     ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
974     ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
975     ok(delete_pf("msitest\\service.exe", TRUE), "File not installed\n");
976     ok(delete_pf("msitest", FALSE), "File not installed\n");
977
978     res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
979     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
980
981     size = MAX_PATH;
982     type = REG_SZ;
983     res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
984     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
985     ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
986
987     size = MAX_PATH;
988     type = REG_SZ;
989     res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
990     ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
991
992     size = sizeof(num);
993     type = REG_DWORD;
994     res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
995     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
996     ok(num == 314, "Expected 314, got %d\n", num);
997
998     size = MAX_PATH;
999     type = REG_SZ;
1000     res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
1001     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
1002     ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
1003
1004     check_service_is_installed();
1005
1006     RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
1007
1008     delete_test_files();
1009 }
1010
1011 static void test_MsiSetComponentState(void)
1012 {
1013     INSTALLSTATE installed, action;
1014     MSIHANDLE package;
1015     char path[MAX_PATH];
1016     UINT r;
1017
1018     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1019
1020     CoInitialize(NULL);
1021
1022     lstrcpy(path, CURR_DIR);
1023     lstrcat(path, "\\");
1024     lstrcat(path, msifile);
1025
1026     r = MsiOpenPackage(path, &package);
1027     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1028
1029     r = MsiDoAction(package, "CostInitialize");
1030     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1031
1032     r = MsiDoAction(package, "FileCost");
1033     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1034
1035     r = MsiDoAction(package, "CostFinalize");
1036     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1037
1038     r = MsiGetComponentState(package, "dangler", &installed, &action);
1039     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1040     ok(installed == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", installed);
1041     ok(action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
1042
1043     r = MsiSetComponentState(package, "dangler", INSTALLSTATE_SOURCE);
1044     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1045
1046     MsiCloseHandle(package);
1047     CoUninitialize();
1048
1049     DeleteFileA(msifile);
1050 }
1051
1052 static void test_packagecoltypes(void)
1053 {
1054     MSIHANDLE hdb, view, rec;
1055     char path[MAX_PATH];
1056     LPCSTR query;
1057     UINT r, count;
1058
1059     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1060
1061     CoInitialize(NULL);
1062
1063     lstrcpy(path, CURR_DIR);
1064     lstrcat(path, "\\");
1065     lstrcat(path, msifile);
1066
1067     r = MsiOpenDatabase(path, MSIDBOPEN_READONLY, &hdb);
1068     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1069
1070     query = "SELECT * FROM `Media`";
1071     r = MsiDatabaseOpenView( hdb, query, &view );
1072     ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1073
1074     r = MsiViewGetColumnInfo( view, MSICOLINFO_NAMES, &rec );
1075     count = MsiRecordGetFieldCount( rec );
1076     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
1077     ok(count == 6, "Expected 6, got %d\n", count);
1078     ok(check_record(rec, 1, "DiskId"), "wrong column label\n");
1079     ok(check_record(rec, 2, "LastSequence"), "wrong column label\n");
1080     ok(check_record(rec, 3, "DiskPrompt"), "wrong column label\n");
1081     ok(check_record(rec, 4, "Cabinet"), "wrong column label\n");
1082     ok(check_record(rec, 5, "VolumeLabel"), "wrong column label\n");
1083     ok(check_record(rec, 6, "Source"), "wrong column label\n");
1084     MsiCloseHandle(rec);
1085
1086     r = MsiViewGetColumnInfo( view, MSICOLINFO_TYPES, &rec );
1087     count = MsiRecordGetFieldCount( rec );
1088     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
1089     ok(count == 6, "Expected 6, got %d\n", count);
1090     ok(check_record(rec, 1, "i2"), "wrong column label\n");
1091     ok(check_record(rec, 2, "i4"), "wrong column label\n");
1092     ok(check_record(rec, 3, "L64"), "wrong column label\n");
1093     ok(check_record(rec, 4, "S255"), "wrong column label\n");
1094     ok(check_record(rec, 5, "S32"), "wrong column label\n");
1095     ok(check_record(rec, 6, "S72"), "wrong column label\n");
1096
1097     MsiCloseHandle(rec);
1098     MsiCloseHandle(view);
1099     MsiCloseHandle(hdb);
1100     DeleteFile(msifile);
1101 }
1102
1103 static void create_cc_test_files(void)
1104 {
1105     CCAB cabParams;
1106     HFCI hfci;
1107     ERF erf;
1108     static CHAR cab_context[] = "test%d.cab";
1109     BOOL res;
1110
1111     create_file("maximus", 500);
1112     create_file("augustus", 50000);
1113     create_file("caesar", 500);
1114
1115     set_cab_parameters(&cabParams, "test1.cab", 200);
1116
1117     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
1118                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
1119                       get_temp_file, &cabParams, cab_context);
1120     ok(hfci != NULL, "Failed to create an FCI context\n");
1121
1122     res = add_file(hfci, "maximus", tcompTYPE_MSZIP);
1123     ok(res, "Failed to add file maximus\n");
1124
1125     res = add_file(hfci, "augustus", tcompTYPE_MSZIP);
1126     ok(res, "Failed to add file augustus\n");
1127
1128     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
1129     ok(res, "Failed to flush the cabinet\n");
1130
1131     res = FCIDestroy(hfci);
1132     ok(res, "Failed to destroy the cabinet\n");
1133
1134     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1135
1136     DeleteFile("maximus");
1137     DeleteFile("augustus");
1138     DeleteFile("caesar");
1139 }
1140
1141 static void delete_cab_files(void)
1142 {
1143     SHFILEOPSTRUCT shfl;
1144     CHAR path[MAX_PATH];
1145
1146     lstrcpyA(path, CURR_DIR);
1147     lstrcatA(path, "\\*.cab");
1148     path[strlen(path) + 1] = '\0';
1149
1150     shfl.hwnd = NULL;
1151     shfl.wFunc = FO_DELETE;
1152     shfl.pFrom = (LPCSTR)path;
1153     shfl.pTo = NULL;
1154     shfl.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_NORECURSION | FOF_SILENT;
1155
1156     SHFileOperation(&shfl);
1157 }
1158
1159 static void test_continuouscabs(void)
1160 {
1161     UINT r;
1162
1163     create_cc_test_files();
1164     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
1165
1166     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1167
1168     r = MsiInstallProductA(msifile, NULL);
1169     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1170     todo_wine
1171     {
1172         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1173         ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1174         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1175     }
1176     ok(delete_pf("msitest", FALSE), "File not installed\n");
1177
1178     delete_cab_files();
1179     DeleteFile(msifile);
1180 }
1181
1182 static void test_caborder(void)
1183 {
1184     UINT r;
1185
1186     create_file("imperator", 100);
1187     create_file("maximus", 500);
1188     create_file("augustus", 50000);
1189     create_file("caesar", 500);
1190
1191     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
1192
1193     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1194
1195     create_cab_file("test1.cab", MEDIA_SIZE, "maximus\0");
1196     create_cab_file("test2.cab", MEDIA_SIZE, "augustus\0");
1197     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1198
1199     r = MsiInstallProductA(msifile, NULL);
1200     ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1201     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1202     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1203     todo_wine
1204     {
1205         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1206         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1207     }
1208
1209     delete_cab_files();
1210
1211     create_cab_file("test1.cab", MEDIA_SIZE, "imperator\0");
1212     create_cab_file("test2.cab", MEDIA_SIZE, "maximus\0augustus\0");
1213     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1214
1215     r = MsiInstallProductA(msifile, NULL);
1216     ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1217     ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1218     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1219     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1220     todo_wine
1221     {
1222         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1223     }
1224
1225     delete_cab_files();
1226     DeleteFile(msifile);
1227
1228     create_cc_test_files();
1229     create_database(msifile, co_tables, sizeof(co_tables) / sizeof(msi_table));
1230
1231     r = MsiInstallProductA(msifile, NULL);
1232     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1233     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1234     ok(!delete_pf("msitest", FALSE), "File is installed\n");
1235     todo_wine
1236     {
1237         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1238         ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1239     }
1240
1241     delete_cab_files();
1242     DeleteFile(msifile);
1243
1244     create_cc_test_files();
1245     create_database(msifile, co2_tables, sizeof(co2_tables) / sizeof(msi_table));
1246
1247     r = MsiInstallProductA(msifile, NULL);
1248     ok(!delete_pf("msitest\\augustus", TRUE), "File is installed\n");
1249     ok(!delete_pf("msitest\\caesar", TRUE), "File is installed\n");
1250     todo_wine
1251     {
1252         ok(r == ERROR_INSTALL_FAILURE, "Expected ERROR_INSTALL_FAILURE, got %u\n", r);
1253         ok(!delete_pf("msitest\\maximus", TRUE), "File is installed\n");
1254         ok(!delete_pf("msitest", FALSE), "File is installed\n");
1255     }
1256
1257     delete_cab_files();
1258     DeleteFile("imperator");
1259     DeleteFile("maximus");
1260     DeleteFile("augustus");
1261     DeleteFile("caesar");
1262     DeleteFile(msifile);
1263 }
1264
1265 static void test_mixedmedia(void)
1266 {
1267     UINT r;
1268
1269     CreateDirectoryA("msitest", NULL);
1270     create_file("msitest\\maximus", 500);
1271     create_file("msitest\\augustus", 500);
1272     create_file("caesar", 500);
1273
1274     create_database(msifile, mm_tables, sizeof(mm_tables) / sizeof(msi_table));
1275
1276     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1277
1278     create_cab_file("test1.cab", MEDIA_SIZE, "caesar\0");
1279
1280     r = MsiInstallProductA(msifile, NULL);
1281     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1282     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1283     ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1284     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1285     ok(delete_pf("msitest", FALSE), "File not installed\n");
1286
1287     /* Delete the files in the temp (current) folder */
1288     DeleteFile("msitest\\maximus");
1289     DeleteFile("msitest\\augustus");
1290     RemoveDirectory("msitest");
1291     DeleteFile("caesar");
1292     DeleteFile("test1.cab");
1293     DeleteFile(msifile);
1294 }
1295
1296 static void test_samesequence(void)
1297 {
1298     UINT r;
1299
1300     create_cc_test_files();
1301     create_database(msifile, ss_tables, sizeof(ss_tables) / sizeof(msi_table));
1302
1303     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1304
1305     r = MsiInstallProductA(msifile, NULL);
1306     todo_wine
1307     {
1308         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1309         ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1310         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1311     }
1312     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1313     ok(delete_pf("msitest", FALSE), "File not installed\n");
1314
1315     delete_cab_files();
1316     DeleteFile(msifile);
1317 }
1318
1319 static void test_uiLevelFlags(void)
1320 {
1321     UINT r;
1322
1323     create_cc_test_files();
1324     create_database(msifile, ui_tables, sizeof(ui_tables) / sizeof(msi_table));
1325
1326     MsiSetInternalUI(INSTALLUILEVEL_NONE | INSTALLUILEVEL_SOURCERESONLY, NULL);
1327
1328     r = MsiInstallProductA(msifile, NULL);
1329     ok(!delete_pf("msitest\\maximus", TRUE), "UI install occurred, but execute-only was requested.\n");
1330     todo_wine
1331     {
1332         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1333         ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1334     }
1335     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1336     ok(delete_pf("msitest", FALSE), "File not installed\n");
1337
1338     delete_cab_files();
1339     DeleteFile(msifile);
1340 }
1341
1342 static BOOL file_matches(LPSTR path)
1343 {
1344     CHAR buf[MAX_PATH];
1345     HANDLE file;
1346     DWORD size;
1347
1348     file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
1349                       NULL, OPEN_EXISTING, 0, NULL);
1350
1351     ZeroMemory(buf, MAX_PATH);
1352     ReadFile(file, buf, 15, &size, NULL);
1353     CloseHandle(file);
1354
1355     return !lstrcmp(buf, "msitest\\maximus");
1356 }
1357
1358 static void test_readonlyfile(void)
1359 {
1360     UINT r;
1361     DWORD size;
1362     HANDLE file;
1363     CHAR path[MAX_PATH];
1364
1365     CreateDirectoryA("msitest", NULL);
1366     create_file("msitest\\maximus", 500);
1367     create_database(msifile, rof_tables, sizeof(rof_tables) / sizeof(msi_table));
1368
1369     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1370
1371     lstrcpy(path, PROG_FILES_DIR);
1372     lstrcat(path, "\\msitest");
1373     CreateDirectory(path, NULL);
1374
1375     lstrcat(path, "\\maximus");
1376     file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
1377                       NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
1378
1379     WriteFile(file, "readonlyfile", 20, &size, NULL);
1380     CloseHandle(file);
1381
1382     r = MsiInstallProductA(msifile, NULL);
1383     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1384     ok(file_matches(path), "Expected file to be overwritten\n");
1385     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1386     ok(delete_pf("msitest", FALSE), "File not installed\n");
1387
1388     /* Delete the files in the temp (current) folder */
1389     DeleteFile("msitest\\maximus");
1390     RemoveDirectory("msitest");
1391     DeleteFile(msifile);
1392 }
1393
1394 static void test_setdirproperty(void)
1395 {
1396     UINT r;
1397
1398     CreateDirectoryA("msitest", NULL);
1399     create_file("msitest\\maximus", 500);
1400     create_database(msifile, sdp_tables, sizeof(sdp_tables) / sizeof(msi_table));
1401
1402     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1403
1404     r = MsiInstallProductA(msifile, NULL);
1405     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1406     ok(delete_pf("Common Files\\msitest\\maximus", TRUE), "File not installed\n");
1407     ok(delete_pf("Common Files\\msitest", FALSE), "File not installed\n");
1408
1409     /* Delete the files in the temp (current) folder */
1410     DeleteFile(msifile);
1411     DeleteFile("msitest\\maximus");
1412     RemoveDirectory("msitest");
1413 }
1414
1415 static void test_cabisextracted(void)
1416 {
1417     UINT r;
1418
1419     CreateDirectoryA("msitest", NULL);
1420     create_file("msitest\\gaius", 500);
1421     create_file("maximus", 500);
1422     create_file("augustus", 500);
1423     create_file("caesar", 500);
1424
1425     create_cab_file("test1.cab", MEDIA_SIZE, "maximus\0");
1426     create_cab_file("test2.cab", MEDIA_SIZE, "augustus\0");
1427     create_cab_file("test3.cab", MEDIA_SIZE, "caesar\0");
1428
1429     create_database(msifile, cie_tables, sizeof(cie_tables) / sizeof(msi_table));
1430
1431     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
1432
1433     r = MsiInstallProductA(msifile, NULL);
1434     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1435     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1436     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1437     ok(delete_pf("msitest\\caesar", TRUE), "File not installed\n");
1438     ok(delete_pf("msitest\\gaius", TRUE), "File not installed\n");
1439     ok(delete_pf("msitest", FALSE), "File not installed\n");
1440
1441     /* Delete the files in the temp (current) folder */
1442     delete_cab_files();
1443     DeleteFile(msifile);
1444     DeleteFile("maximus");
1445     DeleteFile("augustus");
1446     DeleteFile("caesar");
1447     DeleteFile("msitest\\gaius");
1448     RemoveDirectory("msitest");
1449 }
1450
1451 static void test_concurrentinstall(void)
1452 {
1453     UINT r;
1454     CHAR path[MAX_PATH];
1455
1456     CreateDirectoryA("msitest", NULL);
1457     CreateDirectoryA("msitest\\msitest", NULL);
1458     create_file("msitest\\maximus", 500);
1459     create_file("msitest\\msitest\\augustus", 500);
1460
1461     create_database(msifile, ci_tables, sizeof(ci_tables) / sizeof(msi_table));
1462
1463     lstrcpyA(path, CURR_DIR);
1464     lstrcatA(path, "\\msitest\\concurrent.msi");
1465     create_database(path, ci2_tables, sizeof(ci2_tables) / sizeof(msi_table));
1466
1467     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
1468
1469     r = MsiInstallProductA(msifile, NULL);
1470     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1471     ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
1472     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
1473     ok(delete_pf("msitest", FALSE), "File not installed\n");
1474
1475     /* Delete the files in the temp (current) folder */
1476     DeleteFile(msifile);
1477     DeleteFile(path);
1478     DeleteFile("msitest\\msitest\\augustus");
1479     DeleteFile("msitest\\maximus");
1480     RemoveDirectory("msitest\\msitest");
1481     RemoveDirectory("msitest");
1482 }
1483
1484 static void test_setpropertyfolder(void)
1485 {
1486     UINT r;
1487
1488     CreateDirectoryA("msitest", NULL);
1489     create_file("msitest\\maximus", 500);
1490
1491     create_database(msifile, spf_tables, sizeof(spf_tables) / sizeof(msi_table));
1492
1493     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
1494
1495     r = MsiInstallProductA(msifile, NULL);
1496     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1497     ok(delete_pf("msitest\\added\\maximus", TRUE), "File not installed\n");
1498     ok(delete_pf("msitest\\added", FALSE), "File not installed\n");
1499     ok(delete_pf("msitest", FALSE), "File not installed\n");
1500
1501     /* Delete the files in the temp (current) folder */
1502     DeleteFile(msifile);
1503     DeleteFile("msitest\\maximus");
1504     RemoveDirectory("msitest");
1505 }
1506
1507 START_TEST(install)
1508 {
1509     DWORD len;
1510     char temp_path[MAX_PATH], prev_path[MAX_PATH];
1511
1512     GetCurrentDirectoryA(MAX_PATH, prev_path);
1513     GetTempPath(MAX_PATH, temp_path);
1514     SetCurrentDirectoryA(temp_path);
1515
1516     lstrcpyA(CURR_DIR, temp_path);
1517     len = lstrlenA(CURR_DIR);
1518
1519     if(len && (CURR_DIR[len - 1] == '\\'))
1520         CURR_DIR[len - 1] = 0;
1521
1522     get_program_files_dir(PROG_FILES_DIR);
1523
1524     test_MsiInstallProduct();
1525     test_MsiSetComponentState();
1526     test_packagecoltypes();
1527     test_continuouscabs();
1528     test_caborder();
1529     test_mixedmedia();
1530     test_samesequence();
1531     test_uiLevelFlags();
1532     test_readonlyfile();
1533     test_setdirproperty();
1534     test_cabisextracted();
1535     test_concurrentinstall();
1536     test_setpropertyfolder();
1537
1538     SetCurrentDirectoryA(prev_path);
1539 }