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