Browse Source

Refactor Tiff decoder tests: split large "testall" test into smaller ones

pull/1570/head
Brian Popow 6 years ago
parent
commit
163f49973e
  1. 2
      tests/ImageSharp.Tests/Formats/Tiff/Compression/DeflateTiffCompressionTests.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Tiff/Compression/LzwTiffCompressionTests.cs
  3. 2
      tests/ImageSharp.Tests/Formats/Tiff/Compression/NoneTiffCompressionTests.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Tiff/Compression/PackBitsTiffCompressionTests.cs
  5. 2
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs
  6. 117
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  7. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs
  8. 14
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
  9. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffFormatTests.cs
  10. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
  11. 2
      tests/ImageSharp.Tests/Formats/Tiff/Utils/SubStreamTests.cs
  12. 2
      tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs
  13. 19
      tests/ImageSharp.Tests/TestImages.cs
  14. 4
      tests/Images/Input/Tiff/rgb_deflate.tiff
  15. 3
      tests/Images/Input/Tiff/rgb_deflate_predictor.tiff
  16. 3
      tests/Images/Input/Tiff/rgb_palette.tiff
  17. 3
      tests/Images/Input/Tiff/rgb_palette_deflate.tiff

2
tests/ImageSharp.Tests/Formats/Tiff/Compression/DeflateTiffCompressionTests.cs

@ -8,7 +8,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Compression
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class DeflateTiffCompressionTests
{
[Theory]

2
tests/ImageSharp.Tests/Formats/Tiff/Compression/LzwTiffCompressionTests.cs

@ -10,7 +10,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Compression
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class LzwTiffCompressionTests
{
[Theory]

2
tests/ImageSharp.Tests/Formats/Tiff/Compression/NoneTiffCompressionTests.cs

@ -7,7 +7,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Compression
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class NoneTiffCompressionTests
{
[Theory]

2
tests/ImageSharp.Tests/Formats/Tiff/Compression/PackBitsTiffCompressionTests.cs

@ -11,7 +11,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Compression
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class PackBitsTiffCompressionTests
{
[Theory]

2
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs

@ -9,7 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public abstract class PhotometricInterpretationTestBase
{
public static Rgba32 DefaultColor = new Rgba32(42, 96, 18, 128);

117
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

@ -14,21 +14,20 @@ using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
using static SixLabors.ImageSharp.Tests.TestImages.Tiff;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff.BlackBox.Decoder")]
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffDecoderTests
{
private static TiffDecoder TiffDecoder => new TiffDecoder();
private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder();
public static readonly string[] MultiframeTestImages = Multiframes;
public static readonly string[] SingleTestImages = TestImages.Tiff.All;
public static readonly string[] NotSupportedImages = NotSupported;
public static readonly string[] MultiframeTestImages = TestImages.Tiff.Multiframes;
private static TiffDecoder TiffDecoder => new TiffDecoder();
public static readonly string[] NotSupportedImages = TestImages.Tiff.NotSupported;
private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder();
[Theory]
[WithFileCollection(nameof(NotSupportedImages), PixelTypes.Rgba32)]
@ -72,7 +71,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
Assert.NotNull(info.Metadata);
Assert.Equal(expectedByteOrder, info.Metadata.GetTiffMetadata().ByteOrder);
// todo: it's not a mistake?
stream.Seek(0, SeekOrigin.Begin);
using var img = Image.Load(stream);
@ -81,15 +79,78 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
}
[Theory]
[WithFileCollection(nameof(SingleTestImages), PixelTypes.Rgba32)]
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
[WithFile(RgbUncompressed, PixelTypes.Rgba32)]
[WithFile(Calliphora_GrayscaleUncompressed, PixelTypes.Rgba32)]
[WithFile(Calliphora_RgbUncompressed, PixelTypes.Rgba32)]
[WithFile(Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_Uncompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TiffDecoder))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact, ReferenceDecoder);
}
TestTiffDecoder(provider);
}
[Theory]
[WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)]
[WithFile(RgbPalette, PixelTypes.Rgba32)]
[WithFile(RgbPaletteDeflate, PixelTypes.Rgba32)]
[WithFile(PaletteUncompressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_WithPalette<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
[WithFile(Calliphora_GrayscaleDeflate, PixelTypes.Rgba32)]
[WithFile(Calliphora_GrayscaleDeflate_Predictor, PixelTypes.Rgba32)]
[WithFile(Calliphora_RgbDeflate_Predictor, PixelTypes.Rgba32)]
[WithFile(RgbDeflate, PixelTypes.Rgba32)]
[WithFile(RgbDeflatePredictor, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_DeflateCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
[WithFile(RgbLzwPredictor, PixelTypes.Rgba32)]
[WithFile(RgbLzwNoPredictor, PixelTypes.Rgba32)]
[WithFile(Calliphora_RgbLzw_Predictor, PixelTypes.Rgba32)]
[WithFile(SmallRgbLzw, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_LzwCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
[WithFile(HuffmanRleAllTermCodes, PixelTypes.Rgba32)]
[WithFile(HuffmanRleAllMakeupCodes, PixelTypes.Rgba32)]
[WithFile(HuffmanRle_basi3p02, PixelTypes.Rgba32)]
[WithFile(Calliphora_HuffmanCompressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_HuffmanCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
[WithFile(CcittFax3AllTermCodes, PixelTypes.Rgba32)]
[WithFile(CcittFax3AllMakeupCodes, PixelTypes.Rgba32)]
[WithFile(Calliphora_Fax3Compressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_Fax3Compressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
[WithFile(Calliphora_RgbPackbits, PixelTypes.Rgba32)]
[WithFile(RgbPackbits, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_PackBitsCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
TestTiffDecoder(provider);
}
[Theory]
@ -97,16 +158,22 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public void DecodeMultiframe<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(TiffDecoder))
{
Assert.True(image.Frames.Count > 1);
using Image<TPixel> image = provider.GetImage(TiffDecoder);
Assert.True(image.Frames.Count > 1);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact, ReferenceDecoder);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact, ReferenceDecoder);
image.DebugSaveMultiFrame(provider);
image.CompareToOriginalMultiFrame(provider, ImageComparer.Exact, ReferenceDecoder);
}
image.DebugSaveMultiFrame(provider);
image.CompareToOriginalMultiFrame(provider, ImageComparer.Exact, ReferenceDecoder);
}
private static void TestTiffDecoder<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact, ReferenceDecoder);
}
}
}

2
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderHeaderTests.cs

@ -11,7 +11,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffEncoderHeaderTests
{
private static readonly MemoryAllocator MemoryAllocator = new ArrayPoolMemoryAllocator();

14
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs

@ -13,7 +13,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffEncoderTests
{
private static readonly IImageDecoder ReferenceDecoder = new MagickReferenceDecoder();
@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
public static readonly TheoryData<string, TiffBitsPerPixel> TiffBitsPerPixelFiles =
new TheoryData<string, TiffBitsPerPixel>
{
{ TestImages.Tiff.Calliphora_BiColor, TiffBitsPerPixel.Pixel1 },
{ TestImages.Tiff.Calliphora_BiColorUncompressed, TiffBitsPerPixel.Pixel1 },
{ TestImages.Tiff.GrayscaleUncompressed, TiffBitsPerPixel.Pixel8 },
{ TestImages.Tiff.RgbUncompressed, TiffBitsPerPixel.Pixel24 },
};
@ -131,27 +131,27 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
}
[Theory]
[WithFile(TestImages.Tiff.Calliphora_BiColor, PixelTypes.Rgba32)]
[WithFile(TestImages.Tiff.Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeBiColor_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Pixel24, TiffEncodingMode.BiColor);
[Theory]
[WithFile(TestImages.Tiff.Calliphora_BiColor, PixelTypes.Rgba32)]
[WithFile(TestImages.Tiff.Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeBiColor_WithDeflateCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Pixel1, TiffEncodingMode.BiColor, TiffEncoderCompression.Deflate);
[Theory]
[WithFile(TestImages.Tiff.Calliphora_BiColor, PixelTypes.Rgba32)]
[WithFile(TestImages.Tiff.Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeBiColor_WithPackBitsCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Pixel1, TiffEncodingMode.BiColor, TiffEncoderCompression.PackBits);
[Theory]
[WithFile(TestImages.Tiff.Calliphora_BiColor, PixelTypes.Rgba32)]
[WithFile(TestImages.Tiff.Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeBiColor_WithCcittGroup3FaxCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Pixel1, TiffEncodingMode.BiColor, TiffEncoderCompression.CcittGroup3Fax);
[Theory]
[WithFile(TestImages.Tiff.Calliphora_BiColor, PixelTypes.Rgba32)]
[WithFile(TestImages.Tiff.Calliphora_BiColorUncompressed, PixelTypes.Rgba32)]
public void TiffEncoder_EncodeBiColor_WithModifiedHuffmanCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffEncoderCore(provider, TiffBitsPerPixel.Pixel1, TiffEncodingMode.BiColor, TiffEncoderCompression.ModifiedHuffman);

2
tests/ImageSharp.Tests/Formats/Tiff/TiffFormatTests.cs

@ -6,7 +6,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffFormatTests
{
[Fact]

2
tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs

@ -10,7 +10,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffMetadataTests
{
public static readonly string[] MetadataImages = TestImages.Tiff.Metadata;

2
tests/ImageSharp.Tests/Formats/Tiff/Utils/SubStreamTests.cs

@ -10,7 +10,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class SubStreamTests
{
[Fact]

2
tests/ImageSharp.Tests/Formats/Tiff/Utils/TiffWriterTests.cs

@ -10,7 +10,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff.Utils
{
[Trait("Category", "Tiff")]
[Trait("Format", "Tiff")]
public class TiffWriterTests
{
private static readonly MemoryAllocator MemoryAllocator = new ArrayPoolMemoryAllocator();

19
tests/ImageSharp.Tests/TestImages.cs

@ -515,7 +515,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Calliphora_RgbUncompressed = "Tiff/Calliphora_rgb_uncompressed.tiff";
public const string Calliphora_Fax3Compressed = "Tiff/Calliphora_ccitt_fax3.tiff";
public const string Calliphora_HuffmanCompressed = "Tiff/Calliphora_huffman_rle.tiff";
public const string Calliphora_BiColor = "Tiff/Calliphora_bicolor_uncompressed.tiff";
public const string Calliphora_BiColorUncompressed = "Tiff/Calliphora_bicolor_uncompressed.tiff";
public const string CcittFax3AllTermCodes = "Tiff/ccitt_fax3_all_terminating_codes.tiff";
public const string CcittFax3AllMakeupCodes = "Tiff/ccitt_fax3_all_makeup_codes.tiff";
@ -529,7 +529,8 @@ namespace SixLabors.ImageSharp.Tests
public const string GrayscaleUncompressed = "Tiff/grayscale_uncompressed.tiff";
public const string PaletteDeflateMultistrip = "Tiff/palette_grayscale_deflate_multistrip.tiff";
public const string PaletteUncompressed = "Tiff/palette_uncompressed.tiff";
public const string RgbDeflatePredictor = "Tiff/rgb_deflate.tiff";
public const string RgbDeflate = "Tiff/rgb_deflate.tiff";
public const string RgbDeflatePredictor = "Tiff/rgb_deflate_predictor.tiff";
public const string RgbDeflateMultistrip = "Tiff/rgb_deflate_multistrip.tiff";
public const string RgbJpeg = "Tiff/rgb_jpeg.tiff";
public const string RgbLzwPredictor = "Tiff/rgb_lzw_predictor.tiff";
@ -541,6 +542,8 @@ namespace SixLabors.ImageSharp.Tests
public const string RgbPackbits = "Tiff/rgb_packbits.tiff";
public const string RgbPackbitsMultistrip = "Tiff/rgb_packbits_multistrip.tiff";
public const string RgbUncompressed = "Tiff/rgb_uncompressed.tiff";
public const string RgbPalette = "Tiff/rgb_palette.tiff";
public const string RgbPaletteDeflate = "Tiff/rgb_palette_deflate.tiff";
public const string SmallRgbDeflate = "Tiff/rgb_small_deflate.tiff";
public const string SmallRgbLzw = "Tiff/rgb_small_lzw.tiff";
@ -555,18 +558,6 @@ namespace SixLabors.ImageSharp.Tests
public const string SampleMetadata = "Tiff/metadata_sample.tiff";
public static readonly string[] All =
{
Calliphora_PaletteUncompressed, Calliphora_RgbPackbits,
Calliphora_GrayscaleDeflate_Predictor, Calliphora_RgbDeflate_Predictor, RgbDeflatePredictor,
Calliphora_RgbLzw_Predictor, RgbLzwPredictor, // TODO: Undoing the horizontal prediction seems to fail for lzw. Do we need to do something different for lzw?
Calliphora_BiColor, Calliphora_RgbUncompressed, Calliphora_HuffmanCompressed, Calliphora_Fax3Compressed, CcittFax3AllTermCodes, CcittFax3AllMakeupCodes,
HuffmanRleAllTermCodes, HuffmanRleAllMakeupCodes, HuffmanRle_basi3p02, GrayscaleDeflateMultistrip, Calliphora_GrayscaleDeflate, Calliphora_GrayscaleUncompressed,
GrayscaleUncompressed, PaletteDeflateMultistrip, PaletteUncompressed, RgbDeflateMultistrip, /*RgbJpeg,*/ /* RgbLzwMultistrip_Predictor,*/
RgbLzwNoPredictorMultistrip, RgbLzwNoPredictorMultistripMotorola, RgbLzwNoPredictorSinglestripMotorola, RgbPackbits, RgbPackbitsMultistrip, RgbUncompressed,
/* MultiframeLzw_Predictor, MultiFrameDifferentVariants, SampleMetadata,*/ SmallRgbDeflate, SmallRgbLzw, RgbLzwNoPredictor
};
public static readonly string[] Multiframes = { MultiframeDeflateWithPreview /*MultiframeLzw_Predictor, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ };
public static readonly string[] Metadata = { SampleMetadata };

4
tests/Images/Input/Tiff/rgb_deflate.tiff

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1db70e0cfb056cfc675db3a2b85a1f226c53cd70275808773ff580c738b3db1
size 3158
oid sha256:0af0db6a42424e3db5c6b84be6e253817413b2de68cc91f7288a8434150fe088
size 67130

3
tests/Images/Input/Tiff/rgb_deflate_predictor.tiff

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1db70e0cfb056cfc675db3a2b85a1f226c53cd70275808773ff580c738b3db1
size 3158

3
tests/Images/Input/Tiff/rgb_palette.tiff

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:75f1bcaff7dc09ddbe6ded7b764b8c0b17bffc3392bafdc7bc7a4c7d616a38e5
size 67394

3
tests/Images/Input/Tiff/rgb_palette_deflate.tiff

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:434cc4c212dfa975c130e2acd7c704b9cc6d0bf168336b8f778f811ddaf6a812
size 24990
Loading…
Cancel
Save