ReactOS 0.4.16-dev-250-g3ecd236
msi.c
Go to the documentation of this file.
1/*
2 * tests for Microsoft Installer functionality
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define _WIN32_MSI 300
22#define COBJMACROS
23
24#include <stdio.h>
25#include <windows.h>
26#include <msi.h>
27#include <msiquery.h>
28#include <msidefs.h>
29#include <sddl.h>
30#include <fci.h>
31#include <shellapi.h>
32#include <objidl.h>
33
34#include "wine/test.h"
35#include "utils.h"
36
37#define GUID_SIZE (39)
38#define SQUASHED_GUID_SIZE (33)
39
41static const char msifile[] = "winetest.msi";
42static const WCHAR msifileW[] = L"winetest.msi";
43
44/* cabinet definitions */
45
46/* make the max size large so there is only one cab file */
47#define MEDIA_SIZE 0x7FFFFFFF
48#define FOLDER_THRESHOLD 900000
49
51{
52 WCHAR dbW[MAX_PATH], cabinetW[MAX_PATH];
53 IStorage *stg;
54 IStream *stm;
55 HRESULT hr;
57
58 MultiByteToWideChar(CP_ACP, 0, db, -1, dbW, MAX_PATH);
60 if (FAILED(hr))
61 return FALSE;
62
63 MultiByteToWideChar(CP_ACP, 0, cabinet, -1, cabinetW, MAX_PATH);
64 hr = IStorage_CreateStream(stg, cabinetW, STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
65 if (FAILED(hr))
66 {
67 IStorage_Release(stg);
68 return FALSE;
69 }
70
73 {
75 char buffer[1024];
76 if (ReadFile(handle, buffer, sizeof(buffer), &count, NULL))
77 IStream_Write(stm, buffer, count, &count);
79 }
80
81 IStream_Release(stm);
82 IStorage_Release(stg);
83
84 return TRUE;
85}
86
87/* msi database data */
88
89static const char directory_dat[] =
90 "Directory\tDirectory_Parent\tDefaultDir\n"
91 "s72\tS72\tl255\n"
92 "Directory\tDirectory\n"
93 "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
94 "ProgramFilesFolder\tTARGETDIR\t.\n"
95 "TARGETDIR\t\tSourceDir";
96
97static const char component_dat[] =
98 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
99 "s72\tS38\ts72\ti2\tS255\tS72\n"
100 "Component\tComponent\n"
101 "One\t{8F5BAEEF-DD92-40AC-9397-BE3CF9F97C81}\tMSITESTDIR\t2\tNOT REINSTALL\tone.txt\n";
102
103static const char feature_dat[] =
104 "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
105 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
106 "Feature\tFeature\n"
107 "One\t\tOne\tOne\t1\t3\tMSITESTDIR\t0\n"
108 "Two\t\t\t\t2\t1\tTARGETDIR\t0\n";
109
110static const char feature_comp_dat[] =
111 "Feature_\tComponent_\n"
112 "s38\ts72\n"
113 "FeatureComponents\tFeature_\tComponent_\n"
114 "One\tOne\n";
115
116static const char file_dat[] =
117 "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
118 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
119 "File\tFile\n"
120 "one.txt\tOne\tone.txt\t1000\t\t\t0\t1\n";
121
122static const char install_exec_seq_dat[] =
123 "Action\tCondition\tSequence\n"
124 "s72\tS255\tI2\n"
125 "InstallExecuteSequence\tAction\n"
126 "ValidateProductID\t\t700\n"
127 "CostInitialize\t\t800\n"
128 "FileCost\t\t900\n"
129 "CostFinalize\t\t1000\n"
130 "InstallValidate\t\t1400\n"
131 "InstallInitialize\t\t1500\n"
132 "ProcessComponents\t\t1600\n"
133 "UnpublishFeatures\t\t1800\n"
134 "RemoveFiles\t\t3500\n"
135 "InstallFiles\t\t4000\n"
136 "RegisterProduct\t\t6100\n"
137 "PublishFeatures\t\t6300\n"
138 "PublishProduct\t\t6400\n"
139 "InstallFinalize\t\t6600";
140
141static const char media_dat[] =
142 "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
143 "i2\ti4\tL64\tS255\tS32\tS72\n"
144 "Media\tDiskId\n"
145 "1\t1\t\t\tDISK1\t\n";
146
147static const char property_dat[] =
148 "Property\tValue\n"
149 "s72\tl0\n"
150 "Property\tProperty\n"
151 "INSTALLLEVEL\t3\n"
152 "Manufacturer\tWine\n"
153 "ProductCode\t{38847338-1BBC-4104-81AC-2FAAC7ECDDCD}\n"
154 "ProductName\tMSITEST\n"
155 "ProductVersion\t1.1.1\n"
156 "UpgradeCode\t{9574448F-9B86-4E07-B6F6-8D199DA12127}\n"
157 "MSIFASTINSTALL\t1\n";
158
159static const char ci2_property_dat[] =
160 "Property\tValue\n"
161 "s72\tl0\n"
162 "Property\tProperty\n"
163 "INSTALLLEVEL\t3\n"
164 "Manufacturer\tWine\n"
165 "ProductCode\t{FF4AFE9C-6AC2-44F9-A060-9EA6BD16C75E}\n"
166 "ProductName\tMSITEST2\n"
167 "ProductVersion\t1.1.1\n"
168 "UpgradeCode\t{6B60C3CA-B8CA-4FB7-A395-092D98FF5D2A}\n"
169 "MSIFASTINSTALL\t1\n";
170
171static const char mcp_component_dat[] =
172 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
173 "s72\tS38\ts72\ti2\tS255\tS72\n"
174 "Component\tComponent\n"
175 "hydrogen\t{C844BD1E-1907-4C00-8BC9-150BD70DF0A1}\tMSITESTDIR\t2\t\thydrogen\n"
176 "helium\t{5AD3C142-CEF8-490D-B569-784D80670685}\tMSITESTDIR\t2\t\thelium\n"
177 "lithium\t{4AF28FFC-71C7-4307-BDE4-B77C5338F56F}\tMSITESTDIR\t2\tPROPVAR=42\tlithium\n";
178
179static const char mcp_feature_dat[] =
180 "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
181 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
182 "Feature\tFeature\n"
183 "hydroxyl\t\thydroxyl\thydroxyl\t2\t1\tTARGETDIR\t0\n"
184 "heliox\t\theliox\theliox\t2\t5\tTARGETDIR\t0\n"
185 "lithia\t\tlithia\tlithia\t2\t10\tTARGETDIR\t0";
186
187static const char mcp_feature_comp_dat[] =
188 "Feature_\tComponent_\n"
189 "s38\ts72\n"
190 "FeatureComponents\tFeature_\tComponent_\n"
191 "hydroxyl\thydrogen\n"
192 "heliox\thelium\n"
193 "lithia\tlithium";
194
195static const char mcp_file_dat[] =
196 "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
197 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
198 "File\tFile\n"
199 "hydrogen\thydrogen\thydrogen\t0\t\t\t8192\t1\n"
200 "helium\thelium\thelium\t0\t\t\t8192\t1\n"
201 "lithium\tlithium\tlithium\t0\t\t\t8192\t1";
202
203static const char lus_component_dat[] =
204 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
205 "s72\tS38\ts72\ti2\tS255\tS72\n"
206 "Component\tComponent\n"
207 "maximus\t{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}\tMSITESTDIR\t0\tUILevel=5\tmaximus\n";
208
209static const char lus_feature_dat[] =
210 "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
211 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
212 "Feature\tFeature\n"
213 "feature\t\tFeature\tFeature\t2\t1\tTARGETDIR\t0\n"
214 "montecristo\t\tFeature\tFeature\t2\t1\tTARGETDIR\t0";
215
216static const char lus_file_dat[] =
217 "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
218 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
219 "File\tFile\n"
220 "maximus\tmaximus\tmaximus\t500\t\t\t8192\t1";
221
222static const char lus_feature_comp_dat[] =
223 "Feature_\tComponent_\n"
224 "s38\ts72\n"
225 "FeatureComponents\tFeature_\tComponent_\n"
226 "feature\tmaximus\n"
227 "montecristo\tmaximus";
228
229static const char lus_install_exec_seq_dat[] =
230 "Action\tCondition\tSequence\n"
231 "s72\tS255\tI2\n"
232 "InstallExecuteSequence\tAction\n"
233 "ValidateProductID\t\t700\n"
234 "CostInitialize\t\t800\n"
235 "FileCost\t\t900\n"
236 "CostFinalize\t\t1000\n"
237 "InstallValidate\t\t1400\n"
238 "InstallInitialize\t\t1500\n"
239 "ProcessComponents\tPROCESS_COMPONENTS=1 Or FULL=1\t1600\n"
240 "UnpublishFeatures\tUNPUBLISH_FEATURES=1 Or FULL=1\t1800\n"
241 "RemoveFiles\t\t3500\n"
242 "InstallFiles\t\t4000\n"
243 "RegisterUser\tREGISTER_USER=1 Or FULL=1\t6000\n"
244 "RegisterProduct\tREGISTER_PRODUCT=1 Or FULL=1\t6100\n"
245 "PublishFeatures\tPUBLISH_FEATURES=1 Or FULL=1\t6300\n"
246 "PublishProduct\tPUBLISH_PRODUCT=1 Or FULL=1\t6400\n"
247 "InstallFinalize\t\t6600";
248
249static const char lus0_media_dat[] =
250 "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
251 "i2\ti4\tL64\tS255\tS32\tS72\n"
252 "Media\tDiskId\n"
253 "1\t1\t\t\tDISK1\t\n";
254
255static const char lus1_media_dat[] =
256 "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
257 "i2\ti4\tL64\tS255\tS32\tS72\n"
258 "Media\tDiskId\n"
259 "1\t1\t\ttest1.cab\tDISK1\t\n";
260
261static const char lus2_media_dat[] =
262 "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n"
263 "i2\ti4\tL64\tS255\tS32\tS72\n"
264 "Media\tDiskId\n"
265 "1\t1\t\t#test1.cab\tDISK1\t\n";
266
267static const char spf_custom_action_dat[] =
268 "Action\tType\tSource\tTarget\tISComments\n"
269 "s72\ti2\tS64\tS0\tS255\n"
270 "CustomAction\tAction\n"
271 "SetFolderProp\t51\tMSITESTDIR\t[ProgramFilesFolder]\\msitest\\added\t\n"
272 "SetFolderProp2\t51\tMSITESTDIR\t[ProgramFilesFolder]\\msitest\\added\\added2\t\n";
273
274static const char spf_install_exec_seq_dat[] =
275 "Action\tCondition\tSequence\n"
276 "s72\tS255\tI2\n"
277 "InstallExecuteSequence\tAction\n"
278 "CostInitialize\t\t800\n"
279 "FileCost\t\t900\n"
280 "SetFolderProp\t\t950\n"
281 "SetFolderProp2\t\t960\n"
282 "CostFinalize\t\t1000\n"
283 "InstallValidate\t\t1400\n"
284 "InstallInitialize\t\t1500\n"
285 "InstallFiles\t\t4000\n"
286 "InstallServices\t\t5000\n"
287 "InstallFinalize\t\t6600\n";
288
289static const char spf_install_ui_seq_dat[] =
290 "Action\tCondition\tSequence\n"
291 "s72\tS255\tI2\n"
292 "InstallUISequence\tAction\n"
293 "CostInitialize\t\t800\n"
294 "FileCost\t\t900\n"
295 "CostFinalize\t\t1000\n"
296 "ExecuteAction\t\t1100\n";
297
298static const char spf_directory_dat[] =
299 "Directory\tDirectory_Parent\tDefaultDir\n"
300 "s72\tS72\tl255\n"
301 "Directory\tDirectory\n"
302 "PARENTDIR\tTARGETDIR\tparent\n"
303 "CHILDDIR\tPARENTDIR\tchild\n"
304 "MSITESTDIR\tProgramFilesFolder\tmsitest\n"
305 "ProgramFilesFolder\tTARGETDIR\t.\n"
306 "TARGETDIR\t\tSourceDir";
307
308static const char spf_component_dat[] =
309 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
310 "s72\tS38\ts72\ti2\tS255\tS72\n"
311 "Component\tComponent\n"
312 "maximus\t{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}\tMSITESTDIR\t0\tUILevel=5\tmaximus\n";
313
314static const char spf2_install_exec_seq_dat[] =
315 "Action\tCondition\tSequence\n"
316 "s72\tS255\tI2\n"
317 "InstallExecuteSequence\tAction\n"
318 "CostInitialize\t\t800\n"
319 "FileCost\t\t900\n"
320 "FormatParentFolderCheck\t\t910\n"
321 "FormatChildFolderCheck\t\t920\n"
322 "CheckParentFolder\tNOT PARENTDIR=PARENTDIRCHECK\t930\n"
323 "CheckChildFolder\tNOT CHILDDIR=CHILDDIRCHECK\t940\n"
324 "FormatParentFolderCheck2\t\t945\n"
325 "SetParentFolder\t\t950\n"
326 "CheckParentFolder2\tNOT PARENTDIR=PARENTDIRCHECK\t960\n"
327 "CheckChildFolder2\tNOT CHILDDIR=CHILDDIRCHECK\t970\n"
328 "CostFinalize\t\t1000\n"
329 "FormatParentFolderCheck3\t\t1005\n"
330 "CheckParentFolder3\tNOT PARENTDIR=PARENTDIRCHECK\t1010\n"
331 "CheckChildFolder3\tNOT CHILDDIR=CHILDDIRCHECK\t1020\n"
332 "InstallValidate\t\t1400\n"
333 "InstallInitialize\t\t1500\n"
334 "InstallFiles\t\t4000\n"
335 "CreateShortcuts\t\t4100\n"
336 "InstallFinalize\t\t6600\n";
337
338static const char spf2_custom_action_dat[] =
339 "Action\tType\tSource\tTarget\tISComments\n"
340 "s72\ti2\tS64\tS0\tS255\n"
341 "CustomAction\tAction\n"
342 "FormatParentFolderCheck\t51\tPARENTDIRCHECK\t[TARGETDIR]parent\\\t\n"
343 "FormatChildFolderCheck\t51\tCHILDDIRCHECK\t[TARGETDIR]parent\\child\\\t\n"
344 "CheckParentFolder\t19\tPARENTDIR\tparent prop wrong before set: [PARENTDIR]\t\n"
345 "CheckChildFolder\t19\tCHILDDIR\tchild prop wrong before set: [CHILDDIR]\t\n"
346 "FormatParentFolderCheck2\t51\tPARENTDIRCHECK\t[ProgramFilesFolder]msitest\\parent\t\n"
347 "SetParentFolder\t51\tPARENTDIR\t[PARENTDIRCHECK]\t\n"
348 "CheckParentFolder2\t19\tPARENTDIR\tparent prop wrong after set: [PARENTDIR]\t\n"
349 "CheckChildFolder2\t19\tCHILDDIR\tchild prop wrong after set: [CHILDDIR]\t\n"
350 "FormatParentFolderCheck3\t51\tPARENTDIRCHECK\t[ProgramFilesFolder]msitest\\parent\\\t\n"
351 "CheckParentFolder3\t19\tPARENTDIR\tparent prop wrong after CostFinalize: [PARENTDIR]\t\n"
352 "CheckChildFolder3\t19\tCHILDDIR\tchild prop wrong after CostFinalize: [CHILDDIR]\t\n";
353
354static const char shortcut_dat[] =
355 "Shortcut\tDirectory_\tName\tComponent_\tTarget\tArguments\tDescription\tHotkey\tIcon_\tIconIndex\tShowCmd\tWkDir\n"
356 "s72\ts72\tl128\ts72\ts72\tS255\tL255\tI2\tS72\tI2\tI2\tS72\n"
357 "Shortcut\tShortcut\n"
358 "Shortcut\tCHILDDIR\tShortcut\tmaximus\t[#maximus]\t\tShortcut\t\t\t\t\tMSITESTDIR\n";
359
360static const char sd_file_dat[] =
361 "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
362 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
363 "File\tFile\n"
364 "sourcedir.txt\tsourcedir\tsourcedir.txt\t1000\t\t\t8192\t1\n";
365
366static const char sd_feature_dat[] =
367 "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n"
368 "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n"
369 "Feature\tFeature\n"
370 "sourcedir\t\t\tsourcedir feature\t1\t2\tMSITESTDIR\t0\n";
371
372static const char sd_feature_comp_dat[] =
373 "Feature_\tComponent_\n"
374 "s38\ts72\n"
375 "FeatureComponents\tFeature_\tComponent_\n"
376 "sourcedir\tsourcedir\n";
377
378static const char sd_component_dat[] =
379 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
380 "s72\tS38\ts72\ti2\tS255\tS72\n"
381 "Component\tComponent\n"
382 "sourcedir\t{DD422F92-3ED8-49B5-A0B7-F266F98357DF}\tMSITESTDIR\t0\t\tsourcedir.txt\n";
383
384static const char sd_install_ui_seq_dat[] =
385 "Action\tCondition\tSequence\n"
386 "s72\tS255\tI2\n"
387 "InstallUISequence\tAction\n"
388 "TestSourceDirProp1\tnot SourceDir and not SOURCEDIR and not Installed\t99\n"
389 "AppSearch\t\t100\n"
390 "TestSourceDirProp2\tnot SourceDir and not SOURCEDIR and not Installed\t101\n"
391 "LaunchConditions\tnot Installed \t110\n"
392 "TestSourceDirProp3\tnot SourceDir and not SOURCEDIR and not Installed\t111\n"
393 "FindRelatedProducts\t\t120\n"
394 "TestSourceDirProp4\tnot SourceDir and not SOURCEDIR and not Installed\t121\n"
395 "CCPSearch\t\t130\n"
396 "TestSourceDirProp5\tnot SourceDir and not SOURCEDIR and not Installed\t131\n"
397 "RMCCPSearch\t\t140\n"
398 "TestSourceDirProp6\tnot SourceDir and not SOURCEDIR and not Installed\t141\n"
399 "ValidateProductID\t\t150\n"
400 "TestSourceDirProp7\tnot SourceDir and not SOURCEDIR and not Installed\t151\n"
401 "CostInitialize\t\t800\n"
402 "TestSourceDirProp8\tnot SourceDir and not SOURCEDIR and not Installed\t801\n"
403 "FileCost\t\t900\n"
404 "TestSourceDirProp9\tnot SourceDir and not SOURCEDIR and not Installed\t901\n"
405 "IsolateComponents\t\t1000\n"
406 "TestSourceDirProp10\tnot SourceDir and not SOURCEDIR and not Installed\t1001\n"
407 "CostFinalize\t\t1100\n"
408 "TestSourceDirProp11\tnot SourceDir and not SOURCEDIR and not Installed\t1101\n"
409 "MigrateFeatureStates\t\t1200\n"
410 "TestSourceDirProp12\tnot SourceDir and not SOURCEDIR and not Installed\t1201\n"
411 "ExecuteAction\t\t1300\n"
412 "TestSourceDirProp13\tnot SourceDir and not SOURCEDIR and not Installed\t1301\n";
413
414static const char sd_install_exec_seq_dat[] =
415 "Action\tCondition\tSequence\n"
416 "s72\tS255\tI2\n"
417 "InstallExecuteSequence\tAction\n"
418 "TestSourceDirProp14\tSourceDir and SOURCEDIR and not Installed\t99\n"
419 "LaunchConditions\t\t100\n"
420 "TestSourceDirProp15\tSourceDir and SOURCEDIR and not Installed\t101\n"
421 "ValidateProductID\t\t700\n"
422 "TestSourceDirProp16\tSourceDir and SOURCEDIR and not Installed\t701\n"
423 "CostInitialize\t\t800\n"
424 "TestSourceDirProp17\tSourceDir and SOURCEDIR and not Installed\t801\n"
425 "ResolveSource\tResolveSource and not Installed\t850\n"
426 "TestSourceDirProp18\tResolveSource and not SourceDir and not SOURCEDIR and not Installed\t851\n"
427 "TestSourceDirProp19\tnot ResolveSource and SourceDir and SOURCEDIR and not Installed\t852\n"
428 "FileCost\t\t900\n"
429 "TestSourceDirProp20\tSourceDir and SOURCEDIR and not Installed\t901\n"
430 "IsolateComponents\t\t1000\n"
431 "TestSourceDirProp21\tSourceDir and SOURCEDIR and not Installed\t1001\n"
432 "CostFinalize\t\t1100\n"
433 "TestSourceDirProp22\tSourceDir and SOURCEDIR and not Installed\t1101\n"
434 "MigrateFeatureStates\t\t1200\n"
435 "TestSourceDirProp23\tSourceDir and SOURCEDIR and not Installed\t1201\n"
436 "InstallValidate\t\t1400\n"
437 "TestSourceDirProp24\tSourceDir and SOURCEDIR and not Installed\t1401\n"
438 "InstallInitialize\t\t1500\n"
439 "TestSourceDirProp25\tSourceDir and SOURCEDIR and not Installed\t1501\n"
440 "ProcessComponents\t\t1600\n"
441 "TestSourceDirProp26\tnot SourceDir and not SOURCEDIR and not Installed\t1601\n"
442 "UnpublishFeatures\t\t1800\n"
443 "TestSourceDirProp27\tnot SourceDir and not SOURCEDIR and not Installed\t1801\n"
444 "RemoveFiles\t\t3500\n"
445 "TestSourceDirProp28\tnot SourceDir and not SOURCEDIR and not Installed\t3501\n"
446 "InstallFiles\t\t4000\n"
447 "TestSourceDirProp29\tnot SourceDir and not SOURCEDIR and not Installed\t4001\n"
448 "RegisterUser\t\t6000\n"
449 "TestSourceDirProp30\tnot SourceDir and not SOURCEDIR and not Installed\t6001\n"
450 "RegisterProduct\t\t6100\n"
451 "TestSourceDirProp31\tnot SourceDir and not SOURCEDIR and not Installed\t6101\n"
452 "PublishFeatures\t\t6300\n"
453 "TestSourceDirProp32\tnot SourceDir and not SOURCEDIR and not Installed\t6301\n"
454 "PublishProduct\t\t6400\n"
455 "TestSourceDirProp33\tnot SourceDir and not SOURCEDIR and not Installed\t6401\n"
456 "InstallExecute\t\t6500\n"
457 "TestSourceDirProp34\tnot SourceDir and not SOURCEDIR and not Installed\t6501\n"
458 "InstallFinalize\t\t6600\n"
459 "TestSourceDirProp35\tnot SourceDir and not SOURCEDIR and not Installed\t6601\n";
460
461static const char sd_custom_action_dat[] =
462 "Action\tType\tSource\tTarget\tISComments\n"
463 "s72\ti2\tS64\tS0\tS255\n"
464 "CustomAction\tAction\n"
465 "TestSourceDirProp1\t19\t\tTest 1 failed\t\n"
466 "TestSourceDirProp2\t19\t\tTest 2 failed\t\n"
467 "TestSourceDirProp3\t19\t\tTest 3 failed\t\n"
468 "TestSourceDirProp4\t19\t\tTest 4 failed\t\n"
469 "TestSourceDirProp5\t19\t\tTest 5 failed\t\n"
470 "TestSourceDirProp6\t19\t\tTest 6 failed\t\n"
471 "TestSourceDirProp7\t19\t\tTest 7 failed\t\n"
472 "TestSourceDirProp8\t19\t\tTest 8 failed\t\n"
473 "TestSourceDirProp9\t19\t\tTest 9 failed\t\n"
474 "TestSourceDirProp10\t19\t\tTest 10 failed\t\n"
475 "TestSourceDirProp11\t19\t\tTest 11 failed\t\n"
476 "TestSourceDirProp12\t19\t\tTest 12 failed\t\n"
477 "TestSourceDirProp13\t19\t\tTest 13 failed\t\n"
478 "TestSourceDirProp14\t19\t\tTest 14 failed\t\n"
479 "TestSourceDirProp15\t19\t\tTest 15 failed\t\n"
480 "TestSourceDirProp16\t19\t\tTest 16 failed\t\n"
481 "TestSourceDirProp17\t19\t\tTest 17 failed\t\n"
482 "TestSourceDirProp18\t19\t\tTest 18 failed\t\n"
483 "TestSourceDirProp19\t19\t\tTest 19 failed\t\n"
484 "TestSourceDirProp20\t19\t\tTest 20 failed\t\n"
485 "TestSourceDirProp21\t19\t\tTest 21 failed\t\n"
486 "TestSourceDirProp22\t19\t\tTest 22 failed\t\n"
487 "TestSourceDirProp23\t19\t\tTest 23 failed\t\n"
488 "TestSourceDirProp24\t19\t\tTest 24 failed\t\n"
489 "TestSourceDirProp25\t19\t\tTest 25 failed\t\n"
490 "TestSourceDirProp26\t19\t\tTest 26 failed\t\n"
491 "TestSourceDirProp27\t19\t\tTest 27 failed\t\n"
492 "TestSourceDirProp28\t19\t\tTest 28 failed\t\n"
493 "TestSourceDirProp29\t19\t\tTest 29 failed\t\n"
494 "TestSourceDirProp30\t19\t\tTest 30 failed\t\n"
495 "TestSourceDirProp31\t19\t\tTest 31 failed\t\n"
496 "TestSourceDirProp32\t19\t\tTest 32 failed\t\n"
497 "TestSourceDirProp33\t19\t\tTest 33 failed\t\n"
498 "TestSourceDirProp34\t19\t\tTest 34 failed\t\n"
499 "TestSourceDirProp35\t19\t\tTest 35 failed\t\n";
500
501static const char ci_install_exec_seq_dat[] =
502 "Action\tCondition\tSequence\n"
503 "s72\tS255\tI2\n"
504 "InstallExecuteSequence\tAction\n"
505 "CostInitialize\t\t800\n"
506 "FileCost\t\t900\n"
507 "CostFinalize\t\t1000\n"
508 "InstallValidate\t\t1400\n"
509 "InstallInitialize\t\t1500\n"
510 "RunInstall\tnot Installed\t1550\n"
511 "ProcessComponents\t\t1600\n"
512 "UnpublishFeatures\t\t1800\n"
513 "RemoveFiles\t\t3500\n"
514 "InstallFiles\t\t4000\n"
515 "RegisterProduct\t\t6100\n"
516 "PublishFeatures\t\t6300\n"
517 "PublishProduct\t\t6400\n"
518 "InstallFinalize\t\t6600\n";
519
520static const char ci_custom_action_dat[] =
521 "Action\tType\tSource\tTarget\tISComments\n"
522 "s72\ti2\tS64\tS0\tS255\n"
523 "CustomAction\tAction\n"
524 "RunInstall\t23\tmsitest\\concurrent.msi\tMYPROP=[UILevel]\t\n";
525
526static const char ci_component_dat[] =
527 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
528 "s72\tS38\ts72\ti2\tS255\tS72\n"
529 "Component\tComponent\n"
530 "maximus\t{DF2CBABC-3BCC-47E5-A998-448D1C0C895B}\tMSITESTDIR\t0\tUILevel=5\tmaximus\n";
531
532static const char ci2_component_dat[] =
533 "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n"
534 "s72\tS38\ts72\ti2\tS255\tS72\n"
535 "Component\tComponent\n"
536 "augustus\t\tMSITESTDIR\t0\tUILevel=3 AND MYPROP=5\taugustus\n";
537
538static const char ci2_feature_comp_dat[] =
539 "Feature_\tComponent_\n"
540 "s38\ts72\n"
541 "FeatureComponents\tFeature_\tComponent_\n"
542 "feature\taugustus";
543
544static const char ci2_file_dat[] =
545 "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n"
546 "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n"
547 "File\tFile\n"
548 "augustus\taugustus\taugustus\t500\t\t\t8192\t1";
549
550static const char cl_custom_action_dat[] =
551 "Action\tType\tSource\tTarget\tISComments\n"
552 "s72\ti2\tS64\tS0\tS255\n"
553 "CustomAction\tAction\n"
554 "TestCommandlineProp\t19\t\tTest1\t\n";
555
556static const char cl_install_exec_seq_dat[] =
557 "Action\tCondition\tSequence\n"
558 "s72\tS255\tI2\n"
559 "InstallExecuteSequence\tAction\n"
560 "LaunchConditions\t\t100\n"
561 "ValidateProductID\t\t700\n"
562 "CostInitialize\t\t800\n"
563 "FileCost\t\t900\n"
564 "CostFinalize\t\t1000\n"
565 "TestCommandlineProp\tP=\"one\"\t1100\n"
566 "InstallInitialize\t\t1500\n"
567 "ProcessComponents\t\t1600\n"
568 "InstallValidate\t\t1400\n"
569 "InstallFinalize\t\t5000\n";
570
571static const msi_table tables[] =
572{
574 ADD_TABLE(component),
576 ADD_TABLE(feature_comp),
578 ADD_TABLE(install_exec_seq),
581};
582
583static const msi_table mcp_tables[] =
584{
586 ADD_TABLE(mcp_component),
587 ADD_TABLE(mcp_feature),
588 ADD_TABLE(mcp_feature_comp),
589 ADD_TABLE(mcp_file),
590 ADD_TABLE(install_exec_seq),
593};
594
595static const msi_table lus0_tables[] =
596{
597 ADD_TABLE(lus_component),
599 ADD_TABLE(lus_feature),
600 ADD_TABLE(lus_feature_comp),
601 ADD_TABLE(lus_file),
602 ADD_TABLE(lus_install_exec_seq),
603 ADD_TABLE(lus0_media),
605};
606
607static const msi_table lus1_tables[] =
608{
609 ADD_TABLE(lus_component),
611 ADD_TABLE(lus_feature),
612 ADD_TABLE(lus_feature_comp),
613 ADD_TABLE(lus_file),
614 ADD_TABLE(lus_install_exec_seq),
615 ADD_TABLE(lus1_media),
617};
618
619static const msi_table lus2_tables[] =
620{
621 ADD_TABLE(lus_component),
623 ADD_TABLE(lus_feature),
624 ADD_TABLE(lus_feature_comp),
625 ADD_TABLE(lus_file),
626 ADD_TABLE(lus_install_exec_seq),
627 ADD_TABLE(lus2_media),
629};
630
631static const msi_table spf_tables[] =
632{
633 ADD_TABLE(lus_component),
635 ADD_TABLE(lus_feature),
636 ADD_TABLE(lus_feature_comp),
637 ADD_TABLE(lus_file),
638 ADD_TABLE(lus0_media),
640 ADD_TABLE(spf_custom_action),
641 ADD_TABLE(spf_install_exec_seq),
642 ADD_TABLE(spf_install_ui_seq)
643};
644
645static const msi_table spf2_tables[] =
646{
647 ADD_TABLE(spf_component),
648 ADD_TABLE(spf_directory),
649 ADD_TABLE(lus_feature),
650 ADD_TABLE(lus_feature_comp),
651 ADD_TABLE(lus_file),
652 ADD_TABLE(lus0_media),
654 ADD_TABLE(spf2_custom_action),
655 ADD_TABLE(spf2_install_exec_seq),
656 ADD_TABLE(spf_install_ui_seq),
657 ADD_TABLE(shortcut)
658};
659
660static const msi_table sd_tables[] =
661{
663 ADD_TABLE(sd_component),
664 ADD_TABLE(sd_feature),
665 ADD_TABLE(sd_feature_comp),
666 ADD_TABLE(sd_file),
667 ADD_TABLE(sd_install_exec_seq),
668 ADD_TABLE(sd_install_ui_seq),
669 ADD_TABLE(sd_custom_action),
672};
673
674static const msi_table ci_tables[] =
675{
676 ADD_TABLE(ci_component),
678 ADD_TABLE(lus_feature),
679 ADD_TABLE(lus_feature_comp),
680 ADD_TABLE(lus_file),
681 ADD_TABLE(ci_install_exec_seq),
682 ADD_TABLE(lus0_media),
684 ADD_TABLE(ci_custom_action),
685};
686
687static const msi_table ci2_tables[] =
688{
689 ADD_TABLE(ci2_component),
691 ADD_TABLE(lus_feature),
692 ADD_TABLE(ci2_feature_comp),
693 ADD_TABLE(ci2_file),
694 ADD_TABLE(install_exec_seq),
695 ADD_TABLE(lus0_media),
696 ADD_TABLE(ci2_property),
697};
698
699static const msi_table cl_tables[] =
700{
701 ADD_TABLE(component),
704 ADD_TABLE(feature_comp),
706 ADD_TABLE(cl_custom_action),
707 ADD_TABLE(cl_install_exec_seq),
710};
711
713{
714 UINT res;
716
717 /* build summary info */
719 ok(res == ERROR_SUCCESS, "Failed to open summaryinfo\n");
720
722 "Installation Database");
723 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
724
726 "Installation Database");
727 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
728
730 "Wine Hackers");
731 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
732
734 ";1033");
735 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
736
738 "{A2078D65-94D6-4205-8DEE-F68D6FD622AA}");
739 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
740
742 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
743
745 ok(res == ERROR_SUCCESS, "Failed to set summary info\n");
746
748 ok(res == ERROR_SUCCESS, "Failed to make summary info persist\n");
749
751 ok(res == ERROR_SUCCESS, "Failed to close suminfo\n");
752
753 return res;
754}
755
757{
758 MSIHANDLE hdb = 0;
759 CHAR query[MAX_PATH + 72];
760 UINT res;
761
763
764 /* create an empty database */
766 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
767 if (res != ERROR_SUCCESS)
768 return hdb;
769
770 res = MsiDatabaseCommit(hdb);
771 ok(res == ERROR_SUCCESS, "Failed to commit database\n");
772
773 set_summary_info(hdb, prodcode);
774
775 res = run_query(hdb, 0,
776 "CREATE TABLE `Directory` ( "
777 "`Directory` CHAR(255) NOT NULL, "
778 "`Directory_Parent` CHAR(255), "
779 "`DefaultDir` CHAR(255) NOT NULL "
780 "PRIMARY KEY `Directory`)");
781 ok(res == ERROR_SUCCESS , "Failed to create directory table\n");
782
783 res = run_query(hdb, 0,
784 "CREATE TABLE `Property` ( "
785 "`Property` CHAR(72) NOT NULL, "
786 "`Value` CHAR(255) "
787 "PRIMARY KEY `Property`)");
788 ok(res == ERROR_SUCCESS , "Failed to create directory table\n");
789
790 sprintf(query, "INSERT INTO `Property` "
791 "(`Property`, `Value`) "
792 "VALUES( 'ProductCode', '%s' )", prodcode);
793 res = run_query(hdb, 0, query);
794 ok(res == ERROR_SUCCESS , "Failed\n");
795
796 res = MsiDatabaseCommit(hdb);
797 ok(res == ERROR_SUCCESS, "Failed to commit database\n");
798
799 return hdb;
800}
801
802static void test_usefeature(void)
803{
805
807 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
808
809 r = MsiQueryFeatureStateA("{9085040-6000-11d3-8cfe-0150048383c9}" ,NULL);
810 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
811
813 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
814
815 r = MsiUseFeatureExA(NULL, "WORDVIEWFiles", -2, 1 );
816 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
817
818 r = MsiUseFeatureExA("{90850409-6000-11d3-8cfe-0150048383c9}",
819 NULL, -2, 0 );
820 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
821
822 r = MsiUseFeatureExA("{9085040-6000-11d3-8cfe-0150048383c9}",
823 "WORDVIEWFiles", -2, 0 );
824 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
825
826 r = MsiUseFeatureExA("{0085040-6000-11d3-8cfe-0150048383c9}",
827 "WORDVIEWFiles", -2, 0 );
828 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
829
830 r = MsiUseFeatureExA("{90850409-6000-11d3-8cfe-0150048383c9}",
831 "WORDVIEWFiles", -2, 1 );
832 ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n");
833}
834
835static void test_null(void)
836{
837 MSIHANDLE hpkg;
838 UINT r;
839 HKEY hkey;
840 DWORD dwType, cbData;
841 LPBYTE lpData = NULL;
844
845 if (is_wow64)
847
848 r = MsiOpenPackageExW(NULL, 0, &hpkg);
849 ok( r == ERROR_INVALID_PARAMETER,"wrong error\n");
850
852 ok( state == INSTALLSTATE_INVALIDARG, "wrong return\n");
853
855 ok( r == ERROR_INVALID_PARAMETER,"wrong error\n");
856
858 ok( r == ERROR_INVALID_PARAMETER, "wrong error\n");
859
860 r = MsiConfigureFeatureA("{00000000-0000-0000-0000-000000000000}", NULL, 0);
861 ok( r == ERROR_INVALID_PARAMETER, "wrong error\n");
862
863 r = MsiConfigureFeatureA("{00000000-0000-0000-0000-000000000001}", "foo", 0);
864 ok( r == ERROR_INVALID_PARAMETER, "wrong error %d\n", r);
865
866 r = MsiConfigureFeatureA("{00000000-0000-0000-0000-000000000002}", "foo", INSTALLSTATE_DEFAULT);
867 ok( r == ERROR_UNKNOWN_PRODUCT, "wrong error %d\n", r);
868
869 /* make sure empty string to MsiGetProductInfo is not a handle to default registry value, saving and restoring the
870 * necessary registry values */
871
872 /* empty product string */
873 r = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, access, &hkey);
874 if (r == ERROR_ACCESS_DENIED)
875 {
876 skip("Not enough rights to perform tests\n");
877 return;
878 }
879 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
880
881 r = RegQueryValueExA(hkey, NULL, 0, &dwType, lpData, &cbData);
882 ok ( r == ERROR_SUCCESS || r == ERROR_FILE_NOT_FOUND, "wrong error %d\n", r);
883 if ( r == ERROR_SUCCESS )
884 {
885 if (!(lpData = malloc(cbData))) skip("Out of memory\n");
886 else
887 {
888 r = RegQueryValueExA(hkey, NULL, 0, &dwType, lpData, &cbData);
889 ok ( r == ERROR_SUCCESS, "wrong error %d\n", r);
890 }
891 }
892
893 r = RegSetValueA(hkey, NULL, REG_SZ, "test", strlen("test"));
894 if (r == ERROR_ACCESS_DENIED)
895 {
896 skip("Not enough rights to perform tests\n");
897 free(lpData);
898 RegCloseKey(hkey);
899 return;
900 }
901 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
902
903 r = MsiGetProductInfoA("", "", NULL, NULL);
904 ok ( r == ERROR_INVALID_PARAMETER, "wrong error %d\n", r);
905
906 if (lpData)
907 {
908 r = RegSetValueExA(hkey, NULL, 0, dwType, lpData, cbData);
909 ok ( r == ERROR_SUCCESS, "wrong error %d\n", r);
910 free(lpData);
911 }
912 else
913 {
914 r = RegDeleteValueA(hkey, NULL);
915 ok ( r == ERROR_SUCCESS, "wrong error %d\n", r);
916 }
917
918 r = RegCloseKey(hkey);
919 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
920
921 /* empty attribute */
922 r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F1C3AF50-8B56-4A69-A00C-00773FE42F30}",
923 0, NULL, 0, access, NULL, &hkey, NULL);
924 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
925
926 r = RegSetValueA(hkey, NULL, REG_SZ, "test", strlen("test"));
927 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
928
929 r = MsiGetProductInfoA("{F1C3AF50-8B56-4A69-A00C-00773FE42F30}", "", NULL, NULL);
930 ok ( r == ERROR_UNKNOWN_PROPERTY, "wrong error %d\n", r);
931
932 r = RegCloseKey(hkey);
933 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
934
935 r = RegDeleteKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{F1C3AF50-8B56-4A69-A00C-00773FE42F30}",
937 ok( r == ERROR_SUCCESS, "wrong error %d\n", r);
938}
939
940static void test_getcomponentpath(void)
941{
943 char buffer[0x100];
944 DWORD sz;
945
947 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
948
949 r = MsiGetComponentPathA( "bogus", "bogus", NULL, NULL );
950 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
951
952 r = MsiGetComponentPathA( "bogus", "{00000000-0000-0000-000000000000}", NULL, NULL );
953 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
954
955 sz = sizeof buffer;
956 buffer[0]=0;
957 r = MsiGetComponentPathA( "bogus", "{00000000-0000-0000-000000000000}", buffer, &sz );
958 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
959
960 r = MsiGetComponentPathA( "{00000000-78E1-11D2-B60F-006097C998E7}",
961 "{00000000-0000-0000-0000-000000000000}", buffer, &sz );
962 ok( r == INSTALLSTATE_UNKNOWN, "wrong return value\n");
963
964 r = MsiGetComponentPathA( "{00000409-78E1-11D2-B60F-006097C998E7}",
965 "{00000000-0000-0000-0000-00000000}", buffer, &sz );
966 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
967
968 r = MsiGetComponentPathA( "{00000409-78E1-11D2-B60F-006097C998E7}",
969 "{029E403D-A86A-1D11-5B5B0006799C897E}", buffer, &sz );
970 ok( r == INSTALLSTATE_INVALIDARG, "wrong return value\n");
971
972 r = MsiGetComponentPathA( "{00000000-78E1-11D2-B60F-006097C9987e}",
973 "{00000000-A68A-11d1-5B5B-0006799C897E}", buffer, &sz );
974 ok( r == INSTALLSTATE_UNKNOWN, "wrong return value\n");
975}
976
977static void create_test_files(void)
978{
979 CreateDirectoryA("msitest", NULL);
980 create_file("msitest\\one.txt", 100);
981 CreateDirectoryA("msitest\\first", NULL);
982 create_file("msitest\\first\\two.txt", 100);
983 CreateDirectoryA("msitest\\second", NULL);
984 create_file("msitest\\second\\three.txt", 100);
985
986 create_file("four.txt", 100);
987 create_file("five.txt", 100);
988 create_cab_file("msitest.cab", MEDIA_SIZE, "four.txt\0five.txt\0");
989
990 create_file("msitest\\filename", 100);
991 create_file("msitest\\service.exe", 100);
992
993 DeleteFileA("four.txt");
994 DeleteFileA("five.txt");
995}
996
997static void delete_test_files(void)
998{
999 DeleteFileA("msitest.msi");
1000 DeleteFileA("msitest.cab");
1001 DeleteFileA("msitest\\second\\three.txt");
1002 DeleteFileA("msitest\\first\\two.txt");
1003 DeleteFileA("msitest\\one.txt");
1004 DeleteFileA("msitest\\service.exe");
1005 DeleteFileA("msitest\\filename");
1006 RemoveDirectoryA("msitest\\second");
1007 RemoveDirectoryA("msitest\\first");
1008 RemoveDirectoryA("msitest");
1009}
1010
1011#define HASHSIZE sizeof(MSIFILEHASHINFO)
1012
1013static const struct
1014{
1018} hash_data[] =
1019{
1020 { "", 0,
1021 { HASHSIZE,
1022 { 0, 0, 0, 0 },
1023 },
1024 },
1025
1026 { "abc", 0,
1027 { HASHSIZE,
1028 { 0x98500190, 0xb04fd23c, 0x7d3f96d6, 0x727fe128 },
1029 },
1030 },
1031
1032 { "C:\\Program Files\\msitest\\caesar\n", 0,
1033 { HASHSIZE,
1034 { 0x2b566794, 0xfd42181b, 0x2514d6e4, 0x5768b4e2 },
1035 },
1036 },
1037
1038 { "C:\\Program Files\\msitest\\caesar\n", 500,
1039 { HASHSIZE,
1040 { 0x58095058, 0x805efeff, 0x10f3483e, 0x0147d653 },
1041 },
1042 },
1044
1045static void test_MsiGetFileHash(void)
1046{
1047 const char name[] = "msitest.bin";
1048 UINT r;
1050 DWORD i;
1051
1052 hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
1053
1054 /* szFilePath is NULL */
1055 r = MsiGetFileHashA(NULL, 0, &hash);
1056 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
1057
1058 /* szFilePath is empty */
1059 r = MsiGetFileHashA("", 0, &hash);
1061 "Expected ERROR_PATH_NOT_FOUND or ERROR_BAD_PATHNAME, got %d\n", r);
1062
1063 /* szFilePath is nonexistent */
1064 r = MsiGetFileHashA(name, 0, &hash);
1065 ok(r == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", r);
1066
1067 /* dwOptions is non-zero */
1068 r = MsiGetFileHashA(name, 1, &hash);
1069 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
1070
1071 /* pHash.dwFileHashInfoSize is not correct */
1072 hash.dwFileHashInfoSize = 0;
1073 r = MsiGetFileHashA(name, 0, &hash);
1074 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
1075
1076 /* pHash is NULL */
1077 r = MsiGetFileHashA(name, 0, NULL);
1078 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
1079
1080 for (i = 0; i < ARRAY_SIZE(hash_data); i++)
1081 {
1082 int ret;
1083
1085
1086 memset(&hash, 0, sizeof(MSIFILEHASHINFO));
1087 hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
1088
1089 r = MsiGetFileHashA(name, 0, &hash);
1090 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1091
1093 ok(!ret, "Hash incorrect\n");
1094
1096 }
1097}
1098
1099/* copied from dlls/msi/registry.c */
1101{
1102 DWORD i,n=1;
1103 GUID guid;
1104
1105 if (FAILED(CLSIDFromString((LPCOLESTR)in, &guid)))
1106 return FALSE;
1107
1108 for(i=0; i<8; i++)
1109 out[7-i] = in[n++];
1110 n++;
1111 for(i=0; i<4; i++)
1112 out[11-i] = in[n++];
1113 n++;
1114 for(i=0; i<4; i++)
1115 out[15-i] = in[n++];
1116 n++;
1117 for(i=0; i<2; i++)
1118 {
1119 out[17+i*2] = in[n++];
1120 out[16+i*2] = in[n++];
1121 }
1122 n++;
1123 for( ; i<8; i++)
1124 {
1125 out[17+i*2] = in[n++];
1126 out[16+i*2] = in[n++];
1127 }
1128 out[32]=0;
1129 return TRUE;
1130}
1131
1132static void create_test_guid(LPSTR prodcode, LPSTR squashed)
1133{
1134 WCHAR guidW[GUID_SIZE];
1135 WCHAR squashedW[SQUASHED_GUID_SIZE];
1136 GUID guid;
1137 HRESULT hr;
1138 int size;
1139
1140 hr = CoCreateGuid(&guid);
1141 ok(hr == S_OK, "Expected S_OK, got %#lx\n", hr);
1142
1143 size = StringFromGUID2(&guid, guidW, ARRAY_SIZE(guidW));
1144 ok(size == GUID_SIZE, "Expected %d, got %d.\n", GUID_SIZE, size);
1145
1146 WideCharToMultiByte(CP_ACP, 0, guidW, size, prodcode, GUID_SIZE, NULL, NULL);
1147 if (squashed)
1148 {
1149 squash_guid(guidW, squashedW);
1150 WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, SQUASHED_GUID_SIZE, NULL, NULL);
1151 }
1152}
1153
1154static char *get_user_sid(void)
1155{
1156 HANDLE token;
1157 DWORD size = 0;
1159 char *usersid = NULL;
1160
1163
1164 user = malloc(size);
1166 ConvertSidToStringSidA(user->User.Sid, &usersid);
1167 free(user);
1168
1170 return usersid;
1171}
1172
1174{
1175 CHAR prodcode[MAX_PATH];
1176 CHAR prod_squashed[MAX_PATH];
1177 CHAR keypath[MAX_PATH*2];
1178 LPSTR usersid;
1180 LONG res;
1181 HKEY userkey, localkey, props;
1182 HKEY prodkey;
1183 DWORD data, error;
1185
1186 create_test_guid(prodcode, prod_squashed);
1187 usersid = get_user_sid();
1188
1189 if (is_wow64)
1191
1192 /* NULL prodcode */
1193 SetLastError(0xdeadbeef);
1195 error = GetLastError();
1196 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1197 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1198
1199 /* empty prodcode */
1200 SetLastError(0xdeadbeef);
1202 error = GetLastError();
1203 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1204 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1205
1206 /* garbage prodcode */
1207 SetLastError(0xdeadbeef);
1208 state = MsiQueryProductStateA("garbage");
1209 error = GetLastError();
1210 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1211 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1212
1213 /* guid without brackets */
1214 SetLastError(0xdeadbeef);
1215 state = MsiQueryProductStateA("6700E8CF-95AB-4D9C-BC2C-15840DEA7A5D");
1216 error = GetLastError();
1217 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1218 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1219
1220 /* guid with brackets */
1221 SetLastError(0xdeadbeef);
1222 state = MsiQueryProductStateA("{6700E8CF-95AB-4D9C-BC2C-15840DEA7A5D}");
1223 error = GetLastError();
1224 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1225 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1226
1227 /* same length as guid, but random */
1228 SetLastError(0xdeadbeef);
1229 state = MsiQueryProductStateA("A938G02JF-2NF3N93-VN3-2NNF-3KGKALDNF93");
1230 error = GetLastError();
1231 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1232 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1233
1234 /* MSIINSTALLCONTEXT_USERUNMANAGED */
1235
1236 SetLastError(0xdeadbeef);
1237 state = MsiQueryProductStateA(prodcode);
1238 error = GetLastError();
1239 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1240 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1241
1242 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Products\\");
1243 lstrcatA(keypath, prod_squashed);
1244
1245 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &userkey);
1246 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1247
1248 /* user product key exists */
1249 SetLastError(0xdeadbeef);
1250 state = MsiQueryProductStateA(prodcode);
1251 error = GetLastError();
1252 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1253 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1254
1255 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");
1256 lstrcatA(keypath, prodcode);
1257
1258 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1259 if (res == ERROR_ACCESS_DENIED)
1260 {
1261 skip("Not enough rights to perform tests\n");
1262 RegDeleteKeyA(userkey, "");
1263 RegCloseKey(userkey);
1264 LocalFree(usersid);
1265 return;
1266 }
1267 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1268
1269 /* local uninstall key exists */
1270 SetLastError(0xdeadbeef);
1271 state = MsiQueryProductStateA(prodcode);
1272 error = GetLastError();
1273 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1274 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1275
1276 data = 1;
1277 res = RegSetValueExA(localkey, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
1278 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1279
1280 /* WindowsInstaller value exists */
1281 SetLastError(0xdeadbeef);
1282 state = MsiQueryProductStateA(prodcode);
1283 error = GetLastError();
1284 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1285 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1286
1287 RegDeleteValueA(localkey, "WindowsInstaller");
1288 RegDeleteKeyExA(localkey, "", access & KEY_WOW64_64KEY, 0);
1289
1290 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1291 lstrcatA(keypath, usersid);
1292 lstrcatA(keypath, "\\Products\\");
1293 lstrcatA(keypath, prod_squashed);
1294
1295 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1296 if (res == ERROR_ACCESS_DENIED)
1297 {
1298 skip("Not enough rights to perform tests\n");
1299 RegDeleteKeyA(userkey, "");
1300 RegCloseKey(userkey);
1301 LocalFree(usersid);
1302 return;
1303 }
1304 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1305
1306 /* local product key exists */
1307 SetLastError(0xdeadbeef);
1308 state = MsiQueryProductStateA(prodcode);
1309 error = GetLastError();
1310 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1311 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1312
1313 res = RegCreateKeyExA(localkey, "InstallProperties", 0, NULL, 0, access, NULL, &props, NULL);
1314 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1315
1316 /* install properties key exists */
1317 SetLastError(0xdeadbeef);
1318 state = MsiQueryProductStateA(prodcode);
1319 error = GetLastError();
1320 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1321 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1322
1323 data = 1;
1324 res = RegSetValueExA(props, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
1325 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1326
1327 /* WindowsInstaller value exists */
1328 SetLastError(0xdeadbeef);
1329 state = MsiQueryProductStateA(prodcode);
1330 error = GetLastError();
1331 ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1332 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1333
1334 data = 2;
1335 res = RegSetValueExA(props, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
1336 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1337
1338 /* WindowsInstaller value is not 1 */
1339 SetLastError(0xdeadbeef);
1340 state = MsiQueryProductStateA(prodcode);
1341 error = GetLastError();
1342 ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1343 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1344
1345 RegDeleteKeyA(userkey, "");
1346
1347 /* user product key does not exist */
1348 SetLastError(0xdeadbeef);
1349 state = MsiQueryProductStateA(prodcode);
1350 error = GetLastError();
1351 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
1352 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1353
1354 RegDeleteValueA(props, "WindowsInstaller");
1357 RegDeleteKeyExA(localkey, "", access & KEY_WOW64_64KEY, 0);
1358 RegCloseKey(localkey);
1359 RegDeleteKeyA(userkey, "");
1360 RegCloseKey(userkey);
1361
1362 /* MSIINSTALLCONTEXT_USERMANAGED */
1363
1364 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Managed\\");
1365 lstrcatA(keypath, usersid);
1366 lstrcatA(keypath, "\\Installer\\Products\\");
1367 lstrcatA(keypath, prod_squashed);
1368
1369 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
1370 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1371
1372 state = MsiQueryProductStateA(prodcode);
1374 "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1375
1376 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1377 lstrcatA(keypath, usersid);
1378 lstrcatA(keypath, "\\Products\\");
1379 lstrcatA(keypath, prod_squashed);
1380
1381 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1382 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1383
1384 state = MsiQueryProductStateA(prodcode);
1386 "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1387
1388 res = RegCreateKeyExA(localkey, "InstallProperties", 0, NULL, 0, access, NULL, &props, NULL);
1389 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1390
1391 state = MsiQueryProductStateA(prodcode);
1393 "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1394
1395 data = 1;
1396 res = RegSetValueExA(props, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
1397 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1398
1399 /* WindowsInstaller value exists */
1400 state = MsiQueryProductStateA(prodcode);
1401 ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1402
1403 RegDeleteValueA(props, "WindowsInstaller");
1406 RegDeleteKeyExA(localkey, "", access & KEY_WOW64_64KEY, 0);
1407 RegCloseKey(localkey);
1408 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
1409 RegCloseKey(prodkey);
1410
1411 /* MSIINSTALLCONTEXT_MACHINE */
1412
1413 lstrcpyA(keypath, "Software\\Classes\\Installer\\Products\\");
1414 lstrcatA(keypath, prod_squashed);
1415
1416 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
1417 if (res == ERROR_ACCESS_DENIED)
1418 {
1419 skip( "insufficient rights\n" );
1420 LocalFree( usersid );
1421 return;
1422 }
1423 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1424
1425 state = MsiQueryProductStateA(prodcode);
1426 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1427
1428 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1429 lstrcatA(keypath, "S-1-5-18\\Products\\");
1430 lstrcatA(keypath, prod_squashed);
1431
1432 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1433 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1434
1435 state = MsiQueryProductStateA(prodcode);
1437 "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1438
1439 res = RegCreateKeyExA(localkey, "InstallProperties", 0, NULL, 0, access, NULL, &props, NULL);
1440 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1441
1442 state = MsiQueryProductStateA(prodcode);
1444 "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1445
1446 data = 1;
1447 res = RegSetValueExA(props, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
1448 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1449
1450 /* WindowsInstaller value exists */
1451 state = MsiQueryProductStateA(prodcode);
1452 ok(state == INSTALLSTATE_DEFAULT, "Expected INSTALLSTATE_DEFAULT, got %d\n", state);
1453
1454 RegDeleteValueA(props, "WindowsInstaller");
1457 RegDeleteKeyExA(localkey, "", access & KEY_WOW64_64KEY, 0);
1458 RegCloseKey(localkey);
1459 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
1460 RegCloseKey(prodkey);
1461
1462 LocalFree(usersid);
1463}
1464
1465static const char table_enc85[] =
1466"!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
1467"PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
1468"yz{}~";
1469
1470/*
1471 * Encodes a base85 guid given a GUID pointer
1472 * Caller should provide a 21 character buffer for the encoded string.
1473 */
1475{
1476 unsigned int x, *p, i;
1477
1478 p = (unsigned int*) guid;
1479 for( i=0; i<4; i++ )
1480 {
1481 x = p[i];
1482 *str++ = table_enc85[x%85];
1483 x = x/85;
1484 *str++ = table_enc85[x%85];
1485 x = x/85;
1486 *str++ = table_enc85[x%85];
1487 x = x/85;
1488 *str++ = table_enc85[x%85];
1489 x = x/85;
1490 *str++ = table_enc85[x%85];
1491 }
1492 *str = 0;
1493}
1494
1495static void compose_base85_guid(LPSTR component, LPSTR comp_base85, LPSTR squashed)
1496{
1497 WCHAR guidW[MAX_PATH];
1498 WCHAR base85W[MAX_PATH];
1499 WCHAR squashedW[MAX_PATH];
1500 GUID guid;
1501 HRESULT hr;
1502 int size;
1503
1504 hr = CoCreateGuid(&guid);
1505 ok(hr == S_OK, "Expected S_OK, got %#lx\n", hr);
1506
1507 size = StringFromGUID2(&guid, guidW, MAX_PATH);
1508 ok(size == 39, "Expected 39, got %d\n", size);
1509
1510 WideCharToMultiByte(CP_ACP, 0, guidW, size, component, MAX_PATH, NULL, NULL);
1511 encode_base85_guid(&guid, base85W);
1512 WideCharToMultiByte(CP_ACP, 0, base85W, -1, comp_base85, MAX_PATH, NULL, NULL);
1513 squash_guid(guidW, squashedW);
1514 WideCharToMultiByte(CP_ACP, 0, squashedW, -1, squashed, MAX_PATH, NULL, NULL);
1515}
1516
1518{
1519 HKEY userkey, localkey, compkey, compkey2;
1520 CHAR prodcode[MAX_PATH];
1521 CHAR prod_squashed[MAX_PATH];
1522 CHAR component[MAX_PATH];
1523 CHAR comp_base85[MAX_PATH];
1524 CHAR comp_squashed[MAX_PATH], comp_squashed2[MAX_PATH];
1525 CHAR keypath[MAX_PATH*2];
1527 LPSTR usersid;
1528 LONG res;
1530 DWORD error;
1531
1532 create_test_guid(prodcode, prod_squashed);
1533 compose_base85_guid(component, comp_base85, comp_squashed);
1534 compose_base85_guid(component, comp_base85 + 20, comp_squashed2);
1535 usersid = get_user_sid();
1536
1537 if (is_wow64)
1539
1540 /* NULL prodcode */
1541 SetLastError(0xdeadbeef);
1542 state = MsiQueryFeatureStateA(NULL, "feature");
1543 error = GetLastError();
1544 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1545 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1546
1547 /* empty prodcode */
1548 SetLastError(0xdeadbeef);
1549 state = MsiQueryFeatureStateA("", "feature");
1550 error = GetLastError();
1551 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1552 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1553
1554 /* garbage prodcode */
1555 SetLastError(0xdeadbeef);
1556 state = MsiQueryFeatureStateA("garbage", "feature");
1557 error = GetLastError();
1558 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1559 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1560
1561 /* guid without brackets */
1562 SetLastError(0xdeadbeef);
1563 state = MsiQueryFeatureStateA("6700E8CF-95AB-4D9C-BC2C-15840DEA7A5D", "feature");
1564 error = GetLastError();
1565 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1566 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1567
1568 /* guid with brackets */
1569 SetLastError(0xdeadbeef);
1570 state = MsiQueryFeatureStateA("{6700E8CF-95AB-4D9C-BC2C-15840DEA7A5D}", "feature");
1571 error = GetLastError();
1572 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1573 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1574
1575 /* same length as guid, but random */
1576 SetLastError(0xdeadbeef);
1577 state = MsiQueryFeatureStateA("A938G02JF-2NF3N93-VN3-2NNF-3KGKALDNF93", "feature");
1578 error = GetLastError();
1579 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1580 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1581
1582 /* NULL szFeature */
1583 SetLastError(0xdeadbeef);
1584 state = MsiQueryFeatureStateA(prodcode, NULL);
1585 error = GetLastError();
1586 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
1587 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
1588
1589 /* empty szFeature */
1590 SetLastError(0xdeadbeef);
1591 state = MsiQueryFeatureStateA(prodcode, "");
1592 error = GetLastError();
1593 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1594 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1595
1596 /* feature key does not exist yet */
1597 SetLastError(0xdeadbeef);
1598 state = MsiQueryFeatureStateA(prodcode, "feature");
1599 error = GetLastError();
1600 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1601 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1602
1603 /* MSIINSTALLCONTEXT_USERUNMANAGED */
1604
1605 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Features\\");
1606 lstrcatA(keypath, prod_squashed);
1607
1608 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &userkey);
1609 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1610
1611 /* feature key exists */
1612 SetLastError(0xdeadbeef);
1613 state = MsiQueryFeatureStateA(prodcode, "feature");
1614 error = GetLastError();
1615 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1616 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1617
1618 res = RegSetValueExA(userkey, "feature", 0, REG_SZ, (const BYTE *)"", 2);
1619 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1620
1621 /* feature value exists */
1622 SetLastError(0xdeadbeef);
1623 state = MsiQueryFeatureStateA(prodcode, "feature");
1624 error = GetLastError();
1625 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1626 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1627
1628 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1629 lstrcatA(keypath, usersid);
1630 lstrcatA(keypath, "\\Products\\");
1631 lstrcatA(keypath, prod_squashed);
1632 lstrcatA(keypath, "\\Features");
1633
1634 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1635 if (res == ERROR_ACCESS_DENIED)
1636 {
1637 skip("Not enough rights to perform tests\n");
1638 RegDeleteKeyA(userkey, "");
1639 RegCloseKey(userkey);
1640 LocalFree(usersid);
1641 return;
1642 }
1643 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1644
1645 /* userdata features key exists */
1646 SetLastError(0xdeadbeef);
1647 state = MsiQueryFeatureStateA(prodcode, "feature");
1648 error = GetLastError();
1649 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1650 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1651
1652 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaa", 20);
1653 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1654
1655 SetLastError(0xdeadbeef);
1656 state = MsiQueryFeatureStateA(prodcode, "feature");
1657 error = GetLastError();
1658 ok(state == INSTALLSTATE_BADCONFIG, "Expected INSTALLSTATE_BADCONFIG, got %d\n", state);
1659 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1660
1661 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaa", 21);
1662 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1663
1664 SetLastError(0xdeadbeef);
1665 state = MsiQueryFeatureStateA(prodcode, "feature");
1666 error = GetLastError();
1667 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1668 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1669
1670 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaaa", 22);
1671 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1672
1673 SetLastError(0xdeadbeef);
1674 state = MsiQueryFeatureStateA(prodcode, "feature");
1675 error = GetLastError();
1676 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1677 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1678
1679 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)comp_base85, 41);
1680 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1681
1682 SetLastError(0xdeadbeef);
1683 state = MsiQueryFeatureStateA(prodcode, "feature");
1684 error = GetLastError();
1685 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1686 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1687
1688 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1689 lstrcatA(keypath, usersid);
1690 lstrcatA(keypath, "\\Components\\");
1691 lstrcatA(keypath, comp_squashed);
1692
1693 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
1694 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1695
1696 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1697 lstrcatA(keypath, usersid);
1698 lstrcatA(keypath, "\\Components\\");
1699 lstrcatA(keypath, comp_squashed2);
1700
1701 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey2, NULL);
1702 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1703
1704 SetLastError(0xdeadbeef);
1705 state = MsiQueryFeatureStateA(prodcode, "feature");
1706 error = GetLastError();
1707 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1708 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1709
1710 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 1);
1711 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1712
1713 SetLastError(0xdeadbeef);
1714 state = MsiQueryFeatureStateA(prodcode, "feature");
1715 error = GetLastError();
1716 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1717 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1718
1719 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"apple", 6);
1720 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1721
1722 SetLastError(0xdeadbeef);
1723 state = MsiQueryFeatureStateA(prodcode, "feature");
1724 error = GetLastError();
1725 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1726 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1727
1728 res = RegSetValueExA(compkey2, prod_squashed, 0, REG_SZ, (const BYTE *)"orange", 7);
1729 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1730
1731 /* INSTALLSTATE_LOCAL */
1732 SetLastError(0xdeadbeef);
1733 state = MsiQueryFeatureStateA(prodcode, "feature");
1734 error = GetLastError();
1735 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1736 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1737
1738 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01\\", 4);
1739 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1740
1741 /* INSTALLSTATE_SOURCE */
1742 SetLastError(0xdeadbeef);
1743 state = MsiQueryFeatureStateA(prodcode, "feature");
1744 error = GetLastError();
1745 ok(state == INSTALLSTATE_SOURCE, "Expected INSTALLSTATE_SOURCE, got %d\n", state);
1746 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1747
1748 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01", 3);
1749 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1750
1751 /* bad INSTALLSTATE_SOURCE */
1752 SetLastError(0xdeadbeef);
1753 state = MsiQueryFeatureStateA(prodcode, "feature");
1754 error = GetLastError();
1755 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1756 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1757
1758 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01a", 4);
1759 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1760
1761 /* INSTALLSTATE_SOURCE */
1762 SetLastError(0xdeadbeef);
1763 state = MsiQueryFeatureStateA(prodcode, "feature");
1764 error = GetLastError();
1765 ok(state == INSTALLSTATE_SOURCE, "Expected INSTALLSTATE_SOURCE, got %d\n", state);
1766 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1767
1768 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01", 3);
1769 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1770
1771 /* bad INSTALLSTATE_SOURCE */
1772 SetLastError(0xdeadbeef);
1773 state = MsiQueryFeatureStateA(prodcode, "feature");
1774 error = GetLastError();
1775 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1776 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %lu\n", error);
1777
1778 RegDeleteValueA(compkey, prod_squashed);
1779 RegDeleteValueA(compkey2, prod_squashed);
1780 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
1781 RegDeleteKeyExA(compkey2, "", access & KEY_WOW64_64KEY, 0);
1782 RegDeleteValueA(localkey, "feature");
1783 RegDeleteValueA(userkey, "feature");
1784 RegDeleteKeyA(userkey, "");
1785 RegCloseKey(compkey);
1786 RegCloseKey(compkey2);
1787 RegCloseKey(localkey);
1788 RegCloseKey(userkey);
1789
1790 /* MSIINSTALLCONTEXT_USERMANAGED */
1791
1792 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Managed\\");
1793 lstrcatA(keypath, usersid);
1794 lstrcatA(keypath, "\\Installer\\Features\\");
1795 lstrcatA(keypath, prod_squashed);
1796
1797 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &userkey, NULL);
1798 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1799
1800 /* feature key exists */
1801 state = MsiQueryFeatureStateA(prodcode, "feature");
1802 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1803
1804 res = RegSetValueExA(userkey, "feature", 0, REG_SZ, (const BYTE *)"", 1);
1805 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1806
1807 /* feature value exists */
1808 state = MsiQueryFeatureStateA(prodcode, "feature");
1809 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1810
1811 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1812 lstrcatA(keypath, usersid);
1813 lstrcatA(keypath, "\\Products\\");
1814 lstrcatA(keypath, prod_squashed);
1815 lstrcatA(keypath, "\\Features");
1816
1817 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1818 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1819
1820 /* userdata features key exists */
1821 state = MsiQueryFeatureStateA(prodcode, "feature");
1822 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1823
1824 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaa", 20);
1825 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1826
1827 state = MsiQueryFeatureStateA(prodcode, "feature");
1828 ok(state == INSTALLSTATE_BADCONFIG, "Expected INSTALLSTATE_BADCONFIG, got %d\n", state);
1829
1830 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaa", 21);
1831 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1832
1833 state = MsiQueryFeatureStateA(prodcode, "feature");
1834 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1835
1836 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaaa", 22);
1837 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1838
1839 state = MsiQueryFeatureStateA(prodcode, "feature");
1840 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1841
1842 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)comp_base85, 41);
1843 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1844
1845 state = MsiQueryFeatureStateA(prodcode, "feature");
1846 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1847
1848 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1849 lstrcatA(keypath, usersid);
1850 lstrcatA(keypath, "\\Components\\");
1851 lstrcatA(keypath, comp_squashed);
1852
1853 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
1854 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1855
1856 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1857 lstrcatA(keypath, usersid);
1858 lstrcatA(keypath, "\\Components\\");
1859 lstrcatA(keypath, comp_squashed2);
1860
1861 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey2, NULL);
1862 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1863
1864 state = MsiQueryFeatureStateA(prodcode, "feature");
1865 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1866
1867 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 1);
1868 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1869
1870 state = MsiQueryFeatureStateA(prodcode, "feature");
1871 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1872
1873 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"apple", 6);
1874 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1875
1876 state = MsiQueryFeatureStateA(prodcode, "feature");
1877 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1878
1879 res = RegSetValueExA(compkey2, prod_squashed, 0, REG_SZ, (const BYTE *)"orange", 7);
1880 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1881
1882 state = MsiQueryFeatureStateA(prodcode, "feature");
1883 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1884
1885 RegDeleteValueA(compkey, prod_squashed);
1886 RegDeleteValueA(compkey2, prod_squashed);
1887 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
1888 RegDeleteKeyExA(compkey2, "", access & KEY_WOW64_64KEY, 0);
1889 RegDeleteValueA(localkey, "feature");
1890 RegDeleteValueA(userkey, "feature");
1891 RegDeleteKeyExA(userkey, "", access & KEY_WOW64_64KEY, 0);
1892 RegCloseKey(compkey);
1893 RegCloseKey(compkey2);
1894 RegCloseKey(localkey);
1895 RegCloseKey(userkey);
1896
1897 /* MSIINSTALLCONTEXT_MACHINE */
1898
1899 lstrcpyA(keypath, "Software\\Classes\\Installer\\Features\\");
1900 lstrcatA(keypath, prod_squashed);
1901
1902 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &userkey, NULL);
1903 if (res == ERROR_ACCESS_DENIED)
1904 {
1905 skip( "insufficient rights\n" );
1906 LocalFree( usersid );
1907 return;
1908 }
1909 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1910
1911 /* feature key exists */
1912 state = MsiQueryFeatureStateA(prodcode, "feature");
1913 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
1914
1915 res = RegSetValueExA(userkey, "feature", 0, REG_SZ, (const BYTE *)"", 1);
1916 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1917
1918 /* feature value exists */
1919 state = MsiQueryFeatureStateA(prodcode, "feature");
1920 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1921
1922 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1923 lstrcatA(keypath, "S-1-5-18\\Products\\");
1924 lstrcatA(keypath, prod_squashed);
1925 lstrcatA(keypath, "\\Features");
1926
1927 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &localkey, NULL);
1928 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1929
1930 /* userdata features key exists */
1931 state = MsiQueryFeatureStateA(prodcode, "feature");
1932 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1933
1934 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaa", 20);
1935 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1936
1937 state = MsiQueryFeatureStateA(prodcode, "feature");
1938 ok(state == INSTALLSTATE_BADCONFIG, "Expected INSTALLSTATE_BADCONFIG, got %d\n", state);
1939
1940 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaa", 21);
1941 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1942
1943 state = MsiQueryFeatureStateA(prodcode, "feature");
1944 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1945
1946 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)"aaaaaaaaaaaaaaaaaaaaa", 22);
1947 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1948
1949 state = MsiQueryFeatureStateA(prodcode, "feature");
1950 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1951
1952 res = RegSetValueExA(localkey, "feature", 0, REG_SZ, (const BYTE *)comp_base85, 41);
1953 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1954
1955 state = MsiQueryFeatureStateA(prodcode, "feature");
1956 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1957
1958 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1959 lstrcatA(keypath, "S-1-5-18\\Components\\");
1960 lstrcatA(keypath, comp_squashed);
1961
1962 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
1963 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1964
1965 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
1966 lstrcatA(keypath, "S-1-5-18\\Components\\");
1967 lstrcatA(keypath, comp_squashed2);
1968
1969 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey2, NULL);
1970 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1971
1972 state = MsiQueryFeatureStateA(prodcode, "feature");
1973 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1974
1975 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 1);
1976 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1977
1978 state = MsiQueryFeatureStateA(prodcode, "feature");
1979 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1980
1981 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"apple", 6);
1982 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1983
1984 state = MsiQueryFeatureStateA(prodcode, "feature");
1985 ok(state == INSTALLSTATE_ADVERTISED, "Expected INSTALLSTATE_ADVERTISED, got %d\n", state);
1986
1987 res = RegSetValueExA(compkey2, prod_squashed, 0, REG_SZ, (const BYTE *)"orange", 7);
1988 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
1989
1990 state = MsiQueryFeatureStateA(prodcode, "feature");
1991 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
1992
1993 RegDeleteValueA(compkey, prod_squashed);
1994 RegDeleteValueA(compkey2, prod_squashed);
1995 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
1996 RegDeleteKeyExA(compkey2, "", access & KEY_WOW64_64KEY, 0);
1997 RegDeleteValueA(localkey, "feature");
1998 RegDeleteValueA(userkey, "feature");
1999 RegDeleteKeyExA(userkey, "", access & KEY_WOW64_64KEY, 0);
2000 RegCloseKey(compkey);
2001 RegCloseKey(compkey2);
2002 RegCloseKey(localkey);
2003 RegCloseKey(userkey);
2004 LocalFree(usersid);
2005}
2006
2008{
2009 HKEY compkey, prodkey;
2010 CHAR prodcode[MAX_PATH];
2011 CHAR prod_squashed[MAX_PATH];
2012 CHAR component[MAX_PATH];
2013 CHAR comp_base85[MAX_PATH];
2014 CHAR comp_squashed[MAX_PATH];
2015 CHAR keypath[MAX_PATH];
2017 LPSTR usersid;
2018 LONG res;
2019 UINT r;
2021 DWORD error;
2022
2023 static const INSTALLSTATE MAGIC_ERROR = 0xdeadbeef;
2024
2025 create_test_guid(prodcode, prod_squashed);
2026 compose_base85_guid(component, comp_base85, comp_squashed);
2027 usersid = get_user_sid();
2028
2029 if (is_wow64)
2031
2032 /* NULL szProductCode */
2033 state = MAGIC_ERROR;
2034 SetLastError(0xdeadbeef);
2036 error = GetLastError();
2037 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2038 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2039 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2040
2041 /* empty szProductCode */
2042 state = MAGIC_ERROR;
2043 SetLastError(0xdeadbeef);
2045 error = GetLastError();
2046 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2047 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2048 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2049
2050 /* random szProductCode */
2051 state = MAGIC_ERROR;
2052 SetLastError(0xdeadbeef);
2054 error = GetLastError();
2055 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2056 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2057 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2058
2059 /* GUID-length szProductCode */
2060 state = MAGIC_ERROR;
2061 SetLastError(0xdeadbeef);
2062 r = MsiQueryComponentStateA("DJANE93KNDNAS-2KN2NR93KMN3LN13=L1N3KDE", NULL, MSIINSTALLCONTEXT_MACHINE, component, &state);
2063 error = GetLastError();
2064 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2065 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2066 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2067
2068 /* GUID-length with brackets */
2069 state = MAGIC_ERROR;
2070 SetLastError(0xdeadbeef);
2071 r = MsiQueryComponentStateA("{JANE93KNDNAS-2KN2NR93KMN3LN13=L1N3KD}", NULL, MSIINSTALLCONTEXT_MACHINE, component, &state);
2072 error = GetLastError();
2073 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2074 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2075 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2076
2077 /* actual GUID */
2078 state = MAGIC_ERROR;
2079 SetLastError(0xdeadbeef);
2081 error = GetLastError();
2082 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2083 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2084 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2085
2086 state = MAGIC_ERROR;
2087 SetLastError(0xdeadbeef);
2089 error = GetLastError();
2090 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2091 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2092 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2093
2094 lstrcpyA(keypath, "Software\\Classes\\Installer\\Products\\");
2095 lstrcatA(keypath, prod_squashed);
2096
2097 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2098 if (res == ERROR_ACCESS_DENIED)
2099 {
2100 skip("Not enough rights to perform tests\n");
2101 LocalFree(usersid);
2102 return;
2103 }
2104 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2105
2106 state = MAGIC_ERROR;
2107 SetLastError(0xdeadbeef);
2109 error = GetLastError();
2110 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2111 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2112 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2113
2114 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2115 RegCloseKey(prodkey);
2116
2117 /* create local system product key */
2118 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products\\");
2119 lstrcatA(keypath, prod_squashed);
2120 lstrcatA(keypath, "\\InstallProperties");
2121
2122 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2123 if (res == ERROR_ACCESS_DENIED)
2124 {
2125 skip("Not enough rights to perform tests\n");
2126 LocalFree(usersid);
2127 return;
2128 }
2129 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2130
2131 /* local system product key exists */
2132 state = MAGIC_ERROR;
2134 error = GetLastError();
2135 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2136 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2137 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2138
2139 res = RegSetValueExA(prodkey, "LocalPackage", 0, REG_SZ, (const BYTE *)"msitest.msi", 11);
2140 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2141
2142 /* LocalPackage value exists */
2143 state = MAGIC_ERROR;
2144 SetLastError(0xdeadbeef);
2146 error = GetLastError();
2147 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2148 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2149 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2150
2151 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components\\");
2152 lstrcatA(keypath, comp_squashed);
2153
2154 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2155 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2156
2157 /* component key exists */
2158 state = MAGIC_ERROR;
2159 SetLastError(0xdeadbeef);
2161 error = GetLastError();
2162 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2163 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2164 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2165
2166 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 0);
2167 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2168
2169 /* component\product exists */
2170 state = MAGIC_ERROR;
2171 SetLastError(0xdeadbeef);
2173 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2174 error = GetLastError();
2176 "Expected INSTALLSTATE_NOTUSED or INSTALLSTATE_LOCAL, got %d\n", state);
2177 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2178
2179 /* NULL component, product exists */
2180 state = MAGIC_ERROR;
2181 SetLastError(0xdeadbeef);
2183 error = GetLastError();
2184 ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", r);
2185 ok(state == MAGIC_ERROR, "Expected state not changed, got %d\n", state);
2186 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2187
2188 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"hi", 2);
2189 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2190
2191 /* INSTALLSTATE_LOCAL */
2192 state = MAGIC_ERROR;
2193 SetLastError(0xdeadbeef);
2195 error = GetLastError();
2196 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2197 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2198 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2199
2200 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01\\", 4);
2201 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2202
2203 /* INSTALLSTATE_SOURCE */
2204 state = MAGIC_ERROR;
2205 SetLastError(0xdeadbeef);
2207 error = GetLastError();
2208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2209 ok(state == INSTALLSTATE_SOURCE, "Expected INSTALLSTATE_SOURCE, got %d\n", state);
2210 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2211
2212 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01", 3);
2213 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2214
2215 /* bad INSTALLSTATE_SOURCE */
2216 state = MAGIC_ERROR;
2217 SetLastError(0xdeadbeef);
2219 error = GetLastError();
2220 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2221 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2222 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2223
2224 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01a", 4);
2225 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2226
2227 /* INSTALLSTATE_SOURCE */
2228 state = MAGIC_ERROR;
2229 SetLastError(0xdeadbeef);
2231 error = GetLastError();
2232 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2233 ok(state == INSTALLSTATE_SOURCE, "Expected INSTALLSTATE_SOURCE, got %d\n", state);
2234 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2235
2236 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"01:", 4);
2237 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2238
2239 /* registry component */
2240 state = MAGIC_ERROR;
2241 SetLastError(0xdeadbeef);
2243 error = GetLastError();
2244 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2245 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2246 ok(error == 0xdeadbeef, "expected 0xdeadbeef, got %lu\n", error);
2247
2248 RegDeleteValueA(prodkey, "LocalPackage");
2249 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2250 RegDeleteValueA(compkey, prod_squashed);
2251 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2252 RegCloseKey(prodkey);
2253 RegCloseKey(compkey);
2254
2255 /* MSIINSTALLCONTEXT_USERUNMANAGED */
2256
2257 state = MAGIC_ERROR;
2259 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2260 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2261
2262 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Products\\");
2263 lstrcatA(keypath, prod_squashed);
2264
2265 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &prodkey);
2266 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2267
2268 state = MAGIC_ERROR;
2270 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2271 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2272
2273 RegDeleteKeyA(prodkey, "");
2274 RegCloseKey(prodkey);
2275
2276 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
2277 lstrcatA(keypath, usersid);
2278 lstrcatA(keypath, "\\Products\\");
2279 lstrcatA(keypath, prod_squashed);
2280 lstrcatA(keypath, "\\InstallProperties");
2281
2282 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2283 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2284
2285 res = RegSetValueExA(prodkey, "LocalPackage", 0, REG_SZ, (const BYTE *)"msitest.msi", 11);
2286 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2287
2288 RegCloseKey(prodkey);
2289
2290 state = MAGIC_ERROR;
2292 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2293 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2294
2295 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
2296 lstrcatA(keypath, usersid);
2297 lstrcatA(keypath, "\\Components\\");
2298 lstrcatA(keypath, comp_squashed);
2299
2300 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2301 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2302
2303 /* component key exists */
2304 state = MAGIC_ERROR;
2306 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2307 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2308
2309 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"", 0);
2310 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2311
2312 /* component\product exists */
2313 state = MAGIC_ERROR;
2315 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2317 "Expected INSTALLSTATE_NOTUSED or INSTALLSTATE_LOCAL, got %d\n", state);
2318
2319 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"hi", 2);
2320 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2321
2322 state = MAGIC_ERROR;
2324 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2325 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2326
2327 /* MSIINSTALLCONTEXT_USERMANAGED */
2328
2329 state = MAGIC_ERROR;
2331 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2332 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2333
2334 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Products\\");
2335 lstrcatA(keypath, prod_squashed);
2336
2337 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &prodkey);
2338 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2339
2340 state = MAGIC_ERROR;
2342 ok(r == ERROR_UNKNOWN_PRODUCT, "Expected ERROR_UNKNOWN_PRODUCT, got %d\n", r);
2343 ok(state == MAGIC_ERROR, "Expected 0xdeadbeef, got %d\n", state);
2344
2345 RegDeleteKeyA(prodkey, "");
2346 RegCloseKey(prodkey);
2347
2348 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\Managed\\");
2349 lstrcatA(keypath, usersid);
2350 lstrcatA(keypath, "\\Installer\\Products\\");
2351 lstrcatA(keypath, prod_squashed);
2352
2353 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2354 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2355
2356 state = MAGIC_ERROR;
2358 ok(r == ERROR_UNKNOWN_COMPONENT, "Expected ERROR_UNKNOWN_COMPONENT, got %d\n", r);
2359 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2360
2361 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2362 RegCloseKey(prodkey);
2363
2364 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\");
2365 lstrcatA(keypath, usersid);
2366 lstrcatA(keypath, "\\Products\\");
2367 lstrcatA(keypath, prod_squashed);
2368 lstrcatA(keypath, "\\InstallProperties");
2369
2370 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2371 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2372
2373 res = RegSetValueExA(prodkey, "ManagedLocalPackage", 0, REG_SZ, (const BYTE *)"msitest.msi", 11);
2374 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2375
2376 state = MAGIC_ERROR;
2378 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2379 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2380
2381 RegDeleteValueA(prodkey, "LocalPackage");
2382 RegDeleteValueA(prodkey, "ManagedLocalPackage");
2383 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2384 RegDeleteValueA(compkey, prod_squashed);
2385 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2386 RegCloseKey(prodkey);
2387 RegCloseKey(compkey);
2388 LocalFree(usersid);
2389}
2390
2392{
2393 HKEY compkey, prodkey, installprop;
2394 CHAR prodcode[MAX_PATH];
2395 CHAR prod_squashed[MAX_PATH];
2396 CHAR component[MAX_PATH];
2397 CHAR comp_base85[MAX_PATH];
2398 CHAR comp_squashed[MAX_PATH];
2399 CHAR keypath[MAX_PATH];
2402 LPSTR usersid;
2403 DWORD size, val;
2405 LONG res;
2406
2407 create_test_guid(prodcode, prod_squashed);
2408 compose_base85_guid(component, comp_base85, comp_squashed);
2409 usersid = get_user_sid();
2410
2411 if (is_wow64)
2413
2414 /* NULL szProduct */
2415 size = MAX_PATH;
2416 state = MsiGetComponentPathA(NULL, component, path, &size);
2417 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
2418 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2419
2420 /* NULL szComponent */
2421 size = MAX_PATH;
2422 state = MsiGetComponentPathA(prodcode, NULL, path, &size);
2423 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
2424 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2425
2426 size = MAX_PATH;
2428 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
2429 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2430
2431 /* NULL lpPathBuf */
2432 size = MAX_PATH;
2433 state = MsiGetComponentPathA(prodcode, component, NULL, &size);
2434 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2435 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2436
2437 size = MAX_PATH;
2438 state = MsiLocateComponentA(component, NULL, &size);
2439 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2440 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2441
2442 /* NULL pcchBuf */
2443 size = MAX_PATH;
2444 state = MsiGetComponentPathA(prodcode, component, path, NULL);
2445 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
2446 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2447
2448 size = MAX_PATH;
2449 state = MsiLocateComponentA(component, path, NULL);
2450 ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state);
2451 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2452
2453 /* all params valid */
2454 size = MAX_PATH;
2455 state = MsiGetComponentPathA(prodcode, component, path, &size);
2456 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2457 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2458
2459 size = MAX_PATH;
2460 state = MsiLocateComponentA(component, path, &size);
2461 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2462 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2463
2464 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2465 lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Components\\");
2466 lstrcatA(keypath, comp_squashed);
2467
2468 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2469 if (res == ERROR_ACCESS_DENIED)
2470 {
2471 skip("Not enough rights to perform tests\n");
2472 LocalFree(usersid);
2473 return;
2474 }
2475 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2476
2477 /* local system component key exists */
2478 size = MAX_PATH;
2479 state = MsiGetComponentPathA(prodcode, component, path, &size);
2480 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2481 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2482
2483 size = MAX_PATH;
2484 state = MsiLocateComponentA(component, path, &size);
2485 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2486 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2487
2488 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10);
2489 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2490
2491 /* product value exists */
2492 path[0] = 0;
2493 size = MAX_PATH;
2494 state = MsiGetComponentPathA(prodcode, component, path, &size);
2495 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2496 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2497 ok(size == 10, "Expected 10, got %lu\n", size);
2498
2499 path[0] = 0;
2500 size = MAX_PATH;
2501 state = MsiLocateComponentA(component, path, &size);
2502 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2503 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2504 ok(size == 10, "Expected 10, got %lu\n", size);
2505
2506 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2507 lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\");
2508 lstrcatA(keypath, prod_squashed);
2509 lstrcatA(keypath, "\\InstallProperties");
2510
2511 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &installprop, NULL);
2512 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2513
2514 val = 1;
2515 res = RegSetValueExA(installprop, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&val, sizeof(DWORD));
2516 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2517
2518 /* install properties key exists */
2519 path[0] = 0;
2520 size = MAX_PATH;
2521 state = MsiGetComponentPathA(prodcode, component, path, &size);
2522 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2523 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2524 ok(size == 10, "Expected 10, got %lu\n", size);
2525
2526 path[0] = 0;
2527 size = MAX_PATH;
2528 state = MsiLocateComponentA(component, path, &size);
2529 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2530 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2531 ok(size == 10, "Expected 10, got %lu\n", size);
2532
2533 create_file("C:\\imapath", 11);
2534
2535 /* file exists */
2536 path[0] = 'a';
2537 size = 0;
2538 state = MsiGetComponentPathA(prodcode, component, path, &size);
2539 ok(state == INSTALLSTATE_MOREDATA, "Expected INSTALLSTATE_MOREDATA, got %d\n", state);
2540 ok(path[0] == 'a', "got %s\n", path);
2541 ok(size == 10, "Expected 10, got %lu\n", size);
2542
2543 path[0] = 0;
2544 size = MAX_PATH;
2545 state = MsiGetComponentPathA(prodcode, component, path, &size);
2546 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2547 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2548 ok(size == 10, "Expected 10, got %lu\n", size);
2549
2550 size = 0;
2551 path[0] = 'a';
2552 state = MsiLocateComponentA(component, path, &size);
2553 ok(state == INSTALLSTATE_MOREDATA, "Expected INSTALLSTATE_MOREDATA, got %d\n", state);
2554 ok(path[0] == 'a', "got %s\n", path);
2555 ok(size == 10, "Expected 10, got %lu\n", size);
2556
2557 path[0] = 0;
2558 size = MAX_PATH;
2559 state = MsiLocateComponentA(component, path, &size);
2560 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2561 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2562 ok(size == 10, "Expected 10, got %lu\n", size);
2563
2564 RegDeleteValueA(compkey, prod_squashed);
2565 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2566 RegDeleteValueA(installprop, "WindowsInstaller");
2567 RegDeleteKeyExA(installprop, "", access & KEY_WOW64_64KEY, 0);
2568 RegCloseKey(compkey);
2569 RegCloseKey(installprop);
2570 DeleteFileA("C:\\imapath");
2571
2572 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2573 lstrcatA(keypath, "Installer\\UserData\\");
2574 lstrcatA(keypath, usersid);
2575 lstrcatA(keypath, "\\Components\\");
2576 lstrcatA(keypath, comp_squashed);
2577
2578 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2579 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2580
2581 /* user managed component key exists */
2582 size = MAX_PATH;
2583 state = MsiGetComponentPathA(prodcode, component, path, &size);
2584 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2585 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2586
2587 size = MAX_PATH;
2588 state = MsiLocateComponentA(component, path, &size);
2589 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2590 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2591
2592 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10);
2593 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2594
2595 /* product value exists */
2596 path[0] = 0;
2597 size = MAX_PATH;
2598 state = MsiGetComponentPathA(prodcode, component, path, &size);
2599 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2600 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2601 ok(size == 10, "Expected 10, got %lu\n", size);
2602
2603 path[0] = 0;
2604 size = MAX_PATH;
2605 state = MsiLocateComponentA(component, path, &size);
2606 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2607 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2608 ok(size == 10, "Expected 10, got %lu\n", size);
2609
2610 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2611 lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\");
2612 lstrcatA(keypath, prod_squashed);
2613 lstrcatA(keypath, "\\InstallProperties");
2614
2615 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &installprop, NULL);
2616 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2617
2618 val = 1;
2619 res = RegSetValueExA(installprop, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&val, sizeof(DWORD));
2620 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2621
2622 /* install properties key exists */
2623 path[0] = 0;
2624 size = MAX_PATH;
2625 state = MsiGetComponentPathA(prodcode, component, path, &size);
2626 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2627 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2628 ok(size == 10, "Expected 10, got %lu\n", size);
2629
2630 path[0] = 0;
2631 size = MAX_PATH;
2632 state = MsiLocateComponentA(component, path, &size);
2633 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2634 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2635 ok(size == 10, "Expected 10, got %lu\n", size);
2636
2637 create_file("C:\\imapath", 11);
2638
2639 /* file exists */
2640 path[0] = 0;
2641 size = MAX_PATH;
2642 state = MsiGetComponentPathA(prodcode, component, path, &size);
2643 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2644 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2645 ok(size == 10, "Expected 10, got %lu\n", size);
2646
2647 path[0] = 0;
2648 size = MAX_PATH;
2649 state = MsiLocateComponentA(component, path, &size);
2650 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2651 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2652 ok(size == 10, "Expected 10, got %lu\n", size);
2653
2654 RegDeleteValueA(compkey, prod_squashed);
2655 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2656 RegDeleteValueA(installprop, "WindowsInstaller");
2657 RegDeleteKeyExA(installprop, "", access & KEY_WOW64_64KEY, 0);
2658 RegCloseKey(compkey);
2659 RegCloseKey(installprop);
2660 DeleteFileA("C:\\imapath");
2661
2662 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2663 lstrcatA(keypath, "Installer\\Managed\\");
2664 lstrcatA(keypath, usersid);
2665 lstrcatA(keypath, "\\Installer\\Products\\");
2666 lstrcatA(keypath, prod_squashed);
2667
2668 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2669 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2670
2671 /* user managed product key exists */
2672 size = MAX_PATH;
2673 state = MsiGetComponentPathA(prodcode, component, path, &size);
2674 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2675 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2676
2677 size = MAX_PATH;
2678 state = MsiLocateComponentA(component, path, &size);
2679 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2680 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2681
2682 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2683 lstrcatA(keypath, "Installer\\UserData\\");
2684 lstrcatA(keypath, usersid);
2685 lstrcatA(keypath, "\\Components\\");
2686 lstrcatA(keypath, comp_squashed);
2687
2688 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2689 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2690
2691 /* user managed component key exists */
2692 size = MAX_PATH;
2693 state = MsiGetComponentPathA(prodcode, component, path, &size);
2694 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2695 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2696
2697 size = MAX_PATH;
2698 state = MsiLocateComponentA(component, path, &size);
2699 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2700 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2701
2702 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10);
2703 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2704
2705 /* product value exists */
2706 path[0] = 0;
2707 size = MAX_PATH;
2708 state = MsiGetComponentPathA(prodcode, component, path, &size);
2709 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2710 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2711 ok(size == 10, "Expected 10, got %lu\n", size);
2712
2713 path[0] = 0;
2714 size = MAX_PATH;
2715 state = MsiLocateComponentA(component, path, &size);
2716 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2717 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2718 ok(size == 10, "Expected 10, got %lu\n", size);
2719
2720 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2721 lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\");
2722 lstrcatA(keypath, prod_squashed);
2723 lstrcatA(keypath, "\\InstallProperties");
2724
2725 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &installprop, NULL);
2726 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2727
2728 val = 1;
2729 res = RegSetValueExA(installprop, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&val, sizeof(DWORD));
2730 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2731
2732 /* install properties key exists */
2733 path[0] = 0;
2734 size = MAX_PATH;
2735 state = MsiGetComponentPathA(prodcode, component, path, &size);
2736 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2737 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2738 ok(size == 10, "Expected 10, got %lu\n", size);
2739
2740 path[0] = 0;
2741 size = MAX_PATH;
2742 state = MsiLocateComponentA(component, path, &size);
2743 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2744 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2745 ok(size == 10, "Expected 10, got %lu\n", size);
2746
2747 create_file("C:\\imapath", 11);
2748
2749 /* file exists */
2750 path[0] = 0;
2751 size = MAX_PATH;
2752 state = MsiGetComponentPathA(prodcode, component, path, &size);
2753 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2754 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2755 ok(size == 10, "Expected 10, got %lu\n", size);
2756
2757 path[0] = 0;
2758 size = MAX_PATH;
2759 state = MsiLocateComponentA(component, path, &size);
2760 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2761 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2762 ok(size == 10, "Expected 10, got %lu\n", size);
2763
2764 RegDeleteValueA(compkey, prod_squashed);
2765 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2766 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2767 RegDeleteValueA(installprop, "WindowsInstaller");
2768 RegDeleteKeyExA(installprop, "", access & KEY_WOW64_64KEY, 0);
2769 RegCloseKey(prodkey);
2770 RegCloseKey(compkey);
2771 RegCloseKey(installprop);
2772 DeleteFileA("C:\\imapath");
2773
2774 lstrcpyA(keypath, "Software\\Microsoft\\Installer\\Products\\");
2775 lstrcatA(keypath, prod_squashed);
2776
2777 res = RegCreateKeyA(HKEY_CURRENT_USER, keypath, &prodkey);
2778 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2779
2780 /* user unmanaged product key exists */
2781 size = MAX_PATH;
2782 state = MsiGetComponentPathA(prodcode, component, path, &size);
2783 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2784 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2785
2786 size = MAX_PATH;
2787 state = MsiLocateComponentA(component, path, &size);
2788 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2789 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2790
2791 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2792 lstrcatA(keypath, "Installer\\UserData\\");
2793 lstrcatA(keypath, usersid);
2794 lstrcatA(keypath, "\\Components\\");
2795 lstrcatA(keypath, comp_squashed);
2796
2797 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2798 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2799
2800 /* user unmanaged component key exists */
2801 size = MAX_PATH;
2802 state = MsiGetComponentPathA(prodcode, component, path, &size);
2803 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2804 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2805
2806 size = MAX_PATH;
2807 state = MsiLocateComponentA(component, path, &size);
2808 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2809 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2810
2811 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10);
2812 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2813
2814 /* product value exists */
2815 path[0] = 0;
2816 size = MAX_PATH;
2817 state = MsiGetComponentPathA(prodcode, component, path, &size);
2818 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2819 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2820 ok(size == 10, "Expected 10, got %lu\n", size);
2821
2822 path[0] = 0;
2823 size = MAX_PATH;
2824 state = MsiLocateComponentA(component, path, &size);
2825 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2826 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2827 ok(size == 10, "Expected 10, got %lu\n", size);
2828
2829 create_file("C:\\imapath", 11);
2830
2831 /* file exists */
2832 path[0] = 0;
2833 size = MAX_PATH;
2834 state = MsiGetComponentPathA(prodcode, component, path, &size);
2835 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2836 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2837 ok(size == 10, "Expected 10, got %lu\n", size);
2838
2839 path[0] = 0;
2840 size = MAX_PATH;
2841 state = MsiLocateComponentA(component, path, &size);
2842 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2843 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2844 ok(size == 10, "Expected 10, got %lu\n", size);
2845
2846 RegDeleteValueA(compkey, prod_squashed);
2847 RegDeleteKeyA(prodkey, "");
2848 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2849 RegCloseKey(prodkey);
2850 RegCloseKey(compkey);
2851 DeleteFileA("C:\\imapath");
2852
2853 lstrcpyA(keypath, "Software\\Classes\\Installer\\Products\\");
2854 lstrcatA(keypath, prod_squashed);
2855
2856 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &prodkey, NULL);
2857 if (res == ERROR_ACCESS_DENIED)
2858 {
2859 skip( "insufficient rights\n" );
2860 LocalFree( usersid );
2861 return;
2862 }
2863 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2864
2865 /* local classes product key exists */
2866 size = MAX_PATH;
2867 state = MsiGetComponentPathA(prodcode, component, path, &size);
2868 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2869 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2870
2871 size = MAX_PATH;
2872 state = MsiLocateComponentA(component, path, &size);
2873 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2874 ok(size == MAX_PATH, "Expected size to be unchanged, got %lu\n", size);
2875
2876 lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\");
2877 lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Components\\");
2878 lstrcatA(keypath, comp_squashed);
2879
2880 res = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, access, NULL, &compkey, NULL);
2881 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2882
2883 /* local user component key exists */
2884 size = MAX_PATH;
2885 state = MsiGetComponentPathA(prodcode, component, path, &size);
2886 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2887 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2888
2889 size = MAX_PATH;
2890 state = MsiLocateComponentA(component, path, &size);
2891 ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state);
2892 ok(size == MAX_PATH, "Expected size to be unchanged, got %ld\n", size);
2893
2894 res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10);
2895 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", res);
2896
2897 /* product value exists */
2898 path[0] = 0;
2899 size = MAX_PATH;
2900 state = MsiGetComponentPathA(prodcode, component, path, &size);
2901 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2902 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2903 ok(size == 10, "Expected 10, got %lu\n", size);
2904
2905 path[0] = 0;
2906 size = MAX_PATH;
2907 state = MsiLocateComponentA(component, path, &size);
2908 ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state);
2909 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2910 ok(size == 10, "Expected 10, got %lu\n", size);
2911
2912 create_file("C:\\imapath", 11);
2913
2914 /* file exists */
2915 path[0] = 0;
2916 size = MAX_PATH;
2917 state = MsiGetComponentPathA(prodcode, component, path, &size);
2918 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2919 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2920 ok(size == 10, "Expected 10, got %lu\n", size);
2921
2922 path[0] = 0;
2923 size = MAX_PATH;
2924 state = MsiLocateComponentA(component, path, &size);
2925 ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state);
2926 ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path);
2927 ok(size == 10, "Expected 10, got %lu\n", size);
2928
2929 RegDeleteValueA(compkey, prod_squashed);
2930 RegDeleteKeyExA(prodkey, "", access & KEY_WOW64_64KEY, 0);
2931 RegDeleteKeyExA(compkey, "", access & KEY_WOW64_64KEY, 0);
2932 RegCloseKey(prodkey);
2933 RegCloseKey(compkey);
2934 DeleteFileA("C:\\imapath");
2935 LocalFree(usersid);
2936}
2937
2939{
2940 HKEY key_comp, key_installprop, key_prod;
2941 char prod[MAX_PATH], prod_squashed[MAX_PATH];
2942 char comp[MAX_PATH], comp_base85[MAX_PATH], comp_squashed[MAX_PATH];
2943 char path[MAX_PATH], path_key[MAX_PATH], *usersid;
2945 DWORD size, val;
2947 LONG res;
2948
2950
2951 create_test_guid( prod, prod_squashed );
2952 compose_base85_guid( comp, comp_base85, comp_squashed );
2953 usersid = get_user_sid();
2954
2955 /* NULL product */
2956 size = MAX_PATH;
2958 ok( state == INSTALLSTATE_INVALIDARG, "got %d\n", state );
2959 todo_wine ok( !size, "got %lu\n", size );
2960
2961 /* NULL component */
2962 size = MAX_PATH;
2964 ok( state == INSTALLSTATE_INVALIDARG, "got %d\n", state );
2965 todo_wine ok( !size, "got %lu\n", size );
2966
2967 /* non-NULL usersid, MSIINSTALLCONTEXT_MACHINE */
2968 size = MAX_PATH;
2970 ok( state == INSTALLSTATE_INVALIDARG, "got %d\n", state );
2971 todo_wine ok( !size, "got %lu\n", size );
2972
2973 /* NULL buf */
2974 size = MAX_PATH;
2976 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
2977 todo_wine ok( size == MAX_PATH * 2, "got %lu\n", size );
2978
2979 /* NULL buflen */
2980 size = MAX_PATH;
2982 ok( state == INSTALLSTATE_INVALIDARG, "got %d\n", state );
2983 ok( size == MAX_PATH, "got %lu\n", size );
2984
2985 /* all params valid */
2986 size = MAX_PATH;
2988 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
2989 todo_wine ok( !size, "got %lu\n", size );
2990
2991 lstrcpyA( path_key, "Software\\Microsoft\\Windows\\CurrentVersion\\" );
2992 lstrcatA( path_key, "Installer\\UserData\\S-1-5-18\\Components\\" );
2993 lstrcatA( path_key, comp_squashed );
2994
2995 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, path_key, 0, NULL, 0, access, NULL, &key_comp, NULL );
2996 if (res == ERROR_ACCESS_DENIED)
2997 {
2998 skip( "insufficient rights\n" );
2999 LocalFree( usersid );
3000 return;
3001 }
3002 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3003
3004 /* local system component key exists */
3005 size = MAX_PATH;
3007 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
3008
3009 res = RegSetValueExA( key_comp, prod_squashed, 0, REG_SZ, (const BYTE *)"c:\\testcomponentpath", 20 );
3010 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3011
3012 /* product value exists */
3013 path[0] = 0;
3014 size = MAX_PATH;
3016 ok( state == INSTALLSTATE_ABSENT, "got %d\n", state );
3017 ok( !lstrcmpA( path, "c:\\testcomponentpath" ), "got %s\n", path );
3018 ok( size == 20, "got %lu\n", size );
3019
3020 lstrcpyA( path_key, "Software\\Microsoft\\Windows\\CurrentVersion\\" );
3021 lstrcatA( path_key, "Installer\\UserData\\S-1-5-18\\Products\\" );
3022 lstrcatA( path_key, prod_squashed );
3023 lstrcatA( path_key, "\\InstallProperties" );
3024
3025 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, path_key, 0, NULL, 0, access, NULL, &key_installprop, NULL );
3026 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3027
3028 val = 1;
3029 res = RegSetValueExA( key_installprop, "WindowsInstaller", 0, REG_DWORD, (const BYTE *)&val, sizeof(val) );
3030 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3031
3032 /* install properties key exists */
3033 path[0] = 0;
3034 size = MAX_PATH;
3036 ok( state == INSTALLSTATE_ABSENT, "got %d\n", state );
3037 ok( !lstrcmpA( path, "c:\\testcomponentpath"), "got %s\n", path );
3038 ok( size == 20, "got %lu\n", size );
3039
3040 create_file( "c:\\testcomponentpath", 21 );
3041
3042 /* file exists */
3043 path[0] = 0;
3044 size = 0;
3046 ok( state == INSTALLSTATE_MOREDATA, "got %d\n", state );
3047 ok( !path[0], "got %s\n", path );
3048 todo_wine ok( size == 40, "got %lu\n", size );
3049
3050 path[0] = 0;
3051 size = MAX_PATH;
3053 ok( state == INSTALLSTATE_LOCAL, "got %d\n", state );
3054 ok( !lstrcmpA( path, "c:\\testcomponentpath" ), "got %s\n", path );
3055 ok( size == 20, "got %lu\n", size );
3056
3057 RegDeleteValueA( key_comp, prod_squashed );
3058 RegDeleteKeyExA( key_comp, "", access & KEY_WOW64_64KEY, 0 );
3059 RegDeleteValueA( key_installprop, "WindowsInstaller" );
3060 RegDeleteKeyExA( key_installprop, "", access & KEY_WOW64_64KEY, 0 );
3061 RegCloseKey( key_comp );
3062 RegCloseKey( key_installprop );
3063 DeleteFileA( "c:\\testcomponentpath" );
3064
3065 lstrcpyA( path_key, "Software\\Microsoft\\Installer\\Products\\" );
3066 lstrcatA( path_key, prod_squashed );
3067
3068 res = RegCreateKeyA( HKEY_CURRENT_USER, path_key, &key_prod );
3069 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3070
3071 /* user unmanaged product key exists */
3072 size = MAX_PATH;
3074 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
3075 todo_wine ok(!size, "got %lu\n", size);
3076
3077 lstrcpyA( path_key, "Software\\Microsoft\\Windows\\CurrentVersion\\" );
3078 lstrcatA( path_key, "Installer\\UserData\\" );
3079 lstrcatA( path_key, usersid );
3080 lstrcatA( path_key, "\\Components\\" );
3081 lstrcatA( path_key, comp_squashed );
3082
3083 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, path_key, 0, NULL, 0, access, NULL, &key_comp, NULL );
3084 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3085
3086 /* user unmanaged component key exists */
3087 size = MAX_PATH;
3089 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
3090 todo_wine ok(!size, "got %lu\n", size);
3091
3092 res = RegSetValueExA( key_comp, prod_squashed, 0, REG_SZ, (const BYTE *)"c:\\testcomponentpath", 20 );
3093 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3094
3095 /* product value exists */
3096 path[0] = 0;
3097 size = MAX_PATH;
3099 ok( state == INSTALLSTATE_ABSENT, "got %d\n", state );
3100 ok( !lstrcmpA( path, "c:\\testcomponentpath"), "got %s\n", path );
3101 ok( size == 20, "got %lu\n", size );
3102
3103 create_file( "c:\\testcomponentpath", 21 );
3104
3105 /* file exists */
3106 path[0] = 0;
3107 size = MAX_PATH;
3109 ok( state == INSTALLSTATE_LOCAL, "got %d\n", state );
3110 ok( !lstrcmpA( path, "c:\\testcomponentpath"), "got %s\n", path );
3111 ok( size == 20, "got %lu\n", size );
3112
3113 RegDeleteValueA( key_comp, prod_squashed );
3114 RegDeleteKeyA( key_prod, "" );
3115 RegDeleteKeyExA( key_comp, "", access & KEY_WOW64_64KEY, 0 );
3116 RegCloseKey( key_prod );
3117 RegCloseKey( key_comp );
3118 DeleteFileA( "c:\\testcomponentpath" );
3119
3120 lstrcpyA( path_key, "Software\\Microsoft\\Windows\\CurrentVersion\\" );
3121 lstrcatA( path_key, "Installer\\Managed\\" );
3122 lstrcatA( path_key, usersid );
3123 lstrcatA( path_key, "\\Installer\\Products\\" );
3124 lstrcatA( path_key, prod_squashed );
3125
3126 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, path_key, 0, NULL, 0, access, NULL, &key_prod, NULL );
3127 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3128
3129 /* user managed product key exists */
3130 size = MAX_PATH;
3132 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
3133
3134 lstrcpyA( path_key, "Software\\Microsoft\\Windows\\CurrentVersion\\" );
3135 lstrcatA( path_key, "Installer\\UserData\\" );
3136 lstrcatA( path_key, usersid );
3137 lstrcatA( path_key, "\\Components\\" );
3138 lstrcatA( path_key, comp_squashed );
3139
3140 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, path_key, 0, NULL, 0, access, NULL, &key_comp, NULL );
3141 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3142
3143 /* user managed component key exists */
3144 size = MAX_PATH;
3146 ok( state == INSTALLSTATE_UNKNOWN, "got %d\n", state );
3147
3148 res = RegSetValueExA( key_comp, prod_squashed, 0, REG_SZ, (const BYTE *)"c:\\testcomponentpath", 20 );
3149 ok( res == ERROR_SUCCESS, "got %ld\n", res );
3150