Browse Source

Add tests for discontiguous buffers for tga

pull/1109/head
Brian Popow 6 years ago
parent
commit
c30eb200e7
  1. 47
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs
  2. 10
      tests/ImageSharp.Tests/Formats/Tga/TgaEncoderTests.cs

47
tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

@ -1,9 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit;
// ReSharper disable InconsistentNaming
@ -192,5 +195,47 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
TgaTestUtils.CompareWithReferenceDecoder(provider, image);
}
}
// TODO: A InvalidMemoryOperationException is thrown here, review the thrown exception.
[Theory(Skip = "Review Exception")]
[WithFile(Bit16, PixelTypes.Rgba32)]
[WithFile(Bit24, PixelTypes.Rgba32)]
[WithFile(Bit32, PixelTypes.Rgba32)]
public void TgaDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity(100);
ImageFormatException ex = Assert.Throws<ImageFormatException>(provider.GetImage);
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
[Theory]
[WithFile(Bit24, PixelTypes.Rgba32)]
[WithFile(Bit32, PixelTypes.Rgba32)]
public void TgaDecoder_CanDecode_WithLimitedAllocatorBufferCapacity<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
static void RunTest(string providerDump, string nonContiguousBuffersStr)
{
TestImageProvider<TPixel> provider = BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.LimitAllocatorBufferCapacity();
using Image<TPixel> image = provider.GetImage(new TgaDecoder());
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);
if (TestEnvironment.IsWindows)
{
image.CompareToOriginal(provider);
}
}
string providerDump = BasicSerializer.Serialize(provider);
RemoteExecutor.Invoke(
RunTest,
providerDump,
"Disco")
.Dispose();
}
}
}

10
tests/ImageSharp.Tests/Formats/Tga/TgaEncoderTests.cs

@ -122,6 +122,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
public void Encode_Bit32_WithRunLengthEncoding_Works<TPixel>(TestImageProvider<TPixel> provider, TgaBitsPerPixel bitsPerPixel = TgaBitsPerPixel.Pixel32)
where TPixel : struct, IPixel<TPixel> => TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
[Theory]
[WithFile(Bit32, PixelTypes.Rgba32, TgaBitsPerPixel.Pixel32)]
[WithFile(Bit24, PixelTypes.Rgba32, TgaBitsPerPixel.Pixel24)]
public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixel> provider, TgaBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity(10000);
TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
}
private static void TestTgaEncoderCore<TPixel>(
TestImageProvider<TPixel> provider,
TgaBitsPerPixel bitsPerPixel,

Loading…
Cancel
Save