Browse Source

using ImageSharp PNG codecs as reference codecs on linux

af/merge-core
Anton Firszov 9 years ago
parent
commit
ed4cc4b478
  1. 15
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  2. 18
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  3. 34
      tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs

15
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -57,10 +57,17 @@ namespace SixLabors.ImageSharp.Tests
new BmpConfigurationModule() new BmpConfigurationModule()
); );
configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance); if (!IsLinux)
configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png); {
configuration.AddImageFormatDetector(new PngImageFormatDetector()); configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance);
configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png);
configuration.AddImageFormatDetector(new PngImageFormatDetector());
}
else
{
new PngConfigurationModule().Configure(configuration);
}
return configuration; return configuration;
} }

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

@ -90,7 +90,6 @@ namespace SixLabors.ImageSharp.Tests
/// <param name="extension">The extension</param> /// <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="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="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
/// <param name="decoder">Custom decoder</param>
/// <returns></returns> /// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>( public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image, this Image<TPixel> image,
@ -99,16 +98,14 @@ namespace SixLabors.ImageSharp.Tests
object testOutputDetails = null, object testOutputDetails = null,
string extension = "png", string extension = "png",
bool grayscale = false, bool grayscale = false,
bool appendPixelTypeToFileName = true, bool appendPixelTypeToFileName = true)
IImageDecoder decoder = null)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> referenceImage = GetReferenceOutputImage<TPixel>( using (Image<TPixel> referenceImage = GetReferenceOutputImage<TPixel>(
provider, provider,
testOutputDetails, testOutputDetails,
extension, extension,
appendPixelTypeToFileName, appendPixelTypeToFileName))
decoder))
{ {
comparer.VerifySimilarity(referenceImage, image); comparer.VerifySimilarity(referenceImage, image);
} }
@ -119,8 +116,7 @@ namespace SixLabors.ImageSharp.Tests
public static Image<TPixel> GetReferenceOutputImage<TPixel>(this ITestImageProvider provider, public static Image<TPixel> GetReferenceOutputImage<TPixel>(this ITestImageProvider provider,
object testOutputDetails = null, object testOutputDetails = null,
string extension = "png", string extension = "png",
bool appendPixelTypeToFileName = true, bool appendPixelTypeToFileName = true)
IImageDecoder decoder = null)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName); string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
@ -130,7 +126,7 @@ namespace SixLabors.ImageSharp.Tests
throw new Exception("Reference output file missing: " + referenceOutputFile); throw new Exception("Reference output file missing: " + referenceOutputFile);
} }
decoder = decoder ?? TestEnvironment.GetReferenceDecoder(referenceOutputFile); IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(referenceOutputFile);
return Image.Load<TPixel>(referenceOutputFile, decoder); return Image.Load<TPixel>(referenceOutputFile, decoder);
} }
@ -141,15 +137,13 @@ namespace SixLabors.ImageSharp.Tests
ImageComparer comparer, ImageComparer comparer,
object testOutputDetails = null, object testOutputDetails = null,
string extension = "png", string extension = "png",
bool appendPixelTypeToFileName = true, bool appendPixelTypeToFileName = true)
IImageDecoder decoder = null)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> referenceImage = provider.GetReferenceOutputImage<TPixel>( using (Image<TPixel> referenceImage = provider.GetReferenceOutputImage<TPixel>(
testOutputDetails, testOutputDetails,
extension, extension,
appendPixelTypeToFileName, appendPixelTypeToFileName))
decoder))
{ {
return comparer.CompareImages(referenceImage, image); return comparer.CompareImages(referenceImage, image);
} }

34
tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs

@ -14,6 +14,8 @@ using Xunit.Abstractions;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Formats.Png;
public class TestEnvironmentTests public class TestEnvironmentTests
{ {
public TestEnvironmentTests(ITestOutputHelper output) public TestEnvironmentTests(ITestOutputHelper output)
@ -67,8 +69,10 @@ namespace SixLabors.ImageSharp.Tests
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))] [InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))]
[InlineData("lol/Baz.JPG", typeof(JpegEncoder))] [InlineData("lol/Baz.JPG", typeof(JpegEncoder))]
[InlineData("lol/Baz.gif", typeof(GifEncoder))] [InlineData("lol/Baz.gif", typeof(GifEncoder))]
public void GetReferenceEncoder_ReturnsCorrectEncoders(string fileName, Type expectedEncoderType) public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedEncoderType)
{ {
if (TestEnvironment.IsLinux) return;
IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName); IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName);
Assert.IsType(expectedEncoderType, encoder); Assert.IsType(expectedEncoderType, encoder);
} }
@ -77,8 +81,34 @@ namespace SixLabors.ImageSharp.Tests
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))]
[InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))]
[InlineData("lol/Baz.gif", typeof(GifDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))]
public void GetReferenceDecoder_ReturnsCorrectEncoders(string fileName, Type expectedDecoderType) public void GetReferenceDecoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedDecoderType)
{
if (TestEnvironment.IsLinux) return;
IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName);
Assert.IsType(expectedDecoderType, decoder);
}
[Theory]
[InlineData("lol/foo.png", typeof(PngEncoder))]
[InlineData("lol/Baz.JPG", typeof(JpegEncoder))]
[InlineData("lol/Baz.gif", typeof(GifEncoder))]
public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedEncoderType)
{ {
if (!TestEnvironment.IsLinux) return;
IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName);
Assert.IsType(expectedEncoderType, encoder);
}
[Theory]
[InlineData("lol/foo.png", typeof(PngDecoder))]
[InlineData("lol/Baz.JPG", typeof(JpegDecoder))]
[InlineData("lol/Baz.gif", typeof(GifDecoder))]
public void GetReferenceDecoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedDecoderType)
{
if (!TestEnvironment.IsLinux) return;
IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName); IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName);
Assert.IsType(expectedDecoderType, decoder); Assert.IsType(expectedDecoderType, decoder);
} }

Loading…
Cancel
Save