Browse Source

Merge remote-tracking branch 'origin/antonfirsov/qa-lab' into jpeg-lab

# Conflicts:
#	tests/Images/External
pull/298/head
Anton Firszov 9 years ago
parent
commit
f6904d94b1
  1. 2
      src/ImageSharp/Configuration.cs
  2. 2
      src/ImageSharp/Image/ImageExtensions.cs
  3. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  4. 12
      tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs
  5. 12
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  6. 8
      tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
  7. 3
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  8. 14
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  9. 1
      tests/ImageSharp.Tests/TestImages.cs
  10. 3
      tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs
  11. 36
      tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs
  12. 24
      tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs
  13. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  14. 4
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  15. 2
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs
  16. 13
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs
  17. 8
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs
  18. 12
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
  19. 42
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  20. 4
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs
  21. 6
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs
  22. 58
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  23. 16
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  24. 7
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  25. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs
  26. 24
      tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs
  27. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  28. 10
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
  29. 2
      tests/Images/External
  30. BIN
      tests/Images/Input/Png/SnakeGame.png

2
src/ImageSharp/Configuration.cs

@ -140,7 +140,7 @@ namespace ImageSharp
/// </summary>
/// <param name="extension">The extension to discover</param>
/// <returns>The <see cref="IImageFormat"/> if found otherwise null</returns>
public IImageFormat FindFormatByFileExtensions(string extension)
public IImageFormat FindFormatByFileExtension(string extension)
{
return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
}

2
src/ImageSharp/Image/ImageExtensions.cs

@ -52,7 +52,7 @@ namespace ImageSharp
Guard.NotNullOrEmpty(filePath, nameof(filePath));
string ext = Path.GetExtension(filePath).Trim('.');
IImageFormat format = source.Configuration.FindFormatByFileExtensions(ext);
IImageFormat format = source.Configuration.FindFormatByFileExtension(ext);
if (format == null)
{
var stringBuilder = new StringBuilder();

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

@ -139,8 +139,8 @@ namespace ImageSharp.Tests
image.Save(ms, encoder);
}
}
Image<TPixel> mirror = provider.Factory.CreateImage(data);
Image<TPixel> mirror = Image.Load<TPixel>(data);
mirror.DebugSave(provider, $"_{subsample}_Q{quality}");
}

12
tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs

@ -16,19 +16,19 @@ namespace ImageSharp.Tests
public class JpegUtilsTests : TestBase
{
public static Image<TPixel> CreateTestImage<TPixel>(GenericFactory<TPixel> factory)
public static Image<TPixel> CreateTestImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
Image<TPixel> image = factory.CreateImage(10, 10);
var image = new Image<TPixel>(10, 10);
using (PixelAccessor<TPixel> pixels = image.Lock())
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
Vector4 v = new Vector4(i / 10f, j / 10f, 0, 1);
var v = new Vector4(i / 10f, j / 10f, 0, 1);
TPixel color = default(TPixel);
var color = default(TPixel);
color.PackFromVector4(v);
pixels[i, j] = color;
@ -45,7 +45,7 @@ namespace ImageSharp.Tests
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> src = provider.GetImage())
using (Image<TPixel> dest = provider.Factory.CreateImage(8, 8))
using (Image<TPixel> dest = new Image<TPixel>(8,8))
using (PixelArea<TPixel> area = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))
using (PixelAccessor<TPixel> s = src.Lock())
using (PixelAccessor<TPixel> d = dest.Lock())
@ -68,7 +68,7 @@ namespace ImageSharp.Tests
{
using (Image<TPixel> src = provider.GetImage())
using (PixelArea<TPixel> area = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))
using (Image<TPixel> dest = provider.Factory.CreateImage(8, 8))
using (Image<TPixel> dest = new Image<TPixel>(8, 8))
using (PixelAccessor<TPixel> s = src.Lock())
using (PixelAccessor<TPixel> d = dest.Lock())
{

12
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -12,6 +12,8 @@ using Xunit;
namespace ImageSharp.Tests
{
using ImageSharp.Tests.TestUtilities.ImageComparison;
public class PngDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
@ -19,17 +21,19 @@ namespace ImageSharp.Tests
public static readonly string[] TestFiles =
{
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar,
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, TestImages.Png.Rgb48BppInterlaced
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp,
TestImages.Png.Rgb48BppInterlaced, TestImages.Png.SnakeGame
};
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
public void Decode<TPixel>(TestImageProvider<TPixel> imageProvider)
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(imageProvider);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
}

8
tests/ImageSharp.Tests/Image/PixelAccessorTests.cs

@ -17,20 +17,20 @@ namespace ImageSharp.Tests
/// </summary>
public class PixelAccessorTests
{
public static Image<TPixel> CreateTestImage<TPixel>(GenericFactory<TPixel> factory)
public static Image<TPixel> CreateTestImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
Image<TPixel> image = factory.CreateImage(10, 10);
var image = new Image<TPixel>(10, 10);
using (PixelAccessor<TPixel> pixels = image.Lock())
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
Vector4 v = new Vector4(i, j, 0, 1);
var v = new Vector4(i, j, 0, 1);
v /= 10;
TPixel color = default(TPixel);
var color = default(TPixel);
color.PackFromVector4(v);
pixels[i, j] = color;

3
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -28,4 +28,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="TestUtilities\Factories\" />
</ItemGroup>
</Project>

14
tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs

@ -40,7 +40,8 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.DetectEdges(detector));
image.DebugSave(provider, detector.ToString(), grayscale: true);
image.DebugSave(provider, detector.ToString());
image.CompareToReferenceOutput(provider, detector.ToString());
}
}
@ -52,7 +53,8 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.DetectEdges());
image.DebugSave(provider, grayscale: true);
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -73,16 +75,16 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
public void DetectEdges_InBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = source.Clone())
using (Image<TPixel> image = provider.GetImage())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.DetectEdges(bounds));
image.DebugSave(provider, grayscale: true);
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
// TODO: We don't need this any longer after switching to ReferenceImages
ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds);
//ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -31,6 +31,7 @@ namespace ImageSharp.Tests
public const string Bike = "Png/Bike.png";
public const string BikeGrayscale = "Png/BikeGrayscale.png";
public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png";
public const string SnakeGame = "Png/SnakeGame.png";
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public const string Filter0 = "Png/filter0.png";

3
tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs

@ -39,9 +39,8 @@ namespace ImageSharp.Tests
Type colorType = args.Single();
Type imgType = typeof(Image<>).MakeGenericType(colorType);
Type genericFactoryType = (typeof(GenericFactory<>)).MakeGenericType(colorType);
Type funcType = typeof(Func<,>).MakeGenericType(genericFactoryType, imgType);
Type funcType = typeof(Func<>).MakeGenericType(imgType);
MethodInfo genericMethod = m.MakeGenericMethod(args);

36
tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs

@ -1,36 +0,0 @@
// <copyright file="GenericFactory.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 ImageSharp.PixelFormats;
/// <summary>
/// TODO: Non-generic 'Image' class has been removed. We no longer need the factory pattern here!
///
/// Utility class to create specialized subclasses of generic classes (eg. <see cref="Image"/>)
/// Used as parameter for <see cref="WithMemberFactoryAttribute"/> -based factory methods
/// </summary>
public class GenericFactory<TPixel>
where TPixel : struct, IPixel<TPixel>
{
public virtual Image<TPixel> CreateImage(int width, int height)
{
return new Image<TPixel>(width, height);
}
public virtual Image<TPixel> CreateImage(byte[] bytes)
{
return Image.Load<TPixel>(bytes);
}
public virtual Image<TPixel> CreateImage(Image<TPixel> other)
{
return other.Clone();
}
}
}

24
tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs

@ -1,24 +0,0 @@
// <copyright file="ImageFactory.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 ImageSharp.PixelFormats;
/// <summary>
/// TODO: Non-generic 'Image' class has been removed. We no longer need the factory pattern here!
/// </summary>
public class ImageFactory : GenericFactory<Rgba32>
{
public override Image<Rgba32> CreateImage(byte[] bytes) => Image.Load<Rgba32>(bytes);
public override Image<Rgba32> CreateImage(int width, int height) => new Image<Rgba32>(width, height);
public override Image<Rgba32> CreateImage(Image<Rgba32> other)
{
return other.Clone();
}
}
}

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

@ -10,7 +10,7 @@ namespace ImageSharp.Tests.TestUtilities.ImageComparison
public abstract class ImageComparer
{
public static ImageComparer Exact { get; } = ExactImageComparer.Instance;
public static ImageComparer Exact { get; } = Tolerant(0, 0);
public static ImageComparer Tolerant(
float imageThreshold = TolerantImageComparer.DefaultImageThreshold,

4
tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

@ -66,7 +66,7 @@
for (int x = 0; x < width; x++)
{
int d = GetDifferenceInPixelByteSum(ref aBuffer[x], ref bBuffer[x]);
int d = GetHammingDistanceInRgbaSpace(ref aBuffer[x], ref bBuffer[x]);
if (d > this.PixelThresholdInPixelByteSum)
{
@ -92,7 +92,7 @@
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetDifferenceInPixelByteSum(ref Rgba32 a, ref Rgba32 b)
private static int GetHammingDistanceInRgbaSpace(ref Rgba32 a, ref Rgba32 b)
{
return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A);
}

2
tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs

@ -33,7 +33,7 @@ namespace ImageSharp.Tests
protected int Width { get; private set; }
public override Image<TPixel> GetImage() => this.Factory.CreateImage(this.Width, this.Height);
public override Image<TPixel> GetImage() => new Image<TPixel>(this.Width, this.Height);
public override void Deserialize(IXunitSerializationInfo info)

13
tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

@ -45,17 +45,8 @@ namespace ImageSharp.Tests
public override Image<TPixel> GetImage()
{
Key key = new Key(this.PixelType, this.FilePath);
Image<TPixel> cachedImage = cache.GetOrAdd(
key,
fn =>
{
TestFile testFile = TestFile.Create(this.FilePath);
return Image.Load<TPixel>(testFile.Bytes);
});
return cachedImage.Clone();
IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(this.FilePath);
return this.GetImage(decoder);
}
public override Image<TPixel> GetImage(IImageDecoder decoder)

8
tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs

@ -18,14 +18,14 @@ namespace ImageSharp.Tests
{
private class LambdaProvider : TestImageProvider<TPixel>
{
private readonly Func<GenericFactory<TPixel>, Image<TPixel>> creator;
private readonly Func<Image<TPixel>> factoryFunc;
public LambdaProvider(Func<GenericFactory<TPixel>, Image<TPixel>> creator)
public LambdaProvider(Func<Image<TPixel>> factoryFunc)
{
this.creator = creator;
this.factoryFunc = factoryFunc;
}
public override Image<TPixel> GetImage() => this.creator(this.Factory);
public override Image<TPixel> GetImage() => this.factoryFunc();
}
}
}

12
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs

@ -33,7 +33,6 @@ namespace ImageSharp.Tests
/// </summary>
public ImagingTestCaseUtility Utility { get; private set; }
public GenericFactory<TPixel> Factory { get; private set; } = new GenericFactory<TPixel>();
public string TypeName { get; private set; }
public string MethodName { get; private set; }
@ -60,10 +59,10 @@ namespace ImageSharp.Tests
}
public static TestImageProvider<TPixel> Lambda(
Func<GenericFactory<TPixel>, Image<TPixel>> func,
Func<Image<TPixel>> factoryFunc,
MethodInfo testMethod = null,
PixelTypes pixelTypeOverride = PixelTypes.Undefined)
=> new LambdaProvider(func).Init(testMethod, pixelTypeOverride);
=> new LambdaProvider(factoryFunc).Init(testMethod, pixelTypeOverride);
public static TestImageProvider<TPixel> Solid(
int width,
@ -122,12 +121,7 @@ namespace ImageSharp.Tests
}
this.TypeName = typeName;
this.MethodName = methodName;
if (pixelTypeOverride == PixelTypes.Rgba32)
{
this.Factory = new ImageFactory() as GenericFactory<TPixel>;
}
this.Utility = new ImagingTestCaseUtility
{
SourceFileOrDescription = this.SourceFileOrDescription,

42
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -138,13 +138,11 @@ namespace ImageSharp.Tests
string extension = null,
IImageEncoder encoder = null,
object testOutputDetails = null,
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
string path = this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
string extension1 = Path.GetExtension(path);
encoder = encoder ?? GetImageFormatByExtension(extension1, grayscale);
encoder = encoder ?? TestEnvironment.GetReferenceEncoder(path);
using (FileStream stream = File.OpenWrite(path))
{
@ -173,26 +171,26 @@ namespace ImageSharp.Tests
this.Init(method.DeclaringType.Name, method.Name);
}
private static IImageEncoder GetImageFormatByExtension(string extension, bool grayscale)
{
extension = extension?.TrimStart('.');
var format = Configuration.Default.FindFormatByFileExtensions(extension);
IImageEncoder encoder = Configuration.Default.FindEncoder(format);
PngEncoder pngEncoder = encoder as PngEncoder;
if (pngEncoder != null)
{
pngEncoder = new PngEncoder();
encoder = pngEncoder;
pngEncoder.CompressionLevel = 9;
if (grayscale)
{
pngEncoder.PngColorType = PngColorType.Grayscale;
}
}
//private static IImageEncoder GetEncoderByExtension(string extension, bool grayscale)
//{
// extension = extension?.TrimStart('.');
// var format = Configuration.Default.FindFormatByFileExtension(extension);
// IImageEncoder encoder = Configuration.Default.FindEncoder(format);
// PngEncoder pngEncoder = encoder as PngEncoder;
// if (pngEncoder != null)
// {
// pngEncoder = new PngEncoder();
// encoder = pngEncoder;
// pngEncoder.CompressionLevel = 9;
// if (grayscale)
// {
// pngEncoder.PngColorType = PngColorType.Grayscale;
// }
// }
return encoder;
}
// return encoder;
//}
private string GetTestOutputDir()
{

4
tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceDecoder.cs → tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs

@ -8,9 +8,9 @@ namespace ImageSharp.Tests.TestUtilities.ReferenceCodecs
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class ReferenceDecoder : IImageDecoder
public class SystemDrawingReferenceDecoder : IImageDecoder
{
public static ReferenceDecoder Instance { get; } = new ReferenceDecoder();
public static SystemDrawingReferenceDecoder Instance { get; } = new SystemDrawingReferenceDecoder();
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>

6
tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceEncoder.cs → tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs

@ -9,16 +9,16 @@ namespace ImageSharp.Tests.TestUtilities.ReferenceCodecs
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class ReferenceEncoder : IImageEncoder
public class SystemDrawingReferenceEncoder : IImageEncoder
{
private readonly System.Drawing.Imaging.ImageFormat imageFormat;
public ReferenceEncoder(ImageFormat imageFormat)
public SystemDrawingReferenceEncoder(ImageFormat imageFormat)
{
this.imageFormat = imageFormat;
}
public static ReferenceEncoder Png { get; } = new ReferenceEncoder(System.Drawing.Imaging.ImageFormat.Png);
public static SystemDrawingReferenceEncoder Png { get; } = new SystemDrawingReferenceEncoder(System.Drawing.Imaging.ImageFormat.Png);
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>

58
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -1,12 +1,13 @@
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security;
using ImageSharp.Formats;
using ImageSharp.Tests.TestUtilities.ReferenceCodecs;
public static class TestEnvironment
{
private const string ImageSharpSolutionFileName = "ImageSharp.sln";
@ -26,6 +27,8 @@ namespace ImageSharp.Tests
return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi;
});
private static Lazy<Configuration> configuration = new Lazy<Configuration>(CreateDefaultConfiguration);
// ReSharper disable once InconsistentNaming
/// <summary>
/// Gets a value indicating whether test execution runs on CI.
@ -34,6 +37,24 @@ namespace ImageSharp.Tests
internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value;
internal static Configuration Configuration => configuration.Value;
private static Configuration CreateDefaultConfiguration()
{
var configuration = new Configuration(
new PngConfigurationModule(),
new JpegConfigurationModule(),
new GifConfigurationModule(),
new BmpConfigurationModule()
);
configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance);
configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png);
configuration.AddImageFormatDetector(new PngImageFormatDetector());
return configuration;
}
private static string GetSolutionDirectoryFullPathImpl()
{
string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location;
@ -62,23 +83,48 @@ namespace ImageSharp.Tests
return directory.FullName;
}
/// <summary>
/// Gets the correct full path to the Input Images directory.
/// </summary>
internal static string InputImagesDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath);
internal static string InputImagesDirectoryFullPath =>
Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath);
/// <summary>
/// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.)
/// </summary>
internal static string ActualOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ActualOutputDirectoryRelativePath);
internal static string ActualOutputDirectoryFullPath => Path.Combine(
SolutionDirectoryFullPath,
ActualOutputDirectoryRelativePath);
/// <summary>
/// Gets the correct full path to the Expected Output directory. (To compare the test results to.)
/// </summary>
internal static string ReferenceOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ReferenceOutputDirectoryRelativePath);
internal static string ReferenceOutputDirectoryFullPath => Path.Combine(
SolutionDirectoryFullPath,
ReferenceOutputDirectoryRelativePath);
internal static string GetReferenceOutputFileName(string actualOutputFileName) =>
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput");
internal static IImageDecoder GetReferenceDecoder(string filePath)
{
IImageFormat format = GetImageFormat(filePath);
return Configuration.FindDecoder(format);
}
internal static IImageEncoder GetReferenceEncoder(string filePath)
{
IImageFormat format = GetImageFormat(filePath);
return Configuration.FindEncoder(format);
}
internal static IImageFormat GetImageFormat(string filePath)
{
string extension = Path.GetExtension(filePath).ToLower();
if (extension[0] == '.') extension = extension.Substring(1);
IImageFormat format = Configuration.FindFormatByFileExtension(extension);
return format;
}
}
}

16
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -8,7 +8,9 @@ namespace ImageSharp.Tests
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
using ImageSharp.Tests.TestUtilities.ImageComparison;
using ImageSharp.Tests.TestUtilities.ReferenceCodecs;
@ -30,7 +32,6 @@ namespace ImageSharp.Tests
ITestImageProvider provider,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
@ -44,7 +45,6 @@ namespace ImageSharp.Tests
image,
extension,
testOutputDetails: testOutputDetails,
grayscale: grayscale,
appendPixelTypeToFileName: appendPixelTypeToFileName);
return image;
}
@ -171,9 +171,17 @@ namespace ImageSharp.Tests
var testFile = TestFile.Create(path);
using (var original = Image.Load<TPixel>(testFile.Bytes, ReferenceDecoder.Instance))
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path);
IImageFormat format = TestEnvironment.GetImageFormat(path);
IImageDecoder defaultDecoder = Configuration.Default.FindDecoder(format);
if (referenceDecoder.GetType() == defaultDecoder.GetType())
{
throw new InvalidOperationException($"Can't use CompareToOriginal(): no actual reference decoder registered for {format.Name}");
}
using (var original = Image.Load<TPixel>(testFile.Bytes, referenceDecoder))
{
//original.DebugSave(provider, "__SYSTEMDRAWING__");
comparer.VerifySimilarity(original, image);
}

7
tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs → tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -11,12 +11,13 @@ namespace ImageSharp.Tests
using System.Linq;
using System.Reflection;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for TestUtilities
/// Various utility and extension methods.
/// </summary>
public static class TestUtilityExtensions
public static class TestUtils
{
private static readonly Dictionary<Type, PixelTypes> ClrTypes2PixelTypes = new Dictionary<Type, PixelTypes>();
@ -28,7 +29,7 @@ namespace ImageSharp.Tests
.Except(new[] { PixelTypes.Undefined, PixelTypes.All })
.ToArray();
static TestUtilityExtensions()
static TestUtils()
{
// Add Rgba32 Our default.
Type defaultPixelFormatType = typeof(Rgba32);

4
tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs

@ -52,7 +52,7 @@ namespace ImageSharp.Tests
where TPixel : struct, IPixel<TPixel>
{
string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash);
using (Image<TPixel> image = Image.Load<TPixel>(path, ReferenceDecoder.Instance))
using (Image<TPixel> image = Image.Load<TPixel>(path, SystemDrawingReferenceDecoder.Instance))
{
image.DebugSave(dummyProvider);
}
@ -65,7 +65,7 @@ namespace ImageSharp.Tests
{
using (Image<TPixel> image = provider.GetImage())
{
provider.Utility.SaveTestOutputFile(image, "png", ReferenceEncoder.Png);
provider.Utility.SaveTestOutputFile(image, "png", SystemDrawingReferenceEncoder.Png);
}
}
}

24
tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs

@ -6,8 +6,12 @@
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests
{
using System;
using System.IO;
using ImageSharp.Formats;
using ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
using Xunit.Abstractions;
@ -59,5 +63,25 @@ namespace ImageSharp.Tests
this.Output.WriteLine(expected);
Assert.Contains(TestEnvironment.ReferenceOutputDirectoryFullPath, expected);
}
[Theory]
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))]
[InlineData("lol/Baz.JPG", typeof(JpegEncoder))]
[InlineData("lol/Baz.gif", typeof(GifEncoder))]
public void GetReferenceEncoder_ReturnsCorrectEncoders(string fileName, Type expectedEncoderType)
{
IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName);
Assert.IsType(expectedEncoderType, encoder);
}
[Theory]
[InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))]
[InlineData("lol/Baz.JPG", typeof(JpegDecoder))]
[InlineData("lol/Baz.gif", typeof(GifDecoder))]
public void GetReferenceDecoder_ReturnsCorrectEncoders(string fileName, Type expectedDecoderType)
{
IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName);
Assert.IsType(expectedDecoderType, decoder);
}
}
}

4
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -165,10 +165,10 @@ namespace ImageSharp.Tests
/// <typeparam name="TPixel"></typeparam>
/// <param name="factory"></param>
/// <returns></returns>
public static Image<TPixel> CreateTestImage<TPixel>(GenericFactory<TPixel> factory)
public static Image<TPixel> CreateTestImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
return factory.CreateImage(3, 3);
return new Image<TPixel>(3, 3);
}
[Theory]

10
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -27,10 +27,10 @@ namespace ImageSharp.Tests
private ITestOutputHelper Output { get; }
public static Image<TPixel> CreateTestImage<TPixel>(GenericFactory<TPixel> factory)
public static Image<TPixel> CreateTestImage<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
Image<TPixel> image = factory.CreateImage(10, 10);
var image = new Image<TPixel>(10, 10);
using (PixelAccessor<TPixel> pixels = image.Lock())
{
@ -38,10 +38,10 @@ namespace ImageSharp.Tests
{
for (int j = 0; j < 10; j++)
{
Vector4 v = new Vector4(i, j, 0, 1);
var v = new Vector4(i, j, 0, 1);
v /= 10;
TPixel color = default(TPixel);
var color = default(TPixel);
color.PackFromVector4(v);
pixels[i, j] = color;
@ -147,7 +147,7 @@ namespace ImageSharp.Tests
{
KeyValuePair<PixelTypes, Type>[] expanded = PixelTypes.All.ExpandAllTypes().ToArray();
Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2);
Assert.True(expanded.Length >= TestUtils.GetAllPixelTypes().Length - 2);
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit a91dd59e1cc2abbfa5ff2a8fb5690143343a3434
Subproject commit 5029858a874a7e5127d516f0875b1e9df82d01b6

BIN
tests/Images/Input/Png/SnakeGame.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Loading…
Cancel
Save