| 1 | #pragma once |
| 2 | // 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. |
| 3 | |
| 4 | |
| 5 | namespace WixInternal { |
| 6 | namespace TestSupport { |
| 7 | |
| 8 | using namespace System; |
| 9 | using namespace System::Collections::Generic; |
| 10 | using namespace System::Linq; |
| 11 | using namespace Xunit; |
| 12 | |
| 13 | public ref class NativeAssert : WixAssert |
| 14 | { |
| 15 | public: |
| 16 | static void NotNull(LPCWSTR wz) |
| 17 | { |
| 18 | if (!wz) |
| 19 | { |
| 20 | Assert::NotNull(nullptr); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | // For some reason, naming these NotStringEqual methods "NotEqual" breaks Intellisense in files that call any overload of the NotEqual method. |
| 25 | static void NotStringEqual(LPCWSTR expected, LPCWSTR actual) |
| 26 | { |
| 27 | NativeAssert::NotStringEqual(expected, actual, FALSE); |
| 28 | } |
| 29 | |
| 30 | static void NotStringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) |
| 31 | { |
| 32 | WixAssert::NotStringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase); |
| 33 | } |
| 34 | |
| 35 | // For some reason, naming these StringEqual methods "Equal" breaks Intellisense in files that call any overload of the Equal method. |
| 36 | static void StringEqual(LPCWSTR expected, LPCWSTR actual) |
| 37 | { |
| 38 | NativeAssert::StringEqual(expected, actual, FALSE); |
| 39 | } |
| 40 | |
| 41 | static void StringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) |
| 42 | { |
| 43 | WixAssert::StringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase); |
| 44 | } |
| 45 | |
| 46 | static void Succeeded(HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs) |
| 47 | { |
| 48 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1); |
| 49 | formatArgs[0] = NativeAssert::LPSTRToString(zArg); |
| 50 | for (int i = 0; i < zArgs->Length; ++i) |
| 51 | { |
| 52 | formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); |
| 53 | } |
| 54 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); |
| 55 | } |
| 56 | |
| 57 | static void Succeeded(HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs) |
| 58 | { |
| 59 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length); |
| 60 | for (int i = 0; i < wzArgs->Length; ++i) |
| 61 | { |
| 62 | formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); |
| 63 | } |
| 64 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); |
| 65 | } |
| 66 | |
| 67 | static void SpecificReturnCode(HRESULT hrExpected, HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs) |
| 68 | { |
| 69 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1); |
| 70 | formatArgs[0] = NativeAssert::LPSTRToString(zArg); |
| 71 | for (int i = 0; i < zArgs->Length; ++i) |
| 72 | { |
| 73 | formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); |
| 74 | } |
| 75 | WixAssert::SpecificReturnCode(hrExpected, hr, gcnew String(zFormat), formatArgs); |
| 76 | } |
| 77 | |
| 78 | static void SpecificReturnCode(HRESULT hrExpected, HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs) |
| 79 | { |
| 80 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length); |
| 81 | for (int i = 0; i < wzArgs->Length; ++i) |
| 82 | { |
| 83 | formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); |
| 84 | } |
| 85 | WixAssert::SpecificReturnCode(hrExpected, hr, gcnew String(zFormat), formatArgs); |
| 86 | } |
| 87 | |
| 88 | static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes) |
| 89 | { |
| 90 | Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes); |
| 91 | } |
| 92 | |
| 93 | private: |
| 94 | static String^ LPSTRToString(LPCSTR z) |
| 95 | { |
| 96 | return z ? gcnew String(z) : nullptr; |
| 97 | } |
| 98 | static String^ LPWSTRToString(LPCWSTR wz) |
| 99 | { |
| 100 | return wz ? gcnew String(wz) : nullptr; |
| 101 | } |
| 102 | }; |
| 103 | } |
| 104 | } |