Browse Source

Refactored TestImages again so they can be used in Attributes.

pull/57/head
Dirk Lemstra 10 years ago
parent
commit
4c9e3dc4e7
  1. 2
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  2. 2
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs
  3. 52
      tests/ImageSharp.Tests/FileTestBase.cs
  4. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  5. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs
  6. 2
      tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs
  7. 8
      tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs
  8. 2
      tests/ImageSharp.Tests/Profiles/Exif/ExifValueTests.cs
  9. 30
      tests/ImageSharp.Tests/TestFile.cs
  10. 100
      tests/ImageSharp.Tests/TestImages.cs

2
tests/ImageSharp.Tests/Drawing/DrawImageTest.cs

@ -17,7 +17,7 @@ namespace ImageSharp.Tests
{
string path = CreateOutputDirectory("Drawing", "DrawImage");
Image blend = TestImages.Bmp.Car.CreateImage();
Image blend = TestFile.Create(TestImages.Bmp.Car).CreateImage();
foreach (TestFile file in Files)
{

2
tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs

@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300)
};
var brush = new ImageBrush(TestImages.Bmp.Car.CreateImage());
var brush = new ImageBrush(TestFile.Create(TestImages.Bmp.Car).CreateImage());
var image = new Image(500, 500);
using (FileStream output = File.OpenWrite($"{path}/Image.png"))

52
tests/ImageSharp.Tests/FileTestBase.cs

@ -18,32 +18,32 @@ namespace ImageSharp.Tests
/// </summary>
protected static readonly List<TestFile> Files = new List<TestFile>
{
// TestImages.Png.P1, // Perf: Enable for local testing only
// TestImages.Png.Pd, // Perf: Enable for local testing only
// TestImages.Jpeg.Floorplan, // Perf: Enable for local testing only
TestImages.Jpeg.Calliphora,
// TestImages.Jpeg.Ycck, // Perf: Enable for local testing only
// TestImages.Jpeg.Cmyk, // Perf: Enable for local testing only
TestImages.Jpeg.Turtle,
// TestImages.Jpeg.Fb, // Perf: Enable for local testing only
// TestImages.Jpeg.Progress, // Perf: Enable for local testing only
// TestImages.Jpeg.GammaDalaiLamaGray, // Perf: Enable for local testing only
TestImages.Bmp.Car,
// TestImages.Bmp.Neg_height, // Perf: Enable for local testing only
// TestImages.Png.Blur, // Perf: Enable for local testing only
// TestImages.Png.Indexed, // Perf: Enable for local testing only
TestImages.Png.Splash,
// TestImages.Png.SplashInterlaced, // Perf: Enable for local testing only
// TestImages.Png.Interlaced, // Perf: Enable for local testing only
// TestImages.Png.Filter0, // Perf: Enable for local testing only
// TestImages.Png.Filter1, // Perf: Enable for local testing only
// TestImages.Png.Filter2, // Perf: Enable for local testing only
// TestImages.Png.Filter3, // Perf: Enable for local testing only
// TestImages.Png.Filter4, // Perf: Enable for local testing only
// TestImages.Png.FilterVar, // Perf: Enable for local testing only
TestImages.Gif.Rings, // Perf: Enable for local testing only
// TestImages.Gif.Cheers,
// TestImages.Gif.Giphy // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.P1), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Pd), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Floorplan), // Perf: Enable for local testing only
TestFile.Create(TestImages.Jpeg.Calliphora),
// TestFile.Create(TestImages.Jpeg.Ycck), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Cmyk), // Perf: Enable for local testing only
TestFile.Create(TestImages.Jpeg.Turtle),
// TestFile.Create(TestImages.Jpeg.Fb), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.Progress), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Jpeg.GammaDalaiLamaGray), // Perf: Enable for local testing only
TestFile.Create(TestImages.Bmp.Car),
// TestFile.Create(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Blur), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Indexed), // Perf: Enable for local testing only
TestFile.Create(TestImages.Png.Splash),
// TestFile.Create(TestImages.Png.SplashInterlaced), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Interlaced), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Filter0), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Filter1), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Filter2), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Filter3), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.Filter4), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Png.FilterVar), // Perf: Enable for local testing only
TestFile.Create(TestImages.Gif.Rings), // Perf: Enable for local testing only
// TestFile.Create(TestImages.Gif.Cheers),
// TestFile.Create(TestImages.Gif.Giphy) // Perf: Enable for local testing only
};
protected string CreateOutputDirectory(string path, params string[] pathParts)

4
tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs

@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Formats.Jpg
}
public static IEnumerable<object[]> AllJpegFiles
=> TestImages.Jpeg.All.Select(file => new object[] {file});
=> TestImages.Jpeg.All.Select(file => new object[] {TestFile.Create(file)});
[Theory]
[MemberData(nameof(AllJpegFiles))]
@ -60,7 +60,7 @@ namespace ImageSharp.Tests.Formats.Jpg
}
public static IEnumerable<object[]> AllBmpFiles
=> TestImages.Bmp.All.Select(file => new object[] {file});
=> TestImages.Bmp.All.Select(file => new object[] { TestFile.Create(file) });
[Theory]
[MemberData(nameof(AllBmpFiles))]

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

@ -22,7 +22,7 @@ namespace ImageSharp.Tests
new Image((byte[])null);
});
TestFile file = TestImages.Bmp.Car;
TestFile file = TestFile.Create(TestImages.Bmp.Car);
Image image = new Image(file.Bytes);
Assert.Equal(600, image.Width);

2
tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs

@ -30,7 +30,7 @@ namespace ImageSharp.Tests
{
string path = CreateOutputDirectory("AutoOrient");
TestFile file = TestImages.Bmp.F;
TestFile file = TestFile.Create(TestImages.Bmp.F);
Image image = file.CreateImage();
image.ExifProfile = new ExifProfile();

8
tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs

@ -17,7 +17,7 @@ namespace ImageSharp.Tests
[Fact]
public void Constructor()
{
Image image = TestImages.Jpeg.Calliphora.CreateImage();
Image image = TestFile.Create(TestImages.Jpeg.Calliphora).CreateImage();
Assert.Null(image.ExifProfile);
@ -104,7 +104,7 @@ namespace ImageSharp.Tests
[Fact]
public void ReadWriteInfinity()
{
Image image = TestImages.Jpeg.Floorplan.CreateImage();
Image image = TestFile.Create(TestImages.Jpeg.Floorplan).CreateImage();
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity));
image = WriteAndRead(image);
@ -132,7 +132,7 @@ namespace ImageSharp.Tests
{
Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };
Image image = TestImages.Jpeg.Floorplan.CreateImage();
Image image = TestFile.Create(TestImages.Jpeg.Floorplan).CreateImage();
image.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");
ExifValue value = image.ExifProfile.GetValue(ExifTag.Software);
@ -234,7 +234,7 @@ namespace ImageSharp.Tests
private static ExifProfile GetExifProfile()
{
Image image = TestImages.Jpeg.Floorplan.CreateImage();
Image image = TestFile.Create(TestImages.Jpeg.Floorplan).CreateImage();
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);

2
tests/ImageSharp.Tests/Profiles/Exif/ExifValueTests.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Tests
{
private static ExifValue GetExifValue()
{
Image image = TestImages.Jpeg.Floorplan.CreateImage();
Image image = TestFile.Create(TestImages.Jpeg.Floorplan).CreateImage();
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);

30
tests/ImageSharp.Tests/TestFile.cs

@ -2,17 +2,31 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.IO;
namespace ImageSharp.Tests
{
using System.Collections.Concurrent;
using System.IO;
public class TestFile
{
private static readonly ConcurrentDictionary<string, TestFile> cache = new ConcurrentDictionary<string, TestFile>();
private static readonly string FormatsDirectory = GetFormatsDirectory();
private static string GetFormatsDirectory()
{
// Here for code coverage tests.
string directory = "TestImages/Formats/";
if (Directory.Exists(directory))
{
return directory;
}
return "../../../../TestImages/Formats/";
}
private readonly Image image;
private readonly string file;
public TestFile(string file)
private TestFile(string file)
{
this.file = file;
@ -20,6 +34,14 @@ namespace ImageSharp.Tests
this.image = new Image(this.Bytes);
}
public static TestFile Create(string file)
{
return cache.GetOrAdd(file, (string fileName) =>
{
return new TestFile(FormatsDirectory + fileName);
});
}
public byte[] Bytes { get; }
public string FileName

100
tests/ImageSharp.Tests/TestImages.cs

@ -12,68 +12,50 @@ namespace ImageSharp.Tests
/// </summary>
public static class TestImages
{
private static readonly string FormatsDirectory = GetFormatsDirectory();
private static string GetFormatsDirectory()
{
// Here for code coverage tests.
string directory = "TestImages/Formats/";
if (Directory.Exists(directory))
{
return directory;
}
return "../../../../TestImages/Formats/";
}
public static class Png
{
private static readonly string folder = FormatsDirectory + "Png/";
public const string P1 = "Png/pl.png";
public const string Pd = "Png/pd.png";
public const string Blur = "Png/blur.png";
public const string Indexed = "Png/indexed.png";
public const string Splash = "Png/splash.png";
public static TestFile P1 => new TestFile(folder + "pl.png");
public static TestFile Pd => new TestFile(folder + "pd.png");
public static TestFile Blur => new TestFile(folder + "blur.png");
public static TestFile Indexed => new TestFile(folder + "indexed.png");
public static TestFile Splash => new TestFile(folder + "splash.png");
public const string SplashInterlaced = "Png/splash-interlaced.png";
public static TestFile SplashInterlaced => new TestFile(folder + "splash-interlaced.png");
public static TestFile Interlaced => new TestFile(folder + "interlaced.png");
public const string Interlaced = "Png/interlaced.png";
// filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public static TestFile Filter0 => new TestFile(folder + "filter0.png");
public static TestFile Filter1 => new TestFile(folder + "filter1.png");
public static TestFile Filter2 => new TestFile(folder + "filter2.png");
public static TestFile Filter3 => new TestFile(folder + "filter3.png");
public static TestFile Filter4 => new TestFile(folder + "filter4.png");
public const string Filter0 = "Png/filter0.png";
public const string Filter1 = "Png/filter1.png";
public const string Filter2 = "Png/filter2.png";
public const string Filter3 = "Png/filter3.png";
public const string Filter4 = "Png/filter4.png";
// filter changing per scanline
public static TestFile FilterVar => new TestFile(folder + "filterVar.png");
public const string FilterVar = "Png/filterVar.png";
}
public static class Jpeg
{
private static readonly string folder = FormatsDirectory + "Jpg/";
public static TestFile Cmyk => new TestFile(folder + "cmyk.jpg");
public static TestFile Exif => new TestFile(folder + "exif.jpg");
public static TestFile Floorplan => new TestFile(folder + "Floorplan.jpg");
public static TestFile Calliphora => new TestFile(folder + "Calliphora.jpg");
public static TestFile Ycck => new TestFile(folder + "ycck.jpg");
public static TestFile Turtle => new TestFile(folder + "turtle.jpg");
public static TestFile Fb => new TestFile(folder + "fb.jpg");
public static TestFile Progress => new TestFile(folder + "progress.jpg");
public static TestFile GammaDalaiLamaGray => new TestFile(folder + "gamma_dalai_lama_gray.jpg");
public static TestFile Festzug => new TestFile(folder + "Festzug.jpg");
public static TestFile Hiyamugi => new TestFile(folder + "Hiyamugi.jpg");
public static TestFile Jpeg400 => new TestFile(folder + "baseline/jpeg400jfif.jpg");
public static TestFile Jpeg420 => new TestFile(folder + "baseline/jpeg420exif.jpg");
public static TestFile Jpeg422 => new TestFile(folder + "baseline/jpeg422jfif.jpg");
public static TestFile Jpeg444 => new TestFile(folder + "baseline/jpeg444.jpg");
public static readonly TestFile[] All = {
public const string Cmyk = "Jpg/cmyk.jpg";
public const string Exif = "Jpg/exif.jpg";
public const string Floorplan = "Jpg/Floorplan.jpg";
public const string Calliphora = "Jpg/Calliphora.jpg";
public const string Ycck = "Jpg/ycck.jpg";
public const string Turtle = "Jpg/turtle.jpg";
public const string Fb = "Jpg/fb.jpg";
public const string Progress ="Jpg/progress.jpg";
public const string GammaDalaiLamaGray = "Jpg/gamma_dalai_lama_gray.jpg";
public const string Festzug = "Jpg/Festzug.jpg";
public const string Hiyamugi = "Jpg/Hiyamugi.jpg";
public const string Jpeg400 = "Jpg/baseline/jpeg400jfif.jpg";
public const string Jpeg420 = "Jpg/baseline/jpeg420exif.jpg";
public const string Jpeg422 = "Jpg/baseline/jpeg422jfif.jpg";
public const string Jpeg444 = "Jpg/baseline/jpeg444.jpg";
public static readonly string[] All = {
Cmyk, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray,
Festzug, Hiyamugi,
Jpeg400, Jpeg420, Jpeg444,
@ -82,27 +64,23 @@ namespace ImageSharp.Tests
public static class Bmp
{
private static readonly string folder = FormatsDirectory + "Bmp/";
public static TestFile Car => new TestFile(folder + "Car.bmp");
public const string Car = "Bmp/Car.bmp";
public static TestFile F => new TestFile(folder + "F.bmp");
public const string F = "Bmp/F.bmp";
public static TestFile NegHeight => new TestFile(folder + "neg_height.bmp");
public const string NegHeight = "Bmp/neg_height.bmp";
public static readonly TestFile[] All = {
public static readonly string[] All = {
Car, F, NegHeight
};
}
public static class Gif
{
private static readonly string folder = FormatsDirectory + "Gif/";
public static TestFile Rings => new TestFile(folder + "rings.gif");
public static TestFile Giphy => new TestFile(folder + "giphy.gif");
public const string Rings = "Gif/rings.gif";
public const string Giphy = "Gif/giphy.gif";
public static TestFile Cheers => new TestFile(folder + "cheers.gif");
public const string Cheers = "Gif/cheers.gif";
}
}
}

Loading…
Cancel
Save