Browse Source

introduce TestImageExtensions.VerifyOperation(), simplify FillRadialGradientBrushTests and output file names

af/merge-core
Anton Firszov 8 years ago
parent
commit
fe9fcfe6be
  1. 59
      tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs
  2. 73
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

59
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<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (var image = provider.GetImage())
{
TPixel red = NamedColors<TPixel>.Red;
RadialGradientBrush<TPixel> unicolorRadialGradientBrush =
new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
100,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red));
provider.VerifyOperation(
image =>
{
TPixel red = NamedColors<TPixel>.Red;
image.Mutate(x => x.Fill(unicolorRadialGradientBrush));
image.DebugSave(provider);
var unicolorRadialGradientBrush =
new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
100,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(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<TPixel>
{
using (var image = provider.GetImage())
{
RadialGradientBrush<TPixel> brush =
new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(centerX, centerY),
image.Width / 2f,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, NamedColors<TPixel>.Red),
new ColorStop<TPixel>(1, NamedColors<TPixel>.Yellow));
provider.VerifyOperation(
image =>
{
var brush = new RadialGradientBrush<TPixel>(
new SixLabors.Primitives.Point(centerX, centerY),
image.Width / 2f,
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, NamedColors<TPixel>.Red),
new ColorStop<TPixel>(1, NamedColors<TPixel>.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);
}
}
}

73
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<TPixel>
{
return image.CompareToReferenceOutput(
@ -181,7 +182,8 @@ namespace SixLabors.ImageSharp.Tests
(object)testOutputDetails,
extension,
grayscale,
appendPixelTypeToFileName);
appendPixelTypeToFileName,
appendSourceFileOrDescription);
}
/// <summary>
@ -195,6 +197,7 @@ 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="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> 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<TPixel>
{
return CompareToReferenceOutput(
@ -212,7 +216,8 @@ namespace SixLabors.ImageSharp.Tests
testOutputDetails,
extension,
grayscale,
appendPixelTypeToFileName);
appendPixelTypeToFileName,
appendSourceFileOrDescription);
}
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
@ -246,6 +251,7 @@ 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="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> 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<TPixel>
{
using (Image<TPixel> referenceImage = GetReferenceOutputImage<TPixel>(
provider,
testOutputDetails,
extension,
appendPixelTypeToFileName))
appendPixelTypeToFileName,
appendSourceFileOrDescription))
{
comparer.VerifySimilarity(referenceImage, image);
}
@ -523,10 +531,57 @@ namespace SixLabors.ImageSharp.Tests
}
/// <summary>
/// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>.
/// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>.
/// Utility method for doing the following in one step:
/// 1. Executing an operation (taken as a delegate)
/// 2. Executing DebugSave()
/// 3. Executing CopareToReferenceOutput()
/// </summary>
internal static void VerifyOperation<TPixel>(
this TestImageProvider<TPixel> provider,
Action<Image<TPixel>> operation,
FormattableString testOutputDetails,
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
operation(image);
image.DebugSave(
provider,
testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription);
image.CompareToReferenceOutput(provider,
testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription);
}
}
/// <summary>
/// Utility method for doing the following in one step:
/// 1. Executing an operation (taken as a delegate)
/// 2. Executing DebugSave()
/// 3. Executing CopareToReferenceOutput()
/// </summary>
internal static void VerifyEncoder<TPixel>(this Image<TPixel> image,
internal static void VerifyOperation<TPixel>(
this TestImageProvider<TPixel> provider,
Action<Image<TPixel>> operation,
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
provider.VerifyOperation(operation, $"", appendPixelTypeToFileName, appendSourceFileOrDescription);
}
/// <summary>
/// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>.
/// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>.
/// </summary>
internal static void VerifyEncoder<TPixel>(this Image<TPixel> image,
ITestImageProvider provider,
string extension,
object testOutputDetails,

Loading…
Cancel
Save