Browse Source

tests for Png & Gif codecs

af/merge-core
Anton Firszov 9 years ago
parent
commit
4ac74e5a60
  1. 18
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  2. 14
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  3. 20
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  4. 24
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

18
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -3,15 +3,33 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests
{
using System.Text;
using Xunit;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class GifDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
public static readonly string[] TestFiles = { TestImages.Gif.Giphy, TestImages.Gif.Rings, TestImages.Gif.Trans };
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
public void DecodeAndReSave<TPixel>(TestImageProvider<TPixel> imageProvider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
{
imageProvider.Utility.SaveTestOutputFile(image, "bmp");
imageProvider.Utility.SaveTestOutputFile(image, "gif");
}
}
[Fact]
public void Decode_IgnoreMetadataIsFalse_CommentsAreRead()
{

14
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -9,9 +9,23 @@ namespace ImageSharp.Tests
using Xunit;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class GifEncoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
[Theory]
[WithTestPatternImages(100, 100, PixelTypes)]
public void EncodeGeneratedPatterns<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
provider.Utility.SaveTestOutputFile(image, "gif", new GifEncoder());
}
}
[Fact]
public void Encode_IgnoreMetadataIsFalse_CommentsAreWritten()
{

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

@ -9,9 +9,29 @@ namespace ImageSharp.Tests
using Xunit;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class PngDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
public static readonly string[] TestFiles =
{
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar,
TestImages.Png.ChunkLength1, TestImages.Png.ChunkLength2
};
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
public void DecodeAndReSave<TPixel>(TestImageProvider<TPixel> imageProvider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
{
imageProvider.Utility.SaveTestOutputFile(image, "bmp");
}
}
[Fact]
public void Decode_IgnoreMetadataIsFalse_TextChunckIsRead()
{

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

@ -7,6 +7,7 @@ using ImageSharp.Formats;
namespace ImageSharp.Tests
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -17,6 +18,29 @@ namespace ImageSharp.Tests
public class PngEncoderTests : FileTestBase
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
[Theory]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.RgbWithAlpha)]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.Rgb)]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.Palette)]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.Grayscale)]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.GrayscaleWithAlpha)]
public void EncodeGeneratedPatterns<TPixel>(TestImageProvider<TPixel> provider, PngColorType pngColorType)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
PngEncoderOptions options = new PngEncoderOptions()
{
PngColorType = pngColorType
};
provider.Utility.TestName += "_" + pngColorType;
provider.Utility.SaveTestOutputFile(image, "png", new PngEncoder(), options);
}
}
[Theory]
[WithBlankImages(1, 1, PixelTypes.All)]
public void WritesFileMarker<TPixel>(TestImageProvider<TPixel> provider)

Loading…
Cancel
Save