mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.8 KiB
109 lines
3.8 KiB
// ReSharper disable InconsistentNaming
|
|
namespace ImageSharp.Tests
|
|
{
|
|
using System;
|
|
|
|
using ImageSharp.PixelFormats;
|
|
using ImageSharp.Tests.TestUtilities.ImageComparison;
|
|
|
|
using Moq;
|
|
|
|
using Xunit;
|
|
|
|
public class TestImageExtensionsTests
|
|
{
|
|
[Theory]
|
|
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
|
|
public void CompareToReferenceOutput_WhenReferenceOutputMatches_ShouldNotThrow<TPixel>(
|
|
TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
image.CompareToReferenceOutput(provider);
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
|
|
public void CompareToReferenceOutput_WhenReferenceOutputDoesNotMatch_Throws<TPixel>(
|
|
TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
Assert.ThrowsAny<Exception>(() => image.CompareToReferenceOutput(provider));
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
|
|
public void CompareToReferenceOutput_DoNotAppendPixelType<TPixel>(
|
|
TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
image.DebugSave(provider, appendPixelTypeToFileName: false);
|
|
image.CompareToReferenceOutput(provider, appendPixelTypeToFileName: false);
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
|
|
public void CompareToReferenceOutput_WhenReferenceFileMissing_Throws<TPixel>(TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
Assert.ThrowsAny<Exception>(() => image.CompareToReferenceOutput(provider));
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)]
|
|
public void CompareToOriginal_WhenSimilar<TPixel>(TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
using (Image<TPixel> clone = image.Clone())
|
|
{
|
|
clone.CompareToOriginal(provider, ImageComparer.Exact);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)]
|
|
public void CompareToOriginal_WhenDifferent_Throws<TPixel>(TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
ImagingTestCaseUtility.ModifyPixel(image, 3, 1, 1);
|
|
|
|
Assert.ThrowsAny<ImagePixelsAreDifferentException>(
|
|
() =>
|
|
{
|
|
image.CompareToOriginal(provider, ImageComparer.Exact);
|
|
});
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[WithBlankImages(10, 10, PixelTypes.Rgba32)]
|
|
public void CompareToOriginal_WhenInputIsNotFromFile_Throws<TPixel>(TestImageProvider<TPixel> provider)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (Image<TPixel> image = provider.GetImage())
|
|
{
|
|
Assert.ThrowsAny<Exception>(
|
|
() =>
|
|
{
|
|
image.CompareToOriginal(provider, Mock.Of<ImageComparer>());
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|