diff options
Diffstat (limited to 'src/burn/test/BurnUnitTest/RelatedBundleTest.cpp')
-rw-r--r-- | src/burn/test/BurnUnitTest/RelatedBundleTest.cpp | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/src/burn/test/BurnUnitTest/RelatedBundleTest.cpp b/src/burn/test/BurnUnitTest/RelatedBundleTest.cpp new file mode 100644 index 00000000..3d1964c3 --- /dev/null +++ b/src/burn/test/BurnUnitTest/RelatedBundleTest.cpp | |||
@@ -0,0 +1,199 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | |||
6 | namespace Microsoft | ||
7 | { | ||
8 | namespace Tools | ||
9 | { | ||
10 | namespace WindowsInstallerXml | ||
11 | { | ||
12 | namespace Test | ||
13 | { | ||
14 | namespace Bootstrapper | ||
15 | { | ||
16 | using namespace System; | ||
17 | using namespace System::IO; | ||
18 | using namespace Xunit; | ||
19 | using namespace WixBuildTools::TestSupport; | ||
20 | |||
21 | public ref class RelatedBundleTest : BurnUnitTest, IClassFixture<TestRegistryFixture^> | ||
22 | { | ||
23 | private: | ||
24 | TestRegistryFixture^ testRegistry; | ||
25 | public: | ||
26 | RelatedBundleTest(BurnTestFixture^ fixture, TestRegistryFixture^ registryFixture) : BurnUnitTest(fixture) | ||
27 | { | ||
28 | this->testRegistry = registryFixture; | ||
29 | } | ||
30 | |||
31 | [Fact] | ||
32 | void RelatedBundleDetectPerMachineTest() | ||
33 | { | ||
34 | HRESULT hr = S_OK; | ||
35 | IXMLDOMElement* pixeBundle = NULL; | ||
36 | BURN_REGISTRATION registration = { }; | ||
37 | BURN_RELATED_BUNDLES relatedBundles = { }; | ||
38 | BURN_CACHE cache = { }; | ||
39 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
40 | |||
41 | try | ||
42 | { | ||
43 | this->testRegistry->SetUp(); | ||
44 | this->RegisterFakeBundles(); | ||
45 | |||
46 | LPCWSTR wzDocument = | ||
47 | L"<Bundle>" | ||
48 | L" <UX>" | ||
49 | L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' />" | ||
50 | L" </UX>" | ||
51 | L" <RelatedBundle Id='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Action='Upgrade' />" | ||
52 | L" <Registration Id='{D54F896D-1952-43E6-9C67-B5652240618C}' Tag='foo' ProviderKey='foo' Version='1.0.0.0' ExecutableName='setup.exe' PerMachine='yes'>" | ||
53 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='1.0.0.0' />" | ||
54 | L" </Registration>" | ||
55 | L"</Bundle>"; | ||
56 | |||
57 | // load XML document | ||
58 | LoadBundleXmlHelper(wzDocument, &pixeBundle); | ||
59 | |||
60 | hr = CacheInitialize(&cache, &internalCommand); | ||
61 | TestThrowOnFailure(hr, L"Failed initialize cache."); | ||
62 | |||
63 | hr = RegistrationParseFromXml(®istration, &cache, pixeBundle); | ||
64 | TestThrowOnFailure(hr, L"Failed to parse registration from XML."); | ||
65 | |||
66 | RelatedBundlesInitializeForScope(registration.fPerMachine, ®istration, &relatedBundles); | ||
67 | |||
68 | Assert::Equal(1lu, relatedBundles.cRelatedBundles); | ||
69 | |||
70 | BURN_RELATED_BUNDLE* pRelatedBundle = relatedBundles.rgRelatedBundles + 0; | ||
71 | NativeAssert::StringEqual(L"{AD75BE46-B5D7-4208-BC8B-918553C72D83}", pRelatedBundle->package.sczId); | ||
72 | //{E2355133-384C-4332-9B62-1FA950D707B7} should be missing because it causes an error while processing it. It's important that this doesn't cause initialization to fail. | ||
73 | } | ||
74 | finally | ||
75 | { | ||
76 | ReleaseObject(pixeBundle); | ||
77 | RegistrationUninitialize(®istration); | ||
78 | |||
79 | this->testRegistry->TearDown(); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | [Fact] | ||
84 | void RelatedBundleDetectPerUserTest() | ||
85 | { | ||
86 | HRESULT hr = S_OK; | ||
87 | IXMLDOMElement* pixeBundle = NULL; | ||
88 | BURN_REGISTRATION registration = { }; | ||
89 | BURN_RELATED_BUNDLES relatedBundles = { }; | ||
90 | BURN_CACHE cache = { }; | ||
91 | BURN_ENGINE_COMMAND internalCommand = { }; | ||
92 | |||
93 | try | ||
94 | { | ||
95 | this->testRegistry->SetUp(); | ||
96 | this->RegisterFakeBundles(); | ||
97 | |||
98 | LPCWSTR wzDocument = | ||
99 | L"<Bundle>" | ||
100 | L" <UX>" | ||
101 | L" <Payload Id='ux.dll' FilePath='ux.dll' Packaging='embedded' SourcePath='ux.dll' />" | ||
102 | L" </UX>" | ||
103 | L" <RelatedBundle Id='{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}' Action='Upgrade' />" | ||
104 | L" <Registration Id='{3DB49D3D-1FB8-4147-A465-BBE8BFD0DAD0}' Tag='foo' ProviderKey='foo' Version='4.0.0.0' ExecutableName='setup.exe' PerMachine='no'>" | ||
105 | L" <Arp Register='yes' Publisher='WiX Toolset' DisplayName='RegisterBasicTest' DisplayVersion='4.0.0.0' />" | ||
106 | L" </Registration>" | ||
107 | L"</Bundle>"; | ||
108 | |||
109 | // load XML document | ||
110 | LoadBundleXmlHelper(wzDocument, &pixeBundle); | ||
111 | |||
112 | hr = CacheInitialize(&cache, &internalCommand); | ||
113 | TestThrowOnFailure(hr, L"Failed initialize cache."); | ||
114 | |||
115 | hr = RegistrationParseFromXml(®istration, &cache, pixeBundle); | ||
116 | TestThrowOnFailure(hr, L"Failed to parse registration from XML."); | ||
117 | |||
118 | RelatedBundlesInitializeForScope(registration.fPerMachine, ®istration, &relatedBundles); | ||
119 | |||
120 | Assert::Equal(1lu, relatedBundles.cRelatedBundles); | ||
121 | |||
122 | BURN_RELATED_BUNDLE* pRelatedBundle = relatedBundles.rgRelatedBundles + 0; | ||
123 | NativeAssert::StringEqual(L"{6DB5D48C-CD7D-40D2-BCBC-AF630E136761}", pRelatedBundle->package.sczId); | ||
124 | //{42D16EBE-8B6B-4A9A-9AE9-5300F30011AA} should be missing because it causes an error while processing it. It's important that this doesn't cause initialization to fail. | ||
125 | } | ||
126 | finally | ||
127 | { | ||
128 | ReleaseObject(pixeBundle); | ||
129 | RegistrationUninitialize(®istration); | ||
130 | |||
131 | this->testRegistry->TearDown(); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | void RegisterFakeBundles() | ||
136 | { | ||
137 | this->RegisterFakeBundle(L"{D54F896D-1952-43E6-9C67-B5652240618C}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", NULL, L"1.0.0.0", TRUE); | ||
138 | this->RegisterFakeBundle(L"{E2355133-384C-4332-9B62-1FA950D707B7}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", L"", L"1.1.0.0", TRUE); | ||
139 | this->RegisterFakeBundle(L"{AD75BE46-B5D7-4208-BC8B-918553C72D83}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", NULL, L"2.0.0.0", TRUE); | ||
140 | this->RegisterFakeBundle(L"{6DB5D48C-CD7D-40D2-BCBC-AF630E136761}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", NULL, L"3.0.0.0", FALSE); | ||
141 | this->RegisterFakeBundle(L"{42D16EBE-8B6B-4A9A-9AE9-5300F30011AA}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", L"", L"3.1.0.0", FALSE); | ||
142 | this->RegisterFakeBundle(L"{3DB49D3D-1FB8-4147-A465-BBE8BFD0DAD0}", L"{89FDAE1F-8CC1-48B9-B930-3945E0D3E7F0}", NULL, L"4.0.0.0", FALSE); | ||
143 | } | ||
144 | |||
145 | void RegisterFakeBundle(LPCWSTR wzBundleId, LPCWSTR wzUpgradeCodes, LPCWSTR wzCachePath, LPCWSTR wzVersion, BOOL fPerMachine) | ||
146 | { | ||
147 | HRESULT hr = S_OK; | ||
148 | LPWSTR* rgsczUpgradeCodes = NULL; | ||
149 | DWORD cUpgradeCodes = 0; | ||
150 | LPWSTR sczRegistrationKey = NULL; | ||
151 | LPWSTR sczCachePath = NULL; | ||
152 | HKEY hkRegistration = NULL; | ||
153 | HKEY hkRoot = fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | ||
154 | |||
155 | try | ||
156 | { | ||
157 | hr = StrSplitAllocArray(&rgsczUpgradeCodes, reinterpret_cast<UINT*>(&cUpgradeCodes), wzUpgradeCodes, L";"); | ||
158 | NativeAssert::Succeeded(hr, "Failed to split upgrade codes."); | ||
159 | |||
160 | hr = StrAllocFormatted(&sczRegistrationKey, L"%s\\%s", BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId); | ||
161 | NativeAssert::Succeeded(hr, "Failed to build uninstall registry key path."); | ||
162 | |||
163 | if (!wzCachePath) | ||
164 | { | ||
165 | hr = StrAllocFormatted(&sczCachePath, L"%ls.exe", wzBundleId); | ||
166 | NativeAssert::Succeeded(hr, "Failed to build cache path."); | ||
167 | |||
168 | wzCachePath = sczCachePath; | ||
169 | } | ||
170 | |||
171 | hr = RegCreate(hkRoot, sczRegistrationKey, KEY_WRITE, &hkRegistration); | ||
172 | NativeAssert::Succeeded(hr, "Failed to create registration key."); | ||
173 | |||
174 | hr = RegWriteStringArray(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, rgsczUpgradeCodes, cUpgradeCodes); | ||
175 | NativeAssert::Succeeded(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE); | ||
176 | |||
177 | if (wzCachePath && *wzCachePath) | ||
178 | { | ||
179 | hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH, wzCachePath); | ||
180 | NativeAssert::Succeeded(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH); | ||
181 | } | ||
182 | |||
183 | hr = RegWriteString(hkRegistration, BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION, wzVersion); | ||
184 | NativeAssert::Succeeded(hr, "Failed to write %ls value.", BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION); | ||
185 | } | ||
186 | finally | ||
187 | { | ||
188 | ReleaseStrArray(rgsczUpgradeCodes, cUpgradeCodes); | ||
189 | ReleaseStr(sczRegistrationKey); | ||
190 | ReleaseStr(sczCachePath); | ||
191 | ReleaseRegKey(hkRegistration); | ||
192 | } | ||
193 | } | ||
194 | }; | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||