diff options
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h')
| -rw-r--r-- | src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h new file mode 100644 index 00000000..34af4f34 --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h | |||
| @@ -0,0 +1,85 @@ | |||
| 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 WixBuildTools { | ||
| 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 | IEqualityComparer<String^>^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; | ||
| 33 | Assert::NotEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); | ||
| 34 | } | ||
| 35 | |||
| 36 | // For some reason, naming these StringEqual methods "Equal" breaks Intellisense in files that call any overload of the Equal method. | ||
| 37 | static void StringEqual(LPCWSTR expected, LPCWSTR actual) | ||
| 38 | { | ||
| 39 | NativeAssert::StringEqual(expected, actual, FALSE); | ||
| 40 | } | ||
| 41 | |||
| 42 | static void StringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) | ||
| 43 | { | ||
| 44 | IEqualityComparer<String^>^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; | ||
| 45 | Assert::Equal(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); | ||
| 46 | } | ||
| 47 | |||
| 48 | static void Succeeded(HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs) | ||
| 49 | { | ||
| 50 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1); | ||
| 51 | formatArgs[0] = NativeAssert::LPSTRToString(zArg); | ||
| 52 | for (int i = 0; i < zArgs->Length; ++i) | ||
| 53 | { | ||
| 54 | formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); | ||
| 55 | } | ||
| 56 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void Succeeded(HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs) | ||
| 60 | { | ||
| 61 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length); | ||
| 62 | for (int i = 0; i < wzArgs->Length; ++i) | ||
| 63 | { | ||
| 64 | formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); | ||
| 65 | } | ||
| 66 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); | ||
| 67 | } | ||
| 68 | |||
| 69 | static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes) | ||
| 70 | { | ||
| 71 | Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes); | ||
| 72 | } | ||
| 73 | |||
| 74 | private: | ||
| 75 | static String^ LPSTRToString(LPCSTR z) | ||
| 76 | { | ||
| 77 | return z ? gcnew String(z) : nullptr; | ||
| 78 | } | ||
| 79 | static String^ LPWSTRToString(LPCWSTR wz) | ||
| 80 | { | ||
| 81 | return wz ? gcnew String(wz) : nullptr; | ||
| 82 | } | ||
| 83 | }; | ||
| 84 | } | ||
| 85 | } | ||
