Browse Source

Changed the test images from string into TestFile.

af/merge-core
Dirk Lemstra 10 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. 22
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  5. 13
      tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs
  6. 20
      tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs
  7. 6
      tests/ImageSharp.Tests/Profiles/Exif/ExifValueTests.cs
  8. 80
      tests/ImageSharp.Tests/TestImages.cs

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

@ -17,13 +17,7 @@ namespace ImageSharp.Tests
{ {
string path = CreateOutputDirectory("Drawing", "DrawImage"); string path = CreateOutputDirectory("Drawing", "DrawImage");
Image blend;// = new Image(400, 400); Image blend = TestImages.Bmp.Car.CreateImage();
// blend.BackgroundColor(Color.RebeccaPurple);
using (FileStream stream = File.OpenRead(TestImages.Bmp.Car))
{
blend = new Image(stream);
}
foreach (TestFile file in Files) foreach (TestFile file in Files)
{ {

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

@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300) 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); var image = new Image(500, 500);
using (FileStream output = File.OpenWrite($"{path}/Image.png")) using (FileStream output = File.OpenWrite($"{path}/Image.png"))

50
tests/ImageSharp.Tests/FileTestBase.cs

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

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

@ -43,37 +43,32 @@ namespace ImageSharp.Tests.Formats.Jpg
} }
public static IEnumerable<object[]> AllJpegFiles public static IEnumerable<object[]> AllJpegFiles
=> TestImages.Jpeg.All.Select(fn => new object[] {fn}); => TestImages.Jpeg.All.Select(file => new object[] {file});
[Theory] [Theory]
[MemberData(nameof(AllJpegFiles))] [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 = file.CreateImage();
{
var image = new Image(inputStream);
using (var outputStream = CreateOutputStream(bmpFileName)) using (var outputStream = CreateOutputStream(bmpFileName))
{ {
image.Save(outputStream, new BmpFormat()); image.Save(outputStream, new BmpFormat());
} }
} }
}
public static IEnumerable<object[]> AllBmpFiles public static IEnumerable<object[]> AllBmpFiles
=> TestImages.Bmp.All.Select(fn => new object[] {fn}); => TestImages.Bmp.All.Select(file => new object[] {file});
[Theory] [Theory]
[MemberData(nameof(AllBmpFiles))] [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 = file.CreateImage();
{
var image = new Image(inputStream);
using (var outputStream = CreateOutputStream(jpegPath)) using (var outputStream = CreateOutputStream(jpegPath))
{ {
@ -82,4 +77,3 @@ namespace ImageSharp.Tests.Formats.Jpg
} }
} }
} }
}

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

@ -30,19 +30,15 @@ namespace ImageSharp.Tests
{ {
string path = CreateOutputDirectory("AutoOrient"); string path = CreateOutputDirectory("AutoOrient");
string file = TestImages.Bmp.F; TestFile file = TestImages.Bmp.F;
using (FileStream stream = File.OpenRead(file)) Image image = file.CreateImage();
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + orientation + Path.GetExtension(file);
Image image = new Image(stream);
image.ExifProfile = new ExifProfile(); image.ExifProfile = new ExifProfile();
image.ExifProfile.SetValue(ExifTag.Orientation, orientation); 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-{filename}")) using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}"))
{ {
image.RotateFlip(rotateType, flipType) image.RotateFlip(rotateType, flipType)
.Save(before) .Save(before)
@ -53,4 +49,3 @@ namespace ImageSharp.Tests
} }
} }
} }
}

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

@ -17,9 +17,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void Constructor() public void Constructor()
{ {
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Calliphora)) Image image = TestImages.Jpeg.Calliphora.CreateImage();
{
Image image = new Image(stream);
Assert.Null(image.ExifProfile); Assert.Null(image.ExifProfile);
@ -34,7 +32,6 @@ namespace ImageSharp.Tests
ExifValue value = image.ExifProfile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright); ExifValue value = image.ExifProfile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
TestValue(value, "Dirk Lemstra"); TestValue(value, "Dirk Lemstra");
} }
}
[Fact] [Fact]
public void ConstructorEmpty() public void ConstructorEmpty()
@ -107,9 +104,7 @@ namespace ImageSharp.Tests
[Fact] [Fact]
public void ReadWriteInfinity() public void ReadWriteInfinity()
{ {
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan)) Image image = TestImages.Jpeg.Floorplan.CreateImage();
{
Image image = new Image(stream);
image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity)); image.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity));
image = WriteAndRead(image); image = WriteAndRead(image);
@ -131,16 +126,13 @@ namespace ImageSharp.Tests
Assert.NotNull(value); Assert.NotNull(value);
Assert.Equal(new Rational(double.PositiveInfinity), value.Value); Assert.Equal(new Rational(double.PositiveInfinity), value.Value);
} }
}
[Fact] [Fact]
public void SetValue() public void SetValue()
{ {
Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) }; 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 = TestImages.Jpeg.Floorplan.CreateImage();
{
Image image = new Image(stream);
image.ExifProfile.SetValue(ExifTag.Software, "ImageSharp"); image.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");
ExifValue value = image.ExifProfile.GetValue(ExifTag.Software); ExifValue value = image.ExifProfile.GetValue(ExifTag.Software);
@ -207,7 +199,6 @@ namespace ImageSharp.Tests
Assert.Equal(7, image.ExifProfile.Values.Count()); Assert.Equal(7, image.ExifProfile.Values.Count());
} }
}
[Fact] [Fact]
public void Values() public void Values()
@ -241,16 +232,13 @@ namespace ImageSharp.Tests
private static ExifProfile GetExifProfile() private static ExifProfile GetExifProfile()
{ {
using (FileStream stream = File.OpenRead(TestImages.Jpeg.Floorplan)) Image image = TestImages.Jpeg.Floorplan.CreateImage();
{
Image image = new Image(stream);
ExifProfile profile = image.ExifProfile; ExifProfile profile = image.ExifProfile;
Assert.NotNull(profile); Assert.NotNull(profile);
return profile; return profile;
} }
}
private static Image WriteAndRead(Image image) private static Image WriteAndRead(Image image)
{ {

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

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

80
tests/ImageSharp.Tests/TestImages.cs

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

Loading…
Cancel
Save