diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index f70e4e3300..1de4e16467 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -11,6 +11,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using System.Linq; + using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -55,7 +57,8 @@ namespace SixLabors.ImageSharp.Tests public static readonly string[] CommonTestImages = { - TestImages.Png.Splash, TestImages.Png.Indexed, + TestImages.Png.Splash, + TestImages.Png.Indexed, TestImages.Png.FilterVar, TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.CorruptedChunk, @@ -67,6 +70,9 @@ namespace SixLabors.ImageSharp.Tests TestImages.Png.SnakeGame, TestImages.Png.Banner7Adam7InterlaceMode, 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+. // 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.VimImage2, + TestImages.Png.Splash, + TestImages.Png.Indexed, + TestImages.Png.Bad.ChunkLength1, + TestImages.Png.VersioningImage1, + TestImages.Png.Banner7Adam7InterlaceMode, }; - [Theory] - [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] - public void Decode(TestImageProvider provider) - where TPixel : struct, IPixel + private static bool SkipVerification(ITestImageProvider provider) { - using (Image image = provider.GetImage(new PngDecoder())) - { - image.DebugSave(provider); - image.CompareToOriginal(provider, ImageComparer.Exact); - } + string fn = provider.SourceFileOrDescription; + + // 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! + 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] - [WithFileCollection(nameof(WindowsOnlyTestImages), PixelTypes.Rgba32)] - public void Decode_WindowsOnlyTestImages(TestImageProvider provider) + [WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] + public void Decode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage(new PngDecoder())) { image.DebugSave(provider); - if (!TestEnvironment.IsLinux) + if (!SkipVerification(provider)) { image.CompareToOriginal(provider, ImageComparer.Exact); } } } - + [Theory] [WithFile(TestImages.Png.Interlaced, PixelTypes.Rgba32)] public void Decode_Interlaced_DoesNotThrow(TestImageProvider provider) @@ -148,7 +154,7 @@ namespace SixLabors.ImageSharp.Tests image.DebugSave(provider); // 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); } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 9a7b9413e7..e1083602e1 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -124,6 +124,12 @@ namespace SixLabors.ImageSharp.Tests // Does DebugSave & load reference CompareToReferenceInput(): 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); string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType); diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index a2e162a0e5..bacdfb504d 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -94,6 +94,12 @@ namespace SixLabors.ImageSharp.Tests.Memory [InlineData(MaxPooledBufferSizeInBytes + 1)] public void LargeBuffersAreNotPooled_OfByte(int size) { + if (!TestEnvironment.Is64BitProcess) + { + // can lead to OutOfMemoryException + return; + } + Assert.False(this.CheckIsRentingPooledBuffer(size)); } @@ -108,6 +114,12 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public unsafe void LaregeBuffersAreNotPooled_OfBigValueType() { + if (!TestEnvironment.Is64BitProcess) + { + // can lead to OutOfMemoryException + return; + } + int count = MaxPooledBufferSizeInBytes / sizeof(LargeStruct) + 1; Assert.False(this.CheckIsRentingPooledBuffer(count)); @@ -161,6 +173,12 @@ namespace SixLabors.ImageSharp.Tests.Memory [Fact] public void AllocationOverLargeArrayThreshold_UsesDifferentPool() { + if (!TestEnvironment.Is64BitProcess) + { + // can lead to OutOfMemoryException + return; + } + int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int); IBuffer small = this.MemoryManager.Allocate(arrayLengthThreshold - 1); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 0f96348375..783e3dd630 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -19,7 +19,9 @@ namespace SixLabors.ImageSharp.Tests { PixelTypes PixelType { get; } ImagingTestCaseUtility Utility { get; } + string SourceFileOrDescription { get; } } + /// /// Provides instances for parametric unit tests. /// diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index f855c2f8ea..4cee650e8a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -92,6 +92,8 @@ namespace SixLabors.ImageSharp.Tests actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar); 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);