From fb4f8c7108f43d2341ba299424646c4963b21188 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Thu, 26 May 2022 17:33:15 -0500 Subject: Replace PathIsAbsolute with PathIsRooted and add PathIsFullyQualified. --- .../WixBuildTools.TestSupport.Native/NativeAssert.h | 21 +++++++++++++++++++++ .../XunitExtensions/SpecificReturnCodeException.cs | 19 +++++++++++++++++++ .../XunitExtensions/WixAssert.cs | 8 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs (limited to 'src/internal') diff --git a/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h index 62ace4a9..b0206b14 100644 --- a/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h +++ b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h @@ -64,6 +64,27 @@ namespace TestSupport { 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); diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs new file mode 100644 index 00000000..c66890f8 --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs @@ -0,0 +1,19 @@ +// 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.TestSupport +{ + using System; + using Xunit.Sdk; + + public class SpecificReturnCodeException : XunitException + { + public SpecificReturnCodeException(int hr, string userMessage) + : base(String.Format("WixAssert.SpecificReturnCode() Failure\r\n" + + "HRESULT: 0x{0:X8}\r\n" + + "Message: {1}", + hr, userMessage)) + { + this.HResult = hr; + } + } +} diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs index 10156547..1ede55b3 100644 --- a/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs +++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs @@ -52,6 +52,14 @@ namespace WixBuildTools.TestSupport throw new SkipTestException(message); } + public static void SpecificReturnCode(int hrExpected, int hr, string format, params object[] formatArgs) + { + if (hrExpected != hr) + { + throw new SpecificReturnCodeException(hr, String.Format(format, formatArgs)); + } + } + public static void Succeeded(int hr, string format, params object[] formatArgs) { if (0 > hr) -- cgit v1.2.3-55-g6feb