| 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 | namespace DutilTests |
| 6 | { |
| 7 | using namespace System; |
| 8 | using namespace Xunit; |
| 9 | using namespace WixInternal::TestSupport; |
| 10 | |
| 11 | public ref class AppUtil |
| 12 | { |
| 13 | public: |
| 14 | [Fact] |
| 15 | void WaitForMultipleObjectsTest() |
| 16 | { |
| 17 | HRESULT hr = S_OK; |
| 18 | HANDLE hOne = NULL; |
| 19 | HANDLE hTwo = NULL; |
| 20 | HANDLE rghHandles[2] = { }; |
| 21 | DWORD dwSignaledIndex = 0; |
| 22 | |
| 23 | try |
| 24 | { |
| 25 | hOne = ::CreateEventW(NULL, TRUE, FALSE, NULL); |
| 26 | if (!hOne) |
| 27 | { |
| 28 | hr = HRESULT_FROM_WIN32(::GetLastError()); |
| 29 | NativeAssert::Succeeded(FAILED(hr) ? hr : E_FAIL, "Failed to create event."); |
| 30 | } |
| 31 | |
| 32 | hTwo = ::CreateEventW(NULL, TRUE, TRUE, NULL); |
| 33 | if (!hTwo) |
| 34 | { |
| 35 | hr = HRESULT_FROM_WIN32(::GetLastError()); |
| 36 | NativeAssert::Succeeded(FAILED(hr) ? hr : E_FAIL, "Failed to create event."); |
| 37 | } |
| 38 | |
| 39 | rghHandles[0] = hOne; |
| 40 | rghHandles[1] = hTwo; |
| 41 | |
| 42 | hr = AppWaitForMultipleObjects(countof(rghHandles), rghHandles, FALSE, 0, &dwSignaledIndex); |
| 43 | NativeAssert::Succeeded(hr, "Failed to wait for multiple objects."); |
| 44 | Assert::Equal<DWORD>(1, dwSignaledIndex); |
| 45 | |
| 46 | rghHandles[0] = hTwo; |
| 47 | rghHandles[1] = hOne; |
| 48 | |
| 49 | hr = AppWaitForMultipleObjects(countof(rghHandles), rghHandles, FALSE, 0, &dwSignaledIndex); |
| 50 | NativeAssert::Succeeded(hr, "Failed to wait for multiple objects."); |
| 51 | Assert::Equal<DWORD>(0, dwSignaledIndex); |
| 52 | } |
| 53 | finally |
| 54 | { |
| 55 | ReleaseHandle(hOne); |
| 56 | ReleaseHandle(hTwo); |
| 57 | } |
| 58 | } |
| 59 | }; |
| 60 | } |