Browse Source

Added failing test for issue 288

pull/289/head
Devedse 9 years ago
parent
commit
a209a8210d
  1. 60
      tests/ImageSharp.Tests/Image/ImageLoadTests.cs
  2. 5
      tests/ImageSharp.Tests/TestImages.cs
  3. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_1.png
  4. BIN
      tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_2.png

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

@ -10,7 +10,6 @@ namespace ImageSharp.Tests
using ImageSharp.Formats; using ImageSharp.Formats;
using ImageSharp.IO; using ImageSharp.IO;
using ImageSharp.PixelFormats;
using Moq; using Moq;
using Xunit; using Xunit;
@ -44,7 +43,8 @@ namespace ImageSharp.Tests
this.localDecoder.Setup(x => x.Decode<Rgba32>(It.IsAny<Configuration>(), It.IsAny<Stream>())) this.localDecoder.Setup(x => x.Decode<Rgba32>(It.IsAny<Configuration>(), It.IsAny<Stream>()))
.Callback<Configuration, Stream>((c, s) => { .Callback<Configuration, Stream>((c, s) =>
{
using (var ms = new MemoryStream()) using (var ms = new MemoryStream())
{ {
s.CopyTo(ms); s.CopyTo(ms);
@ -76,7 +76,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromStream() public void LoadFromStream()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream); Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream);
Assert.NotNull(img); Assert.NotNull(img);
@ -87,12 +87,11 @@ namespace ImageSharp.Tests
public void LoadFromNoneSeekableStream() public void LoadFromNoneSeekableStream()
{ {
NoneSeekableStream stream = new NoneSeekableStream(this.DataStream); NoneSeekableStream stream = new NoneSeekableStream(this.DataStream);
Image<Rgba32> img = Image.Load<Rgba32>(stream); Image<Rgba32> img = Image.Load<Rgba32>(stream);
Assert.NotNull(img); Assert.NotNull(img);
TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default);
} }
[Fact] [Fact]
@ -104,20 +103,18 @@ namespace ImageSharp.Tests
Assert.Equal(TestFormat.GlobalTestFormat.Sample<Rgba32>(), img); Assert.Equal(TestFormat.GlobalTestFormat.Sample<Rgba32>(), img);
TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default);
} }
[Fact] [Fact]
public void LoadFromStreamWithConfig() public void LoadFromStreamWithConfig()
{ {
Stream stream = new MemoryStream(); Stream stream = new MemoryStream();
Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, stream); Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, stream);
Assert.NotNull(img); Assert.NotNull(img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, stream)); this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, stream));
} }
[Fact] [Fact]
@ -130,7 +127,6 @@ namespace ImageSharp.Tests
Assert.Equal(this.returnImage, img); Assert.Equal(this.returnImage, img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, stream)); this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, stream));
} }
@ -138,7 +134,7 @@ namespace ImageSharp.Tests
public void LoadFromStreamWithDecoder() public void LoadFromStreamWithDecoder()
{ {
Stream stream = new MemoryStream(); Stream stream = new MemoryStream();
Image<Rgba32> img = Image.Load<Rgba32>(stream, this.localDecoder.Object); Image<Rgba32> img = Image.Load<Rgba32>(stream, this.localDecoder.Object);
Assert.NotNull(img); Assert.NotNull(img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, stream)); this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, stream));
@ -158,13 +154,11 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromBytes() public void LoadFromBytes()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream.ToArray()); Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream.ToArray());
Assert.NotNull(img); Assert.NotNull(img);
TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default);
} }
[Fact] [Fact]
@ -182,7 +176,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromBytesWithConfig() public void LoadFromBytesWithConfig()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, this.DataStream.ToArray()); Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, this.DataStream.ToArray());
Assert.NotNull(img); Assert.NotNull(img);
@ -207,7 +201,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromBytesWithDecoder() public void LoadFromBytesWithDecoder()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream.ToArray(), this.localDecoder.Object); Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream.ToArray(), this.localDecoder.Object);
Assert.NotNull(img); Assert.NotNull(img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, It.IsAny<Stream>())); this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, It.IsAny<Stream>()));
@ -228,13 +222,11 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromFile() public void LoadFromFile()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream); Image<Rgba32> img = Image.Load<Rgba32>(this.DataStream);
Assert.NotNull(img); Assert.NotNull(img);
TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default);
} }
[Fact] [Fact]
@ -251,12 +243,11 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromFileWithConfig() public void LoadFromFileWithConfig()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, this.FilePath); Image<Rgba32> img = Image.Load<Rgba32>(this.LocalConfiguration, this.FilePath);
Assert.NotNull(img); Assert.NotNull(img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, this.DataStream)); this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, this.DataStream));
} }
[Fact] [Fact]
@ -273,7 +264,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void LoadFromFileWithDecoder() public void LoadFromFileWithDecoder()
{ {
Image<Rgba32> img = Image.Load<Rgba32>(this.FilePath, this.localDecoder.Object); Image<Rgba32> img = Image.Load<Rgba32>(this.FilePath, this.localDecoder.Object);
Assert.NotNull(img); Assert.NotNull(img);
this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, this.DataStream)); this.localDecoder.Verify(x => x.Decode<Rgba32>(Configuration.Default, this.DataStream));
@ -305,7 +296,6 @@ namespace ImageSharp.Tests
Assert.Equal(Rgba32.White, px[1, 0]); Assert.Equal(Rgba32.White, px[1, 0]);
Assert.Equal(Rgba32.Black, px[1, 1]); Assert.Equal(Rgba32.Black, px[1, 1]);
} }
} }
@ -327,7 +317,31 @@ namespace ImageSharp.Tests
Assert.Equal(Rgba32.White, px[1, 0]); Assert.Equal(Rgba32.White, px[1, 0]);
Assert.Equal(Rgba32.Black, px[1, 1]); Assert.Equal(Rgba32.Black, px[1, 1]);
}
}
[Fact]
public void TestThatTwoImagesAreEqual()
{
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())
{
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];
Assert.Equal(pixel1, pixel2);
}
}
} }
} }

5
tests/ImageSharp.Tests/TestImages.cs

@ -38,6 +38,9 @@ namespace ImageSharp.Tests
// Filter changing per scanline // Filter changing per scanline
public const string FilterVar = "Png/filterVar.png"; public const string FilterVar = "Png/filterVar.png";
public const string VimImage1 = "Png/vim16x16_1.png";
public const string VimImage2 = "Png/vim16x16_2.png";
public static class Bad public static class Bad
{ {
// Odd chunk lengths // Odd chunk lengths
@ -50,7 +53,7 @@ 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 FilterVar, VimImage1, VimImage2
}; };
} }

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

BIN
tests/ImageSharp.Tests/TestImages/Formats/Png/vim16x16_2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Loading…
Cancel
Save