diff options
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp')
-rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp index 76dfa774..94b9ab8e 100644 --- a/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp | |||
@@ -3,8 +3,10 @@ | |||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | using namespace System; | 5 | using namespace System; |
6 | using namespace System::Collections; | ||
6 | using namespace Xunit; | 7 | using namespace Xunit; |
7 | using namespace WixBuildTools::TestSupport; | 8 | using namespace WixBuildTools::TestSupport; |
9 | using namespace WixBuildTools::TestSupport::XunitExtensions; | ||
8 | 10 | ||
9 | namespace DutilTests | 11 | namespace DutilTests |
10 | { | 12 | { |
@@ -46,5 +48,48 @@ namespace DutilTests | |||
46 | ReleaseStr(sczExpanded); | 48 | ReleaseStr(sczExpanded); |
47 | } | 49 | } |
48 | } | 50 | } |
51 | |||
52 | [SkippableFact] | ||
53 | void EnvExpandEnvironmentStringsForUserTest() | ||
54 | { | ||
55 | HRESULT hr = S_OK; | ||
56 | LPWSTR sczExpanded = NULL; | ||
57 | SIZE_T cchExpanded = 0; | ||
58 | String^ variableName = nullptr; | ||
59 | String^ variableValue = nullptr; | ||
60 | |||
61 | // Find a system environment variable that doesn't have variables in its value; | ||
62 | for each (DictionaryEntry^ entry in Environment::GetEnvironmentVariables(EnvironmentVariableTarget::Machine)) | ||
63 | { | ||
64 | variableValue = (String^)entry->Value; | ||
65 | if (variableValue->Contains("%")) | ||
66 | { | ||
67 | continue; | ||
68 | } | ||
69 | |||
70 | variableName = (String^)entry->Key; | ||
71 | break; | ||
72 | } | ||
73 | |||
74 | if (nullptr == variableName) | ||
75 | { | ||
76 | WixAssert::Skip("No suitable system environment variables"); | ||
77 | } | ||
78 | |||
79 | pin_ptr<const wchar_t> wzUnexpanded = PtrToStringChars("%" + variableName + "%_%USERNAME%"); | ||
80 | String^ expandedValue = variableValue + "_SYSTEM"; | ||
81 | |||
82 | try | ||
83 | { | ||
84 | hr = EnvExpandEnvironmentStringsForUser(NULL, wzUnexpanded, &sczExpanded, &cchExpanded); | ||
85 | NativeAssert::Succeeded(hr, "Failed to expand %ls.", wzUnexpanded); | ||
86 | WixAssert::StringEqual(expandedValue, gcnew String(sczExpanded), false); | ||
87 | NativeAssert::Equal<SIZE_T>(expandedValue->Length + 1, cchExpanded); | ||
88 | } | ||
89 | finally | ||
90 | { | ||
91 | ReleaseStr(sczExpanded); | ||
92 | } | ||
93 | } | ||
49 | }; | 94 | }; |
50 | } | 95 | } |