#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) { WixAssert::NotStringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase); } // 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) { WixAssert::StringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase); } 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 SpecificReturnCode(HRESULT hrExpected, 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::SpecificReturnCode(hrExpected, hr, gcnew String(zFormat), formatArgs); } static void SpecificReturnCode(HRESULT hrExpected, 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::SpecificReturnCode(hrExpected, 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; } }; } }