diff options
| author | Rob Mensching <rob@firegiant.com> | 2024-01-10 23:53:18 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2024-01-11 18:24:06 -0800 |
| commit | 4e7b7c0059d76498d1c24f348dbf6d5799203fe0 (patch) | |
| tree | 1b00606cee7fd54ca4e07aa7b550fe63982220b3 /src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp | |
| parent | 57b7689b2dc5e971911d1c6d48eebb5424ebca89 (diff) | |
| download | wix-4e7b7c0059d76498d1c24f348dbf6d5799203fe0.tar.gz wix-4e7b7c0059d76498d1c24f348dbf6d5799203fe0.tar.bz2 wix-4e7b7c0059d76498d1c24f348dbf6d5799203fe0.zip | |
Add pipeutil to dutil
Plus a couple small clean-ups in a couple of dutil files.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp')
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp new file mode 100644 index 00000000..87a5e8f2 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/PipeUtilTest.cpp | |||
| @@ -0,0 +1,89 @@ | |||
| 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 WixInternal::TestSupport; | ||
| 9 | using namespace WixInternal::TestSupport::XunitExtensions; | ||
| 10 | |||
| 11 | static DWORD STDAPICALLTYPE _TestPipeClientThreadProc( | ||
| 12 | __in LPVOID lpThreadParameter | ||
| 13 | ); | ||
| 14 | |||
| 15 | namespace DutilTests | ||
| 16 | { | ||
| 17 | public ref class PipeUtil | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | [Fact] | ||
| 21 | void PipeConnectWriteAndRead() | ||
| 22 | { | ||
| 23 | HRESULT hr = S_OK; | ||
| 24 | HANDLE hServerPipe = INVALID_HANDLE_VALUE; | ||
| 25 | HANDLE hClientThread = NULL; | ||
| 26 | PIPE_MESSAGE msg = { }; | ||
| 27 | DWORD dwThread = 42; | ||
| 28 | DWORD dwTestMessageId = 987654; | ||
| 29 | |||
| 30 | try | ||
| 31 | { | ||
| 32 | hr = PipeCreate(L"DutilTest", NULL, &hServerPipe); | ||
| 33 | NativeAssert::Succeeded(hr, "Failed to create server pipe."); | ||
| 34 | |||
| 35 | hClientThread = ::CreateThread(NULL, 0, _TestPipeClientThreadProc, &dwTestMessageId, 0, NULL); | ||
| 36 | if (hClientThread == 0) | ||
| 37 | { | ||
| 38 | NativeAssert::Fail("Failed to create client thread."); | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | hr = PipeServerWaitForClientConnect(hServerPipe); | ||
| 43 | NativeAssert::Succeeded(hr, "Failed to wait for client to connect to pipe."); | ||
| 44 | |||
| 45 | hr = PipeReadMessage(hServerPipe, &msg); | ||
| 46 | NativeAssert::Succeeded(hr, "Failed to read message from client."); | ||
| 47 | |||
| 48 | NativeAssert::Equal(dwTestMessageId, msg.dwMessageType); | ||
| 49 | |||
| 50 | AppWaitForSingleObject(hClientThread, INFINITE); | ||
| 51 | |||
| 52 | ::GetExitCodeThread(hClientThread, &dwThread); | ||
| 53 | NativeAssert::Equal((DWORD)12, dwThread); | ||
| 54 | } | ||
| 55 | finally | ||
| 56 | { | ||
| 57 | ReleasePipeMessage(&msg); | ||
| 58 | ReleaseHandle(hClientThread); | ||
| 59 | ReleasePipeHandle(hServerPipe); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | }; | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | static DWORD STDAPICALLTYPE _TestPipeClientThreadProc( | ||
| 67 | __in LPVOID lpThreadParameter | ||
| 68 | ) | ||
| 69 | { | ||
| 70 | HRESULT hr = S_OK; | ||
| 71 | HANDLE hClientPipe = INVALID_HANDLE_VALUE; | ||
| 72 | |||
| 73 | hr = PipeClientConnect(L"DutilTest", &hClientPipe); | ||
| 74 | if (FAILED(hr)) | ||
| 75 | { | ||
| 76 | return hr; | ||
| 77 | } | ||
| 78 | |||
| 79 | ::Sleep(200); | ||
| 80 | |||
| 81 | hr = PipeWriteMessage(hClientPipe, *(LPDWORD)lpThreadParameter, NULL, 0); | ||
| 82 | if (FAILED(hr)) | ||
| 83 | { | ||
| 84 | return hr; | ||
| 85 | } | ||
| 86 | |||
| 87 | ReleasePipeHandle(hClientPipe); | ||
| 88 | return 12; | ||
| 89 | } | ||
