Browse Source

Add encode test for width and size > 65k

pull/2192/head
Brian Popow 4 years ago
parent
commit
731abc7aaa
  1. 26
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

26
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
@ -20,6 +21,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
[Trait("Format", "Bmp")]
public class BmpEncoderTests
{
private static BmpEncoder BmpEncoder => new();
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
new()
{
@ -50,14 +53,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
[MemberData(nameof(RatioFiles))]
public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)
{
var options = new BmpEncoder();
var testFile = TestFile.Create(imagePath);
using (Image<Rgba32> input = testFile.CreateRgba32Image())
{
using (var memStream = new MemoryStream())
{
input.Save(memStream, options);
input.Save(memStream, BmpEncoder);
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))
@ -75,14 +76,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
[MemberData(nameof(BmpBitsPerPixelFiles))]
public void Encode_PreserveBitsPerPixel(string imagePath, BmpBitsPerPixel bmpBitsPerPixel)
{
var options = new BmpEncoder();
var testFile = TestFile.Create(imagePath);
using (Image<Rgba32> input = testFile.CreateRgba32Image())
{
using (var memStream = new MemoryStream())
{
input.Save(memStream, options);
input.Save(memStream, BmpEncoder);
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))
@ -328,6 +327,21 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
}
}
[Theory]
[InlineData(1, 66535)]
[InlineData(66535, 1)]
public void Encode_WorksWithSizeGreaterThen65k(int width, int height)
{
Exception exception = Record.Exception(() =>
{
using Image image = new Image<Rgba32>(width, height);
using var memStream = new MemoryStream();
image.Save(memStream, BmpEncoder);
});
Assert.Null(exception);
}
[Theory]
[WithFile(Car, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)]
[WithFile(V5Header, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)]

Loading…
Cancel
Save