Browse Source

validating tests for Overlay processors

af/merge-core
Anton Firszov 7 years ago
parent
commit
e9ce809e8d
  1. 57
      tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs
  2. 70
      tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs
  3. 61
      tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs
  4. 2
      tests/Images/External

57
tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs

@ -10,59 +10,14 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
{
public class GlowTest : FileTestBase
[GroupOutput("Overlays")]
public class GlowTest : OverlayTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow());
image.DebugSave(provider);
}
}
protected override void Apply<T>(IImageProcessingContext<T> ctx, T color) => ctx.Glow(color);
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow(NamedColors<TPixel>.Orange));
image.DebugSave(provider);
}
}
protected override void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY) =>
ctx.Glow(radiusX);
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow(image.Width / 4F));
image.DebugSave(provider);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = source.Clone())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Glow(bounds));
image.DebugSave(provider);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
}
protected override void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect) => ctx.Glow(rect);
}
}

70
tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs

@ -0,0 +1,70 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Reflection;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
{
[GroupOutput("Overlays")]
public abstract class OverlayTestBase
{
public static string[] ColorNames = { "Blue", "White" };
public static string[] InputImages = { TestImages.Png.Ducky, TestImages.Png.Splash };
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f);
[Theory]
[WithFileCollection(nameof(InputImages), nameof(ColorNames), PixelTypes.Rgba32)]
public void FullImage_ApplyColor<TPixel>(TestImageProvider<TPixel> provider, string colorName)
where TPixel : struct, IPixel<TPixel>
{
provider.Utility.TestGroupName = this.GetType().Name;
var f = (FieldInfo)typeof(NamedColors<TPixel>).GetMember(colorName)[0];
TPixel color = (TPixel)f.GetValue(null);
provider.RunValidatingProcessorTest(x => this.Apply(x, color), colorName, ValidatorComparer, appendPixelTypeToFileName: false);
}
[Theory]
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
public void FullImage_ApplyRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.Utility.TestGroupName = this.GetType().Name;
provider.RunValidatingProcessorTest(
x =>
{
Size size = x.GetCurrentSize();
this.Apply(x, size.Width / 4f, size.Height / 4f);
},
comparer: ValidatorComparer,
appendPixelTypeToFileName: false);
}
[Theory]
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
public void InBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.Utility.TestGroupName = this.GetType().Name;
provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => this.Apply(x, rect));
}
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, T color)
where T : struct, IPixel<T>;
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY)
where T : struct, IPixel<T>;
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect)
where T : struct, IPixel<T>;
}
}

61
tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs

@ -1,68 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
{
public class VignetteTest : FileTestBase
[GroupOutput("Overlays")]
public class VignetteTest : OverlayTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette());
image.DebugSave(provider);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette(NamedColors<TPixel>.Orange));
image.DebugSave(provider);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F));
image.DebugSave(provider);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = source.Clone())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
protected override void Apply<T>(IImageProcessingContext<T> ctx, T color) => ctx.Vignette(color);
image.Mutate(x => x.Vignette(bounds));
image.DebugSave(provider);
protected override void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY) =>
ctx.Vignette(radiusX, radiusY);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
}
protected override void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect) => ctx.Vignette(rect);
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit 56ee5df145d9696e401e2bc53e615c553cfb32d5
Subproject commit 854ba68b05162bdd87c0c9bbdcdb1c848aa6ddbe
Loading…
Cancel
Save