From 6a24996a2e831cfe402398af65b31fb1ecd575a9 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 22 Apr 2021 16:36:39 -0700 Subject: Move WixBuildTools into internal --- .../NativeAssert.h | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h (limited to 'src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h') 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 @@ +#pragma once +// 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. + + +namespace WixBuildTools { +namespace TestSupport { + + using namespace System; + using namespace System::Collections::Generic; + using namespace System::Linq; + using namespace Xunit; + + public ref class NativeAssert : WixAssert + { + public: + static void NotNull(LPCWSTR wz) + { + if (!wz) + { + Assert::NotNull(nullptr); + } + } + + // For some reason, naming these NotStringEqual methods "NotEqual" breaks Intellisense in files that call any overload of the NotEqual method. + static void NotStringEqual(LPCWSTR expected, LPCWSTR actual) + { + NativeAssert::NotStringEqual(expected, actual, FALSE); + } + + static void NotStringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) + { + IEqualityComparer^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; + Assert::NotEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); + } + + // For some reason, naming these StringEqual methods "Equal" breaks Intellisense in files that call any overload of the Equal method. + static void StringEqual(LPCWSTR expected, LPCWSTR actual) + { + NativeAssert::StringEqual(expected, actual, FALSE); + } + + static void StringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) + { + IEqualityComparer^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; + Assert::Equal(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); + } + + static void Succeeded(HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array^ zArgs) + { + array^ formatArgs = gcnew array(zArgs->Length + 1); + formatArgs[0] = NativeAssert::LPSTRToString(zArg); + for (int i = 0; i < zArgs->Length; ++i) + { + formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); + } + WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); + } + + static void Succeeded(HRESULT hr, LPCSTR zFormat, ... array^ wzArgs) + { + array^ formatArgs = gcnew array(wzArgs->Length); + for (int i = 0; i < wzArgs->Length; ++i) + { + formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); + } + WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); + } + + static void ValidReturnCode(HRESULT hr, ... array^ validReturnCodes) + { + Assert::Contains(hr, (IEnumerable^)validReturnCodes); + } + + private: + static String^ LPSTRToString(LPCSTR z) + { + return z ? gcnew String(z) : nullptr; + } + static String^ LPWSTRToString(LPCWSTR wz) + { + return wz ? gcnew String(wz) : nullptr; + } + }; +} +} -- cgit v1.2.3-55-g6feb