Add VariantTest.
Sean Hall committed
Jul 17, 2020 at 21:28 UTC
e845e7c68ae792ab2ccd4ca2f054700dde624375
4 files changed
+209
-4
src/test/BurnUnitTest/BurnTestFixture.h
+4
@@ -26,6 +26,9 @@ namespace Bootstrapper
26
hr = RegInitialize();
27
TestThrowOnFailure(hr, L"Failed to initialize Regutil.");
28
29
+ hr = CrypInitialize();
30
+ TestThrowOnFailure(hr, L"Failed to initialize Cryputil.");
31
+
32
PlatformInitialize();
33
34
this->testDirectory = WixBuildTools::TestSupport::TestData::Get();
@@ -38,6 +41,7 @@ namespace Bootstrapper
41
42
~BurnTestFixture()
43
{
44
+ CrypUninitialize();
45
XmlUninitialize();
46
RegUninitialize();
47
LogUninitialize(FALSE);
src/test/BurnUnitTest/BurnUnitTest.vcxproj
+1
@@ -46,6 +46,7 @@
46
<ClCompile Include="SearchTest.cpp" />
47
<ClCompile Include="VariableHelpers.cpp" />
48
<ClCompile Include="VariableTest.cpp" />
49
+ <ClCompile Include="VariantTest.cpp" />
50
</ItemGroup>
51
<ItemGroup>
52
<ClInclude Include="BurnTestException.h" />
src/test/BurnUnitTest/BurnUnitTest.vcxproj.filters
+7
-4
@@ -18,6 +18,9 @@
18
<ClCompile Include="AssemblyInfo.cpp">
19
<Filter>Source Files</Filter>
20
</ClCompile>
21
+ <ClCompile Include="CacheTest.cpp">
22
+ <Filter>Source Files</Filter>
23
+ </ClCompile>
24
<ClCompile Include="ElevationTest.cpp">
25
<Filter>Source Files</Filter>
26
</ClCompile>
@@ -27,6 +30,9 @@
30
<ClCompile Include="ManifestTest.cpp">
31
<Filter>Source Files</Filter>
32
</ClCompile>
33
+ <ClCompile Include="precomp.cpp">
34
+ <Filter>Source Files</Filter>
35
+ </ClCompile>
36
<ClCompile Include="RegistrationTest.cpp">
37
<Filter>Source Files</Filter>
38
</ClCompile>
@@ -39,10 +45,7 @@
45
<ClCompile Include="VariableTest.cpp">
46
<Filter>Source Files</Filter>
47
</ClCompile>
42
- <ClCompile Include="CacheTest.cpp">
43
- <Filter>Source Files</Filter>
44
- </ClCompile>
45
- <ClCompile Include="$(WixRoot)src\common\precomp.cpp">
48
+ <ClCompile Include="VariantTest.cpp">
49
<Filter>Source Files</Filter>
50
</ClCompile>
51
</ItemGroup>
src/test/BurnUnitTest/VariantTest.cpp
new
+197
@@ -0,0 +1,197 @@
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
+namespace Microsoft
6
+{
7
+namespace Tools
8
+{
9
+namespace WindowsInstallerXml
10
+{
11
+namespace Test
12
+{
13
+namespace Bootstrapper
14
+{
15
+ using namespace System;
16
+ using namespace Xunit;
17
+
18
+ public ref class VariantTest : BurnUnitTest
19
+ {
20
+ public:
21
+ VariantTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture)
22
+ {
23
+ }
24
+
25
+ [Fact]
26
+ void VariantBasicTest()
27
+ {
28
+ BURN_VARIANT expectedVariants[8];
29
+ BURN_VARIANT actualVariants[8];
30
+ for (DWORD i = 0; i < 8; i++)
31
+ {
32
+ BVariantUninitialize(expectedVariants + i);
33
+ BVariantUninitialize(actualVariants + i);
34
+ }
35
+
36
+ try
37
+ {
38
+ InitNumericValue(expectedVariants + 0, 2, FALSE, L"PROP1", actualVariants + 0);
39
+ InitStringValue(expectedVariants + 1, L"VAL2", FALSE, L"PROP2", actualVariants + 1);
40
+ InitVersionValue(expectedVariants + 2, MAKEQWORDVERSION(1, 1, 0, 0), FALSE, L"PROP3", actualVariants + 2);
41
+ InitNoneValue(expectedVariants + 3, FALSE, L"PROP4", actualVariants + 3);
42
+ InitNoneValue(expectedVariants + 4, TRUE, L"PROP5", actualVariants + 4);
43
+ InitVersionValue(expectedVariants + 5, MAKEQWORDVERSION(1, 1, 1, 0), TRUE, L"PROP6", actualVariants + 5);
44
+ InitStringValue(expectedVariants + 6, L"7", TRUE, L"PROP7", actualVariants + 6);
45
+ InitNumericValue(expectedVariants + 7, 11, TRUE, L"PROP8", actualVariants + 7);
46
+
47
+ VerifyNumericValue(expectedVariants + 0, actualVariants + 0);
48
+ VerifyStringValue(expectedVariants + 1, actualVariants + 1);
49
+ VerifyVersionValue(expectedVariants + 2, actualVariants + 2);
50
+ VerifyNoneValue(expectedVariants + 3, actualVariants + 3);
51
+ VerifyNoneValue(expectedVariants + 4, actualVariants + 4);
52
+ VerifyVersionValue(expectedVariants + 5, actualVariants + 5);
53
+ VerifyStringValue(expectedVariants + 6, actualVariants + 6);
54
+ VerifyNumericValue(expectedVariants + 7, actualVariants + 7);
55
+ }
56
+ finally
57
+ {
58
+ for (DWORD i = 0; i < 8; i++)
59
+ {
60
+ BVariantUninitialize(expectedVariants + i);
61
+ BVariantUninitialize(actualVariants + i);
62
+ }
63
+ }
64
+ }
65
+
66
+ private:
67
+ void InitNoneValue(BURN_VARIANT* pValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue)
68
+ {
69
+ HRESULT hr = S_OK;
70
+ pValue->Type = BURN_VARIANT_TYPE_NONE;
71
+
72
+ hr = BVariantCopy(pValue, pActualValue);
73
+ NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz);
74
+
75
+ if (fHidden)
76
+ {
77
+ hr = BVariantSetEncryption(pActualValue, TRUE);
78
+ NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz);
79
+
80
+ NativeAssert::True(pActualValue->fEncryptValue);
81
+ }
82
+ }
83
+
84
+ void InitNumericValue(BURN_VARIANT* pValue, LONGLONG llValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue)
85
+ {
86
+ HRESULT hr = S_OK;
87
+ pValue->Type = BURN_VARIANT_TYPE_NUMERIC;
88
+ pValue->llValue = llValue;
89
+
90
+ hr = BVariantCopy(pValue, pActualValue);
91
+ NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz);
92
+
93
+ if (fHidden)
94
+ {
95
+ hr = BVariantSetEncryption(pActualValue, TRUE);
96
+ NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz);
97
+
98
+ NativeAssert::True(pActualValue->fEncryptValue);
99
+ }
100
+ }
101
+
102
+ void InitStringValue(BURN_VARIANT* pValue, LPWSTR wzValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue)
103
+ {
104
+ HRESULT hr = S_OK;
105
+ pValue->Type = BURN_VARIANT_TYPE_STRING;
106
+
107
+ hr = StrAllocString(&pValue->sczValue, wzValue, 0);
108
+ NativeAssert::Succeeded(hr, "Failed to alloc string: {0}", wzValue);
109
+
110
+ hr = BVariantCopy(pValue, pActualValue);
111
+ NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz);
112
+
113
+ if (fHidden)
114
+ {
115
+ hr = BVariantSetEncryption(pActualValue, TRUE);
116
+ NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz);
117
+
118
+ NativeAssert::True(pActualValue->fEncryptValue);
119
+ }
120
+ }
121
+
122
+ void InitVersionValue(BURN_VARIANT* pValue, DWORD64 qwValue, BOOL fHidden, LPCWSTR wz, BURN_VARIANT* pActualValue)
123
+ {
124
+ HRESULT hr = S_OK;
125
+ pValue->Type = BURN_VARIANT_TYPE_VERSION;
126
+ pValue->qwValue = qwValue;
127
+
128
+ hr = BVariantCopy(pValue, pActualValue);
129
+ NativeAssert::Succeeded(hr, "Failed to copy variant {0}", wz);
130
+
131
+ if (fHidden)
132
+ {
133
+ hr = BVariantSetEncryption(pActualValue, TRUE);
134
+ NativeAssert::Succeeded(hr, "Failed to encrypt variant {0}", wz);
135
+
136
+ NativeAssert::True(pActualValue->fEncryptValue);
137
+ }
138
+ }
139
+
140
+ void VerifyNumericValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue)
141
+ {
142
+ HRESULT hr = S_OK;
143
+ LONGLONG llValue = 0;
144
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_NUMERIC, pExpectedValue->Type);
145
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_NUMERIC, pActualValue->Type);
146
+
147
+ hr = BVariantGetNumeric(pActualValue, &llValue);
148
+ NativeAssert::Succeeded(hr, "Failed to get numeric value");
149
+
150
+ NativeAssert::Equal<LONGLONG>(pExpectedValue->llValue, llValue);
151
+ }
152
+
153
+ void VerifyNoneValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue)
154
+ {
155
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_NONE, pExpectedValue->Type);
156
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_NONE, pActualValue->Type);
157
+ NativeAssert::Equal<LONGLONG>(pExpectedValue->llValue, pActualValue->llValue);
158
+ }
159
+
160
+ void VerifyStringValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue)
161
+ {
162
+ HRESULT hr = S_OK;
163
+ LPWSTR sczValue = NULL;
164
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_STRING, pExpectedValue->Type);
165
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_STRING, pActualValue->Type);
166
+
167
+ try
168
+ {
169
+ hr = BVariantGetString(pActualValue, &sczValue);
170
+ NativeAssert::Succeeded(hr, "Failed to get numeric value");
171
+
172
+ NativeAssert::StringEqual(pExpectedValue->sczValue, sczValue);
173
+ }
174
+ finally
175
+ {
176
+ ReleaseStr(sczValue);
177
+ }
178
+ }
179
+
180
+ void VerifyVersionValue(BURN_VARIANT* pExpectedValue, BURN_VARIANT* pActualValue)
181
+ {
182
+ HRESULT hr = S_OK;
183
+ DWORD64 qwValue = 0;
184
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_VERSION, pExpectedValue->Type);
185
+ NativeAssert::Equal<DWORD>(BURN_VARIANT_TYPE_VERSION, pActualValue->Type);
186
+
187
+ hr = BVariantGetVersion(pActualValue, &qwValue);
188
+ NativeAssert::Succeeded(hr, "Failed to get numeric value");
189
+
190
+ NativeAssert::Equal<DWORD64>(pExpectedValue->qwValue, qwValue);
191
+ }
192
+ };
193
+}
194
+}
195
+}
196
+}
197
+}