Browse Source

Changed the test images from string into TestFile.

af/merge-core
Dirk Lemstra 9 years ago
parent
commit
6e0a9b49db
  1. 8
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  2. 2
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs
  3. 50
      tests/ImageSharp.Tests/FileTestBase.cs
  4. 34
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  5. 27
      tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs
  6. 152
      tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs
  7. 12
      tests/ImageSharp.Tests/Profiles/Exif/ExifValueTests.cs
  8. 78
      tests/ImageSharp.Tests/TestImages.cs

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

@ -17,13 +17,7 @@ namespace ImageSharp.Tests
{
string path = CreateOutputDirectory("Drawing", "DrawImage");
Image blend;// = new Image(400, 400);
// blend.BackgroundColor(Color.RebeccaPurple);
using (FileStream stream = File.OpenRead(TestImages.Bmp.Car))
{
blend = new Image(stream);
}
Image blend = 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(Files[2].CreateImage());
var brush = new ImageBrush(TestImages.Bmp.Car.CreateImage());
var image = new Image(500, 500);
using (FileStream output = File.OpenWrite($"{path}/Image.png"))

50
tests/ImageSharp.Tests/FileTestBase.cs

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

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

@ -43,42 +43,36 @@ namespace ImageSharp.Tests.Formats.Jpg
}
public static IEnumerable<object[]> AllJpegFiles
=> TestImages.Jpeg.All.Select(fn => new object[] {fn});
=> TestImages.Jpeg.All.Select(file => new object[] {file});
[Theory]
[MemberData(nameof(AllJpegFiles))]
public void OpenJpeg_SaveBmp(string jpegPath)
public void OpenJpeg_SaveBmp(TestFile file)
{
string bmpFileName = Path.GetFileNameWithoutExtension(jpegPath) + ".bmp";
string bmpFileName = file.FileNameWithoutExtension + ".bmp";
using (var inputStream = File.OpenRead(jpegPath))
{
var image = new Image(inputStream);
var image = file.CreateImage();
using (var outputStream = CreateOutputStream(bmpFileName))
{
image.Save(outputStream, new BmpFormat());
}
using (var outputStream = CreateOutputStream(bmpFileName))
{
image.Save(outputStream, new BmpFormat());
}
}
public static IEnumerable<object[]> AllBmpFiles
=> TestImages.Bmp.All.Select(fn => new object[] {fn});
=> TestImages.Bmp.All.Select(file => new object[] {file});
[Theory]
[MemberData(nameof(AllBmpFiles))]
public void OpenBmp_SaveJpeg(string bmpPath)
public void OpenBmp_SaveJpeg(TestFile file)
{
string jpegPath = Path.GetFileNameWithoutExtension(bmpPath) + ".jpeg";
string jpegPath = file.FileNameWithoutExtension + ".jpeg";
using (var inputStream = File.OpenRead(bmpPath))
{
var image = new Image(inputStream);
var image = file.CreateImage();
using (var outputStream = CreateOutputStream(jpegPath))
{
image.Save(outputStream, new JpegFormat());
}
using (var outputStream = CreateOutputStream(jpegPath))
{
image.Save(outputStream, new JpegFormat());
}
}
}

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

@ -30,25 +30,20 @@ namespace ImageSharp.Tests
{
string path = CreateOutputDirectory("AutoOrient");
string file = TestImages.Bmp.F;
TestFile file = TestImages.Bmp.F;
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + orientation + Path.GetExtension(file);
Image image = new Image(stream);
image.ExifProfile = new ExifProfile();
image.ExifProfile.SetValue(ExifTag.Orientation, orientation);
Image image = file.CreateImage();
image.ExifProfile = new ExifProfile();
image.ExifProfile.SetValue(ExifTag.Orientation, orientation);
using (FileStream before = File.OpenWrite($"{path}/before-{filename}"))
using (FileStream before = File.OpenWrite($"{path}/before-{file.FileName}"))
{
using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}"))
{
using (FileStream after = File.OpenWrite($"{path}/after-{filename}"))
{
image.RotateFlip(rotateType, flipType)
.Save(before)
.AutoOrient()
.Save(after);
}
image.RotateFlip(rotateType, flipType)
.Save(before)
.AutoOrient()
.Save(after);
}
}
}

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

@ -17,23 +17,20 @@ namespace ImageSharp.Tests
[Fact]
public void Constructor()
{
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Calliphora))
{
Image image = new Image(stream);
Image image = TestImages.Jpeg.Calliphora.CreateImage();
Assert.Null(image.ExifProfile);
Assert.Null(image.ExifProfile);
image.ExifProfile = new ExifProfile();
image.ExifProfile.SetValue(ExifTag.Copyright, "Dirk Lemstra");
image.ExifProfile = new ExifProfile();
image.ExifProfile.SetValue(ExifTag.Copyright, "Dirk Lemstra");
image = WriteAndRead(image);
image = WriteAndRead(image);
Assert.NotNull(image.ExifProfile);
Assert.Equal(1, image.ExifProfile.Values.Count());
Assert.NotNull(image.ExifProfile);
Assert.Equal(1, image.ExifProfile.Values.Count());
ExifValue value = image.ExifProfile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
TestValue(value, "Dirk Lemstra");
}
ExifValue value = image.ExifProfile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
TestValue(value, "Dirk Lemstra");
}
[Fact]
@ -107,30 +104,27 @@ namespace ImageSharp.Tests
[Fact]
public void ReadWriteInfinity()
{
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan))
{
Image image = new Image(stream);
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity));
Image image = TestImages.Jpeg.Floorplan.CreateImage();
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity));
image = WriteAndRead(image);
ExifValue value = image.ExifProfile.GetValue(ExifTag.ExposureBiasValue);
Assert.NotNull(value);
Assert.Equal(new SignedRational(double.PositiveInfinity), value.Value);
image = WriteAndRead(image);
ExifValue value = image.ExifProfile.GetValue(ExifTag.ExposureBiasValue);
Assert.NotNull(value);
Assert.Equal(new SignedRational(double.PositiveInfinity), value.Value);
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.NegativeInfinity));
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.NegativeInfinity));
image = WriteAndRead(image);
value = image.ExifProfile.GetValue(ExifTag.ExposureBiasValue);
Assert.NotNull(value);
Assert.Equal(new SignedRational(double.NegativeInfinity), value.Value);
image = WriteAndRead(image);
value = image.ExifProfile.GetValue(ExifTag.ExposureBiasValue);
Assert.NotNull(value);
Assert.Equal(new SignedRational(double.NegativeInfinity), value.Value);
image.ExifProfile.SetValue(ExifTag.FlashEnergy, new Rational(double.NegativeInfinity));
image.ExifProfile.SetValue(ExifTag.FlashEnergy, new Rational(double.NegativeInfinity));
image = WriteAndRead(image);
value = image.ExifProfile.GetValue(ExifTag.FlashEnergy);
Assert.NotNull(value);
Assert.Equal(new Rational(double.PositiveInfinity), value.Value);
}
image = WriteAndRead(image);
value = image.ExifProfile.GetValue(ExifTag.FlashEnergy);
Assert.NotNull(value);
Assert.Equal(new Rational(double.PositiveInfinity), value.Value);
}
[Fact]
@ -138,75 +132,72 @@ namespace ImageSharp.Tests
{
Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan))
{
Image image = new Image(stream);
image.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");
Image image = TestImages.Jpeg.Floorplan.CreateImage();
image.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");
ExifValue value = image.ExifProfile.GetValue(ExifTag.Software);
TestValue(value, "ImageSharp");
ExifValue value = image.ExifProfile.GetValue(ExifTag.Software);
TestValue(value, "ImageSharp");
Assert.Throws<ArgumentException>(() => { value.Value = 15; });
Assert.Throws<ArgumentException>(() => { value.Value = 15; });
image.ExifProfile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));
image.ExifProfile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));
value = image.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
value = image.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
TestValue(value, new SignedRational(7555, 100));
TestValue(value, new SignedRational(7555, 100));
Assert.Throws<ArgumentException>(() => { value.Value = 75; });
Assert.Throws<ArgumentException>(() => { value.Value = 75; });
image.ExifProfile.SetValue(ExifTag.XResolution, new Rational(150.0));
image.ExifProfile.SetValue(ExifTag.XResolution, new Rational(150.0));
value = image.ExifProfile.GetValue(ExifTag.XResolution);
TestValue(value, new Rational(150, 1));
value = image.ExifProfile.GetValue(ExifTag.XResolution);
TestValue(value, new Rational(150, 1));
Assert.Throws<ArgumentException>(() => { value.Value = "ImageSharp"; });
Assert.Throws<ArgumentException>(() => { value.Value = "ImageSharp"; });
image.ExifProfile.SetValue(ExifTag.ReferenceBlackWhite, null);
image.ExifProfile.SetValue(ExifTag.ReferenceBlackWhite, null);
value = image.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
TestValue(value, (string)null);
value = image.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
TestValue(value, (string)null);
image.ExifProfile.SetValue(ExifTag.GPSLatitude, latitude);
image.ExifProfile.SetValue(ExifTag.GPSLatitude, latitude);
value = image.ExifProfile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
value = image.ExifProfile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
image = WriteAndRead(image);
image = WriteAndRead(image);
Assert.NotNull(image.ExifProfile);
Assert.Equal(17, image.ExifProfile.Values.Count());
Assert.NotNull(image.ExifProfile);
Assert.Equal(17, image.ExifProfile.Values.Count());
value = image.ExifProfile.GetValue(ExifTag.Software);
TestValue(value, "ImageSharp");
value = image.ExifProfile.GetValue(ExifTag.Software);
TestValue(value, "ImageSharp");
value = image.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
TestValue(value, new SignedRational(75.55));
value = image.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
TestValue(value, new SignedRational(75.55));
value = image.ExifProfile.GetValue(ExifTag.XResolution);
TestValue(value, new Rational(150.0));
value = image.ExifProfile.GetValue(ExifTag.XResolution);
TestValue(value, new Rational(150.0));
value = image.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
Assert.Null(value);
value = image.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
Assert.Null(value);
value = image.ExifProfile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
value = image.ExifProfile.GetValue(ExifTag.GPSLatitude);
TestValue(value, latitude);
image.ExifProfile.Parts = ExifParts.ExifTags;
image.ExifProfile.Parts = ExifParts.ExifTags;
image = WriteAndRead(image);
image = WriteAndRead(image);
Assert.NotNull(image.ExifProfile);
Assert.Equal(8, image.ExifProfile.Values.Count());
Assert.NotNull(image.ExifProfile);
Assert.Equal(8, image.ExifProfile.Values.Count());
Assert.NotNull(image.ExifProfile.GetValue(ExifTag.ColorSpace));
Assert.True(image.ExifProfile.RemoveValue(ExifTag.ColorSpace));
Assert.False(image.ExifProfile.RemoveValue(ExifTag.ColorSpace));
Assert.Null(image.ExifProfile.GetValue(ExifTag.ColorSpace));
Assert.NotNull(image.ExifProfile.GetValue(ExifTag.ColorSpace));
Assert.True(image.ExifProfile.RemoveValue(ExifTag.ColorSpace));
Assert.False(image.ExifProfile.RemoveValue(ExifTag.ColorSpace));
Assert.Null(image.ExifProfile.GetValue(ExifTag.ColorSpace));
Assert.Equal(7, image.ExifProfile.Values.Count());
}
Assert.Equal(7, image.ExifProfile.Values.Count());
}
[Fact]
@ -241,15 +232,12 @@ namespace ImageSharp.Tests
private static ExifProfile GetExifProfile()
{
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan))
{
Image image = new Image(stream);
Image image = TestImages.Jpeg.Floorplan.CreateImage();
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);
return profile;
}
return profile;
}
private static Image WriteAndRead(Image image)

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

@ -5,7 +5,6 @@
namespace ImageSharp.Tests
{
using System.IO;
using System.Linq;
using Xunit;
@ -13,15 +12,12 @@ namespace ImageSharp.Tests
{
private static ExifValue GetExifValue()
{
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan))
{
Image image = new Image(stream);
Image image = TestImages.Jpeg.Floorplan.CreateImage();
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);
ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile);
return profile.Values.First();
}
return profile.Values.First();
}
[Fact]

78
tests/ImageSharp.Tests/TestImages.cs

@ -14,49 +14,51 @@ namespace ImageSharp.Tests
{
private static readonly string folder = "TestImages/Formats/Png/";
public static string P1 => folder + "pl.png";
public static string Pd => folder + "pd.png";
public static string Blur => folder + "blur.png";
public static string Indexed => folder + "indexed.png";
public static string Splash => folder + "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 static string SplashInterlaced => folder + "splash-interlaced.png";
public static TestFile SplashInterlaced => new TestFile(folder + "splash-interlaced.png");
public static string Interlaced => folder + "interlaced.png";
public static TestFile Interlaced => new TestFile(folder + "interlaced.png");
// filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public static string Filter0 => folder + "filter0.png";
public static string Filter1 => folder + "filter1.png";
public static string Filter2 => folder + "filter2.png";
public static string Filter3 => folder + "filter3.png";
public static string Filter4 => folder + "filter4.png";
// filter changing per scanline
public static string FilterVar => folder + "filterVar.png";
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");
// filter changing per scanline
public static TestFile FilterVar => new TestFile(folder + "filterVar.png");
}
public static class Jpeg
{
private static readonly string folder = "TestImages/Formats/Jpg/";
public static string Cmyk => folder + "cmyk.jpg";
public static string Exif => folder + "exif.jpg";
public static string Floorplan => folder + "Floorplan.jpg";
public static string Calliphora => folder + "Calliphora.jpg";
public static string Ycck => folder + "ycck.jpg";
public static string Turtle => folder + "turtle.jpg";
public static string Fb => folder + "fb.jpg";
public static string Progress => folder + "progress.jpg";
public static string GammaDalaiLamaGray => folder + "gamma_dalai_lama_gray.jpg";
public static string Festzug => folder + "Festzug.jpg";
public static string Hiyamugi => folder + "Hiyamugi.jpg";
public static string Jpeg400 => folder + "baseline/jpeg400jfif.jpg";
public static string Jpeg420 => folder + "baseline/jpeg420exif.jpg";
public static string Jpeg422 => folder + "baseline/jpeg422jfif.jpg";
public static string Jpeg444 => folder + "baseline/jpeg444.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 string[] All = {
public static readonly TestFile[] All = {
Cmyk, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray,
Festzug, Hiyamugi,
Jpeg400, Jpeg420, Jpeg444,
@ -67,13 +69,13 @@ namespace ImageSharp.Tests
{
private static readonly string folder = "TestImages/Formats/Bmp/";
public static string Car => folder + "Car.bmp";
public static TestFile Car => new TestFile(folder + "Car.bmp");
public static string F => folder + "F.bmp";
public static TestFile F => new TestFile(folder + "F.bmp");
public static string NegHeight => folder + "neg_height.bmp";
public static TestFile NegHeight => new TestFile(folder + "neg_height.bmp");
public static readonly string[] All = {
public static readonly TestFile[] All = {
Car, F, NegHeight
};
}
@ -82,8 +84,8 @@ namespace ImageSharp.Tests
{
private static readonly string folder = "TestImages/Formats/Gif/";
public static string Rings => folder + "rings.gif";
public static string Giphy => folder + "giphy.gif";
public static TestFile Rings => new TestFile(folder + "rings.gif");
public static TestFile Giphy => new TestFile(folder + "giphy.gif");
}
}
}

Loading…
Cancel
Save