msi: Also set the SOURCEDIR property in MSI_InstallPackage.
[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 admin_exec_seq_dat[] = "Action\tCondition\tSequence\n"
38                                          "s72\tS255\tI2\n"
39                                          "AdminExecuteSequence\tAction\n"
40                                          "CostFinalize\t\t1000\n"
41                                          "CostInitialize\t\t800\n"
42                                          "FileCost\t\t900\n"
43                                          "InstallAdminPackage\t\t3900\n"
44                                          "InstallFiles\t\t4000\n"
45                                          "InstallFinalize\t\t6600\n"
46                                          "InstallInitialize\t\t1500\n"
47                                          "InstallValidate\t\t1400";
48
49 static const CHAR advt_exec_seq_dat[] = "Action\tCondition\tSequence\n"
50                                         "s72\tS255\tI2\n"
51                                         "AdvtExecuteSequence\tAction\n"
52                                         "CostFinalize\t\t1000\n"
53                                         "CostInitialize\t\t800\n"
54                                         "CreateShortcuts\t\t4500\n"
55                                         "InstallFinalize\t\t6600\n"
56                                         "InstallInitialize\t\t1500\n"
57                                         "InstallValidate\t\t1400\n"
58                                         "PublishComponents\t\t6200\n"
59                                         "PublishFeatures\t\t6300\n"
60                                         "PublishProduct\t\t6400\n"
61                                         "RegisterClassInfo\t\t4600\n"
62                                         "RegisterExtensionInfo\t\t4700\n"
63                                         "RegisterMIMEInfo\t\t4900\n"
64                                         "RegisterProgIdInfo\t\t4800";
65
66 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
67                                     "s72\tS38\ts72\ti2\tS255\tS72\n"
68                                     "Component\tComponent\n"
69                                     "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
70                                     "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
71                                     "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
72                                     "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
73                                     "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
74                                     "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
75                                     "component\t\tTARGETDIR\t0\t1\tfile";
76
77 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
78                                     "s72\tS72\tl255\n"
79                                     "Directory\tDirectory\n"
80                                     "CABOUTDIR\tMSITESTDIR\tcabout\n"
81                                     "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
82                                     "FIRSTDIR\tMSITESTDIR\tfirst\n"
83                                     "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
84                                     "NEWDIR\tCABOUTDIR\tnew\n"
85                                     "ProgramFilesFolder\tTARGETDIR\t.\n"
86                                     "TARGETDIR\t\tSourceDir";
87
88 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
89                                   "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
90                                   "Feature\tFeature\n"
91                                   "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
92                                   "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
93                                   "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
94                                   "Three\t\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
95                                   "Two\t\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
96                                   "feature\t\t\t\t2\t1\tTARGETDIR\t0";
97
98 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
99                                        "s38\ts72\n"
100                                        "FeatureComponents\tFeature_\tComponent_\n"
101                                        "Five\tFive\n"
102                                        "Four\tFour\n"
103                                        "One\tOne\n"
104                                        "Three\tThree\n"
105                                        "Two\tTwo\n"
106                                        "feature\tcomponent";
107
108 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
109                                "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
110                                "File\tFile\n"
111                                "five.txt\tFive\tfive.txt\t1000\t\t\t16384\t5\n"
112                                "four.txt\tFour\tfour.txt\t1000\t\t\t16384\t4\n"
113                                "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
114                                "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
115                                "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
116                                "file\tcomponent\tfilename\t100\t\t\t8192\t1";
117
118 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
119                                            "s72\tS255\tI2\n"
120                                            "InstallExecuteSequence\tAction\n"
121                                            "AllocateRegistrySpace\tNOT Installed\t1550\n"
122                                            "CostFinalize\t\t1000\n"
123                                            "CostInitialize\t\t800\n"
124                                            "FileCost\t\t900\n"
125                                            "InstallFiles\t\t4000\n"
126                                            "InstallFinalize\t\t6600\n"
127                                            "InstallInitialize\t\t1500\n"
128                                            "InstallValidate\t\t1400\n"
129                                            "LaunchConditions\t\t100\n"
130                                            "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
131
132 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
133                                 "i2\ti4\tL64\tS255\tS32\tS72\n"
134                                 "Media\tDiskId\n"
135                                 "1\t3\t\t\tDISK1\t\n"
136                                 "2\t5\t\tmsitest.cab\tDISK2\t\n";
137
138 static const CHAR property_dat[] = "Property\tValue\n"
139                                    "s72\tl0\n"
140                                    "Property\tProperty\n"
141                                    "DefaultUIFont\tDlgFont8\n"
142                                    "INSTALLLEVEL\t3\n"
143                                    "InstallMode\tTypical\n"
144                                    "Manufacturer\tWine\n"
145                                    "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
146                                    "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
147                                    "ProductID\tnone\n"
148                                    "ProductLanguage\t1033\n"
149                                    "ProductName\tMSITEST\n"
150                                    "ProductVersion\t1.1.1\n"
151                                    "PROMPTROLLBACKCOST\tP\n"
152                                    "Setup\tSetup\n"
153                                    "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
154
155 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
156                                    "s72\ti2\tl255\tL255\tL0\ts72\n"
157                                    "Registry\tRegistry\n"
158                                    "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
159                                    "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
160                                    "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
161                                    "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
162
163 typedef struct _msi_table
164 {
165     const CHAR *filename;
166     const CHAR *data;
167     int size;
168 } msi_table;
169
170 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
171
172 static const msi_table tables[] =
173 {
174     ADD_TABLE(admin_exec_seq),
175     ADD_TABLE(advt_exec_seq),
176     ADD_TABLE(component),
177     ADD_TABLE(directory),
178     ADD_TABLE(feature),
179     ADD_TABLE(feature_comp),
180     ADD_TABLE(file),
181     ADD_TABLE(install_exec_seq),
182     ADD_TABLE(media),
183     ADD_TABLE(property),
184     ADD_TABLE(registry)
185 };
186
187 /* cabinet definitions */
188
189 /* make the max size large so there is only one cab file */
190 #define MEDIA_SIZE          999999999
191 #define FOLDER_THRESHOLD    900000
192
193 /* The following defintions were copied from dlls/cabinet/cabinet.h
194  * because they are undocumented in windows.
195  */
196
197 /* EXTRACTdest flags */
198 #define EXTRACT_FILLFILELIST  0x00000001
199 #define EXTRACT_EXTRACTFILES  0x00000002
200
201 struct ExtractFileList {
202     LPSTR  filename;
203     struct ExtractFileList *next;
204     BOOL   unknown;  /* always 1L */
205 };
206
207 /* the first parameter of the function extract */
208 typedef struct {
209     long   result1;          /* 0x000 */
210     long   unknown1[3];      /* 0x004 */
211     struct ExtractFileList *filelist; /* 0x010 */
212     long   filecount;        /* 0x014 */
213     long   flags;            /* 0x018 */
214     char   directory[0x104]; /* 0x01c */
215     char   lastfile[0x20c];  /* 0x120 */
216 } EXTRACTDEST;
217
218 /* cabinet function pointers */
219 HMODULE hCabinet;
220 static HRESULT (WINAPI *pExtract)(EXTRACTDEST*, LPCSTR);
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     return TRUE;
237 }
238
239 static long progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
240 {
241     return 0;
242 }
243
244 static int file_placed(PCCAB pccab, char *pszFile, long cbFile,
245                        BOOL fContinuation, void *pv)
246 {
247     return 0;
248 }
249
250 static INT_PTR fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
251 {
252     HANDLE handle;
253     DWORD dwAccess = 0;
254     DWORD dwShareMode = 0;
255     DWORD dwCreateDisposition = OPEN_EXISTING;
256     
257     dwAccess = GENERIC_READ | GENERIC_WRITE;
258     /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
259     dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
260
261     if (GetFileAttributesA(pszFile) != INVALID_FILE_ATTRIBUTES)
262         dwCreateDisposition = OPEN_EXISTING;
263     else
264         dwCreateDisposition = CREATE_NEW;
265
266     handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
267                          dwCreateDisposition, 0, NULL);
268
269     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
270
271     return (INT_PTR)handle;
272 }
273
274 static UINT fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
275 {
276     HANDLE handle = (HANDLE)hf;
277     DWORD dwRead;
278     BOOL res;
279     
280     res = ReadFile(handle, memory, cb, &dwRead, NULL);
281     ok(res, "Failed to ReadFile\n");
282
283     return dwRead;
284 }
285
286 static UINT fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
287 {
288     HANDLE handle = (HANDLE)hf;
289     DWORD dwWritten;
290     BOOL res;
291
292     res = WriteFile(handle, memory, cb, &dwWritten, NULL);
293     ok(res, "Failed to WriteFile\n");
294
295     return dwWritten;
296 }
297
298 static int fci_close(INT_PTR hf, int *err, void *pv)
299 {
300     HANDLE handle = (HANDLE)hf;
301     ok(CloseHandle(handle), "Failed to CloseHandle\n");
302
303     return 0;
304 }
305
306 static long fci_seek(INT_PTR hf, long dist, int seektype, int *err, void *pv)
307 {
308     HANDLE handle = (HANDLE)hf;
309     DWORD ret;
310     
311     ret = SetFilePointer(handle, dist, NULL, seektype);
312     ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
313
314     return ret;
315 }
316
317 static int fci_delete(char *pszFile, int *err, void *pv)
318 {
319     BOOL ret = DeleteFileA(pszFile);
320     ok(ret, "Failed to DeleteFile %s\n", pszFile);
321
322     return 0;
323 }
324
325 static BOOL check_record(MSIHANDLE rec, UINT field, LPCSTR val)
326 {
327     CHAR buffer[0x20];
328     UINT r;
329     DWORD sz;
330
331     sz = sizeof buffer;
332     r = MsiRecordGetString(rec, field, buffer, &sz);
333     return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
334 }
335
336 static BOOL get_temp_file(char *pszTempName, int cbTempName, void *pv)
337 {
338     LPSTR tempname;
339
340     tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
341     GetTempFileNameA(".", "xx", 0, tempname);
342
343     if (tempname && (strlen(tempname) < (unsigned)cbTempName))
344     {
345         lstrcpyA(pszTempName, tempname);
346         HeapFree(GetProcessHeap(), 0, tempname);
347         return TRUE;
348     }
349
350     HeapFree(GetProcessHeap(), 0, tempname);
351
352     return FALSE;
353 }
354
355 static INT_PTR get_open_info(char *pszName, USHORT *pdate, USHORT *ptime,
356                              USHORT *pattribs, int *err, void *pv)
357 {
358     BY_HANDLE_FILE_INFORMATION finfo;
359     FILETIME filetime;
360     HANDLE handle;
361     DWORD attrs;
362     BOOL res;
363
364     handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
365                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
366
367     ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
368
369     res = GetFileInformationByHandle(handle, &finfo);
370     ok(res, "Expected GetFileInformationByHandle to succeed\n");
371    
372     FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime);
373     FileTimeToDosDateTime(&filetime, pdate, ptime);
374
375     attrs = GetFileAttributes(pszName);
376     ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
377
378     return (INT_PTR)handle;
379 }
380
381 static void add_file(HFCI hfci, char *file)
382 {
383     char path[MAX_PATH];
384     BOOL res;
385
386     lstrcpyA(path, CURR_DIR);
387     lstrcatA(path, "\\");
388     lstrcatA(path, file);
389
390     res = FCIAddFile(hfci, path, file, FALSE, get_next_cabinet, progress,
391                      get_open_info, tcompTYPE_MSZIP);
392     ok(res, "Expected FCIAddFile to succeed\n");
393 }
394
395 static void set_cab_parameters(PCCAB pCabParams, const CHAR *name)
396 {
397     ZeroMemory(pCabParams, sizeof(CCAB));
398
399     pCabParams->cb = MEDIA_SIZE;
400     pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
401     pCabParams->setID = 0xbeef;
402     lstrcpyA(pCabParams->szCabPath, CURR_DIR);
403     lstrcatA(pCabParams->szCabPath, "\\");
404     lstrcpyA(pCabParams->szCab, name);
405 }
406
407 static void create_cab_file(const CHAR *name)
408 {
409     CCAB cabParams;
410     HFCI hfci;
411     ERF erf;
412     static CHAR four_txt[] = "four.txt",
413                 five_txt[] = "five.txt";
414     BOOL res;
415
416     set_cab_parameters(&cabParams, name);
417
418     hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
419                       fci_read, fci_write, fci_close, fci_seek, fci_delete,
420                       get_temp_file, &cabParams, NULL);
421
422     ok(hfci != NULL, "Failed to create an FCI context\n");
423
424     add_file(hfci, four_txt);
425     add_file(hfci, five_txt);
426
427     res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
428     ok(res, "Failed to flush the cabinet\n");
429
430     res = FCIDestroy(hfci);
431     ok(res, "Failed to destroy the cabinet\n");
432 }
433
434 static BOOL init_function_pointers(void)
435 {
436     hCabinet = LoadLibraryA("cabinet.dll");
437     if (!hCabinet)
438         return FALSE;
439
440     pExtract = (void *)GetProcAddress(hCabinet, "Extract");
441     if (!pExtract)
442         return FALSE;
443
444     return TRUE;
445 }
446
447 static BOOL get_program_files_dir(LPSTR buf)
448 {
449     HKEY hkey;
450     CHAR temp[MAX_PATH];
451     DWORD type = REG_EXPAND_SZ, size;
452
453     if (RegOpenKey(HKEY_LOCAL_MACHINE,
454                    "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
455         return FALSE;
456
457     size = MAX_PATH;
458     if (RegQueryValueEx(hkey, "ProgramFilesPath", 0, &type, (LPBYTE)temp, &size))
459         return FALSE;
460
461     ExpandEnvironmentStrings(temp, buf, MAX_PATH);
462
463     RegCloseKey(hkey);
464     return TRUE;
465 }
466
467 static void create_file(const CHAR *name)
468 {
469     HANDLE file;
470     DWORD written;
471
472     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
473     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
474     WriteFile(file, name, strlen(name), &written, NULL);
475     WriteFile(file, "\n", strlen("\n"), &written, NULL);
476     CloseHandle(file);
477 }
478
479 static void create_test_files(void)
480 {
481     get_program_files_dir(PROG_FILES_DIR);
482
483     CreateDirectoryA("msitest", NULL);
484     create_file("msitest\\one.txt");
485     CreateDirectoryA("msitest\\first", NULL);
486     create_file("msitest\\first\\two.txt");
487     CreateDirectoryA("msitest\\second", NULL);
488     create_file("msitest\\second\\three.txt");
489
490     create_file("four.txt");
491     create_file("five.txt");
492     create_cab_file("msitest.cab");
493
494     create_file("filename");
495
496     DeleteFileA("four.txt");
497     DeleteFileA("five.txt");
498 }
499
500 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
501 {
502     CHAR path[MAX_PATH];
503
504     lstrcpyA(path, PROG_FILES_DIR);
505     lstrcatA(path, "\\");
506     lstrcatA(path, rel_path);
507
508     if (is_file)
509         return DeleteFileA(path);
510     else
511         return RemoveDirectoryA(path);
512 }
513
514 static void delete_test_files(void)
515 {
516     DeleteFileA("filename");
517     DeleteFileA("msitest.msi");
518     DeleteFileA("msitest.cab");
519     DeleteFileA("msitest\\second\\three.txt");
520     DeleteFileA("msitest\\first\\two.txt");
521     DeleteFileA("msitest\\one.txt");
522     RemoveDirectoryA("msitest\\second");
523     RemoveDirectoryA("msitest\\first");
524     RemoveDirectoryA("msitest");
525 }
526
527 static void write_file(const CHAR *filename, const char *data, int data_size)
528 {
529     DWORD size;
530
531     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
532                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
533
534     WriteFile(hf, data, data_size, &size, NULL);
535     CloseHandle(hf);
536 }
537
538 static void write_msi_summary_info(MSIHANDLE db)
539 {
540     MSIHANDLE summary;
541     UINT r;
542
543     r = MsiGetSummaryInformationA(db, NULL, 4, &summary);
544     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
545
546     r = MsiSummaryInfoSetPropertyA(summary, PID_TEMPLATE, VT_LPSTR, 0, NULL, ";1033");
547     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
548
549     r = MsiSummaryInfoSetPropertyA(summary, PID_REVNUMBER, VT_LPSTR, 0, NULL,
550                                    "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
551     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
552
553     r = MsiSummaryInfoSetPropertyA(summary, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
554     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
555
556     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 0, NULL, NULL);
557     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
558
559     /* write the summary changes back to the stream */
560     r = MsiSummaryInfoPersist(summary);
561     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
562
563     MsiCloseHandle(summary);
564 }
565
566 static void create_database(const CHAR *name, const msi_table *tables, int num_tables)
567 {
568     MSIHANDLE db;
569     UINT r;
570     int j;
571
572     r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
573     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
574
575     /* import the tables into the database */
576     for (j = 0; j < num_tables; j++)
577     {
578         const msi_table *table = &tables[j];
579
580         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
581
582         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
583         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
584
585         DeleteFileA(table->filename);
586     }
587
588     write_msi_summary_info(db);
589
590     r = MsiDatabaseCommit(db);
591     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
592
593     MsiCloseHandle(db);
594 }
595
596 static void test_MsiInstallProduct(void)
597 {
598     UINT r;
599     CHAR path[MAX_PATH];
600     LONG res;
601     HKEY hkey;
602     DWORD num, size, type;
603
604     create_test_files();
605     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
606
607     r = MsiInstallProductA(msifile, NULL);
608     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
609
610     todo_wine
611     {
612         ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
613         ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
614         ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
615         ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
616         ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
617         ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
618         ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
619         ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
620         ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
621         ok(delete_pf("msitest", FALSE), "File not installed\n");
622     }
623
624     res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
625     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
626
627     size = MAX_PATH;
628     type = REG_SZ;
629     res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
630     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
631     ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
632
633     size = MAX_PATH;
634     type = REG_SZ;
635     res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
636     todo_wine
637     {
638         ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
639     }
640
641     size = sizeof(num);
642     type = REG_DWORD;
643     res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
644     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
645     ok(num == 314, "Expected 314, got %d\n", num);
646
647     size = MAX_PATH;
648     type = REG_SZ;
649     res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
650     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
651     ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
652
653
654     RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
655
656     delete_test_files();
657 }
658
659 static void test_MsiSetComponentState(void)
660 {
661     MSIHANDLE package;
662     char path[MAX_PATH];
663     UINT r;
664
665     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
666
667     CoInitialize(NULL);
668
669     lstrcpy(path, CURR_DIR);
670     lstrcat(path, "\\");
671     lstrcat(path, msifile);
672
673     r = MsiOpenPackage(path, &package);
674     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
675
676     r = MsiDoAction(package, "CostInitialize");
677     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
678
679     r = MsiDoAction(package, "FileCost");
680     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
681
682     r = MsiDoAction(package, "CostFinalize");
683     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
684
685     r = MsiSetComponentState(package, "dangler", INSTALLSTATE_SOURCE);
686     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
687
688     MsiCloseHandle(package);
689     CoUninitialize();
690
691     DeleteFileA(msifile);
692 }
693
694 static void test_packagecoltypes(void)
695 {
696     MSIHANDLE hdb, view, rec;
697     char path[MAX_PATH];
698     LPCSTR query;
699     UINT r, count;
700
701     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
702
703     CoInitialize(NULL);
704
705     lstrcpy(path, CURR_DIR);
706     lstrcat(path, "\\");
707     lstrcat(path, msifile);
708
709     r = MsiOpenDatabase(path, MSIDBOPEN_READONLY, &hdb);
710     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
711
712     query = "SELECT * FROM `Media`";
713     r = MsiDatabaseOpenView( hdb, query, &view );
714     ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
715
716     r = MsiViewGetColumnInfo( view, MSICOLINFO_NAMES, &rec );
717     count = MsiRecordGetFieldCount( rec );
718     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
719     ok(count == 6, "Expected 6, got %d\n", count);
720     ok(check_record(rec, 1, "DiskId"), "wrong column label\n");
721     ok(check_record(rec, 2, "LastSequence"), "wrong column label\n");
722     ok(check_record(rec, 3, "DiskPrompt"), "wrong column label\n");
723     ok(check_record(rec, 4, "Cabinet"), "wrong column label\n");
724     ok(check_record(rec, 5, "VolumeLabel"), "wrong column label\n");
725     ok(check_record(rec, 6, "Source"), "wrong column label\n");
726     MsiCloseHandle(rec);
727
728     r = MsiViewGetColumnInfo( view, MSICOLINFO_TYPES, &rec );
729     count = MsiRecordGetFieldCount( rec );
730     ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
731     ok(count == 6, "Expected 6, got %d\n", count);
732     ok(check_record(rec, 4, "S255"), "wrong column label\n");
733     ok(check_record(rec, 5, "S32"), "wrong column label\n");
734     ok(check_record(rec, 6, "S72"), "wrong column label\n");
735     todo_wine
736     {
737         ok(check_record(rec, 1, "i2"), "wrong column label\n");
738         ok(check_record(rec, 2, "i4"), "wrong column label\n");
739         ok(check_record(rec, 3, "L64"), "wrong column label\n");
740     }
741
742     MsiCloseHandle(rec);
743     MsiCloseHandle(view);
744     MsiCloseHandle(hdb);
745     DeleteFile(msifile);
746 }
747
748 START_TEST(install)
749 {
750     DWORD len;
751
752     if (!init_function_pointers())
753         return;
754
755     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
756     len = lstrlenA(CURR_DIR);
757
758     if(len && (CURR_DIR[len-1] == '\\'))
759         CURR_DIR[len - 1] = 0;
760
761     test_MsiInstallProduct();
762     test_MsiSetComponentState();
763     test_packagecoltypes();
764 }