aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-03 17:49:33 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-07 19:44:36 -0500
commit266b097c0b0a13dd4934f55f61cad62ffcbb953d (patch)
tree21400e8e1f7a6a5ebbc1abaacb40c472fc0b9fbc /src/libs/dutil/test/DUtilUnitTest
parent584213c5ffeca09b3fe24bd5e92f73fd057ac642 (diff)
downloadwix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.tar.gz
wix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.tar.bz2
wix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.zip
REG_EXPAND_SZ values are not necessarily a path.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj1
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters3
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp50
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp43
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/precomp.h1
5 files changed, 98 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
index 5b40eaf1..ee9f505e 100644
--- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
+++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
@@ -49,6 +49,7 @@
49 <ClCompile Include="DictUtilTest.cpp" /> 49 <ClCompile Include="DictUtilTest.cpp" />
50 <ClCompile Include="DirUtilTests.cpp" /> 50 <ClCompile Include="DirUtilTests.cpp" />
51 <ClCompile Include="DUtilTests.cpp" /> 51 <ClCompile Include="DUtilTests.cpp" />
52 <ClCompile Include="EnvUtilTests.cpp" />
52 <ClCompile Include="error.cpp" /> 53 <ClCompile Include="error.cpp" />
53 <ClCompile Include="FileUtilTest.cpp" /> 54 <ClCompile Include="FileUtilTest.cpp" />
54 <ClCompile Include="GuidUtilTest.cpp" /> 55 <ClCompile Include="GuidUtilTest.cpp" />
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
index fde49348..bcda6df0 100644
--- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
+++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
@@ -30,6 +30,9 @@
30 <ClCompile Include="DUtilTests.cpp"> 30 <ClCompile Include="DUtilTests.cpp">
31 <Filter>Source Files</Filter> 31 <Filter>Source Files</Filter>
32 </ClCompile> 32 </ClCompile>
33 <ClCompile Include="EnvUtilTests.cpp">
34 <Filter>Source Files</Filter>
35 </ClCompile>
33 <ClCompile Include="error.cpp"> 36 <ClCompile Include="error.cpp">
34 <Filter>Source Files</Filter> 37 <Filter>Source Files</Filter>
35 </ClCompile> 38 </ClCompile>
diff --git a/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp
new file mode 100644
index 00000000..76dfa774
--- /dev/null
+++ b/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp
@@ -0,0 +1,50 @@
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
5using namespace System;
6using namespace Xunit;
7using namespace WixBuildTools::TestSupport;
8
9namespace DutilTests
10{
11 public ref class EnvUtil
12 {
13 public:
14 [Fact]
15 void EnvExpandEnvironmentStringsTest()
16 {
17 HRESULT hr = S_OK;
18 LPWSTR sczExpanded = NULL;
19 SIZE_T cchExpanded = 0;
20 LPCWSTR wzSimpleString = L"%USERPROFILE%";
21 LPCWSTR wzMultipleString = L"%TEMP%;%PATH%";
22 LPCWSTR wzLongMultipleString = L"%TEMP%;%PATH%;C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789";
23 String^ expandedSimpleString = Environment::ExpandEnvironmentVariables(gcnew String(wzSimpleString));
24 String^ expandedMultipleString = Environment::ExpandEnvironmentVariables(gcnew String(wzMultipleString));
25 String^ expandedLongMultipleString = Environment::ExpandEnvironmentVariables(gcnew String(wzLongMultipleString));
26
27 try
28 {
29 hr = EnvExpandEnvironmentStrings(wzSimpleString, &sczExpanded, &cchExpanded);
30 NativeAssert::Succeeded(hr, "Failed to expand simple string.");
31 WixAssert::StringEqual(expandedSimpleString, gcnew String(sczExpanded), false);
32 NativeAssert::Equal<SIZE_T>(expandedSimpleString->Length + 1, cchExpanded);
33
34 hr = EnvExpandEnvironmentStrings(wzMultipleString, &sczExpanded, &cchExpanded);
35 NativeAssert::Succeeded(hr, "Failed to expand multiple string.");
36 WixAssert::StringEqual(expandedMultipleString, gcnew String(sczExpanded), false);
37 NativeAssert::Equal<SIZE_T>(expandedMultipleString->Length + 1, cchExpanded);
38
39 hr = EnvExpandEnvironmentStrings(wzLongMultipleString, &sczExpanded, &cchExpanded);
40 NativeAssert::Succeeded(hr, "Failed to expand long multiple string.");
41 WixAssert::StringEqual(expandedLongMultipleString, gcnew String(sczExpanded), false);
42 NativeAssert::Equal<SIZE_T>(expandedLongMultipleString->Length + 1, cchExpanded);
43 }
44 finally
45 {
46 ReleaseStr(sczExpanded);
47 }
48 }
49 };
50}
diff --git a/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp
index 575e3238..9e97f5e0 100644
--- a/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/RegUtilTest.cpp
@@ -208,6 +208,49 @@ namespace DutilTests
208 } 208 }
209 209
210 [Fact] 210 [Fact]
211 void RegUtilExpandLongStringValueTest()
212 {
213 this->ExpandLongStringValueTest();
214 }
215
216 [Fact]
217 void RegUtilExpandLongStringValueFallbackTest()
218 {
219 RegFunctionForceFallback();
220 this->ExpandLongStringValueTest();
221 }
222
223 void ExpandLongStringValueTest()
224 {
225 HRESULT hr = S_OK;
226 LPWSTR sczValue = NULL;
227 LPCWSTR wzValue = L"%TEMP%;%PATH%;C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789";
228 String^ expandedValue = Environment::ExpandEnvironmentVariables(gcnew String(wzValue));
229
230 try
231 {
232 this->CreateBaseKey();
233
234 hr = RegWriteExpandString(hkBase, L"ExpandString", wzValue);
235 NativeAssert::Succeeded(hr, "Failed to write expand string value.");
236
237 hr = RegReadString(hkBase, L"ExpandString", &sczValue);
238 NativeAssert::Succeeded(hr, "Failed to read expand string value.");
239 WixAssert::StringEqual(expandedValue, gcnew String(sczValue), false);
240
241 ReleaseNullStr(sczValue);
242
243 hr = RegReadString(hkBase, L"ExpandString", &sczValue);
244 NativeAssert::Succeeded(hr, "Failed to read expand string value.");
245 WixAssert::StringEqual(expandedValue, gcnew String(sczValue), false);
246 }
247 finally
248 {
249 ReleaseStr(sczValue);
250 }
251 }
252
253 [Fact]
211 void RegUtilNotExpandStringValueTest() 254 void RegUtilNotExpandStringValueTest()
212 { 255 {
213 this->NotExpandStringValueTest(); 256 this->NotExpandStringValueTest();
diff --git a/src/libs/dutil/test/DUtilUnitTest/precomp.h b/src/libs/dutil/test/DUtilUnitTest/precomp.h
index e9f8770b..bc628816 100644
--- a/src/libs/dutil/test/DUtilUnitTest/precomp.h
+++ b/src/libs/dutil/test/DUtilUnitTest/precomp.h
@@ -15,6 +15,7 @@
15#include <atomutil.h> 15#include <atomutil.h>
16#include <dictutil.h> 16#include <dictutil.h>
17#include <dirutil.h> 17#include <dirutil.h>
18#include <envutil.h>
18#include <fileutil.h> 19#include <fileutil.h>
19#include <guidutil.h> 20#include <guidutil.h>
20#include <iniutil.h> 21#include <iniutil.h>