msi: Implement MsiSetMode.
[wine.git] / dlls / msi / tests / automation.c
blobcab6cb7170dc8324d0c604c75ee68fcf23fe993d
1 /*
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
22 #define COBJMACROS
24 #include <stdio.h>
26 #include <initguid.h>
27 #include <windows.h>
28 #include <msiquery.h>
29 #include <msidefs.h>
30 #include <msi.h>
31 #include <fci.h>
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;
50 * OLE automation data
51 **/
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"
69 "s72\tS72\tl255\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"
81 "Feature\tFeature\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"
90 "s38\ts72\n"
91 "FeatureComponents\tFeature_\tComponent_\n"
92 "Five\tFive\n"
93 "Four\tFour\n"
94 "One\tOne\n"
95 "Three\tThree\n"
96 "Two\tTwo\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"
101 "File\tFile\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"
110 "s72\tS255\tI2\n"
111 "InstallExecuteSequence\tAction\n"
112 "AllocateRegistrySpace\tNOT Installed\t1550\n"
113 "CostFinalize\t\t1000\n"
114 "CostInitialize\t\t800\n"
115 "FileCost\t\t900\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"
127 "Media\tDiskId\n"
128 "1\t5\t\t\tDISK1\t\n";
130 static const CHAR property_dat[] = "Property\tValue\n"
131 "s72\tl0\n"
132 "Property\tProperty\n"
133 "DefaultUIFont\tDlgFont8\n"
134 "HASUIRUN\t0\n"
135 "INSTALLLEVEL\t3\n"
136 "InstallMode\tTypical\n"
137 "Manufacturer\tWine\n"
138 "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
139 "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
140 "ProductID\tnone\n"
141 "ProductLanguage\t1033\n"
142 "ProductName\tMSITEST\n"
143 "ProductVersion\t1.1.1\n"
144 "PROMPTROLLBACKCOST\tP\n"
145 "Setup\tSetup\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;
159 const CHAR *data;
160 int size;
161 } msi_table;
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),
169 ADD_TABLE(feature),
170 ADD_TABLE(feature_comp),
171 ADD_TABLE(file),
172 ADD_TABLE(install_exec_seq),
173 ADD_TABLE(media),
174 ADD_TABLE(property),
175 ADD_TABLE(registry)
178 typedef struct _msi_summary_info
180 UINT property;
181 UINT datatype;
182 INT iValue;
183 FILETIME *pftValue;
184 const CHAR *szValue;
185 } 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)
203 * Database Helpers
206 static void write_file(const CHAR *filename, const char *data, int data_size)
208 DWORD 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);
214 CloseHandle(hf);
217 static void write_msi_summary_info(MSIHANDLE db, const msi_summary_info *info, int num_info)
219 MSIHANDLE summary;
220 UINT r;
221 int j;
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)
246 MSIHANDLE db;
247 UINT r;
248 int j;
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);
271 MsiCloseHandle(db);
274 static BOOL create_package(LPWSTR path)
276 DWORD len;
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());
286 if (!len)
287 return FALSE;
289 /* lstrcatW does not work on win95 */
290 path[len - 1] = '\\';
291 memcpy(&path[len], szMsifile, sizeof(szMsifile));
292 return TRUE;
296 * Installation helpers
299 static char PROG_FILES_DIR[MAX_PATH];
301 static BOOL get_program_files_dir(LPSTR buf)
303 HKEY hkey;
304 DWORD type = REG_EXPAND_SZ, size;
306 if (RegOpenKey(HKEY_LOCAL_MACHINE,
307 "Software\\Microsoft\\Windows\\CurrentVersion", &hkey))
308 return FALSE;
310 size = MAX_PATH;
311 if (RegQueryValueEx(hkey, "ProgramFilesDir", 0, &type, (LPBYTE)buf, &size))
312 return FALSE;
314 RegCloseKey(hkey);
315 return TRUE;
318 static void create_file(const CHAR *name, DWORD size)
320 HANDLE file;
321 DWORD written, left;
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);
331 SetEndOfFile(file);
333 CloseHandle(file);
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)
353 CHAR path[MAX_PATH];
355 lstrcpyA(path, PROG_FILES_DIR);
356 lstrcatA(path, "\\");
357 lstrcatA(path, rel_path);
359 if (is_file)
360 return DeleteFileA(path);
361 else
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) \
401 do { \
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); \
406 } while(0);
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 )
453 LPOLESTR str;
454 UINT len;
455 DISPID id = -1;
456 HRESULT r;
458 len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0 );
459 str = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
460 if (str)
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);
465 if (r != S_OK)
466 return -1;
469 return id;
472 static void test_dispid(void)
474 DISPID dispid;
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);
510 todo_wine
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);
547 todo_wine
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);
560 todo_wine
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 };
609 HRESULT hr;
610 DISPID dispid;
611 OLECHAR *name;
612 VARIANT varresult;
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
780 * VT_I4.
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);
794 DeleteFileW(path);
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;
827 DISPID dispid;
828 HRESULT hr;
829 UINT i;
830 UINT len;
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);
847 if (hr == S_OK)
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);
851 else
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]);
863 return hr;
866 /* Object_Property helper functions */
868 static HRESULT Installer_CreateRecord(int count, IDispatch **pRecord)
870 VARIANT varresult;
871 VARIANTARG vararg[1];
872 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
873 HRESULT hr;
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);
881 return hr;
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)
904 VARIANT varresult;
905 VARIANTARG vararg;
906 HRESULT hr;
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);
913 return hr;
916 static HRESULT Installer_RegistryValueW(HKEY hkey, LPCWSTR szKey, LPCWSTR szValue, LPWSTR szString)
918 VARIANT varresult;
919 VARIANTARG vararg;
920 HRESULT hr;
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);
931 return hr;
934 static HRESULT Installer_RegistryValueI(HKEY hkey, LPCWSTR szKey, int iValue, LPWSTR szString, VARTYPE vtResult)
936 VARIANT varresult;
937 VARIANTARG vararg;
938 HRESULT hr;
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);
948 return hr;
951 static HRESULT Installer_OpenPackage(LPCWSTR szPackagePath, int options, IDispatch **pSession)
953 VARIANT varresult;
954 VARIANTARG vararg[2];
955 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
956 HRESULT hr;
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);
967 return hr;
970 static HRESULT Installer_OpenDatabase(LPCWSTR szDatabasePath, int openmode, IDispatch **pDatabase)
972 VARIANT varresult;
973 VARIANTARG vararg[2];
974 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
975 HRESULT hr;
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);
986 return hr;
989 static HRESULT Installer_InstallProduct(LPCWSTR szPackagePath, LPCWSTR szPropertyValues)
991 VARIANT varresult;
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)
1007 VARIANT varresult;
1008 VARIANTARG vararg[1];
1009 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1010 HRESULT hr;
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);
1019 return hr;
1022 static HRESULT Installer_ProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute, LPWSTR szString)
1024 VARIANT varresult;
1025 VARIANTARG vararg[2];
1026 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1027 HRESULT hr;
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);
1040 return hr;
1043 static HRESULT Installer_Products(IDispatch **pStringList)
1045 VARIANT varresult;
1046 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1047 HRESULT hr;
1049 hr = invoke(pInstaller, "Products", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1050 *pStringList = V_DISPATCH(&varresult);
1051 return hr;
1054 static HRESULT Installer_RelatedProducts(LPCWSTR szProduct, IDispatch **pStringList)
1056 VARIANT varresult;
1057 VARIANTARG vararg[1];
1058 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1059 HRESULT hr;
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);
1067 return hr;
1070 static HRESULT Installer_VersionGet(LPWSTR szVersion)
1072 VARIANT varresult;
1073 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1074 HRESULT hr;
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);
1080 return hr;
1083 static HRESULT Session_Installer(IDispatch *pSession, IDispatch **pInst)
1085 VARIANT varresult;
1086 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1087 HRESULT hr;
1089 hr = invoke(pSession, "Installer", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1090 *pInst = V_DISPATCH(&varresult);
1091 return hr;
1094 static HRESULT Session_PropertyGet(IDispatch *pSession, LPCWSTR szName, LPWSTR szReturn)
1096 VARIANT varresult;
1097 VARIANTARG vararg[1];
1098 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1099 HRESULT hr;
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);
1109 return hr;
1112 static HRESULT Session_PropertyPut(IDispatch *pSession, LPCWSTR szName, LPCWSTR szValue)
1114 VARIANT varresult;
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)
1131 VARIANT varresult;
1132 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1133 HRESULT hr;
1135 hr = invoke(pSession, "Language", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1136 *pLangId = V_I4(&varresult);
1137 VariantClear(&varresult);
1138 return hr;
1141 static HRESULT Session_ModeGet(IDispatch *pSession, int iFlag, BOOL *pMode)
1143 VARIANT varresult;
1144 VARIANTARG vararg[1];
1145 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1146 HRESULT hr;
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);
1155 return hr;
1158 static HRESULT Session_ModePut(IDispatch *pSession, int iFlag, BOOL bMode)
1160 VARIANT varresult;
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)
1177 VARIANT varresult;
1178 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1179 HRESULT hr;
1181 hr = invoke(pSession, "Database", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
1182 *pDatabase = V_DISPATCH(&varresult);
1183 return hr;
1186 static HRESULT Session_DoAction(IDispatch *pSession, LPCWSTR szAction, int *iReturn)
1188 VARIANT varresult;
1189 VARIANTARG vararg[1];
1190 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1191 HRESULT hr;
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);
1200 return hr;
1203 static HRESULT Session_EvaluateCondition(IDispatch *pSession, LPCWSTR szCondition, int *iReturn)
1205 VARIANT varresult;
1206 VARIANTARG vararg[1];
1207 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1208 HRESULT hr;
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);
1217 return hr;
1220 static HRESULT Session_Message(IDispatch *pSession, LONG kind, IDispatch *record, int *ret)
1222 VARIANT varresult;
1223 VARIANTARG vararg[2];
1224 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1225 HRESULT hr;
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);
1238 return hr;
1241 static HRESULT Session_SetInstallLevel(IDispatch *pSession, LONG iInstallLevel)
1243 VARIANT varresult;
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)
1256 VARIANT varresult;
1257 VARIANTARG vararg[1];
1258 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1259 HRESULT hr;
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);
1268 return hr;
1271 static HRESULT Session_FeatureRequestStateGet(IDispatch *pSession, LPCWSTR szName, int *pState)
1273 VARIANT varresult;
1274 VARIANTARG vararg[1];
1275 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1276 HRESULT hr;
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);
1285 return hr;
1288 static HRESULT Session_FeatureRequestStatePut(IDispatch *pSession, LPCWSTR szName, int iState)
1290 VARIANT varresult;
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)
1307 VARIANT varresult;
1308 VARIANTARG vararg[1];
1309 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1310 HRESULT hr;
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);
1318 return hr;
1321 static HRESULT Database_SummaryInformation(IDispatch *pDatabase, int iUpdateCount, IDispatch **pSummaryInfo)
1323 VARIANT varresult;
1324 VARIANTARG vararg[1];
1325 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1326 HRESULT hr;
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);
1334 return hr;
1337 static HRESULT View_Execute(IDispatch *pView, IDispatch *pRecord)
1339 VARIANT varresult;
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)
1352 VARIANT varresult;
1353 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1354 HRESULT hr = invoke(pView, "Fetch", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
1355 *ppRecord = V_DISPATCH(&varresult);
1356 return hr;
1359 static HRESULT View_Modify(IDispatch *pView, int iMode, IDispatch *pRecord)
1361 VARIANT varresult;
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;
1371 if (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)
1379 VARIANT varresult;
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)
1386 VARIANT varresult;
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);
1391 return hr;
1394 static HRESULT Record_StringDataGet(IDispatch *pRecord, int iField, LPWSTR szString)
1396 VARIANT varresult;
1397 VARIANTARG vararg[1];
1398 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1399 HRESULT hr;
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);
1409 return hr;
1412 static HRESULT Record_StringDataPut(IDispatch *pRecord, int iField, LPCWSTR szString)
1414 VARIANT varresult;
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)
1431 VARIANT varresult;
1432 VARIANTARG vararg[1];
1433 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1434 HRESULT hr;
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);
1443 return hr;
1446 static HRESULT Record_IntegerDataPut(IDispatch *pRecord, int iField, int iValue)
1448 VARIANT varresult;
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)
1465 VARIANT varresult;
1466 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1467 HRESULT hr = invoke(pList, "_NewEnum", DISPATCH_METHOD, &dispparams, &varresult, VT_UNKNOWN);
1468 *ppEnumVARIANT = V_UNKNOWN(&varresult);
1469 return hr;
1472 static HRESULT StringList_Item(IDispatch *pStringList, int iIndex, LPWSTR szString)
1474 VARIANT varresult;
1475 VARIANTARG vararg[1];
1476 DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
1477 HRESULT hr;
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);
1487 return hr;
1490 static HRESULT StringList_Count(IDispatch *pStringList, int *pCount)
1492 VARIANT varresult;
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);
1497 return hr;
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)
1513 VARIANT varresult;
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)
1529 VARIANT varresult;
1530 DISPPARAMS dispparams = {NULL, NULL, 0, 0};
1531 HRESULT hr;
1533 hr = invoke(pSummaryInfo, "PropertyCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
1534 *pCount = V_I4(&varresult);
1535 VariantClear(&varresult);
1536 return hr;
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;
1548 SYSTEMTIME st;
1549 HRESULT hr;
1550 int j;
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)
1576 FILETIME ft;
1577 DATE d;
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));
1588 else
1589 skip("SummaryInfo_Property (pid %d) unhandled result type %d\n", entry->property, vt);
1591 VariantClear(&varresult);
1594 /* SummaryInfo::Property, get; invalid arguments */
1596 /* Invalid pids */
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);
1625 if (!readonly)
1627 /* SummaryInfo::Property, put; one for each type */
1629 /* VT_I2 */
1630 VariantInit(&var);
1631 V_VT(&var) = VT_I2;
1632 V_I2(&var) = 1;
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);
1640 VariantClear(&var);
1642 /* VT_BSTR */
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);
1652 VariantClear(&var);
1654 /* VT_DATE */
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);
1665 VariantClear(&var);
1667 /* VT_I4 */
1668 V_VT(&var) = VT_I4;
1669 V_I4(&var) = 1000;
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);
1677 VariantClear(&var);
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;
1694 HRESULT hr;
1696 hr = Database_OpenView(pDatabase, szSql, &pView);
1697 ok(hr == S_OK, "Database_OpenView failed, hresult 0x%08x\n", hr);
1698 if (hr == S_OK)
1700 IDispatch *pRecord = NULL;
1701 WCHAR szString[MAX_PATH];
1703 /* View::Execute */
1704 hr = View_Execute(pView, NULL);
1705 ok(hr == S_OK, "View_Execute failed, hresult 0x%08x\n", hr);
1707 /* View::Fetch */
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");
1711 if (pRecord)
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);
1759 /* View::Fetch */
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");
1763 if (pRecord)
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);
1774 /* View::Fetch */
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");
1778 if (pRecord)
1779 IDispatch_Release(pRecord);
1781 /* View::Close */
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");
1792 if (pSummaryInfo)
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];
1813 UINT len;
1814 BOOL bool;
1815 int myint;
1816 IDispatch *pDatabase = NULL, *pInst = NULL, *record = NULL;
1817 HRESULT hr;
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 hr = Session_ModeGet(pSession, MSIRUNMODE_MAINTENANCE, &bool);
1869 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1870 todo_wine ok(!bool, "Maintenance mode is %d\n", bool);
1872 /* Session::Mode, put */
1873 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, TRUE);
1874 ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1875 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1876 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1877 ok(bool, "Reboot at end session mode is %d, expected 1\n", bool);
1878 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, FALSE); /* set it again so we don't reboot */
1879 ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1881 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTNOW, TRUE);
1882 todo_wine ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1883 hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTNOW, &bool);
1884 ok(hr == S_OK, "Session_ModeGet failed, hresult 0x%08x\n", hr);
1885 ok(bool, "Reboot now mode is %d, expected 1\n", bool);
1886 hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTNOW, FALSE); /* set it again so we don't reboot */
1887 todo_wine ok(hr == S_OK, "Session_ModePut failed, hresult 0x%08x\n", hr);
1889 hr = Session_ModePut(pSession, MSIRUNMODE_MAINTENANCE, TRUE);
1890 ok(hr == DISP_E_EXCEPTION, "Session_ModePut failed, hresult 0x%08x\n", hr);
1892 /* Session::Database, get */
1893 hr = Session_Database(pSession, &pDatabase);
1894 ok(hr == S_OK, "Session_Database failed, hresult 0x%08x\n", hr);
1895 if (hr == S_OK)
1897 test_Database(pDatabase, TRUE);
1898 IDispatch_Release(pDatabase);
1901 /* Session::EvaluateCondition */
1902 hr = Session_EvaluateCondition(pSession, NULL, &myint);
1903 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1904 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1906 hr = Session_EvaluateCondition(pSession, szEmpty, &myint);
1907 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1908 ok(myint == MSICONDITION_NONE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1910 hr = Session_EvaluateCondition(pSession, szEquals, &myint);
1911 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1912 ok(myint == MSICONDITION_ERROR, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1914 /* Session::DoAction(CostInitialize) must occur before the next statements */
1915 hr = Session_DoAction(pSession, szCostInitialize, &myint);
1916 ok(hr == S_OK, "Session_DoAction failed, hresult 0x%08x\n", hr);
1917 ok(myint == IDOK, "DoAction(CostInitialize) returned %d, %d expected\n", myint, IDOK);
1919 /* Session::SetInstallLevel */
1920 hr = Session_SetInstallLevel(pSession, INSTALLLEVEL_MINIMUM);
1921 ok(hr == S_OK, "Session_SetInstallLevel failed, hresult 0x%08x\n", hr);
1923 /* Session::FeatureCurrentState, get */
1924 hr = Session_FeatureCurrentState(pSession, szOne, &myint);
1925 ok(hr == S_OK, "Session_FeatureCurrentState failed, hresult 0x%08x\n", hr);
1926 ok(myint == INSTALLSTATE_UNKNOWN, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1928 /* Session::Message */
1929 hr = Installer_CreateRecord(0, &record);
1930 ok(hr == S_OK, "Installer_CreateRecord failed: %08x\n", hr);
1931 hr = Session_Message(pSession, INSTALLMESSAGE_INFO, record, &myint);
1932 ok(hr == S_OK, "Session_Message failed: %08x\n", hr);
1933 ok(myint == 0, "Session_Message returned %x\n", myint);
1935 /* Session::EvaluateCondition */
1936 hr = Session_EvaluateCondition(pSession, szOneStateFalse, &myint);
1937 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1938 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1940 hr = Session_EvaluateCondition(pSession, szOneStateTrue, &myint);
1941 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1942 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1944 /* Session::FeatureRequestState, put */
1945 hr = Session_FeatureRequestStatePut(pSession, szOne, INSTALLSTATE_ADVERTISED);
1946 ok(hr == S_OK, "Session_FeatureRequestStatePut failed, hresult 0x%08x\n", hr);
1947 hr = Session_FeatureRequestStateGet(pSession, szOne, &myint);
1948 ok(hr == S_OK, "Session_FeatureRequestStateGet failed, hresult 0x%08x\n", hr);
1949 ok(myint == INSTALLSTATE_ADVERTISED, "Feature request state was %d but expected %d\n", myint, INSTALLSTATE_ADVERTISED);
1951 /* Session::EvaluateCondition */
1952 hr = Session_EvaluateCondition(pSession, szOneActionFalse, &myint);
1953 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1954 ok(myint == MSICONDITION_FALSE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1956 hr = Session_EvaluateCondition(pSession, szOneActionTrue, &myint);
1957 ok(hr == S_OK, "Session_EvaluateCondition failed, hresult 0x%08x\n", hr);
1958 ok(myint == MSICONDITION_TRUE, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1961 /* delete key and all its subkeys */
1962 static DWORD delete_key( HKEY hkey )
1964 char name[MAX_PATH];
1965 DWORD ret;
1967 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
1969 HKEY tmp;
1970 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
1972 ret = delete_key( tmp );
1973 RegCloseKey( tmp );
1975 if (ret) break;
1977 if (ret != ERROR_NO_MORE_ITEMS) return ret;
1978 RegDeleteKeyA( hkey, "" );
1979 return 0;
1982 static void test_Installer_RegistryValue(void)
1984 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
1985 static const WCHAR szKey[] = { 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t',0 };
1986 static const WCHAR szOne[] = { 'O','n','e',0 };
1987 static const WCHAR szTwo[] = { 'T','w','o',0 };
1988 static const WCHAR szThree[] = { 'T','h','r','e','e',0 };
1989 static const WCHAR szREG_BINARY[] = { '(','R','E','G','_','B','I','N','A','R','Y',')',0 };
1990 static const WCHAR szFour[] = { 'F','o','u','r',0 };
1991 static const WCHAR szExpand[] = { '%','M','S','I','T','E','S','T','%',0 };
1992 static const WCHAR szFive[] = { 'F','i','v','e',0,'H','i',0,0 };
1993 static const WCHAR szFiveHi[] = { 'F','i','v','e','\n','H','i',0 };
1994 static const WCHAR szSix[] = { 'S','i','x',0 };
1995 static const WCHAR szREG_[] = { '(','R','E','G','_',']',0 };
1996 static const WCHAR szSeven[] = { 'S','e','v','e','n',0 };
1997 static const WCHAR szEight[] = { 'E','i','g','h','t',0 };
1998 static const WCHAR szBlank[] = { 0 };
1999 VARIANT varresult;
2000 VARIANTARG vararg;
2001 WCHAR szString[MAX_PATH];
2002 HKEY hkey, hkey_sub;
2003 HKEY curr_user = (HKEY)1;
2004 HRESULT hr;
2005 BOOL bRet;
2006 LONG lRet;
2008 /* Delete keys */
2009 SetLastError(0xdeadbeef);
2010 lRet = RegOpenKeyW( HKEY_CURRENT_USER, szKey, &hkey );
2011 if (!lRet && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2013 win_skip("Needed W-functions are not implemented\n");
2014 return;
2016 if (!lRet)
2017 delete_key( hkey );
2019 /* Does our key exist? Shouldn't; check with all three possible value parameter types */
2020 hr = Installer_RegistryValueE(curr_user, szKey, &bRet);
2021 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
2022 ok(!bRet, "Registry key expected to not exist, but Installer_RegistryValue claims it does\n");
2024 memset(szString, 0, sizeof(szString));
2025 hr = Installer_RegistryValueW(curr_user, szKey, NULL, szString);
2026 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2028 memset(szString, 0, sizeof(szString));
2029 hr = Installer_RegistryValueI(curr_user, szKey, 0, szString, VT_BSTR);
2030 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2032 /* Create key */
2033 ok(!RegCreateKeyW( HKEY_CURRENT_USER, szKey, &hkey ), "RegCreateKeyW failed\n");
2035 ok(!RegSetValueExW(hkey,szOne,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
2036 "RegSetValueExW failed\n");
2037 ok(!RegSetValueExW(hkey,szTwo,0,REG_DWORD, (const BYTE *)qw, 4),
2038 "RegSetValueExW failed\n");
2039 ok(!RegSetValueExW(hkey,szThree,0,REG_BINARY, (const BYTE *)qw, 4),
2040 "RegSetValueExW failed\n");
2041 ok(SetEnvironmentVariableA("MSITEST", "Four"), "SetEnvironmentVariableA failed %d\n", GetLastError());
2042 ok(!RegSetValueExW(hkey,szFour,0,REG_EXPAND_SZ, (const BYTE *)szExpand, sizeof(szExpand)),
2043 "RegSetValueExW failed\n");
2044 ok(!RegSetValueExW(hkey,szFive,0,REG_MULTI_SZ, (const BYTE *)szFive, sizeof(szFive)),
2045 "RegSetValueExW failed\n");
2046 ok(!RegSetValueExW(hkey,szSix,0,REG_QWORD, (const BYTE *)qw, 8),
2047 "RegSetValueExW failed\n");
2048 ok(!RegSetValueExW(hkey,szSeven,0,REG_NONE, NULL, 0),
2049 "RegSetValueExW failed\n");
2051 ok(!RegSetValueExW(hkey,NULL,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
2052 "RegSetValueExW failed\n");
2054 ok(!RegCreateKeyW( hkey, szEight, &hkey_sub ), "RegCreateKeyW failed\n");
2056 /* Does our key exist? It should, and make sure we retrieve the correct default value */
2057 bRet = FALSE;
2058 hr = Installer_RegistryValueE(curr_user, szKey, &bRet);
2059 ok(hr == S_OK, "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
2060 ok(bRet, "Registry key expected to exist, but Installer_RegistryValue claims it does not\n");
2062 memset(szString, 0, sizeof(szString));
2063 hr = Installer_RegistryValueW(curr_user, szKey, NULL, szString);
2064 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2065 ok_w2("Default registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
2067 /* Ask for the value of a nonexistent key */
2068 memset(szString, 0, sizeof(szString));
2069 hr = Installer_RegistryValueW(curr_user, szKey, szExpand, szString);
2070 ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2072 /* Get values of keys */
2073 memset(szString, 0, sizeof(szString));
2074 hr = Installer_RegistryValueW(curr_user, szKey, szOne, szString);
2075 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2076 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
2078 VariantInit(&vararg);
2079 V_VT(&vararg) = VT_BSTR;
2080 V_BSTR(&vararg) = SysAllocString(szTwo);
2081 hr = Installer_RegistryValue(curr_user, szKey, vararg, &varresult, VT_I4);
2082 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
2083 ok(V_I4(&varresult) == 305419896, "Registry value %d does not match expected value\n", V_I4(&varresult));
2084 VariantClear(&varresult);
2086 memset(szString, 0, sizeof(szString));
2087 hr = Installer_RegistryValueW(curr_user, szKey, szThree, szString);
2088 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2089 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_BINARY);
2091 memset(szString, 0, sizeof(szString));
2092 hr = Installer_RegistryValueW(curr_user, szKey, szFour, szString);
2093 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2094 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFour);
2096 /* Vista does not NULL-terminate this case */
2097 memset(szString, 0, sizeof(szString));
2098 hr = Installer_RegistryValueW(curr_user, szKey, szFive, szString);
2099 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2100 ok_w2n("Registry value \"%s\" does not match expected \"%s\"\n",
2101 szString, szFiveHi, lstrlenW(szFiveHi));
2103 memset(szString, 0, sizeof(szString));
2104 hr = Installer_RegistryValueW(curr_user, szKey, szSix, szString);
2105 ok(hr == S_OK, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
2106 ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_);
2108 VariantInit(&vararg);
2109 V_VT(&vararg) = VT_BSTR;
2110 V_BSTR(&vararg) = SysAllocString(szSeven);
2111 hr = Installer_RegistryValue(curr_user, szKey, vararg, &varresult, VT_EMPTY);
2112 ok(hr == S_OK, "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
2114 /* Get string class name for the key */
2115 memset(szString, 0, sizeof(szString));
2116 hr = Installer_RegistryValueI(curr_user, szKey, 0, szString, VT_BSTR);
2117 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2118 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szBlank);
2120 /* Get name of a value by positive number (RegEnumValue like), valid index */
2121 memset(szString, 0, sizeof(szString));
2122 hr = Installer_RegistryValueI(curr_user, szKey, 2, szString, VT_BSTR);
2123 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2124 /* RegEnumValue order seems different on wine */
2125 todo_wine ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szTwo);
2127 /* Get name of a value by positive number (RegEnumValue like), invalid index */
2128 memset(szString, 0, sizeof(szString));
2129 hr = Installer_RegistryValueI(curr_user, szKey, 10, szString, VT_EMPTY);
2130 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2132 /* Get name of a subkey by negative number (RegEnumValue like), valid index */
2133 memset(szString, 0, sizeof(szString));
2134 hr = Installer_RegistryValueI(curr_user, szKey, -1, szString, VT_BSTR);
2135 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2136 ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szEight);
2138 /* Get name of a subkey by negative number (RegEnumValue like), invalid index */
2139 memset(szString, 0, sizeof(szString));
2140 hr = Installer_RegistryValueI(curr_user, szKey, -10, szString, VT_EMPTY);
2141 ok(hr == S_OK, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
2143 /* clean up */
2144 delete_key(hkey);
2147 static void test_Installer_Products(BOOL bProductInstalled)
2149 WCHAR szString[MAX_PATH];
2150 HRESULT hr;
2151 int idx;
2152 IUnknown *pUnk = NULL;
2153 IEnumVARIANT *pEnum = NULL;
2154 VARIANT var;
2155 ULONG celt;
2156 int iCount, iValue;
2157 IDispatch *pStringList = NULL;
2158 BOOL bProductFound = FALSE;
2160 /* Installer::Products */
2161 hr = Installer_Products(&pStringList);
2162 ok(hr == S_OK, "Installer_Products failed, hresult 0x%08x\n", hr);
2163 if (hr == S_OK)
2165 /* StringList::_NewEnum */
2166 hr = StringList__NewEnum(pStringList, &pUnk);
2167 ok(hr == S_OK, "StringList_NewEnum failed, hresult 0x%08x\n", hr);
2168 if (hr == S_OK)
2170 hr = IUnknown_QueryInterface(pUnk, &IID_IEnumVARIANT, (void **)&pEnum);
2171 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
2173 if (!pEnum)
2174 skip("IEnumVARIANT tests\n");
2176 /* StringList::Count */
2177 hr = StringList_Count(pStringList, &iCount);
2178 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2180 for (idx=0; idx<iCount; idx++)
2182 /* StringList::Item */
2183 memset(szString, 0, sizeof(szString));
2184 hr = StringList_Item(pStringList, idx, szString);
2185 ok(hr == S_OK, "StringList_Item failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2187 if (hr == S_OK)
2189 /* Installer::ProductState */
2190 hr = Installer_ProductState(szString, &iValue);
2191 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2192 if (hr == S_OK)
2193 ok(iValue == INSTALLSTATE_DEFAULT || iValue == INSTALLSTATE_ADVERTISED, "Installer_ProductState returned %d, expected %d or %d\n", iValue, INSTALLSTATE_DEFAULT, INSTALLSTATE_ADVERTISED);
2195 /* Not found our product code yet? Check */
2196 if (!bProductFound && !strcmp_ww(szString, szProductCode))
2197 bProductFound = TRUE;
2199 /* IEnumVARIANT::Next */
2200 if (pEnum)
2202 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
2203 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2204 ok(celt == 1, "%d items were retrieved, expected 1\n", celt);
2205 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2206 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
2207 VariantClear(&var);
2212 if (bProductInstalled)
2214 ok(bProductInstalled == bProductFound, "Product expected to %s installed but product code was %s\n",
2215 bProductInstalled ? "be" : "not be",
2216 bProductFound ? "found" : "not found");
2219 if (pEnum)
2221 IEnumVARIANT *pEnum2 = NULL;
2223 if (0) /* Crashes on Windows XP */
2225 /* IEnumVARIANT::Clone, NULL pointer */
2226 hr = IEnumVARIANT_Clone(pEnum, NULL);
2229 /* IEnumVARIANT::Clone */
2230 hr = IEnumVARIANT_Clone(pEnum, &pEnum2);
2231 ok(hr == S_OK, "IEnumVARIANT_Clone failed, hresult 0x%08x\n", hr);
2232 if (hr == S_OK)
2234 /* IEnumVARIANT::Clone is supposed to save the position, but it actually just goes back to the beginning */
2236 /* IEnumVARIANT::Next of the clone */
2237 if (iCount)
2239 hr = IEnumVARIANT_Next(pEnum2, 1, &var, &celt);
2240 ok(hr == S_OK, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2241 ok(celt == 1, "%d items were retrieved, expected 0\n", celt);
2242 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2243 VariantClear(&var);
2245 else
2246 skip("IEnumVARIANT::Next of clone will not return success with 0 products\n");
2248 IEnumVARIANT_Release(pEnum2);
2251 /* IEnumVARIANT::Skip should fail */
2252 hr = IEnumVARIANT_Skip(pEnum, 1);
2253 ok(hr == S_FALSE, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
2255 /* IEnumVARIANT::Next, NULL variant pointer */
2256 hr = IEnumVARIANT_Next(pEnum, 1, NULL, &celt);
2257 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2258 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
2260 /* IEnumVARIANT::Next, should not return any more items */
2261 hr = IEnumVARIANT_Next(pEnum, 1, &var, &celt);
2262 ok(hr == S_FALSE, "IEnumVARIANT_Next failed, hresult 0x%08x\n", hr);
2263 ok(celt == 0, "%d items were retrieved, expected 0\n", celt);
2264 VariantClear(&var);
2266 /* IEnumVARIANT::Reset */
2267 hr = IEnumVARIANT_Reset(pEnum);
2268 ok(hr == S_OK, "IEnumVARIANT_Reset failed, hresult 0x%08x\n", hr);
2270 if (iCount)
2272 /* IEnumVARIANT::Skip to the last product */
2273 hr = IEnumVARIANT_Skip(pEnum, iCount-1);
2274 ok(hr == S_OK, "IEnumVARIANT_Skip failed, hresult 0x%08x\n", hr);
2276 /* IEnumVARIANT::Next should match the very last retrieved value, also makes sure it works with
2277 * NULL celt pointer. */
2278 hr = IEnumVARIANT_Next(pEnum, 1, &var, NULL);
2279 ok(hr == S_OK, "IEnumVARIANT_Next failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
2280 ok(V_VT(&var) == VT_BSTR, "IEnumVARIANT_Next returned variant of type %d, expected %d\n", V_VT(&var), VT_BSTR);
2281 ok_w2("%s returned by StringList_Item does not match %s returned by IEnumVARIANT_Next\n", szString, V_BSTR(&var));
2282 VariantClear(&var);
2284 else
2285 skip("IEnumVARIANT::Skip impossible for 0 products\n");
2288 /* StringList::Item using an invalid index */
2289 memset(szString, 0, sizeof(szString));
2290 hr = StringList_Item(pStringList, iCount, szString);
2291 ok(hr == DISP_E_BADINDEX, "StringList_Item for an invalid index did not return DISP_E_BADINDEX, hresult 0x%08x\n", hr);
2293 if (pEnum) IEnumVARIANT_Release(pEnum);
2294 if (pUnk) IUnknown_Release(pUnk);
2295 IDispatch_Release(pStringList);
2299 /* Delete a registry subkey, including all its subkeys (RegDeleteKey does not work on keys with subkeys without
2300 * deleting the subkeys first) */
2301 static UINT delete_registry_key(HKEY hkeyParent, LPCSTR subkey)
2303 UINT ret;
2304 CHAR *string = NULL;
2305 HKEY hkey;
2306 DWORD dwSize;
2308 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2309 if (ret != ERROR_SUCCESS) return ret;
2310 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2311 if (ret != ERROR_SUCCESS) return ret;
2312 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2314 while (RegEnumKeyA(hkey, 0, string, dwSize) == ERROR_SUCCESS)
2315 delete_registry_key(hkey, string);
2317 RegCloseKey(hkey);
2318 HeapFree(GetProcessHeap(), 0, string);
2319 RegDeleteKeyA(hkeyParent, subkey);
2320 return ERROR_SUCCESS;
2323 /* Find a specific registry subkey at any depth within the given key and subkey and return its parent key. */
2324 static UINT find_registry_key(HKEY hkeyParent, LPCSTR subkey, LPCSTR findkey, HKEY *phkey)
2326 UINT ret;
2327 CHAR *string = NULL;
2328 int idx = 0;
2329 HKEY hkey;
2330 DWORD dwSize;
2331 BOOL found = FALSE;
2333 *phkey = 0;
2335 ret = RegOpenKey(hkeyParent, subkey, &hkey);
2336 if (ret != ERROR_SUCCESS) return ret;
2337 ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &dwSize, NULL, NULL, NULL, NULL, NULL, NULL);
2338 if (ret != ERROR_SUCCESS) return ret;
2339 if (!(string = HeapAlloc(GetProcessHeap(), 0, ++dwSize))) return ERROR_NOT_ENOUGH_MEMORY;
2341 while (!found &&
2342 RegEnumKeyA(hkey, idx++, string, dwSize) == ERROR_SUCCESS)
2344 if (!strcmp(string, findkey))
2346 *phkey = hkey;
2347 found = TRUE;
2349 else if (find_registry_key(hkey, string, findkey, phkey) == ERROR_SUCCESS) found = TRUE;
2352 if (*phkey != hkey) RegCloseKey(hkey);
2353 HeapFree(GetProcessHeap(), 0, string);
2354 return (found ? ERROR_SUCCESS : ERROR_FILE_NOT_FOUND);
2357 static void test_Installer_InstallProduct(void)
2359 HRESULT hr;
2360 CHAR path[MAX_PATH];
2361 WCHAR szString[MAX_PATH];
2362 LONG res;
2363 HKEY hkey;
2364 DWORD num, size, type;
2365 int iValue, iCount;
2366 IDispatch *pStringList = NULL;
2368 create_test_files();
2370 /* Installer::InstallProduct */
2371 hr = Installer_InstallProduct(szMsifile, NULL);
2372 if (hr == DISP_E_EXCEPTION)
2374 skip("Installer object not supported.\n");
2375 delete_test_files();
2376 return;
2378 ok(hr == S_OK, "Installer_InstallProduct failed, hresult 0x%08x\n", hr);
2380 /* Installer::ProductState for our product code, which has been installed */
2381 hr = Installer_ProductState(szProductCode, &iValue);
2382 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2383 ok(iValue == INSTALLSTATE_DEFAULT, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_DEFAULT);
2385 /* Installer::ProductInfo for our product code */
2387 /* NULL attribute */
2388 memset(szString, 0, sizeof(szString));
2389 hr = Installer_ProductInfo(szProductCode, NULL, szString);
2390 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2391 ok_exception(hr, szProductInfoException);
2393 /* Nonexistent attribute */
2394 memset(szString, 0, sizeof(szString));
2395 hr = Installer_ProductInfo(szProductCode, szMsifile, szString);
2396 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2397 ok_exception(hr, szProductInfoException);
2399 /* Package name */
2400 memset(szString, 0, sizeof(szString));
2401 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szString);
2402 ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2403 todo_wine ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMsifile);
2405 /* Product name */
2406 memset(szString, 0, sizeof(szString));
2407 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PRODUCTNAMEW, szString);
2408 ok(hr == S_OK, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2409 todo_wine ok_w2("Installer_ProductInfo returned %s but expected %s\n", szString, szMSITEST);
2411 /* Installer::Products */
2412 test_Installer_Products(TRUE);
2414 /* Installer::RelatedProducts for our upgrade code */
2415 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2416 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2417 if (hr == S_OK)
2419 /* StringList::Count */
2420 hr = StringList_Count(pStringList, &iCount);
2421 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2422 ok(iCount == 1, "Expected one related product but found %d\n", iCount);
2424 /* StringList::Item */
2425 memset(szString, 0, sizeof(szString));
2426 hr = StringList_Item(pStringList, 0, szString);
2427 ok(hr == S_OK, "StringList_Item failed (idx 0, count %d), hresult 0x%08x\n", iCount, hr);
2428 ok_w2("StringList_Item returned %s but expected %s\n", szString, szProductCode);
2430 IDispatch_Release(pStringList);
2433 /* Check & clean up installed files & registry keys */
2434 ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
2435 ok(delete_pf("msitest\\cabout\\new", FALSE), "File not installed\n");
2436 ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
2437 ok(delete_pf("msitest\\cabout", FALSE), "File not installed\n");
2438 ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
2439 ok(delete_pf("msitest\\changed", FALSE), "File not installed\n");
2440 ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
2441 ok(delete_pf("msitest\\first", FALSE), "File not installed\n");
2442 ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
2443 ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
2444 ok(delete_pf("msitest", FALSE), "File not installed\n");
2446 res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest", &hkey);
2447 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2449 size = MAX_PATH;
2450 type = REG_SZ;
2451 res = RegQueryValueExA(hkey, "Name", NULL, &type, (LPBYTE)path, &size);
2452 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2453 ok(!lstrcmpA(path, "imaname"), "Expected imaname, got %s\n", path);
2455 size = MAX_PATH;
2456 type = REG_SZ;
2457 res = RegQueryValueExA(hkey, "blah", NULL, &type, (LPBYTE)path, &size);
2458 ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
2460 size = sizeof(num);
2461 type = REG_DWORD;
2462 res = RegQueryValueExA(hkey, "number", NULL, &type, (LPBYTE)&num, &size);
2463 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2464 ok(num == 314, "Expected 314, got %d\n", num);
2466 size = MAX_PATH;
2467 type = REG_SZ;
2468 res = RegQueryValueExA(hkey, "OrderTestName", NULL, &type, (LPBYTE)path, &size);
2469 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2470 ok(!lstrcmpA(path, "OrderTestValue"), "Expected imaname, got %s\n", path);
2472 RegCloseKey(hkey);
2474 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wine\\msitest");
2475 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2477 /* Remove registry keys written by RegisterProduct standard action */
2478 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F1C3AF50-8B56-4A69-A00C-00773FE42F30}");
2479 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2481 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2482 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2484 res = find_registry_key(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", "05FA3C1F65B896A40AC00077F34EF203", &hkey);
2485 ok(res == ERROR_SUCCESS ||
2486 broken(res == ERROR_FILE_NOT_FOUND), /* win9x */
2487 "Expected ERROR_SUCCESS, got %d\n", res);
2488 if (res == ERROR_SUCCESS)
2490 res = delete_registry_key(hkey, "05FA3C1F65B896A40AC00077F34EF203");
2491 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2492 RegCloseKey(hkey);
2494 res = RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Products\\05FA3C1F65B896A40AC00077F34EF203");
2495 ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
2497 else
2499 /* win9x defaults to a per-machine install. */
2500 RegDeleteKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Products\\05FA3C1F65B896A40AC00077F34EF203");
2503 /* Remove registry keys written by PublishProduct standard action */
2504 res = RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Installer", &hkey);
2505 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2507 res = delete_registry_key(hkey, "Products\\05FA3C1F65B896A40AC00077F34EF203");
2508 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2510 res = RegDeleteKeyA(hkey, "UpgradeCodes\\D8E760ECA1E276347B43E42BDBDA5656");
2511 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
2513 RegCloseKey(hkey);
2515 /* Delete installation files we installed */
2516 delete_test_files();
2519 static void test_Installer(void)
2521 static WCHAR szCreateRecordException[] = { 'C','r','e','a','t','e','R','e','c','o','r','d',',','C','o','u','n','t',0 };
2522 static WCHAR szIntegerDataException[] = { 'I','n','t','e','g','e','r','D','a','t','a',',','F','i','e','l','d',0 };
2523 WCHAR szPath[MAX_PATH];
2524 HRESULT hr;
2525 IDispatch *pSession = NULL, *pDatabase = NULL, *pRecord = NULL, *pStringList = NULL;
2526 int iValue, iCount;
2528 if (!pInstaller) return;
2530 /* Installer::CreateRecord */
2532 /* Test for error */
2533 hr = Installer_CreateRecord(-1, &pRecord);
2534 ok(hr == DISP_E_EXCEPTION, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2535 ok_exception(hr, szCreateRecordException);
2537 /* Test for success */
2538 hr = Installer_CreateRecord(1, &pRecord);
2539 ok(hr == S_OK, "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
2540 ok(pRecord != NULL, "Installer_CreateRecord should not have returned NULL record\n");
2541 if (pRecord)
2543 /* Record::FieldCountGet */
2544 hr = Record_FieldCountGet(pRecord, &iValue);
2545 ok(hr == S_OK, "Record_FiledCountGet failed, hresult 0x%08x\n", hr);
2546 ok(iValue == 1, "Record_FieldCountGet result was %d but expected 1\n", iValue);
2548 /* Record::IntegerDataGet */
2549 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2550 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2551 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2553 /* Record::IntegerDataGet, bad index */
2554 hr = Record_IntegerDataGet(pRecord, 10, &iValue);
2555 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2556 ok(iValue == MSI_NULL_INTEGER, "Record_IntegerDataGet result was %d but expected %d\n", iValue, MSI_NULL_INTEGER);
2558 /* Record::IntegerDataPut */
2559 hr = Record_IntegerDataPut(pRecord, 1, 100);
2560 ok(hr == S_OK, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2562 /* Record::IntegerDataPut, bad index */
2563 hr = Record_IntegerDataPut(pRecord, 10, 100);
2564 ok(hr == DISP_E_EXCEPTION, "Record_IntegerDataPut failed, hresult 0x%08x\n", hr);
2565 ok_exception(hr, szIntegerDataException);
2567 /* Record::IntegerDataGet */
2568 hr = Record_IntegerDataGet(pRecord, 1, &iValue);
2569 ok(hr == S_OK, "Record_IntegerDataGet failed, hresult 0x%08x\n", hr);
2570 ok(iValue == 100, "Record_IntegerDataGet result was %d but expected 100\n", iValue);
2572 IDispatch_Release(pRecord);
2575 create_package(szPath);
2577 /* Installer::OpenPackage */
2578 hr = Installer_OpenPackage(szPath, 0, &pSession);
2579 ok(hr == S_OK, "Installer_OpenPackage failed, hresult 0x%08x\n", hr);
2580 if (hr == S_OK)
2582 test_Session(pSession);
2583 IDispatch_Release(pSession);
2586 /* Installer::OpenDatabase */
2587 hr = Installer_OpenDatabase(szPath, (INT_PTR)MSIDBOPEN_TRANSACT, &pDatabase);
2588 ok(hr == S_OK, "Installer_OpenDatabase failed, hresult 0x%08x\n", hr);
2589 if (hr == S_OK)
2591 test_Database(pDatabase, FALSE);
2592 IDispatch_Release(pDatabase);
2595 /* Installer::RegistryValue */
2596 test_Installer_RegistryValue();
2598 /* Installer::ProductState for our product code, which should not be installed */
2599 hr = Installer_ProductState(szProductCode, &iValue);
2600 ok(hr == S_OK, "Installer_ProductState failed, hresult 0x%08x\n", hr);
2601 ok(iValue == INSTALLSTATE_UNKNOWN, "Installer_ProductState returned %d, expected %d\n", iValue, INSTALLSTATE_UNKNOWN);
2603 /* Installer::ProductInfo for our product code, which should not be installed */
2605 /* Package name */
2606 memset(szPath, 0, sizeof(szPath));
2607 hr = Installer_ProductInfo(szProductCode, WINE_INSTALLPROPERTY_PACKAGENAMEW, szPath);
2608 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2609 ok_exception(hr, szProductInfoException);
2611 /* NULL attribute and NULL product code */
2612 memset(szPath, 0, sizeof(szPath));
2613 hr = Installer_ProductInfo(NULL, NULL, szPath);
2614 ok(hr == DISP_E_EXCEPTION, "Installer_ProductInfo failed, hresult 0x%08x\n", hr);
2615 ok_exception(hr, szProductInfoException);
2617 /* Installer::Products */
2618 test_Installer_Products(FALSE);
2620 /* Installer::RelatedProducts for our upgrade code, should not find anything */
2621 hr = Installer_RelatedProducts(szUpgradeCode, &pStringList);
2622 ok(hr == S_OK, "Installer_RelatedProducts failed, hresult 0x%08x\n", hr);
2623 if (hr == S_OK)
2625 /* StringList::Count */
2626 hr = StringList_Count(pStringList, &iCount);
2627 ok(hr == S_OK, "StringList_Count failed, hresult 0x%08x\n", hr);
2628 ok(!iCount, "Expected no related products but found %d\n", iCount);
2630 IDispatch_Release(pStringList);
2633 /* Installer::Version */
2634 memset(szPath, 0, sizeof(szPath));
2635 hr = Installer_VersionGet(szPath);
2636 ok(hr == S_OK, "Installer_VersionGet failed, hresult 0x%08x\n", hr);
2638 /* Installer::InstallProduct and other tests that depend on our product being installed */
2639 test_Installer_InstallProduct();
2642 START_TEST(automation)
2644 DWORD len;
2645 char temp_path[MAX_PATH], prev_path[MAX_PATH];
2646 HRESULT hr;
2647 CLSID clsid;
2648 IUnknown *pUnk;
2650 GetSystemTimeAsFileTime(&systemtime);
2652 GetCurrentDirectoryA(MAX_PATH, prev_path);
2653 GetTempPath(MAX_PATH, temp_path);
2654 SetCurrentDirectoryA(temp_path);
2656 lstrcpyA(CURR_DIR, temp_path);
2657 len = lstrlenA(CURR_DIR);
2659 if(len && (CURR_DIR[len - 1] == '\\'))
2660 CURR_DIR[len - 1] = 0;
2662 get_program_files_dir(PROG_FILES_DIR);
2664 hr = OleInitialize(NULL);
2665 ok (hr == S_OK, "OleInitialize returned 0x%08x\n", hr);
2666 hr = CLSIDFromProgID(szProgId, &clsid);
2667 ok (hr == S_OK, "CLSIDFromProgID returned 0x%08x\n", hr);
2668 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
2669 ok(hr == S_OK, "CoCreateInstance returned 0x%08x\n", hr);
2671 if (pUnk)
2673 hr = IUnknown_QueryInterface(pUnk, &IID_IDispatch, (void **)&pInstaller);
2674 ok (hr == S_OK, "IUnknown::QueryInterface returned 0x%08x\n", hr);
2676 test_dispid();
2677 test_dispatch();
2678 test_Installer();
2680 IDispatch_Release(pInstaller);
2681 IUnknown_Release(pUnk);
2684 OleUninitialize();
2686 SetCurrentDirectoryA(prev_path);