aboutsummaryrefslogtreecommitdiff
path: root/src/test/BurnUnitTest/VariableHelpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/BurnUnitTest/VariableHelpers.cpp')
-rw-r--r--src/test/BurnUnitTest/VariableHelpers.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/test/BurnUnitTest/VariableHelpers.cpp b/src/test/BurnUnitTest/VariableHelpers.cpp
new file mode 100644
index 00000000..9ce46a76
--- /dev/null
+++ b/src/test/BurnUnitTest/VariableHelpers.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
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)
21 {
22 HRESULT hr = S_OK;
23
24 hr = VariableSetString(pVariables, wzVariable, wzValue, FALSE);
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, DWORD64 qwValue)
37 {
38 HRESULT hr = S_OK;
39
40 hr = VariableSetVersion(pVariables, wzVariable, qwValue, FALSE);
41 TestThrowOnFailure2(hr, L"Failed to set %s to: 0x%016I64x", wzVariable, qwValue);
42 }
43
44 String^ VariableGetStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
45 {
46 HRESULT hr = S_OK;
47 LPWSTR scz = NULL;
48 try
49 {
50 hr = VariableGetString(pVariables, wzVariable, &scz);
51 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
52
53 return gcnew String(scz);
54 }
55 finally
56 {
57 ReleaseStr(scz);
58 }
59 }
60
61 __int64 VariableGetNumericHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
62 {
63 HRESULT hr = S_OK;
64 LONGLONG llValue = 0;
65
66 hr = VariableGetNumeric(pVariables, wzVariable, &llValue);
67 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
68
69 return llValue;
70 }
71
72 unsigned __int64 VariableGetVersionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
73 {
74 HRESULT hr = S_OK;
75 DWORD64 qwValue = 0;
76
77 hr = VariableGetVersion(pVariables, wzVariable, &qwValue);
78 TestThrowOnFailure1(hr, L"Failed to get: %s", wzVariable);
79
80 return qwValue;
81 }
82
83 String^ VariableGetFormattedHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
84 {
85 HRESULT hr = S_OK;
86 LPWSTR scz = NULL;
87 try
88 {
89 hr = VariableGetFormatted(pVariables, wzVariable, &scz);
90 TestThrowOnFailure1(hr, L"Failed to get formatted: %s", wzVariable);
91
92 return gcnew String(scz);
93 }
94 finally
95 {
96 ReleaseStr(scz);
97 }
98 }
99
100 String^ VariableFormatStringHelper(BURN_VARIABLES* pVariables, LPCWSTR wzIn)
101 {
102 HRESULT hr = S_OK;
103 LPWSTR scz = NULL;
104 try
105 {
106 hr = VariableFormatString(pVariables, wzIn, &scz, NULL);
107 TestThrowOnFailure1(hr, L"Failed to format string: '%s'", wzIn);
108
109 return gcnew String(scz);
110 }
111 finally
112 {
113 ReleaseStr(scz);
114 }
115 }
116
117 String^ VariableEscapeStringHelper(LPCWSTR wzIn)
118 {
119 HRESULT hr = S_OK;
120 LPWSTR scz = NULL;
121 try
122 {
123 hr = VariableEscapeString(wzIn, &scz);
124 TestThrowOnFailure1(hr, L"Failed to escape string: '%s'", wzIn);
125
126 return gcnew String(scz);
127 }
128 finally
129 {
130 ReleaseStr(scz);
131 }
132 }
133
134 bool EvaluateConditionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzCondition)
135 {
136 HRESULT hr = S_OK;
137 BOOL f = FALSE;
138
139 hr = ConditionEvaluate(pVariables, wzCondition, &f);
140 TestThrowOnFailure1(hr, L"Failed to evaluate condition: '%s'", wzCondition);
141
142 return f ? true : false;
143 }
144
145 bool EvaluateFailureConditionHelper(BURN_VARIABLES* pVariables, LPCWSTR wzCondition)
146 {
147 HRESULT hr = S_OK;
148 BOOL f = FALSE;
149
150 hr = ConditionEvaluate(pVariables, wzCondition, &f);
151 return E_INVALIDDATA == hr ? true : false;
152 }
153
154 bool VariableExistsHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
155 {
156 HRESULT hr = S_OK;
157 BURN_VARIANT value = { };
158
159 try
160 {
161 hr = VariableGetVariant(pVariables, wzVariable, &value);
162 if (E_NOTFOUND == hr || value.Type == BURN_VARIANT_TYPE_NONE)
163 {
164 return false;
165 }
166 else
167 {
168 TestThrowOnFailure1(hr, L"Failed to find variable: '%s'", wzVariable);
169 return true;
170 }
171 }
172 finally
173 {
174 BVariantUninitialize(&value);
175 }
176 }
177
178 int VariableGetTypeHelper(BURN_VARIABLES* pVariables, LPCWSTR wzVariable)
179 {
180 HRESULT hr = S_OK;
181 BURN_VARIANT value = { };
182
183 try
184 {
185 hr = VariableGetVariant(pVariables, wzVariable, &value);
186 TestThrowOnFailure1(hr, L"Failed to find variable: '%s'", wzVariable);
187
188 return (int)value.Type;
189 }
190 finally
191 {
192 BVariantUninitialize(&value);
193 }
194 }
195}
196}
197}
198}
199}