From 41dd980cea28405e1e21ab76a97699e37b4699a6 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 10 May 2018 01:44:23 +0200 Subject: [PATCH] use FormattableString for .DebugSave(...) and .CompareToReferenceOutput(...) whenever possible --- .../Transforms/AffineTransformTests.cs | 4 +- .../TestUtilities/ImagingTestCaseUtility.cs | 6 +- .../TestUtilities/TestImageExtensions.cs | 65 ++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs index 9380d4e185..3232c848e9 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs @@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); - string testOutputDetails = $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})"; + FormattableString testOutputDetails = $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})"; image.DebugSave(provider, testOutputDetails); image.CompareToReferenceOutput(ValidatorComparer, provider, testOutputDetails); } @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); - string testOutputDetails = $"R({angleDeg})_S({s})"; + FormattableString testOutputDetails = $"R({angleDeg})_S({s})"; image.DebugSave(provider, testOutputDetails); image.CompareToReferenceOutput(ValidatorComparer, provider, testOutputDetails); } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 02f8ddd7ea..2177551af3 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -111,7 +111,11 @@ namespace SixLabors.ImageSharp.Tests { string detailsString = null; - if (testOutputDetails is string s) + if (testOutputDetails is FormattableString fs) + { + detailsString = fs.AsInvariantString(); + } + else if (testOutputDetails is string s) { detailsString = s; } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 8955eeb63c..99c696f29a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -52,6 +52,23 @@ namespace SixLabors.ImageSharp.Tests }); } + public static Image DebugSave( + this Image image, + ITestImageProvider provider, + FormattableString testOutputDetails, + string extension = "png", + bool appendPixelTypeToFileName = true, + bool appendSourceFileOrDescription = true) + where TPixel : struct, IPixel + { + return image.DebugSave( + provider, + (object)testOutputDetails, + extension, + appendPixelTypeToFileName, + appendSourceFileOrDescription); + } + /// /// Saves the image only when not running in the CI server. /// @@ -86,6 +103,17 @@ namespace SixLabors.ImageSharp.Tests return image; } + public static Image DebugSave( + this Image image, + ITestImageProvider provider, + IImageEncoder encoder, + FormattableString testOutputDetails, + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + return image.DebugSave(provider, encoder, (object)testOutputDetails, appendPixelTypeToFileName); + } + /// /// Saves the image only when not running in the CI server. /// @@ -139,6 +167,23 @@ namespace SixLabors.ImageSharp.Tests return image; } + public static Image CompareToReferenceOutput( + this Image image, + ITestImageProvider provider, + FormattableString testOutputDetails, + string extension = "png", + bool grayscale = false, + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + return image.CompareToReferenceOutput( + provider, + (object)testOutputDetails, + extension, + grayscale, + appendPixelTypeToFileName); + } + /// /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough. /// The output file should be named identically to the output produced by . @@ -150,7 +195,6 @@ 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 custom for the verification /// public static Image CompareToReferenceOutput( this Image image, @@ -171,6 +215,25 @@ namespace SixLabors.ImageSharp.Tests appendPixelTypeToFileName); } + public static Image CompareToReferenceOutput( + this Image image, + ImageComparer comparer, + ITestImageProvider provider, + FormattableString testOutputDetails, + string extension = "png", + bool grayscale = false, + bool appendPixelTypeToFileName = true) + where TPixel : struct, IPixel + { + return image.CompareToReferenceOutput( + comparer, + provider, + (object)testOutputDetails, + extension, + grayscale, + appendPixelTypeToFileName); + } + /// /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough. /// The output file should be named identically to the output produced by .