msi: Allow UPDATE queries without a condition.
[wine] / dlls / msi / tests / install.c
1 /*
2  * Copyright (C) 2006 James Hawkins
3  *
4  * A test program for installing MSI products.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdio.h>
22
23 #include <windows.h>
24 #include <msiquery.h>
25 #include <msidefs.h>
26 #include <msi.h>
27 #include <fci.h>
28
29 #include "wine/test.h"
30
31 static const char *msifile = "winetest.msi";
32 CHAR CURR_DIR[MAX_PATH];
33 CHAR PROG_FILES_DIR[MAX_PATH];
34
35 /* msi database data */
36
37 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
38                                     "s72\tS38\ts72\ti2\tS255\tS72\n"
39                                     "Component\tComponent\n"
40                                     "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
41                                     "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
42                                     "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
43                                     "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
44                                     "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
45                                     "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
46                                     "component\t\tMSITESTDIR\t0\t1\tfile\n"
47                                     "service_comp\t\tMSITESTDIR\t0\t1\tservice_file";
48
49 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
50                                     "s72\tS72\tl255\n"
51                                     "Directory\tDirectory\n"
52                                     "CABOUTDIR\tMSITESTDIR\tcabout\n"
53                                     "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
54                                     "FIRSTDIR\tMSITESTDIR\tfirst\n"
55                                     "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
56                                     "NEWDIR\tCABOUTDIR\tnew\n"
57                                     "ProgramFilesFolder\tTARGETDIR\t.\n"
58                                     "TARGETDIR\t\tSourceDir";
59
60 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
61                                   "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
62                                   "Feature\tFeature\n"
63                                   "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
64                                   "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
65                                   "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
66                                   "Three\t\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
67                                   "Two\t\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
68                                   "feature\t\t\t\t2\t1\tTARGETDIR\t0\n"
69                                   "service_feature\t\t\t\t2\t1\tTARGETDIR\t0";
70
71 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
72                                        "s38\ts72\n"
73                                        "FeatureComponents\tFeature_\tComponent_\n"
74                                        "Five\tFive\n"
75                                        "Four\tFour\n"
76                                        "One\tOne\n"
77                                        "Three\tThree\n"
78                                        "Two\tTwo\n"
79                                        "feature\tcomponent\n"
80                                        "service_feature\tservice_comp\n";
81
82 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
83                                "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
84                                "File\tFile\n"
85                                "five.txt\tFive\tfive.txt\t1000\t\t\t16384\t5\n"
86                                "four.txt\tFour\tfour.txt\t1000\t\t\t16384\t4\n"
87                                "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
88                                "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
89                                "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
90                                "file\tcomponent\tfilename\t100\t\t\t8192\t1\n"
91                                "service_file\tservice_comp\tservice.exe\t100\t\t\t8192\t1";
92
93 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
94                                            "s72\tS255\tI2\n"
95                                            "InstallExecuteSequence\tAction\n"
96                                            "AllocateRegistrySpace\tNOT Installed\t1550\n"
97                                            "CostFinalize\t\t1000\n"
98                                            "CostInitialize\t\t800\n"
99                                            "FileCost\t\t900\n"
100                                            "InstallFiles\t\t4000\n"
101                                            "InstallServices\t\t5000\n"
102                                            "InstallFinalize\t\t6600\n"
103                                            "InstallInitialize\t\t1500\n"
104                                            "InstallValidate\t\t1400\n"
105                                            "LaunchConditions\t\t100\n"
106                                            "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
107
108 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
109                                 "i2\ti4\tL64\tS255\tS32\tS72\n"
110                                 "Media\tDiskId\n"
111                                 "1\t3\t\t\tDISK1\t\n"
112                                 "2\t5\t\tmsitest.cab\tDISK2\t\n";
113
114 static const CHAR property_dat[] = "Property\tValue\n"
115                                    "s72\tl0\n"
116                                    "Property\tProperty\n"
117                                    "DefaultUIFont\tDlgFont8\n"
118                                    "INSTALLLEVEL\t3\n"
119                                    "InstallMode\tTypical\n"
120                                    "Manufacturer\tWine\n"
121                                    "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
122                                    "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
123                                    "ProductID\tnone\n"
124                                    "ProductLanguage\t1033\n"
125                                    "ProductName\tMSITEST\n"
126                                    "ProductVersion\t1.1.1\n"
127                                    "PROMPTROLLBACKCOST\tP\n"
128                                    "Setup\tSetup\n"
129                                    "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
130
131 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
132                                    "s72\ti2\tl255\tL255\tL0\ts72\n"
133                                    "Registry\tRegistry\n"
134                                    "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
135                                    "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
136                                    "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
137                                    "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
138
139 static const CHAR service_install_dat[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
140                                           "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
141                                           "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
142                                           "ServiceInstall\tServiceInstall\n"
143                                           "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
144
145 static const CHAR service_control_dat[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
146                                           "s72\tl255\ti2\tL255\tI2\ts72\n"
147                                           "ServiceControl\tServiceControl\n"
148                                           "ServiceControl\tTestService\t8\t\t0\tservice_comp";
149
150 /* tables for test_continuouscabs */
151 static const CHAR cc_component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
152                                        "s72\tS38\ts72\ti2\tS255\tS72\n"
153                                        "Component\tComponent\n"
154                                        "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
155                                        "augustus\t\tMSITESTDIR\t0\t1\taugustus";
156
157 static const CHAR cc_feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
158                                      "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
159                                      "Feature\tFeature\n"
160                                      "feature\t\t\t\t2\t1\tTARGETDIR\t0";
161
162 static const CHAR cc_feature_comp_dat[] = "Feature_\tComponent_\n"
163                                           "s38\ts72\n"
164                                           "FeatureComponents\tFeature_\tComponent_\n"
165                                           "feature\tmaximus\n"
166                                           "feature\taugustus";
167
168 static const CHAR cc_file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
169                                   "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
170                                   "File\tFile\n"
171                                   "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
172                                   "augustus\taugustus\taugustus\t50000\t\t\t16384\t1";
173
174 static const CHAR cc_media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
175                                    "i2\ti4\tL64\tS255\tS32\tS72\n"
176                                    "Media\tDiskId\n"
177                                    "1\t10\t\ttest1.cab\tDISK1\t\n"
178                                    "2\t2\t\ttest2.cab\tDISK2\t\n";
179
180 typedef struct _msi_table
181 {
182     const CHAR *filename;
183     const CHAR *data;
184     int size;
185 } msi_table;
186
187 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
188
189 static const msi_table tables[] =
190 {
191     ADD_TABLE(component),
192     ADD_TABLE(directory),
193     ADD_TABLE(feature),
194     ADD_TABLE(feature_comp),
195     ADD_TABLE(file),
196     ADD_TABLE(install_exec_seq),
197     ADD_TABLE(media),
198     ADD_TABLE(property),
199     ADD_TABLE(registry),
200     ADD_TABLE(service_install),
201     ADD_TABLE(service_control)
202 };
203
204 static const msi_table cc_tables[] =
205 {
206     ADD_TABLE(cc_component),
207     ADD_TABLE(directory),
208     ADD_TABLE(cc_feature),
209     ADD_TABLE(cc_feature_comp),
210     ADD_TABLE(cc_file),
211     ADD_TABLE(install_exec_seq),
212     ADD_TABLE(cc_media),
213     ADD_TABLE(property),
214 };
215
216 /* cabinet definitions */
217
218 /* make the max size large so there is only one cab file */
219 #define MEDIA_SIZE          0x7FFFFFFF
220 #define FOLDER_THRESHOLD    900000
221
222 /* the FCI callbacks */
223
224 static void *mem_alloc(ULONG cb)
225 {
226     return HeapAlloc(GetProcessHeap(), 0, cb);
227 }
228
229 static void mem_free(void *memory)
230 {
231     HeapFree(GetProcessHeap(), 0, memory);
232 }
233
234 static BOOL get_next_cabinet(PCCAB pccab, ULONG  cbPrevCab, void *pv)
235 {
236     sprintf(pccab->szCab, pv, pccab->iCab);
237     return TRUE;
238 }
239
240 static long progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
241 {
242     return 0;
243 }
244
245 static int file_placed(PCCAB pccab, char *pszFile, long cbFile,
246                        BOOL fContinuation, void *pv)
247 {
248     return 0;
249 }
250
251 static INT_PTR fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
252 {
253     HANDLE handle;
254     DWORD dwAccess = 0;
255     DWORD dwShareMode = 0;
256     DWORD dwCreateDisposition = OPEN_EXISTING;
257     
258     dwAccess = GENERIC_READ | GENERIC_WRITE;
259     /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
260     dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
261
262     if (GetFileAttributesA(pszFile) != INVALID_FILE_ATTRIBUTES)
263         dwCreateDisposition = OPEN_EXISTING;
264     else
265         dwCreateDisposition = CREATE_NEW;
266
267     handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
268                          dwCreateDisposition, 0, NULL);
269
270     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
271
272     return (INT_PTR)handle;
273 }
274
275 static UINT fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
276 {
277     HANDLE handle = (HANDLE)hf;
278     DWORD dwRead;
279     BOOL res;
280     
281     res = ReadFile(handle, memory, cb, &dwRead, NULL);
282     ok(res, "Failed to ReadFile\n");
283
284     return dwRead;
285 }
286
287 static UINT fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
288 {
289     HANDLE handle = (HANDLE)hf;
290     DWORD dwWritten;
291     BOOL res;
292
293     res = WriteFile(handle, memory, cb, &dwWritten, NULL);
294     ok(res, "Failed to WriteFile\n");
295
296     return dwWritten;
297 }
298
299 static int fci_close(INT_PTR hf, int *err, void *pv)
300 {
301     HANDLE handle = (HANDLE)hf;
302     ok(CloseHandle(handle), "Failed to CloseHandle\n");
303
304     return 0;
305 }
306
307 static long fci_seek(INT_PTR hf, long dist, int seektype, int *err, void *pv)
308 {
309     HANDLE handle = (HANDLE)hf;
310     DWORD ret;
311     
312     ret = SetFilePointer(handle, dist, NULL, seektype);
313     ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
314
315     return ret;
316 }
317
318 static int fci_delete(char *pszFile, int *err, void *pv)
319 {
320     BOOL ret = DeleteFileA(pszFile);
321     ok(ret, "Failed to DeleteFile %s\n", pszFile);
322
323     return 0;
324 }
325
326 static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
327 {
328     CHAR buffer[0x20];
329     UINT r;
330     DWORD sz;
331
332     sz = sizeof buffer;
333     r = MsiRecordGetString(rec, field, buffer, &sz);
334     return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
335 }
336
337 static BOOL get_temp_file(char *pszTempName, int cbTempName, void *pv)
338 {
339     LPSTR tempname;
340
341     tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
342     GetTempFileNameA(".", "xx", 0, tempname);
343
344     if (tempname && (strlen(tempname) < (unsigned)cbTempName))
345     {
346         lstrcpyA(pszTempName, tempname);
347         HeapFree(GetProcessHeap(), 0, tempname);
348         return TRUE;
349     }
350
351     HeapFree(GetProcessHeap(), 0, tempname);
352
353     return FALSE;
354 }
355
356 static INT_PTR get_open_info(char *pszName, USHORT *pdate, USHORT *ptime,
357                              USHORT *pattribs, int *err, void *pv)
358 {
359     BY_HANDLE_FILE_INFORMATION finfo;
360     FILETIME filetime;
361     HANDLE handle;
362     DWORD attrs;
363     BOOL res;
364
365     handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
366                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
367
368     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
369
370     res = GetFileInformationByHandle(handle, &finfo);
371     ok(res, "Expected GetFileInformationByHandle to succeed\n");
372    
373     FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime);
374     FileTimeToDosDateTime(&filetime, pdate, ptime);
375
376     attrs = GetFileAttributes(pszName);
377     ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
378
379     return (INT_PTR)handle;
380 }
381
382 static BOOL add_file(HFCI hfci, const char *file, TCOMP compress)
383 {
384     char path[MAX_PATH];
385     char filename[MAX_PATH];
386
387     lstrcpyA(path, CURR_DIR);
388     lstrcatA(path, "\\");
389     lstrcatA(path, file);
390
391     lstrcpyA(filename, file);
392
393     return FCIAddFile(hfci, path, filename, FALSE, get_next_cabinet,
394                       progress, get_open_info, compress);
395 }
396
397 static void set_cab_parameters(PCCAB pCabParams, const CHAR *name, DWORD max_size)
398 {
399     ZeroMemory(pCabParams, sizeof(CCAB));
400
401     pCabParams->cb = max_size;
402     pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
403     pCabParams->setID = 0xbeef;
404     pCabParams->iCab = 1;
405     lstrcpyA(pCabParams->szCabPath, CURR_DIR);
406     lstrcatA(pCabParams->szCabPath, "\\");
407     lstrcpyA(pCabParams->szCab, name);
408 }
409
410 static void create_cab_file(const CHAR *name, DWORD max_size, const CHAR *files)
411 {
412     CCAB cabParams;
413     LPCSTR ptr;
414     HFCI hfci;
415     ERF erf;
416     BOOL res;
417
418     set_cab_parameters(&cabParams, name, max_size);
419
420     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
421                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
422                       get_temp_file, &cabParams, NULL);
423
424     ok(hfci != NULL, "Failed to create an FCI context\n");
425
426     ptr = files;
427     while (*ptr)
428     {
429         res = add_file(hfci, ptr, tcompTYPE_MSZIP);
430         ok(res, "Failed to add file: %s\n", ptr);
431         ptr += lstrlen(ptr) + 1;
432     }
433
434     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
435     ok(res, "Failed to flush the cabinet\n");
436
437     res = FCIDestroy(hfci);
438     ok(res, "Failed to destroy the cabinet\n");
439 }
440
441 static BOOL get_program_files_dir(LPSTR buf)
442 {
443     HKEY hkey;
444     DWORD type = REG_EXPAND_SZ, size;
445
446     if (RegOpenKey(HKEY_LOCAL_MACHINE,
447                    "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
448         return FALSE;
449
450     size = MAX_PATH;
451     if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
452         return FALSE;
453
454     RegCloseKey(hkey);
455     return TRUE;
456 }
457
458 static void create_file(const CHAR *name, DWORD size)
459 {
460     HANDLE file;
461     DWORD written, left;
462
463     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
464     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
465     WriteFile(file, name, strlen(name), &written, NULL);
466     WriteFile(file, "\n", strlen("\n"), &written, NULL);
467
468     left = size - lstrlen(name) - 1;
469
470     SetFilePointer(file, left, NULL, FILE_CURRENT);
471     SetEndOfFile(file);
472     
473     CloseHandle(file);
474 }
475
476 static void create_test_files(void)
477 {
478     CreateDirectoryA("msitest", NULL);
479     create_file("msitest\\one.txt", 100);
480     CreateDirectoryA("msitest\\first", NULL);
481     create_file("msitest\\first\\two.txt", 100);
482     CreateDirectoryA("msitest\\second", NULL);
483     create_file("msitest\\second\\three.txt", 100);
484
485     create_file("four.txt", 100);
486     create_file("five.txt", 100);
487     create_cab_file("msitest.cab", MEDIA_SIZE, "four.txt\0five.txt\0");
488
489     create_file("msitest\\filename", 100);
490     create_file("msitest\\service.exe", 100);
491
492     DeleteFileA("four.txt");
493     DeleteFileA("five.txt");
494 }
495
496 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
497 {
498     CHAR path[MAX_PATH];
499
500     lstrcpyA(path, PROG_FILES_DIR);
501     lstrcatA(path, "\\");
502     lstrcatA(path, rel_path);
503
504     if (is_file)
505         return DeleteFileA(path);
506     else
507         return RemoveDirectoryA(path);
508 }
509
510 static void delete_test_files(void)
511 {
512     DeleteFileA("msitest.msi");
513     DeleteFileA("msitest.cab");
514     DeleteFileA("msitest\\second\\three.txt");
515     DeleteFileA("msitest\\first\\two.txt");
516     DeleteFileA("msitest\\one.txt");
517     DeleteFileA("msitest\\service.exe");
518     DeleteFileA("msitest\\filename");
519     RemoveDirectoryA("msitest\\second");
520     RemoveDirectoryA("msitest\\first");
521     RemoveDirectoryA("msitest");
522 }
523
524 static void write_file(const CHAR *filename, const char *data, int data_size)
525 {
526     DWORD size;
527
528     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
529                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
530
531     WriteFile(hf, data, data_size, &size, NULL);
532     CloseHandle(hf);
533 }
534
535 static void write_msi_summary_info(MSIHANDLE db)
536 {
537     MSIHANDLE summary;
538     UINT r;
539
540     r = MsiGetSummaryInformationA(db, NULL, 4, &summary);
541     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
542
543     r = MsiSummaryInfoSetPropertyA(summary, PID_TEMPLATE, VT_LPSTR, 0, NULL, ";1033");
544     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
545
546     r = MsiSummaryInfoSetPropertyA(summary, PID_REVNUMBER, VT_LPSTR, 0, NULL,
547                                    "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
548     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
549
550     r = MsiSummaryInfoSetPropertyA(summary, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
551     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
552
553     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 0, NULL, NULL);
554     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
555
556     /* write the summary changes back to the stream */
557     r = MsiSummaryInfoPersist(summary);
558     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
559
560     MsiCloseHandle(summary);
561 }
562
563 static void create_database(const CHAR *name, const msi_table *tables, int num_tables)
564 {
565     MSIHANDLE db;
566     UINT r;
567     int j;
568
569     r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
570     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
571
572     /* import the tables into the database */
573     for (j = 0; j < num_tables; j++)
574     {
575         const msi_table *table = &tables[j];
576
577         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
578
579         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
580         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
581
582         DeleteFileA(table->filename);
583     }
584
585     write_msi_summary_info(db);
586
587     r = MsiDatabaseCommit(db);
588     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
589
590     MsiCloseHandle(db);
591 }
592
593 static void check_service_is_installed(void)
594 {
595     SC_HANDLE scm, service;
596     BOOL res;
597
598     scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
599     ok(scm != NULL, "Failed to open the SC Manager\n");
600
601     service = OpenService(scm, "TestService", SC_MANAGER_ALL_ACCESS);
602     ok(service != NULL, "Failed to open TestService\n");
603
604     res = DeleteService(service);
605     ok(res, "Failed to delete TestService\n");
606 }
607
608 static void test_MsiInstallProduct(void)
609 {
610     UINT r;
611     CHAR path[MAX_PATH];
612     LONG res;
613     HKEY hkey;
614     DWORD num, size, type;
615
616     create_test_files();
617     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
618
619     r = MsiInstallProductA(msifile, NULL);
620     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
621
622     ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
623     ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
624     ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
625     ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
626     ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
627     ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
628     ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
629     ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
630     ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
631     ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
632     ok(delete_pf("msitest\\service.exe", TRUE), "File not installed\n");
633     ok(delete_pf("msitest", FALSE), "File not installed\n");
634
635     res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
636     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
637
638     size = MAX_PATH;
639     type = REG_SZ;
640     res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
641     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
642     ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
643
644     size = MAX_PATH;
645     type = REG_SZ;
646     res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
647     ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
648
649     size = sizeof(num);
650     type = REG_DWORD;
651     res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
652     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
653     ok(num == 314, "Expected 314, got %d\n", num);
654
655     size = MAX_PATH;
656     type = REG_SZ;
657     res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
658     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
659     ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
660
661     check_service_is_installed();
662
663     RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
664
665     delete_test_files();
666 }
667
668 static void test_MsiSetComponentState(void)
669 {
670     INSTALLSTATE installed, action;
671     MSIHANDLE package;
672     char path[MAX_PATH];
673     UINT r;
674
675     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
676
677     CoInitialize(NULL);
678
679     lstrcpy(path, CURR_DIR);
680     lstrcat(path, "\\");
681     lstrcat(path, msifile);
682
683     r = MsiOpenPackage(path, &package);
684     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
685
686     r = MsiDoAction(package, "CostInitialize");
687     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
688
689     r = MsiDoAction(package, "FileCost");
690     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
691
692     r = MsiDoAction(package, "CostFinalize");
693     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
694
695     r = MsiGetComponentState(package, "dangler", &installed, &action);
696     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
697     ok(installed == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", installed);
698     ok(action == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action);
699
700     r = MsiSetComponentState(package, "dangler", INSTALLSTATE_SOURCE);
701     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
702
703     MsiCloseHandle(package);
704     CoUninitialize();
705
706     DeleteFileA(msifile);
707 }
708
709 static void test_packagecoltypes(void)
710 {
711     MSIHANDLE hdb, view, rec;
712     char path[MAX_PATH];
713     LPCSTR query;
714     UINT r, count;
715
716     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
717
718     CoInitialize(NULL);
719
720     lstrcpy(path, CURR_DIR);
721     lstrcat(path, "\\");
722     lstrcat(path, msifile);
723
724     r = MsiOpenDatabase(path, MSIDBOPEN_READONLY, &hdb);
725     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
726
727     query = "SELECT * FROM `Media`";
728     r = MsiDatabaseOpenView( hdb, query, &view );
729     ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
730
731     r = MsiViewGetColumnInfo( view, MSICOLINFO_NAMES, &rec );
732     count = MsiRecordGetFieldCount( rec );
733     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
734     ok(count == 6, "Expected 6, got %d\n", count);
735     ok(check_record(rec, 1, "DiskId"), "wrong column label\n");
736     ok(check_record(rec, 2, "LastSequence"), "wrong column label\n");
737     ok(check_record(rec, 3, "DiskPrompt"), "wrong column label\n");
738     ok(check_record(rec, 4, "Cabinet"), "wrong column label\n");
739     ok(check_record(rec, 5, "VolumeLabel"), "wrong column label\n");
740     ok(check_record(rec, 6, "Source"), "wrong column label\n");
741     MsiCloseHandle(rec);
742
743     r = MsiViewGetColumnInfo( view, MSICOLINFO_TYPES, &rec );
744     count = MsiRecordGetFieldCount( rec );
745     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
746     ok(count == 6, "Expected 6, got %d\n", count);
747     ok(check_record(rec, 1, "i2"), "wrong column label\n");
748     ok(check_record(rec, 2, "i4"), "wrong column label\n");
749     ok(check_record(rec, 3, "L64"), "wrong column label\n");
750     ok(check_record(rec, 4, "S255"), "wrong column label\n");
751     ok(check_record(rec, 5, "S32"), "wrong column label\n");
752     ok(check_record(rec, 6, "S72"), "wrong column label\n");
753
754     MsiCloseHandle(rec);
755     MsiCloseHandle(view);
756     MsiCloseHandle(hdb);
757     DeleteFile(msifile);
758 }
759
760 static void create_cc_test_files(void)
761 {
762     CCAB cabParams;
763     HFCI hfci;
764     ERF erf;
765     BOOL res;
766
767     create_file("maximus", 500);
768     create_file("augustus", 50000);
769
770     set_cab_parameters(&cabParams, "test1.cab", 200);
771
772     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
773                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
774                       get_temp_file, &cabParams, (void*)"test%d.cab");
775     ok(hfci != NULL, "Failed to create an FCI context\n");
776
777     /* spews out hundreds of cab files.  re-enable when cabinet.dll is fixed */
778 #if 0
779     res = add_file(hfci, "maximus", tcompTYPE_MSZIP);
780     ok(res, "Failed to add file maximus\n");
781
782     res = add_file(hfci, "augustus", tcompTYPE_MSZIP);
783     todo_wine
784     {
785         ok(res, "Failed to add file augustus\n");
786     }
787 #endif
788
789     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
790     ok(res, "Failed to flush the cabinet\n");
791
792     res = FCIDestroy(hfci);
793     ok(res, "Failed to destroy the cabinet\n");
794
795     DeleteFile("maximus");
796     DeleteFile("augustus");
797 }
798
799 static void test_continuouscabs(void)
800 {
801     UINT r;
802
803     create_cc_test_files();
804     create_database(msifile, cc_tables, sizeof(cc_tables) / sizeof(msi_table));
805
806     r = MsiInstallProductA(msifile, NULL);
807     todo_wine
808     {
809         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
810     }
811
812     todo_wine
813     {
814         ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n");
815         ok(delete_pf("msitest\\augustus", TRUE), "File not installed\n");
816     }
817     ok(delete_pf("msitest", FALSE), "File not installed\n");
818
819     DeleteFile("test1.cab");
820     DeleteFile("test2.cab");
821     DeleteFile(msifile);
822 }
823
824 START_TEST(install)
825 {
826     DWORD len;
827
828     get_program_files_dir(PROG_FILES_DIR);
829
830     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
831     len = lstrlenA(CURR_DIR);
832
833     if(len && (CURR_DIR[len-1] == '\\'))
834         CURR_DIR[len - 1] = 0;
835
836     test_MsiInstallProduct();
837     test_MsiSetComponentState();
838     test_packagecoltypes();
839     test_continuouscabs();
840 }