crypt32: Introduce function to encode an array of items as a set.
[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     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1880
1881     /* PublishProduct and RegisterProduct and ProcessComponents */
1882     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1 PROCESS_COMPONENTS=1");
1883     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1884     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1885     ok(pf_exists("msitest"), "File not installed\n");
1886
1887     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1888     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1889
1890     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1891     todo_wine
1892     {
1893         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1894     }
1895
1896     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1897     todo_wine
1898     {
1899         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1900     }
1901
1902     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1903                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1904     todo_wine
1905     {
1906         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1907         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1908     }
1909
1910     /* complete uninstall */
1911     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
1912     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1913     ok(pf_exists("msitest\\maximus"), "File deleted\n");
1914     ok(pf_exists("msitest"), "File deleted\n");
1915
1916     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1917     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1918
1919     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1920     todo_wine
1921     {
1922         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1923     }
1924
1925     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1926     todo_wine
1927     {
1928         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1929     }
1930
1931     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1932                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1933     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1934     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1935
1936     /* PublishProduct, RegisterProduct, ProcessComponents, PublishFeatures */
1937     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1 PUBLISH_PRODUCT=1 PROCESS_COMPONENTS=1 PUBLISH_FEATURES=1");
1938     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1939     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1940     ok(pf_exists("msitest"), "File not installed\n");
1941
1942     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1943     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1944
1945     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
1946     todo_wine
1947     {
1948         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1949     }
1950
1951     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1952     todo_wine
1953     {
1954         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1955     }
1956
1957     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1958                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1959     todo_wine
1960     {
1961         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1962         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1963     }
1964
1965     /* complete uninstall */
1966     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
1967     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1968     todo_wine
1969     {
1970         ok(!pf_exists("msitest\\maximus"), "File deleted\n");
1971         ok(!pf_exists("msitest"), "File deleted\n");
1972     }
1973
1974     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
1975     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1976
1977     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");\
1978     todo_wine
1979     {
1980         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1981     }
1982
1983     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
1984     todo_wine
1985     {
1986         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1987     }
1988
1989     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1990                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
1991     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
1992     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1993
1994     /* complete install */
1995     r = MsiInstallProductA(msifile, "FULL=1");
1996     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1997     ok(pf_exists("msitest\\maximus"), "File not installed\n");
1998     ok(pf_exists("msitest"), "File not installed\n");
1999
2000     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2001     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2002
2003     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2004     todo_wine
2005     {
2006         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2007     }
2008
2009     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2010     todo_wine
2011     {
2012         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2013     }
2014
2015     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2016                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2017     todo_wine
2018     {
2019         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2020         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2021     }
2022
2023     /* no UnpublishFeatures */
2024     r = MsiInstallProductA(msifile, "REMOVE=ALL");
2025     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2026     todo_wine
2027     {
2028         ok(!pf_exists("msitest\\maximus"), "File deleted\n");
2029         ok(!pf_exists("msitest"), "File deleted\n");
2030     }
2031
2032     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2033     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2034
2035     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2036     todo_wine
2037     {
2038         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2039     }
2040
2041     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2042     todo_wine
2043     {
2044         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2045     }
2046
2047     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2048                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2049     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2050     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2051
2052     /* complete install */
2053     r = MsiInstallProductA(msifile, "FULL=1");
2054     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2055     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2056     ok(pf_exists("msitest"), "File not installed\n");
2057
2058     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2059     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2060
2061     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2062     todo_wine
2063     {
2064         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2065     }
2066
2067     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2068     todo_wine
2069     {
2070         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2071     }
2072
2073     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2074                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2075     todo_wine
2076     {
2077         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2078         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2079     }
2080
2081     /* UnpublishFeatures, only feature removed.  Only works when entire product is removed */
2082     r = MsiInstallProductA(msifile, "UNPUBLISH_FEATURES=1 REMOVE=feature");
2083     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2084     ok(pf_exists("msitest\\maximus"), "File deleted\n");
2085     ok(pf_exists("msitest"), "File deleted\n");
2086
2087     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2088     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2089
2090     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2091     todo_wine
2092     {
2093         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2094     }
2095
2096     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2097     todo_wine
2098     {
2099         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2100     }
2101
2102     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2103                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2104     todo_wine
2105     {
2106         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2107         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2108     }
2109
2110     /* complete install */
2111     r = MsiInstallProductA(msifile, "FULL=1");
2112     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2113     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2114     ok(pf_exists("msitest"), "File not installed\n");
2115
2116     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2117     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2118
2119     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2120     todo_wine
2121     {
2122         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2123     }
2124
2125     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2126     todo_wine
2127     {
2128         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2129     }
2130
2131     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2132                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2133     todo_wine
2134     {
2135         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2136         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2137     }
2138
2139     /* UnpublishFeatures, both features removed */
2140     r = MsiInstallProductA(msifile, "UNPUBLISH_FEATURES=1 REMOVE=feature,montecristo");
2141     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2142     todo_wine
2143     {
2144         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2145         ok(!pf_exists("msitest"), "File not deleted\n");
2146     }
2147
2148     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2149     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2150
2151     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2152     todo_wine
2153     {
2154         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2155     }
2156
2157     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2158     todo_wine
2159     {
2160         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2161     }
2162
2163     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2164                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2165     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2166     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2167
2168     /* complete install */
2169     r = MsiInstallProductA(msifile, "FULL=1");
2170     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2171     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2172     ok(pf_exists("msitest"), "File not installed\n");
2173
2174     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2175     ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
2176
2177     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2178     todo_wine
2179     {
2180         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2181     }
2182
2183     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2184     todo_wine
2185     {
2186         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2187     }
2188
2189     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2190                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2191     todo_wine
2192     {
2193         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2194         ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2195     }
2196
2197     /* complete uninstall */
2198     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
2199     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2200     todo_wine
2201     {
2202         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2203         ok(!pf_exists("msitest"), "File not deleted\n");
2204     }
2205
2206     state = MsiQueryProductState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}");
2207     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2208
2209     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "feature");
2210     todo_wine
2211     {
2212         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2213     }
2214
2215     state = MsiQueryFeatureState("{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}", "montecristo");
2216     todo_wine
2217     {
2218         ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2219     }
2220
2221     r = MsiQueryComponentStateA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2222                                 "{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}", &state);
2223     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2224     ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2225
2226     /* make sure 'Program Files\msitest' is removed */
2227     delete_pfmsitest_files();
2228
2229     DeleteFile(msifile);
2230     DeleteFile("msitest\\maximus");
2231     RemoveDirectory("msitest");
2232 }
2233
2234 static void test_publishsourcelist(void)
2235 {
2236     UINT r;
2237     DWORD size;
2238     CHAR value[MAX_PATH];
2239     CHAR prodcode[] = "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}";
2240
2241     CreateDirectoryA("msitest", NULL);
2242     create_file("msitest\\maximus", 500);
2243
2244     create_database(msifile, pp_tables, sizeof(pp_tables) / sizeof(msi_table));
2245
2246     MsiSetInternalUI(INSTALLUILEVEL_FULL, NULL);
2247
2248     r = MsiInstallProductA(msifile, NULL);
2249     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2250     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2251     ok(pf_exists("msitest"), "File not installed\n");
2252
2253     /* nothing published */
2254     size = 0xdeadbeef;
2255     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2256                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2257     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2258     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2259
2260     r = MsiInstallProductA(msifile, "REGISTER_PRODUCT=1");
2261     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2262     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2263     ok(pf_exists("msitest"), "File not installed\n");
2264
2265     /* after RegisterProduct */
2266     size = 0xdeadbeef;
2267     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2268                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2269     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2270     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2271
2272     r = MsiInstallProductA(msifile, "PROCESS_COMPONENTS=1");
2273     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2274     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2275     ok(pf_exists("msitest"), "File not installed\n");
2276
2277     /* after ProcessComponents */
2278     size = 0xdeadbeef;
2279     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2280                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2281     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2282     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2283
2284     r = MsiInstallProductA(msifile, "PUBLISH_FEATURES=1");
2285     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2286     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2287     ok(pf_exists("msitest"), "File not installed\n");
2288
2289     /* after PublishFeatures */
2290     size = 0xdeadbeef;
2291     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2292                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, NULL, &size);
2293     ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2294     ok(size == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", size);
2295
2296     r = MsiInstallProductA(msifile, "PUBLISH_PRODUCT=1");
2297     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2298     ok(pf_exists("msitest\\maximus"), "File not installed\n");
2299     ok(pf_exists("msitest"), "File not installed\n");
2300
2301     /* after PublishProduct */
2302     size = MAX_PATH;
2303     lstrcpyA(value, "aaa");
2304     r = MsiSourceListGetInfoA(prodcode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2305                               MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAME, value, &size);
2306     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2307     ok(!lstrcmpA(value, "msitest.msi"), "Expected 'msitest.msi', got %s\n", value);
2308     ok(size == 11, "Expected 11, got %d\n", size);
2309
2310     /* complete uninstall */
2311     r = MsiInstallProductA(msifile, "FULL=1 REMOVE=ALL");
2312     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2313     todo_wine
2314     {
2315         ok(!pf_exists("msitest\\maximus"), "File not deleted\n");
2316         ok(!pf_exists("msitest"), "File not deleted\n");
2317     }
2318
2319     /* make sure 'Program Files\msitest' is removed */
2320     delete_pfmsitest_files();
2321
2322     DeleteFile(msifile);
2323     DeleteFile("msitest\\maximus");
2324     RemoveDirectory("msitest");
2325 }
2326
2327 static UINT run_query(MSIHANDLE hdb, MSIHANDLE hrec, const char *query)
2328 {
2329     MSIHANDLE hview = 0;
2330     UINT r;
2331
2332     r = MsiDatabaseOpenView(hdb, query, &hview);
2333     if(r != ERROR_SUCCESS)
2334         return r;
2335
2336     r = MsiViewExecute(hview, hrec);
2337     if(r == ERROR_SUCCESS)
2338         r = MsiViewClose(hview);
2339     MsiCloseHandle(hview);
2340     return r;
2341 }
2342
2343 static void set_transform_summary_info(void)
2344 {
2345     UINT r;
2346     MSIHANDLE suminfo;
2347
2348     /* build summmary info */
2349     r = MsiGetSummaryInformation(0, mstfile, 3, &suminfo);
2350     todo_wine
2351     {
2352         ok(r == ERROR_SUCCESS , "Failed to open summaryinfo\n");
2353     }
2354
2355     r = MsiSummaryInfoSetProperty(suminfo, PID_TITLE, VT_LPSTR, 0, NULL, "MSITEST");
2356     todo_wine
2357     {
2358         ok(r == ERROR_SUCCESS, "Failed to set summary info\n");
2359     }
2360
2361     r = MsiSummaryInfoSetProperty(suminfo, PID_REVNUMBER, VT_LPSTR, 0, NULL,
2362                         "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}1.1.1;"
2363                         "{7DF88A48-996F-4EC8-A022-BF956F9B2CBB}1.1.1;"
2364                         "{4C0EAA15-0264-4E5A-8758-609EF142B92D}");
2365     todo_wine
2366     {
2367         ok(r == ERROR_SUCCESS , "Failed to set summary info\n");
2368     }
2369
2370     r = MsiSummaryInfoSetProperty(suminfo, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
2371     todo_wine
2372     {
2373         ok(r == ERROR_SUCCESS, "Failed to set summary info\n");
2374     }
2375
2376     r = MsiSummaryInfoPersist(suminfo);
2377     todo_wine
2378     {
2379         ok(r == ERROR_SUCCESS , "Failed to make summary info persist\n");
2380     }
2381
2382     r = MsiCloseHandle(suminfo);
2383     todo_wine
2384     {
2385         ok(r == ERROR_SUCCESS , "Failed to close suminfo\n");
2386     }
2387 }
2388
2389 static void generate_transform(void)
2390 {
2391     MSIHANDLE hdb1, hdb2;
2392     LPCSTR query;
2393     UINT r;
2394
2395     /* start with two identical databases */
2396     CopyFile(msifile, msifile2, FALSE);
2397
2398     r = MsiOpenDatabase(msifile2, MSIDBOPEN_TRANSACT, &hdb1);
2399     ok(r == ERROR_SUCCESS , "Failed to create database\n");
2400
2401     r = MsiDatabaseCommit(hdb1);
2402     ok(r == ERROR_SUCCESS , "Failed to commit database\n");
2403
2404     r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb2);
2405     ok(r == ERROR_SUCCESS , "Failed to create database\n");
2406
2407     query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2408     r = run_query(hdb1, 0, query);
2409     ok(r == ERROR_SUCCESS, "failed to add property\n");
2410
2411     /* database needs to be committed */
2412     MsiDatabaseCommit(hdb1);
2413
2414     r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2415     ok(r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r);
2416
2417 #if 0  /* not implemented in wine yet */
2418     r = MsiCreateTransformSummaryInfo(hdb2, hdb2, mstfile, 0, 0);
2419     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2420 #endif
2421
2422     MsiCloseHandle(hdb1);
2423     MsiCloseHandle(hdb2);
2424 }
2425
2426 /* data for generating a transform */
2427
2428 /* tables transform names - encoded as they would be in an msi database file */
2429 static const WCHAR name1[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2430 static const WCHAR name2[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2431 static const WCHAR name3[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2432
2433 /* data in each table */
2434 static const char data1[] = /* _StringData */
2435     "propval";  /* all the strings squashed together */
2436
2437 static const WCHAR data2[] = { /* _StringPool */
2438 /*  len, refs */
2439     0,   0,    /* string 0 ''     */
2440     4,   1,    /* string 1 'prop' */
2441     3,   1,    /* string 2 'val'  */
2442 };
2443
2444 static const WCHAR data3[] = { /* Property */
2445     0x0201, 0x0001, 0x0002,
2446 };
2447
2448 static const struct {
2449     LPCWSTR name;
2450     const void *data;
2451     DWORD size;
2452 } table_transform_data[] =
2453 {
2454     { name1, data1, sizeof data1 - 1 },
2455     { name2, data2, sizeof data2 },
2456     { name3, data3, sizeof data3 },
2457 };
2458
2459 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2460
2461 static void generate_transform_manual(void)
2462 {
2463     IStorage *stg = NULL;
2464     IStream *stm;
2465     WCHAR name[0x20];
2466     HRESULT r;
2467     DWORD i, count;
2468     const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2469
2470     const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2471
2472     MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2473
2474     r = StgCreateDocfile(name, mode, 0, &stg);
2475     ok(r == S_OK, "failed to create storage\n");
2476     if (!stg)
2477         return;
2478
2479     r = IStorage_SetClass(stg, &CLSID_MsiTransform);
2480     ok(r == S_OK, "failed to set storage type\n");
2481
2482     for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2483     {
2484         r = IStorage_CreateStream(stg, table_transform_data[i].name,
2485                             STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
2486         if (FAILED(r))
2487         {
2488             ok(0, "failed to create stream %08x\n", r);
2489             continue;
2490         }
2491
2492         r = IStream_Write(stm, table_transform_data[i].data,
2493                           table_transform_data[i].size, &count);
2494         if (FAILED(r) || count != table_transform_data[i].size)
2495             ok(0, "failed to write stream\n");
2496         IStream_Release(stm);
2497     }
2498
2499     IStorage_Release(stg);
2500
2501     set_transform_summary_info();
2502 }
2503
2504 static void test_transformprop(void)
2505 {
2506     UINT r;
2507
2508     CreateDirectoryA("msitest", NULL);
2509     create_file("msitest\\augustus", 500);
2510
2511     create_database(msifile, tp_tables, sizeof(tp_tables) / sizeof(msi_table));
2512
2513     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2514
2515     r = MsiInstallProductA(msifile, NULL);
2516     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2517     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2518     ok(!delete_pf("msitest", FALSE), "File installed\n");
2519
2520     if (0)
2521         generate_transform();
2522     else
2523         generate_transform_manual();
2524
2525     r = MsiInstallProductA(msifile, "TRANSFORMS=winetest.mst");
2526     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2527     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
2528     ok(delete_pf("msitest", FALSE), "File not installed\n");
2529
2530     /* Delete the files in the temp (current) folder */
2531     DeleteFile(msifile);
2532     DeleteFile(msifile2);
2533     DeleteFile(mstfile);
2534     DeleteFile("msitest\\augustus");
2535     RemoveDirectory("msitest");
2536 }
2537
2538 static void test_currentworkingdir(void)
2539 {
2540     UINT r;
2541     CHAR path[MAX_PATH];
2542     LPSTR ptr, ptr2;
2543
2544     CreateDirectoryA("msitest", NULL);
2545     create_file("msitest\\augustus", 500);
2546
2547     create_database(msifile, cwd_tables, sizeof(cwd_tables) / sizeof(msi_table));
2548
2549     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2550
2551     CreateDirectoryA("diffdir", NULL);
2552     SetCurrentDirectoryA("diffdir");
2553
2554     sprintf(path, "..\\%s", msifile);
2555     r = MsiInstallProductA(path, NULL);
2556     todo_wine
2557     {
2558         ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %u\n", r);
2559         ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2560         ok(!delete_pf("msitest", FALSE), "File installed\n");
2561     }
2562
2563     sprintf(path, "%s\\%s", CURR_DIR, msifile);
2564     r = MsiInstallProductA(path, NULL);
2565     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2566     ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
2567     ok(delete_pf("msitest", FALSE), "File not installed\n");
2568
2569     lstrcpyA(path, CURR_DIR);
2570     if (path[lstrlenA(path) - 1] != '\\')
2571         lstrcatA(path, "\\");
2572     lstrcatA(path, "msitest.msi");
2573
2574     ptr2 = strrchr(path, '\\');
2575     *ptr2 = '\0';
2576     ptr = strrchr(path, '\\');
2577     *ptr2 = '\\';
2578     *(ptr++) = '\0';
2579
2580     SetCurrentDirectoryA(path);
2581
2582     r = MsiInstallProductA(ptr, 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     SetCurrentDirectoryA(CURR_DIR);
2588
2589     DeleteFile(msifile);
2590     DeleteFile("msitest\\augustus");
2591     RemoveDirectory("msitest");
2592     RemoveDirectory("diffdir");
2593 }
2594
2595 static void set_admin_summary_info(const CHAR *name)
2596 {
2597     MSIHANDLE db, summary;
2598     UINT r;
2599
2600     r = MsiOpenDatabaseA(name, MSIDBOPEN_DIRECT, &db);
2601     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2602
2603     r = MsiGetSummaryInformationA(db, NULL, 1, &summary);
2604     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2605
2606     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 5, NULL, NULL);
2607     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2608
2609     /* write the summary changes back to the stream */
2610     r = MsiSummaryInfoPersist(summary);
2611     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2612
2613     MsiCloseHandle(summary);
2614
2615     r = MsiDatabaseCommit(db);
2616     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2617
2618     MsiCloseHandle(db);
2619 }
2620
2621 static void test_admin(void)
2622 {
2623     UINT r;
2624
2625     CreateDirectoryA("msitest", NULL);
2626     create_file("msitest\\augustus", 500);
2627
2628     create_database(msifile, adm_tables, sizeof(adm_tables) / sizeof(msi_table));
2629     set_admin_summary_info(msifile);
2630
2631     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2632
2633     r = MsiInstallProductA(msifile, NULL);
2634     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2635     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2636     ok(!delete_pf("msitest", FALSE), "File installed\n");
2637     ok(!DeleteFile("c:\\msitest\\augustus"), "File installed\n");
2638     ok(!RemoveDirectory("c:\\msitest"), "File installed\n");
2639
2640     r = MsiInstallProductA(msifile, "ACTION=ADMIN");
2641     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2642     ok(!delete_pf("msitest\\augustus", TRUE), "File installed\n");
2643     ok(!delete_pf("msitest", FALSE), "File installed\n");
2644     todo_wine
2645     {
2646         ok(DeleteFile("c:\\msitest\\augustus"), "File not installed\n");
2647         ok(RemoveDirectory("c:\\msitest"), "File not installed\n");
2648     }
2649
2650     DeleteFile(msifile);
2651     DeleteFile("msitest\\augustus");
2652     RemoveDirectory("msitest");
2653 }
2654
2655 static void set_admin_property_stream(LPCSTR file)
2656 {
2657     IStorage *stg;
2658     IStream *stm;
2659     WCHAR fileW[MAX_PATH];
2660     HRESULT hr;
2661     DWORD count;
2662     const DWORD mode = STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
2663
2664     /* AdminProperties */
2665     static const WCHAR stmname[] = {0x41ca,0x4330,0x3e71,0x44b5,0x4233,0x45f5,0x422c,0x4836,0};
2666     static const WCHAR data[] = {'M','Y','P','R','O','P','=','2','7','1','8',0};
2667
2668     MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, MAX_PATH);
2669
2670     hr = StgOpenStorage(fileW, NULL, mode, NULL, 0, &stg);
2671     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2672     if (!stg)
2673         return;
2674
2675     hr = IStorage_CreateStream(stg, stmname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
2676     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2677
2678     hr = IStream_Write(stm, data, sizeof(data) - 1, &count);
2679     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
2680
2681     IStream_Release(stm);
2682     IStorage_Release(stg);
2683 }
2684
2685 static void test_adminprops(void)
2686 {
2687     UINT r;
2688
2689     CreateDirectoryA("msitest", NULL);
2690     create_file("msitest\\augustus", 500);
2691
2692     create_database(msifile, amp_tables, sizeof(amp_tables) / sizeof(msi_table));
2693     set_admin_summary_info(msifile);
2694     set_admin_property_stream(msifile);
2695
2696     MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
2697
2698     r = MsiInstallProductA(msifile, NULL);
2699     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2700     ok(delete_pf("msitest\\augustus", TRUE), "File installed\n");
2701     ok(delete_pf("msitest", FALSE), "File installed\n");
2702
2703     DeleteFile(msifile);
2704     DeleteFile("msitest\\augustus");
2705     RemoveDirectory("msitest");
2706 }
2707
2708 START_TEST(install)
2709 {
2710     DWORD len;
2711     char temp_path[MAX_PATH], prev_path[MAX_PATH];
2712
2713     GetCurrentDirectoryA(MAX_PATH, prev_path);
2714     GetTempPath(MAX_PATH, temp_path);
2715     SetCurrentDirectoryA(temp_path);
2716
2717     lstrcpyA(CURR_DIR, temp_path);
2718     len = lstrlenA(CURR_DIR);
2719
2720     if(len && (CURR_DIR[len - 1] == '\\'))
2721         CURR_DIR[len - 1] = 0;
2722
2723     get_program_files_dir(PROG_FILES_DIR);
2724
2725     test_MsiInstallProduct();
2726     test_MsiSetComponentState();
2727     test_packagecoltypes();
2728     test_continuouscabs();
2729     test_caborder();
2730     test_mixedmedia();
2731     test_samesequence();
2732     test_uiLevelFlags();
2733     test_readonlyfile();
2734     test_setdirproperty();
2735     test_cabisextracted();
2736     test_concurrentinstall();
2737     test_setpropertyfolder();
2738     test_publish();
2739     test_publishsourcelist();
2740     test_transformprop();
2741     test_currentworkingdir();
2742     test_admin();
2743     test_adminprops();
2744
2745     SetCurrentDirectoryA(prev_path);
2746 }