Browse Source

use FormattableString for .DebugSave(...) and .CompareToReferenceOutput(...) whenever possible

pull/568/head
Anton Firszov 8 years ago
parent
commit
41dd980cea
  1. 4
      tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs
  2. 6
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  3. 65
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

4
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);
}

6
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;
}

65
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -52,6 +52,23 @@ namespace SixLabors.ImageSharp.Tests
});
}
public static Image<TPixel> DebugSave<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
FormattableString testOutputDetails,
string extension = "png",
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
return image.DebugSave(
provider,
(object)testOutputDetails,
extension,
appendPixelTypeToFileName,
appendSourceFileOrDescription);
}
/// <summary>
/// Saves the image only when not running in the CI server.
/// </summary>
@ -86,6 +103,17 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
public static Image<TPixel> DebugSave<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
IImageEncoder encoder,
FormattableString testOutputDetails,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
return image.DebugSave(provider, encoder, (object)testOutputDetails, appendPixelTypeToFileName);
}
/// <summary>
/// Saves the image only when not running in the CI server.
/// </summary>
@ -139,6 +167,23 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
FormattableString testOutputDetails,
string extension = "png",
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
return image.CompareToReferenceOutput(
provider,
(object)testOutputDetails,
extension,
grayscale,
appendPixelTypeToFileName);
}
/// <summary>
/// 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 <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
@ -150,7 +195,6 @@ namespace SixLabors.ImageSharp.Tests
/// <param name="extension">The extension</param>
/// <param name="grayscale">A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size.</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
/// <param name="comparer">A custom <see cref="ImageComparer"/> for the verification</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
@ -171,6 +215,25 @@ namespace SixLabors.ImageSharp.Tests
appendPixelTypeToFileName);
}
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
ImageComparer comparer,
ITestImageProvider provider,
FormattableString testOutputDetails,
string extension = "png",
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
return image.CompareToReferenceOutput(
comparer,
provider,
(object)testOutputDetails,
extension,
grayscale,
appendPixelTypeToFileName);
}
/// <summary>
/// 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 <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.

Loading…
Cancel
Save