2 * Copyright (C) 2007 Mike McCormack for CodeWeavers
3 * Copyright (C) 2007 Misha Koshelev
5 * A test program for Microsoft Installer OLE automation functionality.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
37 static const char *msifile = "winetest-automation.msi";
38 static const WCHAR szMsifile[] = {'w','i','n','e','t','e','s','t','-','a','u','t','o','m','a','t','i','o','n','.','m','s','i',0};
39 static const WCHAR szMSITEST[] = { 'M','S','I','T','E','S','T',0 };
40 static const WCHAR szProductCode[] = { '{','F','1','C','3','A','F','5','0','-','8','B','5','6','-','4','A','6','9','-','A','0','0','C','-','0','0','7','7','3','F','E','4','2','F','3','0','}',0 };
41 static const WCHAR szUpgradeCode[] = { '{','C','E','0','6','7','E','8','D','-','2','E','1','A','-','4','3','6','7','-','B','7','3','4','-','4','E','B','2','B','D','A','D','6','5','6','5','}',0 };
42 static const WCHAR szProductInfoException[] = { 'P','r','o','d','u','c','t','I','n','f','o',',','P','r','o','d','u','c','t',',','A','t','t','r','i','b','u','t','e',0 };
43 static const WCHAR WINE_INSTALLPROPERTY_PACKAGENAMEW[] = {'P','a','c','k','a','g','e','N','a','m','e',0};
44 static const WCHAR WINE_INSTALLPROPERTY_PRODUCTNAMEW[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
45 static FILETIME systemtime;
46 static CHAR CURR_DIR[MAX_PATH];
47 static EXCEPINFO excepinfo;
52 static const WCHAR szProgId[] = { 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r','.','I','n','s','t','a','l','l','e','r',0 };
53 static IDispatch *pInstaller;
55 /* msi database data */
57 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
58 "s72\tS38\ts72\ti2\tS255\tS72\n"
59 "Component\tComponent\n"
60 "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
61 "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
62 "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
63 "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
64 "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
65 "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
66 "component\t\tMSITESTDIR\t0\t1\tfile\n";
68 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
70 "Directory\tDirectory\n"
71 "CABOUTDIR\tMSITESTDIR\tcabout\n"
72 "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
73 "FIRSTDIR\tMSITESTDIR\tfirst\n"
74 "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
75 "NEWDIR\tCABOUTDIR\tnew\n"
76 "ProgramFilesFolder\tTARGETDIR\t.\n"
77 "TARGETDIR\t\tSourceDir";
79 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
80 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
82 "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
83 "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
84 "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
85 "Three\tOne\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
86 "Two\tOne\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
87 "feature\t\t\t\t2\t1\tTARGETDIR\t0\n";
89 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
91 "FeatureComponents\tFeature_\tComponent_\n"
97 "feature\tcomponent\n";
99 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
100 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
102 "five.txt\tFive\tfive.txt\t1000\t\t\t0\t5\n"
103 "four.txt\tFour\tfour.txt\t1000\t\t\t0\t4\n"
104 "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
105 "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
106 "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
107 "file\tcomponent\tfilename\t100\t\t\t8192\t1\n";
109 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
111 "InstallExecuteSequence\tAction\n"
112 "AllocateRegistrySpace\tNOT Installed\t1550\n"
113 "CostFinalize\t\t1000\n"
114 "CostInitialize\t\t800\n"
116 "InstallFiles\t\t4000\n"
117 "RegisterProduct\t\t6100\n"
118 "PublishProduct\t\t6400\n"
119 "InstallFinalize\t\t6600\n"
120 "InstallInitialize\t\t1500\n"
121 "InstallValidate\t\t1400\n"
122 "LaunchConditions\t\t100\n"
123 "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
125 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
126 "i2\ti4\tL64\tS255\tS32\tS72\n"
128 "1\t5\t\t\tDISK1\t\n";
130 static const CHAR property_dat[] = "Property\tValue\n"
132 "Property\tProperty\n"
133 "DefaultUIFont\tDlgFont8\n"
136 "InstallMode\tTypical\n"
137 "Manufacturer\tWine\n"
138 "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
139 "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
141 "ProductLanguage\t1033\n"
142 "ProductName\tMSITEST\n"
143 "ProductVersion\t1.1.1\n"
144 "PROMPTROLLBACKCOST\tP\n"
146 "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
148 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
149 "s72\ti2\tl255\tL255\tL0\ts72\n"
150 "Registry\tRegistry\n"
151 "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
152 "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
153 "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
154 "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
156 typedef struct _msi_table
158 const CHAR *filename;
163 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
165 static const msi_table tables[] =
167 ADD_TABLE(component),
168 ADD_TABLE(directory),
170 ADD_TABLE(feature_comp),
172 ADD_TABLE(install_exec_seq),
178 typedef struct _msi_summary_info
187 #define ADD_INFO_I2(property, iValue) {property, VT_I2, iValue, NULL, NULL}
188 #define ADD_INFO_I4(property, iValue) {property, VT_I4, iValue, NULL, NULL}
189 #define ADD_INFO_LPSTR(property, szValue) {property, VT_LPSTR, 0, NULL, szValue}
190 #define ADD_INFO_FILETIME(property, pftValue) {property, VT_FILETIME, 0, pftValue, NULL}
192 static const msi_summary_info summary_info[] =
194 ADD_INFO_LPSTR(PID_TEMPLATE, ";1033"),
195 ADD_INFO_LPSTR(PID_REVNUMBER, "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}"),
196 ADD_INFO_I4(PID_PAGECOUNT, 100),
197 ADD_INFO_I4(PID_WORDCOUNT, 0),
198 ADD_INFO_FILETIME(PID_CREATE_DTM, &systemtime),
199 ADD_INFO_FILETIME(PID_LASTPRINTED, &systemtime)
206 static void write_file(const CHAR *filename, const char *data, int data_size)
210 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
211 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
213 WriteFile(hf, data, data_size, &size, NULL);
217 static void write_msi_summary_info(MSIHANDLE db, const msi_summary_info *info, int num_info)
223 r = MsiGetSummaryInformationA(db, NULL, num_info, &summary);
224 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
226 /* import summary information into the stream */
227 for (j = 0; j < num_info; j++)
229 const msi_summary_info *entry = &info[j];
231 r = MsiSummaryInfoSetPropertyA(summary, entry->property, entry->datatype,
232 entry->iValue, entry->pftValue, entry->szValue);
233 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
236 /* write the summary changes back to the stream */
237 r = MsiSummaryInfoPersist(summary);
238 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
240 MsiCloseHandle(summary);
243 static void create_database(const CHAR *name, const msi_table *tables, int num_tables,
244 const msi_summary_info *info, int num_info)
250 r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
253 /* import the tables into the database */
254 for (j = 0; j < num_tables; j++)
256 const msi_table *table = &tables[j];
258 write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
260 r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
261 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
263 DeleteFileA(table->filename);
266 write_msi_summary_info(db, info, num_info);
268 r = MsiDatabaseCommit(db);
269 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
274 static BOOL create_package(LPWSTR path)
278 /* Prepare package */
279 create_database(msifile, tables,
280 sizeof(tables) / sizeof(msi_table), summary_info,
281 sizeof(summary_info) / sizeof(msi_summary_info));
283 len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
284 CURR_DIR, -1, path, MAX_PATH);
285 ok(len, "MultiByteToWideChar returned error %d\n", GetLastError());
289 /* lstrcatW does not work on win95 */
290 path[len - 1] = '\\';
291 memcpy(&path[len], szMsifile, sizeof(szMsifile));
296 * Installation helpers
299 static char PROG_FILES_DIR[MAX_PATH];
301 static BOOL get_program_files_dir(LPSTR buf)
304 DWORD type = REG_EXPAND_SZ, size;
306 if (RegOpenKey(HKEY_LOCAL_MACHINE,
307 "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
311 if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
318 static void create_file(const CHAR *name, DWORD size)
323 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
324 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
325 WriteFile(file, name, strlen(name), &written, NULL);
326 WriteFile(file, "\n", strlen("\n"), &written, NULL);
328 left = size - lstrlen(name) - 1;
330 SetFilePointer(file, left, NULL, FILE_CURRENT);
336 static void create_test_files(void)
338 CreateDirectoryA("msitest", NULL);
339 create_file("msitest\\one.txt", 100);
340 CreateDirectoryA("msitest\\first", NULL);
341 create_file("msitest\\first\\two.txt", 100);
342 CreateDirectoryA("msitest\\second", NULL);
343 create_file("msitest\\second\\three.txt", 100);
344 CreateDirectoryA("msitest\\cabout",NULL);
345 create_file("msitest\\cabout\\four.txt", 100);
346 CreateDirectoryA("msitest\\cabout\\new",NULL);
347 create_file("msitest\\cabout\\new\\five.txt", 100);
348 create_file("msitest\\filename", 100);
351 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
355 lstrcpyA(path, PROG_FILES_DIR);
356 lstrcatA(path, "\\");
357 lstrcatA(path, rel_path);
360 return DeleteFileA(path);
362 return RemoveDirectoryA(path);
365 static void delete_test_files(void)
367 DeleteFileA(msifile);
368 DeleteFileA("msitest\\cabout\\new\\five.txt");
369 DeleteFileA("msitest\\cabout\\four.txt");
370 DeleteFileA("msitest\\second\\three.txt");
371 DeleteFileA("msitest\\first\\two.txt");
372 DeleteFileA("msitest\\one.txt");
373 DeleteFileA("msitest\\filename");
374 RemoveDirectoryA("msitest\\cabout\\new");
375 RemoveDirectoryA("msitest\\cabout");
376 RemoveDirectoryA("msitest\\second");
377 RemoveDirectoryA("msitest\\first");
378 RemoveDirectoryA("msitest");
382 * Automation helpers and tests
385 /* ok-like statement which takes two unicode strings or one unicode and one ANSI string as arguments */
386 static CHAR string1[MAX_PATH], string2[MAX_PATH];
388 /* lstrcmpW is not supported on Win9x */
389 static int strcmp_ww(const WCHAR* str1, const WCHAR* str2)
391 CHAR str1A[MAX_PATH], str2A[MAX_PATH];
393 WideCharToMultiByte(CP_ACP, 0, str1, -1, str1A, MAX_PATH, NULL, NULL);
394 WideCharToMultiByte(CP_ACP, 0, str2, -1, str2A, MAX_PATH, NULL, NULL);
396 return lstrcmpA(str1A, str2A);
399 #define ok_w2(format, szString1, szString2) \
402 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
403 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
404 if (lstrcmpA(string1, string2) != 0) \
405 ok(0, format, string1, string2); \
408 #define ok_w2n(format, szString1, szString2, len) \
410 if (memcmp(szString1, szString2, len * sizeof(WCHAR)) != 0) \
412 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
413 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
414 ok(0, format, string1, string2); \
417 #define ok_aw(format, aString, wString) \
419 WideCharToMultiByte(CP_ACP, 0, wString, -1, string1, MAX_PATH, NULL, NULL); \
420 if (lstrcmpA(string1, aString) != 0) \
421 ok(0, format, string1, aString); \
423 #define ok_awplus(format, extra, aString, wString) \
425 WideCharToMultiByte(CP_ACP, 0, wString, -1, string1, MAX_PATH, NULL, NULL); \
426 if (lstrcmpA(string1, aString) != 0) \
427 ok(0, format, extra, string1, aString); \
429 /* exception checker */
430 static WCHAR szSource[] = {'M','s','i',' ','A','P','I',' ','E','r','r','o','r',0};
432 #define ok_exception(hr, szDescription) \
433 if (hr == DISP_E_EXCEPTION) \
435 /* Compare wtype, source, and destination */ \
436 ok(excepinfo.wCode == 1000, "Exception info was %d, expected 1000\n", excepinfo.wCode); \
438 ok(excepinfo.bstrSource != NULL, "Exception source was NULL\n"); \
439 if (excepinfo.bstrSource) \
440 ok_w2("Exception source was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrSource, szSource); \
442 ok(excepinfo.bstrDescription != NULL, "Exception description was NULL\n"); \
443 if (excepinfo.bstrDescription) \
444 ok_w2("Exception description was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrDescription, szDescription); \
446 SysFreeString(excepinfo.bstrSource); \
447 SysFreeString(excepinfo.bstrDescription); \
448 SysFreeString(excepinfo.bstrHelpFile); \
451 static DISPID get_dispid( IDispatch *disp, const char *name )
458 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0 );
459 str = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
462 len = MultiByteToWideChar(CP_ACP, 0, name, -1, str, len );
463 r = IDispatch_GetIDsOfNames( disp, &IID_NULL, &str, 1, 0, &id );
464 HeapFree(GetProcessHeap(), 0, str);
472 static void test_dispid(void)
476 dispid = get_dispid(pInstaller, "CreateRecord");
477 ok(dispid == 1, "Expected 1, got %d\n", dispid);
478 dispid = get_dispid(pInstaller, "OpenPackage");
479 ok(dispid == 2, "Expected 2, got %d\n", dispid);
480 dispid = get_dispid(pInstaller, "OpenProduct");
481 ok(dispid == 3, "Expected 3, got %d\n", dispid);
482 dispid = get_dispid(pInstaller, "OpenDatabase");
483 ok(dispid == 4, "Expected 4, got %d\n", dispid);
484 dispid = get_dispid(pInstaller, "SummaryInformation");
485 ok(dispid == 5, "Expected 5, got %d\n", dispid);
486 dispid = get_dispid( pInstaller, "UILevel" );
487 ok(dispid == 6, "Expected 6, got %d\n", dispid);
488 dispid = get_dispid(pInstaller, "EnableLog");
489 ok(dispid == 7, "Expected 7, got %d\n", dispid);
490 dispid = get_dispid(pInstaller, "InstallProduct");
491 ok(dispid == 8, "Expected 8, got %d\n", dispid);
492 dispid = get_dispid(pInstaller, "Version");
493 ok(dispid == 9, "Expected 9, got %d\n", dispid);
494 dispid = get_dispid(pInstaller, "LastErrorRecord");
495 ok(dispid == 10, "Expected 10, got %d\n", dispid);
496 dispid = get_dispid(pInstaller, "RegistryValue");
497 ok(dispid == 11, "Expected 11, got %d\n", dispid);
498 dispid = get_dispid(pInstaller, "Environment");
499 ok(dispid == 12, "Expected 12, got %d\n", dispid);
500 dispid = get_dispid(pInstaller, "FileAttributes");
501 ok(dispid == 13, "Expected 13, got %d\n", dispid);
502 dispid = get_dispid(pInstaller, "FileSize");
503 ok(dispid == 15, "Expected 15, got %d\n", dispid);
504 dispid = get_dispid(pInstaller, "FileVersion");
505 ok(dispid == 16, "Expected 16, got %d\n", dispid);
506 dispid = get_dispid(pInstaller, "ProductState");
507 ok(dispid == 17, "Expected 17, got %d\n", dispid);
508 dispid = get_dispid(pInstaller, "ProductInfo");
509 ok(dispid == 18, "Expected 18, got %d\n", dispid);
512 dispid = get_dispid(pInstaller, "ConfigureProduct");
513 ok(dispid == 19, "Expected 19, got %d\n", dispid);
514 dispid = get_dispid(pInstaller, "ReinstallProduct");
515 ok(dispid == 20 , "Expected 20, got %d\n", dispid);
516 dispid = get_dispid(pInstaller, "CollectUserInfo");
517 ok(dispid == 21, "Expected 21, got %d\n", dispid);
518 dispid = get_dispid(pInstaller, "ApplyPatch");
519 ok(dispid == 22, "Expected 22, got %d\n", dispid);
520 dispid = get_dispid(pInstaller, "FeatureParent");
521 ok(dispid == 23, "Expected 23, got %d\n", dispid);
522 dispid = get_dispid(pInstaller, "FeatureState");
523 ok(dispid == 24, "Expected 24, got %d\n", dispid);
524 dispid = get_dispid(pInstaller, "UseFeature");
525 ok(dispid == 25, "Expected 25, got %d\n", dispid);
526 dispid = get_dispid(pInstaller, "FeatureUsageCount");
527 ok(dispid == 26, "Expected 26, got %d\n", dispid);
528 dispid = get_dispid(pInstaller, "FeatureUsageDate");
529 ok(dispid == 27, "Expected 27, got %d\n", dispid);
530 dispid = get_dispid(pInstaller, "ConfigureFeature");
531 ok(dispid == 28, "Expected 28, got %d\n", dispid);
532 dispid = get_dispid(pInstaller, "ReinstallFeature");
533 ok(dispid == 29, "Expected 29, got %d\n", dispid);
534 dispid = get_dispid(pInstaller, "ProvideComponent");
535 ok(dispid == 30, "Expected 30, got %d\n", dispid);
536 dispid = get_dispid(pInstaller, "ComponentPath");
537 ok(dispid == 31, "Expected 31, got %d\n", dispid);
538 dispid = get_dispid(pInstaller, "ProvideQualifiedComponent");
539 ok(dispid == 32, "Expected 32, got %d\n", dispid);
540 dispid = get_dispid(pInstaller, "QualifierDescription");
541 ok(dispid == 33, "Expected 33, got %d\n", dispid);
542 dispid = get_dispid(pInstaller, "ComponentQualifiers");
543 ok(dispid == 34, "Expected 34, got %d\n", dispid);
545 dispid = get_dispid(pInstaller, "Products");
546 ok(dispid == 35, "Expected 35, got %d\n", dispid);
549 dispid = get_dispid(pInstaller, "Features");
550 ok(dispid == 36, "Expected 36, got %d\n", dispid);
551 dispid = get_dispid(pInstaller, "Components");
552 ok(dispid == 37, "Expected 37, got %d\n", dispid);
553 dispid = get_dispid(pInstaller, "ComponentClients");
554 ok(dispid == 38, "Expected 38, got %d\n", dispid);
555 dispid = get_dispid(pInstaller, "Patches");
556 ok(dispid == 39, "Expected 39, got %d\n", dispid);
558 dispid = get_dispid(pInstaller, "RelatedProducts");
559 ok(dispid == 40, "Expected 40, got %d\n", dispid);
562 dispid = get_dispid(pInstaller, "PatchInfo");
563 ok(dispid == 41, "Expected 41, got %d\n", dispid);
564 dispid = get_dispid(pInstaller, "PatchTransforms");
565 ok(dispid == 42, "Expected 42, got %d\n", dispid);
566 dispid = get_dispid(pInstaller, "AddSource");
567 ok(dispid == 43, "Expected 43, got %d\n", dispid);
568 dispid = get_dispid(pInstaller, "ClearSourceList");
569 ok(dispid == 44, "Expected 44, got %d\n", dispid);
570 dispid = get_dispid(pInstaller, "ForceSourceListResolution");
571 ok(dispid == 45, "Expected 45, got %d\n", dispid);
572 dispid = get_dispid(pInstaller, "ShortcutTarget");
573 ok(dispid == 46, "Expected 46, got %d\n", dispid);
574 dispid = get_dispid(pInstaller, "FileHash");
575 ok(dispid == 47, "Expected 47, got %d\n", dispid);
576 dispid = get_dispid(pInstaller, "FileSignatureInfo");
577 ok(dispid == 48, "Expected 48, got %d\n", dispid);
579 dispid = get_dispid(pInstaller, "RemovePatches");
580 ok(dispid == 49 || dispid == -1, "Expected 49 or -1, got %d\n", dispid);
581 dispid = get_dispid(pInstaller, "ApplyMultiplePatches");
582 ok(dispid == 51 || dispid == -1, "Expected 51 or -1, got %d\n", dispid);
583 dispid = get_dispid(pInstaller, "ProductsEx");
584 ok(dispid == 52 || dispid == -1, "Expected 52 or -1, got %d\n", dispid);
585 dispid = get_dispid(pInstaller, "PatchesEx");
586 ok(dispid == 55 || dispid == -1, "Expected 55 or -1, got %d\n", dispid);
587 dispid = get_dispid(pInstaller, "ExtractPatchXMLData");
588 ok(dispid == 57 || dispid == -1, "Expected 57 or -1, got %d\n", dispid);
589 dispid = get_dispid( pInstaller, "ProductElevated" );
590 ok(dispid == 59 || dispid == -1, "Expected 59 or -1, got %d\n", dispid);
591 dispid = get_dispid( pInstaller, "ProvideAssembly" );
592 ok(dispid == 60 || dispid == -1, "Expected 60 or -1, got %d\n", dispid);
593 dispid = get_dispid( pInstaller, "ProductInfoFromScript" );
594 ok(dispid == 61 || dispid == -1, "Expected 61 or -1, got %d\n", dispid);
595 dispid = get_dispid( pInstaller, "AdvertiseProduct" );
596 ok(dispid == 62 || dispid == -1, "Expected 62 or -1, got %d\n", dispid);
597 dispid = get_dispid( pInstaller, "CreateAdvertiseScript" );
598 ok(dispid == 63 || dispid == -1, "Expected 63 or -1, got %d\n", dispid);
599 dispid = get_dispid( pInstaller, "PatchFiles" );
600 ok(dispid == 65 || dispid == -1, "Expected 65 or -1, got %d\n", dispid);
603 /* Test basic IDispatch functions */
604 static void test_dispatch(void)
606 static WCHAR szOpenPackage[] = { 'O','p','e','n','P','a','c','k','a','g','e',0 };
607 static WCHAR szOpenPackageException[] = {'O','p','e','n','P','a','c','k','a','g','e',',','P','a','c','k','a','g','e','P','a','t','h',',','O','p','t','i','o','n','s',0};
608 static WCHAR szProductState[] = { 'P','r','o','d','u','c','t','S','t','a','t','e',0 };
613 VARIANTARG vararg[3];
614 WCHAR path[MAX_PATH];
615 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
617 /* Test getting ID of a function name that does not exist */
618 name = (WCHAR *)szMsifile;
619 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
620 ok(hr == DISP_E_UNKNOWNNAME, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
622 /* Test invoking this function */
623 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
624 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
626 /* Test getting ID of a function name that does exist */
627 name = szOpenPackage;
628 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
629 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
631 /* Test invoking this function (without parameters passed) */
632 if (0) /* All of these crash MSI on Windows XP */
634 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
635 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, &excepinfo, NULL);
636 VariantInit(&varresult);
637 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, &varresult, &excepinfo, NULL);
640 /* Try with NULL params */
641 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
642 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
644 /* Try one empty parameter */
645 dispparams.rgvarg = vararg;
646 dispparams.cArgs = 1;
647 VariantInit(&vararg[0]);
648 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
649 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
651 /* Try two empty parameters */
652 dispparams.cArgs = 2;
653 VariantInit(&vararg[0]);
654 VariantInit(&vararg[1]);
655 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
656 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
658 /* Try one parameter, the required BSTR. Second parameter is optional.
659 * NOTE: The specified package does not exist, which is why the call fails.
661 dispparams.cArgs = 1;
662 VariantInit(&vararg[0]);
663 V_VT(&vararg[0]) = VT_BSTR;
664 V_BSTR(&vararg[0]) = SysAllocString(szMsifile);
665 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
666 ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
667 ok_exception(hr, szOpenPackageException);
668 VariantClear(&vararg[0]);
670 /* Provide the required BSTR and an empty second parameter.
671 * NOTE: The specified package does not exist, which is why the call fails.
673 dispparams.cArgs = 2;
674 VariantInit(&vararg[1]);
675 V_VT(&vararg[1]) = VT_BSTR;
676 V_BSTR(&vararg[1]) = SysAllocString(szMsifile);
677 VariantInit(&vararg[0]);
678 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
679 ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
680 ok_exception(hr, szOpenPackageException);
681 VariantClear(&vararg[1]);
683 /* Provide the required BSTR and two empty parameters.
684 * NOTE: The specified package does not exist, which is why the call fails.
686 dispparams.cArgs = 3;
687 VariantInit(&vararg[2]);
688 V_VT(&vararg[2]) = VT_BSTR;
689 V_BSTR(&vararg[2]) = SysAllocString(szMsifile);
690 VariantInit(&vararg[1]);
691 VariantInit(&vararg[0]);
692 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
693 ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
694 ok_exception(hr, szOpenPackageException);
695 VariantClear(&vararg[2]);
697 /* Provide the required BSTR and a second parameter with the wrong type. */
698 dispparams.cArgs = 2;
699 VariantInit(&vararg[1]);
700 V_VT(&vararg[1]) = VT_BSTR;
701 V_BSTR(&vararg[1]) = SysAllocString(szMsifile);
702 VariantInit(&vararg[0]);
703 V_VT(&vararg[0]) = VT_BSTR;
704 V_BSTR(&vararg[0]) = SysAllocString(szMsifile);
705 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
706 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
707 VariantClear(&vararg[0]);
708 VariantClear(&vararg[1]);
710 /* Create a proper installer package. */
711 create_package(path);
713 /* Try one parameter, the required BSTR. Second parameter is optional.
714 * Proper installer package exists. Path to the package is relative.
716 dispparams.cArgs = 1;
717 VariantInit(&vararg[0]);
718 V_VT(&vararg[0]) = VT_BSTR;
719 V_BSTR(&vararg[0]) = SysAllocString(szMsifile);
720 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
721 todo_wine ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
722 ok_exception(hr, szOpenPackageException);
723 VariantClear(&vararg[0]);
724 if (hr != DISP_E_EXCEPTION)
725 VariantClear(&varresult);
727 /* Try one parameter, the required BSTR. Second parameter is optional.
728 * Proper installer package exists. Path to the package is absolute.
730 dispparams.cArgs = 1;
731 VariantInit(&vararg[0]);
732 V_VT(&vararg[0]) = VT_BSTR;
733 V_BSTR(&vararg[0]) = SysAllocString(path);
734 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
735 ok(hr == S_OK, "IDispatch::Invoke returned 0x%08x\n", hr);
736 VariantClear(&vararg[0]);
737 VariantClear(&varresult);
739 /* Provide the required BSTR and an empty second parameter. Proper
740 * installation package exists.
742 dispparams.cArgs = 2;
743 VariantInit(&vararg[1]);
744 V_VT(&vararg[1]) = VT_BSTR;
745 V_BSTR(&vararg[1]) = SysAllocString(path);
746 VariantInit(&vararg[0]);
747 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
748 ok(hr == S_OK, "IDispatch::Invoke returned 0x%08x\n", hr);
749 VariantClear(&vararg[1]);
750 VariantClear(&varresult);
752 /* Provide the required BSTR and two empty parameters. Proper
753 * installation package exists.
755 dispparams.cArgs = 3;
756 VariantInit(&vararg[2]);
757 V_VT(&vararg[2]) = VT_BSTR;
758 V_BSTR(&vararg[2]) = SysAllocString(path);
759 VariantInit(&vararg[1]);
760 VariantInit(&vararg[0]);
761 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
762 ok(hr == S_OK, "IDispatch::Invoke returned 0x%08x\n", hr);
763 VariantClear(&vararg[2]);
764 VariantClear(&varresult);
766 /* Provide the required BSTR and a second parameter with the wrong type. */
767 dispparams.cArgs = 2;
768 VariantInit(&vararg[1]);
769 V_VT(&vararg[1]) = VT_BSTR;
770 V_BSTR(&vararg[1]) = SysAllocString(path);
771 VariantInit(&vararg[0]);
772 V_VT(&vararg[0]) = VT_BSTR;
773 V_BSTR(&vararg[0]) = SysAllocString(path);
774 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
775 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
776 VariantClear(&vararg[0]);
777 VariantClear(&vararg[1]);
779 /* Provide the required BSTR and a second parameter that can be coerced to
782 dispparams.cArgs = 2;
783 VariantInit(&vararg[1]);
784 V_VT(&vararg[1]) = VT_BSTR;
785 V_BSTR(&vararg[1]) = SysAllocString(path);
786 VariantInit(&vararg[0]);
787 V_VT(&vararg[0]) = VT_I2;
788 V_BSTR(&vararg[0]) = 0;
789 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
790 ok(hr == S_OK, "IDispatch::Invoke returned 0x%08x\n", hr);
791 VariantClear(&vararg[1]);
792 VariantClear(&varresult);
796 /* Test invoking a method as a DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT */
797 VariantInit(&vararg[0]);
798 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
799 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
801 VariantInit(&vararg[0]);
802 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
803 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
805 /* Test invoking a read-only property as DISPATCH_PROPERTYPUT or as a DISPATCH_METHOD */
806 name = szProductState;
807 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
808 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
810 dispparams.rgvarg = NULL;
811 dispparams.cArgs = 0;
812 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
813 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
815 dispparams.rgvarg = NULL;
816 dispparams.cArgs = 0;
817 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
818 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
821 /* invocation helper function */
822 static int _invoke_todo_vtResult = 0;
824 static HRESULT invoke(IDispatch *pDispatch, LPCSTR szName, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, VARTYPE vtResult)
826 OLECHAR *name = NULL;
832 memset(pVarResult, 0, sizeof(VARIANT));
833 VariantInit(pVarResult);
835 len = MultiByteToWideChar(CP_ACP, 0, szName, -1, NULL, 0 );
836 name = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
837 if (!name) return E_FAIL;
838 len = MultiByteToWideChar(CP_ACP, 0, szName, -1, name, len );
839 hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
840 HeapFree(GetProcessHeap(), 0, name);
841 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
842 if (!hr == S_OK) return hr;
844 memset(&excepinfo, 0, sizeof(excepinfo));
845 hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_NEUTRAL, wFlags, pDispParams, pVarResult, &excepinfo, NULL);
849 if (_invoke_todo_vtResult) todo_wine
850 ok(V_VT(pVarResult) == vtResult, "Variant result type is %d, expected %d\n", V_VT(pVarResult), vtResult);
852 ok(V_VT(pVarResult) == vtResult, "Variant result type is %d, expected %d\n", V_VT(pVarResult), vtResult);
853 if (vtResult != VT_EMPTY)
855 hr = VariantChangeTypeEx(pVarResult, pVarResult, LOCALE_NEUTRAL, 0, vtResult);
856 ok(hr == S_OK, "VariantChangeTypeEx returned 0x%08x\n", hr);
860 for (i=0; i<pDispParams->cArgs; i++)
861 VariantClear(&pDispParams->rgvarg[i]);
866 /* Object_Property helper functions */
868 static HRESULT Installer_CreateRecord(int count, IDispatch **pRecord)
871 VARIANTARG vararg[1];
872 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
875 VariantInit(&vararg[0]);
876 V_VT(&vararg[0]) = VT_I4;
877 V_I4(&vararg[0]) = count;
879 hr = invoke(pInstaller, "CreateRecord", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
880 *pRecord = V_DISPATCH(&varresult);
884 static HRESULT Installer_RegistryValue(HKEY hkey, LPCWSTR szKey, VARIANT vValue, VARIANT *pVarResult, VARTYPE vtExpect)
886 VARIANTARG vararg[3];
887 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
889 VariantInit(&vararg[2]);
890 V_VT(&vararg[2]) = VT_I4;
891 V_I4(&vararg[2]) = (INT_PTR)hkey;
892 VariantInit(&vararg[1]);
893 V_VT(&vararg[1]) = VT_BSTR;
894 V_BSTR(&vararg[1]) = SysAllocString(szKey);
895 VariantInit(&vararg[0]);
896 VariantCopy(&vararg[0], &vValue);
897 VariantClear(&vValue);
899 return invoke(pInstaller, "RegistryValue", DISPATCH_METHOD, &dispparams, pVarResult, vtExpect);
902 static HRESULT Installer_RegistryValueE(HKEY hkey, LPCWSTR szKey, BOOL *pBool)
908 VariantInit(&vararg);
909 V_VT(&vararg) = VT_EMPTY;
910 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BOOL);
911 *pBool = V_BOOL(&varresult);
912 VariantClear(&varresult);
916 static HRESULT Installer_RegistryValueW(HKEY hkey, LPCWSTR szKey, LPCWSTR szValue, LPWSTR szString)
922 VariantInit(&vararg);
923 V_VT(&vararg) = VT_BSTR;
924 V_BSTR(&vararg) = SysAllocString(szValue);
926 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BSTR);
927 if (V_BSTR(&varresult))
928 /* lstrcpyW is not implemented on Win95 (lstrlenW is though) */
929 memcpy(szString, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
930 VariantClear(&varresult);
934 static HRESULT Installer_RegistryValueI(HKEY hkey, LPCWSTR szKey, int iValue, LPWSTR szString, VARTYPE vtResult)
940 VariantInit(&vararg);
941 V_VT(&vararg) = VT_I4;
942 V_I4(&vararg) = iValue;
944 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, vtResult);
945 if (SUCCEEDED(hr) && vtResult == VT_BSTR)
946 memcpy(szString, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
947 VariantClear(&varresult);
951 static HRESULT Installer_OpenPackage(LPCWSTR szPackagePath, int options, IDispatch **pSession)
954 VARIANTARG vararg[2];
955 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
958 VariantInit(&vararg[1]);
959 V_VT(&vararg[1]) = VT_BSTR;
960 V_BSTR(&vararg[1]) = SysAllocString(szPackagePath);
961 VariantInit(&vararg[0]);
962 V_VT(&vararg[0]) = VT_I4;
963 V_I4(&vararg[0]) = options;
965 hr = invoke(pInstaller, "OpenPackage", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
966 *pSession = V_DISPATCH(&varresult);
970 static HRESULT Installer_OpenDatabase(LPCWSTR szDatabasePath, int openmode, IDispatch **pDatabase)
973 VARIANTARG vararg[2];
974 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
977 VariantInit(&vararg[1]);
978 V_VT(&vararg[1]) = VT_BSTR;
979 V_BSTR(&vararg[1]) = SysAllocString(szDatabasePath);
980 VariantInit(&vararg[0]);
981 V_VT(&vararg[0]) = VT_I4;
982 V_I4(&vararg[0]) = openmode;
984 hr = invoke(pInstaller, "OpenDatabase", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
985 *pDatabase = V_DISPATCH(&varresult);
989 static HRESULT Installer_InstallProduct(LPCWSTR szPackagePath, LPCWSTR szPropertyValues)
992 VARIANTARG vararg[2];
993 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
995 VariantInit(&vararg[1]);
996 V_VT(&vararg[1]) = VT_BSTR;
997 V_BSTR(&vararg[1]) = SysAllocString(szPackagePath);
998 VariantInit(&vararg[0]);
999 V_VT(&vararg[0]) = VT_BSTR;
1000 V_BSTR(&vararg[0]) = SysAllocString(szPropertyValues);
1002 return invoke(pInstaller, "InstallProduct", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1005 static HRESULT Installer_ProductState(LPCWSTR szProduct, int *pInstallState)
1008 VARIANTARG vararg[1];
1009 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1012 VariantInit(&vararg[0]);
1013 V_VT(&vararg[0]) = VT_BSTR;
1014 V_BSTR(&vararg[0]) = SysAllocString(szProduct);
1016 hr = invoke(pInstaller, "ProductState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1017 *pInstallState = V_I4(&varresult);
1018 VariantClear(&varresult);
1022 static HRESULT Installer_ProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute, LPWSTR szString)
1025 VARIANTARG vararg[2];
1026 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1029 VariantInit(&vararg[1]);
1030 V_VT(&vararg[1]) = VT_BSTR;
1031 V_BSTR(&vararg[1]) = SysAllocString(szProduct);
1032 VariantInit(&vararg[0]);
1033 V_VT(&vararg[0]) = VT_BSTR;
1034 V_BSTR(&vararg[0]) = SysAllocString(szAttribute);
1036 hr = invoke(pInstaller, "ProductInfo", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1037 if (V_BSTR(&varresult))
1038 memcpy(szString, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
1039 VariantClear(&varresult);
1043 static HRESULT Installer_Products(IDispatch **pStringList)
1046 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1049 hr = invoke(pInstaller, "Products", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1050 *pStringList = V_DISPATCH(&varresult);
1054 static HRESULT Installer_RelatedProducts(LPCWSTR szProduct, IDispatch **pStringList)
1057 VARIANTARG vararg[1];
1058 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1061 VariantInit(&vararg[0]);
1062 V_VT(&vararg[0]) = VT_BSTR;
1063 V_BSTR(&vararg[0]) = SysAllocString(szProduct);
1065 hr = invoke(pInstaller, "RelatedProducts", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1066 *pStringList = V_DISPATCH(&varresult);
1070 static HRESULT Installer_VersionGet(LPWSTR szVersion)
1073 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1076 hr = invoke(pInstaller, "Version", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1077 if (V_BSTR(&varresult))
1078 memcpy(szVersion, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
1079 VariantClear(&varresult);
1083 static HRESULT Session_Installer(IDispatch *pSession, IDispatch **pInst)
1086 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1089 hr = invoke(pSession, "Installer", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1090 *pInst = V_DISPATCH(&varresult);
1094 static HRESULT Session_PropertyGet(IDispatch *pSession, LPCWSTR szName, LPWSTR szReturn)
1097 VARIANTARG vararg[1];
1098 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1101 VariantInit(&vararg[0]);
1102 V_VT(&vararg[0]) = VT_BSTR;
1103 V_BSTR(&vararg[0]) = SysAllocString(szName);
1105 hr = invoke(pSession, "Property", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1106 if (V_BSTR(&varresult))
1107 memcpy(szReturn, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
1108 VariantClear(&varresult);
1112 static HRESULT Session_PropertyPut(IDispatch *pSession, LPCWSTR szName, LPCWSTR szValue)
1115 VARIANTARG vararg[2];
1116 DISPID dispid = DISPID_PROPERTYPUT;
1117 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1119 VariantInit(&vararg[1]);
1120 V_VT(&vararg[1]) = VT_BSTR;
1121 V_BSTR(&vararg[1]) = SysAllocString(szName);
1122 VariantInit(&vararg[0]);
1123 V_VT(&vararg[0]) = VT_BSTR;
1124 V_BSTR(&vararg[0]) = SysAllocString(szValue);
1126 return invoke(pSession, "Property", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1129 static HRESULT Session_LanguageGet(IDispatch *pSession, UINT *pLangId)
1132 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1135 hr = invoke(pSession, "Language", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1136 *pLangId = V_I4(&varresult);
1137 VariantClear(&varresult);
1141 static HRESULT Session_ModeGet(IDispatch *pSession, int iFlag, BOOL *pMode)
1144 VARIANTARG vararg[1];
1145 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1148 VariantInit(&vararg[0]);
1149 V_VT(&vararg[0]) = VT_I4;
1150 V_I4(&vararg[0]) = iFlag;
1152 hr = invoke(pSession, "Mode", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BOOL);
1153 *pMode = V_BOOL(&varresult);
1154 VariantClear(&varresult);
1158 static HRESULT Session_ModePut(IDispatch *pSession, int iFlag, BOOL bMode)
1161 VARIANTARG vararg[2];
1162 DISPID dispid = DISPID_PROPERTYPUT;
1163 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1165 VariantInit(&vararg[1]);
1166 V_VT(&vararg[1]) = VT_I4;
1167 V_I4(&vararg[1]) = iFlag;
1168 VariantInit(&vararg[0]);
1169 V_VT(&vararg[0]) = VT_BOOL;
1170 V_BOOL(&vararg[0]) = bMode;
1172 return invoke(pSession, "Mode", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1175 static HRESULT Session_Database(IDispatch *pSession, IDispatch **pDatabase)
1178 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1181 hr = invoke(pSession, "Database", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1182 *pDatabase = V_DISPATCH(&varresult);
1186 static HRESULT Session_DoAction(IDispatch *pSession, LPCWSTR szAction, int *iReturn)
1189 VARIANTARG vararg[1];
1190 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1193 VariantInit(&vararg[0]);
1194 V_VT(&vararg[0]) = VT_BSTR;
1195 V_BSTR(&vararg[0]) = SysAllocString(szAction);
1197 hr = invoke(pSession, "DoAction", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
1198 *iReturn = V_I4(&varresult);
1199 VariantClear(&varresult);
1203 static HRESULT Session_EvaluateCondition(IDispatch *pSession, LPCWSTR szCondition, int *iReturn)
1206 VARIANTARG vararg[1];
1207 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1210 VariantInit(&vararg[0]);
1211 V_VT(&vararg[0]) = VT_BSTR;
1212 V_BSTR(&vararg[0]) = SysAllocString(szCondition);
1214 hr = invoke(pSession, "EvaluateCondition", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
1215 *iReturn = V_I4(&varresult);
1216 VariantClear(&varresult);
1220 static HRESULT Session_Message(IDispatch *pSession, LONG kind, IDispatch *record, int *ret)
1223 VARIANTARG vararg[2];
1224 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1227 VariantInit(&varresult);
1228 V_VT(vararg) = VT_DISPATCH;
1229 V_DISPATCH(vararg) = record;
1230 V_VT(vararg+1) = VT_I4;
1231 V_I4(vararg+1) = kind;
1233 hr = invoke(pSession, "Message", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
1235 ok(V_VT(&varresult) == VT_I4, "V_VT(varresult) = %d\n", V_VT(&varresult));
1236 *ret = V_I4(&varresult);
1241 static HRESULT Session_SetInstallLevel(IDispatch *pSession, LONG iInstallLevel)
1244 VARIANTARG vararg[1];
1245 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1247 VariantInit(&vararg[0]);
1248 V_VT(&vararg[0]) = VT_I4;
1249 V_I4(&vararg[0]) = iInstallLevel;
1251 return invoke(pSession, "SetInstallLevel", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1254 static HRESULT Session_FeatureCurrentState(IDispatch *pSession, LPCWSTR szName, int *pState)
1257 VARIANTARG vararg[1];
1258 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1261 VariantInit(&vararg[0]);
1262 V_VT(&vararg[0]) = VT_BSTR;
1263 V_BSTR(&vararg[0]) = SysAllocString(szName);
1265 hr = invoke(pSession, "FeatureCurrentState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1266 *pState = V_I4(&varresult);
1267 VariantClear(&varresult);
1271 static HRESULT Session_FeatureRequestStateGet(IDispatch *pSession, LPCWSTR szName, int *pState)
1274 VARIANTARG vararg[1];
1275 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1278 VariantInit(&vararg[0]);
1279 V_VT(&vararg[0]) = VT_BSTR;
1280 V_BSTR(&vararg[0]) = SysAllocString(szName);
1282 hr = invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1283 *pState = V_I4(&varresult);
1284 VariantClear(&varresult);
1288 static HRESULT Session_FeatureRequestStatePut(IDispatch *pSession, LPCWSTR szName, int iState)
1291 VARIANTARG vararg[2];
1292 DISPID dispid = DISPID_PROPERTYPUT;
1293 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1295 VariantInit(&vararg[1]);
1296 V_VT(&vararg[1]) = VT_BSTR;
1297 V_BSTR(&vararg[1]) = SysAllocString(szName);
1298 VariantInit(&vararg[0]);
1299 V_VT(&vararg[0]) = VT_I4;
1300 V_I4(&vararg[0]) = iState;
1302 return invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1305 static HRESULT Database_OpenView(IDispatch *pDatabase, LPCWSTR szSql, IDispatch **pView)
1308 VARIANTARG vararg[1];
1309 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1312 VariantInit(&vararg[0]);
1313 V_VT(&vararg[0]) = VT_BSTR;
1314 V_BSTR(&vararg[0]) = SysAllocString(szSql);
1316 hr = invoke(pDatabase, "OpenView", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
1317 *pView = V_DISPATCH(&varresult);
1321 static HRESULT Database_SummaryInformation(IDispatch *pDatabase, int iUpdateCount, IDispatch **pSummaryInfo)
1324 VARIANTARG vararg[1];
1325 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1328 VariantInit(&vararg[0]);
1329 V_VT(&vararg[0]) = VT_I4;
1330 V_I4(&vararg[0]) = iUpdateCount;
1332 hr = invoke(pDatabase, "SummaryInformation", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1333 *pSummaryInfo = V_DISPATCH(&varresult);
1337 static HRESULT View_Execute(IDispatch *pView, IDispatch *pRecord)
1340 VARIANTARG vararg[1];
1341 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1343 VariantInit(&vararg[0]);
1344 V_VT(&vararg[0]) = VT_DISPATCH;
1345 V_DISPATCH(&vararg[0]) = pRecord;
1347 return invoke(pView, "Execute", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1350 static HRESULT View_Fetch(IDispatch *pView, IDispatch **ppRecord)
1353 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1354 HRESULT hr = invoke(pView, "Fetch", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
1355 *ppRecord = V_DISPATCH(&varresult);
1359 static HRESULT View_Modify(IDispatch *pView, int iMode, IDispatch *pRecord)
1362 VARIANTARG vararg[2];
1363 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1365 VariantInit(&vararg[1]);
1366 V_VT(&vararg[1]) = VT_I4;
1367 V_I4(&vararg[1]) = iMode;
1368 VariantInit(&vararg[0]);
1369 V_VT(&vararg[0]) = VT_DISPATCH;
1370 V_DISPATCH(&vararg[0]) = pRecord;
1372 IDispatch_AddRef(pRecord); /* VariantClear in invoke will call IDispatch_Release */
1374 return invoke(pView, "Modify", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1377 static HRESULT View_Close(IDispatch *pView)
1380 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1381 return invoke(pView, "Close", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1384 static HRESULT Record_FieldCountGet(IDispatch *pRecord, int *pFieldCount)
1387 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1388 HRESULT hr = invoke(pRecord, "FieldCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1389 *pFieldCount = V_I4(&varresult);
1390 VariantClear(&varresult);
1394 static HRESULT Record_StringDataGet(IDispatch *pRecord, int iField, LPWSTR szString)
1397 VARIANTARG vararg[1];
1398 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1401 VariantInit(&vararg[0]);
1402 V_VT(&vararg[0]) = VT_I4;
1403 V_I4(&vararg[0]) = iField;
1405 hr = invoke(pRecord, "StringData", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1406 if (V_BSTR(&varresult))
1407 memcpy(szString, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
1408 VariantClear(&varresult);
1412 static HRESULT Record_StringDataPut(IDispatch *pRecord, int iField, LPCWSTR szString)
1415 VARIANTARG vararg[2];
1416 DISPID dispid = DISPID_PROPERTYPUT;
1417 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1419 VariantInit(&vararg[1]);
1420 V_VT(&vararg[1]) = VT_I4;
1421 V_I4(&vararg[1]) = iField;
1422 VariantInit(&vararg[0]);
1423 V_VT(&vararg[0]) = VT_BSTR;
1424 V_BSTR(&vararg[0]) = SysAllocString(szString);
1426 return invoke(pRecord, "StringData", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1429 static HRESULT Record_IntegerDataGet(IDispatch *pRecord, int iField, int *pValue)
1432 VARIANTARG vararg[1];
1433 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1436 VariantInit(&vararg[0]);
1437 V_VT(&vararg[0]) = VT_I4;
1438 V_I4(&vararg[0]) = iField;
1440 hr = invoke(pRecord, "IntegerData", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1441 *pValue = V_I4(&varresult);
1442 VariantClear(&varresult);
1446 static HRESULT Record_IntegerDataPut(IDispatch *pRecord, int iField, int iValue)
1449 VARIANTARG vararg[2];
1450 DISPID dispid = DISPID_PROPERTYPUT;
1451 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1453 VariantInit(&vararg[1]);
1454 V_VT(&vararg[1]) = VT_I4;
1455 V_I4(&vararg[1]) = iField;
1456 VariantInit(&vararg[0]);
1457 V_VT(&vararg[0]) = VT_I4;
1458 V_I4(&vararg[0]) = iValue;
1460 return invoke(pRecord, "IntegerData", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1463 static HRESULT StringList__NewEnum(IDispatch *pList, IUnknown **ppEnumVARIANT)
1466 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1467 HRESULT hr = invoke(pList, "_NewEnum", DISPATCH_METHOD, &dispparams, &varresult, VT_UNKNOWN);
1468 *ppEnumVARIANT = V_UNKNOWN(&varresult);
1472 static HRESULT StringList_Item(IDispatch *pStringList, int iIndex, LPWSTR szString)
1475 VARIANTARG vararg[1];
1476 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1479 VariantInit(&vararg[0]);
1480 V_VT(&vararg[0]) = VT_I4;
1481 V_I4(&vararg[0]) = iIndex;
1483 hr = invoke(pStringList, "Item", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1484 if (V_BSTR(&varresult))
1485 memcpy(szString, V_BSTR(&varresult), (lstrlenW(V_BSTR(&varresult)) + 1) * sizeof(WCHAR));
1486 VariantClear(&varresult);
1490 static HRESULT StringList_Count(IDispatch *pStringList, int *pCount)
1493 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1494 HRESULT hr = invoke(pStringList, "Count", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1495 *pCount = V_I4(&varresult);
1496 VariantClear(&varresult);
1500 static HRESULT SummaryInfo_PropertyGet(IDispatch *pSummaryInfo, int pid, VARIANT *pVarResult, VARTYPE vtExpect)
1502 VARIANTARG vararg[1];
1503 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1505 VariantInit(&vararg[0]);
1506 V_VT(&vararg[0]) = VT_I4;
1507 V_I4(&vararg[0]) = pid;
1508 return invoke(pSummaryInfo, "Property", DISPATCH_PROPERTYGET, &dispparams, pVarResult, vtExpect);
1511 static HRESULT SummaryInfo_PropertyPut(IDispatch *pSummaryInfo, int pid, VARIANT *pVariant)
1514 VARIANTARG vararg[2];
1515 DISPID dispid = DISPID_PROPERTYPUT;
1516 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1518 VariantInit(&vararg[1]);
1519 V_VT(&vararg[1]) = VT_I4;
1520 V_I4(&vararg[1]) = pid;
1521 VariantInit(&vararg[0]);
1522 VariantCopyInd(vararg, pVariant);
1524 return invoke(pSummaryInfo, "Property", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1527 static HRESULT SummaryInfo_PropertyCountGet(IDispatch *pSummaryInfo, int *pCount)
1530 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1533 hr = invoke(pSummaryInfo, "PropertyCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1534 *pCount = V_I4(&varresult);
1535 VariantClear(&varresult);
1539 /* Test the various objects */
1541 #define TEST_SUMMARYINFO_PROPERTIES_MODIFIED 4
1543 static void test_SummaryInfo(IDispatch *pSummaryInfo, const msi_summary_info *info, int num_info, BOOL readonly)
1545 static const WCHAR szPropertyException[] = { 'P','r','o','p','e','r','t','y',',','P','i','d',0 };
1546 static const WCHAR szTitle[] = { 'T','i','t','l','e',0 };
1547 VARIANT varresult, var;
1552 /* SummaryInfo::PropertyCount */
1553 hr = SummaryInfo_PropertyCountGet(pSummaryInfo, &j);
1554 ok(hr == S_OK, "SummaryInfo_PropertyCount failed, hresult 0x%08x\n", hr);
1555 ok(j == num_info, "SummaryInfo_PropertyCount returned %d, expected %d\n", j, num_info);
1557 /* SummaryInfo::Property, get for properties we have set */
1558 for (j = 0; j < num_info; j++)
1560 const msi_summary_info *entry = &info[j];
1562 int vt = entry->datatype;
1563 if (vt == VT_LPSTR) vt = VT_BSTR;
1564 else if (vt == VT_FILETIME) vt = VT_DATE;
1565 else if (vt == VT_I2) vt = VT_I4;
1567 hr = SummaryInfo_PropertyGet(pSummaryInfo, entry->property, &varresult, vt);
1568 ok(hr == S_OK, "SummaryInfo_Property (pid %d) failed, hresult 0x%08x\n", entry->property, hr);
1569 if (V_VT(&varresult) != vt)
1570 skip("Skipping property tests due to type mismatch\n");
1571 else if (vt == VT_I4)
1572 ok(V_I4(&varresult) == entry->iValue, "SummaryInfo_Property (pid %d) I4 result expected to be %d, but was %d\n",
1573 entry->property, entry->iValue, V_I4(&varresult));
1574 else if (vt == VT_DATE)
1579 FileTimeToLocalFileTime(entry->pftValue, &ft);
1580 FileTimeToSystemTime(&ft, &st);
1581 SystemTimeToVariantTime(&st, &d);
1582 ok(d == V_DATE(&varresult), "SummaryInfo_Property (pid %d) DATE result expected to be %lf, but was %lf\n", entry->property, d, V_DATE(&varresult));
1584 else if (vt == VT_BSTR)
1586 ok_awplus("SummaryInfo_Property (pid %d) BSTR result expected to be %s, but was %s\n", entry->property, entry->szValue, V_BSTR(&varresult));
1589 skip("SummaryInfo_Property (pid %d) unhandled result type %d\n", entry->property, vt);
1591 VariantClear(&varresult);
1594 /* SummaryInfo::Property, get; invalid arguments */
1597 hr = SummaryInfo_PropertyGet(pSummaryInfo, -1, &varresult, VT_EMPTY);
1598 ok(hr == DISP_E_EXCEPTION, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1599 ok_exception(hr, szPropertyException);
1601 hr = SummaryInfo_PropertyGet(pSummaryInfo, 1000, &varresult, VT_EMPTY);
1602 ok(hr == DISP_E_EXCEPTION, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1603 ok_exception(hr, szPropertyException);
1605 /* Unsupported pids */
1606 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_DICTIONARY, &varresult, VT_EMPTY);
1607 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1609 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_THUMBNAIL, &varresult, VT_EMPTY);
1610 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1612 /* Pids we have not set, one for each type */
1613 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CODEPAGE, &varresult, VT_EMPTY);
1614 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1616 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_TITLE, &varresult, VT_EMPTY);
1617 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1619 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_EDITTIME, &varresult, VT_EMPTY);
1620 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1622 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CHARCOUNT, &varresult, VT_EMPTY);
1623 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1627 /* SummaryInfo::Property, put; one for each type */
1633 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_CODEPAGE, &var);
1634 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1636 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CODEPAGE, &varresult, VT_I4 /* NOT VT_I2 */);
1637 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1638 ok(V_I2(&var) == V_I2(&varresult), "SummaryInfo_PropertyGet expected %d, but returned %d\n", V_I2(&var), V_I2(&varresult));
1639 VariantClear(&varresult);
1643 V_VT(&var) = VT_BSTR;
1644 V_BSTR(&var) = SysAllocString(szTitle);
1645 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_TITLE, &var);
1646 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1648 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_TITLE, &varresult, V_VT(&var));
1649 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1650 ok_w2("SummaryInfo_PropertyGet expected %s, but returned %s\n", V_BSTR(&var), V_BSTR(&varresult));
1651 VariantClear(&varresult);
1655 V_VT(&var) = VT_DATE;
1656 FileTimeToSystemTime(&systemtime, &st);
1657 SystemTimeToVariantTime(&st, &V_DATE(&var));
1658 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_LASTSAVE_DTM, &var);
1659 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1661 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_LASTSAVE_DTM, &varresult, V_VT(&var));
1662 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1663 ok(V_DATE(&var) == V_DATE(&varresult), "SummaryInfo_PropertyGet expected %lf, but returned %lf\n", V_DATE(&var), V_DATE(&varresult));
1664 VariantClear(&varresult);
1670 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_CHARCOUNT, &var);
1671 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1673 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CHARCOUNT, &varresult, V_VT(&var));
1674 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1675 ok(V_I4(&var) == V_I4(&varresult), "SummaryInfo_PropertyGet expected %d, but returned %d\n", V_I4(&var), V_I4(&varresult));
1676 VariantClear(&varresult);
1679 /* SummaryInfo::PropertyCount */
1680 hr = SummaryInfo_PropertyCountGet(pSummaryInfo, &j);
1681 ok(hr == S_OK, "SummaryInfo_PropertyCount failed, hresult 0x%08x\n", hr);
1682 ok(j == num_info+4, "SummaryInfo_PropertyCount returned %d, expected %d\n", j, num_info);
1686 static void test_Database(IDispatch *pDatabase, BOOL readonly)
1688 static WCHAR szSql[] = { 'S','E','L','E','C','T',' ','`','F','e','a','t','u','r','e','`',' ','F','R','O','M',' ','`','F','e','a','t','u','r','e','`',' ','W','H','E','R','E',' ','`','F','e','a','t','u','r','e','_','P','a','r','e','n','t','`','=','\'','O','n','e','\'',0 };
1689 static WCHAR szThree[] = { 'T','h','r','e','e',0 };
1690 static WCHAR szTwo[] = { 'T','w','o',0 };
1691 static WCHAR szStringDataField[] = { 'S','t','r','i','n','g','D','a','t','a',',','F','i','e','l','d',0 };
1692 static WCHAR szModifyModeRecord[] = { 'M','o','d','i','f','y',',','M','o','d','e',',','R','e','c','o','r','d',0 };
1693 IDispatch *pView = NULL, *pSummaryInfo = NULL;
1696 hr = Database_OpenView(pDatabase, szSql, &pView);
1697 ok(hr == S_OK, "Database_OpenView failed, hresult 0x%08x\n", hr);
1700 IDispatch *pRecord = NULL;
1701 WCHAR szString[MAX_PATH];
1704 hr = View_Execute(pView, NULL);
1705 ok(hr == S_OK, "View_Execute failed, hresult 0x%08x\n", hr);
1708 hr = View_Fetch(pView, &pRecord);
1709 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1710 ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
1713 /* Record::StringDataGet */
1714 memset(szString, 0, sizeof(szString));
1715 hr = Record_StringDataGet(pRecord, 1, szString);
1716 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1717 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szThree);
1719 /* Record::StringDataPut with correct index */
1720 hr = Record_StringDataPut(pRecord, 1, szTwo);
1721 ok(hr == S_OK, "Record_StringDataPut failed, hresult 0x%08x\n", hr);
1723 /* Record::StringDataGet */
1724 memset(szString, 0, sizeof(szString));
1725 hr = Record_StringDataGet(pRecord, 1, szString);
1726 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1727 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szTwo);
1729 /* Record::StringDataPut with incorrect index */
1730 hr = Record_StringDataPut(pRecord, -1, szString);
1731 ok(hr == DISP_E_EXCEPTION, "Record_StringDataPut failed, hresult 0x%08x\n", hr);
1732 ok_exception(hr, szStringDataField);
1734 /* View::Modify with incorrect parameters */
1735 hr = View_Modify(pView, -5, NULL);
1736 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1737 ok_exception(hr, szModifyModeRecord);
1739 hr = View_Modify(pView, -5, pRecord);
1740 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1741 ok_exception(hr, szModifyModeRecord);
1743 hr = View_Modify(pView, MSIMODIFY_REFRESH, NULL);
1744 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1745 ok_exception(hr, szModifyModeRecord);
1747 hr = View_Modify(pView, MSIMODIFY_REFRESH, pRecord);
1748 ok(hr == S_OK, "View_Modify failed, hresult 0x%08x\n", hr);
1750 /* Record::StringDataGet, confirm that the record is back to its unmodified value */
1751 memset(szString, 0, sizeof(szString));
1752 hr = Record_StringDataGet(pRecord, 1, szString);
1753 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1754 todo_wine ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szThree);
1756 IDispatch_Release(pRecord);
1760 hr = View_Fetch(pView, &pRecord);
1761 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1762 ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
1765 /* Record::StringDataGet */
1766 memset(szString, 0, sizeof(szString));
1767 hr = Record_StringDataGet(pRecord, 1, szString);
1768 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1769 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szTwo);
1771 IDispatch_Release(pRecord);
1775 hr = View_Fetch(pView, &pRecord);
1776 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1777 ok(pRecord == NULL, "View_Fetch should have returned NULL record\n");
1779 IDispatch_Release(pRecord);
1782 hr = View_Close(pView);
1783 ok(hr == S_OK, "View_Close failed, hresult 0x%08x\n", hr);
1785 IDispatch_Release(pView);
1788 /* Database::SummaryInformation */
1789 hr = Database_SummaryInformation(pDatabase, TEST_SUMMARYINFO_PROPERTIES_MODIFIED, &pSummaryInfo);
1790 ok(hr == S_OK, "Database_SummaryInformation failed, hresult 0x%08x\n", hr);
1791 ok(pSummaryInfo != NULL, "Database_SummaryInformation should not have returned NULL record\n");
1794 test_SummaryInfo(pSummaryInfo, summary_info, sizeof(summary_info)/sizeof(msi_summary_info), readonly);
1795 IDispatch_Release(pSummaryInfo);
1799 static void test_Session(IDispatch *pSession)
1801 static WCHAR szProductName[] = { 'P','r','o','d','u','c','t','N','a','m','e',0 };
1802 static WCHAR szOne[] = { 'O','n','e',0 };
1803 static WCHAR szOneStateFalse[] = { '!','O','n','e','>','0',0 };
1804 static WCHAR szOneStateTrue[] = { '!','O','n','e','=','-','1',0 };
1805 static WCHAR szOneActionFalse[] = { '$','O','n','e','=','-','1',0 };
1806 static WCHAR szOneActionTrue[] = { '$','O','n','e','>','0',0 };
1807 static WCHAR szCostInitialize[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1808 static WCHAR szEmpty[] = { 0 };
1809 static WCHAR szEquals[] = { '=',0 };
1810 static WCHAR szPropertyName[] = { 'P','r','o','p','e','r','t','y',',','N','a','m','e',0 };
1811 WCHAR stringw[MAX_PATH];
1812 CHAR string[MAX_PATH];
1816 IDispatch *pDatabase = NULL, *pInst = NULL, *record = NULL;
1819 /* Session::Installer */
1820 hr = Session_Installer(pSession, &pInst);
1821 ok(hr == S_OK, "Session_Installer failed, hresult 0x%08x\n", hr);
1822 ok(pInst != NULL, "Session_Installer returned NULL IDispatch pointer\n");
1823 ok(pInst == pInstaller, "Session_Installer does not match Installer instance from CoCreateInstance\n");
1825 /* Session::Property, get */
1826 memset(stringw, 0, sizeof(stringw));
1827 hr = Session_PropertyGet(pSession, szProductName, stringw);
1828 ok(hr == S_OK, "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1829 if (strcmp_ww(stringw, szMSITEST) != 0)
1831 len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1832 ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1833 ok(0, "Property \"ProductName\" expected to be \"MSITEST\" but was \"%s\"\n", string);
1836 /* Session::Property, put */
1837 hr = Session_PropertyPut(pSession, szProductName, szProductName);
1838 ok(hr == S_OK, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1839 memset(stringw, 0, sizeof(stringw));
1840 hr = Session_PropertyGet(pSession, szProductName, stringw);
1841 ok(hr == S_OK, "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1842 if (strcmp_ww(stringw, szProductName) != 0)
1844 len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1845 ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1846 ok(0, "Property \"ProductName\" expected to be \"ProductName\" but was \"%s\"\n", string);
1849 /* Try putting a property using empty property identifier */
1850 hr = Session_PropertyPut(pSession, szEmpty, szProductName);
1851 ok(hr == DISP_E_EXCEPTION, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1852 ok_exception(hr, szPropertyName);
1854 /* Try putting a property using illegal property identifier */
1855 hr = Session_PropertyPut(pSession, szEquals, szProductName);
1856 ok(hr == S_OK, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1858 /* Session::Language, get */
1859 hr = Session_LanguageGet(pSession, &len);
1860 ok(hr == S_OK, "Session_LanguageGet failed, hresult 0x%08x\n", hr);
1861 /* Not sure how to check the language is correct */
1863 /* Session::Mode, get */
1864 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1865 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1866 todo_wine ok(!bool, "Reboot at end session mode is %d\n", bool);
1868 /* Session::Mode, put */
1869 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, TRUE);
1870 ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1871 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1872 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1873 ok(bool, "Reboot at end session mode is %d, expected 1\n", bool);
1874 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, FALSE); /* set it again so we don't reboot */
1875 ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1877 /* Session::Database, get */
1878 hr = Session_Database(pSession, &pDatabase);
1879 ok(hr == S_OK, "Session_Database failed, hresult 0x%08x\n", hr);
1882 test_Database(pDatabase, TRUE);
1883 IDispatch_Release(pDatabase);
1886 /* Session::EvaluateCondition */
1887 hr = Session_EvaluateCondition(pSession, NULL, &myint);
1888 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1889 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1891 hr = Session_EvaluateCondition(pSession, szEmpty, &myint);
1892 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1893 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1895 hr = Session_EvaluateCondition(pSession, szEquals, &myint);
1896 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1897 ok(myint == MSICONDITION_ERROR, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1899 /* Session::DoAction(CostInitialize) must occur before the next statements */
1900 hr = Session_DoAction(pSession, szCostInitialize, &myint);
1901 ok(hr == S_OK, "Session_DoAction failed, hresult 0x%08x\n", hr);
1902 ok(myint == IDOK, "DoAction(CostInitialize) returned %d, %d expected\n", myint, IDOK);
1904 /* Session::SetInstallLevel */
1905 hr = Session_SetInstallLevel(pSession, INSTALLLEVEL_MINIMUM);
1906 ok(hr == S_OK, "Session_SetInstallLevel failed, hresult 0x%08x\n", hr);
1908 /* Session::FeatureCurrentState, get */
1909 hr = Session_FeatureCurrentState(pSession, szOne, &myint);
1910 ok(hr == S_OK, "Session_FeatureCurrentState failed, hresult 0x%08x\n", hr);
1911 ok(myint == INSTALLSTATE_UNKNOWN, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1913 /* Session::Message */
1914 hr = Installer_CreateRecord(0, &record);
1915 ok(hr == S_OK, "Installer_CreateRecord failed: %08x\n", hr);
1916 hr = Session_Message(pSession, INSTALLMESSAGE_INFO, record, &myint);
1917 ok(hr == S_OK, "Session_Message failed: %08x\n", hr);
1918 ok(myint == 0, "Session_Message returned %x\n", myint);
1920 /* Session::EvaluateCondition */
1921 hr = Session_EvaluateCondition(pSession, szOneStateFalse, &myint);
1922 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1923 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1925 hr = Session_EvaluateCondition(pSession, szOneStateTrue, &myint);
1926 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1927 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1929 /* Session::FeatureRequestState, put */
1930 hr = Session_FeatureRequestStatePut(pSession, szOne, INSTALLSTATE_ADVERTISED);
1931 ok(hr == S_OK, "Session_FeatureRequestStatePut failed, hresult 0x%08x\n", hr);
1932 hr = Session_FeatureRequestStateGet(pSession, szOne, &myint);
1933 ok(hr == S_OK, "Session_FeatureRequestStateGet failed, hresult 0x%08x\n", hr);
1934 ok(myint == INSTALLSTATE_ADVERTISED, "Feature request state was %d but expected %d\n", myint, INSTALLSTATE_ADVERTISED);
1936 /* Session::EvaluateCondition */
1937 hr = Session_EvaluateCondition(pSession, szOneActionFalse, &myint);
1938 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1939 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1941 hr = Session_EvaluateCondition(pSession, szOneActionTrue, &myint);
1942 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1943 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1946 /* delete key and all its subkeys */
1947 static DWORD delete_key( HKEY hkey )
1949 char name[MAX_PATH];
1952 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
1955 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
1957 ret = delete_key( tmp );
1962 if (ret != ERROR_NO_MORE_ITEMS) return ret;
1963 RegDeleteKeyA( hkey, "" );
1967 static void test_Installer_RegistryValue(void)
1969 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
1970 static const WCHAR szKey[] = { 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t',0 };
1971 static const WCHAR szOne[] = { 'O','n','e',0 };
1972 static const WCHAR szTwo[] = { 'T','w','o',0 };
1973 static const WCHAR szThree[] = { 'T','h','r','e','e',0 };
1974 static const WCHAR szREG_BINARY[] = { '(','R','E','G','_','B','I','N','A','R','Y',')',0 };
1975 static const WCHAR szFour[] = { 'F','o','u','r',0 };
1976 static const WCHAR szExpand[] = { '%','M','S','I','T','E','S','T','%',0 };
1977 static const WCHAR szFive[] = { 'F','i','v','e',0,'H','i',0,0 };
1978 static const WCHAR szFiveHi[] = { 'F','i','v','e','\n','H','i',0 };
1979 static const WCHAR szSix[] = { 'S','i','x',0 };
1980 static const WCHAR szREG_[] = { '(','R','E','G','_',']',0 };
1981 static const WCHAR szSeven[] = { 'S','e','v','e','n',0 };
1982 static const WCHAR szEight[] = { 'E','i','g','h','t',0 };
1983 static const WCHAR szBlank[] = { 0 };
1986 WCHAR szString[MAX_PATH];
1987 HKEY hkey, hkey_sub;
1988 HKEY curr_user = (HKEY)1;
1994 SetLastError(0xdeadbeef);
1995 lRet = RegOpenKeyW( HKEY_CURRENT_USER, szKey, &hkey );
1996 if (!lRet && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1998 win_skip("Needed W-functions are not implemented\n");
2004 /* Does our key exist? Shouldn't; check with all three possible value parameter types */
2005 hr = Installer_RegistryValueE(curr_user, szKey, &bRet);
2006 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
2007 ok(!bRet, "Registry key expected to not exist, but Installer_RegistryValue claims it does\n");
2009 memset(szString, 0, sizeof(szString));
2010 hr = Installer_RegistryValueW(curr_user, szKey, NULL, szString);
2011 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2013 memset(szString, 0, sizeof(szString));
2014 hr = Installer_RegistryValueI(curr_user, szKey, 0, szString, VT_BSTR);
2015 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2018 ok(!RegCreateKeyW( HKEY_CURRENT_USER, szKey, &hkey ), "RegCreateKeyW failed\n");
2020 ok(!RegSetValueExW(hkey,szOne,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
2021 "RegSetValueExW failed\n");
2022 ok(!RegSetValueExW(hkey,szTwo,0,REG_DWORD, (const BYTE *)qw, 4),
2023 "RegSetValueExW failed\n");
2024 ok(!RegSetValueExW(hkey,szThree,0,REG_BINARY, (const BYTE *)qw, 4),
2025 "RegSetValueExW failed\n");
2026 ok(SetEnvironmentVariableA("MSITEST", "Four"), "SetEnvironmentVariableA failed %d\n", GetLastError());
2027 ok(!RegSetValueExW(hkey,szFour,0,REG_EXPAND_SZ, (const BYTE *)szExpand, sizeof(szExpand)),
2028 "RegSetValueExW failed\n");
2029 ok(!RegSetValueExW(hkey,szFive,0,REG_MULTI_SZ, (const BYTE *)szFive, sizeof(szFive)),
2030 "RegSetValueExW failed\n");
2031 ok(!RegSetValueExW(hkey,szSix,0,REG_QWORD, (const BYTE *)qw, 8),
2032 "RegSetValueExW failed\n");
2033 ok(!RegSetValueExW(hkey,szSeven,0,REG_NONE, NULL, 0),
2034 "RegSetValueExW failed\n");
2036 ok(!RegSetValueExW(hkey,NULL,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
2037 "RegSetValueExW failed\n");
2039 ok(!RegCreateKeyW( hkey, szEight, &hkey_sub ), "RegCreateKeyW failed\n");
2041 /* Does our key exist? It should, and make sure we retrieve the correct default value */
2043 hr = Installer_RegistryValueE(curr_user, szKey, &bRet);
2044 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
2045 ok(bRet, "Registry key expected to exist, but Installer_RegistryValue claims it does not\n");
2047 memset(szString, 0, sizeof(szString));
2048 hr = Installer_RegistryValueW(curr_user, szKey, NULL, szString);
2049 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2050 ok_w2("Default registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
2052 /* Ask for the value of a nonexistent key */
2053 memset(szString, 0, sizeof(szString));
2054 hr = Installer_RegistryValueW(curr_user, szKey, szExpand, szString);
2055 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2057 /* Get values of keys */
2058 memset(szString, 0, sizeof(szString));
2059 hr = Installer_RegistryValueW(curr_user, szKey, szOne, szString);
2060 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2061 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
2063 VariantInit(&vararg);
2064 V_VT(&vararg) = VT_BSTR;
2065 V_BSTR(&vararg) = SysAllocString(szTwo);
2066 hr = Installer_RegistryValue(curr_user, szKey, vararg, &varresult, VT_I4);
2067 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
2068 ok(V_I4(&varresult) == 305419896, "Registry value %d does not match expected value\n", V_I4(&varresult));
2069 VariantClear(&varresult);
2071 memset(szString, 0, sizeof(szString));
2072 hr = Installer_RegistryValueW(curr_user, szKey, szThree, szString);
2073 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2074 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_BINARY);
2076 memset(szString, 0, sizeof(szString));
2077 hr = Installer_RegistryValueW(curr_user, szKey, szFour, szString);
2078 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2079 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFour);
2081 /* Vista does not NULL-terminate this case */
2082 memset(szString, 0, sizeof(szString));
2083 hr = Installer_RegistryValueW(curr_user, szKey, szFive, szString);
2084 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2085 ok_w2n("Registry value \"%s\" does not match expected \"%s\"\n",
2086 szString, szFiveHi, lstrlenW(szFiveHi));
2088 memset(szString, 0, sizeof(szString));
2089 hr = Installer_RegistryValueW(curr_user, szKey, szSix, szString);
2090 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2091 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_);
2093 VariantInit(&vararg);
2094 V_VT(&vararg) = VT_BSTR;
2095 V_BSTR(&vararg) = SysAllocString(szSeven);
2096 hr = Installer_RegistryValue(curr_user, szKey, vararg, &varresult, VT_EMPTY);
2097 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
2099 /* Get string class name for the key */
2100 memset(szString, 0, sizeof(szString));
2101 hr = Installer_RegistryValueI(curr_user, szKey, 0, szString, VT_BSTR);
2102 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2103 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szBlank);
2105 /* Get name of a value by positive number (RegEnumValue like), valid index */
2106 memset(szString, 0, sizeof(szString));
2107 hr = Installer_RegistryValueI(curr_user, szKey, 2, szString, VT_BSTR);
2108 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2109 /* RegEnumValue order seems different on wine */
2110 todo_wine ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szTwo);
2112 /* Get name of a value by positive number (RegEnumValue like), invalid index */
2113 memset(szString, 0, sizeof(szString));
2114 hr = Installer_RegistryValueI(curr_user, szKey, 10, szString, VT_EMPTY);
2115 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2117 /* Get name of a subkey by negative number (RegEnumValue like), valid index */
2118 memset(szString, 0, sizeof(szString));
2119 hr = Installer_RegistryValueI(curr_user, szKey, -1, szString, VT_BSTR);
2120 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2121 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szEight);
2123 /* Get name of a subkey by negative number (RegEnumValue like), invalid index */
2124 memset(szString, 0, sizeof(szString));
2125 hr = Installer_RegistryValueI(curr_user, szKey, -10, szString, VT_EMPTY);
2126 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2132 static void test_Installer_Products(BOOL bProductInstalled)
2134 WCHAR szString[MAX_PATH];
2137 IUnknown *pUnk = NULL;
2138 IEnumVARIANT *pEnum = NULL;
2142 IDispatch *pStringList = NULL;
2143 BOOL bProductFound = FALSE;
2145 /* Installer::Products */
2146 hr = Installer_Products(&pStringList);
2147 ok(hr == S_OK, "Installer_Products failed, hresult 0x%08x\n", hr);
2150 /* StringList::_NewEnum */
2151 hr = StringList__NewEnum(pStringList, &pUnk);
2152 ok(hr == S_OK, "StringList_NewEnum failed, hresult 0x%08x\n", hr);
2155 hr = IUnknown_QueryInterface(pUnk, &IID_IEnumVARIANT, (void **)&pEnum);
2156 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
2159 skip("IEnumVARIANT tests\n");
2161 /* StringList::Count */
2162 hr = StringList_Count(pStringList, &iCount);
2163 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2165 for (idx=0; idx<iCount; idx++)
2167 /* StringList::Item */
2168 memset(szString, 0, sizeof(szString));
2169 hr = StringList_Item(pStringList, idx, szString);
2170 ok(hr == S_OK, "StringList_Item failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2174 /* Installer::ProductState */
2175 hr = Installer_ProductState(szString, &iValue);
2176 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2178 ok(iValue == INSTALLSTATE_DEFAULT || iValue == INSTALLSTATE_ADVERTISED, "Installer_ProductState returned %d, expected %d or %d\n", iValue, INSTALLSTATE_DEFAULT, INSTALLSTATE_ADVERTISED);
2180 /* Not found our product code yet? Check */
2181 if (!bProductFound && !strcmp_ww(szString, szProductCode))
2182 bProductFound = TRUE;
2184 /* IEnumVARIANT::Next */
2187 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
2188 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2189 ok(celt == 1, "%d items were retrieved, expected 1\n", celt);
2190 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2191 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
2197 if (bProductInstalled)
2199 ok(bProductInstalled == bProductFound, "Product expected to %s installed but product code was %s\n",
2200 bProductInstalled ? "be" : "not be",
2201 bProductFound ? "found" : "not found");
2206 IEnumVARIANT *pEnum2 = NULL;
2208 if (0) /* Crashes on Windows XP */
2210 /* IEnumVARIANT::Clone, NULL pointer */
2211 hr = IEnumVARIANT_Clone(pEnum, NULL);
2214 /* IEnumVARIANT::Clone */
2215 hr = IEnumVARIANT_Clone(pEnum, &pEnum2);
2216 ok(hr == S_OK, "IEnumVARIANT_Clone failed, hresult 0x%08x\n", hr);
2219 /* IEnumVARIANT::Clone is supposed to save the position, but it actually just goes back to the beginning */
2221 /* IEnumVARIANT::Next of the clone */
2224 hr = IEnumVARIANT_Next(pEnum2, 1, &var, &celt);
2225 ok(hr == S_OK, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2226 ok(celt == 1, "%d items were retrieved, expected 0\n", celt);
2227 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2231 skip("IEnumVARIANT::Next of clone will not return success with 0 products\n");
2233 IEnumVARIANT_Release(pEnum2);
2236 /* IEnumVARIANT::Skip should fail */
2237 hr = IEnumVARIANT_Skip(pEnum, 1);
2238 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
2240 /* IEnumVARIANT::Next, NULL variant pointer */
2241 hr = IEnumVARIANT_Next(pEnum, 1, NULL, &celt);
2242 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2243 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
2245 /* IEnumVARIANT::Next, should not return any more items */
2246 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
2247 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2248 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
2251 /* IEnumVARIANT::Reset */
2252 hr = IEnumVARIANT_Reset(pEnum);
2253 ok(hr == S_OK, "IEnumVARIANT_Reset failed, hresult 0x%08x\n", hr);
2257 /* IEnumVARIANT::Skip to the last product */
2258 hr = IEnumVARIANT_Skip(pEnum, iCount-1);
2259 ok(hr == S_OK, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
2261 /* IEnumVARIANT::Next should match the very last retrieved value, also makes sure it works with
2262 * NULL celt pointer. */
2263 hr = IEnumVARIANT_Next(pEnum, 1, &var, NULL);
2264 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2265 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2266 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
2270 skip("IEnumVARIANT::Skip impossible for 0 products\n");
2273 /* StringList::Item using an invalid index */
2274 memset(szString, 0, sizeof(szString));
2275 hr = StringList_Item(pStringList, iCount, szString);
2276 ok(hr == DISP_E_BADINDEX, "StringList_Item for an invalid index did not return DISP_E_BADINDEX, hresult 0x%08x\n", hr);
2278 if (pEnum) IEnumVARIANT_Release(pEnum);
2279 if (pUnk) IUnknown_Release(pUnk);
2280 IDispatch_Release(pStringList);
2284 /* Delete a registry subkey, including all its subkeys (RegDeleteKey does not work on keys with subkeys without
2285 * deleting the subkeys first) */
2286 static UINT delete_registry_key(HKEY hkeyParent, LPCSTR subkey)
2289 CHAR *string = NULL;
2293 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2294 if (ret != ERROR_SUCCESS) return ret;
2295 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2296 if (ret != ERROR_SUCCESS) return ret;
2297 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2299 while (RegEnumKeyA(hkey, 0, string, dwSize) == ERROR_SUCCESS)
2300 delete_registry_key(hkey, string);
2303 HeapFree(GetProcessHeap(), 0, string);
2304 RegDeleteKeyA(hkeyParent, subkey);
2305 return ERROR_SUCCESS;
2308 /* Find a specific registry subkey at any depth within the given key and subkey and return its parent key. */
2309 static UINT find_registry_key(HKEY hkeyParent, LPCSTR subkey, LPCSTR findkey, HKEY *phkey)
2312 CHAR *string = NULL;
2320 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2321 if (ret != ERROR_SUCCESS) return ret;
2322 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2323 if (ret != ERROR_SUCCESS) return ret;
2324 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2327 RegEnumKeyA(hkey, idx++, string, dwSize) == ERROR_SUCCESS)
2329 if (!strcmp(string, findkey))
2334 else if (find_registry_key(hkey, string, findkey, phkey) == ERROR_SUCCESS) found = TRUE;
2337 if (*phkey != hkey) RegCloseKey(hkey);
2338 HeapFree(GetProcessHeap(), 0, string);
2339 return (found ? ERROR_SUCCESS : ERROR_FILE_NOT_FOUND);
2342 static void test_Installer_InstallProduct(void)
2345 CHAR path[MAX_PATH];
2346 WCHAR szString[MAX_PATH];
2349 DWORD num, size, type;
2351 IDispatch *pStringList = NULL;
2353 create_test_files();
2355 /* Installer::InstallProduct */
2356 hr = Installer_InstallProduct(szMsifile, NULL);
2357 if (hr == DISP_E_EXCEPTION)
2359 skip("Installer object not supported.\n");
2360 delete_test_files();
2363 ok(hr == S_OK, "Installer_InstallProduct failed, hresult 0x%08x\n", hr);
2365 /* Installer::ProductState for our product code, which has been installed */
2366 hr = Installer_ProductState(szProductCode, &iValue);
2367 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2368 ok(iValue == INSTALLSTATE_DEFAULT, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_DEFAULT);
2370 /* Installer::ProductInfo for our product code */
2372 /* NULL attribute */
2373 memset(szString, 0, sizeof(szString));
2374 hr = Installer_ProductInfo(szProductCode, NULL, szString);
2375 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2376 ok_exception(hr, szProductInfoException);
2378 /* Nonexistent attribute */
2379 memset(szString, 0, sizeof(szString));
2380 hr = Installer_ProductInfo(szProductCode, szMsifile, szString);
2381 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2382 ok_exception(hr, szProductInfoException);
2385 memset(szString, 0, sizeof(szString));
2386 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szString);
2387 ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2388 todo_wine ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMsifile);
2391 memset(szString, 0, sizeof(szString));
2392 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PRODUCTNAMEW, szString);
2393 ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2394 todo_wine ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMSITEST);
2396 /* Installer::Products */
2397 test_Installer_Products(TRUE);
2399 /* Installer::RelatedProducts for our upgrade code */
2400 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2401 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2404 /* StringList::Count */
2405 hr = StringList_Count(pStringList, &iCount);
2406 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2407 ok(iCount == 1, "Expected one related product but found %d\n", iCount);
2409 /* StringList::Item */
2410 memset(szString, 0, sizeof(szString));
2411 hr = StringList_Item(pStringList, 0, szString);
2412 ok(hr == S_OK, "StringList_Item failed (idx 0, count %d), hresult 0x%08x\n", iCount, hr);
2413 ok_w2("StringList_Item returned %s but expected %s\n", szString, szProductCode);
2415 IDispatch_Release(pStringList);
2418 /* Check & clean up installed files & registry keys */
2419 ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
2420 ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
2421 ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
2422 ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
2423 ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
2424 ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
2425 ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
2426 ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
2427 ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
2428 ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
2429 ok(delete_pf("msitest", FALSE), "File not installed\n");
2431 res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
2432 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2436 res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
2437 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2438 ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
2442 res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
2443 ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
2447 res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
2448 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2449 ok(num == 314, "Expected 314, got %d\n", num);
2453 res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
2454 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2455 ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
2459 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
2460 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2462 /* Remove registry keys written by RegisterProduct standard action */
2463 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F1C3AF50-8B56-4A69-A00C-00773FE42F30}");
2464 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2466 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2467 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2469 res = find_registry_key(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", "05FA3C1F65B896A40AC00077F34EF203", &hkey);
2470 ok(res == ERROR_SUCCESS ||
2471 broken(res == ERROR_FILE_NOT_FOUND), /* win9x */
2472 "Expected ERROR_SUCCESS, got %d\n", res);
2473 if (res == ERROR_SUCCESS)
2475 res = delete_registry_key(hkey, "05FA3C1F65B896A40AC00077F34EF203");
2476 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2479 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Products\\05FA3C1F65B896A40AC00077F34EF203");
2480 ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
2484 /* win9x defaults to a per-machine install. */
2485 RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Products\\05FA3C1F65B896A40AC00077F34EF203");
2488 /* Remove registry keys written by PublishProduct standard action */
2489 res = RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Installer", &hkey);
2490 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2492 res = delete_registry_key(hkey, "Products\\05FA3C1F65B896A40AC00077F34EF203");
2493 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2495 res = RegDeleteKeyA(hkey, "UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2496 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2500 /* Delete installation files we installed */
2501 delete_test_files();
2504 static void test_Installer(void)
2506 static WCHAR szCreateRecordException[] = { 'C','r','e','a','t','e','R','e','c','o','r','d',',','C','o','u','n','t',0 };
2507 static WCHAR szIntegerDataException[] = { 'I','n','t','e','g','e','r','D','a','t','a',',','F','i','e','l','d',0 };
2508 WCHAR szPath[MAX_PATH];
2510 IDispatch *pSession = NULL, *pDatabase = NULL, *pRecord = NULL, *pStringList = NULL;
2513 if (!pInstaller) return;
2515 /* Installer::CreateRecord */
2517 /* Test for error */
2518 hr = Installer_CreateRecord(-1, &pRecord);
2519 ok(hr == DISP_E_EXCEPTION, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2520 ok_exception(hr, szCreateRecordException);
2522 /* Test for success */
2523 hr = Installer_CreateRecord(1, &pRecord);
2524 ok(hr == S_OK, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2525 ok(pRecord != NULL, "Installer_CreateRecord should not have returned NULL record\n");
2528 /* Record::FieldCountGet */
2529 hr = Record_FieldCountGet(pRecord, &iValue);
2530 ok(hr == S_OK, "Record_FiledCountGet failed, hresult 0x%08x\n", hr);
2531 ok(iValue == 1, "Record_FieldCountGet result was %d but expected 1\n", iValue);
2533 /* Record::IntegerDataGet */
2534 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2535 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2536 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2538 /* Record::IntegerDataGet, bad index */
2539 hr = Record_IntegerDataGet(pRecord, 10, &iValue);
2540 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2541 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2543 /* Record::IntegerDataPut */
2544 hr = Record_IntegerDataPut(pRecord, 1, 100);
2545 ok(hr == S_OK, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2547 /* Record::IntegerDataPut, bad index */
2548 hr = Record_IntegerDataPut(pRecord, 10, 100);
2549 ok(hr == DISP_E_EXCEPTION, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2550 ok_exception(hr, szIntegerDataException);
2552 /* Record::IntegerDataGet */
2553 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2554 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2555 ok(iValue == 100, "Record_IntegerDataGet result was %d but expected 100\n", iValue);
2557 IDispatch_Release(pRecord);
2560 create_package(szPath);
2562 /* Installer::OpenPackage */
2563 hr = Installer_OpenPackage(szPath, 0, &pSession);
2564 ok(hr == S_OK, "Installer_OpenPackage failed, hresult 0x%08x\n", hr);
2567 test_Session(pSession);
2568 IDispatch_Release(pSession);
2571 /* Installer::OpenDatabase */
2572 hr = Installer_OpenDatabase(szPath, (INT_PTR)MSIDBOPEN_TRANSACT, &pDatabase);
2573 ok(hr == S_OK, "Installer_OpenDatabase failed, hresult 0x%08x\n", hr);
2576 test_Database(pDatabase, FALSE);
2577 IDispatch_Release(pDatabase);
2580 /* Installer::RegistryValue */
2581 test_Installer_RegistryValue();
2583 /* Installer::ProductState for our product code, which should not be installed */
2584 hr = Installer_ProductState(szProductCode, &iValue);
2585 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2586 ok(iValue == INSTALLSTATE_UNKNOWN, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_UNKNOWN);
2588 /* Installer::ProductInfo for our product code, which should not be installed */
2591 memset(szPath, 0, sizeof(szPath));
2592 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szPath);
2593 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2594 ok_exception(hr, szProductInfoException);
2596 /* NULL attribute and NULL product code */
2597 memset(szPath, 0, sizeof(szPath));
2598 hr = Installer_ProductInfo(NULL, NULL, szPath);
2599 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2600 ok_exception(hr, szProductInfoException);
2602 /* Installer::Products */
2603 test_Installer_Products(FALSE);
2605 /* Installer::RelatedProducts for our upgrade code, should not find anything */
2606 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2607 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2610 /* StringList::Count */
2611 hr = StringList_Count(pStringList, &iCount);
2612 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2613 ok(!iCount, "Expected no related products but found %d\n", iCount);
2615 IDispatch_Release(pStringList);
2618 /* Installer::Version */
2619 memset(szPath, 0, sizeof(szPath));
2620 hr = Installer_VersionGet(szPath);
2621 ok(hr == S_OK, "Installer_VersionGet failed, hresult 0x%08x\n", hr);
2623 /* Installer::InstallProduct and other tests that depend on our product being installed */
2624 test_Installer_InstallProduct();
2627 START_TEST(automation)
2630 char temp_path[MAX_PATH], prev_path[MAX_PATH];
2635 GetSystemTimeAsFileTime(&systemtime);
2637 GetCurrentDirectoryA(MAX_PATH, prev_path);
2638 GetTempPath(MAX_PATH, temp_path);
2639 SetCurrentDirectoryA(temp_path);
2641 lstrcpyA(CURR_DIR, temp_path);
2642 len = lstrlenA(CURR_DIR);
2644 if(len && (CURR_DIR[len - 1] == '\\'))
2645 CURR_DIR[len - 1] = 0;
2647 get_program_files_dir(PROG_FILES_DIR);
2649 hr = OleInitialize(NULL);
2650 ok (hr == S_OK, "OleInitialize returned 0x%08x\n", hr);
2651 hr = CLSIDFromProgID(szProgId, &clsid);
2652 ok (hr == S_OK, "CLSIDFromProgID returned 0x%08x\n", hr);
2653 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
2654 ok(hr == S_OK, "CoCreateInstance returned 0x%08x\n", hr);
2658 hr = IUnknown_QueryInterface(pUnk, &IID_IDispatch, (void **)&pInstaller);
2659 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
2665 IDispatch_Release(pInstaller);
2666 IUnknown_Release(pUnk);
2671 SetCurrentDirectoryA(prev_path);