Browse Source

proper BmpDecoderTests (at least on Windows)

af/merge-core
Anton Firszov 9 years ago
parent
commit
d9d0cb4555
  1. 34
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  2. 32
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  3. 5
      tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs
  4. 0
      tests/Images/Input/Bmp/BitmapCoreHeaderQR.bmp

34
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -1,26 +1,38 @@
// <copyright file="BmpEncoderTests.cs" company="James Jackson-South"> // Copyright (c) Six Labors and contributors.
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright>
using ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using ImageSharp.PixelFormats; using SixLabors.ImageSharp.Formats.Bmp;
using Xunit;
public class BmpDecoderTests : FileTestBase public class BmpDecoderTests : FileTestBase
{ {
[Theory] [Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgb24)] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgb24)]
public void OpenAllBmpFiles_SaveBmp<TPixel>(TestImageProvider<TPixel> provider) public void DecodeBmp<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
{
image.DebugSave(provider, "bmp");
image.CompareToOriginal(provider);
}
}
[Theory]
[WithFile(TestImages.Bmp.F, CommonNonDefaultPixelTypes)]
public void BmpDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
{ {
provider.Utility.SaveTestOutputFile(image, "bmp"); image.DebugSave(provider, "bmp");
image.CompareToOriginal(provider);
} }
} }
} }

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

@ -48,24 +48,44 @@ namespace SixLabors.ImageSharp.Tests
internal static Configuration Configuration => configuration.Value; internal static Configuration Configuration => configuration.Value;
private static void ConfigureCodecs(
this Configuration cfg,
IImageFormat imageFormat,
IImageDecoder decoder,
IImageEncoder encoder,
IImageFormatDetector detector)
{
cfg.SetDecoder(imageFormat, decoder);
cfg.SetEncoder(imageFormat, encoder);
cfg.AddImageFormatDetector(detector);
}
private static Configuration CreateDefaultConfiguration() private static Configuration CreateDefaultConfiguration()
{ {
var configuration = new Configuration( var configuration = new Configuration(
new PngConfigurationModule(), new PngConfigurationModule(),
new JpegConfigurationModule(), new JpegConfigurationModule(),
new GifConfigurationModule(), new GifConfigurationModule()
new BmpConfigurationModule()
); );
if (!IsLinux) if (!IsLinux)
{ {
configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance); configuration.ConfigureCodecs(
configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png); ImageFormats.Png,
configuration.AddImageFormatDetector(new PngImageFormatDetector()); SystemDrawingReferenceDecoder.Instance,
SystemDrawingReferenceEncoder.Png,
new PngImageFormatDetector());
configuration.ConfigureCodecs(
ImageFormats.Bitmap,
SystemDrawingReferenceDecoder.Instance,
SystemDrawingReferenceEncoder.Png,
new PngImageFormatDetector());
} }
else else
{ {
new PngConfigurationModule().Configure(configuration); configuration.Configure(new PngConfigurationModule());
configuration.Configure(new BmpConfigurationModule());
} }
return configuration; return configuration;

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

@ -14,6 +14,7 @@ using Xunit.Abstractions;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png;
public class TestEnvironmentTests public class TestEnvironmentTests
@ -67,6 +68,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory] [Theory]
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))] [InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))]
[InlineData("lol/Rofl.bmp", 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_Windows(string fileName, Type expectedEncoderType) public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedEncoderType)
@ -79,6 +81,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory] [Theory]
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))]
[InlineData("lol/Rofl.bmp", 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_Windows(string fileName, Type expectedDecoderType) public void GetReferenceDecoder_ReturnsCorrectEncoders_Windows(string fileName, Type expectedDecoderType)
@ -91,6 +94,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory] [Theory]
[InlineData("lol/foo.png", typeof(PngEncoder))] [InlineData("lol/foo.png", typeof(PngEncoder))]
[InlineData("lol/Rofl.bmp", typeof(BmpEncoder))]
[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_Linux(string fileName, Type expectedEncoderType) public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedEncoderType)
@ -103,6 +107,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory] [Theory]
[InlineData("lol/foo.png", typeof(PngDecoder))] [InlineData("lol/foo.png", typeof(PngDecoder))]
[InlineData("lol/Rofl.bmp", typeof(BmpDecoder))]
[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_Linux(string fileName, Type expectedDecoderType) public void GetReferenceDecoder_ReturnsCorrectEncoders_Linux(string fileName, Type expectedDecoderType)

0
tests/ImageSharp.Tests/TestImages/Formats/Bmp/BitmapCoreHeaderQR.bmp → tests/Images/Input/Bmp/BitmapCoreHeaderQR.bmp

Loading…
Cancel
Save