aboutsummaryrefslogtreecommitdiff
path: root/src/burn/test/BurnUnitTest/VariableHelpers.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-04-22 17:06:54 -0700
committerRob Mensching <rob@firegiant.com>2021-04-29 16:36:06 -0700
commitaf10c45d7b3a44af0b461a557847fe03263dcc10 (patch)
tree6a5c1532304782c36ffe4200b38f3afb76789a43 /src/burn/test/BurnUnitTest/VariableHelpers.cpp
parent9c2aed97299fb96aeee3f1471ce40225437aaecf (diff)
downloadwix-af10c45d7b3a44af0b461a557847fe03263dcc10.tar.gz
wix-af10c45d7b3a44af0b461a557847fe03263dcc10.tar.bz2
wix-af10c45d7b3a44af0b461a557847fe03263dcc10.zip
Move burn into burn
Diffstat (limited to 'src/burn/test/BurnUnitTest/VariableHelpers.cpp')
-rw-r--r--src/burn/test/BurnUnitTest/VariableHelpers.cpp217
1 files changed, 217 insertions, 0 deletions
diff --git a/src/burn/test/BurnUnitTest/VariableHelpers.cpp b/src/burn/test/BurnUnitTest/VariableHelpers.cpp
new file mode 100644
index 00000000..40f958f8
--- /dev/null
+++ b/src/burn/test/BurnUnitTest/VariableHelpers.cpp
@@ -0,0 +1,217 @@
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
6using namespace System;
7using namespace Xunit;
8
9
10namespace Microsoft
11{
12namespace Tools
13{
14namespace WindowsInstallerXml
15{
16namespace Test
17{
18namespace Bootstrapper
19{
20 void VariableSetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue, BOOL fFormatted)
21 {
22 HRESULT hr = S_OK;
23
24 hr = VariableSetString(pVariables, wzVariable, wzValue, FALSE, fFormatted);
25 TestThrowOnFailure2(hr, L"Failed to set %s to: %s", wzVariable, wzValue);
26 }
27
28 void VariableSetNumericHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LONGLONG llValue)
29 {
30 HRESULT hr = S_OK;
31
32 hr = VariableSetNumeric(pVariables, wzVariable, llValue, FALSE);
33 TestThrowOnFailure2(hr, L"Failed to set %s to: %I64d", wzVariable, llValue);
34 }
35
36 void VariableSetVersionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, LPCWSTR wzValue)
37 {
38 HRESULT hr = S_OK;
39 VERUTIL_VERSION* pVersion = NULL;
40
41 try
42 {
43 hr = VerParseVersion(wzValue, 0, FALSE, &pVersion);
44 TestThrowOnFailure1(hr, L"Failed to parse version '%ls'", wzValue);
45
46 hr = VariableSetVersion(pVariables, wzVariable, pVersion, FALSE);
47 TestThrowOnFailure2(hr, L"Failed to set %s to: '%ls'", wzVariable, wzValue);
48 }
49 finally
50 {
51 ReleaseVerutilVersion(pVersion);
52 }
53 }
54
55 String^ VariableGetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
56 {
57 HRESULT hr = S_OK;
58 LPWSTR scz = NULL;
59 try
60 {
61 hr = VariableGetString(pVariables, wzVariable, &scz);
62 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
63
64 return gcnew String(scz);
65 }
66 finally
67 {
68 ReleaseStr(scz);
69 }
70 }
71
72 __int64 VariableGetNumericHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
73 {
74 HRESULT hr = S_OK;
75 LONGLONG llValue = 0;
76
77 hr = VariableGetNumeric(pVariables, wzVariable, &llValue);
78 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
79
80 return llValue;
81 }
82
83 String^ VariableGetVersionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
84 {
85 HRESULT hr = S_OK;
86 VERUTIL_VERSION* pValue = NULL;
87
88 try
89 {
90 hr = VariableGetVersion(pVariables, wzVariable, &pValue);
91 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
92
93 return gcnew String(pValue->sczVersion);
94 }
95 finally
96 {
97 ReleaseVerutilVersion(pValue);
98 }
99 }
100
101 String^ VariableGetFormattedHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable, BOOL* pfContainsHiddenVariable)
102 {
103 HRESULT hr = S_OK;
104 LPWSTR scz = NULL;
105 try
106 {
107 hr = VariableGetFormatted(pVariables, wzVariable, &scz, pfContainsHiddenVariable);
108 TestThrowOnFailure1(hr, L"Failed to get formatted: %s", wzVariable);
109
110 return gcnew String(scz);
111 }
112 finally
113 {
114 ReleaseStr(scz);
115 }
116 }
117
118 String^ VariableFormatStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzIn)
119 {
120 HRESULT hr = S_OK;
121 LPWSTR scz = NULL;
122 try
123 {
124 hr = VariableFormatString(pVariables, wzIn, &scz, NULL);
125 TestThrowOnFailure1(hr, L"Failed to format string: '%s'", wzIn);
126
127 return gcnew String(scz);
128 }
129 finally
130 {
131 ReleaseStr(scz);
132 }
133 }
134
135 String^ VariableEscapeStringHelper(LPCWSTR wzIn)
136 {
137 HRESULT hr = S_OK;
138 LPWSTR scz = NULL;
139 try
140 {
141 hr = VariableEscapeString(wzIn, &scz);
142 TestThrowOnFailure1(hr, L"Failed to escape string: '%s'", wzIn);
143
144 return gcnew String(scz);
145 }
146 finally
147 {
148 ReleaseStr(scz);
149 }
150 }
151
152 bool EvaluateConditionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzCondition)
153 {
154 HRESULT hr = S_OK;
155 BOOL f = FALSE;
156
157 hr = ConditionEvaluate(pVariables, wzCondition, &f);
158 TestThrowOnFailure1(hr, L"Failed to evaluate condition: '%s'", wzCondition);
159
160 return f ? true : false;
161 }
162
163 bool EvaluateFailureConditionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzCondition)
164 {
165 HRESULT hr = S_OK;
166 BOOL f = FALSE;
167
168 hr = ConditionEvaluate(pVariables, wzCondition, &f);
169 return E_INVALIDDATA == hr ? true : false;
170 }
171
172 bool VariableExistsHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
173 {
174 HRESULT hr = S_OK;
175 BURN_VARIANT value = { };
176
177 try
178 {
179 hr = VariableGetVariant(pVariables, wzVariable, &value);
180 if (E_NOTFOUND == hr || value.Type == BURN_VARIANT_TYPE_NONE)
181 {
182 return false;
183 }
184 else
185 {
186 TestThrowOnFailure1(hr, L"Failed to find variable: '%s'", wzVariable);
187 return true;
188 }
189 }
190 finally
191 {
192 BVariantUninitialize(&value);
193 }
194 }
195
196 int VariableGetTypeHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
197 {
198 HRESULT hr = S_OK;
199 BURN_VARIANT value = { };
200
201 try
202 {
203 hr = VariableGetVariant(pVariables, wzVariable, &value);
204 TestThrowOnFailure1(hr, L"Failed to find variable: '%s'", wzVariable);
205
206 return (int)value.Type;
207 }
208 finally
209 {
210 BVariantUninitialize(&value);
211 }
212 }
213}
214}
215}
216}
217}