Browse Source

Added tests for loading image with CRC

Added tests for comparing Versioning image 1 and 2
Moved equality tests for images to seperate file
pull/294/head
Devedse 9 years ago
parent
commit
f8c2727c14
  1. 2
      tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs
  2. 124
      tests/ImageSharp.Tests/Image/ImageEqualTests.cs
  3. 24
      tests/ImageSharp.Tests/Image/ImageLoadTests.cs
  4. 2
      tests/ImageSharp.Tests/Image/ImageSaveTests.cs
  5. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs
  6. 6
      tests/ImageSharp.Tests/TestImages.cs
  7. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_1.png
  8. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_2.png

2
tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs

@ -1,4 +1,4 @@
// <copyright file="PixelAccessorTests.cs" company="James Jackson-South"> // <copyright file="ImageDiscoverMimeType.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>

124
tests/ImageSharp.Tests/Image/ImageEqualTests.cs

@ -0,0 +1,124 @@
// <copyright file="ImageEqualTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using System.IO;
using ImageSharp.Formats;
using ImageSharp.IO;
using ImageSharp.Tests;
using Moq;
using Xunit;
public class ImageEqualTests
{
//private readonly Mock<IFileSystem> fileSystem;
//private Image<Rgba32> returnImage;
//private Mock<IImageDecoder> localDecoder;
//private readonly string FilePath;
//private readonly Mock<IImageFormatDetector> localMimeTypeDetector;
//private readonly Mock<IImageFormat> localImageFormatMock;
//public Configuration LocalConfiguration { get; private set; }
//public byte[] Marker { get; private set; }
//public MemoryStream DataStream { get; private set; }
//public byte[] DecodedData { get; private set; }
public ImageEqualTests()
{
//this.returnImage = new Image<Rgba32>(1, 1);
//this.localImageFormatMock = new Mock<IImageFormat>();
//this.localDecoder = new Mock<IImageDecoder>();
//this.localMimeTypeDetector = new Mock<IImageFormatDetector>();
//this.localMimeTypeDetector.Setup(x => x.HeaderSize).Returns(1);
//this.localMimeTypeDetector.Setup(x => x.DetectFormat(It.IsAny<ReadOnlySpan<byte>>())).Returns(localImageFormatMock.Object);
//this.localDecoder.Setup(x => x.Decode<Rgba32>(It.IsAny<Configuration>(), It.IsAny<Stream>()))
// .Callback<Configuration, Stream>((c, s) =>
// {
// using (var ms = new MemoryStream())
// {
// s.CopyTo(ms);
// this.DecodedData = ms.ToArray();
// }
// })
// .Returns(this.returnImage);
//this.fileSystem = new Mock<IFileSystem>();
//this.LocalConfiguration = new Configuration()
//{
// FileSystem = this.fileSystem.Object
//};
//this.LocalConfiguration.AddImageFormatDetector(this.localMimeTypeDetector.Object);
//this.LocalConfiguration.SetDecoder(localImageFormatMock.Object, this.localDecoder.Object);
//TestFormat.RegisterGloablTestFormat();
//this.Marker = Guid.NewGuid().ToByteArray();
//this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker);
//this.FilePath = Guid.NewGuid().ToString();
//this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream);
//TestFileSystem.RegisterGloablTestFormat();
//TestFileSystem.Global.AddFile(this.FilePath, this.DataStream);
}
[Fact]
public void TestsThatVimImagesAreEqual()
{
var image1Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VimImage1);
var image2Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VimImage2);
using (Image<Rgba32> img1 = image1Provider.GetImage())
using (Image<Rgba32> img2 = image2Provider.GetImage())
{
bool imagesEqual = AreImagesEqual(img1, img2);
Assert.True(imagesEqual);
}
}
[Fact]
public void TestsThatVersioningImagesAreEqual()
{
var image1Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VersioningImage1);
var image2Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VersioningImage2);
using (Image<Rgba32> img1 = image1Provider.GetImage())
using (Image<Rgba32> img2 = image2Provider.GetImage())
{
bool imagesEqual = AreImagesEqual(img1, img2);
//Assert.True(imagesEqual);
}
}
private bool AreImagesEqual(Image<Rgba32> img1, Image<Rgba32> img2)
{
Assert.Equal(img1.Width, img2.Width);
Assert.Equal(img1.Height, img2.Height);
for (int y = 0; y < img1.Height; y++)
{
for (int x = 0; x < img1.Width; x++)
{
Rgba32 pixel1 = img1[x, y];
Rgba32 pixel2 = img2[x, y];
if (pixel1 != pixel2)
{
return false;
}
}
}
return true;
}
}
}

24
tests/ImageSharp.Tests/Image/ImageLoadTests.cs

@ -1,4 +1,4 @@
// <copyright file="PixelAccessorTests.cs" company="James Jackson-South"> // <copyright file="ImageLoadTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -321,27 +321,13 @@ namespace ImageSharp.Tests
} }
[Fact] [Fact]
public void TestThatTwoImagesAreEqual() public void LoadsImageWithoutThrowingCrcException()
{ {
var image1Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VimImage1); var image1Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VersioningImage1);
var image2Provider = TestImageProvider<Rgba32>.File(TestImages.Png.VimImage2);
using (Image<Rgba32> img1 = image1Provider.GetImage()) using (Image<Rgba32> img = image1Provider.GetImage())
using (Image<Rgba32> img2 = image2Provider.GetImage())
{ {
Assert.Equal(img1.Width, img2.Width); Assert.Equal(166036, img.Pixels.Length);
Assert.Equal(img1.Height, img2.Height);
for (int y = 0; y < img1.Height; y++)
{
for (int x = 0; x < img1.Width; x++)
{
Rgba32 pixel1 = img1[x, y];
Rgba32 pixel2 = img2[x, y];
Assert.Equal(pixel1, pixel2);
}
}
} }
} }

2
tests/ImageSharp.Tests/Image/ImageSaveTests.cs

@ -1,4 +1,4 @@
// <copyright file="PixelAccessorTests.cs" company="James Jackson-South"> // <copyright file="ImageSaveTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>

2
tests/ImageSharp.Tests/Image/ImageTests.cs

@ -1,4 +1,4 @@
// <copyright file="PixelAccessorTests.cs" company="James Jackson-South"> // <copyright file="ImageTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>

6
tests/ImageSharp.Tests/TestImages.cs

@ -41,6 +41,9 @@ namespace ImageSharp.Tests
public const string VimImage1 = "Png/vim16x16_1.png"; public const string VimImage1 = "Png/vim16x16_1.png";
public const string VimImage2 = "Png/vim16x16_2.png"; public const string VimImage2 = "Png/vim16x16_2.png";
public const string VersioningImage1 = "Png/versioning-1_1.png";
public const string VersioningImage2 = "Png/versioning-1_2.png";
public static class Bad public static class Bad
{ {
// Odd chunk lengths // Odd chunk lengths
@ -53,7 +56,8 @@ namespace ImageSharp.Tests
P1, Pd, Blur, Splash, Cross, P1, Pd, Blur, Splash, Cross,
Powerpoint, SplashInterlaced, Interlaced, Powerpoint, SplashInterlaced, Interlaced,
Filter0, Filter1, Filter2, Filter3, Filter4, Filter0, Filter1, Filter2, Filter3, Filter4,
FilterVar, VimImage1, VimImage2 FilterVar, VimImage1, VimImage2, VersioningImage1,
VersioningImage2
}; };
} }

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/versioning-1_2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Loading…
Cancel
Save