diff options
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp')
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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 | } | ||
