aboutsummaryrefslogtreecommitdiff
path: root/src/burn/test
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-02-28 18:42:51 -0600
committerSean Hall <r.sean.hall@gmail.com>2022-03-01 11:37:00 -0600
commitbefcd209d62a25020f46a688002b259c59e4dc3b (patch)
treecbf6c5a57276264599f95a712939d44645f5ca7a /src/burn/test
parent3f658fa2b4bd80619fcf89e1e87ae12b48effb7a (diff)
downloadwix-befcd209d62a25020f46a688002b259c59e4dc3b.tar.gz
wix-befcd209d62a25020f46a688002b259c59e4dc3b.tar.bz2
wix-befcd209d62a25020f46a688002b259c59e4dc3b.zip
Refactor related bundle enumeration into butil.
Related to #3693
Diffstat (limited to 'src/burn/test')
-rw-r--r--src/burn/test/BurnUnitTest/BurnTestException.h11
-rw-r--r--src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj1
-rw-r--r--src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters3
-rw-r--r--src/burn/test/BurnUnitTest/RelatedBundleTest.cpp199
-rw-r--r--src/burn/test/BurnUnitTest/precomp.h1
5 files changed, 207 insertions, 8 deletions
diff --git a/src/burn/test/BurnUnitTest/BurnTestException.h b/src/burn/test/BurnUnitTest/BurnTestException.h
index bd94b4fc..e813f95c 100644
--- a/src/burn/test/BurnUnitTest/BurnTestException.h
+++ b/src/burn/test/BurnUnitTest/BurnTestException.h
@@ -13,19 +13,14 @@ namespace Test
13namespace Bootstrapper 13namespace Bootstrapper
14{ 14{
15 using namespace System; 15 using namespace System;
16 using namespace WixBuildTools::TestSupport;
16 17
17 public ref struct BurnTestException : public System::Exception 18 public ref struct BurnTestException : public SucceededException
18 { 19 {
19 public: 20 public:
20 BurnTestException(HRESULT error)
21 {
22 this->HResult = error;
23 }
24
25 BurnTestException(HRESULT error, String^ message) 21 BurnTestException(HRESULT error, String^ message)
26 : Exception(message) 22 : SucceededException(error, message)
27 { 23 {
28 this->HResult = error;
29 } 24 }
30 25
31 property Int32 ErrorCode 26 property Int32 ErrorCode
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj
index 36903239..f4f95b7f 100644
--- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj
+++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj
@@ -56,6 +56,7 @@
56 <DisableSpecificWarnings>4564;4691</DisableSpecificWarnings> 56 <DisableSpecificWarnings>4564;4691</DisableSpecificWarnings>
57 </ClCompile> 57 </ClCompile>
58 <ClCompile Include="RegistrationTest.cpp" /> 58 <ClCompile Include="RegistrationTest.cpp" />
59 <ClCompile Include="RelatedBundleTest.cpp" />
59 <ClCompile Include="SearchTest.cpp" /> 60 <ClCompile Include="SearchTest.cpp" />
60 <ClCompile Include="TestRegistryFixture.cpp" /> 61 <ClCompile Include="TestRegistryFixture.cpp" />
61 <ClCompile Include="VariableHelpers.cpp" /> 62 <ClCompile Include="VariableHelpers.cpp" />
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters
index 96563fc6..90290f52 100644
--- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters
+++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters
@@ -39,6 +39,9 @@
39 <ClCompile Include="RegistrationTest.cpp"> 39 <ClCompile Include="RegistrationTest.cpp">
40 <Filter>Source Files</Filter> 40 <Filter>Source Files</Filter>
41 </ClCompile> 41 </ClCompile>
42 <ClCompile Include="RelatedBundleTest.cpp">
43 <Filter>Source Files</Filter>
44 </ClCompile>
42 <ClCompile Include="SearchTest.cpp"> 45 <ClCompile Include="SearchTest.cpp">
43 <Filter>Source Files</Filter> 46 <Filter>Source Files</Filter>
44 </ClCompile> 47 </ClCompile>
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
6namespace Microsoft
7{
8namespace Tools
9{
10namespace WindowsInstallerXml
11{
12namespace Test
13{
14namespace 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(&registration, &cache, pixeBundle);
64 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
65
66 RelatedBundlesInitializeForScope(registration.fPerMachine, &registration, &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(&registration);
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(&registration, &cache, pixeBundle);
116 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
117
118 RelatedBundlesInitializeForScope(registration.fPerMachine, &registration, &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(&registration);
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}
diff --git a/src/burn/test/BurnUnitTest/precomp.h b/src/burn/test/BurnUnitTest/precomp.h
index ecab3494..ded9fc2d 100644
--- a/src/burn/test/BurnUnitTest/precomp.h
+++ b/src/burn/test/BurnUnitTest/precomp.h
@@ -53,6 +53,7 @@
53#include "update.h" 53#include "update.h"
54#include "pseudobundle.h" 54#include "pseudobundle.h"
55#include "registration.h" 55#include "registration.h"
56#include "relatedbundle.h"
56#include "plan.h" 57#include "plan.h"
57#include "pipe.h" 58#include "pipe.h"
58#include "logging.h" 59#include "logging.h"