2 * Copyright (C) 2006 James Hawkins
4 * A test program for installing MSI products.
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.
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.
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
29 #include "wine/test.h"
31 static const char *msifile
= "winetest.msi";
32 CHAR CURR_DIR
[MAX_PATH
];
33 CHAR PROG_FILES_DIR
[MAX_PATH
];
35 /* msi database data */
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";
49 static const CHAR directory_dat
[] = "Directory\tDirectory_Parent\tDefaultDir\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";
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"
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";
71 static const CHAR feature_comp_dat
[] = "Feature_\tComponent_\n"
73 "FeatureComponents\tFeature_\tComponent_\n"
79 "feature\tcomponent\n"
80 "service_feature\tservice_comp\n";
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"
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";
93 static const CHAR install_exec_seq_dat
[] = "Action\tCondition\tSequence\n"
95 "InstallExecuteSequence\tAction\n"
96 "AllocateRegistrySpace\tNOT Installed\t1550\n"
97 "CostFinalize\t\t1000\n"
98 "CostInitialize\t\t800\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";
108 static const CHAR media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
109 "i2\ti4\tL64\tS255\tS32\tS72\n"
111 "1\t3\t\t\tDISK1\t\n"
112 "2\t5\t\tmsitest.cab\tDISK2\t\n";
114 static const CHAR property_dat
[] = "Property\tValue\n"
116 "Property\tProperty\n"
117 "DefaultUIFont\tDlgFont8\n"
119 "InstallMode\tTypical\n"
120 "Manufacturer\tWine\n"
121 "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
122 "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
124 "ProductLanguage\t1033\n"
125 "ProductName\tMSITEST\n"
126 "ProductVersion\t1.1.1\n"
127 "PROMPTROLLBACKCOST\tP\n"
129 "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
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";
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";
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";
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\n"
156 "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
158 static const CHAR cc_feature_dat
[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
159 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
161 "feature\t\t\t\t2\t1\tTARGETDIR\t0";
163 static const CHAR cc_feature_comp_dat
[] = "Feature_\tComponent_\n"
165 "FeatureComponents\tFeature_\tComponent_\n"
167 "feature\taugustus\n"
170 static const CHAR cc_file_dat
[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
171 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
173 "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
174 "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
175 "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12";
177 static const CHAR cc_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
178 "i2\ti4\tL64\tS255\tS32\tS72\n"
180 "1\t10\t\ttest1.cab\tDISK1\t\n"
181 "2\t2\t\ttest2.cab\tDISK2\t\n"
182 "3\t12\t\ttest3.cab\tDISK3\t\n";
184 static const CHAR co_file_dat
[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
185 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
187 "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
188 "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
189 "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
191 static const CHAR co_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
192 "i2\ti4\tL64\tS255\tS32\tS72\n"
194 "1\t10\t\ttest1.cab\tDISK1\t\n"
195 "2\t2\t\ttest2.cab\tDISK2\t\n"
196 "3\t3\t\ttest3.cab\tDISK3\t\n";
198 static const CHAR co2_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
199 "i2\ti4\tL64\tS255\tS32\tS72\n"
201 "1\t10\t\ttest1.cab\tDISK1\t\n"
202 "2\t12\t\ttest3.cab\tDISK3\t\n"
203 "3\t2\t\ttest2.cab\tDISK2\t\n";
205 typedef struct _msi_table
207 const CHAR
*filename
;
212 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
214 static const msi_table tables
[] =
216 ADD_TABLE(component
),
217 ADD_TABLE(directory
),
219 ADD_TABLE(feature_comp
),
221 ADD_TABLE(install_exec_seq
),
225 ADD_TABLE(service_install
),
226 ADD_TABLE(service_control
)
229 static const msi_table cc_tables
[] =
231 ADD_TABLE(cc_component
),
232 ADD_TABLE(directory
),
233 ADD_TABLE(cc_feature
),
234 ADD_TABLE(cc_feature_comp
),
236 ADD_TABLE(install_exec_seq
),
241 static const msi_table co_tables
[] =
243 ADD_TABLE(cc_component
),
244 ADD_TABLE(directory
),
245 ADD_TABLE(cc_feature
),
246 ADD_TABLE(cc_feature_comp
),
248 ADD_TABLE(install_exec_seq
),
253 static const msi_table co2_tables
[] =
255 ADD_TABLE(cc_component
),
256 ADD_TABLE(directory
),
257 ADD_TABLE(cc_feature
),
258 ADD_TABLE(cc_feature_comp
),
260 ADD_TABLE(install_exec_seq
),
261 ADD_TABLE(co2_media
),
265 /* cabinet definitions */
267 /* make the max size large so there is only one cab file */
268 #define MEDIA_SIZE 0x7FFFFFFF
269 #define FOLDER_THRESHOLD 900000
271 /* the FCI callbacks */
273 static void *mem_alloc(ULONG cb
)
275 return HeapAlloc(GetProcessHeap(), 0, cb
);
278 static void mem_free(void *memory
)
280 HeapFree(GetProcessHeap(), 0, memory
);
283 static BOOL
get_next_cabinet(PCCAB pccab
, ULONG cbPrevCab
, void *pv
)
285 sprintf(pccab
->szCab
, pv
, pccab
->iCab
);
289 static long progress(UINT typeStatus
, ULONG cb1
, ULONG cb2
, void *pv
)
294 static int file_placed(PCCAB pccab
, char *pszFile
, long cbFile
,
295 BOOL fContinuation
, void *pv
)
300 static INT_PTR
fci_open(char *pszFile
, int oflag
, int pmode
, int *err
, void *pv
)
304 DWORD dwShareMode
= 0;
305 DWORD dwCreateDisposition
= OPEN_EXISTING
;
307 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
308 /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
309 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
311 if (GetFileAttributesA(pszFile
) != INVALID_FILE_ATTRIBUTES
)
312 dwCreateDisposition
= OPEN_EXISTING
;
314 dwCreateDisposition
= CREATE_NEW
;
316 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
317 dwCreateDisposition
, 0, NULL
);
319 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszFile
);
321 return (INT_PTR
)handle
;
324 static UINT
fci_read(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
326 HANDLE handle
= (HANDLE
)hf
;
330 res
= ReadFile(handle
, memory
, cb
, &dwRead
, NULL
);
331 ok(res
, "Failed to ReadFile\n");
336 static UINT
fci_write(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
338 HANDLE handle
= (HANDLE
)hf
;
342 res
= WriteFile(handle
, memory
, cb
, &dwWritten
, NULL
);
343 ok(res
, "Failed to WriteFile\n");
348 static int fci_close(INT_PTR hf
, int *err
, void *pv
)
350 HANDLE handle
= (HANDLE
)hf
;
351 ok(CloseHandle(handle
), "Failed to CloseHandle\n");
356 static long fci_seek(INT_PTR hf
, long dist
, int seektype
, int *err
, void *pv
)
358 HANDLE handle
= (HANDLE
)hf
;
361 ret
= SetFilePointer(handle
, dist
, NULL
, seektype
);
362 ok(ret
!= INVALID_SET_FILE_POINTER
, "Failed to SetFilePointer\n");
367 static int fci_delete(char *pszFile
, int *err
, void *pv
)
369 BOOL ret
= DeleteFileA(pszFile
);
370 ok(ret
, "Failed to DeleteFile %s\n", pszFile
);
375 static BOOL
check_record(MSIHANDLE rec
, UINT field
, LPCSTR val
)
382 r
= MsiRecordGetString(rec
, field
, buffer
, &sz
);
383 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
386 static BOOL
get_temp_file(char *pszTempName
, int cbTempName
, void *pv
)
390 tempname
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
);
391 GetTempFileNameA(".", "xx", 0, tempname
);
393 if (tempname
&& (strlen(tempname
) < (unsigned)cbTempName
))
395 lstrcpyA(pszTempName
, tempname
);
396 HeapFree(GetProcessHeap(), 0, tempname
);
400 HeapFree(GetProcessHeap(), 0, tempname
);
405 static INT_PTR
get_open_info(char *pszName
, USHORT
*pdate
, USHORT
*ptime
,
406 USHORT
*pattribs
, int *err
, void *pv
)
408 BY_HANDLE_FILE_INFORMATION finfo
;
414 handle
= CreateFile(pszName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
415 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
417 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszName
);
419 res
= GetFileInformationByHandle(handle
, &finfo
);
420 ok(res
, "Expected GetFileInformationByHandle to succeed\n");
422 FileTimeToLocalFileTime(&finfo
.ftLastWriteTime
, &filetime
);
423 FileTimeToDosDateTime(&filetime
, pdate
, ptime
);
425 attrs
= GetFileAttributes(pszName
);
426 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Failed to GetFileAttributes\n");
428 return (INT_PTR
)handle
;
431 static BOOL
add_file(HFCI hfci
, const char *file
, TCOMP compress
)
434 char filename
[MAX_PATH
];
436 lstrcpyA(path
, CURR_DIR
);
437 lstrcatA(path
, "\\");
438 lstrcatA(path
, file
);
440 lstrcpyA(filename
, file
);
442 return FCIAddFile(hfci
, path
, filename
, FALSE
, get_next_cabinet
,
443 progress
, get_open_info
, compress
);
446 static void set_cab_parameters(PCCAB pCabParams
, const CHAR
*name
, DWORD max_size
)
448 ZeroMemory(pCabParams
, sizeof(CCAB
));
450 pCabParams
->cb
= max_size
;
451 pCabParams
->cbFolderThresh
= FOLDER_THRESHOLD
;
452 pCabParams
->setID
= 0xbeef;
453 pCabParams
->iCab
= 1;
454 lstrcpyA(pCabParams
->szCabPath
, CURR_DIR
);
455 lstrcatA(pCabParams
->szCabPath
, "\\");
456 lstrcpyA(pCabParams
->szCab
, name
);
459 static void create_cab_file(const CHAR
*name
, DWORD max_size
, const CHAR
*files
)
467 set_cab_parameters(&cabParams
, name
, max_size
);
469 hfci
= FCICreate(&erf
, file_placed
, mem_alloc
, mem_free
, fci_open
,
470 fci_read
, fci_write
, fci_close
, fci_seek
, fci_delete
,
471 get_temp_file
, &cabParams
, NULL
);
473 ok(hfci
!= NULL
, "Failed to create an FCI context\n");
478 res
= add_file(hfci
, ptr
, tcompTYPE_MSZIP
);
479 ok(res
, "Failed to add file: %s\n", ptr
);
480 ptr
+= lstrlen(ptr
) + 1;
483 res
= FCIFlushCabinet(hfci
, FALSE
, get_next_cabinet
, progress
);
484 ok(res
, "Failed to flush the cabinet\n");
486 res
= FCIDestroy(hfci
);
487 ok(res
, "Failed to destroy the cabinet\n");
490 static BOOL
get_program_files_dir(LPSTR buf
)
493 DWORD type
= REG_EXPAND_SZ
, size
;
495 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
496 "Software\\Microsoft\\Windows\\CurrentVersion", &hkey
))
500 if (RegQueryValueEx(hkey
, "ProgramFilesDir", 0, &type
, (LPBYTE
)buf
, &size
))
507 static void create_file(const CHAR
*name
, DWORD size
)
512 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
513 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
514 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
515 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
517 left
= size
- lstrlen(name
) - 1;
519 SetFilePointer(file
, left
, NULL
, FILE_CURRENT
);
525 static void create_test_files(void)
527 CreateDirectoryA("msitest", NULL
);
528 create_file("msitest\\one.txt", 100);
529 CreateDirectoryA("msitest\\first", NULL
);
530 create_file("msitest\\first\\two.txt", 100);
531 CreateDirectoryA("msitest\\second", NULL
);
532 create_file("msitest\\second\\three.txt", 100);
534 create_file("four.txt", 100);
535 create_file("five.txt", 100);
536 create_cab_file("msitest.cab", MEDIA_SIZE
, "four.txt\0five.txt\0");
538 create_file("msitest\\filename", 100);
539 create_file("msitest\\service.exe", 100);
541 DeleteFileA("four.txt");
542 DeleteFileA("five.txt");
545 static BOOL
delete_pf(const CHAR
*rel_path
, BOOL is_file
)
549 lstrcpyA(path
, PROG_FILES_DIR
);
550 lstrcatA(path
, "\\");
551 lstrcatA(path
, rel_path
);
554 return DeleteFileA(path
);
556 return RemoveDirectoryA(path
);
559 static void delete_test_files(void)
561 DeleteFileA("msitest.msi");
562 DeleteFileA("msitest.cab");
563 DeleteFileA("msitest\\second\\three.txt");
564 DeleteFileA("msitest\\first\\two.txt");
565 DeleteFileA("msitest\\one.txt");
566 DeleteFileA("msitest\\service.exe");
567 DeleteFileA("msitest\\filename");
568 RemoveDirectoryA("msitest\\second");
569 RemoveDirectoryA("msitest\\first");
570 RemoveDirectoryA("msitest");
573 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
577 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
578 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
580 WriteFile(hf
, data
, data_size
, &size
, NULL
);
584 static void write_msi_summary_info(MSIHANDLE db
)
589 r
= MsiGetSummaryInformationA(db
, NULL
, 4, &summary
);
590 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
592 r
= MsiSummaryInfoSetPropertyA(summary
, PID_TEMPLATE
, VT_LPSTR
, 0, NULL
, ";1033");
593 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
595 r
= MsiSummaryInfoSetPropertyA(summary
, PID_REVNUMBER
, VT_LPSTR
, 0, NULL
,
596 "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
597 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
599 r
= MsiSummaryInfoSetPropertyA(summary
, PID_PAGECOUNT
, VT_I4
, 100, NULL
, NULL
);
600 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
602 r
= MsiSummaryInfoSetPropertyA(summary
, PID_WORDCOUNT
, VT_I4
, 0, NULL
, NULL
);
603 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
605 /* write the summary changes back to the stream */
606 r
= MsiSummaryInfoPersist(summary
);
607 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
609 MsiCloseHandle(summary
);
612 static void create_database(const CHAR
*name
, const msi_table
*tables
, int num_tables
)
618 r
= MsiOpenDatabaseA(name
, MSIDBOPEN_CREATE
, &db
);
619 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
621 /* import the tables into the database */
622 for (j
= 0; j
< num_tables
; j
++)
624 const msi_table
*table
= &tables
[j
];
626 write_file(table
->filename
, table
->data
, (table
->size
- 1) * sizeof(char));
628 r
= MsiDatabaseImportA(db
, CURR_DIR
, table
->filename
);
629 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
631 DeleteFileA(table
->filename
);
634 write_msi_summary_info(db
);
636 r
= MsiDatabaseCommit(db
);
637 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
642 static void check_service_is_installed(void)
644 SC_HANDLE scm
, service
;
647 scm
= OpenSCManager(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
648 ok(scm
!= NULL
, "Failed to open the SC Manager\n");
650 service
= OpenService(scm
, "TestService", SC_MANAGER_ALL_ACCESS
);
651 ok(service
!= NULL
, "Failed to open TestService\n");
653 res
= DeleteService(service
);
654 ok(res
, "Failed to delete TestService\n");
657 static void test_MsiInstallProduct(void)
663 DWORD num
, size
, type
;
666 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
668 r
= MsiInstallProductA(msifile
, NULL
);
669 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
671 ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE
), "File not installed\n");
672 ok(delete_pf("msitest\\cabout\\new", FALSE
), "File not installed\n");
673 ok(delete_pf("msitest\\cabout\\four.txt", TRUE
), "File not installed\n");
674 ok(delete_pf("msitest\\cabout", FALSE
), "File not installed\n");
675 ok(delete_pf("msitest\\changed\\three.txt", TRUE
), "File not installed\n");
676 ok(delete_pf("msitest\\changed", FALSE
), "File not installed\n");
677 ok(delete_pf("msitest\\first\\two.txt", TRUE
), "File not installed\n");
678 ok(delete_pf("msitest\\first", FALSE
), "File not installed\n");
679 ok(delete_pf("msitest\\one.txt", TRUE
), "File not installed\n");
680 ok(delete_pf("msitest\\filename", TRUE
), "File not installed\n");
681 ok(delete_pf("msitest\\service.exe", TRUE
), "File not installed\n");
682 ok(delete_pf("msitest", FALSE
), "File not installed\n");
684 res
= RegOpenKey(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Wine\\msitest", &hkey
);
685 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
689 res
= RegQueryValueExA(hkey
, "Name", NULL
, &type
, (LPBYTE
)path
, &size
);
690 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
691 ok(!lstrcmpA(path
, "imaname"), "Expected imaname, got %s\n", path
);
695 res
= RegQueryValueExA(hkey
, "blah", NULL
, &type
, (LPBYTE
)path
, &size
);
696 ok(res
== ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res
);
700 res
= RegQueryValueExA(hkey
, "number", NULL
, &type
, (LPBYTE
)&num
, &size
);
701 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
702 ok(num
== 314, "Expected 314, got %d\n", num
);
706 res
= RegQueryValueExA(hkey
, "OrderTestName", NULL
, &type
, (LPBYTE
)path
, &size
);
707 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
708 ok(!lstrcmpA(path
, "OrderTestValue"), "Expected imaname, got %s\n", path
);
710 check_service_is_installed();
712 RegDeleteKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Wine\\msitest");
717 static void test_MsiSetComponentState(void)
719 INSTALLSTATE installed
, action
;
724 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
728 lstrcpy(path
, CURR_DIR
);
730 lstrcat(path
, msifile
);
732 r
= MsiOpenPackage(path
, &package
);
733 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
735 r
= MsiDoAction(package
, "CostInitialize");
736 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
738 r
= MsiDoAction(package
, "FileCost");
739 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
741 r
= MsiDoAction(package
, "CostFinalize");
742 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
744 r
= MsiGetComponentState(package
, "dangler", &installed
, &action
);
745 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
746 ok(installed
== INSTALLSTATE_ABSENT
, "Expected INSTALLSTATE_ABSENT, got %d\n", installed
);
747 ok(action
== INSTALLSTATE_UNKNOWN
, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action
);
749 r
= MsiSetComponentState(package
, "dangler", INSTALLSTATE_SOURCE
);
750 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
752 MsiCloseHandle(package
);
755 DeleteFileA(msifile
);
758 static void test_packagecoltypes(void)
760 MSIHANDLE hdb
, view
, rec
;
765 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
769 lstrcpy(path
, CURR_DIR
);
771 lstrcat(path
, msifile
);
773 r
= MsiOpenDatabase(path
, MSIDBOPEN_READONLY
, &hdb
);
774 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
776 query
= "SELECT * FROM `Media`";
777 r
= MsiDatabaseOpenView( hdb
, query
, &view
);
778 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
780 r
= MsiViewGetColumnInfo( view
, MSICOLINFO_NAMES
, &rec
);
781 count
= MsiRecordGetFieldCount( rec
);
782 ok(r
== ERROR_SUCCESS
, "MsiViewGetColumnInfo failed\n");
783 ok(count
== 6, "Expected 6, got %d\n", count
);
784 ok(check_record(rec
, 1, "DiskId"), "wrong column label\n");
785 ok(check_record(rec
, 2, "LastSequence"), "wrong column label\n");
786 ok(check_record(rec
, 3, "DiskPrompt"), "wrong column label\n");
787 ok(check_record(rec
, 4, "Cabinet"), "wrong column label\n");
788 ok(check_record(rec
, 5, "VolumeLabel"), "wrong column label\n");
789 ok(check_record(rec
, 6, "Source"), "wrong column label\n");
792 r
= MsiViewGetColumnInfo( view
, MSICOLINFO_TYPES
, &rec
);
793 count
= MsiRecordGetFieldCount( rec
);
794 ok(r
== ERROR_SUCCESS
, "MsiViewGetColumnInfo failed\n");
795 ok(count
== 6, "Expected 6, got %d\n", count
);
796 ok(check_record(rec
, 1, "i2"), "wrong column label\n");
797 ok(check_record(rec
, 2, "i4"), "wrong column label\n");
798 ok(check_record(rec
, 3, "L64"), "wrong column label\n");
799 ok(check_record(rec
, 4, "S255"), "wrong column label\n");
800 ok(check_record(rec
, 5, "S32"), "wrong column label\n");
801 ok(check_record(rec
, 6, "S72"), "wrong column label\n");
804 MsiCloseHandle(view
);
809 static void create_cc_test_files(void)
814 static CHAR cab_context
[] = "test%d.cab";
817 create_file("maximus", 500);
818 create_file("augustus", 50000);
819 create_file("caesar", 500);
821 set_cab_parameters(&cabParams
, "test1.cab", 200);
823 hfci
= FCICreate(&erf
, file_placed
, mem_alloc
, mem_free
, fci_open
,
824 fci_read
, fci_write
, fci_close
, fci_seek
, fci_delete
,
825 get_temp_file
, &cabParams
, cab_context
);
826 ok(hfci
!= NULL
, "Failed to create an FCI context\n");
828 res
= add_file(hfci
, "maximus", tcompTYPE_MSZIP
);
829 ok(res
, "Failed to add file maximus\n");
831 res
= add_file(hfci
, "augustus", tcompTYPE_MSZIP
);
832 ok(res
, "Failed to add file augustus\n");
834 res
= FCIFlushCabinet(hfci
, FALSE
, get_next_cabinet
, progress
);
835 ok(res
, "Failed to flush the cabinet\n");
837 res
= FCIDestroy(hfci
);
838 ok(res
, "Failed to destroy the cabinet\n");
840 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
842 DeleteFile("maximus");
843 DeleteFile("augustus");
844 DeleteFile("caesar");
847 static void delete_cab_files(void)
852 lstrcpyA(path
, CURR_DIR
);
853 lstrcatA(path
, "\\*.cab\0");
856 shfl
.wFunc
= FO_DELETE
;
857 shfl
.pFrom
= (LPCSTR
)path
;
859 shfl
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_NORECURSION
| FOF_SILENT
;
861 SHFileOperation(&shfl
);
864 static void test_continuouscabs(void)
868 create_cc_test_files();
869 create_database(msifile
, cc_tables
, sizeof(cc_tables
) / sizeof(msi_table
));
871 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
873 r
= MsiInstallProductA(msifile
, NULL
);
874 ok(delete_pf("msitest\\maximus", TRUE
), "File not installed\n");
877 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
878 ok(delete_pf("msitest\\augustus", TRUE
), "File not installed\n");
879 ok(delete_pf("msitest\\caesar", TRUE
), "File not installed\n");
881 ok(delete_pf("msitest", FALSE
), "File not installed\n");
887 static void test_caborder(void)
891 create_file("imperator", 100);
892 create_file("maximus", 500);
893 create_file("augustus", 50000);
894 create_file("caesar", 500);
896 create_database(msifile
, cc_tables
, sizeof(cc_tables
) / sizeof(msi_table
));
898 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
900 create_cab_file("test1.cab", MEDIA_SIZE
, "maximus\0");
901 create_cab_file("test2.cab", MEDIA_SIZE
, "augustus\0");
902 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
904 r
= MsiInstallProductA(msifile
, NULL
);
905 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
906 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
907 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
910 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
911 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
916 create_cab_file("test1.cab", MEDIA_SIZE
, "imperator\0");
917 create_cab_file("test2.cab", MEDIA_SIZE
, "maximus\0augustus\0");
918 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
920 r
= MsiInstallProductA(msifile
, NULL
);
921 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
922 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
923 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
924 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
927 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
933 create_cc_test_files();
934 create_database(msifile
, co_tables
, sizeof(co_tables
) / sizeof(msi_table
));
936 r
= MsiInstallProductA(msifile
, NULL
);
937 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
938 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
939 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
942 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
943 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
949 create_cc_test_files();
950 create_database(msifile
, co2_tables
, sizeof(co2_tables
) / sizeof(msi_table
));
952 r
= MsiInstallProductA(msifile
, NULL
);
953 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
954 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
957 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
958 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
959 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
963 DeleteFile("imperator");
964 DeleteFile("maximus");
965 DeleteFile("augustus");
966 DeleteFile("caesar");
973 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
975 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
976 GetTempPath(MAX_PATH
, temp_path
);
977 SetCurrentDirectoryA(temp_path
);
979 lstrcpyA(CURR_DIR
, temp_path
);
980 len
= lstrlenA(CURR_DIR
);
982 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
983 CURR_DIR
[len
- 1] = 0;
985 get_program_files_dir(PROG_FILES_DIR
);
987 test_MsiInstallProduct();
988 test_MsiSetComponentState();
989 test_packagecoltypes();
990 test_continuouscabs();
993 SetCurrentDirectoryA(prev_path
);