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"
120 "InstallMode\tTypical\n"
121 "Manufacturer\tWine\n"
122 "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
123 "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
125 "ProductLanguage\t1033\n"
126 "ProductName\tMSITEST\n"
127 "ProductVersion\t1.1.1\n"
128 "PROMPTROLLBACKCOST\tP\n"
130 "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
132 static const CHAR registry_dat
[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
133 "s72\ti2\tl255\tL255\tL0\ts72\n"
134 "Registry\tRegistry\n"
135 "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
136 "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
137 "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
138 "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
140 static const CHAR service_install_dat
[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
141 "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
142 "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
143 "ServiceInstall\tServiceInstall\n"
144 "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
146 static const CHAR service_control_dat
[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
147 "s72\tl255\ti2\tL255\tI2\ts72\n"
148 "ServiceControl\tServiceControl\n"
149 "ServiceControl\tTestService\t8\t\t0\tservice_comp";
151 /* tables for test_continuouscabs */
152 static const CHAR cc_component_dat
[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
153 "s72\tS38\ts72\ti2\tS255\tS72\n"
154 "Component\tComponent\n"
155 "maximus\t\tMSITESTDIR\t0\t1\tmaximus\n"
156 "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
157 "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
159 static const CHAR cc_feature_dat
[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
160 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
162 "feature\t\t\t\t2\t1\tTARGETDIR\t0";
164 static const CHAR cc_feature_comp_dat
[] = "Feature_\tComponent_\n"
166 "FeatureComponents\tFeature_\tComponent_\n"
168 "feature\taugustus\n"
171 static const CHAR cc_file_dat
[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
172 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
174 "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
175 "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
176 "caesar\tcaesar\tcaesar\t500\t\t\t16384\t12";
178 static const CHAR cc_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
179 "i2\ti4\tL64\tS255\tS32\tS72\n"
181 "1\t10\t\ttest1.cab\tDISK1\t\n"
182 "2\t2\t\ttest2.cab\tDISK2\t\n"
183 "3\t12\t\ttest3.cab\tDISK3\t\n";
185 static const CHAR co_file_dat
[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
186 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
188 "maximus\tmaximus\tmaximus\t500\t\t\t16384\t1\n"
189 "augustus\taugustus\taugustus\t50000\t\t\t16384\t2\n"
190 "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
192 static const CHAR co_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
193 "i2\ti4\tL64\tS255\tS32\tS72\n"
195 "1\t10\t\ttest1.cab\tDISK1\t\n"
196 "2\t2\t\ttest2.cab\tDISK2\t\n"
197 "3\t3\t\ttest3.cab\tDISK3\t\n";
199 static const CHAR co2_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
200 "i2\ti4\tL64\tS255\tS32\tS72\n"
202 "1\t10\t\ttest1.cab\tDISK1\t\n"
203 "2\t12\t\ttest3.cab\tDISK3\t\n"
204 "3\t2\t\ttest2.cab\tDISK2\t\n";
206 static const CHAR mm_file_dat
[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
207 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
209 "maximus\tmaximus\tmaximus\t500\t\t\t512\t1\n"
210 "augustus\taugustus\taugustus\t500\t\t\t512\t2\n"
211 "caesar\tcaesar\tcaesar\t500\t\t\t16384\t3";
213 static const CHAR mm_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
214 "i2\ti4\tL64\tS255\tS32\tS72\n"
216 "1\t3\t\ttest1.cab\tDISK1\t\n";
218 static const CHAR ss_media_dat
[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
219 "i2\ti4\tL64\tS255\tS32\tS72\n"
221 "1\t2\t\ttest1.cab\tDISK1\t\n"
222 "2\t2\t\ttest2.cab\tDISK2\t\n"
223 "3\t12\t\ttest3.cab\tDISK3\t\n";
225 /* tables for test_uiLevelFlags */
226 static const CHAR ui_component_dat
[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
227 "s72\tS38\ts72\ti2\tS255\tS72\n"
228 "Component\tComponent\n"
229 "maximus\t\tMSITESTDIR\t0\tHASUIRUN=1\tmaximus\n"
230 "augustus\t\tMSITESTDIR\t0\t1\taugustus\n"
231 "caesar\t\tMSITESTDIR\t0\t1\tcaesar\n";
233 static const CHAR ui_install_ui_seq_dat
[] = "Action\tCondition\tSequence\n"
235 "InstallUISequence\tAction\n"
236 "SetUIProperty\t\t5\n"
237 "ExecuteAction\t\t1100\n";
239 static const CHAR ui_custom_action_dat
[] = "Action\tType\tSource\tTarget\tISComments\n"
240 "s72\ti2\tS64\tS0\tS255\n"
241 "CustomAction\tAction\n"
242 "SetUIProperty\t51\tHASUIRUN\t1\t\n";
244 typedef struct _msi_table
246 const CHAR
*filename
;
251 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
253 static const msi_table tables
[] =
255 ADD_TABLE(component
),
256 ADD_TABLE(directory
),
258 ADD_TABLE(feature_comp
),
260 ADD_TABLE(install_exec_seq
),
264 ADD_TABLE(service_install
),
265 ADD_TABLE(service_control
)
268 static const msi_table cc_tables
[] =
270 ADD_TABLE(cc_component
),
271 ADD_TABLE(directory
),
272 ADD_TABLE(cc_feature
),
273 ADD_TABLE(cc_feature_comp
),
275 ADD_TABLE(install_exec_seq
),
280 static const msi_table co_tables
[] =
282 ADD_TABLE(cc_component
),
283 ADD_TABLE(directory
),
284 ADD_TABLE(cc_feature
),
285 ADD_TABLE(cc_feature_comp
),
287 ADD_TABLE(install_exec_seq
),
292 static const msi_table co2_tables
[] =
294 ADD_TABLE(cc_component
),
295 ADD_TABLE(directory
),
296 ADD_TABLE(cc_feature
),
297 ADD_TABLE(cc_feature_comp
),
299 ADD_TABLE(install_exec_seq
),
300 ADD_TABLE(co2_media
),
304 static const msi_table mm_tables
[] =
306 ADD_TABLE(cc_component
),
307 ADD_TABLE(directory
),
308 ADD_TABLE(cc_feature
),
309 ADD_TABLE(cc_feature_comp
),
311 ADD_TABLE(install_exec_seq
),
316 static const msi_table ss_tables
[] =
318 ADD_TABLE(cc_component
),
319 ADD_TABLE(directory
),
320 ADD_TABLE(cc_feature
),
321 ADD_TABLE(cc_feature_comp
),
323 ADD_TABLE(install_exec_seq
),
328 static const msi_table ui_tables
[] =
330 ADD_TABLE(ui_component
),
331 ADD_TABLE(directory
),
332 ADD_TABLE(cc_feature
),
333 ADD_TABLE(cc_feature_comp
),
335 ADD_TABLE(install_exec_seq
),
336 ADD_TABLE(ui_install_ui_seq
),
337 ADD_TABLE(ui_custom_action
),
342 /* cabinet definitions */
344 /* make the max size large so there is only one cab file */
345 #define MEDIA_SIZE 0x7FFFFFFF
346 #define FOLDER_THRESHOLD 900000
348 /* the FCI callbacks */
350 static void *mem_alloc(ULONG cb
)
352 return HeapAlloc(GetProcessHeap(), 0, cb
);
355 static void mem_free(void *memory
)
357 HeapFree(GetProcessHeap(), 0, memory
);
360 static BOOL
get_next_cabinet(PCCAB pccab
, ULONG cbPrevCab
, void *pv
)
362 sprintf(pccab
->szCab
, pv
, pccab
->iCab
);
366 static long progress(UINT typeStatus
, ULONG cb1
, ULONG cb2
, void *pv
)
371 static int file_placed(PCCAB pccab
, char *pszFile
, long cbFile
,
372 BOOL fContinuation
, void *pv
)
377 static INT_PTR
fci_open(char *pszFile
, int oflag
, int pmode
, int *err
, void *pv
)
381 DWORD dwShareMode
= 0;
382 DWORD dwCreateDisposition
= OPEN_EXISTING
;
384 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
385 /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
386 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
388 if (GetFileAttributesA(pszFile
) != INVALID_FILE_ATTRIBUTES
)
389 dwCreateDisposition
= OPEN_EXISTING
;
391 dwCreateDisposition
= CREATE_NEW
;
393 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
394 dwCreateDisposition
, 0, NULL
);
396 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszFile
);
398 return (INT_PTR
)handle
;
401 static UINT
fci_read(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
403 HANDLE handle
= (HANDLE
)hf
;
407 res
= ReadFile(handle
, memory
, cb
, &dwRead
, NULL
);
408 ok(res
, "Failed to ReadFile\n");
413 static UINT
fci_write(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
415 HANDLE handle
= (HANDLE
)hf
;
419 res
= WriteFile(handle
, memory
, cb
, &dwWritten
, NULL
);
420 ok(res
, "Failed to WriteFile\n");
425 static int fci_close(INT_PTR hf
, int *err
, void *pv
)
427 HANDLE handle
= (HANDLE
)hf
;
428 ok(CloseHandle(handle
), "Failed to CloseHandle\n");
433 static long fci_seek(INT_PTR hf
, long dist
, int seektype
, int *err
, void *pv
)
435 HANDLE handle
= (HANDLE
)hf
;
438 ret
= SetFilePointer(handle
, dist
, NULL
, seektype
);
439 ok(ret
!= INVALID_SET_FILE_POINTER
, "Failed to SetFilePointer\n");
444 static int fci_delete(char *pszFile
, int *err
, void *pv
)
446 BOOL ret
= DeleteFileA(pszFile
);
447 ok(ret
, "Failed to DeleteFile %s\n", pszFile
);
452 static BOOL
check_record(MSIHANDLE rec
, UINT field
, LPCSTR val
)
459 r
= MsiRecordGetString(rec
, field
, buffer
, &sz
);
460 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
463 static BOOL
get_temp_file(char *pszTempName
, int cbTempName
, void *pv
)
467 tempname
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
);
468 GetTempFileNameA(".", "xx", 0, tempname
);
470 if (tempname
&& (strlen(tempname
) < (unsigned)cbTempName
))
472 lstrcpyA(pszTempName
, tempname
);
473 HeapFree(GetProcessHeap(), 0, tempname
);
477 HeapFree(GetProcessHeap(), 0, tempname
);
482 static INT_PTR
get_open_info(char *pszName
, USHORT
*pdate
, USHORT
*ptime
,
483 USHORT
*pattribs
, int *err
, void *pv
)
485 BY_HANDLE_FILE_INFORMATION finfo
;
491 handle
= CreateFile(pszName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
492 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
494 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszName
);
496 res
= GetFileInformationByHandle(handle
, &finfo
);
497 ok(res
, "Expected GetFileInformationByHandle to succeed\n");
499 FileTimeToLocalFileTime(&finfo
.ftLastWriteTime
, &filetime
);
500 FileTimeToDosDateTime(&filetime
, pdate
, ptime
);
502 attrs
= GetFileAttributes(pszName
);
503 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Failed to GetFileAttributes\n");
505 return (INT_PTR
)handle
;
508 static BOOL
add_file(HFCI hfci
, const char *file
, TCOMP compress
)
511 char filename
[MAX_PATH
];
513 lstrcpyA(path
, CURR_DIR
);
514 lstrcatA(path
, "\\");
515 lstrcatA(path
, file
);
517 lstrcpyA(filename
, file
);
519 return FCIAddFile(hfci
, path
, filename
, FALSE
, get_next_cabinet
,
520 progress
, get_open_info
, compress
);
523 static void set_cab_parameters(PCCAB pCabParams
, const CHAR
*name
, DWORD max_size
)
525 ZeroMemory(pCabParams
, sizeof(CCAB
));
527 pCabParams
->cb
= max_size
;
528 pCabParams
->cbFolderThresh
= FOLDER_THRESHOLD
;
529 pCabParams
->setID
= 0xbeef;
530 pCabParams
->iCab
= 1;
531 lstrcpyA(pCabParams
->szCabPath
, CURR_DIR
);
532 lstrcatA(pCabParams
->szCabPath
, "\\");
533 lstrcpyA(pCabParams
->szCab
, name
);
536 static void create_cab_file(const CHAR
*name
, DWORD max_size
, const CHAR
*files
)
544 set_cab_parameters(&cabParams
, name
, max_size
);
546 hfci
= FCICreate(&erf
, file_placed
, mem_alloc
, mem_free
, fci_open
,
547 fci_read
, fci_write
, fci_close
, fci_seek
, fci_delete
,
548 get_temp_file
, &cabParams
, NULL
);
550 ok(hfci
!= NULL
, "Failed to create an FCI context\n");
555 res
= add_file(hfci
, ptr
, tcompTYPE_MSZIP
);
556 ok(res
, "Failed to add file: %s\n", ptr
);
557 ptr
+= lstrlen(ptr
) + 1;
560 res
= FCIFlushCabinet(hfci
, FALSE
, get_next_cabinet
, progress
);
561 ok(res
, "Failed to flush the cabinet\n");
563 res
= FCIDestroy(hfci
);
564 ok(res
, "Failed to destroy the cabinet\n");
567 static BOOL
get_program_files_dir(LPSTR buf
)
570 DWORD type
= REG_EXPAND_SZ
, size
;
572 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
573 "Software\\Microsoft\\Windows\\CurrentVersion", &hkey
))
577 if (RegQueryValueEx(hkey
, "ProgramFilesDir", 0, &type
, (LPBYTE
)buf
, &size
))
584 static void create_file(const CHAR
*name
, DWORD size
)
589 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
590 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
591 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
592 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
594 left
= size
- lstrlen(name
) - 1;
596 SetFilePointer(file
, left
, NULL
, FILE_CURRENT
);
602 static void create_test_files(void)
604 CreateDirectoryA("msitest", NULL
);
605 create_file("msitest\\one.txt", 100);
606 CreateDirectoryA("msitest\\first", NULL
);
607 create_file("msitest\\first\\two.txt", 100);
608 CreateDirectoryA("msitest\\second", NULL
);
609 create_file("msitest\\second\\three.txt", 100);
611 create_file("four.txt", 100);
612 create_file("five.txt", 100);
613 create_cab_file("msitest.cab", MEDIA_SIZE
, "four.txt\0five.txt\0");
615 create_file("msitest\\filename", 100);
616 create_file("msitest\\service.exe", 100);
618 DeleteFileA("four.txt");
619 DeleteFileA("five.txt");
622 static BOOL
delete_pf(const CHAR
*rel_path
, BOOL is_file
)
626 lstrcpyA(path
, PROG_FILES_DIR
);
627 lstrcatA(path
, "\\");
628 lstrcatA(path
, rel_path
);
631 return DeleteFileA(path
);
633 return RemoveDirectoryA(path
);
636 static void delete_test_files(void)
638 DeleteFileA("msitest.msi");
639 DeleteFileA("msitest.cab");
640 DeleteFileA("msitest\\second\\three.txt");
641 DeleteFileA("msitest\\first\\two.txt");
642 DeleteFileA("msitest\\one.txt");
643 DeleteFileA("msitest\\service.exe");
644 DeleteFileA("msitest\\filename");
645 RemoveDirectoryA("msitest\\second");
646 RemoveDirectoryA("msitest\\first");
647 RemoveDirectoryA("msitest");
650 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
654 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
655 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
657 WriteFile(hf
, data
, data_size
, &size
, NULL
);
661 static void write_msi_summary_info(MSIHANDLE db
)
666 r
= MsiGetSummaryInformationA(db
, NULL
, 4, &summary
);
667 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
669 r
= MsiSummaryInfoSetPropertyA(summary
, PID_TEMPLATE
, VT_LPSTR
, 0, NULL
, ";1033");
670 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
672 r
= MsiSummaryInfoSetPropertyA(summary
, PID_REVNUMBER
, VT_LPSTR
, 0, NULL
,
673 "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
674 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
676 r
= MsiSummaryInfoSetPropertyA(summary
, PID_PAGECOUNT
, VT_I4
, 100, NULL
, NULL
);
677 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
679 r
= MsiSummaryInfoSetPropertyA(summary
, PID_WORDCOUNT
, VT_I4
, 0, NULL
, NULL
);
680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
682 /* write the summary changes back to the stream */
683 r
= MsiSummaryInfoPersist(summary
);
684 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
686 MsiCloseHandle(summary
);
689 static void create_database(const CHAR
*name
, const msi_table
*tables
, int num_tables
)
695 r
= MsiOpenDatabaseA(name
, MSIDBOPEN_CREATE
, &db
);
696 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
698 /* import the tables into the database */
699 for (j
= 0; j
< num_tables
; j
++)
701 const msi_table
*table
= &tables
[j
];
703 write_file(table
->filename
, table
->data
, (table
->size
- 1) * sizeof(char));
705 r
= MsiDatabaseImportA(db
, CURR_DIR
, table
->filename
);
706 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
708 DeleteFileA(table
->filename
);
711 write_msi_summary_info(db
);
713 r
= MsiDatabaseCommit(db
);
714 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
719 static void check_service_is_installed(void)
721 SC_HANDLE scm
, service
;
724 scm
= OpenSCManager(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
725 ok(scm
!= NULL
, "Failed to open the SC Manager\n");
727 service
= OpenService(scm
, "TestService", SC_MANAGER_ALL_ACCESS
);
728 ok(service
!= NULL
, "Failed to open TestService\n");
730 res
= DeleteService(service
);
731 ok(res
, "Failed to delete TestService\n");
734 static void test_MsiInstallProduct(void)
740 DWORD num
, size
, type
;
743 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
745 r
= MsiInstallProductA(msifile
, NULL
);
746 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
748 ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE
), "File not installed\n");
749 ok(delete_pf("msitest\\cabout\\new", FALSE
), "File not installed\n");
750 ok(delete_pf("msitest\\cabout\\four.txt", TRUE
), "File not installed\n");
751 ok(delete_pf("msitest\\cabout", FALSE
), "File not installed\n");
752 ok(delete_pf("msitest\\changed\\three.txt", TRUE
), "File not installed\n");
753 ok(delete_pf("msitest\\changed", FALSE
), "File not installed\n");
754 ok(delete_pf("msitest\\first\\two.txt", TRUE
), "File not installed\n");
755 ok(delete_pf("msitest\\first", FALSE
), "File not installed\n");
756 ok(delete_pf("msitest\\one.txt", TRUE
), "File not installed\n");
757 ok(delete_pf("msitest\\filename", TRUE
), "File not installed\n");
758 ok(delete_pf("msitest\\service.exe", TRUE
), "File not installed\n");
759 ok(delete_pf("msitest", FALSE
), "File not installed\n");
761 res
= RegOpenKey(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Wine\\msitest", &hkey
);
762 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
766 res
= RegQueryValueExA(hkey
, "Name", NULL
, &type
, (LPBYTE
)path
, &size
);
767 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
768 ok(!lstrcmpA(path
, "imaname"), "Expected imaname, got %s\n", path
);
772 res
= RegQueryValueExA(hkey
, "blah", NULL
, &type
, (LPBYTE
)path
, &size
);
773 ok(res
== ERROR_FILE_NOT_FOUND
, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res
);
777 res
= RegQueryValueExA(hkey
, "number", NULL
, &type
, (LPBYTE
)&num
, &size
);
778 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
779 ok(num
== 314, "Expected 314, got %d\n", num
);
783 res
= RegQueryValueExA(hkey
, "OrderTestName", NULL
, &type
, (LPBYTE
)path
, &size
);
784 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
785 ok(!lstrcmpA(path
, "OrderTestValue"), "Expected imaname, got %s\n", path
);
787 check_service_is_installed();
789 RegDeleteKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Wine\\msitest");
794 static void test_MsiSetComponentState(void)
796 INSTALLSTATE installed
, action
;
801 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
805 lstrcpy(path
, CURR_DIR
);
807 lstrcat(path
, msifile
);
809 r
= MsiOpenPackage(path
, &package
);
810 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
812 r
= MsiDoAction(package
, "CostInitialize");
813 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
815 r
= MsiDoAction(package
, "FileCost");
816 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
818 r
= MsiDoAction(package
, "CostFinalize");
819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
821 r
= MsiGetComponentState(package
, "dangler", &installed
, &action
);
822 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
823 ok(installed
== INSTALLSTATE_ABSENT
, "Expected INSTALLSTATE_ABSENT, got %d\n", installed
);
824 ok(action
== INSTALLSTATE_UNKNOWN
, "Expected INSTALLSTATE_UNKNOWN, got %d\n", action
);
826 r
= MsiSetComponentState(package
, "dangler", INSTALLSTATE_SOURCE
);
827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
829 MsiCloseHandle(package
);
832 DeleteFileA(msifile
);
835 static void test_packagecoltypes(void)
837 MSIHANDLE hdb
, view
, rec
;
842 create_database(msifile
, tables
, sizeof(tables
) / sizeof(msi_table
));
846 lstrcpy(path
, CURR_DIR
);
848 lstrcat(path
, msifile
);
850 r
= MsiOpenDatabase(path
, MSIDBOPEN_READONLY
, &hdb
);
851 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
853 query
= "SELECT * FROM `Media`";
854 r
= MsiDatabaseOpenView( hdb
, query
, &view
);
855 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
857 r
= MsiViewGetColumnInfo( view
, MSICOLINFO_NAMES
, &rec
);
858 count
= MsiRecordGetFieldCount( rec
);
859 ok(r
== ERROR_SUCCESS
, "MsiViewGetColumnInfo failed\n");
860 ok(count
== 6, "Expected 6, got %d\n", count
);
861 ok(check_record(rec
, 1, "DiskId"), "wrong column label\n");
862 ok(check_record(rec
, 2, "LastSequence"), "wrong column label\n");
863 ok(check_record(rec
, 3, "DiskPrompt"), "wrong column label\n");
864 ok(check_record(rec
, 4, "Cabinet"), "wrong column label\n");
865 ok(check_record(rec
, 5, "VolumeLabel"), "wrong column label\n");
866 ok(check_record(rec
, 6, "Source"), "wrong column label\n");
869 r
= MsiViewGetColumnInfo( view
, MSICOLINFO_TYPES
, &rec
);
870 count
= MsiRecordGetFieldCount( rec
);
871 ok(r
== ERROR_SUCCESS
, "MsiViewGetColumnInfo failed\n");
872 ok(count
== 6, "Expected 6, got %d\n", count
);
873 ok(check_record(rec
, 1, "i2"), "wrong column label\n");
874 ok(check_record(rec
, 2, "i4"), "wrong column label\n");
875 ok(check_record(rec
, 3, "L64"), "wrong column label\n");
876 ok(check_record(rec
, 4, "S255"), "wrong column label\n");
877 ok(check_record(rec
, 5, "S32"), "wrong column label\n");
878 ok(check_record(rec
, 6, "S72"), "wrong column label\n");
881 MsiCloseHandle(view
);
886 static void create_cc_test_files(void)
891 static CHAR cab_context
[] = "test%d.cab";
894 create_file("maximus", 500);
895 create_file("augustus", 50000);
896 create_file("caesar", 500);
898 set_cab_parameters(&cabParams
, "test1.cab", 200);
900 hfci
= FCICreate(&erf
, file_placed
, mem_alloc
, mem_free
, fci_open
,
901 fci_read
, fci_write
, fci_close
, fci_seek
, fci_delete
,
902 get_temp_file
, &cabParams
, cab_context
);
903 ok(hfci
!= NULL
, "Failed to create an FCI context\n");
905 res
= add_file(hfci
, "maximus", tcompTYPE_MSZIP
);
906 ok(res
, "Failed to add file maximus\n");
908 res
= add_file(hfci
, "augustus", tcompTYPE_MSZIP
);
909 ok(res
, "Failed to add file augustus\n");
911 res
= FCIFlushCabinet(hfci
, FALSE
, get_next_cabinet
, progress
);
912 ok(res
, "Failed to flush the cabinet\n");
914 res
= FCIDestroy(hfci
);
915 ok(res
, "Failed to destroy the cabinet\n");
917 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
919 DeleteFile("maximus");
920 DeleteFile("augustus");
921 DeleteFile("caesar");
924 static void delete_cab_files(void)
929 lstrcpyA(path
, CURR_DIR
);
930 lstrcatA(path
, "\\*.cab\0");
933 shfl
.wFunc
= FO_DELETE
;
934 shfl
.pFrom
= (LPCSTR
)path
;
936 shfl
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_NORECURSION
| FOF_SILENT
;
938 SHFileOperation(&shfl
);
941 static void test_continuouscabs(void)
945 create_cc_test_files();
946 create_database(msifile
, cc_tables
, sizeof(cc_tables
) / sizeof(msi_table
));
948 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
950 r
= MsiInstallProductA(msifile
, NULL
);
951 ok(delete_pf("msitest\\maximus", TRUE
), "File not installed\n");
954 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
955 ok(delete_pf("msitest\\augustus", TRUE
), "File not installed\n");
956 ok(delete_pf("msitest\\caesar", TRUE
), "File not installed\n");
958 ok(delete_pf("msitest", FALSE
), "File not installed\n");
964 static void test_caborder(void)
968 create_file("imperator", 100);
969 create_file("maximus", 500);
970 create_file("augustus", 50000);
971 create_file("caesar", 500);
973 create_database(msifile
, cc_tables
, sizeof(cc_tables
) / sizeof(msi_table
));
975 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
977 create_cab_file("test1.cab", MEDIA_SIZE
, "maximus\0");
978 create_cab_file("test2.cab", MEDIA_SIZE
, "augustus\0");
979 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
981 r
= MsiInstallProductA(msifile
, NULL
);
982 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
983 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
984 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
987 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
988 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
993 create_cab_file("test1.cab", MEDIA_SIZE
, "imperator\0");
994 create_cab_file("test2.cab", MEDIA_SIZE
, "maximus\0augustus\0");
995 create_cab_file("test3.cab", MEDIA_SIZE
, "caesar\0");
997 r
= MsiInstallProductA(msifile
, NULL
);
998 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
999 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
1000 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
1001 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
1004 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
1008 DeleteFile(msifile
);
1010 create_cc_test_files();
1011 create_database(msifile
, co_tables
, sizeof(co_tables
) / sizeof(msi_table
));
1013 r
= MsiInstallProductA(msifile
, NULL
);
1014 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
1015 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
1016 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
1019 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
1020 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
1024 DeleteFile(msifile
);
1026 create_cc_test_files();
1027 create_database(msifile
, co2_tables
, sizeof(co2_tables
) / sizeof(msi_table
));
1029 r
= MsiInstallProductA(msifile
, NULL
);
1030 ok(!delete_pf("msitest\\augustus", TRUE
), "File is installed\n");
1031 ok(!delete_pf("msitest\\caesar", TRUE
), "File is installed\n");
1034 ok(r
== ERROR_INSTALL_FAILURE
, "Expected ERROR_INSTALL_FAILURE, got %u\n", r
);
1035 ok(!delete_pf("msitest\\maximus", TRUE
), "File is installed\n");
1036 ok(!delete_pf("msitest", FALSE
), "File is installed\n");
1040 DeleteFile("imperator");
1041 DeleteFile("maximus");
1042 DeleteFile("augustus");
1043 DeleteFile("caesar");
1044 DeleteFile(msifile
);
1047 static void test_mixedmedia(void)
1051 CreateDirectoryA("msitest", NULL
);
1052 create_file("msitest\\maximus", 500);
1053 create_file("msitest\\augustus", 500);
1054 create_file("caesar", 500);
1056 create_database(msifile
, mm_tables
, sizeof(mm_tables
) / sizeof(msi_table
));
1058 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
1060 create_cab_file("test1.cab", MEDIA_SIZE
, "caesar\0");
1062 r
= MsiInstallProductA(msifile
, NULL
);
1063 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1064 ok(delete_pf("msitest\\augustus", TRUE
), "File not installed\n");
1065 ok(delete_pf("msitest\\caesar", TRUE
), "File not installed\n");
1066 ok(delete_pf("msitest\\maximus", TRUE
), "File not installed\n");
1067 ok(delete_pf("msitest", FALSE
), "File not installed\n");
1069 DeleteFile("maximus");
1070 DeleteFile("augustus");
1071 DeleteFile("caesar");
1072 RemoveDirectory("msitest");
1073 DeleteFile("test1.cab");
1074 DeleteFile(msifile
);
1077 static void test_samesequence(void)
1081 create_cc_test_files();
1082 create_database(msifile
, ss_tables
, sizeof(ss_tables
) / sizeof(msi_table
));
1084 MsiSetInternalUI(INSTALLUILEVEL_NONE
, NULL
);
1086 r
= MsiInstallProductA(msifile
, NULL
);
1089 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1090 ok(delete_pf("msitest\\augustus", TRUE
), "File not installed\n");
1091 ok(delete_pf("msitest\\caesar", TRUE
), "File not installed\n");
1093 ok(delete_pf("msitest\\maximus", TRUE
), "File not installed\n");
1094 ok(delete_pf("msitest", FALSE
), "File not installed\n");
1097 DeleteFile(msifile
);
1100 static void test_uiLevelFlags(void)
1104 create_cc_test_files();
1105 create_database(msifile
, ui_tables
, sizeof(ui_tables
) / sizeof(msi_table
));
1107 MsiSetInternalUI(INSTALLUILEVEL_NONE
| INSTALLUILEVEL_SOURCERESONLY
, NULL
);
1109 r
= MsiInstallProductA(msifile
, NULL
);
1110 ok(!delete_pf("msitest\\maximus", TRUE
), "UI install occurred, but execute-only was requested.\n");
1113 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1114 ok(delete_pf("msitest\\augustus", TRUE
), "File not installed\n");
1115 ok(delete_pf("msitest\\caesar", TRUE
), "File not installed\n");
1117 delete_pf("msitest", FALSE
);
1120 DeleteFile(msifile
);
1126 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
1128 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
1129 GetTempPath(MAX_PATH
, temp_path
);
1130 SetCurrentDirectoryA(temp_path
);
1132 lstrcpyA(CURR_DIR
, temp_path
);
1133 len
= lstrlenA(CURR_DIR
);
1135 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
1136 CURR_DIR
[len
- 1] = 0;
1138 get_program_files_dir(PROG_FILES_DIR
);
1140 test_MsiInstallProduct();
1141 test_MsiSetComponentState();
1142 test_packagecoltypes();
1143 test_continuouscabs();
1146 test_samesequence();
1147 test_uiLevelFlags();
1149 SetCurrentDirectoryA(prev_path
);