diff options
Diffstat (limited to 'src/test/DUtilUnitTest/VarUtilTest.cpp')
-rw-r--r-- | src/test/DUtilUnitTest/VarUtilTest.cpp | 532 |
1 files changed, 0 insertions, 532 deletions
diff --git a/src/test/DUtilUnitTest/VarUtilTest.cpp b/src/test/DUtilUnitTest/VarUtilTest.cpp deleted file mode 100644 index 206310f5..00000000 --- a/src/test/DUtilUnitTest/VarUtilTest.cpp +++ /dev/null | |||
@@ -1,532 +0,0 @@ | |||
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 | #undef GetTempPath | ||
5 | #undef GetEnvironmentVariable | ||
6 | |||
7 | using namespace System; | ||
8 | using namespace Xunit; | ||
9 | using namespace WixTest; | ||
10 | |||
11 | namespace DutilTests | ||
12 | { | ||
13 | typedef struct _VarUtilContext | ||
14 | { | ||
15 | DWORD dw; | ||
16 | LPWSTR scz; | ||
17 | } VarUtilContext; | ||
18 | |||
19 | void FreeValueContext(LPVOID pvContext) | ||
20 | { | ||
21 | if (pvContext) | ||
22 | { | ||
23 | MemFree(pvContext); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public ref class VarUtil | ||
28 | { | ||
29 | public: | ||
30 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
31 | void VarUtilBasicTest() | ||
32 | { | ||
33 | HRESULT hr = S_OK; | ||
34 | VARIABLES_HANDLE pVariables = NULL; | ||
35 | |||
36 | try | ||
37 | { | ||
38 | hr = VarCreate(&pVariables); | ||
39 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
40 | |||
41 | // set variables | ||
42 | VarSetStringHelper(pVariables, L"PROP1", L"VAL1"); | ||
43 | VarSetNumericHelper(pVariables, L"PROP2", 2); | ||
44 | VarSetStringHelper(pVariables, L"PROP5", L"VAL5"); | ||
45 | VarSetStringHelper(pVariables, L"PROP3", L"VAL3"); | ||
46 | VarSetStringHelper(pVariables, L"PROP4", L"VAL4"); | ||
47 | VarSetStringHelper(pVariables, L"PROP6", L"VAL6"); | ||
48 | VarSetStringHelper(pVariables, L"PROP7", L"7"); | ||
49 | VarSetVersionHelper(pVariables, L"PROP8", MAKEQWORDVERSION(1, 1, 0, 0)); | ||
50 | |||
51 | // set overwritten variables | ||
52 | VarSetStringHelper(pVariables, L"OVERWRITTEN_STRING", L"ORIGINAL"); | ||
53 | VarSetNumericHelper(pVariables, L"OVERWRITTEN_STRING", 42); | ||
54 | |||
55 | VarSetNumericHelper(pVariables, L"OVERWRITTEN_NUMBER", 5); | ||
56 | VarSetStringHelper(pVariables, L"OVERWRITTEN_NUMBER", L"NEW"); | ||
57 | |||
58 | // get and verify variable values | ||
59 | VarGetStringHelper(pVariables, L"PROP1", L"VAL1"); | ||
60 | VarGetNumericHelper(pVariables, L"PROP2", 2); | ||
61 | VarGetStringHelper(pVariables, L"PROP2", L"2"); | ||
62 | VarGetStringHelper(pVariables, L"PROP3", L"VAL3"); | ||
63 | VarGetStringHelper(pVariables, L"PROP4", L"VAL4"); | ||
64 | VarGetStringHelper(pVariables, L"PROP5", L"VAL5"); | ||
65 | VarGetStringHelper(pVariables, L"PROP6", L"VAL6"); | ||
66 | VarGetNumericHelper(pVariables, L"PROP7", 7); | ||
67 | VarGetVersionHelper(pVariables, L"PROP8", MAKEQWORDVERSION(1, 1, 0, 0)); | ||
68 | VarGetStringHelper(pVariables, L"PROP8", L"1.1.0.0"); | ||
69 | |||
70 | VarGetNumericHelper(pVariables, L"OVERWRITTEN_STRING", 42); | ||
71 | VarGetStringHelper(pVariables, L"OVERWRITTEN_NUMBER", L"NEW"); | ||
72 | } | ||
73 | finally | ||
74 | { | ||
75 | ReleaseVariables(pVariables); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
80 | void VarUtilFormatTest() | ||
81 | { | ||
82 | HRESULT hr = S_OK; | ||
83 | VARIABLES_HANDLE pVariables = NULL; | ||
84 | LPWSTR scz = NULL; | ||
85 | DWORD cch = 0; | ||
86 | try | ||
87 | { | ||
88 | hr = VarCreate(&pVariables); | ||
89 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
90 | |||
91 | // set variables | ||
92 | VarSetStringHelper(pVariables, L"PROP1", L"VAL1"); | ||
93 | VarSetStringHelper(pVariables, L"PROP2", L"VAL2"); | ||
94 | VarSetNumericHelper(pVariables, L"PROP3", 3); | ||
95 | |||
96 | // test string formatting | ||
97 | VarFormatStringHelper(pVariables, L"NOPROP", L"NOPROP"); | ||
98 | VarFormatStringHelper(pVariables, L"[PROP1]", L"VAL1"); | ||
99 | VarFormatStringHelper(pVariables, L" [PROP1] ", L" VAL1 "); | ||
100 | VarFormatStringHelper(pVariables, L"PRE [PROP1]", L"PRE VAL1"); | ||
101 | VarFormatStringHelper(pVariables, L"[PROP1] POST", L"VAL1 POST"); | ||
102 | VarFormatStringHelper(pVariables, L"PRE [PROP1] POST", L"PRE VAL1 POST"); | ||
103 | VarFormatStringHelper(pVariables, L"[PROP1] MID [PROP2]", L"VAL1 MID VAL2"); | ||
104 | VarFormatStringHelper(pVariables, L"[NONE]", L""); | ||
105 | VarFormatStringHelper(pVariables, L"[prop1]", L""); | ||
106 | VarFormatStringHelper(pVariables, L"[\\[]", L"["); | ||
107 | VarFormatStringHelper(pVariables, L"[\\]]", L"]"); | ||
108 | VarFormatStringHelper(pVariables, L"[]", L"[]"); | ||
109 | VarFormatStringHelper(pVariables, L"[NONE", L"[NONE"); | ||
110 | VarGetFormattedHelper(pVariables, L"PROP2", L"VAL2"); | ||
111 | VarGetFormattedHelper(pVariables, L"PROP3", L"3"); | ||
112 | |||
113 | hr = VarFormatString(pVariables, L"PRE [PROP1] POST", &scz, &cch); | ||
114 | NativeAssert::Succeeded(hr, "Failed to format string."); | ||
115 | |||
116 | Assert::Equal<DWORD>(lstrlenW(scz), cch); | ||
117 | |||
118 | hr = VarFormatString(pVariables, L"PRE [PROP1] POST", NULL, &cch); | ||
119 | NativeAssert::Succeeded(hr, "Failed to format string."); | ||
120 | |||
121 | Assert::Equal<DWORD>(lstrlenW(scz), cch); | ||
122 | } | ||
123 | finally | ||
124 | { | ||
125 | ReleaseVariables(pVariables); | ||
126 | ReleaseStr(scz); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
131 | void VarUtilEscapeTest() | ||
132 | { | ||
133 | // test string escaping | ||
134 | VarEscapeStringHelper(L"[", L"[\\[]"); | ||
135 | VarEscapeStringHelper(L"]", L"[\\]]"); | ||
136 | VarEscapeStringHelper(L" [TEXT] ", L" [\\[]TEXT[\\]] "); | ||
137 | } | ||
138 | |||
139 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
140 | void VarUtilConditionTest() | ||
141 | { | ||
142 | HRESULT hr = S_OK; | ||
143 | VARIABLES_HANDLE pVariables = NULL; | ||
144 | |||
145 | try | ||
146 | { | ||
147 | hr = VarCreate(&pVariables); | ||
148 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
149 | |||
150 | // set variables | ||
151 | VarSetStringHelper(pVariables, L"PROP1", L"VAL1"); | ||
152 | VarSetStringHelper(pVariables, L"PROP2", L"VAL2"); | ||
153 | VarSetStringHelper(pVariables, L"PROP3", L"VAL3"); | ||
154 | VarSetStringHelper(pVariables, L"PROP4", L"BEGIN MID END"); | ||
155 | VarSetNumericHelper(pVariables, L"PROP5", 5); | ||
156 | VarSetNumericHelper(pVariables, L"PROP6", 6); | ||
157 | VarSetStringHelper(pVariables, L"PROP7", L""); | ||
158 | VarSetNumericHelper(pVariables, L"PROP8", 0); | ||
159 | VarSetStringHelper(pVariables, L"_PROP9", L"VAL9"); | ||
160 | VarSetNumericHelper(pVariables, L"PROP10", -10); | ||
161 | VarSetNumericHelper(pVariables, L"PROP11", 9223372036854775807ll); | ||
162 | VarSetNumericHelper(pVariables, L"PROP12", -9223372036854775808ll); | ||
163 | VarSetNumericHelper(pVariables, L"PROP13", 0x00010000); | ||
164 | VarSetNumericHelper(pVariables, L"PROP14", 0x00000001); | ||
165 | VarSetNumericHelper(pVariables, L"PROP15", 0x00010001); | ||
166 | VarSetVersionHelper(pVariables, L"PROP16", MAKEQWORDVERSION(0, 0, 0, 0)); | ||
167 | VarSetVersionHelper(pVariables, L"PROP17", MAKEQWORDVERSION(1, 0, 0, 0)); | ||
168 | VarSetVersionHelper(pVariables, L"PROP18", MAKEQWORDVERSION(1, 1, 0, 0)); | ||
169 | VarSetVersionHelper(pVariables, L"PROP19", MAKEQWORDVERSION(1, 1, 1, 0)); | ||
170 | VarSetVersionHelper(pVariables, L"PROP20", MAKEQWORDVERSION(1, 1, 1, 1)); | ||
171 | VarSetNumericHelper(pVariables, L"vPROP21", 1); | ||
172 | VarSetVersionHelper(pVariables, L"PROP22", MAKEQWORDVERSION(65535, 65535, 65535, 65535)); | ||
173 | VarSetStringHelper(pVariables, L"PROP23", L"1.1.1"); | ||
174 | |||
175 | // test conditions | ||
176 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1")); | ||
177 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5")); | ||
178 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP7")); | ||
179 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP8")); | ||
180 | Assert::True(EvaluateConditionHelper(pVariables, L"_PROP9")); | ||
181 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP16")); | ||
182 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17")); | ||
183 | |||
184 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\"")); | ||
185 | Assert::False(EvaluateConditionHelper(pVariables, L"NONE = \"NOT\"")); | ||
186 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 <> \"VAL1\"")); | ||
187 | Assert::True(EvaluateConditionHelper(pVariables, L"NONE <> \"NOT\"")); | ||
188 | |||
189 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 ~= \"val1\"")); | ||
190 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"val1\"")); | ||
191 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 ~<> \"val1\"")); | ||
192 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 <> \"val1\"")); | ||
193 | |||
194 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 = 5")); | ||
195 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 = 0")); | ||
196 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 <> 5")); | ||
197 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <> 0")); | ||
198 | |||
199 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP10 = -10")); | ||
200 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP10 <> -10")); | ||
201 | |||
202 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 = v1")); | ||
203 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 = v0")); | ||
204 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 <> v1")); | ||
205 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 <> v0")); | ||
206 | |||
207 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP16 = v0")); | ||
208 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 = v1")); | ||
209 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 = v1.1")); | ||
210 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 = v1.1.1")); | ||
211 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP20 = v1.1.1.1")); | ||
212 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP20 = v1.1.1.1.0")); | ||
213 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP20 = v1.1.1.1.1")); | ||
214 | Assert::True(EvaluateConditionHelper(pVariables, L"vPROP21 = 1")); | ||
215 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP23 = v1.1.1")); | ||
216 | Assert::True(EvaluateConditionHelper(pVariables, L"v1.1.1 = PROP23")); | ||
217 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 <> v1.1.1")); | ||
218 | Assert::True(EvaluateConditionHelper(pVariables, L"v1.1.1 <> PROP1")); | ||
219 | |||
220 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP11 = 9223372036854775806")); | ||
221 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP11 = 9223372036854775807")); | ||
222 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP11 = 9223372036854775808")); | ||
223 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP11 = 92233720368547758070000")); | ||
224 | |||
225 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP12 = -9223372036854775807")); | ||
226 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP12 = -9223372036854775808")); | ||
227 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP12 = -9223372036854775809")); | ||
228 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP12 = -92233720368547758080000")); | ||
229 | |||
230 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP22 = v65535.65535.65535.65535")); | ||
231 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP22 = v65536.65535.65535.65535")); | ||
232 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"PROP22 = v65535.655350000.65535.65535")); | ||
233 | |||
234 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 < 6")); | ||
235 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 < 5")); | ||
236 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 > 4")); | ||
237 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 > 5")); | ||
238 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <= 6")); | ||
239 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 <= 5")); | ||
240 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 <= 4")); | ||
241 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 >= 4")); | ||
242 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP5 >= 5")); | ||
243 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP5 >= 6")); | ||
244 | |||
245 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 << \"BEGIN\"")); | ||
246 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 << \"END\"")); | ||
247 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 >> \"END\"")); | ||
248 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 >> \"BEGIN\"")); | ||
249 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP4 >< \"MID\"")); | ||
250 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP4 >< \"NONE\"")); | ||
251 | |||
252 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP16 < v1.1")); | ||
253 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP16 < v0")); | ||
254 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP17 > v0.12")); | ||
255 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP17 > v1")); | ||
256 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 >= v1.0")); | ||
257 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP18 >= v1.1")); | ||
258 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP18 >= v2.1")); | ||
259 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.1234.1")); | ||
260 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.1.1")); | ||
261 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP19 <= v1.0.123")); | ||
262 | |||
263 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP6 = \"6\"")); | ||
264 | Assert::True(EvaluateConditionHelper(pVariables, L"\"6\" = PROP6")); | ||
265 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP6 = \"ABC\"")); | ||
266 | Assert::False(EvaluateConditionHelper(pVariables, L"\"ABC\" = PROP6")); | ||
267 | Assert::False(EvaluateConditionHelper(pVariables, L"\"ABC\" = PROP6")); | ||
268 | |||
269 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP13 << 1")); | ||
270 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP13 << 0")); | ||
271 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP14 >> 1")); | ||
272 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP14 >> 0")); | ||
273 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP15 >< 65537")); | ||
274 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP15 >< 0")); | ||
275 | |||
276 | Assert::False(EvaluateConditionHelper(pVariables, L"NOT PROP1")); | ||
277 | Assert::True(EvaluateConditionHelper(pVariables, L"NOT (PROP1 <> \"VAL1\")")); | ||
278 | |||
279 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"VAL2\"")); | ||
280 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
281 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" AND PROP2 = \"VAL2\"")); | ||
282 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" AND PROP2 = \"NOT\"")); | ||
283 | |||
284 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" OR PROP2 = \"VAL2\"")); | ||
285 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" OR PROP2 = \"NOT\"")); | ||
286 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" OR PROP2 = \"VAL2\"")); | ||
287 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"NOT\" OR PROP2 = \"NOT\"")); | ||
288 | |||
289 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"VAL2\" OR PROP3 = \"NOT\"")); | ||
290 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\" OR PROP3 = \"VAL3\"")); | ||
291 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND PROP2 = \"NOT\" OR PROP3 = \"NOT\"")); | ||
292 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP1 = \"VAL1\" AND (PROP2 = \"NOT\" OR PROP3 = \"VAL3\")")); | ||
293 | Assert::True(EvaluateConditionHelper(pVariables, L"(PROP1 = \"VAL1\" AND PROP2 = \"VAL2\") OR PROP3 = \"NOT\"")); | ||
294 | |||
295 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR PROP1 = \"VAL1\" AND PROP2 = \"VAL2\"")); | ||
296 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"VAL3\" OR PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
297 | Assert::False(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR PROP1 = \"VAL1\" AND PROP2 = \"NOT\"")); | ||
298 | Assert::True(EvaluateConditionHelper(pVariables, L"(PROP3 = \"NOT\" OR PROP1 = \"VAL1\") AND PROP2 = \"VAL2\"")); | ||
299 | Assert::True(EvaluateConditionHelper(pVariables, L"PROP3 = \"NOT\" OR (PROP1 = \"VAL1\" AND PROP2 = \"VAL2\")")); | ||
300 | |||
301 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"=")); | ||
302 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"(PROP1")); | ||
303 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"(PROP1 = \"")); | ||
304 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"1A")); | ||
305 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"*")); | ||
306 | |||
307 | Assert::True(EvaluateFailureConditionHelper(pVariables, L"1 == 1")); | ||
308 | } | ||
309 | finally | ||
310 | { | ||
311 | ReleaseVariables(pVariables); | ||
312 | } | ||
313 | } | ||
314 | |||
315 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
316 | void VarUtilValueTest() | ||
317 | { | ||
318 | HRESULT hr = S_OK; | ||
319 | VARIABLES_HANDLE pVariables = NULL; | ||
320 | VARIABLE_VALUE values[8]; | ||
321 | |||
322 | try | ||
323 | { | ||
324 | hr = VarCreate(&pVariables); | ||
325 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
326 | |||
327 | // set variables | ||
328 | InitNumericValue(pVariables, values + 0, 2, FALSE, 1, L"PROP1"); | ||
329 | InitStringValue(pVariables, values + 1, L"VAL2", FALSE, 2, L"PROP2"); | ||
330 | InitVersionValue(pVariables, values + 2, MAKEQWORDVERSION(1, 1, 0, 0), FALSE, 3, L"PROP3"); | ||
331 | InitNoneValue(pVariables, values + 3, FALSE, 4, L"PROP4"); | ||
332 | InitNoneValue(pVariables, values + 4, TRUE, 5, L"PROP5"); | ||
333 | InitVersionValue(pVariables, values + 5, MAKEQWORDVERSION(1, 1, 1, 0), TRUE, 6, L"PROP6"); | ||
334 | InitStringValue(pVariables, values + 6, L"7", TRUE, 7, L"PROP7"); | ||
335 | InitNumericValue(pVariables, values + 7, 11, TRUE, 8, L"PROP8"); | ||
336 | |||
337 | for (DWORD i = 0; i < 8; i++) | ||
338 | { | ||
339 | VerifyValue(pVariables, values + i); | ||
340 | } | ||
341 | } | ||
342 | finally | ||
343 | { | ||
344 | VarDestroy(pVariables, FreeValueContext); | ||
345 | } | ||
346 | } | ||
347 | |||
348 | [NamedFact(Skip = "varutil Not Implemented Yet.")] | ||
349 | void VarUtilEnumTest() | ||
350 | { | ||
351 | HRESULT hr = S_OK; | ||
352 | const DWORD dwIndex = 8; | ||
353 | VARIABLES_HANDLE pVariables = NULL; | ||
354 | VARIABLE_ENUM_HANDLE pEnum = NULL; | ||
355 | VARIABLE_VALUE values[dwIndex]; | ||
356 | VARIABLE_VALUE* pValue = NULL; | ||
357 | |||
358 | try | ||
359 | { | ||
360 | hr = VarCreate(&pVariables); | ||
361 | NativeAssert::Succeeded(hr, "Failed to initialize variables."); | ||
362 | |||
363 | hr = VarStartEnum(pVariables, &pEnum, &pValue); | ||
364 | NativeAssert::ValidReturnCode(hr, E_NOMOREITEMS); | ||
365 | |||
366 | // set variables | ||
367 | InitNumericValue(pVariables, values + 0, 2, FALSE, 0, L"PROP1"); | ||
368 | InitStringValue(pVariables, values + 1, L"VAL2", FALSE, 0, L"PROP2"); | ||
369 | InitVersionValue(pVariables, values + 2, MAKEQWORDVERSION(1, 1, 0, 0), FALSE, 0, L"PROP3"); | ||
370 | InitNoneValue(pVariables, values + 3, FALSE, 0, L"PROP4"); | ||
371 | InitNoneValue(pVariables, values + 4, TRUE, 0, L"PROP5"); | ||
372 | InitVersionValue(pVariables, values + 5, MAKEQWORDVERSION(1, 1, 1, 0), TRUE, 0, L"PROP6"); | ||
373 | InitStringValue(pVariables, values + 6, L"7", TRUE, 0, L"PROP7"); | ||
374 | InitNumericValue(pVariables, values + 7, 11, TRUE, 0, L"PROP8"); | ||
375 | |||
376 | hr = VarStartEnum(pVariables, &pEnum, &pValue); | ||
377 | |||
378 | for (DWORD i = dwIndex - 1; i; --i) | ||
379 | { | ||
380 | NativeAssert::ValidReturnCode(hr, S_OK); | ||
381 | |||
382 | VarUtilContext* pContext = reinterpret_cast<VarUtilContext*>(pValue->pvContext); | ||
383 | pContext->dw += 1; | ||
384 | |||
385 | hr = VarNextVariable(pEnum, &pValue); | ||
386 | } | ||
387 | |||
388 | NativeAssert::ValidReturnCode(hr, E_NOMOREITEMS); | ||
389 | |||
390 | for (DWORD j = 0; j < dwIndex; j++) | ||
391 | { | ||
392 | VarUtilContext* pContext = reinterpret_cast<VarUtilContext*>(values[j].pvContext); | ||
393 | NativeAssert::Equal<DWORD>(1, pContext->dw); | ||
394 | } | ||
395 | |||
396 | VarFinishEnum(pEnum); | ||
397 | pEnum = NULL; | ||
398 | |||
399 | hr = VarStartEnum(pVariables, &pEnum, &pValue); | ||
400 | |||
401 | for (DWORD i = dwIndex - 1; i; --i) | ||
402 | { | ||
403 | NativeAssert::ValidReturnCode(hr, S_OK); | ||
404 | |||
405 | VarUtilContext* pContext = reinterpret_cast<VarUtilContext*>(pValue->pvContext); | ||
406 | pContext->dw += 1; | ||
407 | |||
408 | hr = VarNextVariable(pEnum, &pValue); | ||
409 | } | ||
410 | |||
411 | NativeAssert::ValidReturnCode(hr, E_NOMOREITEMS); | ||
412 | |||
413 | for (DWORD j = 0; j < dwIndex; j++) | ||
414 | { | ||
415 | VarUtilContext* pContext = reinterpret_cast<VarUtilContext*>(values[j].pvContext); | ||
416 | NativeAssert::Equal<DWORD>(2, pContext->dw); | ||
417 | } | ||
418 | } | ||
419 | finally | ||
420 | { | ||
421 | VarFinishEnum(pEnum); | ||
422 | ReleaseVariableValue(pValue); | ||
423 | VarDestroy(pVariables, FreeValueContext); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | private: | ||
428 | void InitNoneValue(VARIABLES_HANDLE pVariables, VARIABLE_VALUE* pValue, BOOL fHidden, DWORD dw, LPCWSTR wz) | ||
429 | { | ||
430 | pValue->type = VARIABLE_VALUE_TYPE_NONE; | ||
431 | pValue->fHidden = fHidden; | ||
432 | |||
433 | InitValueContext(pValue, dw, wz); | ||
434 | |||
435 | HRESULT hr = VarSetValue(pVariables, wz, pValue); | ||
436 | NativeAssert::Succeeded(hr, "Failed to set value for variable {0}", wz); | ||
437 | } | ||
438 | |||
439 | void InitNumericValue(VARIABLES_HANDLE pVariables, VARIABLE_VALUE* pValue, LONGLONG llValue, BOOL fHidden, DWORD dw, LPCWSTR wz) | ||
440 | { | ||
441 | pValue->type = VARIABLE_VALUE_TYPE_NUMERIC; | ||
442 | pValue->fHidden = fHidden; | ||
443 | |||
444 | pValue->llValue = llValue; | ||
445 | |||
446 | InitValueContext(pValue, dw, wz); | ||
447 | |||
448 | HRESULT hr = VarSetValue(pVariables, wz, pValue); | ||
449 | NativeAssert::Succeeded(hr, "Failed to set value for variable {0}", wz); | ||
450 | } | ||
451 | |||
452 | void InitStringValue(VARIABLES_HANDLE pVariables, VARIABLE_VALUE* pValue, LPWSTR wzValue, BOOL fHidden, DWORD dw, LPCWSTR wz) | ||
453 | { | ||
454 | pValue->type = VARIABLE_VALUE_TYPE_STRING; | ||
455 | pValue->fHidden = fHidden; | ||
456 | |||
457 | HRESULT hr = StrAllocString(&pValue->sczValue, wzValue, 0); | ||
458 | NativeAssert::Succeeded(hr, "Failed to alloc string: {0}", wzValue); | ||
459 | |||
460 | InitValueContext(pValue, dw, wz); | ||
461 | |||
462 | hr = VarSetValue(pVariables, wz, pValue); | ||
463 | NativeAssert::Succeeded(hr, "Failed to set value for variable {0}", wz); | ||
464 | } | ||
465 | |||
466 | void InitVersionValue(VARIABLES_HANDLE pVariables, VARIABLE_VALUE* pValue, DWORD64 qwValue, BOOL fHidden, DWORD dw, LPCWSTR wz) | ||
467 | { | ||
468 | pValue->type = VARIABLE_VALUE_TYPE_VERSION; | ||
469 | pValue->fHidden = fHidden; | ||
470 | |||
471 | pValue->qwValue = qwValue; | ||
472 | |||
473 | InitValueContext(pValue, dw, wz); | ||
474 | |||
475 | HRESULT hr = VarSetValue(pVariables, wz, pValue); | ||
476 | NativeAssert::Succeeded(hr, "Failed to set value for variable {0}", wz); | ||
477 | } | ||
478 | |||
479 | void InitValueContext(VARIABLE_VALUE* pValue, DWORD dw, LPCWSTR wz) | ||
480 | { | ||
481 | pValue->pvContext = MemAlloc(sizeof(VarUtilContext), TRUE); | ||
482 | VarUtilContext* pContext = reinterpret_cast<VarUtilContext*>(pValue->pvContext); | ||
483 | if (!pContext) | ||
484 | { | ||
485 | throw gcnew OutOfMemoryException(); | ||
486 | } | ||
487 | |||
488 | pContext->dw = dw; | ||
489 | |||
490 | HRESULT hr = StrAllocString(&pContext->scz, wz, 0); | ||
491 | NativeAssert::Succeeded(hr, "Failed to alloc string: {0}", wz); | ||
492 | } | ||
493 | |||
494 | void VerifyValue(VARIABLES_HANDLE pVariables, VARIABLE_VALUE* pExpectedValue) | ||
495 | { | ||
496 | VARIABLE_VALUE* pActualValue = NULL; | ||
497 | |||
498 | try | ||
499 | { | ||
500 | VarUtilContext* pExpectedContext = reinterpret_cast<VarUtilContext*>(pExpectedValue->pvContext); | ||
501 | NativeAssert::True(NULL != pExpectedContext); | ||
502 | |||
503 | HRESULT hr = VarGetValue(pVariables, pExpectedContext->scz, &pActualValue); | ||
504 | NativeAssert::Succeeded(hr, "Failed to get value: {0}", pExpectedContext->scz); | ||
505 | |||
506 | NativeAssert::Equal<DWORD>(pExpectedValue->type, pActualValue->type); | ||
507 | NativeAssert::InRange<DWORD>(pExpectedValue->type, VARIABLE_VALUE_TYPE_NONE, VARIABLE_VALUE_TYPE_STRING); | ||
508 | |||
509 | switch (pExpectedValue->type) | ||
510 | { | ||
511 | case VARIABLE_VALUE_TYPE_NONE: | ||
512 | case VARIABLE_VALUE_TYPE_VERSION: | ||
513 | NativeAssert::Equal(pExpectedValue->qwValue, pActualValue->qwValue); | ||
514 | break; | ||
515 | case VARIABLE_VALUE_TYPE_NUMERIC: | ||
516 | NativeAssert::Equal(pExpectedValue->llValue, pActualValue->llValue); | ||
517 | break; | ||
518 | case VARIABLE_VALUE_TYPE_STRING: | ||
519 | NativeAssert::StringEqual(pExpectedValue->sczValue, pActualValue->sczValue); | ||
520 | break; | ||
521 | } | ||
522 | |||
523 | NativeAssert::Equal(pExpectedValue->fHidden, pActualValue->fHidden); | ||
524 | NativeAssert::True(pExpectedValue->pvContext == pActualValue->pvContext); | ||
525 | } | ||
526 | finally | ||
527 | { | ||
528 | ReleaseVariableValue(pActualValue); | ||
529 | } | ||
530 | } | ||
531 | }; | ||
532 | } | ||