diff --git a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs index 5388391cd7..b365156e09 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using System; + [GroupOutput("Drawing/GradientBrushes")] public class FillRadialGradientBrushTests { @@ -16,23 +18,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing TestImageProvider provider) where TPixel : struct, IPixel { - using (var image = provider.GetImage()) - { - TPixel red = NamedColors.Red; - - RadialGradientBrush unicolorRadialGradientBrush = - new RadialGradientBrush( - new SixLabors.Primitives.Point(0, 0), - 100, - GradientRepetitionMode.None, - new ColorStop(0, red), - new ColorStop(1, red)); + provider.VerifyOperation( + image => + { + TPixel red = NamedColors.Red; - image.Mutate(x => x.Fill(unicolorRadialGradientBrush)); - image.DebugSave(provider); + var unicolorRadialGradientBrush = + new RadialGradientBrush( + new SixLabors.Primitives.Point(0, 0), + 100, + GradientRepetitionMode.None, + new ColorStop(0, red), + new ColorStop(1, red)); - image.CompareToReferenceOutput(provider); - } + image.Mutate(x => x.Fill(unicolorRadialGradientBrush)); + }, + false, + false); } [Theory] @@ -47,20 +49,21 @@ namespace SixLabors.ImageSharp.Tests.Drawing int centerY) where TPixel : struct, IPixel { - using (var image = provider.GetImage()) - { - RadialGradientBrush brush = - new RadialGradientBrush( - new SixLabors.Primitives.Point(centerX, centerY), - image.Width / 2f, - GradientRepetitionMode.None, - new ColorStop(0, NamedColors.Red), - new ColorStop(1, NamedColors.Yellow)); + provider.VerifyOperation( + image => + { + var brush = new RadialGradientBrush( + new SixLabors.Primitives.Point(centerX, centerY), + image.Width / 2f, + GradientRepetitionMode.None, + new ColorStop(0, NamedColors.Red), + new ColorStop(1, NamedColors.Yellow)); - image.Mutate(x => x.Fill(brush)); - image.DebugSave(provider, $"center{centerX:D3},{centerY:D3}"); - image.CompareToReferenceOutput(provider); - } + image.Mutate(x => x.Fill(brush)); + }, + $"center({centerX},{centerY})", + false, + false); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 34c93a7c19..c811b02418 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -173,7 +173,8 @@ namespace SixLabors.ImageSharp.Tests FormattableString testOutputDetails, string extension = "png", bool grayscale = false, - bool appendPixelTypeToFileName = true) + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) where TPixel : struct, IPixel { return image.CompareToReferenceOutput( @@ -181,7 +182,8 @@ namespace SixLabors.ImageSharp.Tests (object)testOutputDetails, extension, grayscale, - appendPixelTypeToFileName); + appendPixelTypeToFileName, + appendSourceFileOrDescription); } /// @@ -195,6 +197,7 @@ namespace SixLabors.ImageSharp.Tests /// The extension /// A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size. /// A boolean indicating whether to append the pixel type to the output file name. + /// A boolean indicating whether to append to the test output file name. /// public static Image CompareToReferenceOutput( this Image image, @@ -202,7 +205,8 @@ namespace SixLabors.ImageSharp.Tests object testOutputDetails = null, string extension = "png", bool grayscale = false, - bool appendPixelTypeToFileName = true) + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) where TPixel : struct, IPixel { return CompareToReferenceOutput( @@ -212,7 +216,8 @@ namespace SixLabors.ImageSharp.Tests testOutputDetails, extension, grayscale, - appendPixelTypeToFileName); + appendPixelTypeToFileName, + appendSourceFileOrDescription); } public static Image CompareToReferenceOutput( @@ -246,6 +251,7 @@ namespace SixLabors.ImageSharp.Tests /// The extension /// A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size. /// A boolean indicating whether to append the pixel type to the output file name. + /// A boolean indicating whether to append to the test output file name. /// public static Image CompareToReferenceOutput( this Image image, @@ -254,14 +260,16 @@ namespace SixLabors.ImageSharp.Tests object testOutputDetails = null, string extension = "png", bool grayscale = false, - bool appendPixelTypeToFileName = true) + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) where TPixel : struct, IPixel { using (Image referenceImage = GetReferenceOutputImage( provider, testOutputDetails, extension, - appendPixelTypeToFileName)) + appendPixelTypeToFileName, + appendSourceFileOrDescription)) { comparer.VerifySimilarity(referenceImage, image); } @@ -523,10 +531,57 @@ namespace SixLabors.ImageSharp.Tests } /// - /// Loads the expected image with a reference decoder + compares it to . - /// Also performs a debug save using . + /// Utility method for doing the following in one step: + /// 1. Executing an operation (taken as a delegate) + /// 2. Executing DebugSave() + /// 3. Executing CopareToReferenceOutput() + /// + internal static void VerifyOperation( + this TestImageProvider provider, + Action> operation, + FormattableString testOutputDetails, + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + operation(image); + + image.DebugSave( + provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); + + image.CompareToReferenceOutput(provider, + testOutputDetails, + appendPixelTypeToFileName: appendPixelTypeToFileName, + appendSourceFileOrDescription: appendSourceFileOrDescription); + } + } + + /// + /// Utility method for doing the following in one step: + /// 1. Executing an operation (taken as a delegate) + /// 2. Executing DebugSave() + /// 3. Executing CopareToReferenceOutput() /// - internal static void VerifyEncoder(this Image image, + internal static void VerifyOperation( + this TestImageProvider provider, + Action> operation, + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) + where TPixel : struct, IPixel + { + provider.VerifyOperation(operation, $"", appendPixelTypeToFileName, appendSourceFileOrDescription); + } + + /// + /// Loads the expected image with a reference decoder + compares it to . + /// Also performs a debug save using . + /// + internal static void VerifyEncoder(this Image image, ITestImageProvider provider, string extension, object testOutputDetails,