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
32 #include "wine/test.h"
34 static const char *msifile = "winetest.msi";
35 static const WCHAR szMsifile[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
36 static const WCHAR szMSITEST[] = { 'M','S','I','T','E','S','T',0 };
37 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 };
38 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 };
39 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 };
40 static const WCHAR WINE_INSTALLPROPERTY_PACKAGENAMEW[] = {'P','a','c','k','a','g','e','N','a','m','e',0};
41 static const WCHAR WINE_INSTALLPROPERTY_PRODUCTNAMEW[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
42 static FILETIME systemtime;
43 static CHAR CURR_DIR[MAX_PATH];
44 static EXCEPINFO excepinfo;
49 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 };
50 static IDispatch *pInstaller;
52 /* msi database data */
54 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
55 "s72\tS38\ts72\ti2\tS255\tS72\n"
56 "Component\tComponent\n"
57 "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
58 "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
59 "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
60 "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
61 "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
62 "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
63 "component\t\tMSITESTDIR\t0\t1\tfile\n"
64 "service_comp\t\tMSITESTDIR\t0\t1\tservice_file";
66 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
68 "Directory\tDirectory\n"
69 "CABOUTDIR\tMSITESTDIR\tcabout\n"
70 "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
71 "FIRSTDIR\tMSITESTDIR\tfirst\n"
72 "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
73 "NEWDIR\tCABOUTDIR\tnew\n"
74 "ProgramFilesFolder\tTARGETDIR\t.\n"
75 "TARGETDIR\t\tSourceDir";
77 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
78 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
80 "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
81 "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
82 "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
83 "Three\tOne\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
84 "Two\tOne\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
85 "feature\t\t\t\t2\t1\tTARGETDIR\t0\n"
86 "service_feature\t\t\t\t2\t1\tTARGETDIR\t0";
88 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
90 "FeatureComponents\tFeature_\tComponent_\n"
96 "feature\tcomponent\n"
97 "service_feature\tservice_comp\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"
108 "service_file\tservice_comp\tservice.exe\t100\t\t\t8192\t1";
110 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
112 "InstallExecuteSequence\tAction\n"
113 "AllocateRegistrySpace\tNOT Installed\t1550\n"
114 "CostFinalize\t\t1000\n"
115 "CostInitialize\t\t800\n"
117 "InstallFiles\t\t4000\n"
118 "InstallServices\t\t5000\n"
119 "RegisterProduct\t\t6100\n"
120 "PublishProduct\t\t6400\n"
121 "InstallFinalize\t\t6600\n"
122 "InstallInitialize\t\t1500\n"
123 "InstallValidate\t\t1400\n"
124 "LaunchConditions\t\t100\n"
125 "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
127 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
128 "i2\ti4\tL64\tS255\tS32\tS72\n"
130 "1\t5\t\t\tDISK1\t\n";
132 static const CHAR property_dat[] = "Property\tValue\n"
134 "Property\tProperty\n"
135 "DefaultUIFont\tDlgFont8\n"
138 "InstallMode\tTypical\n"
139 "Manufacturer\tWine\n"
140 "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
141 "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
143 "ProductLanguage\t1033\n"
144 "ProductName\tMSITEST\n"
145 "ProductVersion\t1.1.1\n"
146 "PROMPTROLLBACKCOST\tP\n"
148 "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
150 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
151 "s72\ti2\tl255\tL255\tL0\ts72\n"
152 "Registry\tRegistry\n"
153 "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
154 "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
155 "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
156 "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
158 static const CHAR service_install_dat[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
159 "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
160 "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
161 "ServiceInstall\tServiceInstall\n"
162 "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
164 static const CHAR service_control_dat[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
165 "s72\tl255\ti2\tL255\tI2\ts72\n"
166 "ServiceControl\tServiceControl\n"
167 "ServiceControl\tTestService\t8\t\t0\tservice_comp";
169 typedef struct _msi_table
171 const CHAR *filename;
176 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
178 static const msi_table tables[] =
180 ADD_TABLE(component),
181 ADD_TABLE(directory),
183 ADD_TABLE(feature_comp),
185 ADD_TABLE(install_exec_seq),
189 ADD_TABLE(service_install),
190 ADD_TABLE(service_control)
193 typedef struct _msi_summary_info
202 #define ADD_INFO_I2(property, iValue) {property, VT_I2, iValue, NULL, NULL}
203 #define ADD_INFO_I4(property, iValue) {property, VT_I4, iValue, NULL, NULL}
204 #define ADD_INFO_LPSTR(property, szValue) {property, VT_LPSTR, 0, NULL, szValue}
205 #define ADD_INFO_FILETIME(property, pftValue) {property, VT_FILETIME, 0, pftValue, NULL}
207 static const msi_summary_info summary_info[] =
209 ADD_INFO_LPSTR(PID_TEMPLATE, ";1033"),
210 ADD_INFO_LPSTR(PID_REVNUMBER, "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}"),
211 ADD_INFO_I4(PID_PAGECOUNT, 100),
212 ADD_INFO_I4(PID_WORDCOUNT, 0),
213 ADD_INFO_FILETIME(PID_CREATE_DTM, &systemtime),
214 ADD_INFO_FILETIME(PID_LASTPRINTED, &systemtime)
221 static void write_file(const CHAR *filename, const char *data, int data_size)
225 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
226 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
228 WriteFile(hf, data, data_size, &size, NULL);
232 static void write_msi_summary_info(MSIHANDLE db, const msi_summary_info *info, int num_info)
238 r = MsiGetSummaryInformationA(db, NULL, num_info, &summary);
239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
241 /* import summary information into the stream */
242 for (j = 0; j < num_info; j++)
244 const msi_summary_info *entry = &info[j];
246 r = MsiSummaryInfoSetPropertyA(summary, entry->property, entry->datatype,
247 entry->iValue, entry->pftValue, entry->szValue);
248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
251 /* write the summary changes back to the stream */
252 r = MsiSummaryInfoPersist(summary);
253 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
255 MsiCloseHandle(summary);
258 static void create_database(const CHAR *name, const msi_table *tables, int num_tables,
259 const msi_summary_info *info, int num_info)
265 r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
266 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
268 /* import the tables into the database */
269 for (j = 0; j < num_tables; j++)
271 const msi_table *table = &tables[j];
273 write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
275 r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
276 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
278 DeleteFileA(table->filename);
281 write_msi_summary_info(db, info, num_info);
283 r = MsiDatabaseCommit(db);
284 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
290 * Installation helpers
293 static char PROG_FILES_DIR[MAX_PATH];
295 static BOOL get_program_files_dir(LPSTR buf)
298 DWORD type = REG_EXPAND_SZ, size;
300 if (RegOpenKey(HKEY_LOCAL_MACHINE,
301 "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
305 if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
312 static void create_file(const CHAR *name, DWORD size)
317 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
318 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
319 WriteFile(file, name, strlen(name), &written, NULL);
320 WriteFile(file, "\n", strlen("\n"), &written, NULL);
322 left = size - lstrlen(name) - 1;
324 SetFilePointer(file, left, NULL, FILE_CURRENT);
330 static void create_test_files(void)
332 CreateDirectoryA("msitest", NULL);
333 create_file("msitest\\one.txt", 100);
334 CreateDirectoryA("msitest\\first", NULL);
335 create_file("msitest\\first\\two.txt", 100);
336 CreateDirectoryA("msitest\\second", NULL);
337 create_file("msitest\\second\\three.txt", 100);
338 CreateDirectoryA("msitest\\cabout",NULL);
339 create_file("msitest\\cabout\\four.txt", 100);
340 CreateDirectoryA("msitest\\cabout\\new",NULL);
341 create_file("msitest\\cabout\\new\\five.txt", 100);
342 create_file("msitest\\filename", 100);
343 create_file("msitest\\service.exe", 100);
346 static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
350 lstrcpyA(path, PROG_FILES_DIR);
351 lstrcatA(path, "\\");
352 lstrcatA(path, rel_path);
355 return DeleteFileA(path);
357 return RemoveDirectoryA(path);
360 static void delete_test_files(void)
362 DeleteFileA(msifile);
363 DeleteFileA("msitest\\cabout\\new\\five.txt");
364 DeleteFileA("msitest\\cabout\\four.txt");
365 DeleteFileA("msitest\\second\\three.txt");
366 DeleteFileA("msitest\\first\\two.txt");
367 DeleteFileA("msitest\\one.txt");
368 DeleteFileA("msitest\\service.exe");
369 DeleteFileA("msitest\\filename");
370 RemoveDirectoryA("msitest\\cabout\\new");
371 RemoveDirectoryA("msitest\\cabout");
372 RemoveDirectoryA("msitest\\second");
373 RemoveDirectoryA("msitest\\first");
374 RemoveDirectoryA("msitest");
377 static void check_service_is_installed(void)
379 SC_HANDLE scm, service;
382 scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
383 ok(scm != NULL, "Failed to open the SC Manager\n");
385 service = OpenService(scm, "TestService", SC_MANAGER_ALL_ACCESS);
386 ok(service != NULL, "Failed to open TestService\n");
388 res = DeleteService(service);
389 ok(res, "Failed to delete TestService\n");
393 * Automation helpers and tests
396 /* ok-like statement which takes two unicode strings or one unicode and one ANSI string as arguments */
397 static CHAR string1[MAX_PATH], string2[MAX_PATH];
399 #define ok_w2(format, szString1, szString2) \
401 if (lstrcmpW(szString1, szString2) != 0) \
403 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
404 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
405 ok(0, format, string1, string2); \
408 #define ok_aw(format, aString, wString) \
410 WideCharToMultiByte(CP_ACP, 0, wString, -1, string1, MAX_PATH, NULL, NULL); \
411 if (lstrcmpA(string1, aString) != 0) \
412 ok(0, format, string1, aString); \
414 #define ok_awplus(format, extra, aString, wString) \
416 WideCharToMultiByte(CP_ACP, 0, wString, -1, string1, MAX_PATH, NULL, NULL); \
417 if (lstrcmpA(string1, aString) != 0) \
418 ok(0, format, extra, string1, aString); \
420 /* exception checker */
421 static WCHAR szSource[] = {'M','s','i',' ','A','P','I',' ','E','r','r','o','r',0};
423 #define ok_exception(hr, szDescription) \
424 if (hr == DISP_E_EXCEPTION) \
426 /* Compare wtype, source, and destination */ \
427 ok(excepinfo.wCode == 1000, "Exception info was %d, expected 1000\n", excepinfo.wCode); \
429 ok(excepinfo.bstrSource != NULL, "Exception source was NULL\n"); \
430 if (excepinfo.bstrSource) \
431 ok_w2("Exception source was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrSource, szSource); \
433 ok(excepinfo.bstrDescription != NULL, "Exception description was NULL\n"); \
434 if (excepinfo.bstrDescription) \
435 ok_w2("Exception description was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrDescription, szDescription); \
438 static DISPID get_dispid( IDispatch *disp, const char *name )
445 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0 );
446 str = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
449 len = MultiByteToWideChar(CP_ACP, 0, name, -1, str, len );
450 r = IDispatch_GetIDsOfNames( disp, &IID_NULL, &str, 1, 0, &id );
451 HeapFree(GetProcessHeap(), 0, str);
459 static void test_dispid(void)
461 ok( get_dispid( pInstaller, "CreateRecord" ) == 1, "dispid wrong\n");
462 ok( get_dispid( pInstaller, "OpenPackage" ) == 2, "dispid wrong\n");
463 todo_wine ok( get_dispid( pInstaller, "OpenProduct" ) == 3, "dispid wrong\n");
464 ok( get_dispid( pInstaller, "OpenDatabase" ) == 4, "dispid wrong\n");
466 ok( get_dispid( pInstaller, "SummaryInformation" ) == 5, "dispid wrong\n");
467 ok( get_dispid( pInstaller, "UILevel" ) == 6, "dispid wrong\n");
468 ok( get_dispid( pInstaller, "EnableLog" ) == 7, "dispid wrong\n");
470 ok( get_dispid( pInstaller, "InstallProduct" ) == 8, "dispid wrong\n");
472 ok( get_dispid( pInstaller, "Version" ) == 9, "dispid wrong\n");
473 ok( get_dispid( pInstaller, "LastErrorRecord" ) == 10, "dispid wrong\n");
475 ok( get_dispid( pInstaller, "RegistryValue" ) == 11, "dispid wrong\n");
477 ok( get_dispid( pInstaller, "Environment" ) == 12, "dispid wrong\n");
478 ok( get_dispid( pInstaller, "FileAttributes" ) == 13, "dispid wrong\n");
480 ok( get_dispid( pInstaller, "FileSize" ) == 15, "dispid wrong\n");
481 ok( get_dispid( pInstaller, "FileVersion" ) == 16, "dispid wrong\n");
483 ok( get_dispid( pInstaller, "ProductState" ) == 17, "dispid wrong\n");
484 ok( get_dispid( pInstaller, "ProductInfo" ) == 18, "dispid wrong\n");
486 ok( get_dispid( pInstaller, "ConfigureProduct" ) == 19, "dispid wrong\n");
487 ok( get_dispid( pInstaller, "ReinstallProduct" ) == 20 , "dispid wrong\n");
488 ok( get_dispid( pInstaller, "CollectUserInfo" ) == 21, "dispid wrong\n");
489 ok( get_dispid( pInstaller, "ApplyPatch" ) == 22, "dispid wrong\n");
490 ok( get_dispid( pInstaller, "FeatureParent" ) == 23, "dispid wrong\n");
491 ok( get_dispid( pInstaller, "FeatureState" ) == 24, "dispid wrong\n");
492 ok( get_dispid( pInstaller, "UseFeature" ) == 25, "dispid wrong\n");
493 ok( get_dispid( pInstaller, "FeatureUsageCount" ) == 26, "dispid wrong\n");
494 ok( get_dispid( pInstaller, "FeatureUsageDate" ) == 27, "dispid wrong\n");
495 ok( get_dispid( pInstaller, "ConfigureFeature" ) == 28, "dispid wrong\n");
496 ok( get_dispid( pInstaller, "ReinstallFeature" ) == 29, "dispid wrong\n");
497 ok( get_dispid( pInstaller, "ProvideComponent" ) == 30, "dispid wrong\n");
498 ok( get_dispid( pInstaller, "ComponentPath" ) == 31, "dispid wrong\n");
499 ok( get_dispid( pInstaller, "ProvideQualifiedComponent" ) == 32, "dispid wrong\n");
500 ok( get_dispid( pInstaller, "QualifierDescription" ) == 33, "dispid wrong\n");
501 ok( get_dispid( pInstaller, "ComponentQualifiers" ) == 34, "dispid wrong\n");
503 ok( get_dispid( pInstaller, "Products" ) == 35, "dispid wrong\n");
505 ok( get_dispid( pInstaller, "Features" ) == 36, "dispid wrong\n");
506 ok( get_dispid( pInstaller, "Components" ) == 37, "dispid wrong\n");
507 ok( get_dispid( pInstaller, "ComponentClients" ) == 38, "dispid wrong\n");
508 ok( get_dispid( pInstaller, "Patches" ) == 39, "dispid wrong\n");
510 ok( get_dispid( pInstaller, "RelatedProducts" ) == 40, "dispid wrong\n");
512 ok( get_dispid( pInstaller, "PatchInfo" ) == 41, "dispid wrong\n");
513 ok( get_dispid( pInstaller, "PatchTransforms" ) == 42, "dispid wrong\n");
514 ok( get_dispid( pInstaller, "AddSource" ) == 43, "dispid wrong\n");
515 ok( get_dispid( pInstaller, "ClearSourceList" ) == 44, "dispid wrong\n");
516 ok( get_dispid( pInstaller, "ForceSourceListResolution" ) == 45, "dispid wrong\n");
517 ok( get_dispid( pInstaller, "ShortcutTarget" ) == 46, "dispid wrong\n");
518 ok( get_dispid( pInstaller, "FileHash" ) == 47, "dispid wrong\n");
519 ok( get_dispid( pInstaller, "FileSignatureInfo" ) == 48, "dispid wrong\n");
520 ok( get_dispid( pInstaller, "RemovePatches" ) == 49, "dispid wrong\n");
522 ok( get_dispid( pInstaller, "ApplyMultiplePatches" ) == 51, "dispid wrong\n");
523 ok( get_dispid( pInstaller, "ProductsEx" ) == 52, "dispid wrong\n");
525 ok( get_dispid( pInstaller, "PatchesEx" ) == 55, "dispid wrong\n");
527 ok( get_dispid( pInstaller, "ExtractPatchXMLData" ) == 57, "dispid wrong\n");
530 /* MSDN claims the following functions exist but IDispatch->GetIDsOfNames disagrees */
533 get_dispid( pInstaller, "ProductElevated" );
534 get_dispid( pInstaller, "ProductInfoFromScript" );
535 get_dispid( pInstaller, "ProvideAssembly" );
536 get_dispid( pInstaller, "CreateAdvertiseScript" );
537 get_dispid( pInstaller, "AdvertiseProduct" );
538 get_dispid( pInstaller, "PatchFiles" );
542 /* Test basic IDispatch functions */
543 static void test_dispatch(void)
545 static WCHAR szOpenPackage[] = { 'O','p','e','n','P','a','c','k','a','g','e',0 };
546 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};
547 static WCHAR szProductState[] = { 'P','r','o','d','u','c','t','S','t','a','t','e',0 };
552 VARIANTARG vararg[2];
553 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
555 /* Test getting ID of a function name that does not exist */
556 name = (WCHAR *)szMsifile;
557 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
558 ok(hr == DISP_E_UNKNOWNNAME, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
560 /* Test invoking this function */
561 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
562 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
564 /* Test getting ID of a function name that does exist */
565 name = (WCHAR *)szOpenPackage;
566 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
567 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
569 /* Test invoking this function (without parameters passed) */
570 if (0) /* All of these crash MSI on Windows XP */
572 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
573 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, &excepinfo, NULL);
574 VariantInit(&varresult);
575 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, &varresult, &excepinfo, NULL);
578 /* Try with NULL params */
579 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
580 todo_wine ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
582 /* Try one empty parameter */
583 dispparams.rgvarg = vararg;
584 dispparams.cArgs = 1;
585 VariantInit(&vararg[0]);
586 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
587 todo_wine ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
589 /* Try one parameter, function requires two */
590 VariantInit(&vararg[0]);
591 V_VT(&vararg[0]) = VT_BSTR;
592 V_BSTR(&vararg[0]) = SysAllocString(szMsifile);
593 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
594 VariantClear(&vararg[0]);
596 ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
597 ok_exception(hr, szOpenPackageException);
599 /* Test invoking a method as a DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT */
600 VariantInit(&vararg[0]);
601 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
602 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
604 VariantInit(&vararg[0]);
605 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
606 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
608 /* Test invoking a read-only property as DISPATCH_PROPERTYPUT or as a DISPATCH_METHOD */
609 name = (WCHAR *)szProductState;
610 hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
611 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
613 dispparams.rgvarg = NULL;
614 dispparams.cArgs = 0;
615 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
616 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
618 dispparams.rgvarg = NULL;
619 dispparams.cArgs = 0;
620 hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
621 ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
624 /* invocation helper function */
625 static int _invoke_todo_vtResult = 0;
627 static HRESULT invoke(IDispatch *pDispatch, LPCSTR szName, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, VARTYPE vtResult)
629 OLECHAR *name = NULL;
635 memset(pVarResult, 0, sizeof(VARIANT));
636 VariantInit(pVarResult);
638 len = MultiByteToWideChar(CP_ACP, 0, szName, -1, NULL, 0 );
639 name = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
640 if (!name) return E_FAIL;
641 len = MultiByteToWideChar(CP_ACP, 0, szName, -1, name, len );
642 hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
643 HeapFree(GetProcessHeap(), 0, name);
644 ok(hr == S_OK, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
645 if (!hr == S_OK) return hr;
647 memset(&excepinfo, 0, sizeof(excepinfo));
648 hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_NEUTRAL, wFlags, pDispParams, pVarResult, &excepinfo, NULL);
652 if (_invoke_todo_vtResult) todo_wine
653 ok(V_VT(pVarResult) == vtResult, "Variant result type is %d, expected %d\n", V_VT(pVarResult), vtResult);
655 ok(V_VT(pVarResult) == vtResult, "Variant result type is %d, expected %d\n", V_VT(pVarResult), vtResult);
656 if (vtResult != VT_EMPTY)
658 hr = VariantChangeTypeEx(pVarResult, pVarResult, LOCALE_NEUTRAL, 0, vtResult);
659 ok(hr == S_OK, "VariantChangeTypeEx returned 0x%08x\n", hr);
663 for (i=0; i<pDispParams->cArgs; i++)
664 VariantClear(&pDispParams->rgvarg[i]);
669 /* Object_Property helper functions */
671 static HRESULT Installer_CreateRecord(int count, IDispatch **pRecord)
674 VARIANTARG vararg[1];
675 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
678 VariantInit(&vararg[0]);
679 V_VT(&vararg[0]) = VT_I4;
680 V_I4(&vararg[0]) = count;
682 hr = invoke(pInstaller, "CreateRecord", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
683 *pRecord = V_DISPATCH(&varresult);
687 static HRESULT Installer_RegistryValue(HKEY hkey, LPCWSTR szKey, VARIANT vValue, VARIANT *pVarResult, VARTYPE vtExpect)
689 VARIANTARG vararg[3];
690 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
692 VariantInit(&vararg[2]);
693 V_VT(&vararg[2]) = VT_I4;
694 V_I4(&vararg[2]) = (int)hkey;
695 VariantInit(&vararg[1]);
696 V_VT(&vararg[1]) = VT_BSTR;
697 V_BSTR(&vararg[1]) = SysAllocString(szKey);
698 VariantInit(&vararg[0]);
699 VariantCopy(&vararg[0], &vValue);
700 VariantClear(&vValue);
702 return invoke(pInstaller, "RegistryValue", DISPATCH_METHOD, &dispparams, pVarResult, vtExpect);
705 static HRESULT Installer_RegistryValueE(HKEY hkey, LPCWSTR szKey, BOOL *pBool)
711 VariantInit(&vararg);
712 V_VT(&vararg) = VT_EMPTY;
713 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BOOL);
714 *pBool = V_BOOL(&varresult);
715 VariantClear(&varresult);
719 static HRESULT Installer_RegistryValueW(HKEY hkey, LPCWSTR szKey, LPCWSTR szValue, LPWSTR szString)
725 VariantInit(&vararg);
726 V_VT(&vararg) = VT_BSTR;
727 V_BSTR(&vararg) = SysAllocString(szValue);
729 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BSTR);
730 if (V_BSTR(&varresult)) lstrcpyW(szString, V_BSTR(&varresult));
731 VariantClear(&varresult);
735 static HRESULT Installer_RegistryValueI(HKEY hkey, LPCWSTR szKey, int iValue, LPWSTR szString, VARTYPE vtResult)
741 VariantInit(&vararg);
742 V_VT(&vararg) = VT_I4;
743 V_I4(&vararg) = iValue;
745 hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, vtResult);
746 if (vtResult == VT_BSTR) lstrcpyW(szString, V_BSTR(&varresult));
747 VariantClear(&varresult);
751 static HRESULT Installer_OpenPackage(LPCWSTR szPackagePath, int options, IDispatch **pSession)
754 VARIANTARG vararg[2];
755 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
758 VariantInit(&vararg[1]);
759 V_VT(&vararg[1]) = VT_BSTR;
760 V_BSTR(&vararg[1]) = SysAllocString(szPackagePath);
761 VariantInit(&vararg[0]);
762 V_VT(&vararg[0]) = VT_I4;
763 V_I4(&vararg[0]) = options;
765 hr = invoke(pInstaller, "OpenPackage", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
766 *pSession = V_DISPATCH(&varresult);
770 static HRESULT Installer_OpenDatabase(LPCWSTR szDatabasePath, int openmode, IDispatch **pDatabase)
773 VARIANTARG vararg[2];
774 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
777 VariantInit(&vararg[1]);
778 V_VT(&vararg[1]) = VT_BSTR;
779 V_BSTR(&vararg[1]) = SysAllocString(szDatabasePath);
780 VariantInit(&vararg[0]);
781 V_VT(&vararg[0]) = VT_I4;
782 V_I4(&vararg[0]) = openmode;
784 hr = invoke(pInstaller, "OpenDatabase", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
785 *pDatabase = V_DISPATCH(&varresult);
789 static HRESULT Installer_InstallProduct(LPCWSTR szPackagePath, LPCWSTR szPropertyValues)
792 VARIANTARG vararg[2];
793 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
795 VariantInit(&vararg[1]);
796 V_VT(&vararg[1]) = VT_BSTR;
797 V_BSTR(&vararg[1]) = SysAllocString(szPackagePath);
798 VariantInit(&vararg[0]);
799 V_VT(&vararg[0]) = VT_BSTR;
800 V_BSTR(&vararg[0]) = SysAllocString(szPropertyValues);
802 return invoke(pInstaller, "InstallProduct", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
805 static HRESULT Installer_ProductState(LPCWSTR szProduct, int *pInstallState)
808 VARIANTARG vararg[1];
809 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
812 VariantInit(&vararg[0]);
813 V_VT(&vararg[0]) = VT_BSTR;
814 V_BSTR(&vararg[0]) = SysAllocString(szProduct);
816 hr = invoke(pInstaller, "ProductState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
817 *pInstallState = V_I4(&varresult);
818 VariantClear(&varresult);
822 static HRESULT Installer_ProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute, LPWSTR szString)
825 VARIANTARG vararg[2];
826 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
829 VariantInit(&vararg[1]);
830 V_VT(&vararg[1]) = VT_BSTR;
831 V_BSTR(&vararg[1]) = SysAllocString(szProduct);
832 VariantInit(&vararg[0]);
833 V_VT(&vararg[0]) = VT_BSTR;
834 V_BSTR(&vararg[0]) = SysAllocString(szAttribute);
836 hr = invoke(pInstaller, "ProductInfo", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
837 if (V_BSTR(&varresult)) lstrcpyW(szString, V_BSTR(&varresult));
838 VariantClear(&varresult);
842 static HRESULT Installer_Products(IDispatch **pStringList)
845 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
848 hr = invoke(pInstaller, "Products", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
849 *pStringList = V_DISPATCH(&varresult);
853 static HRESULT Installer_RelatedProducts(LPCWSTR szProduct, IDispatch **pStringList)
856 VARIANTARG vararg[1];
857 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
860 VariantInit(&vararg[0]);
861 V_VT(&vararg[0]) = VT_BSTR;
862 V_BSTR(&vararg[0]) = SysAllocString(szProduct);
864 hr = invoke(pInstaller, "RelatedProducts", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
865 *pStringList = V_DISPATCH(&varresult);
869 static HRESULT Installer_VersionGet(LPWSTR szVersion)
872 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
875 hr = invoke(pInstaller, "Version", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
876 if (V_BSTR(&varresult)) lstrcpyW(szVersion, V_BSTR(&varresult));
877 VariantClear(&varresult);
881 static HRESULT Session_Installer(IDispatch *pSession, IDispatch **pInst)
884 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
887 hr = invoke(pSession, "Installer", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
888 *pInst = V_DISPATCH(&varresult);
892 static HRESULT Session_PropertyGet(IDispatch *pSession, LPCWSTR szName, LPWSTR szReturn)
895 VARIANTARG vararg[1];
896 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
899 VariantInit(&vararg[0]);
900 V_VT(&vararg[0]) = VT_BSTR;
901 V_BSTR(&vararg[0]) = SysAllocString(szName);
903 hr = invoke(pSession, "Property", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
904 if (V_BSTR(&varresult)) lstrcpyW(szReturn, V_BSTR(&varresult));
905 VariantClear(&varresult);
909 static HRESULT Session_PropertyPut(IDispatch *pSession, LPCWSTR szName, LPCWSTR szValue)
912 VARIANTARG vararg[2];
913 DISPID dispid = DISPID_PROPERTYPUT;
914 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
916 VariantInit(&vararg[1]);
917 V_VT(&vararg[1]) = VT_BSTR;
918 V_BSTR(&vararg[1]) = SysAllocString(szName);
919 VariantInit(&vararg[0]);
920 V_VT(&vararg[0]) = VT_BSTR;
921 V_BSTR(&vararg[0]) = SysAllocString(szValue);
923 return invoke(pSession, "Property", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
926 static HRESULT Session_LanguageGet(IDispatch *pSession, UINT *pLangId)
929 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
932 hr = invoke(pSession, "Language", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
933 *pLangId = V_I4(&varresult);
934 VariantClear(&varresult);
938 static HRESULT Session_ModeGet(IDispatch *pSession, int iFlag, BOOL *pMode)
941 VARIANTARG vararg[1];
942 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
945 VariantInit(&vararg[0]);
946 V_VT(&vararg[0]) = VT_I4;
947 V_I4(&vararg[0]) = iFlag;
949 hr = invoke(pSession, "Mode", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BOOL);
950 *pMode = V_BOOL(&varresult);
951 VariantClear(&varresult);
955 static HRESULT Session_ModePut(IDispatch *pSession, int iFlag, BOOL bMode)
958 VARIANTARG vararg[2];
959 DISPID dispid = DISPID_PROPERTYPUT;
960 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
962 VariantInit(&vararg[1]);
963 V_VT(&vararg[1]) = VT_I4;
964 V_I4(&vararg[1]) = iFlag;
965 VariantInit(&vararg[0]);
966 V_VT(&vararg[0]) = VT_BOOL;
967 V_BOOL(&vararg[0]) = bMode;
969 return invoke(pSession, "Mode", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
972 static HRESULT Session_Database(IDispatch *pSession, IDispatch **pDatabase)
975 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
978 hr = invoke(pSession, "Database", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
979 *pDatabase = V_DISPATCH(&varresult);
983 static HRESULT Session_DoAction(IDispatch *pSession, LPCWSTR szAction, int *iReturn)
986 VARIANTARG vararg[1];
987 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
990 VariantInit(&vararg[0]);
991 V_VT(&vararg[0]) = VT_BSTR;
992 V_BSTR(&vararg[0]) = SysAllocString(szAction);
994 hr = invoke(pSession, "DoAction", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
995 *iReturn = V_I4(&varresult);
996 VariantClear(&varresult);
1000 static HRESULT Session_EvaluateCondition(IDispatch *pSession, LPCWSTR szCondition, int *iReturn)
1003 VARIANTARG vararg[1];
1004 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1007 VariantInit(&vararg[0]);
1008 V_VT(&vararg[0]) = VT_BSTR;
1009 V_BSTR(&vararg[0]) = SysAllocString(szCondition);
1011 hr = invoke(pSession, "EvaluateCondition", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
1012 *iReturn = V_I4(&varresult);
1013 VariantClear(&varresult);
1017 static HRESULT Session_SetInstallLevel(IDispatch *pSession, long iInstallLevel)
1020 VARIANTARG vararg[1];
1021 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1023 VariantInit(&vararg[0]);
1024 V_VT(&vararg[0]) = VT_I4;
1025 V_I4(&vararg[0]) = iInstallLevel;
1027 return invoke(pSession, "SetInstallLevel", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1030 static HRESULT Session_FeatureCurrentState(IDispatch *pSession, LPCWSTR szName, int *pState)
1033 VARIANTARG vararg[1];
1034 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1037 VariantInit(&vararg[0]);
1038 V_VT(&vararg[0]) = VT_BSTR;
1039 V_BSTR(&vararg[0]) = SysAllocString(szName);
1041 hr = invoke(pSession, "FeatureCurrentState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1042 *pState = V_I4(&varresult);
1043 VariantClear(&varresult);
1047 static HRESULT Session_FeatureRequestStateGet(IDispatch *pSession, LPCWSTR szName, int *pState)
1050 VARIANTARG vararg[1];
1051 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1054 VariantInit(&vararg[0]);
1055 V_VT(&vararg[0]) = VT_BSTR;
1056 V_BSTR(&vararg[0]) = SysAllocString(szName);
1058 hr = invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1059 *pState = V_I4(&varresult);
1060 VariantClear(&varresult);
1064 static HRESULT Session_FeatureRequestStatePut(IDispatch *pSession, LPCWSTR szName, int iState)
1067 VARIANTARG vararg[2];
1068 DISPID dispid = DISPID_PROPERTYPUT;
1069 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1071 VariantInit(&vararg[1]);
1072 V_VT(&vararg[1]) = VT_BSTR;
1073 V_BSTR(&vararg[1]) = SysAllocString(szName);
1074 VariantInit(&vararg[0]);
1075 V_VT(&vararg[0]) = VT_I4;
1076 V_I4(&vararg[0]) = iState;
1078 return invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1081 static HRESULT Database_OpenView(IDispatch *pDatabase, LPCWSTR szSql, IDispatch **pView)
1084 VARIANTARG vararg[1];
1085 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1088 VariantInit(&vararg[0]);
1089 V_VT(&vararg[0]) = VT_BSTR;
1090 V_BSTR(&vararg[0]) = SysAllocString(szSql);
1092 hr = invoke(pDatabase, "OpenView", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
1093 *pView = V_DISPATCH(&varresult);
1097 static HRESULT Database_SummaryInformation(IDispatch *pDatabase, int iUpdateCount, IDispatch **pSummaryInfo)
1100 VARIANTARG vararg[1];
1101 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1104 VariantInit(&vararg[0]);
1105 V_VT(&vararg[0]) = VT_I4;
1106 V_I4(&vararg[0]) = iUpdateCount;
1108 hr = invoke(pDatabase, "SummaryInformation", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1109 *pSummaryInfo = V_DISPATCH(&varresult);
1113 static HRESULT View_Execute(IDispatch *pView, IDispatch *pRecord)
1116 VARIANTARG vararg[1];
1117 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1119 VariantInit(&vararg[0]);
1120 V_VT(&vararg[0]) = VT_DISPATCH;
1121 V_DISPATCH(&vararg[0]) = pRecord;
1123 return invoke(pView, "Execute", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1126 static HRESULT View_Fetch(IDispatch *pView, IDispatch **ppRecord)
1129 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1130 HRESULT hr = invoke(pView, "Fetch", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
1131 *ppRecord = V_DISPATCH(&varresult);
1135 static HRESULT View_Modify(IDispatch *pView, int iMode, IDispatch *pRecord)
1138 VARIANTARG vararg[2];
1139 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1141 VariantInit(&vararg[1]);
1142 V_VT(&vararg[1]) = VT_I4;
1143 V_I4(&vararg[1]) = iMode;
1144 VariantInit(&vararg[0]);
1145 V_VT(&vararg[0]) = VT_DISPATCH;
1146 V_DISPATCH(&vararg[0]) = pRecord;
1148 IDispatch_AddRef(pRecord); /* VariantClear in invoke will call IDispatch_Release */
1150 return invoke(pView, "Modify", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1153 static HRESULT View_Close(IDispatch *pView)
1156 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1157 return invoke(pView, "Close", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
1160 static HRESULT Record_FieldCountGet(IDispatch *pRecord, int *pFieldCount)
1163 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1164 HRESULT hr = invoke(pRecord, "FieldCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1165 *pFieldCount = V_I4(&varresult);
1166 VariantClear(&varresult);
1170 static HRESULT Record_StringDataGet(IDispatch *pRecord, int iField, LPWSTR szString)
1173 VARIANTARG vararg[1];
1174 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1177 VariantInit(&vararg[0]);
1178 V_VT(&vararg[0]) = VT_I4;
1179 V_I4(&vararg[0]) = iField;
1181 hr = invoke(pRecord, "StringData", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1182 if (V_BSTR(&varresult)) lstrcpyW(szString, V_BSTR(&varresult));
1183 VariantClear(&varresult);
1187 static HRESULT Record_StringDataPut(IDispatch *pRecord, int iField, LPCWSTR szString)
1190 VARIANTARG vararg[2];
1191 DISPID dispid = DISPID_PROPERTYPUT;
1192 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1194 VariantInit(&vararg[1]);
1195 V_VT(&vararg[1]) = VT_I4;
1196 V_I4(&vararg[1]) = iField;
1197 VariantInit(&vararg[0]);
1198 V_VT(&vararg[0]) = VT_BSTR;
1199 V_BSTR(&vararg[0]) = SysAllocString(szString);
1201 return invoke(pRecord, "StringData", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1204 static HRESULT Record_IntegerDataGet(IDispatch *pRecord, int iField, int *pValue)
1207 VARIANTARG vararg[1];
1208 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1211 VariantInit(&vararg[0]);
1212 V_VT(&vararg[0]) = VT_I4;
1213 V_I4(&vararg[0]) = iField;
1215 hr = invoke(pRecord, "IntegerData", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1216 *pValue = V_I4(&varresult);
1217 VariantClear(&varresult);
1221 static HRESULT Record_IntegerDataPut(IDispatch *pRecord, int iField, int iValue)
1224 VARIANTARG vararg[2];
1225 DISPID dispid = DISPID_PROPERTYPUT;
1226 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1228 VariantInit(&vararg[1]);
1229 V_VT(&vararg[1]) = VT_I4;
1230 V_I4(&vararg[1]) = iField;
1231 VariantInit(&vararg[0]);
1232 V_VT(&vararg[0]) = VT_I4;
1233 V_I4(&vararg[0]) = iValue;
1235 return invoke(pRecord, "IntegerData", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1238 static HRESULT StringList__NewEnum(IDispatch *pList, IUnknown **ppEnumVARIANT)
1241 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1242 HRESULT hr = invoke(pList, "_NewEnum", DISPATCH_METHOD, &dispparams, &varresult, VT_UNKNOWN);
1243 *ppEnumVARIANT = V_UNKNOWN(&varresult);
1247 static HRESULT StringList_Item(IDispatch *pStringList, int iIndex, LPWSTR szString)
1250 VARIANTARG vararg[1];
1251 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1254 VariantInit(&vararg[0]);
1255 V_VT(&vararg[0]) = VT_I4;
1256 V_I4(&vararg[0]) = iIndex;
1258 hr = invoke(pStringList, "Item", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
1259 if (V_BSTR(&varresult)) lstrcpyW(szString, V_BSTR(&varresult));
1260 VariantClear(&varresult);
1264 static HRESULT StringList_Count(IDispatch *pStringList, int *pCount)
1267 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1268 HRESULT hr = invoke(pStringList, "Count", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1269 *pCount = V_I4(&varresult);
1270 VariantClear(&varresult);
1274 static HRESULT SummaryInfo_PropertyGet(IDispatch *pSummaryInfo, int pid, VARIANT *pVarResult, VARTYPE vtExpect)
1276 VARIANTARG vararg[1];
1277 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1279 VariantInit(&vararg[0]);
1280 V_VT(&vararg[0]) = VT_I4;
1281 V_I4(&vararg[0]) = pid;
1282 return invoke(pSummaryInfo, "Property", DISPATCH_PROPERTYGET, &dispparams, pVarResult, vtExpect);
1285 static HRESULT SummaryInfo_PropertyPut(IDispatch *pSummaryInfo, int pid, VARIANT *pVariant)
1288 VARIANTARG vararg[2];
1289 DISPID dispid = DISPID_PROPERTYPUT;
1290 DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
1292 VariantInit(&vararg[1]);
1293 V_VT(&vararg[1]) = VT_I4;
1294 V_I4(&vararg[1]) = pid;
1295 VariantInit(&vararg[0]);
1296 VariantCopyInd(vararg, pVariant);
1298 return invoke(pSummaryInfo, "Property", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
1301 static HRESULT SummaryInfo_PropertyCountGet(IDispatch *pSummaryInfo, int *pCount)
1304 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1307 hr = invoke(pSummaryInfo, "PropertyCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1308 *pCount = V_I4(&varresult);
1309 VariantClear(&varresult);
1313 /* Test the various objects */
1315 #define TEST_SUMMARYINFO_PROPERTIES_MODIFIED 4
1317 static void test_SummaryInfo(IDispatch *pSummaryInfo, const msi_summary_info *info, int num_info, BOOL readonly)
1319 static const WCHAR szPropertyException[] = { 'P','r','o','p','e','r','t','y',',','P','i','d',0 };
1320 static const WCHAR szTitle[] = { 'T','i','t','l','e',0 };
1321 VARIANT varresult, var;
1326 /* SummaryInfo::PropertyCount */
1327 hr = SummaryInfo_PropertyCountGet(pSummaryInfo, &j);
1328 ok(hr == S_OK, "SummaryInfo_PropertyCount failed, hresult 0x%08x\n", hr);
1329 ok(j == num_info, "SummaryInfo_PropertyCount returned %d, expected %d\n", j, num_info);
1331 /* SummaryInfo::Property, get for properties we have set */
1332 for (j = 0; j < num_info; j++)
1334 const msi_summary_info *entry = &info[j];
1336 int vt = entry->datatype;
1337 if (vt == VT_LPSTR) vt = VT_BSTR;
1338 else if (vt == VT_FILETIME) vt = VT_DATE;
1339 else if (vt == VT_I2) vt = VT_I4;
1341 hr = SummaryInfo_PropertyGet(pSummaryInfo, entry->property, &varresult, vt);
1342 ok(hr == S_OK, "SummaryInfo_Property (pid %d) failed, hresult 0x%08x\n", entry->property, hr);
1343 if (V_VT(&varresult) != vt)
1344 skip("Skipping property tests due to type mismatch\n");
1345 else if (vt == VT_I4)
1346 ok(V_I4(&varresult) == entry->iValue, "SummaryInfo_Property (pid %d) I4 result expected to be %d, but was %d\n",
1347 entry->property, entry->iValue, V_I4(&varresult));
1348 else if (vt == VT_DATE)
1353 FileTimeToLocalFileTime(entry->pftValue, &ft);
1354 FileTimeToSystemTime(&ft, &st);
1355 SystemTimeToVariantTime(&st, &d);
1356 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));
1358 else if (vt == VT_BSTR)
1360 ok_awplus("SummaryInfo_Property (pid %d) BSTR result expected to be %s, but was %s\n", entry->property, entry->szValue, V_BSTR(&varresult));
1363 skip("SummaryInfo_Property (pid %d) unhandled result type %d\n", entry->property, vt);
1366 /* SummaryInfo::Property, get; invalid arguments */
1369 hr = SummaryInfo_PropertyGet(pSummaryInfo, -1, &varresult, VT_EMPTY);
1370 ok(hr == DISP_E_EXCEPTION, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1371 ok_exception(hr, szPropertyException);
1373 hr = SummaryInfo_PropertyGet(pSummaryInfo, 1000, &varresult, VT_EMPTY);
1374 ok(hr == DISP_E_EXCEPTION, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1375 ok_exception(hr, szPropertyException);
1377 /* Unsupported pids */
1378 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_DICTIONARY, &varresult, VT_EMPTY);
1379 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1381 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_THUMBNAIL, &varresult, VT_EMPTY);
1382 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1384 /* Pids we have not set, one for each type */
1385 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CODEPAGE, &varresult, VT_EMPTY);
1386 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1388 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_TITLE, &varresult, VT_EMPTY);
1389 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1391 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_EDITTIME, &varresult, VT_EMPTY);
1392 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1394 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CHARCOUNT, &varresult, VT_EMPTY);
1395 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1399 /* SummaryInfo::Property, put; one for each type */
1405 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_CODEPAGE, &var);
1406 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1408 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CODEPAGE, &varresult, VT_I4 /* NOT VT_I2 */);
1409 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1410 ok(V_I2(&var) == V_I2(&varresult), "SummaryInfo_PropertyGet expected %d, but returned %d\n", V_I2(&var), V_I2(&varresult));
1411 VariantClear(&varresult);
1415 V_VT(&var) = VT_BSTR;
1416 V_BSTR(&var) = SysAllocString(szTitle);
1417 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_TITLE, &var);
1418 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1420 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_TITLE, &varresult, V_VT(&var));
1421 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1422 ok_w2("SummaryInfo_PropertyGet expected %s, but returned %s\n", V_BSTR(&var), V_BSTR(&varresult));
1423 VariantClear(&varresult);
1427 V_VT(&var) = VT_DATE;
1428 FileTimeToSystemTime(&systemtime, &st);
1429 SystemTimeToVariantTime(&st, &V_DATE(&var));
1430 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_LASTSAVE_DTM, &var);
1431 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1433 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_LASTSAVE_DTM, &varresult, V_VT(&var));
1434 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1435 /* FIXME: Off by one second */
1436 todo_wine ok(V_DATE(&var) == V_DATE(&varresult), "SummaryInfo_PropertyGet expected %lf, but returned %lf\n", V_DATE(&var), V_DATE(&varresult));
1437 VariantClear(&varresult);
1443 hr = SummaryInfo_PropertyPut(pSummaryInfo, PID_CHARCOUNT, &var);
1444 ok(hr == S_OK, "SummaryInfo_PropertyPut failed, hresult 0x%08x\n", hr);
1446 hr = SummaryInfo_PropertyGet(pSummaryInfo, PID_CHARCOUNT, &varresult, V_VT(&var));
1447 ok(hr == S_OK, "SummaryInfo_PropertyGet failed, hresult 0x%08x\n", hr);
1448 ok(V_I4(&var) == V_I4(&varresult), "SummaryInfo_PropertyGet expected %d, but returned %d\n", V_I4(&var), V_I4(&varresult));
1449 VariantClear(&varresult);
1452 /* SummaryInfo::PropertyCount */
1453 hr = SummaryInfo_PropertyCountGet(pSummaryInfo, &j);
1454 ok(hr == S_OK, "SummaryInfo_PropertyCount failed, hresult 0x%08x\n", hr);
1455 ok(j == num_info+4, "SummaryInfo_PropertyCount returned %d, expected %d\n", j, num_info);
1459 static void test_Database(IDispatch *pDatabase, BOOL readonly)
1461 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 };
1462 static WCHAR szThree[] = { 'T','h','r','e','e',0 };
1463 static WCHAR szTwo[] = { 'T','w','o',0 };
1464 static WCHAR szStringDataField[] = { 'S','t','r','i','n','g','D','a','t','a',',','F','i','e','l','d',0 };
1465 static WCHAR szModifyModeRecord[] = { 'M','o','d','i','f','y',',','M','o','d','e',',','R','e','c','o','r','d',0 };
1466 IDispatch *pView = NULL, *pSummaryInfo = NULL;
1469 hr = Database_OpenView(pDatabase, szSql, &pView);
1470 ok(hr == S_OK, "Database_OpenView failed, hresult 0x%08x\n", hr);
1473 IDispatch *pRecord = NULL;
1474 WCHAR szString[MAX_PATH];
1477 hr = View_Execute(pView, NULL);
1478 ok(hr == S_OK, "View_Execute failed, hresult 0x%08x\n", hr);
1481 hr = View_Fetch(pView, &pRecord);
1482 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1483 ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
1486 /* Record::StringDataGet */
1487 memset(szString, 0, sizeof(szString));
1488 hr = Record_StringDataGet(pRecord, 1, szString);
1489 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1490 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szThree);
1492 /* Record::StringDataPut with correct index */
1493 hr = Record_StringDataPut(pRecord, 1, szTwo);
1494 ok(hr == S_OK, "Record_StringDataPut failed, hresult 0x%08x\n", hr);
1496 /* Record::StringDataGet */
1497 memset(szString, 0, sizeof(szString));
1498 hr = Record_StringDataGet(pRecord, 1, szString);
1499 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1500 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szTwo);
1502 /* Record::StringDataPut with incorrect index */
1503 hr = Record_StringDataPut(pRecord, -1, szString);
1504 ok(hr == DISP_E_EXCEPTION, "Record_StringDataPut failed, hresult 0x%08x\n", hr);
1505 ok_exception(hr, szStringDataField);
1507 /* View::Modify with incorrect parameters */
1508 hr = View_Modify(pView, -5, NULL);
1509 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1510 ok_exception(hr, szModifyModeRecord);
1512 hr = View_Modify(pView, -5, pRecord);
1513 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1514 ok_exception(hr, szModifyModeRecord);
1516 hr = View_Modify(pView, MSIMODIFY_REFRESH, NULL);
1517 ok(hr == DISP_E_EXCEPTION, "View_Modify failed, hresult 0x%08x\n", hr);
1518 ok_exception(hr, szModifyModeRecord);
1520 /* View::Modify with MSIMODIFY_REFRESH should undo our changes */
1521 hr = View_Modify(pView, MSIMODIFY_REFRESH, pRecord);
1522 /* Wine's MsiViewModify currently does not support MSIMODIFY_REFRESH */
1523 todo_wine ok(hr == S_OK, "View_Modify failed, hresult 0x%08x\n", hr);
1525 /* Record::StringDataGet, confirm that the record is back to its unmodified value */
1526 memset(szString, 0, sizeof(szString));
1527 hr = Record_StringDataGet(pRecord, 1, szString);
1528 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1529 todo_wine ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szThree);
1531 IDispatch_Release(pRecord);
1535 hr = View_Fetch(pView, &pRecord);
1536 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1537 ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
1540 /* Record::StringDataGet */
1541 memset(szString, 0, sizeof(szString));
1542 hr = Record_StringDataGet(pRecord, 1, szString);
1543 ok(hr == S_OK, "Record_StringDataGet failed, hresult 0x%08x\n", hr);
1544 ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szTwo);
1546 IDispatch_Release(pRecord);
1550 hr = View_Fetch(pView, &pRecord);
1551 ok(hr == S_OK, "View_Fetch failed, hresult 0x%08x\n", hr);
1552 ok(pRecord == NULL, "View_Fetch should have returned NULL record\n");
1554 IDispatch_Release(pRecord);
1557 hr = View_Close(pView);
1558 ok(hr == S_OK, "View_Close failed, hresult 0x%08x\n", hr);
1560 IDispatch_Release(pView);
1563 /* Database::SummaryInformation */
1564 hr = Database_SummaryInformation(pDatabase, TEST_SUMMARYINFO_PROPERTIES_MODIFIED, &pSummaryInfo);
1565 ok(hr == S_OK, "Database_SummaryInformation failed, hresult 0x%08x\n", hr);
1566 ok(pSummaryInfo != NULL, "Database_SummaryInformation should not have returned NULL record\n");
1569 test_SummaryInfo(pSummaryInfo, summary_info, sizeof(summary_info)/sizeof(msi_summary_info), readonly);
1570 IDispatch_Release(pSummaryInfo);
1574 static void test_Session(IDispatch *pSession)
1576 static WCHAR szProductName[] = { 'P','r','o','d','u','c','t','N','a','m','e',0 };
1577 static WCHAR szOne[] = { 'O','n','e',0 };
1578 static WCHAR szOneStateFalse[] = { '!','O','n','e','>','0',0 };
1579 static WCHAR szOneStateTrue[] = { '!','O','n','e','=','-','1',0 };
1580 static WCHAR szOneActionFalse[] = { '$','O','n','e','=','-','1',0 };
1581 static WCHAR szOneActionTrue[] = { '$','O','n','e','>','0',0 };
1582 static WCHAR szCostInitialize[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1583 static WCHAR szEmpty[] = { 0 };
1584 static WCHAR szEquals[] = { '=',0 };
1585 static WCHAR szPropertyName[] = { 'P','r','o','p','e','r','t','y',',','N','a','m','e',0 };
1586 WCHAR stringw[MAX_PATH];
1587 CHAR string[MAX_PATH];
1591 IDispatch *pDatabase = NULL, *pInst = NULL;
1594 /* Session::Installer */
1595 hr = Session_Installer(pSession, &pInst);
1596 ok(hr == S_OK, "Session_Installer failed, hresult 0x%08x\n", hr);
1597 ok(pInst != NULL, "Session_Installer returned NULL IDispatch pointer\n");
1598 ok(pInst == pInstaller, "Session_Installer does not match Installer instance from CoCreateInstance\n");
1600 /* Session::Property, get */
1601 memset(stringw, 0, sizeof(stringw));
1602 hr = Session_PropertyGet(pSession, szProductName, stringw);
1603 ok(hr == S_OK, "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1604 if (lstrcmpW(stringw, szMSITEST) != 0)
1606 len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1607 ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1608 ok(0, "Property \"ProductName\" expected to be \"MSITEST\" but was \"%s\"\n", string);
1611 /* Session::Property, put */
1612 hr = Session_PropertyPut(pSession, szProductName, szProductName);
1613 ok(hr == S_OK, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1614 memset(stringw, 0, sizeof(stringw));
1615 hr = Session_PropertyGet(pSession, szProductName, stringw);
1616 ok(hr == S_OK, "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1617 if (lstrcmpW(stringw, szProductName) != 0)
1619 len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1620 ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1621 ok(0, "Property \"ProductName\" expected to be \"ProductName\" but was \"%s\"\n", string);
1624 /* Try putting a property using empty property identifier */
1625 hr = Session_PropertyPut(pSession, szEmpty, szProductName);
1626 ok(hr == DISP_E_EXCEPTION, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1627 ok_exception(hr, szPropertyName);
1629 /* Try putting a property using illegal property identifier */
1630 hr = Session_PropertyPut(pSession, szEquals, szProductName);
1631 ok(hr == S_OK, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1633 /* Session::Language, get */
1634 hr = Session_LanguageGet(pSession, &len);
1635 ok(hr == S_OK, "Session_LanguageGet failed, hresult 0x%08x\n", hr);
1636 /* Not sure how to check the language is correct */
1638 /* Session::Mode, get */
1639 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1640 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1641 todo_wine ok(!bool, "Reboot at end session mode is %d\n", bool);
1643 /* Session::Mode, put */
1644 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, TRUE);
1645 todo_wine ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1646 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1647 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1648 ok(bool, "Reboot at end session mode is %d, expected 1\n", bool);
1649 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, FALSE); /* set it again so we don't reboot */
1650 todo_wine ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1652 /* Session::Database, get */
1653 hr = Session_Database(pSession, &pDatabase);
1654 ok(hr == S_OK, "Session_Database failed, hresult 0x%08x\n", hr);
1657 test_Database(pDatabase, TRUE);
1658 IDispatch_Release(pDatabase);
1661 /* Session::EvaluateCondition */
1662 hr = Session_EvaluateCondition(pSession, NULL, &myint);
1663 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1664 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1666 hr = Session_EvaluateCondition(pSession, szEmpty, &myint);
1667 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1668 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1670 hr = Session_EvaluateCondition(pSession, szEquals, &myint);
1671 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1672 ok(myint == MSICONDITION_ERROR, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1674 /* Session::DoAction(CostInitialize) must occur before the next statements */
1675 hr = Session_DoAction(pSession, szCostInitialize, &myint);
1676 ok(hr == S_OK, "Session_DoAction failed, hresult 0x%08x\n", hr);
1677 ok(myint == IDOK, "DoAction(CostInitialize) returned %d, %d expected\n", myint, IDOK);
1679 /* Session::SetInstallLevel */
1680 hr = Session_SetInstallLevel(pSession, INSTALLLEVEL_MINIMUM);
1681 ok(hr == S_OK, "Session_SetInstallLevel failed, hresult 0x%08x\n", hr);
1683 /* Session::FeatureCurrentState, get */
1684 hr = Session_FeatureCurrentState(pSession, szOne, &myint);
1685 ok(hr == S_OK, "Session_FeatureCurrentState failed, hresult 0x%08x\n", hr);
1686 ok(myint == INSTALLSTATE_UNKNOWN, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1688 /* Session::EvaluateCondition */
1689 hr = Session_EvaluateCondition(pSession, szOneStateFalse, &myint);
1690 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1691 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1693 hr = Session_EvaluateCondition(pSession, szOneStateTrue, &myint);
1694 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1695 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1697 /* Session::FeatureRequestState, put */
1698 hr = Session_FeatureRequestStatePut(pSession, szOne, INSTALLSTATE_ADVERTISED);
1699 ok(hr == S_OK, "Session_FeatureRequestStatePut failed, hresult 0x%08x\n", hr);
1700 hr = Session_FeatureRequestStateGet(pSession, szOne, &myint);
1701 ok(hr == S_OK, "Session_FeatureRequestStateGet failed, hresult 0x%08x\n", hr);
1702 ok(myint == INSTALLSTATE_ADVERTISED, "Feature request state was %d but expected %d\n", myint, INSTALLSTATE_ADVERTISED);
1704 /* Session::EvaluateCondition */
1705 hr = Session_EvaluateCondition(pSession, szOneActionFalse, &myint);
1706 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1707 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1709 hr = Session_EvaluateCondition(pSession, szOneActionTrue, &myint);
1710 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1711 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1714 /* delete key and all its subkeys */
1715 static DWORD delete_key( HKEY hkey )
1717 char name[MAX_PATH];
1720 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
1723 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
1725 ret = delete_key( tmp );
1730 if (ret != ERROR_NO_MORE_ITEMS) return ret;
1731 RegDeleteKeyA( hkey, "" );
1735 static void test_Installer_RegistryValue(void)
1737 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
1738 static const WCHAR szKey[] = { 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t',0 };
1739 static const WCHAR szOne[] = { 'O','n','e',0 };
1740 static const WCHAR szTwo[] = { 'T','w','o',0 };
1741 static const WCHAR szThree[] = { 'T','h','r','e','e',0 };
1742 static const WCHAR szREG_BINARY[] = { '(','R','E','G','_','B','I','N','A','R','Y',')',0 };
1743 static const WCHAR szFour[] = { 'F','o','u','r',0 };
1744 static const WCHAR szExpand[] = { '%','M','S','I','T','E','S','T','%',0 };
1745 static const WCHAR szFive[] = { 'F','i','v','e',0,'H','i',0,0 };
1746 static const WCHAR szFiveHi[] = { 'F','i','v','e','\n','H','i',0 };
1747 static const WCHAR szSix[] = { 'S','i','x',0 };
1748 static const WCHAR szREG_[] = { '(','R','E','G','_',']',0 };
1749 static const WCHAR szSeven[] = { 'S','e','v','e','n',0 };
1750 static const WCHAR szEight[] = { 'E','i','g','h','t',0 };
1751 static const WCHAR szBlank[] = { 0 };
1754 WCHAR szString[MAX_PATH];
1755 HKEY hkey, hkey_sub;
1760 if (!RegOpenKeyW( HKEY_CURRENT_USER, szKey, &hkey )) delete_key( hkey );
1762 /* Does our key exist? Shouldn't; check with all three possible value parameter types */
1763 hr = Installer_RegistryValueE(HKEY_CURRENT_USER, szKey, &bRet);
1764 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
1765 ok(!bRet, "Registry key expected to not exist, but Installer_RegistryValue claims it does\n");
1767 memset(szString, 0, sizeof(szString));
1768 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, NULL, szString);
1769 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1771 memset(szString, 0, sizeof(szString));
1772 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 0, szString, VT_BSTR);
1773 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1776 ok(!RegCreateKeyW( HKEY_CURRENT_USER, szKey, &hkey ), "RegCreateKeyW failed\n");
1778 ok(!RegSetValueExW(hkey,szOne,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
1779 "RegSetValueExW failed\n");
1780 ok(!RegSetValueExW(hkey,szTwo,0,REG_DWORD, (const BYTE *)qw, 4),
1781 "RegSetValueExW failed\n");
1782 ok(!RegSetValueExW(hkey,szThree,0,REG_BINARY, (const BYTE *)qw, 4),
1783 "RegSetValueExW failed\n");
1784 ok(SetEnvironmentVariableA("MSITEST", "Four"), "SetEnvironmentVariableA failed %d\n", GetLastError());
1785 ok(!RegSetValueExW(hkey,szFour,0,REG_EXPAND_SZ, (const BYTE *)szExpand, sizeof(szExpand)),
1786 "RegSetValueExW failed\n");
1787 ok(!RegSetValueExW(hkey,szFive,0,REG_MULTI_SZ, (const BYTE *)szFive, sizeof(szFive)),
1788 "RegSetValueExW failed\n");
1789 ok(!RegSetValueExW(hkey,szSix,0,REG_QWORD, (const BYTE *)qw, 8),
1790 "RegSetValueExW failed\n");
1791 ok(!RegSetValueExW(hkey,szSeven,0,REG_NONE, (const BYTE *)NULL, 0),
1792 "RegSetValueExW failed\n");
1794 ok(!RegSetValueExW(hkey,NULL,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
1795 "RegSetValueExW failed\n");
1797 ok(!RegCreateKeyW( hkey, szEight, &hkey_sub ), "RegCreateKeyW failed\n");
1799 /* Does our key exist? It should, and make sure we retrieve the correct default value */
1801 hr = Installer_RegistryValueE(HKEY_CURRENT_USER, szKey, &bRet);
1802 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
1803 ok(bRet, "Registry key expected to exist, but Installer_RegistryValue claims it does not\n");
1805 memset(szString, 0, sizeof(szString));
1806 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, NULL, szString);
1807 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1808 ok_w2("Default registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
1810 /* Ask for the value of a nonexistent key */
1811 memset(szString, 0, sizeof(szString));
1812 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szExpand, szString);
1813 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1815 /* Get values of keys */
1816 memset(szString, 0, sizeof(szString));
1817 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szOne, szString);
1818 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1819 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
1821 VariantInit(&vararg);
1822 V_VT(&vararg) = VT_BSTR;
1823 V_BSTR(&vararg) = SysAllocString(szTwo);
1824 hr = Installer_RegistryValue(HKEY_CURRENT_USER, szKey, vararg, &varresult, VT_I4);
1825 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
1826 ok(V_I4(&varresult) == 305419896, "Registry value %d does not match expected value\n", V_I4(&varresult));
1827 VariantClear(&varresult);
1829 memset(szString, 0, sizeof(szString));
1830 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szThree, szString);
1831 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1832 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_BINARY);
1834 memset(szString, 0, sizeof(szString));
1835 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szFour, szString);
1836 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1837 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFour);
1839 memset(szString, 0, sizeof(szString));
1840 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szFive, szString);
1841 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1842 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFiveHi);
1844 memset(szString, 0, sizeof(szString));
1845 hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szSix, szString);
1846 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1847 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_);
1849 VariantInit(&vararg);
1850 V_VT(&vararg) = VT_BSTR;
1851 V_BSTR(&vararg) = SysAllocString(szSeven);
1852 hr = Installer_RegistryValue(HKEY_CURRENT_USER, szKey, vararg, &varresult, VT_EMPTY);
1853 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
1855 /* Get string class name for the key */
1856 memset(szString, 0, sizeof(szString));
1857 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 0, szString, VT_BSTR);
1858 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1859 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szBlank);
1861 /* Get name of a value by positive number (RegEnumValue like), valid index */
1862 memset(szString, 0, sizeof(szString));
1863 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 2, szString, VT_BSTR);
1864 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1865 /* RegEnumValue order seems different on wine */
1866 todo_wine ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szTwo);
1868 /* Get name of a value by positive number (RegEnumValue like), invalid index */
1869 memset(szString, 0, sizeof(szString));
1870 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 10, szString, VT_EMPTY);
1871 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1873 /* Get name of a subkey by negative number (RegEnumValue like), valid index */
1874 memset(szString, 0, sizeof(szString));
1875 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, -1, szString, VT_BSTR);
1876 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1877 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szEight);
1879 /* Get name of a subkey by negative number (RegEnumValue like), invalid index */
1880 memset(szString, 0, sizeof(szString));
1881 hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, -10, szString, VT_EMPTY);
1882 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1888 static void test_Installer_Products(BOOL bProductInstalled)
1890 WCHAR szString[MAX_PATH];
1893 IUnknown *pUnk = NULL;
1894 IEnumVARIANT *pEnum = NULL;
1898 IDispatch *pStringList = NULL;
1899 BOOL bProductFound = FALSE;
1901 /* Installer::Products */
1902 hr = Installer_Products(&pStringList);
1903 ok(hr == S_OK, "Installer_Products failed, hresult 0x%08x\n", hr);
1906 /* StringList::_NewEnum */
1907 hr = StringList__NewEnum(pStringList, &pUnk);
1908 ok(hr == S_OK, "StringList_NewEnum failed, hresult 0x%08x\n", hr);
1911 hr = IUnknown_QueryInterface(pUnk, &IID_IEnumVARIANT, (void **)&pEnum);
1912 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
1915 skip("IEnumVARIANT tests\n");
1917 /* StringList::Count */
1918 hr = StringList_Count(pStringList, &iCount);
1919 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
1921 for (idx=0; idx<iCount; idx++)
1923 /* StringList::Item */
1924 memset(szString, 0, sizeof(szString));
1925 hr = StringList_Item(pStringList, idx, szString);
1926 ok(hr == S_OK, "StringList_Item failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
1930 /* Installer::ProductState */
1931 hr = Installer_ProductState(szString, &iValue);
1932 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
1934 ok(iValue == INSTALLSTATE_DEFAULT || iValue == INSTALLSTATE_ADVERTISED, "Installer_ProductState returned %d, expected %d or %d\n", iValue, INSTALLSTATE_DEFAULT, INSTALLSTATE_ADVERTISED);
1936 /* Not found our product code yet? Check */
1937 if (!bProductFound && !lstrcmpW(szString, szProductCode))
1938 bProductFound = TRUE;
1940 /* IEnumVARIANT::Next */
1943 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
1944 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
1945 ok(celt == 1, "%d items were retrieved, expected 1\n", celt);
1946 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
1947 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
1953 ok(bProductInstalled == bProductFound, "Product expected to %s installed but product code was %s\n",
1954 bProductInstalled ? "be" : "not be",
1955 bProductFound ? "found" : "not found");
1959 IEnumVARIANT *pEnum2 = NULL;
1961 if (0) /* Crashes on Windows XP */
1963 /* IEnumVARIANT::Clone, NULL pointer */
1964 hr = IEnumVARIANT_Clone(pEnum, NULL);
1967 /* IEnumVARIANT::Clone */
1968 hr = IEnumVARIANT_Clone(pEnum, &pEnum2);
1969 ok(hr == S_OK, "IEnumVARIANT_Clone failed, hresult 0x%08x\n", hr);
1972 /* IEnumVARIANT::Clone is supposed to save the position, but it actually just goes back to the beginning */
1974 /* IEnumVARIANT::Next of the clone */
1977 hr = IEnumVARIANT_Next(pEnum2, 1, &var, &celt);
1978 ok(hr == S_OK, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
1979 ok(celt == 1, "%d items were retrieved, expected 0\n", celt);
1980 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
1984 skip("IEnumVARIANT::Next of clone will not return success with 0 products\n");
1986 IEnumVARIANT_Release(pEnum2);
1989 /* IEnumVARIANT::Skip should fail */
1990 hr = IEnumVARIANT_Skip(pEnum, 1);
1991 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
1993 /* IEnumVARIANT::Next, NULL variant pointer */
1994 hr = IEnumVARIANT_Next(pEnum, 1, NULL, &celt);
1995 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
1996 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
1998 /* IEnumVARIANT::Next, should not return any more items */
1999 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
2000 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2001 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
2004 /* IEnumVARIANT::Reset */
2005 hr = IEnumVARIANT_Reset(pEnum);
2006 ok(hr == S_OK, "IEnumVARIANT_Reset failed, hresult 0x%08x\n", hr);
2010 /* IEnumVARIANT::Skip to the last product */
2011 hr = IEnumVARIANT_Skip(pEnum, iCount-1);
2012 ok(hr == S_OK, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
2014 /* IEnumVARIANT::Next should match the very last retrieved value, also makes sure it works with
2015 * NULL celt pointer. */
2016 hr = IEnumVARIANT_Next(pEnum, 1, &var, NULL);
2017 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2018 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2019 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
2023 skip("IEnumVARIANT::Skip impossible for 0 products\n");
2026 /* StringList::Item using an invalid index */
2027 memset(szString, 0, sizeof(szString));
2028 hr = StringList_Item(pStringList, iCount, szString);
2029 ok(hr == DISP_E_BADINDEX, "StringList_Item for an invalid index did not return DISP_E_BADINDEX, hresult 0x%08x\n", hr);
2031 if (pEnum) IEnumVARIANT_Release(pEnum);
2032 if (pUnk) IUnknown_Release(pUnk);
2033 IDispatch_Release(pStringList);
2037 /* Delete a registry subkey, including all its subkeys (RegDeleteKey does not work on keys with subkeys without
2038 * deleting the subkeys first) */
2039 static UINT delete_registry_key(HKEY hkeyParent, LPCSTR subkey)
2042 CHAR *string = NULL;
2046 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2047 if (ret != ERROR_SUCCESS) return ret;
2048 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2049 if (ret != ERROR_SUCCESS) return ret;
2050 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2052 while (RegEnumKeyA(hkey, 0, string, dwSize) == ERROR_SUCCESS)
2053 delete_registry_key(hkey, string);
2056 HeapFree(GetProcessHeap(), 0, string);
2057 RegDeleteKeyA(hkeyParent, subkey);
2058 return ERROR_SUCCESS;
2061 /* Find a specific registry subkey at any depth within the given key and subkey and return its parent key. */
2062 static UINT find_registry_key(HKEY hkeyParent, LPCSTR subkey, LPCSTR findkey, HKEY *phkey)
2065 CHAR *string = NULL;
2073 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2074 if (ret != ERROR_SUCCESS) return ret;
2075 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2076 if (ret != ERROR_SUCCESS) return ret;
2077 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2080 RegEnumKeyA(hkey, idx++, string, dwSize) == ERROR_SUCCESS)
2082 if (!strcmp(string, findkey))
2087 else if (find_registry_key(hkey, string, findkey, phkey) == ERROR_SUCCESS) found = TRUE;
2090 if (*phkey != hkey) RegCloseKey(hkey);
2091 HeapFree(GetProcessHeap(), 0, string);
2092 return (found ? ERROR_SUCCESS : ERROR_FILE_NOT_FOUND);
2095 static void test_Installer_InstallProduct(LPCWSTR szPath)
2098 CHAR path[MAX_PATH];
2099 WCHAR szString[MAX_PATH];
2102 DWORD num, size, type;
2104 IDispatch *pStringList = NULL;
2106 create_test_files();
2108 /* Installer::InstallProduct */
2109 hr = Installer_InstallProduct(szMsifile, NULL);
2110 ok(hr == S_OK, "Installer_InstallProduct failed, hresult 0x%08x\n", hr);
2112 /* Installer::ProductState for our product code, which has been installed */
2113 hr = Installer_ProductState(szProductCode, &iValue);
2114 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2115 ok(iValue == INSTALLSTATE_DEFAULT, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_DEFAULT);
2117 /* Installer::ProductInfo for our product code */
2119 /* NULL attribute */
2120 memset(szString, 0, sizeof(szString));
2121 hr = Installer_ProductInfo(szProductCode, NULL, szString);
2122 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2123 ok_exception(hr, szProductInfoException);
2125 /* Nonexistent attribute */
2126 memset(szString, 0, sizeof(szString));
2127 hr = Installer_ProductInfo(szProductCode, szMsifile, szString);
2128 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2129 ok_exception(hr, szProductInfoException);
2132 memset(szString, 0, sizeof(szString));
2133 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szString);
2134 todo_wine ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2135 todo_wine ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMsifile);
2138 memset(szString, 0, sizeof(szString));
2139 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PRODUCTNAMEW, szString);
2140 ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2141 ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMSITEST);
2143 /* Installer::Products */
2144 test_Installer_Products(TRUE);
2146 /* Installer::RelatedProducts for our upgrade code */
2147 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2148 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2151 /* StringList::Count */
2152 hr = StringList_Count(pStringList, &iCount);
2153 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2154 ok(iCount == 1, "Expected one related product but found %d\n", iCount);
2156 /* StringList::Item */
2157 memset(szString, 0, sizeof(szString));
2158 hr = StringList_Item(pStringList, 0, szString);
2159 ok(hr == S_OK, "StringList_Item failed (idx 0, count %d), hresult 0x%08x\n", iCount, hr);
2160 ok_w2("StringList_Item returned %s but expected %s\n", szString, szProductCode);
2162 IDispatch_Release(pStringList);
2165 /* Check & clean up installed files & registry keys */
2166 ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
2167 ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
2168 ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
2169 ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
2170 ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
2171 ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
2172 ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
2173 ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
2174 ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
2175 ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
2176 ok(delete_pf("msitest\\service.exe", TRUE), "File not installed\n");
2177 ok(delete_pf("msitest", FALSE), "File not installed\n");
2179 res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
2180 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2184 res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
2185 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2186 ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
2190 res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
2191 ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
2195 res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
2196 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2197 ok(num == 314, "Expected 314, got %d\n", num);
2201 res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
2202 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2203 ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
2207 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
2208 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2210 check_service_is_installed();
2212 /* Remove registry keys written by RegisterProduct standard action */
2213 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F1C3AF50-8B56-4A69-A00C-00773FE42F30}");
2214 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2216 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2217 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2219 res = find_registry_key(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", "05FA3C1F65B896A40AC00077F34EF203", &hkey);
2220 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2221 if (res == ERROR_SUCCESS)
2223 res = delete_registry_key(hkey, "05FA3C1F65B896A40AC00077F34EF203");
2224 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2228 /* Remove registry keys written by PublishProduct standard action */
2229 res = RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Installer", &hkey);
2230 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2232 res = delete_registry_key(hkey, "Products\\05FA3C1F65B896A40AC00077F34EF203");
2233 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2235 res = RegDeleteKeyA(hkey, "UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2236 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2240 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Products\\05FA3C1F65B896A40AC00077F34EF203");
2241 todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_SUCCESS, got %d\n", res);
2243 /* Delete installation files we installed */
2244 delete_test_files();
2247 static void test_Installer(void)
2249 static WCHAR szBackslash[] = { '\\',0 };
2250 static WCHAR szCreateRecordException[] = { 'C','r','e','a','t','e','R','e','c','o','r','d',',','C','o','u','n','t',0 };
2251 static WCHAR szIntegerDataException[] = { 'I','n','t','e','g','e','r','D','a','t','a',',','F','i','e','l','d',0 };
2252 WCHAR szPath[MAX_PATH];
2255 IDispatch *pSession = NULL, *pDatabase = NULL, *pRecord = NULL, *pStringList = NULL;
2258 if (!pInstaller) return;
2260 /* Installer::CreateRecord */
2262 /* Test for error */
2263 hr = Installer_CreateRecord(-1, &pRecord);
2264 ok(hr == DISP_E_EXCEPTION, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2265 ok_exception(hr, szCreateRecordException);
2267 /* Test for success */
2268 hr = Installer_CreateRecord(1, &pRecord);
2269 ok(hr == S_OK, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2270 ok(pRecord != NULL, "Installer_CreateRecord should not have returned NULL record\n");
2273 /* Record::FieldCountGet */
2274 hr = Record_FieldCountGet(pRecord, &iValue);
2275 ok(hr == S_OK, "Record_FiledCountGet failed, hresult 0x%08x\n", hr);
2276 ok(iValue == 1, "Record_FieldCountGet result was %d but expected 1\n", iValue);
2278 /* Record::IntegerDataGet */
2279 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2280 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2281 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2283 /* Record::IntegerDataGet, bad index */
2284 hr = Record_IntegerDataGet(pRecord, 10, &iValue);
2285 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2286 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2288 /* Record::IntegerDataPut */
2289 hr = Record_IntegerDataPut(pRecord, 1, 100);
2290 ok(hr == S_OK, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2292 /* Record::IntegerDataPut, bad index */
2293 hr = Record_IntegerDataPut(pRecord, 10, 100);
2294 ok(hr == DISP_E_EXCEPTION, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2295 ok_exception(hr, szIntegerDataException);
2297 /* Record::IntegerDataGet */
2298 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2299 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2300 ok(iValue == 100, "Record_IntegerDataGet result was %d but expected 100\n", iValue);
2302 IDispatch_Release(pRecord);
2305 /* Prepare package */
2306 create_database(msifile, tables, sizeof(tables) / sizeof(msi_table),
2307 summary_info, sizeof(summary_info) / sizeof(msi_summary_info));
2309 len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, CURR_DIR, -1, szPath, MAX_PATH);
2310 ok(len, "MultiByteToWideChar returned error %d\n", GetLastError());
2313 lstrcatW(szPath, szBackslash);
2314 lstrcatW(szPath, szMsifile);
2316 /* Installer::OpenPackage */
2317 hr = Installer_OpenPackage(szPath, 0, &pSession);
2318 ok(hr == S_OK, "Installer_OpenPackage failed, hresult 0x%08x\n", hr);
2321 test_Session(pSession);
2322 IDispatch_Release(pSession);
2325 /* Installer::OpenDatabase */
2326 hr = Installer_OpenDatabase(szPath, (int)MSIDBOPEN_TRANSACT, &pDatabase);
2327 ok(hr == S_OK, "Installer_OpenDatabase failed, hresult 0x%08x\n", hr);
2330 test_Database(pDatabase, FALSE);
2331 IDispatch_Release(pDatabase);
2334 /* Installer::RegistryValue */
2335 test_Installer_RegistryValue();
2337 /* Installer::ProductState for our product code, which should not be installed */
2338 hr = Installer_ProductState(szProductCode, &iValue);
2339 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2340 ok(iValue == INSTALLSTATE_UNKNOWN, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_UNKNOWN);
2342 /* Installer::ProductInfo for our product code, which should not be installed */
2345 memset(szPath, 0, sizeof(szPath));
2346 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szPath);
2347 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2348 ok_exception(hr, szProductInfoException);
2350 /* NULL attribute and NULL product code */
2351 memset(szPath, 0, sizeof(szPath));
2352 hr = Installer_ProductInfo(NULL, NULL, szPath);
2353 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2354 ok_exception(hr, szProductInfoException);
2356 /* Installer::Products */
2357 test_Installer_Products(FALSE);
2359 /* Installer::RelatedProducts for our upgrade code, should not find anything */
2360 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2361 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2364 /* StringList::Count */
2365 hr = StringList_Count(pStringList, &iCount);
2366 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2367 ok(!iCount, "Expected no related products but found %d\n", iCount);
2369 IDispatch_Release(pStringList);
2372 /* Installer::Version */
2374 memset(szPath, 0, sizeof(szPath));
2375 hr = Installer_VersionGet(szPath);
2376 ok(hr == S_OK, "Installer_VersionGet failed, hresult 0x%08x\n", hr);
2379 /* Installer::InstallProduct and other tests that depend on our product being installed */
2380 test_Installer_InstallProduct(szPath);
2383 START_TEST(automation)
2386 char temp_path[MAX_PATH], prev_path[MAX_PATH];
2391 GetSystemTimeAsFileTime(&systemtime);
2393 GetCurrentDirectoryA(MAX_PATH, prev_path);
2394 GetTempPath(MAX_PATH, temp_path);
2395 SetCurrentDirectoryA(temp_path);
2397 lstrcpyA(CURR_DIR, temp_path);
2398 len = lstrlenA(CURR_DIR);
2400 if(len && (CURR_DIR[len - 1] == '\\'))
2401 CURR_DIR[len - 1] = 0;
2403 get_program_files_dir(PROG_FILES_DIR);
2405 hr = OleInitialize(NULL);
2406 ok (hr == S_OK, "OleInitialize returned 0x%08x\n", hr);
2407 hr = CLSIDFromProgID(szProgId, &clsid);
2408 ok (hr == S_OK, "CLSIDFromProgID returned 0x%08x\n", hr);
2409 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
2410 ok(hr == S_OK, "CoCreateInstance returned 0x%08x\n", hr);
2414 hr = IUnknown_QueryInterface(pUnk, &IID_IDispatch, (void **)&pInstaller);
2415 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
2421 IDispatch_Release(pInstaller);
2422 IUnknown_Release(pUnk);
2427 SetCurrentDirectoryA(prev_path);