mcicda: Exclude unused headers.
[wine] / dlls / msi / tests / automation.c
1 /*
2  * Copyright (C) 2007 Mike McCormack for CodeWeavers
3  * Copyright (C) 2007 Misha Koshelev
4  *
5  * A test program for Microsoft Installer OLE automation functionality.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define COBJMACROS
23
24 #include <stdio.h>
25
26 #include <windows.h>
27 #include <msiquery.h>
28 #include <msidefs.h>
29 #include <msi.h>
30 #include <fci.h>
31
32 #include "wine/test.h"
33
34 static const char *msifile = "winetest.msi";
35 static const WCHAR szMsifile[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
36 CHAR CURR_DIR[MAX_PATH];
37 EXCEPINFO excepinfo;
38
39 /*
40  * OLE automation data
41  **/
42 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 };
43 static IDispatch *pInstaller;
44
45 /* msi database data */
46
47 static const CHAR component_dat[] = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
48                                     "s72\tS38\ts72\ti2\tS255\tS72\n"
49                                     "Component\tComponent\n"
50                                     "Five\t{8CC92E9D-14B2-4CA4-B2AA-B11D02078087}\tNEWDIR\t2\t\tfive.txt\n"
51                                     "Four\t{FD37B4EA-7209-45C0-8917-535F35A2F080}\tCABOUTDIR\t2\t\tfour.txt\n"
52                                     "One\t{783B242E-E185-4A56-AF86-C09815EC053C}\tMSITESTDIR\t2\t\tone.txt\n"
53                                     "Three\t{010B6ADD-B27D-4EDD-9B3D-34C4F7D61684}\tCHANGEDDIR\t2\t\tthree.txt\n"
54                                     "Two\t{BF03D1A6-20DA-4A65-82F3-6CAC995915CE}\tFIRSTDIR\t2\t\ttwo.txt\n"
55                                     "dangler\t{6091DF25-EF96-45F1-B8E9-A9B1420C7A3C}\tTARGETDIR\t4\t\tregdata\n"
56                                     "component\t\tMSITESTDIR\t0\t1\tfile\n"
57                                     "service_comp\t\tMSITESTDIR\t0\t1\tservice_file";
58
59 static const CHAR directory_dat[] = "Directory\tDirectory_Parent\tDefaultDir\n"
60                                     "s72\tS72\tl255\n"
61                                     "Directory\tDirectory\n"
62                                     "CABOUTDIR\tMSITESTDIR\tcabout\n"
63                                     "CHANGEDDIR\tMSITESTDIR\tchanged:second\n"
64                                     "FIRSTDIR\tMSITESTDIR\tfirst\n"
65                                     "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
66                                     "NEWDIR\tCABOUTDIR\tnew\n"
67                                     "ProgramFilesFolder\tTARGETDIR\t.\n"
68                                     "TARGETDIR\t\tSourceDir";
69
70 static const CHAR feature_dat[] = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
71                                   "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
72                                   "Feature\tFeature\n"
73                                   "Five\t\tFive\tThe Five Feature\t5\t3\tNEWDIR\t0\n"
74                                   "Four\t\tFour\tThe Four Feature\t4\t3\tCABOUTDIR\t0\n"
75                                   "One\t\tOne\tThe One Feature\t1\t3\tMSITESTDIR\t0\n"
76                                   "Three\tOne\tThree\tThe Three Feature\t3\t3\tCHANGEDDIR\t0\n"
77                                   "Two\tOne\tTwo\tThe Two Feature\t2\t3\tFIRSTDIR\t0\n"
78                                   "feature\t\t\t\t2\t1\tTARGETDIR\t0\n"
79                                   "service_feature\t\t\t\t2\t1\tTARGETDIR\t0";
80
81 static const CHAR feature_comp_dat[] = "Feature_\tComponent_\n"
82                                        "s38\ts72\n"
83                                        "FeatureComponents\tFeature_\tComponent_\n"
84                                        "Five\tFive\n"
85                                        "Four\tFour\n"
86                                        "One\tOne\n"
87                                        "Three\tThree\n"
88                                        "Two\tTwo\n"
89                                        "feature\tcomponent\n"
90                                        "service_feature\tservice_comp\n";
91
92 static const CHAR file_dat[] = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
93                                "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
94                                "File\tFile\n"
95                                "five.txt\tFive\tfive.txt\t1000\t\t\t16384\t5\n"
96                                "four.txt\tFour\tfour.txt\t1000\t\t\t16384\t4\n"
97                                "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n"
98                                "three.txt\tThree\tthree.txt\t1000\t\t\t0\t3\n"
99                                "two.txt\tTwo\ttwo.txt\t1000\t\t\t0\t2\n"
100                                "file\tcomponent\tfilename\t100\t\t\t8192\t1\n"
101                                "service_file\tservice_comp\tservice.exe\t100\t\t\t8192\t1";
102
103 static const CHAR install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
104                                            "s72\tS255\tI2\n"
105                                            "InstallExecuteSequence\tAction\n"
106                                            "AllocateRegistrySpace\tNOT Installed\t1550\n"
107                                            "CostFinalize\t\t1000\n"
108                                            "CostInitialize\t\t800\n"
109                                            "FileCost\t\t900\n"
110                                            "InstallFiles\t\t4000\n"
111                                            "InstallServices\t\t5000\n"
112                                            "InstallFinalize\t\t6600\n"
113                                            "InstallInitialize\t\t1500\n"
114                                            "InstallValidate\t\t1400\n"
115                                            "LaunchConditions\t\t100\n"
116                                            "WriteRegistryValues\tSourceDir And SOURCEDIR\t5000";
117
118 static const CHAR media_dat[] = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
119                                 "i2\ti4\tL64\tS255\tS32\tS72\n"
120                                 "Media\tDiskId\n"
121                                 "1\t3\t\t\tDISK1\t\n"
122                                 "2\t5\t\tmsitest.cab\tDISK2\t\n";
123
124 static const CHAR property_dat[] = "Property\tValue\n"
125                                    "s72\tl0\n"
126                                    "Property\tProperty\n"
127                                    "DefaultUIFont\tDlgFont8\n"
128                                    "HASUIRUN\t0\n"
129                                    "INSTALLLEVEL\t3\n"
130                                    "InstallMode\tTypical\n"
131                                    "Manufacturer\tWine\n"
132                                    "PIDTemplate\t12345<###-%%%%%%%>@@@@@\n"
133                                    "ProductCode\t{F1C3AF50-8B56-4A69-A00C-00773FE42F30}\n"
134                                    "ProductID\tnone\n"
135                                    "ProductLanguage\t1033\n"
136                                    "ProductName\tMSITEST\n"
137                                    "ProductVersion\t1.1.1\n"
138                                    "PROMPTROLLBACKCOST\tP\n"
139                                    "Setup\tSetup\n"
140                                    "UpgradeCode\t{CE067E8D-2E1A-4367-B734-4EB2BDAD6565}";
141
142 static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_\n"
143                                    "s72\ti2\tl255\tL255\tL0\ts72\n"
144                                    "Registry\tRegistry\n"
145                                    "Apples\t2\tSOFTWARE\\Wine\\msitest\tName\timaname\tOne\n"
146                                    "Oranges\t2\tSOFTWARE\\Wine\\msitest\tnumber\t#314\tTwo\n"
147                                    "regdata\t2\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
148                                    "OrderTest\t2\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent";
149
150 static const CHAR service_install_dat[] = "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
151                                           "LoadOrderGroup\tDependencies\tStartName\tPassword\tArguments\tComponent_\tDescription\n"
152                                           "s72\ts255\tL255\ti4\ti4\ti4\tS255\tS255\tS255\tS255\tS255\ts72\tL255\n"
153                                           "ServiceInstall\tServiceInstall\n"
154                                           "TestService\tTestService\tTestService\t2\t3\t0\t\t\tTestService\t\t\tservice_comp\t\t";
155
156 static const CHAR service_control_dat[] = "ServiceControl\tName\tEvent\tArguments\tWait\tComponent_\n"
157                                           "s72\tl255\ti2\tL255\tI2\ts72\n"
158                                           "ServiceControl\tServiceControl\n"
159                                           "ServiceControl\tTestService\t8\t\t0\tservice_comp";
160
161 typedef struct _msi_table
162 {
163     const CHAR *filename;
164     const CHAR *data;
165     int size;
166 } msi_table;
167
168 #define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
169
170 static const msi_table tables[] =
171 {
172     ADD_TABLE(component),
173     ADD_TABLE(directory),
174     ADD_TABLE(feature),
175     ADD_TABLE(feature_comp),
176     ADD_TABLE(file),
177     ADD_TABLE(install_exec_seq),
178     ADD_TABLE(media),
179     ADD_TABLE(property),
180     ADD_TABLE(registry),
181     ADD_TABLE(service_install),
182     ADD_TABLE(service_control)
183 };
184
185 /*
186  * Database Helpers
187  */
188
189 static void write_file(const CHAR *filename, const char *data, int data_size)
190 {
191     DWORD size;
192
193     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
194                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
195
196     WriteFile(hf, data, data_size, &size, NULL);
197     CloseHandle(hf);
198 }
199
200 static void write_msi_summary_info(MSIHANDLE db)
201 {
202     MSIHANDLE summary;
203     UINT r;
204
205     r = MsiGetSummaryInformationA(db, NULL, 4, &summary);
206     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
207
208     r = MsiSummaryInfoSetPropertyA(summary, PID_TEMPLATE, VT_LPSTR, 0, NULL, ";1033");
209     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
210
211     r = MsiSummaryInfoSetPropertyA(summary, PID_REVNUMBER, VT_LPSTR, 0, NULL,
212                                    "{004757CA-5092-49c2-AD20-28E1CE0DF5F2}");
213     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
214
215     r = MsiSummaryInfoSetPropertyA(summary, PID_PAGECOUNT, VT_I4, 100, NULL, NULL);
216     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
217
218     r = MsiSummaryInfoSetPropertyA(summary, PID_WORDCOUNT, VT_I4, 0, NULL, NULL);
219     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
220
221     /* write the summary changes back to the stream */
222     r = MsiSummaryInfoPersist(summary);
223     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
224
225     MsiCloseHandle(summary);
226 }
227
228 static void create_database(const CHAR *name, const msi_table *tables, int num_tables)
229 {
230     MSIHANDLE db;
231     UINT r;
232     int j;
233
234     r = MsiOpenDatabaseA(name, MSIDBOPEN_CREATE, &db);
235     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
236
237     /* import the tables into the database */
238     for (j = 0; j < num_tables; j++)
239     {
240         const msi_table *table = &tables[j];
241
242         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
243
244         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
245         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
246
247         DeleteFileA(table->filename);
248     }
249
250     write_msi_summary_info(db);
251
252     r = MsiDatabaseCommit(db);
253     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
254
255     MsiCloseHandle(db);
256 }
257
258 /*
259  * Automation helpers and tests
260  */
261
262 /* ok-like statement which takes two unicode strings as arguments */
263 static CHAR string1[MAX_PATH], string2[MAX_PATH];
264
265 #define ok_w2(format, szString1, szString2) \
266 \
267     if (lstrcmpW(szString1, szString2) != 0) \
268     { \
269         WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
270         WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
271         ok(0, format, string1, string2); \
272     }
273
274 /* exception checker */
275 static WCHAR szSource[] = {'M','s','i',' ','A','P','I',' ','E','r','r','o','r',0};
276
277 #define ok_exception(hr, szDescription)           \
278     if (hr == DISP_E_EXCEPTION) \
279     { \
280         /* Compare wtype, source, and destination */                    \
281         ok(excepinfo.wCode == 1000, "Exception info was %d, expected 1000\n", excepinfo.wCode); \
282 \
283         ok(excepinfo.bstrSource != NULL, "Exception source was NULL\n"); \
284         if (excepinfo.bstrSource)                                       \
285             ok_w2("Exception source was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrSource, szSource); \
286 \
287         ok(excepinfo.bstrDescription != NULL, "Exception description was NULL\n"); \
288         if (excepinfo.bstrDescription) \
289             ok_w2("Exception description was \"%s\" but expected to be \"%s\"\n", excepinfo.bstrDescription, szDescription); \
290     }
291
292 static DISPID get_dispid( IDispatch *disp, const char *name )
293 {
294     LPOLESTR str;
295     UINT len;
296     DISPID id = -1;
297     HRESULT r;
298
299     len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0 );
300     str = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
301     if (str)
302     {
303         len = MultiByteToWideChar(CP_ACP, 0, name, -1, str, len );
304         r = IDispatch_GetIDsOfNames( disp, &IID_NULL, &str, 1, 0, &id );
305         HeapFree(GetProcessHeap(), 0, str);
306         if (r != S_OK)
307             return -1;
308     }
309
310     return id;
311 }
312
313 static void test_dispid(void)
314 {
315     todo_wine {
316     ok( get_dispid( pInstaller, "CreateRecord" ) == 1, "dispid wrong\n");
317     }
318     ok( get_dispid( pInstaller, "OpenPackage" ) == 2, "dispid wrong\n");
319     todo_wine {
320     ok( get_dispid( pInstaller, "OpenProduct" ) == 3, "dispid wrong\n");
321     ok( get_dispid( pInstaller, "OpenDatabase" ) == 4, "dispid wrong\n");
322     ok( get_dispid( pInstaller, "SummaryInformation" ) == 5, "dispid wrong\n");
323     ok( get_dispid( pInstaller, "UILevel" ) == 6, "dispid wrong\n");
324     ok( get_dispid( pInstaller, "EnableLog" ) == 7, "dispid wrong\n");
325     ok( get_dispid( pInstaller, "InstallProduct" ) == 8, "dispid wrong\n");
326     ok( get_dispid( pInstaller, "Version" ) == 9, "dispid wrong\n");
327     ok( get_dispid( pInstaller, "LastErrorRecord" ) == 10, "dispid wrong\n");
328     ok( get_dispid( pInstaller, "RegistryValue" ) == 11, "dispid wrong\n");
329     ok( get_dispid( pInstaller, "Environment" ) == 12, "dispid wrong\n");
330     ok( get_dispid( pInstaller, "FileAttributes" ) == 13, "dispid wrong\n");
331
332     ok( get_dispid( pInstaller, "FileSize" ) == 15, "dispid wrong\n");
333     ok( get_dispid( pInstaller, "FileVersion" ) == 16, "dispid wrong\n");
334     }
335     ok( get_dispid( pInstaller, "ProductState" ) == 17, "dispid wrong\n");
336     todo_wine {
337     ok( get_dispid( pInstaller, "ProductInfo" ) == 18, "dispid wrong\n");
338     ok( get_dispid( pInstaller, "ConfigureProduct" ) == 19, "dispid wrong\n");
339     ok( get_dispid( pInstaller, "ReinstallProduct" ) == 20 , "dispid wrong\n");
340     ok( get_dispid( pInstaller, "CollectUserInfo" ) == 21, "dispid wrong\n");
341     ok( get_dispid( pInstaller, "ApplyPatch" ) == 22, "dispid wrong\n");
342     ok( get_dispid( pInstaller, "FeatureParent" ) == 23, "dispid wrong\n");
343     ok( get_dispid( pInstaller, "FeatureState" ) == 24, "dispid wrong\n");
344     ok( get_dispid( pInstaller, "UseFeature" ) == 25, "dispid wrong\n");
345     ok( get_dispid( pInstaller, "FeatureUsageCount" ) == 26, "dispid wrong\n");
346     ok( get_dispid( pInstaller, "FeatureUsageDate" ) == 27, "dispid wrong\n");
347     ok( get_dispid( pInstaller, "ConfigureFeature" ) == 28, "dispid wrong\n");
348     ok( get_dispid( pInstaller, "ReinstallFeature" ) == 29, "dispid wrong\n");
349     ok( get_dispid( pInstaller, "ProvideComponent" ) == 30, "dispid wrong\n");
350     ok( get_dispid( pInstaller, "ComponentPath" ) == 31, "dispid wrong\n");
351     ok( get_dispid( pInstaller, "ProvideQualifiedComponent" ) == 32, "dispid wrong\n");
352     ok( get_dispid( pInstaller, "QualifierDescription" ) == 33, "dispid wrong\n");
353     ok( get_dispid( pInstaller, "ComponentQualifiers" ) == 34, "dispid wrong\n");
354     }
355     ok( get_dispid( pInstaller, "Products" ) == 35, "dispid wrong\n");
356     todo_wine {
357     ok( get_dispid( pInstaller, "Features" ) == 36, "dispid wrong\n");
358     ok( get_dispid( pInstaller, "Components" ) == 37, "dispid wrong\n");
359     ok( get_dispid( pInstaller, "ComponentClients" ) == 38, "dispid wrong\n");
360     ok( get_dispid( pInstaller, "Patches" ) == 39, "dispid wrong\n");
361     ok( get_dispid( pInstaller, "RelatedProducts" ) == 40, "dispid wrong\n");
362     ok( get_dispid( pInstaller, "PatchInfo" ) == 41, "dispid wrong\n");
363     ok( get_dispid( pInstaller, "PatchTransforms" ) == 42, "dispid wrong\n");
364     ok( get_dispid( pInstaller, "AddSource" ) == 43, "dispid wrong\n");
365     ok( get_dispid( pInstaller, "ClearSourceList" ) == 44, "dispid wrong\n");
366     ok( get_dispid( pInstaller, "ForceSourceListResolution" ) == 45, "dispid wrong\n");
367     ok( get_dispid( pInstaller, "ShortcutTarget" ) == 46, "dispid wrong\n");
368     ok( get_dispid( pInstaller, "FileHash" ) == 47, "dispid wrong\n");
369     ok( get_dispid( pInstaller, "FileSignatureInfo" ) == 48, "dispid wrong\n");
370     ok( get_dispid( pInstaller, "RemovePatches" ) == 49, "dispid wrong\n");
371
372     ok( get_dispid( pInstaller, "ApplyMultiplePatches" ) == 51, "dispid wrong\n");
373     ok( get_dispid( pInstaller, "ProductsEx" ) ==  52, "dispid wrong\n");
374
375     ok( get_dispid( pInstaller, "PatchesEx" ) == 55, "dispid wrong\n");
376
377     ok( get_dispid( pInstaller, "ExtractPatchXMLData" ) == 57, "dispid wrong\n");
378     }
379
380     /* MSDN claims the following functions exist but IDispatch->GetIDsOfNames disagrees */
381     if (0)
382     {
383         get_dispid( pInstaller, "ProductElevated" );
384         get_dispid( pInstaller, "ProductInfoFromScript" );
385         get_dispid( pInstaller, "ProvideAssembly" );
386         get_dispid( pInstaller, "CreateAdvertiseScript" );
387         get_dispid( pInstaller, "AdvertiseProduct" );
388         get_dispid( pInstaller, "PatchFiles" );
389     }
390 }
391
392 /* Test basic IDispatch functions */
393 static void test_dispatch(void)
394 {
395     static WCHAR szOpenPackage[] = { 'O','p','e','n','P','a','c','k','a','g','e',0 };
396     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};
397     HRESULT hr;
398     DISPID dispid;
399     OLECHAR *name;
400     VARIANT varresult;
401     VARIANTARG vararg[2];
402     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
403
404     /* Test getting ID of a function name that does not exist */
405     name = (WCHAR *)szMsifile;
406     hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
407     ok(hr == DISP_E_UNKNOWNNAME, "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
408
409     /* Test invoking this function */
410     hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
411     ok(hr == DISP_E_MEMBERNOTFOUND, "IDispatch::Invoke returned 0x%08x\n", hr);
412
413     /* Test getting ID of a function name that does exist */
414     name = (WCHAR *)szOpenPackage;
415     hr = IDispatch_GetIDsOfNames(pInstaller, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
416     ok(SUCCEEDED(hr), "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
417
418     /* Test invoking this function (without parameters passed) */
419     if (0) /* All of these crash MSI on Windows XP */
420     {
421         hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
422         hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, NULL, &excepinfo, NULL);
423         VariantInit(&varresult);
424         hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, NULL, &varresult, &excepinfo, NULL);
425     }
426
427     /* Try with NULL params */
428     hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
429     todo_wine ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
430
431     /* Try one empty parameter */
432     dispparams.rgvarg = vararg;
433     dispparams.cArgs = 1;
434     VariantInit(&vararg[0]);
435     hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
436     todo_wine ok(hr == DISP_E_TYPEMISMATCH, "IDispatch::Invoke returned 0x%08x\n", hr);
437
438     /* Try one parameter, function requires two */
439     VariantInit(&vararg[0]);
440     V_VT(&vararg[0]) = VT_BSTR;
441     V_BSTR(&vararg[0]) = SysAllocString(szMsifile);
442     hr = IDispatch_Invoke(pInstaller, dispid, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
443     VariantClear(&vararg[0]);
444
445     ok(hr == DISP_E_EXCEPTION, "IDispatch::Invoke returned 0x%08x\n", hr);
446     ok_exception(hr, szOpenPackageException);
447 }
448
449 /* invocation helper function */
450 static HRESULT invoke(IDispatch *pDispatch, LPCSTR szName, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, VARTYPE vtResult)
451 {
452     OLECHAR *name = NULL;
453     DISPID dispid;
454     HRESULT hr;
455     int i;
456     UINT len;
457
458     memset(pVarResult, 0, sizeof(VARIANT));
459     VariantInit(pVarResult);
460
461     len = MultiByteToWideChar(CP_ACP, 0, szName, -1, NULL, 0 );
462     name = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR) );
463     if (!name) return E_FAIL;
464     len = MultiByteToWideChar(CP_ACP, 0, szName, -1, name, len );
465     hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
466     HeapFree(GetProcessHeap(), 0, name);
467     ok(SUCCEEDED(hr), "IDispatch::GetIDsOfNames returned 0x%08x\n", hr);
468     if (!SUCCEEDED(hr)) return hr;
469
470     memset(&excepinfo, 0, sizeof(excepinfo));
471     hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_NEUTRAL, wFlags, pDispParams, pVarResult, &excepinfo, NULL);
472
473     if (SUCCEEDED(hr))
474     {
475         ok(V_VT(pVarResult) == vtResult, "Variant result type is %d, expected %d\n", V_VT(pVarResult), vtResult);
476         if (vtResult != VT_EMPTY)
477         {
478             hr = VariantChangeTypeEx(pVarResult, pVarResult, LOCALE_NEUTRAL, 0, vtResult);
479             ok(SUCCEEDED(hr), "VariantChangeTypeEx returned 0x%08x\n", hr);
480         }
481     }
482
483     for (i=0; i<pDispParams->cArgs; i++)
484         VariantClear(&pDispParams->rgvarg[i]);
485
486     return hr;
487 }
488
489 /* Object_Property helper functions */
490
491 static HRESULT Installer_CreateRecord(int count, IDispatch **pRecord)
492 {
493     VARIANT varresult;
494     VARIANTARG vararg[1];
495     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
496     HRESULT hr;
497
498     VariantInit(&vararg[0]);
499     V_VT(&vararg[0]) = VT_I4;
500     V_I4(&vararg[0]) = count;
501
502     hr = invoke(pInstaller, "CreateRecord", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
503     *pRecord = V_DISPATCH(&varresult);
504     return hr;
505 }
506
507 static HRESULT Installer_RegistryValue(HKEY hkey, LPCWSTR szKey, VARIANT vValue, VARIANT *pVarResult, VARTYPE vtExpect)
508 {
509     VARIANTARG vararg[3];
510     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
511
512     VariantInit(&vararg[2]);
513     V_VT(&vararg[2]) = VT_I4;
514     V_I4(&vararg[2]) = (int)hkey;
515     VariantInit(&vararg[1]);
516     V_VT(&vararg[1]) = VT_BSTR;
517     V_BSTR(&vararg[1]) = SysAllocString(szKey);
518     VariantInit(&vararg[0]);
519     VariantCopy(&vararg[0], &vValue);
520     VariantClear(&vValue);
521
522     return invoke(pInstaller, "RegistryValue", DISPATCH_METHOD, &dispparams, pVarResult, vtExpect);
523 }
524
525 static HRESULT Installer_RegistryValueE(HKEY hkey, LPCWSTR szKey, BOOL *pBool)
526 {
527     VARIANT varresult;
528     VARIANTARG vararg;
529     HRESULT hr;
530
531     VariantInit(&vararg);
532     V_VT(&vararg) = VT_EMPTY;
533     hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BOOL);
534     *pBool = V_BOOL(&varresult);
535     VariantClear(&varresult);
536     return hr;
537 }
538
539 static HRESULT Installer_RegistryValueW(HKEY hkey, LPCWSTR szKey, LPCWSTR szValue, LPWSTR szString)
540 {
541     VARIANT varresult;
542     VARIANTARG vararg;
543     HRESULT hr;
544
545     VariantInit(&vararg);
546     V_VT(&vararg) = VT_BSTR;
547     V_BSTR(&vararg) = SysAllocString(szValue);
548
549     hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, VT_BSTR);
550     lstrcpyW(szString, V_BSTR(&varresult));
551     VariantClear(&varresult);
552     return hr;
553 }
554
555 static HRESULT Installer_RegistryValueI(HKEY hkey, LPCWSTR szKey, int iValue, LPWSTR szString, VARTYPE vtResult)
556 {
557     VARIANT varresult;
558     VARIANTARG vararg;
559     HRESULT hr;
560
561     VariantInit(&vararg);
562     V_VT(&vararg) = VT_I4;
563     V_I4(&vararg) = iValue;
564
565     hr = Installer_RegistryValue(hkey, szKey, vararg, &varresult, vtResult);
566     if (vtResult == VT_BSTR) lstrcpyW(szString, V_BSTR(&varresult));
567     VariantClear(&varresult);
568     return hr;
569 }
570
571 static HRESULT Installer_OpenPackage(LPCWSTR szPackagePath, int options, IDispatch **pSession)
572 {
573     VARIANT varresult;
574     VARIANTARG vararg[2];
575     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
576     HRESULT hr;
577
578     VariantInit(&vararg[1]);
579     V_VT(&vararg[1]) = VT_BSTR;
580     V_BSTR(&vararg[1]) = SysAllocString(szPackagePath);
581     VariantInit(&vararg[0]);
582     V_VT(&vararg[0]) = VT_I4;
583     V_I4(&vararg[0]) = options;
584
585     hr = invoke(pInstaller, "OpenPackage", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
586     *pSession = V_DISPATCH(&varresult);
587     return hr;
588 }
589
590 static HRESULT Installer_ProductState(LPCWSTR szProduct, int *pInstallState)
591 {
592     VARIANT varresult;
593     VARIANTARG vararg[1];
594     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
595     HRESULT hr;
596
597     VariantInit(&vararg[0]);
598     V_VT(&vararg[0]) = VT_BSTR;
599     V_BSTR(&vararg[0]) = SysAllocString(szProduct);
600
601     hr = invoke(pInstaller, "ProductState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
602     *pInstallState = V_I4(&varresult);
603     VariantClear(&varresult);
604     return hr;
605 }
606
607 static HRESULT Installer_Products(IDispatch **pStringList)
608 {
609     VARIANT varresult;
610     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
611     HRESULT hr;
612
613     hr = invoke(pInstaller, "Products", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
614     *pStringList = V_DISPATCH(&varresult);
615     return hr;
616 }
617
618 static HRESULT Installer_VersionGet(LPCWSTR szVersion)
619 {
620     VARIANT varresult;
621     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
622     HRESULT hr;
623
624     hr = invoke(pInstaller, "Version", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
625     lstrcpyW((WCHAR *)szVersion, V_BSTR(&varresult));
626     VariantClear(&varresult);
627     return hr;
628 }
629
630 static HRESULT Session_Installer(IDispatch *pSession, IDispatch **pInst)
631 {
632     VARIANT varresult;
633     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
634     HRESULT hr;
635
636     hr = invoke(pSession, "Installer", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
637     *pInst = V_DISPATCH(&varresult);
638     return hr;
639 }
640
641 static HRESULT Session_PropertyGet(IDispatch *pSession, LPCWSTR szName, LPCWSTR szReturn)
642 {
643     VARIANT varresult;
644     VARIANTARG vararg[1];
645     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
646     HRESULT hr;
647
648     VariantInit(&vararg[0]);
649     V_VT(&vararg[0]) = VT_BSTR;
650     V_BSTR(&vararg[0]) = SysAllocString(szName);
651
652     hr = invoke(pSession, "Property", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
653     lstrcpyW((WCHAR *)szReturn, V_BSTR(&varresult));
654     VariantClear(&varresult);
655     return hr;
656 }
657
658 static HRESULT Session_PropertyPut(IDispatch *pSession, LPCWSTR szName, LPCWSTR szValue)
659 {
660     VARIANT varresult;
661     VARIANTARG vararg[2];
662     DISPID dispid = DISPID_PROPERTYPUT;
663     DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
664
665     VariantInit(&vararg[1]);
666     V_VT(&vararg[1]) = VT_BSTR;
667     V_BSTR(&vararg[1]) = SysAllocString(szName);
668     VariantInit(&vararg[0]);
669     V_VT(&vararg[0]) = VT_BSTR;
670     V_BSTR(&vararg[0]) = SysAllocString(szValue);
671
672     return invoke(pSession, "Property", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
673 }
674
675 static HRESULT Session_LanguageGet(IDispatch *pSession, UINT *pLangId)
676 {
677     VARIANT varresult;
678     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
679     HRESULT hr;
680
681     hr = invoke(pSession, "Language", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
682     *pLangId = V_I4(&varresult);
683     VariantClear(&varresult);
684     return hr;
685 }
686
687 static HRESULT Session_ModeGet(IDispatch *pSession, int iFlag, BOOL *pMode)
688 {
689     VARIANT varresult;
690     VARIANTARG vararg[1];
691     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
692     HRESULT hr;
693
694     VariantInit(&vararg[0]);
695     V_VT(&vararg[0]) = VT_I4;
696     V_I4(&vararg[0]) = iFlag;
697
698     hr = invoke(pSession, "Mode", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BOOL);
699     *pMode = V_BOOL(&varresult);
700     VariantClear(&varresult);
701     return hr;
702 }
703
704 static HRESULT Session_ModePut(IDispatch *pSession, int iFlag, BOOL bMode)
705 {
706     VARIANT varresult;
707     VARIANTARG vararg[2];
708     DISPID dispid = DISPID_PROPERTYPUT;
709     DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
710
711     VariantInit(&vararg[1]);
712     V_VT(&vararg[1]) = VT_I4;
713     V_I4(&vararg[1]) = iFlag;
714     VariantInit(&vararg[0]);
715     V_VT(&vararg[0]) = VT_BOOL;
716     V_BOOL(&vararg[0]) = bMode;
717
718     return invoke(pSession, "Mode", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
719 }
720
721 static HRESULT Session_Database(IDispatch *pSession, IDispatch **pDatabase)
722 {
723     VARIANT varresult;
724     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
725     HRESULT hr;
726
727     hr = invoke(pSession, "Database", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_DISPATCH);
728     *pDatabase = V_DISPATCH(&varresult);
729     return hr;
730 }
731
732 static HRESULT Session_DoAction(IDispatch *pSession, LPCWSTR szAction, int *iReturn)
733 {
734     VARIANT varresult;
735     VARIANTARG vararg[1];
736     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
737     HRESULT hr;
738
739     VariantInit(&vararg[0]);
740     V_VT(&vararg[0]) = VT_BSTR;
741     V_BSTR(&vararg[0]) = SysAllocString(szAction);
742
743     hr = invoke(pSession, "DoAction", DISPATCH_METHOD, &dispparams, &varresult, VT_I4);
744     *iReturn = V_I4(&varresult);
745     VariantClear(&varresult);
746     return hr;
747 }
748
749 static HRESULT Session_SetInstallLevel(IDispatch *pSession, long iInstallLevel)
750 {
751     VARIANT varresult;
752     VARIANTARG vararg[1];
753     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
754
755     VariantInit(&vararg[0]);
756     V_VT(&vararg[0]) = VT_I4;
757     V_I4(&vararg[0]) = iInstallLevel;
758
759     return invoke(pSession, "SetInstallLevel", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
760 }
761
762 static HRESULT Session_FeatureCurrentState(IDispatch *pSession, LPCWSTR szName, int *pState)
763 {
764     VARIANT varresult;
765     VARIANTARG vararg[1];
766     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
767     HRESULT hr;
768
769     VariantInit(&vararg[0]);
770     V_VT(&vararg[0]) = VT_BSTR;
771     V_BSTR(&vararg[0]) = SysAllocString(szName);
772
773     hr = invoke(pSession, "FeatureCurrentState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
774     *pState = V_I4(&varresult);
775     VariantClear(&varresult);
776     return hr;
777 }
778
779 static HRESULT Session_FeatureRequestStateGet(IDispatch *pSession, LPCWSTR szName, int *pState)
780 {
781     VARIANT varresult;
782     VARIANTARG vararg[1];
783     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
784     HRESULT hr;
785
786     VariantInit(&vararg[0]);
787     V_VT(&vararg[0]) = VT_BSTR;
788     V_BSTR(&vararg[0]) = SysAllocString(szName);
789
790     hr = invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
791     *pState = V_I4(&varresult);
792     VariantClear(&varresult);
793     return hr;
794 }
795
796 static HRESULT Session_FeatureRequestStatePut(IDispatch *pSession, LPCWSTR szName, int iState)
797 {
798     VARIANT varresult;
799     VARIANTARG vararg[2];
800     DISPID dispid = DISPID_PROPERTYPUT;
801     DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
802
803     VariantInit(&vararg[1]);
804     V_VT(&vararg[1]) = VT_BSTR;
805     V_BSTR(&vararg[1]) = SysAllocString(szName);
806     VariantInit(&vararg[0]);
807     V_VT(&vararg[0]) = VT_I4;
808     V_I4(&vararg[0]) = iState;
809
810     return invoke(pSession, "FeatureRequestState", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_EMPTY);
811 }
812
813 static HRESULT Database_OpenView(IDispatch *pDatabase, LPCWSTR szSql, IDispatch **pView)
814 {
815     VARIANT varresult;
816     VARIANTARG vararg[1];
817     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
818     HRESULT hr;
819
820     VariantInit(&vararg[0]);
821     V_VT(&vararg[0]) = VT_BSTR;
822     V_BSTR(&vararg[0]) = SysAllocString(szSql);
823
824     hr = invoke(pDatabase, "OpenView", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
825     *pView = V_DISPATCH(&varresult);
826     return hr;
827 }
828
829 static HRESULT View_Execute(IDispatch *pView, IDispatch *pRecord)
830 {
831     VARIANT varresult;
832     VARIANTARG vararg[1];
833     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
834
835     VariantInit(&vararg[0]);
836     V_VT(&vararg[0]) = VT_DISPATCH;
837     V_DISPATCH(&vararg[0]) = pRecord;
838
839     return invoke(pView, "Execute", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
840 }
841
842 static HRESULT View_Fetch(IDispatch *pView, IDispatch **ppRecord)
843 {
844     VARIANT varresult;
845     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
846     HRESULT hr = invoke(pView, "Fetch", DISPATCH_METHOD, &dispparams, &varresult, VT_DISPATCH);
847     *ppRecord = V_DISPATCH(&varresult);
848     return hr;
849 }
850
851 static HRESULT View_Close(IDispatch *pView)
852 {
853     VARIANT varresult;
854     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
855     return invoke(pView, "Close", DISPATCH_METHOD, &dispparams, &varresult, VT_EMPTY);
856 }
857
858 static HRESULT Record_FieldCountGet(IDispatch *pRecord, int *pFieldCount)
859 {
860     VARIANT varresult;
861     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
862     HRESULT hr = invoke(pRecord, "FieldCount", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
863     *pFieldCount = V_I4(&varresult);
864     VariantClear(&varresult);
865     return hr;
866 }
867
868 static HRESULT Record_StringDataGet(IDispatch *pRecord, int iField, LPCWSTR szString)
869 {
870     VARIANT varresult;
871     VARIANTARG vararg[1];
872     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
873     HRESULT hr;
874
875     VariantInit(&vararg[0]);
876     V_VT(&vararg[0]) = VT_I4;
877     V_I4(&vararg[0]) = iField;
878
879     hr = invoke(pRecord, "StringData", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
880     lstrcpyW((WCHAR *)szString, V_BSTR(&varresult));
881     VariantClear(&varresult);
882     return hr;
883 }
884
885 static HRESULT Record_StringDataPut(IDispatch *pRecord, int iField, LPCWSTR szString)
886 {
887     VARIANT varresult;
888     VARIANTARG vararg[2];
889     DISPID dispid = DISPID_PROPERTYPUT;
890     DISPPARAMS dispparams = {vararg, &dispid, sizeof(vararg)/sizeof(VARIANTARG), 1};
891
892     VariantInit(&vararg[1]);
893     V_VT(&vararg[1]) = VT_I4;
894     V_I4(&vararg[1]) = iField;
895     VariantInit(&vararg[0]);
896     V_VT(&vararg[0]) = VT_BSTR;
897     V_BSTR(&vararg[0]) = SysAllocString(szString);
898
899     return invoke(pRecord, "StringData", DISPATCH_PROPERTYPUT, &dispparams, &varresult, VT_BSTR);
900 }
901
902 static HRESULT StringList_Item(IDispatch *pStringList, int iIndex, LPWSTR szString)
903 {
904     VARIANT varresult;
905     VARIANTARG vararg[1];
906     DISPPARAMS dispparams = {vararg, NULL, sizeof(vararg)/sizeof(VARIANTARG), 0};
907     HRESULT hr;
908
909     VariantInit(&vararg[0]);
910     V_VT(&vararg[0]) = VT_I4;
911     V_I4(&vararg[0]) = iIndex;
912
913     hr = invoke(pStringList, "Item", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_BSTR);
914     lstrcpyW(szString, V_BSTR(&varresult));
915     VariantClear(&varresult);
916     return hr;
917 }
918
919 static HRESULT StringList_Count(IDispatch *pStringList, int *pCount)
920 {
921     VARIANT varresult;
922     DISPPARAMS dispparams = {NULL, NULL, 0, 0};
923     HRESULT hr = invoke(pStringList, "Count", DISPATCH_PROPERTYGET, &dispparams, &varresult, VT_I4);
924     *pCount = V_I4(&varresult);
925     VariantClear(&varresult);
926     return hr;
927 }
928
929 /* Test the various objects */
930
931 static void test_Database(IDispatch *pDatabase)
932 {
933     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 };
934     static WCHAR szThree[] = { 'T','h','r','e','e',0 };
935     static WCHAR szTwo[] = { 'T','w','o',0 };
936     static WCHAR szStringDataField[] = { 'S','t','r','i','n','g','D','a','t','a',',','F','i','e','l','d',0 };
937     IDispatch *pView = NULL;
938     HRESULT hr;
939
940     hr = Database_OpenView(pDatabase, szSql, &pView);
941     ok(SUCCEEDED(hr), "Database_OpenView failed, hresult 0x%08x\n", hr);
942     if (SUCCEEDED(hr))
943     {
944         IDispatch *pRecord = NULL;
945         WCHAR szString[MAX_PATH];
946
947         /* View::Execute */
948         hr = View_Execute(pView, NULL);
949         ok(SUCCEEDED(hr), "View_Execute failed, hresult 0x%08x\n", hr);
950
951         /* View::Fetch */
952         hr = View_Fetch(pView, &pRecord);
953         ok(SUCCEEDED(hr), "View_Fetch failed, hresult 0x%08x\n", hr);
954         ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
955         if (pRecord)
956         {
957             /* Record::StringDataGet */
958             memset(szString, 0, sizeof(szString));
959             hr = Record_StringDataGet(pRecord, 1, szString);
960             ok(SUCCEEDED(hr), "Record_StringDataGet failed, hresult 0x%08x\n", hr);
961             ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szThree);
962
963             /* Record::StringDataPut with incorrect index */
964             hr = Record_StringDataPut(pRecord, -1, szString);
965             ok(hr == DISP_E_EXCEPTION, "Record_StringDataPut failed, hresult 0x%08x\n", hr);
966             ok_exception(hr, szStringDataField);
967
968             IDispatch_Release(pRecord);
969         }
970
971         /* View::Fetch */
972         hr = View_Fetch(pView, &pRecord);
973         ok(SUCCEEDED(hr), "View_Fetch failed, hresult 0x%08x\n", hr);
974         ok(pRecord != NULL, "View_Fetch should not have returned NULL record\n");
975         if (pRecord)
976         {
977             /* Record::StringDataGet */
978             memset(szString, 0, sizeof(szString));
979             hr = Record_StringDataGet(pRecord, 1, szString);
980             ok(SUCCEEDED(hr), "Record_StringDataGet failed, hresult 0x%08x\n", hr);
981             ok_w2("Record_StringDataGet result was %s but expected %s\n", szString, szTwo);
982
983             IDispatch_Release(pRecord);
984         }
985
986         /* View::Fetch */
987         hr = View_Fetch(pView, &pRecord);
988         ok(SUCCEEDED(hr), "View_Fetch failed, hresult 0x%08x\n", hr);
989         ok(pRecord == NULL, "View_Fetch should have returned NULL record\n");
990         if (pRecord)
991             IDispatch_Release(pRecord);
992
993         /* View::Close */
994         hr = View_Close(pView);
995         ok(SUCCEEDED(hr), "View_Close failed, hresult 0x%08x\n", hr);
996
997         IDispatch_Release(pView);
998     }
999 }
1000
1001 static void test_Session(IDispatch *pSession)
1002 {
1003     static WCHAR szProductName[] = { 'P','r','o','d','u','c','t','N','a','m','e',0 };
1004     static WCHAR szMSITEST[] = { 'M','S','I','T','E','S','T',0 };
1005     static WCHAR szOne[] = { 'O','n','e',0 };
1006     static WCHAR szCostInitialize[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1007     static WCHAR szEmpty[] = { 0 };
1008     static WCHAR szEquals[] = { '=',0 };
1009     static WCHAR szPropertyName[] = { 'P','r','o','p','e','r','t','y',',','N','a','m','e',0 };
1010     WCHAR stringw[MAX_PATH];
1011     CHAR string[MAX_PATH];
1012     UINT len;
1013     BOOL bool;
1014     int myint;
1015     IDispatch *pDatabase = NULL, *pInst = NULL;
1016     HRESULT hr;
1017
1018     /* Session::Installer */
1019     hr = Session_Installer(pSession, &pInst);
1020     ok(SUCCEEDED(hr), "Session_Installer failed, hresult 0x%08x\n", hr);
1021     ok(pInst != NULL, "Session_Installer returned NULL IDispatch pointer\n");
1022     ok(pInst == pInstaller, "Session_Installer does not match Installer instance from CoCreateInstance\n");
1023
1024     /* Session::Property, get */
1025     memset(stringw, 0, sizeof(stringw));
1026     hr = Session_PropertyGet(pSession, szProductName, stringw);
1027     ok(SUCCEEDED(hr), "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1028     if (lstrcmpW(stringw, szMSITEST) != 0)
1029     {
1030         len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1031         ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1032         ok(0, "Property \"ProductName\" expected to be \"MSITEST\" but was \"%s\"\n", string);
1033     }
1034
1035     /* Session::Property, put */
1036     hr = Session_PropertyPut(pSession, szProductName, szProductName);
1037     ok(SUCCEEDED(hr), "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1038     memset(stringw, 0, sizeof(stringw));
1039     hr = Session_PropertyGet(pSession, szProductName, stringw);
1040     ok(SUCCEEDED(hr), "Session_PropertyGet failed, hresult 0x%08x\n", hr);
1041     if (lstrcmpW(stringw, szProductName) != 0)
1042     {
1043         len = WideCharToMultiByte(CP_ACP, 0, stringw, -1, string, MAX_PATH, NULL, NULL);
1044         ok(len, "WideCharToMultiByteChar returned error %d\n", GetLastError());
1045         ok(0, "Property \"ProductName\" expected to be \"ProductName\" but was \"%s\"\n", string);
1046     }
1047
1048     /* Try putting a property using empty property identifier */
1049     hr = Session_PropertyPut(pSession, szEmpty, szProductName);
1050     ok(hr == DISP_E_EXCEPTION, "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1051     ok_exception(hr, szPropertyName);
1052
1053     /* Try putting a property using illegal property identifier */
1054     hr = Session_PropertyPut(pSession, szEquals, szProductName);
1055     ok(SUCCEEDED(hr), "Session_PropertyPut failed, hresult 0x%08x\n", hr);
1056
1057     /* Session::Language, get */
1058     hr = Session_LanguageGet(pSession, &len);
1059     ok(SUCCEEDED(hr), "Session_LanguageGet failed, hresult 0x%08x\n", hr);
1060     /* Not sure how to check the language is correct */
1061
1062     /* Session::Mode, get */
1063     hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1064     ok(SUCCEEDED(hr), "Session_ModeGet failed, hresult 0x%08x\n", hr);
1065     todo_wine ok(!bool, "Reboot at end session mode is %d\n", bool);
1066
1067     /* Session::Mode, put */
1068     hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, TRUE);
1069     todo_wine ok(SUCCEEDED(hr), "Session_ModePut failed, hresult 0x%08x\n", hr);
1070     hr = Session_ModeGet(pSession, MSIRUNMODE_REBOOTATEND, &bool);
1071     ok(SUCCEEDED(hr), "Session_ModeGet failed, hresult 0x%08x\n", hr);
1072     ok(bool, "Reboot at end session mode is %d, expected 1\n", bool);
1073     hr = Session_ModePut(pSession, MSIRUNMODE_REBOOTATEND, FALSE);  /* set it again so we don't reboot */
1074     todo_wine ok(SUCCEEDED(hr), "Session_ModePut failed, hresult 0x%08x\n", hr);
1075
1076     /* Session::Database, get */
1077     hr = Session_Database(pSession, &pDatabase);
1078     ok(SUCCEEDED(hr), "Session_Database failed, hresult 0x%08x\n", hr);
1079     if (SUCCEEDED(hr))
1080     {
1081         test_Database(pDatabase);
1082         IDispatch_Release(pDatabase);
1083     }
1084
1085     /* Session::DoAction(CostInitialize) must occur before the next statements */
1086     hr = Session_DoAction(pSession, szCostInitialize, &myint);
1087     ok(SUCCEEDED(hr), "Session_DoAction failed, hresult 0x%08x\n", hr);
1088     ok(myint == IDOK, "DoAction(CostInitialize) returned %d, %d expected\n", myint, IDOK);
1089
1090     /* Session::SetInstallLevel */
1091     hr = Session_SetInstallLevel(pSession, INSTALLLEVEL_MINIMUM);
1092     ok(SUCCEEDED(hr), "Session_SetInstallLevel failed, hresult 0x%08x\n", hr);
1093
1094     /* Session::FeatureCurrentState, get */
1095     hr = Session_FeatureCurrentState(pSession, szOne, &myint);
1096     ok(SUCCEEDED(hr), "Session_FeatureCurrentState failed, hresult 0x%08x\n", hr);
1097     ok(myint == INSTALLSTATE_UNKNOWN, "Feature current state was %d but expected %d\n", myint, INSTALLSTATE_UNKNOWN);
1098
1099     /* Session::FeatureRequestState, put */
1100     hr = Session_FeatureRequestStatePut(pSession, szOne, INSTALLSTATE_ADVERTISED);
1101     ok(SUCCEEDED(hr), "Session_FeatureRequestStatePut failed, hresult 0x%08x\n", hr);
1102     hr = Session_FeatureRequestStateGet(pSession, szOne, &myint);
1103     ok(SUCCEEDED(hr), "Session_FeatureRequestStateGet failed, hresult 0x%08x\n", hr);
1104     ok(myint == INSTALLSTATE_ADVERTISED, "Feature request state was %d but expected %d\n", myint, INSTALLSTATE_ADVERTISED);
1105 }
1106
1107 /* delete key and all its subkeys */
1108 static DWORD delete_key( HKEY hkey )
1109 {
1110     char name[MAX_PATH];
1111     DWORD ret;
1112
1113     while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
1114     {
1115         HKEY tmp;
1116         if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
1117         {
1118             ret = delete_key( tmp );
1119             RegCloseKey( tmp );
1120         }
1121         if (ret) break;
1122     }
1123     if (ret != ERROR_NO_MORE_ITEMS) return ret;
1124     RegDeleteKeyA( hkey, "" );
1125     return 0;
1126 }
1127
1128 static void test_Installer_RegistryValue(void)
1129 {
1130     static const DWORD qw[2] = { 0x12345678, 0x87654321 };
1131     static const WCHAR szKey[] = { 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t',0 };
1132     static const WCHAR szOne[] = { 'O','n','e',0 };
1133     static const WCHAR szTwo[] = { 'T','w','o',0 };
1134     static const WCHAR szThree[] = { 'T','h','r','e','e',0 };
1135     static const WCHAR szREG_BINARY[] = { '(','R','E','G','_','B','I','N','A','R','Y',')',0 };
1136     static const WCHAR szFour[] = { 'F','o','u','r',0 };
1137     static const WCHAR szExpand[] = { '%','M','S','I','T','E','S','T','%',0 };
1138     static const WCHAR szFive[] = { 'F','i','v','e',0,'H','i',0,0 };
1139     static const WCHAR szFiveHi[] = { 'F','i','v','e','\n','H','i',0 };
1140     static const WCHAR szSix[] = { 'S','i','x',0 };
1141     static const WCHAR szREG_[] = { '(','R','E','G','_',']',0 };
1142     static const WCHAR szSeven[] = { 'S','e','v','e','n',0 };
1143     static const WCHAR szEight[] = { 'E','i','g','h','t',0 };
1144     static const WCHAR szBlank[] = { 0 };
1145     VARIANT varresult;
1146     VARIANTARG vararg;
1147     WCHAR szString[MAX_PATH];
1148     HKEY hkey, hkey_sub;
1149     HRESULT hr;
1150     BOOL bRet;
1151
1152     /* Delete keys */
1153     if (!RegOpenKeyW( HKEY_CURRENT_USER, szKey, &hkey )) delete_key( hkey );
1154
1155     /* Does our key exist? Shouldn't; check with all three possible value parameter types */
1156     todo_wine {
1157         hr = Installer_RegistryValueE(HKEY_CURRENT_USER, szKey, &bRet);
1158         ok(SUCCEEDED(hr), "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
1159         if (SUCCEEDED(hr))
1160             ok(!bRet, "Registry key expected to not exist, but Installer_RegistryValue claims it does\n");
1161
1162         memset(szString, 0, sizeof(szString));
1163         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, NULL, szString);
1164         ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1165
1166         memset(szString, 0, sizeof(szString));
1167         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 0, szString, VT_BSTR);
1168         ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1169     }
1170
1171     /* Create key */
1172     ok(!RegCreateKeyW( HKEY_CURRENT_USER, szKey, &hkey ), "RegCreateKeyW failed\n");
1173
1174     ok(!RegSetValueExW(hkey,szOne,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
1175         "RegSetValueExW failed\n");
1176     ok(!RegSetValueExW(hkey,szTwo,0,REG_DWORD, (const BYTE *)qw, 4),
1177         "RegSetValueExW failed\n");
1178     ok(!RegSetValueExW(hkey,szThree,0,REG_BINARY, (const BYTE *)qw, 4),
1179         "RegSetValueExW failed\n");
1180     ok(SetEnvironmentVariableA("MSITEST", "Four"), "SetEnvironmentVariableA failed %d\n", GetLastError());
1181     ok(!RegSetValueExW(hkey,szFour,0,REG_EXPAND_SZ, (const BYTE *)szExpand, sizeof(szExpand)),
1182         "RegSetValueExW failed\n");
1183     ok(!RegSetValueExW(hkey,szFive,0,REG_MULTI_SZ, (const BYTE *)szFive, sizeof(szFive)),
1184         "RegSetValueExW failed\n");
1185     ok(!RegSetValueExW(hkey,szSix,0,REG_QWORD, (const BYTE *)qw, 8),
1186         "RegSetValueExW failed\n");
1187     ok(!RegSetValueExW(hkey,szSeven,0,REG_NONE, (const BYTE *)NULL, 0),
1188         "RegSetValueExW failed\n");
1189
1190     ok(!RegSetValueExW(hkey,NULL,0,REG_SZ, (const BYTE *)szOne, sizeof(szOne)),
1191         "RegSetValueExW failed\n");
1192
1193     ok(!RegCreateKeyW( hkey, szEight, &hkey_sub ), "RegCreateKeyW failed\n");
1194
1195     todo_wine {
1196         /* Does our key exist? It should, and make sure we retrieve the correct default value */
1197         bRet = FALSE;
1198         hr = Installer_RegistryValueE(HKEY_CURRENT_USER, szKey, &bRet);
1199         ok(SUCCEEDED(hr), "Installer_RegistryValueE failed, hresult 0x%08x\n", hr);
1200         if (SUCCEEDED(hr))
1201             ok(bRet, "Registry key expected to exist, but Installer_RegistryValue claims it does not\n");
1202
1203         memset(szString, 0, sizeof(szString));
1204         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, NULL, szString);
1205         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1206         ok_w2("Default registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
1207
1208         /* Ask for the value of a non-existent key */
1209         memset(szString, 0, sizeof(szString));
1210         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szExpand, szString);
1211         ok(hr == DISP_E_BADINDEX, "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1212
1213         /* Get values of keys */
1214         memset(szString, 0, sizeof(szString));
1215         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szOne, szString);
1216         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1217         ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szOne);
1218
1219         VariantInit(&vararg);
1220         V_VT(&vararg) = VT_BSTR;
1221         V_BSTR(&vararg) = SysAllocString(szTwo);
1222         hr = Installer_RegistryValue(HKEY_CURRENT_USER, szKey, vararg, &varresult, VT_I4);
1223         ok(SUCCEEDED(hr), "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
1224         ok(V_I4(&varresult) == 305419896, "Registry value %d does not match expected value\n", V_I4(&varresult));
1225         VariantClear(&varresult);
1226
1227         memset(szString, 0, sizeof(szString));
1228         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szThree, szString);
1229         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1230         ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_BINARY);
1231
1232         memset(szString, 0, sizeof(szString));
1233         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szFour, szString);
1234         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1235         ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFour);
1236
1237         memset(szString, 0, sizeof(szString));
1238         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szFive, szString);
1239         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1240         ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szFiveHi);
1241
1242         memset(szString, 0, sizeof(szString));
1243         hr = Installer_RegistryValueW(HKEY_CURRENT_USER, szKey, szSix, szString);
1244         ok(SUCCEEDED(hr), "Installer_RegistryValueW failed, hresult 0x%08x\n", hr);
1245         ok_w2("Registry value \"%s\" does not match expected \"%s\"\n", szString, szREG_);
1246
1247         VariantInit(&vararg);
1248         V_VT(&vararg) = VT_BSTR;
1249         V_BSTR(&vararg) = SysAllocString(szSeven);
1250         hr = Installer_RegistryValue(HKEY_CURRENT_USER, szKey, vararg, &varresult, VT_EMPTY);
1251         ok(SUCCEEDED(hr), "Installer_RegistryValue failed, hresult 0x%08x\n", hr);
1252
1253         /* Get string class name for the key */
1254         memset(szString, 0, sizeof(szString));
1255         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 0, szString, VT_BSTR);
1256         ok(SUCCEEDED(hr), "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1257         ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szBlank);
1258
1259         /* Get name of a value by positive number (RegEnumValue like), valid index */
1260         memset(szString, 0, sizeof(szString));
1261         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 2, szString, VT_BSTR);
1262         ok(SUCCEEDED(hr), "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1263         ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szTwo);
1264
1265         /* Get name of a value by positive number (RegEnumValue like), invalid index */
1266         memset(szString, 0, sizeof(szString));
1267         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, 10, szString, VT_EMPTY);
1268         ok(SUCCEEDED(hr), "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1269
1270         /* Get name of a subkey by negative number (RegEnumValue like), valid index */
1271         memset(szString, 0, sizeof(szString));
1272         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, -1, szString, VT_BSTR);
1273         ok(SUCCEEDED(hr), "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1274         ok_w2("Registry name \"%s\" does not match expected \"%s\"\n", szString, szEight);
1275
1276         /* Get name of a subkey by negative number (RegEnumValue like), invalid index */
1277         memset(szString, 0, sizeof(szString));
1278         hr = Installer_RegistryValueI(HKEY_CURRENT_USER, szKey, -10, szString, VT_EMPTY);
1279         ok(SUCCEEDED(hr), "Installer_RegistryValueI failed, hresult 0x%08x\n", hr);
1280     }
1281
1282     /* clean up */
1283     delete_key(hkey);
1284 }
1285
1286 static void test_Installer(void)
1287 {
1288     static 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 };
1289     static WCHAR szBackslash[] = { '\\',0 };
1290     WCHAR szPath[MAX_PATH];
1291     HRESULT hr;
1292     UINT len;
1293     IDispatch *pSession = NULL, *pRecord = NULL, *pStringList = NULL;
1294     int iState;
1295
1296     if (!pInstaller) return;
1297
1298     /* Installer::CreateRecord */
1299     todo_wine {
1300         hr = Installer_CreateRecord(1, &pRecord);
1301         ok(SUCCEEDED(hr), "Installer_CreateRecord failed, hresult 0x%08x\n", hr);
1302         ok(pRecord != NULL, "Installer_CreateRecord should not have returned NULL record\n");
1303     }
1304     if (pRecord)
1305     {
1306         int iFieldCount = 0;
1307
1308         /* Record::FieldCountGet */
1309         hr = Record_FieldCountGet(pRecord, &iFieldCount);
1310         ok(SUCCEEDED(hr), "Record_FiledCountGet failed, hresult 0x%08x\n", hr);
1311         ok(iFieldCount == 1, "Record_FieldCountGet result was %d but expected 1\n", iFieldCount);
1312
1313         IDispatch_Release(pRecord);
1314     }
1315
1316     /* Prepare package */
1317     create_database(msifile, tables, sizeof(tables) / sizeof(msi_table));
1318
1319     len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, CURR_DIR, -1, szPath, MAX_PATH);
1320     ok(len, "MultiByteToWideChar returned error %d\n", GetLastError());
1321     if (!len) return;
1322
1323     lstrcatW(szPath, szBackslash);
1324     lstrcatW(szPath, szMsifile);
1325
1326     /* Installer::OpenPackage */
1327     hr = Installer_OpenPackage(szPath, 0, &pSession);
1328     ok(SUCCEEDED(hr), "Installer_OpenPackage failed, hresult 0x%08x\n", hr);
1329     if (SUCCEEDED(hr))
1330     {
1331         test_Session(pSession);
1332         IDispatch_Release(pSession);
1333     }
1334
1335     DeleteFileA(msifile);
1336
1337     /* Installer::RegistryValue */
1338     test_Installer_RegistryValue();
1339
1340     /* Installer::Products */
1341     hr = Installer_Products(&pStringList);
1342     ok(SUCCEEDED(hr), "Installer_Products failed, hresult 0x%08x\n", hr);
1343     if (SUCCEEDED(hr))
1344     {
1345         int iCount = 0, idx;
1346
1347         /* StringList::Count */
1348         hr = StringList_Count(pStringList, &iCount);
1349         ok(SUCCEEDED(hr), "StringList_Count failed, hresult 0x%08x\n", hr);
1350
1351         for (idx=0; idx<iCount; idx++)
1352         {
1353             /* StringList::Item */
1354             memset(szPath, 0, sizeof(szPath));
1355             hr = StringList_Item(pStringList, idx, szPath);
1356             ok(SUCCEEDED(hr), "StringList_Item failed (idx %d, count %d), hresult 0x%08x\n", idx, iCount, hr);
1357
1358             if (SUCCEEDED(hr))
1359             {
1360                 /* Installer::ProductState */
1361                 hr = Installer_ProductState(szPath, &iState);
1362                 ok(SUCCEEDED(hr), "Installer_ProductState failed, hresult 0x%08x\n", hr);
1363                 if (SUCCEEDED(hr))
1364                     ok(iState == INSTALLSTATE_DEFAULT || iState == INSTALLSTATE_ADVERTISED, "Installer_ProductState returned %d, expected %d or %d", iState, INSTALLSTATE_DEFAULT, INSTALLSTATE_ADVERTISED);
1365             }
1366         }
1367
1368         /* StringList::Item using an invalid index */
1369         memset(szPath, 0, sizeof(szPath));
1370         hr = StringList_Item(pStringList, iCount, szPath);
1371         ok(hr == DISP_E_BADINDEX, "StringList_Item for an invalid index did not return DISP_E_BADINDEX, hresult 0x%08x\n", hr);
1372
1373         IDispatch_Release(pStringList);
1374     }
1375
1376     /* Installer::ProductState for our product code, which should not be installed */
1377     hr = Installer_ProductState(szProductCode, &iState);
1378     ok(SUCCEEDED(hr), "Installer_ProductState failed, hresult 0x%08x\n", hr);
1379     if (SUCCEEDED(hr))
1380         ok(iState == INSTALLSTATE_UNKNOWN, "Installer_ProductState returned %d, expected %d", iState, INSTALLSTATE_UNKNOWN);
1381
1382     /* Installer::Version */
1383     todo_wine {
1384         memset(szPath, 0, sizeof(szPath));
1385         hr = Installer_VersionGet(szPath);
1386         ok(SUCCEEDED(hr), "Installer_VersionGet failed, hresult 0x%08x\n", hr);
1387     }
1388 }
1389
1390 START_TEST(automation)
1391 {
1392     DWORD len;
1393     char temp_path[MAX_PATH], prev_path[MAX_PATH];
1394     HRESULT hr;
1395     CLSID clsid;
1396     IUnknown *pUnk;
1397
1398     GetCurrentDirectoryA(MAX_PATH, prev_path);
1399     GetTempPath(MAX_PATH, temp_path);
1400     SetCurrentDirectoryA(temp_path);
1401
1402     lstrcpyA(CURR_DIR, temp_path);
1403     len = lstrlenA(CURR_DIR);
1404
1405     if(len && (CURR_DIR[len - 1] == '\\'))
1406         CURR_DIR[len - 1] = 0;
1407
1408     hr = OleInitialize(NULL);
1409     ok (SUCCEEDED(hr), "OleInitialize returned 0x%08x\n", hr);
1410     hr = CLSIDFromProgID(szProgId, &clsid);
1411     ok (SUCCEEDED(hr), "CLSIDFromProgID returned 0x%08x\n", hr);
1412     hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk);
1413     ok(SUCCEEDED(hr), "CoCreateInstance returned 0x%08x\n", hr);
1414
1415     if (pUnk)
1416     {
1417         hr = IUnknown_QueryInterface(pUnk, &IID_IDispatch, (void **)&pInstaller);
1418         ok (SUCCEEDED(hr), "IUnknown::QueryInterface returned 0x%08x\n", hr);
1419
1420         test_dispid();
1421         test_dispatch();
1422         test_Installer();
1423
1424         hr = IUnknown_Release(pUnk);
1425         ok (SUCCEEDED(hr), "IUnknown::Release returned 0x%08x\n", hr);
1426     }
1427
1428     OleUninitialize();
1429
1430     SetCurrentDirectoryA(prev_path);
1431 }