diff options
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp')
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/EnvUtilTests.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
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 | |||
| 5 | using namespace System; | ||
| 6 | using namespace Xunit; | ||
| 7 | using namespace WixBuildTools::TestSupport; | ||
| 8 | |||
| 9 | namespace 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 | } | ||
