Browse Source

detecting mono runtime & skipping some png decoder tests

af/merge-core
Anton Firszov 8 years ago
parent
commit
cb43d04d9e
  1. 42
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  2. 6
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  3. 18
      tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  4. 2
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
  5. 2
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

42
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -11,6 +11,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using System.Linq;
using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -55,7 +57,8 @@ namespace SixLabors.ImageSharp.Tests
public static readonly string[] CommonTestImages = public static readonly string[] CommonTestImages =
{ {
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Splash,
TestImages.Png.Indexed,
TestImages.Png.FilterVar, TestImages.Png.FilterVar,
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength1,
TestImages.Png.Bad.CorruptedChunk, TestImages.Png.Bad.CorruptedChunk,
@ -67,6 +70,9 @@ namespace SixLabors.ImageSharp.Tests
TestImages.Png.SnakeGame, TestImages.Png.SnakeGame,
TestImages.Png.Banner7Adam7InterlaceMode, TestImages.Png.Banner7Adam7InterlaceMode,
TestImages.Png.Banner8Index, TestImages.Png.Banner8Index,
TestImages.Png.Bad.ChunkLength2,
TestImages.Png.VimImage2,
}; };
@ -78,42 +84,42 @@ namespace SixLabors.ImageSharp.Tests
// This is a workaround for Mono-s decoder being incompatible with ours and GDI+. // This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
// We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA! // We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
public static readonly string[] WindowsOnlyTestImages = private static readonly string[] SkipOnMono =
{ {
TestImages.Png.Bad.ChunkLength2, TestImages.Png.Bad.ChunkLength2,
TestImages.Png.VimImage2, TestImages.Png.VimImage2,
TestImages.Png.Splash,
TestImages.Png.Indexed,
TestImages.Png.Bad.ChunkLength1,
TestImages.Png.VersioningImage1,
TestImages.Png.Banner7Adam7InterlaceMode,
}; };
[Theory] private static bool SkipVerification(ITestImageProvider provider)
[WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)]
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage(new PngDecoder())) string fn = provider.SourceFileOrDescription;
{
image.DebugSave(provider); // This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
image.CompareToOriginal(provider, ImageComparer.Exact); // We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
} return (TestEnvironment.IsLinux || TestEnvironment.IsMono) && SkipOnMono.Contains(fn);
} }
// This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
// We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
[Theory] [Theory]
[WithFileCollection(nameof(WindowsOnlyTestImages), PixelTypes.Rgba32)] [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)]
public void Decode_WindowsOnlyTestImages<TPixel>(TestImageProvider<TPixel> provider) public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage(new PngDecoder())) using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{ {
image.DebugSave(provider); image.DebugSave(provider);
if (!TestEnvironment.IsLinux) if (!SkipVerification(provider))
{ {
image.CompareToOriginal(provider, ImageComparer.Exact); image.CompareToOriginal(provider, ImageComparer.Exact);
} }
} }
} }
[Theory] [Theory]
[WithFile(TestImages.Png.Interlaced, PixelTypes.Rgba32)] [WithFile(TestImages.Png.Interlaced, PixelTypes.Rgba32)]
public void Decode_Interlaced_DoesNotThrow<TPixel>(TestImageProvider<TPixel> provider) public void Decode_Interlaced_DoesNotThrow<TPixel>(TestImageProvider<TPixel> provider)
@ -148,7 +154,7 @@ namespace SixLabors.ImageSharp.Tests
image.DebugSave(provider); image.DebugSave(provider);
// Workaround a bug in mono-s System.Drawing PNG decoder. It can't deal with 48Bpp png-s :( // Workaround a bug in mono-s System.Drawing PNG decoder. It can't deal with 48Bpp png-s :(
if (!TestEnvironment.IsLinux) if (!TestEnvironment.IsLinux && !TestEnvironment.IsMono)
{ {
image.CompareToOriginal(provider, ImageComparer.Exact); image.CompareToOriginal(provider, ImageComparer.Exact);
} }

6
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -124,6 +124,12 @@ namespace SixLabors.ImageSharp.Tests
// Does DebugSave & load reference CompareToReferenceInput(): // Does DebugSave & load reference CompareToReferenceInput():
string actualOutputFile = ((ITestImageProvider)provider).Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType); string actualOutputFile = ((ITestImageProvider)provider).Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType);
if (TestEnvironment.IsMono)
{
// There are bugs in mono's System.Drawing implementation, reference decoders are not always reliable!
return;
}
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile);
string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType); string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType);

18
tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs

@ -94,6 +94,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(MaxPooledBufferSizeInBytes + 1)] [InlineData(MaxPooledBufferSizeInBytes + 1)]
public void LargeBuffersAreNotPooled_OfByte(int size) public void LargeBuffersAreNotPooled_OfByte(int size)
{ {
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
Assert.False(this.CheckIsRentingPooledBuffer<byte>(size)); Assert.False(this.CheckIsRentingPooledBuffer<byte>(size));
} }
@ -108,6 +114,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact] [Fact]
public unsafe void LaregeBuffersAreNotPooled_OfBigValueType() public unsafe void LaregeBuffersAreNotPooled_OfBigValueType()
{ {
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
int count = MaxPooledBufferSizeInBytes / sizeof(LargeStruct) + 1; int count = MaxPooledBufferSizeInBytes / sizeof(LargeStruct) + 1;
Assert.False(this.CheckIsRentingPooledBuffer<LargeStruct>(count)); Assert.False(this.CheckIsRentingPooledBuffer<LargeStruct>(count));
@ -161,6 +173,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact] [Fact]
public void AllocationOverLargeArrayThreshold_UsesDifferentPool() public void AllocationOverLargeArrayThreshold_UsesDifferentPool()
{ {
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int);
IBuffer<int> small = this.MemoryManager.Allocate<int>(arrayLengthThreshold - 1); IBuffer<int> small = this.MemoryManager.Allocate<int>(arrayLengthThreshold - 1);

2
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs

@ -19,7 +19,9 @@ namespace SixLabors.ImageSharp.Tests
{ {
PixelTypes PixelType { get; } PixelTypes PixelType { get; }
ImagingTestCaseUtility Utility { get; } ImagingTestCaseUtility Utility { get; }
string SourceFileOrDescription { get; }
} }
/// <summary> /// <summary>
/// Provides <see cref="Image{TPixel}" /> instances for parametric unit tests. /// Provides <see cref="Image{TPixel}" /> instances for parametric unit tests.
/// </summary> /// </summary>

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

@ -92,6 +92,8 @@ namespace SixLabors.ImageSharp.Tests
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar); actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar);
internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194
internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

Loading…
Cancel
Save