diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:49:15 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
commit | 584213c5ffeca09b3fe24bd5e92f73fd057ac642 (patch) | |
tree | 45619273a56248d662dda598bca3076efa8a5135 /src/libs/dutil/test/DUtilUnitTest | |
parent | 648f370f7966b2738c1446601057d888bbd2c70f (diff) | |
download | wix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.tar.gz wix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.tar.bz2 wix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.zip |
Add RegReadUnexpandedString to get an unexpanded REG_EXPAND_SZ value.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
4 files changed, 685 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj index c37bdad1..5b40eaf1 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj | |||
@@ -61,6 +61,7 @@ | |||
61 | <!-- Warnings from referencing netstandard dlls --> | 61 | <!-- Warnings from referencing netstandard dlls --> |
62 | <DisableSpecificWarnings>4564;4691</DisableSpecificWarnings> | 62 | <DisableSpecificWarnings>4564;4691</DisableSpecificWarnings> |
63 | </ClCompile> | 63 | </ClCompile> |
64 | <ClCompile Include="RegUtilTest.cpp" /> | ||
64 | <ClCompile Include="SceUtilTest.cpp" Condition=" Exists('$(SqlCESdkIncludePath)') " /> | 65 | <ClCompile Include="SceUtilTest.cpp" Condition=" Exists('$(SqlCESdkIncludePath)') " /> |
65 | <ClCompile Include="StrUtilTest.cpp" /> | 66 | <ClCompile Include="StrUtilTest.cpp" /> |
66 | <ClCompile Include="UriUtilTest.cpp" /> | 67 | <ClCompile Include="UriUtilTest.cpp" /> |
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters index 4df7af89..fde49348 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | |||
@@ -54,6 +54,9 @@ | |||
54 | <ClCompile Include="precomp.cpp"> | 54 | <ClCompile Include="precomp.cpp"> |
55 | <Filter>Source Files</Filter> | 55 | <Filter>Source Files</Filter> |
56 | </ClCompile> | 56 | </ClCompile> |
57 | <ClCompile Include="RegUtilTest.cpp"> | ||
58 | <Filter>Source Files</Filter> | ||
59 | </ClCompile> | ||
57 | <ClCompile Include="StrUtilTest.cpp"> | 60 | <ClCompile Include="StrUtilTest.cpp"> |
58 | <Filter>Source Files</Filter> | 61 | <Filter>Source Files</Filter> |
59 | </ClCompile> | 62 | </ClCompile> |
diff --git a/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp index 273f2eb6..09d0aeab 100644 --- a/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp | |||
@@ -481,6 +481,8 @@ namespace DutilTests | |||
481 | ReleaseMem(pResults->rgDirectories); | 481 | ReleaseMem(pResults->rgDirectories); |
482 | ReleaseMem(pResults->rgRegKeys); | 482 | ReleaseMem(pResults->rgRegKeys); |
483 | ReleaseMem(pResults); | 483 | ReleaseMem(pResults); |
484 | |||
485 | RegUninitialize(); | ||
484 | } | 486 | } |
485 | } | 487 | } |
486 | }; | 488 | }; |
diff --git a/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp new file mode 100644 index 00000000..575e3238 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp | |||
@@ -0,0 +1,679 @@ | |||
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 | using namespace System; | ||
6 | using namespace System::Collections::Generic; | ||
7 | using namespace System::Runtime::InteropServices; | ||
8 | using namespace Xunit; | ||
9 | using namespace WixBuildTools::TestSupport; | ||
10 | |||
11 | LPCWSTR wzBaseRegKey = L"Software\\RegUtilTest\\"; | ||
12 | LPWSTR rgwzMultiValue[2] = { L"First", L"Second" }; | ||
13 | LPWSTR rgwzEmptyMultiValue[2] = { L"", L"" }; | ||
14 | |||
15 | HKEY hkBase; | ||
16 | |||
17 | namespace DutilTests | ||
18 | { | ||
19 | public ref class RegUtil : IDisposable | ||
20 | { | ||
21 | private: | ||
22 | |||
23 | void CreateBaseKey() | ||
24 | { | ||
25 | HRESULT hr = RegCreate(HKEY_CURRENT_USER, wzBaseRegKey, KEY_ALL_ACCESS, &hkBase); | ||
26 | NativeAssert::Succeeded(hr, "Failed to create base key."); | ||
27 | } | ||
28 | |||
29 | public: | ||
30 | RegUtil() | ||
31 | { | ||
32 | HRESULT hr = RegInitialize(); | ||
33 | NativeAssert::Succeeded(hr, "RegInitialize failed."); | ||
34 | } | ||
35 | |||
36 | ~RegUtil() | ||
37 | { | ||
38 | RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | ||
39 | |||
40 | if (hkBase) | ||
41 | { | ||
42 | RegDelete(hkBase, NULL, REG_KEY_DEFAULT, TRUE); | ||
43 | } | ||
44 | |||
45 | ReleaseRegKey(hkBase); | ||
46 | |||
47 | RegUninitialize(); | ||
48 | } | ||
49 | |||
50 | [Fact] | ||
51 | void RegUtilStringValueTest() | ||
52 | { | ||
53 | this->StringValueTest(); | ||
54 | } | ||
55 | |||
56 | [Fact] | ||
57 | void RegUtilStringValueFallbackTest() | ||
58 | { | ||
59 | RegFunctionForceFallback(); | ||
60 | this->StringValueTest(); | ||
61 | } | ||
62 | |||
63 | void StringValueTest() | ||
64 | { | ||
65 | HRESULT hr = S_OK; | ||
66 | LPWSTR sczValue = NULL; | ||
67 | LPCWSTR wzValue = L"Value"; | ||
68 | |||
69 | try | ||
70 | { | ||
71 | this->CreateBaseKey(); | ||
72 | |||
73 | hr = RegWriteString(hkBase, L"String", wzValue); | ||
74 | NativeAssert::Succeeded(hr, "Failed to write string value."); | ||
75 | |||
76 | hr = RegReadString(hkBase, L"String", &sczValue); | ||
77 | NativeAssert::Succeeded(hr, "Failed to read string value."); | ||
78 | NativeAssert::StringEqual(wzValue, sczValue); | ||
79 | |||
80 | ReleaseNullStr(sczValue); | ||
81 | hr = StrAllocString(&sczValue, L"e", 0); | ||
82 | NativeAssert::Succeeded(hr, "Failed to reallocate string value."); | ||
83 | |||
84 | hr = RegReadString(hkBase, L"String", &sczValue); | ||
85 | NativeAssert::Succeeded(hr, "Failed to read string value."); | ||
86 | NativeAssert::StringEqual(wzValue, sczValue); | ||
87 | } | ||
88 | finally | ||
89 | { | ||
90 | ReleaseStr(sczValue); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | [Fact] | ||
95 | void RegUtilPartialStringValueTest() | ||
96 | { | ||
97 | this->PartialStringValueTest(); | ||
98 | } | ||
99 | |||
100 | [Fact] | ||
101 | void RegUtilPartialStringValueFallbackTest() | ||
102 | { | ||
103 | RegFunctionForceFallback(); | ||
104 | this->PartialStringValueTest(); | ||
105 | } | ||
106 | |||
107 | void PartialStringValueTest() | ||
108 | { | ||
109 | HRESULT hr = S_OK; | ||
110 | LPWSTR sczValue = NULL; | ||
111 | LPCWSTR wzValue = L"Value"; | ||
112 | BOOL fNeedsExpansion = FALSE; | ||
113 | |||
114 | try | ||
115 | { | ||
116 | this->CreateBaseKey(); | ||
117 | |||
118 | // Use API directly to write non-null terminated string. | ||
119 | hr = HRESULT_FROM_WIN32(::RegSetValueExW(hkBase, L"PartialString", 0, REG_SZ, reinterpret_cast<const BYTE*>(wzValue), 4 * sizeof(WCHAR))); | ||
120 | NativeAssert::Succeeded(hr, "Failed to write partial string value."); | ||
121 | |||
122 | hr = RegReadString(hkBase, L"PartialString", &sczValue); | ||
123 | NativeAssert::Succeeded(hr, "Failed to read partial string value."); | ||
124 | NativeAssert::StringEqual(L"Valu", sczValue); | ||
125 | |||
126 | hr = RegReadUnexpandedString(hkBase, L"PartialString", &fNeedsExpansion, &sczValue); | ||
127 | NativeAssert::Succeeded(hr, "Failed to read partial unexpanded string value."); | ||
128 | NativeAssert::StringEqual(L"Valu", sczValue); | ||
129 | Assert::False(fNeedsExpansion); | ||
130 | } | ||
131 | finally | ||
132 | { | ||
133 | ReleaseStr(sczValue); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | [Fact] | ||
138 | void RegUtilEmptyStringValueTest() | ||
139 | { | ||
140 | this->EmptyStringValueTest(); | ||
141 | } | ||
142 | |||
143 | [Fact] | ||
144 | void RegUtilEmptyStringValueFallbackTest() | ||
145 | { | ||
146 | RegFunctionForceFallback(); | ||
147 | this->EmptyStringValueTest(); | ||
148 | } | ||
149 | |||
150 | void EmptyStringValueTest() | ||
151 | { | ||
152 | HRESULT hr = S_OK; | ||
153 | LPWSTR sczValue = NULL; | ||
154 | |||
155 | try | ||
156 | { | ||
157 | this->CreateBaseKey(); | ||
158 | |||
159 | // Use API directly to write non-null terminated string. | ||
160 | hr = HRESULT_FROM_WIN32(::RegSetValueExW(hkBase, L"EmptyString", 0, REG_SZ, reinterpret_cast<const BYTE*>(L""), 0)); | ||
161 | NativeAssert::Succeeded(hr, "Failed to write partial string value."); | ||
162 | |||
163 | hr = RegReadString(hkBase, L"EmptyString", &sczValue); | ||
164 | NativeAssert::Succeeded(hr, "Failed to read partial string value."); | ||
165 | NativeAssert::StringEqual(L"", sczValue); | ||
166 | } | ||
167 | finally | ||
168 | { | ||
169 | ReleaseStr(sczValue); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | [Fact] | ||
174 | void RegUtilExpandStringValueTest() | ||
175 | { | ||
176 | this->ExpandStringValueTest(); | ||
177 | } | ||
178 | |||
179 | [Fact] | ||
180 | void RegUtilExpandStringValueFallbackTest() | ||
181 | { | ||
182 | RegFunctionForceFallback(); | ||
183 | this->ExpandStringValueTest(); | ||
184 | } | ||
185 | |||
186 | void ExpandStringValueTest() | ||
187 | { | ||
188 | HRESULT hr = S_OK; | ||
189 | LPWSTR sczValue = NULL; | ||
190 | LPCWSTR wzValue = L"Value_%USERNAME%"; | ||
191 | String^ expandedValue = Environment::ExpandEnvironmentVariables(gcnew String(wzValue)); | ||
192 | |||
193 | try | ||
194 | { | ||
195 | this->CreateBaseKey(); | ||
196 | |||
197 | hr = RegWriteExpandString(hkBase, L"ExpandString", wzValue); | ||
198 | NativeAssert::Succeeded(hr, "Failed to write expand string value."); | ||
199 | |||
200 | hr = RegReadString(hkBase, L"ExpandString", &sczValue); | ||
201 | NativeAssert::Succeeded(hr, "Failed to read expand string value."); | ||
202 | WixAssert::StringEqual(expandedValue, gcnew String(sczValue), false); | ||
203 | } | ||
204 | finally | ||
205 | { | ||
206 | ReleaseStr(sczValue); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | [Fact] | ||
211 | void RegUtilNotExpandStringValueTest() | ||
212 | { | ||
213 | this->NotExpandStringValueTest(); | ||
214 | } | ||
215 | |||
216 | [Fact] | ||
217 | void RegUtilNotExpandStringValueFallbackTest() | ||
218 | { | ||
219 | RegFunctionForceFallback(); | ||
220 | this->NotExpandStringValueTest(); | ||
221 | } | ||
222 | |||
223 | void NotExpandStringValueTest() | ||
224 | { | ||
225 | HRESULT hr = S_OK; | ||
226 | LPWSTR sczValue = NULL; | ||
227 | BOOL fNeedsExpansion = FALSE; | ||
228 | LPCWSTR wzValue = L"Value_%USERNAME%"; | ||
229 | |||
230 | try | ||
231 | { | ||
232 | this->CreateBaseKey(); | ||
233 | |||
234 | hr = RegWriteExpandString(hkBase, L"NotExpandString", wzValue); | ||
235 | NativeAssert::Succeeded(hr, "Failed to write expand string value."); | ||
236 | |||
237 | hr = RegReadUnexpandedString(hkBase, L"NotExpandString", &fNeedsExpansion, &sczValue); | ||
238 | NativeAssert::Succeeded(hr, "Failed to read expand string value."); | ||
239 | NativeAssert::StringEqual(wzValue, sczValue); | ||
240 | Assert::True(fNeedsExpansion); | ||
241 | } | ||
242 | finally | ||
243 | { | ||
244 | ReleaseStr(sczValue); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | [Fact] | ||
249 | void RegUtilMultiStringValueTest() | ||
250 | { | ||
251 | this->MultiStringValueTest(); | ||
252 | } | ||
253 | |||
254 | [Fact] | ||
255 | void RegUtilMultiStringValueFallbackTest() | ||
256 | { | ||
257 | RegFunctionForceFallback(); | ||
258 | this->MultiStringValueTest(); | ||
259 | } | ||
260 | |||
261 | void MultiStringValueTest() | ||
262 | { | ||
263 | HRESULT hr = S_OK; | ||
264 | LPWSTR* rgsczStrings = NULL; | ||
265 | DWORD cStrings = 0; | ||
266 | |||
267 | try | ||
268 | { | ||
269 | this->CreateBaseKey(); | ||
270 | |||
271 | hr = RegWriteStringArray(hkBase, L"MultiString", rgwzMultiValue, 2); | ||
272 | NativeAssert::Succeeded(hr, "Failed to write multi string value."); | ||
273 | |||
274 | hr = RegReadStringArray(hkBase, L"MultiString", &rgsczStrings, &cStrings); | ||
275 | NativeAssert::Succeeded(hr, "Failed to read multi string value."); | ||
276 | Assert::Equal<DWORD>(2, cStrings); | ||
277 | NativeAssert::StringEqual(L"First", rgsczStrings[0]); | ||
278 | NativeAssert::StringEqual(L"Second", rgsczStrings[1]); | ||
279 | } | ||
280 | finally | ||
281 | { | ||
282 | ReleaseStrArray(rgsczStrings, cStrings); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | [Fact] | ||
287 | void RegUtilPartialMultiStringValueTest() | ||
288 | { | ||
289 | this->PartialMultiStringValueTest(); | ||
290 | } | ||
291 | |||
292 | [Fact] | ||
293 | void RegUtilPartialMultiStringValueFallbackTest() | ||
294 | { | ||
295 | RegFunctionForceFallback(); | ||
296 | this->PartialMultiStringValueTest(); | ||
297 | } | ||
298 | |||
299 | void PartialMultiStringValueTest() | ||
300 | { | ||
301 | HRESULT hr = S_OK; | ||
302 | LPWSTR* rgsczStrings = NULL; | ||
303 | DWORD cStrings = 0; | ||
304 | |||
305 | try | ||
306 | { | ||
307 | this->CreateBaseKey(); | ||
308 | |||
309 | // Use API directly to write non-double-null terminated string. | ||
310 | hr = HRESULT_FROM_WIN32(::RegSetValueExW(hkBase, L"PartialMultiString", 0, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(L"First\0Second"), 13 * sizeof(WCHAR))); | ||
311 | NativeAssert::Succeeded(hr, "Failed to write partial multi string value."); | ||
312 | |||
313 | hr = RegReadStringArray(hkBase, L"PartialMultiString", &rgsczStrings, &cStrings); | ||
314 | NativeAssert::Succeeded(hr, "Failed to read partial multi string value."); | ||
315 | Assert::Equal<DWORD>(2, cStrings); | ||
316 | NativeAssert::StringEqual(L"First", rgsczStrings[0]); | ||
317 | NativeAssert::StringEqual(L"Second", rgsczStrings[1]); | ||
318 | } | ||
319 | finally | ||
320 | { | ||
321 | ReleaseStrArray(rgsczStrings, cStrings); | ||
322 | } | ||
323 | } | ||
324 | |||
325 | [Fact] | ||
326 | void RegUtilEmptyMultiStringValueTest() | ||
327 | { | ||
328 | this->EmptyMultiStringValueTest(); | ||
329 | } | ||
330 | |||
331 | [Fact] | ||
332 | void RegUtilEmptyMultiStringValueFallbackTest() | ||
333 | { | ||
334 | RegFunctionForceFallback(); | ||
335 | this->EmptyMultiStringValueTest(); | ||
336 | } | ||
337 | |||
338 | void EmptyMultiStringValueTest() | ||
339 | { | ||
340 | HRESULT hr = S_OK; | ||
341 | LPWSTR* rgsczStrings = NULL; | ||
342 | DWORD cStrings = 0; | ||
343 | |||
344 | try | ||
345 | { | ||
346 | this->CreateBaseKey(); | ||
347 | |||
348 | hr = RegWriteStringArray(hkBase, L"EmptyMultiString", rgwzMultiValue, 0); | ||
349 | NativeAssert::Succeeded(hr, "Failed to write empty multi string value."); | ||
350 | |||
351 | hr = RegReadStringArray(hkBase, L"EmptyMultiString", &rgsczStrings, &cStrings); | ||
352 | NativeAssert::Succeeded(hr, "Failed to read empty multi string value."); | ||
353 | Assert::Equal<DWORD>(0, cStrings); | ||
354 | } | ||
355 | finally | ||
356 | { | ||
357 | ReleaseStrArray(rgsczStrings, cStrings); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | [Fact] | ||
362 | void RegUtilOneEmptyMultiStringValueTest() | ||
363 | { | ||
364 | this->OneEmptyMultiStringValueTest(); | ||
365 | } | ||
366 | |||
367 | [Fact] | ||
368 | void RegUtilOneEmptyMultiStringValueFallbackTest() | ||
369 | { | ||
370 | RegFunctionForceFallback(); | ||
371 | this->OneEmptyMultiStringValueTest(); | ||
372 | } | ||
373 | |||
374 | void OneEmptyMultiStringValueTest() | ||
375 | { | ||
376 | HRESULT hr = S_OK; | ||
377 | LPWSTR* rgsczStrings = NULL; | ||
378 | DWORD cStrings = 0; | ||
379 | |||
380 | try | ||
381 | { | ||
382 | this->CreateBaseKey(); | ||
383 | |||
384 | hr = RegWriteStringArray(hkBase, L"OneEmptyMultiString", rgwzEmptyMultiValue, 1); | ||
385 | NativeAssert::Succeeded(hr, "Failed to write one empty multi string value."); | ||
386 | |||
387 | hr = RegReadStringArray(hkBase, L"OneEmptyMultiString", &rgsczStrings, &cStrings); | ||
388 | NativeAssert::Succeeded(hr, "Failed to read one empty multi string value."); | ||
389 | Assert::Equal<DWORD>(0, cStrings); | ||
390 | } | ||
391 | finally | ||
392 | { | ||
393 | ReleaseStrArray(rgsczStrings, cStrings); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | [Fact] | ||
398 | void RegUtilTwoEmptyMultiStringValueTest() | ||
399 | { | ||
400 | this->TwoEmptyMultiStringValueTest(); | ||
401 | } | ||
402 | |||
403 | [Fact] | ||
404 | void RegUtilTwoEmptyMultiStringValueFallbackTest() | ||
405 | { | ||
406 | RegFunctionForceFallback(); | ||
407 | this->TwoEmptyMultiStringValueTest(); | ||
408 | } | ||
409 | |||
410 | void TwoEmptyMultiStringValueTest() | ||
411 | { | ||
412 | HRESULT hr = S_OK; | ||
413 | LPWSTR* rgsczStrings = NULL; | ||
414 | DWORD cStrings = 0; | ||
415 | |||
416 | try | ||
417 | { | ||
418 | this->CreateBaseKey(); | ||
419 | |||
420 | hr = RegWriteStringArray(hkBase, L"OneEmptyMultiString", rgwzEmptyMultiValue, 2); | ||
421 | NativeAssert::Succeeded(hr, "Failed to write one empty multi string value."); | ||
422 | |||
423 | hr = RegReadStringArray(hkBase, L"OneEmptyMultiString", &rgsczStrings, &cStrings); | ||
424 | NativeAssert::Succeeded(hr, "Failed to read one empty multi string value."); | ||
425 | Assert::Equal<DWORD>(2, cStrings); | ||
426 | NativeAssert::StringEqual(L"", rgsczStrings[0]); | ||
427 | NativeAssert::StringEqual(L"", rgsczStrings[1]); | ||
428 | } | ||
429 | finally | ||
430 | { | ||
431 | ReleaseStrArray(rgsczStrings, cStrings); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | [Fact] | ||
436 | void RegUtilOnePartialEmptyMultiStringValueTest() | ||
437 | { | ||
438 | this->OnePartialEmptyMultiStringValueTest(); | ||
439 | } | ||
440 | |||
441 | [Fact] | ||
442 | void RegUtilOnePartialEmptyMultiStringValueFallbackTest() | ||
443 | { | ||
444 | RegFunctionForceFallback(); | ||
445 | this->OnePartialEmptyMultiStringValueTest(); | ||
446 | } | ||
447 | |||
448 | void OnePartialEmptyMultiStringValueTest() | ||
449 | { | ||
450 | HRESULT hr = S_OK; | ||
451 | LPWSTR* rgsczStrings = NULL; | ||
452 | DWORD cStrings = 0; | ||
453 | |||
454 | try | ||
455 | { | ||
456 | this->CreateBaseKey(); | ||
457 | |||
458 | // Use API directly to write non-double-null terminated string. | ||
459 | hr = HRESULT_FROM_WIN32(::RegSetValueExW(hkBase, L"OnePartialEmptyMultiString", 0, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(L""), 1 * sizeof(WCHAR))); | ||
460 | NativeAssert::Succeeded(hr, "Failed to write partial empty multi string value."); | ||
461 | |||
462 | hr = RegReadStringArray(hkBase, L"OnePartialEmptyMultiString", &rgsczStrings, &cStrings); | ||
463 | NativeAssert::Succeeded(hr, "Failed to read partial empty multi string value."); | ||
464 | Assert::Equal<DWORD>(0, cStrings); | ||
465 | } | ||
466 | finally | ||
467 | { | ||
468 | ReleaseStrArray(rgsczStrings, cStrings); | ||
469 | } | ||
470 | } | ||
471 | |||
472 | [Fact] | ||
473 | void RegUtilBinaryValueTest() | ||
474 | { | ||
475 | this->BinaryValueTest(); | ||
476 | } | ||
477 | |||
478 | [Fact] | ||
479 | void RegUtilBinaryValueFallbackTest() | ||
480 | { | ||
481 | RegFunctionForceFallback(); | ||
482 | this->BinaryValueTest(); | ||
483 | } | ||
484 | |||
485 | void BinaryValueTest() | ||
486 | { | ||
487 | HRESULT hr = S_OK; | ||
488 | BYTE pbSource[4] = { 1, 2, 3, 4 }; | ||
489 | BYTE* pbBuffer = NULL; | ||
490 | SIZE_T cbBuffer = 0; | ||
491 | |||
492 | try | ||
493 | { | ||
494 | this->CreateBaseKey(); | ||
495 | |||
496 | hr = RegWriteBinary(hkBase, L"Binary", pbSource, 4); | ||
497 | NativeAssert::Succeeded(hr, "Failed to write binary value."); | ||
498 | |||
499 | hr = RegReadBinary(hkBase, L"Binary", &pbBuffer, &cbBuffer); | ||
500 | NativeAssert::Succeeded(hr, "Failed to read binary value."); | ||
501 | Assert::Equal<DWORD>(4, cbBuffer); | ||
502 | Assert::Equal<BYTE>(1, pbBuffer[0]); | ||
503 | Assert::Equal<BYTE>(2, pbBuffer[1]); | ||
504 | Assert::Equal<BYTE>(3, pbBuffer[2]); | ||
505 | Assert::Equal<BYTE>(4, pbBuffer[3]); | ||
506 | } | ||
507 | finally | ||
508 | { | ||
509 | ReleaseMem(pbBuffer); | ||
510 | } | ||
511 | } | ||
512 | |||
513 | [Fact] | ||
514 | void RegUtilEmptyBinaryValueTest() | ||
515 | { | ||
516 | this->EmptyBinaryValueTest(); | ||
517 | } | ||
518 | |||
519 | [Fact] | ||
520 | void RegUtilEmptyBinaryValueFallbackTest() | ||
521 | { | ||
522 | RegFunctionForceFallback(); | ||
523 | this->EmptyBinaryValueTest(); | ||
524 | } | ||
525 | |||
526 | void EmptyBinaryValueTest() | ||
527 | { | ||
528 | HRESULT hr = S_OK; | ||
529 | BYTE* pbBuffer = NULL; | ||
530 | SIZE_T cbBuffer = 0; | ||
531 | |||
532 | try | ||
533 | { | ||
534 | this->CreateBaseKey(); | ||
535 | |||
536 | hr = RegWriteBinary(hkBase, L"Binary", NULL, 0); | ||
537 | NativeAssert::Succeeded(hr, "Failed to write binary value."); | ||
538 | |||
539 | hr = RegReadBinary(hkBase, L"Binary", &pbBuffer, &cbBuffer); | ||
540 | NativeAssert::Succeeded(hr, "Failed to read binary value."); | ||
541 | Assert::Equal<DWORD>(0, cbBuffer); | ||
542 | } | ||
543 | finally | ||
544 | { | ||
545 | ReleaseMem(pbBuffer); | ||
546 | } | ||
547 | } | ||
548 | |||
549 | [Fact] | ||
550 | void RegUtilQwordVersionValueTest() | ||
551 | { | ||
552 | this->QwordVersionValueTest(); | ||
553 | } | ||
554 | |||
555 | [Fact] | ||
556 | void RegUtilQwordVersionValueFallbackTest() | ||
557 | { | ||
558 | RegFunctionForceFallback(); | ||
559 | this->QwordVersionValueTest(); | ||
560 | } | ||
561 | |||
562 | void QwordVersionValueTest() | ||
563 | { | ||
564 | HRESULT hr = S_OK; | ||
565 | DWORD64 qwVersion = FILEMAKEVERSION(1, 2, 3, 4); | ||
566 | DWORD64 qwValue = 0; | ||
567 | |||
568 | this->CreateBaseKey(); | ||
569 | |||
570 | hr = RegWriteQword(hkBase, L"QwordVersion", qwVersion); | ||
571 | NativeAssert::Succeeded(hr, "Failed to write qword version value."); | ||
572 | |||
573 | hr = RegReadVersion(hkBase, L"QwordVersion", &qwValue); | ||
574 | NativeAssert::Succeeded(hr, "Failed to read qword version value."); | ||
575 | Assert::Equal<DWORD64>(qwVersion, qwValue); | ||
576 | } | ||
577 | |||
578 | [Fact] | ||
579 | void RegUtilStringVersionValueTest() | ||
580 | { | ||
581 | this->StringVersionValueTest(); | ||
582 | } | ||
583 | |||
584 | [Fact] | ||
585 | void RegUtilStringVersionValueFallbackTest() | ||
586 | { | ||
587 | RegFunctionForceFallback(); | ||
588 | this->StringVersionValueTest(); | ||
589 | } | ||
590 | |||
591 | void StringVersionValueTest() | ||
592 | { | ||
593 | HRESULT hr = S_OK; | ||
594 | LPCWSTR wzVersion = L"65535.65535.65535.65535"; | ||
595 | DWORD64 qwValue = 0; | ||
596 | |||
597 | this->CreateBaseKey(); | ||
598 | |||
599 | hr = RegWriteString(hkBase, L"StringVersion", wzVersion); | ||
600 | NativeAssert::Succeeded(hr, "Failed to write string version value."); | ||
601 | |||
602 | hr = RegReadVersion(hkBase, L"StringVersion", &qwValue); | ||
603 | NativeAssert::Succeeded(hr, "Failed to read string version value."); | ||
604 | Assert::Equal<DWORD64>(MAXDWORD64, qwValue); | ||
605 | } | ||
606 | |||
607 | [Fact] | ||
608 | void RegUtilQwordWixVersionValueTest() | ||
609 | { | ||
610 | this->QwordWixVersionValueTest(); | ||
611 | } | ||
612 | |||
613 | [Fact] | ||
614 | void RegUtilQwordWixVersionValueFallbackTest() | ||
615 | { | ||
616 | RegFunctionForceFallback(); | ||
617 | this->QwordWixVersionValueTest(); | ||
618 | } | ||
619 | |||
620 | void QwordWixVersionValueTest() | ||
621 | { | ||
622 | HRESULT hr = S_OK; | ||
623 | DWORD64 qwVersion = FILEMAKEVERSION(1, 2, 3, 4); | ||
624 | VERUTIL_VERSION* pVersion = NULL; | ||
625 | |||
626 | try | ||
627 | { | ||
628 | this->CreateBaseKey(); | ||
629 | |||
630 | hr = RegWriteQword(hkBase, L"QwordWixVersion", qwVersion); | ||
631 | NativeAssert::Succeeded(hr, "Failed to write qword wix version value."); | ||
632 | |||
633 | hr = RegReadWixVersion(hkBase, L"QwordWixVersion", &pVersion); | ||
634 | NativeAssert::Succeeded(hr, "Failed to read qword wix version value."); | ||
635 | NativeAssert::StringEqual(L"1.2.3.4", pVersion->sczVersion); | ||
636 | } | ||
637 | finally | ||
638 | { | ||
639 | ReleaseVerutilVersion(pVersion); | ||
640 | } | ||
641 | } | ||
642 | |||
643 | [Fact] | ||
644 | void RegUtilStringWixVersionValueTest() | ||
645 | { | ||
646 | this->StringWixVersionValueTest(); | ||
647 | } | ||
648 | |||
649 | [Fact] | ||
650 | void RegUtilStringWixVersionValueFallbackTest() | ||
651 | { | ||
652 | RegFunctionForceFallback(); | ||
653 | this->StringWixVersionValueTest(); | ||
654 | } | ||
655 | |||
656 | void StringWixVersionValueTest() | ||
657 | { | ||
658 | HRESULT hr = S_OK; | ||
659 | LPCWSTR wzVersion = L"65535.65535.65535.65535-abc+def"; | ||
660 | VERUTIL_VERSION* pVersion = NULL; | ||
661 | |||
662 | try | ||
663 | { | ||
664 | this->CreateBaseKey(); | ||
665 | |||
666 | hr = RegWriteString(hkBase, L"StringWixVersion", wzVersion); | ||
667 | NativeAssert::Succeeded(hr, "Failed to write string wix version value."); | ||
668 | |||
669 | hr = RegReadWixVersion(hkBase, L"StringWixVersion", &pVersion); | ||
670 | NativeAssert::Succeeded(hr, "Failed to read string wix version value."); | ||
671 | NativeAssert::StringEqual(wzVersion, pVersion->sczVersion); | ||
672 | } | ||
673 | finally | ||
674 | { | ||
675 | ReleaseVerutilVersion(pVersion); | ||
676 | } | ||
677 | } | ||
678 | }; | ||
679 | } | ||