diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:50:22 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
commit | 8810aa8908ed7887616d86dd5fb821fcfa92f444 (patch) | |
tree | 8bc05667c36cc0d3db73504c867e85b01f1a79b0 /src/libs/dutil/test/DUtilUnitTest | |
parent | 266b097c0b0a13dd4934f55f61cad62ffcbb953d (diff) | |
download | wix-8810aa8908ed7887616d86dd5fb821fcfa92f444.tar.gz wix-8810aa8908ed7887616d86dd5fb821fcfa92f444.tar.bz2 wix-8810aa8908ed7887616d86dd5fb821fcfa92f444.zip |
Update Burn algorithm for picking elevated temp path to use SystemTemp.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
5 files changed, 94 insertions, 1 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj index ee9f505e..a1f13239 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj | |||
@@ -40,7 +40,7 @@ | |||
40 | 40 | ||
41 | <PropertyGroup> | 41 | <PropertyGroup> |
42 | <ProjectAdditionalIncludeDirectories>..\..\WixToolset.DUtil\inc</ProjectAdditionalIncludeDirectories> | 42 | <ProjectAdditionalIncludeDirectories>..\..\WixToolset.DUtil\inc</ProjectAdditionalIncludeDirectories> |
43 | <ProjectAdditionalLinkLibraries>rpcrt4.lib;Mpr.lib;Ws2_32.lib;shlwapi.lib;urlmon.lib;wininet.lib</ProjectAdditionalLinkLibraries> | 43 | <ProjectAdditionalLinkLibraries>rpcrt4.lib;Mpr.lib;Ws2_32.lib;shlwapi.lib;urlmon.lib;userenv.lib;wininet.lib</ProjectAdditionalLinkLibraries> |
44 | </PropertyGroup> | 44 | </PropertyGroup> |
45 | 45 | ||
46 | <ItemGroup> | 46 | <ItemGroup> |
@@ -57,6 +57,7 @@ | |||
57 | <ClCompile Include="MemUtilTest.cpp" /> | 57 | <ClCompile Include="MemUtilTest.cpp" /> |
58 | <ClCompile Include="MonUtilTest.cpp" /> | 58 | <ClCompile Include="MonUtilTest.cpp" /> |
59 | <ClCompile Include="PathUtilTest.cpp" /> | 59 | <ClCompile Include="PathUtilTest.cpp" /> |
60 | <ClCompile Include="ProcUtilTest.cpp" /> | ||
60 | <ClCompile Include="precomp.cpp"> | 61 | <ClCompile Include="precomp.cpp"> |
61 | <PrecompiledHeader>Create</PrecompiledHeader> | 62 | <PrecompiledHeader>Create</PrecompiledHeader> |
62 | <!-- Warnings from referencing netstandard dlls --> | 63 | <!-- Warnings from referencing netstandard dlls --> |
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters index bcda6df0..cb0c8a73 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="PathUtilTest.cpp"> | 54 | <ClCompile Include="PathUtilTest.cpp"> |
55 | <Filter>Source Files</Filter> | 55 | <Filter>Source Files</Filter> |
56 | </ClCompile> | 56 | </ClCompile> |
57 | <ClCompile Include="ProcUtilTest.cpp"> | ||
58 | <Filter>Source Files</Filter> | ||
59 | </ClCompile> | ||
57 | <ClCompile Include="precomp.cpp"> | 60 | <ClCompile Include="precomp.cpp"> |
58 | <Filter>Source Files</Filter> | 61 | <Filter>Source Files</Filter> |
59 | </ClCompile> | 62 | </ClCompile> |
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 | } |
diff --git a/src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp new file mode 100644 index 00000000..297d90f4 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp | |||
@@ -0,0 +1,42 @@ | |||
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::Security::Principal; | ||
7 | using namespace Xunit; | ||
8 | using namespace WixBuildTools::TestSupport; | ||
9 | |||
10 | namespace DutilTests | ||
11 | { | ||
12 | public ref class ProcUtil | ||
13 | { | ||
14 | public: | ||
15 | [Fact] | ||
16 | void ProcTokenUserTest() | ||
17 | { | ||
18 | HRESULT hr = S_OK; | ||
19 | TOKEN_USER* pTokenUser = NULL; | ||
20 | LPWSTR sczSid = NULL; | ||
21 | |||
22 | try | ||
23 | { | ||
24 | hr = ProcTokenUser(::GetCurrentProcess(), &pTokenUser); | ||
25 | NativeAssert::Succeeded(hr, "Failed to get TokenUser for current process."); | ||
26 | |||
27 | if (!::ConvertSidToStringSidW(pTokenUser->User.Sid, &sczSid)) | ||
28 | { | ||
29 | hr = HRESULT_FROM_WIN32(::GetLastError()); | ||
30 | NativeAssert::Succeeded(hr, "Failed to get string SID from TokenUser SID."); | ||
31 | } | ||
32 | |||
33 | Assert::Equal<String^>(WindowsIdentity::GetCurrent()->User->Value, gcnew String(sczSid)); | ||
34 | } | ||
35 | finally | ||
36 | { | ||
37 | ReleaseMem(pTokenUser); | ||
38 | ReleaseStr(sczSid); | ||
39 | } | ||
40 | } | ||
41 | }; | ||
42 | } | ||
diff --git a/src/libs/dutil/test/DUtilUnitTest/precomp.h b/src/libs/dutil/test/DUtilUnitTest/precomp.h index bc628816..ac57cdd4 100644 --- a/src/libs/dutil/test/DUtilUnitTest/precomp.h +++ b/src/libs/dutil/test/DUtilUnitTest/precomp.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <windows.h> | 5 | #include <windows.h> |
6 | #include <strsafe.h> | 6 | #include <strsafe.h> |
7 | #include <ShlObj.h> | 7 | #include <ShlObj.h> |
8 | #include <sddl.h> | ||
8 | 9 | ||
9 | // Include error.h before dutil.h | 10 | // Include error.h before dutil.h |
10 | #include <dutilsources.h> | 11 | #include <dutilsources.h> |
@@ -21,6 +22,7 @@ | |||
21 | #include <iniutil.h> | 22 | #include <iniutil.h> |
22 | #include <memutil.h> | 23 | #include <memutil.h> |
23 | #include <pathutil.h> | 24 | #include <pathutil.h> |
25 | #include <procutil.h> | ||
24 | #include <strutil.h> | 26 | #include <strutil.h> |
25 | #include <monutil.h> | 27 | #include <monutil.h> |
26 | #include <regutil.h> | 28 | #include <regutil.h> |