Browse Source

renamed TestImageFactory --to--> TestImageProvider

af/merge-core
antonfirsov 10 years ago
parent
commit
c62e12248a
  1. 12
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  2. 12
      tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
  3. 4
      tests/ImageSharp.Tests/TestUtilities/ImageDataAttributeBase.cs
  4. 4
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  5. 4
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  6. 57
      tests/ImageSharp.Tests/TestUtilities/TestImageProvider.cs
  7. 55
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageFactoryTests.cs
  8. 14
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
  9. 6
      tests/ImageSharp.Tests/TestUtilities/WithBlankImageAttribute.cs
  10. 8
      tests/ImageSharp.Tests/TestUtilities/WithFileAttribute.cs
  11. 8
      tests/ImageSharp.Tests/TestUtilities/WithFileCollectionAttribute.cs
  12. 8
      tests/ImageSharp.Tests/TestUtilities/WithMemberFactoryAttribute.cs
  13. 12
      tests/ImageSharp.Tests/TestUtilities/WithSolidFilledImagesAttribute.cs

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

@ -27,12 +27,12 @@ namespace ImageSharp.Tests.Formats.Jpg
[Theory] [Theory]
//[WithFileCollection(nameof(AllJpegFiles), PixelTypes.All)] //[WithFileCollection(nameof(AllJpegFiles), PixelTypes.All)]
[WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.Argb)] [WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.Argb)]
public void OpenJpeg_SaveBmp<TColor>(TestImageFactory<TColor> factory) public void OpenJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = factory.Create(); var image = provider.GetImage();
factory.Utility.SaveTestOutputFile(image, "bmp"); provider.Utility.SaveTestOutputFile(image, "bmp");
} }
@ -41,12 +41,12 @@ namespace ImageSharp.Tests.Formats.Jpg
[Theory] [Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb, JpegSubsample.Ratio420, 75)] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb, JpegSubsample.Ratio444, 75)] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb, JpegSubsample.Ratio444, 75)]
public void OpenBmp_SaveJpeg<TColor>(TestImageFactory<TColor> factory, JpegSubsample subSample, int quality) public void OpenBmp_SaveJpeg<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var image = factory.Create(); var image = provider.GetImage();
var utility = factory.Utility; var utility = provider.Utility;
utility.TestName += "_" + subSample + "_Q" + quality; utility.TestName += "_" + subSample + "_Q" + quality;
using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg"))) using (var outputStream = File.OpenWrite(utility.GetTestOutputFileName("jpg")))

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

@ -46,10 +46,10 @@ namespace ImageSharp.Tests
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.ZYX)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.ZYX)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.XYZW)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.XYZW)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.ZYXW)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.ZYXW)]
public void CopyTo_Then_CopyFrom_OnFullImageRect<TColor>(TestImageFactory<TColor> factory, ComponentOrder order) public void CopyTo_Then_CopyFrom_OnFullImageRect<TColor>(TestImageProvider<TColor> provider, ComponentOrder order)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var src = factory.Create(); var src = provider.GetImage();
var dest = new Image<TColor>(src.Width, src.Height); var dest = new Image<TColor>(src.Width, src.Height);
@ -90,11 +90,11 @@ namespace ImageSharp.Tests
[WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.ZYX)] [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.ZYX)]
[WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.XYZW)] [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.XYZW)]
[WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.ZYXW)] [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.ZYXW)]
public void CopyTo_Then_CopyFrom_WithOffset<TColor>(TestImageFactory<TColor> factory, ComponentOrder order) public void CopyTo_Then_CopyFrom_WithOffset<TColor>(TestImageProvider<TColor> provider, ComponentOrder order)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var srcImage = factory.Create(); var srcImage = provider.GetImage();
var color = default(TColor); var color = default(TColor);
color.PackFromBytes(255, 0, 0, 255); color.PackFromBytes(255, 0, 0, 255);
@ -116,8 +116,8 @@ namespace ImageSharp.Tests
} }
} }
factory.Utility.SourceFileOrDescription = order.ToString(); provider.Utility.SourceFileOrDescription = order.ToString();
factory.Utility.SaveTestOutputFile(destImage, "bmp"); provider.Utility.SaveTestOutputFile(destImage, "bmp");
var expectedImage = new Image<TColor>(8, 8).Fill(color); var expectedImage = new Image<TColor>(8, 8).Fill(color);

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

@ -12,7 +12,7 @@ namespace ImageSharp.Tests.TestUtilities
using Xunit.Sdk; using Xunit.Sdk;
/// <summary> /// <summary>
/// Base class for Theory Data attributes which pass an instance of <see cref="TestImageFactory{TColor,TPacked}"/> to the test cases. /// Base class for Theory Data attributes which pass an instance of <see cref="TestImageProvider{TColor}"/> to the test cases.
/// </summary> /// </summary>
public abstract class ImageDataAttributeBase : DataAttribute public abstract class ImageDataAttributeBase : DataAttribute
{ {
@ -37,7 +37,7 @@ namespace ImageSharp.Tests.TestUtilities
{ {
foreach (var pixelType in this.PixelTypes.ToTypes()) foreach (var pixelType in this.PixelTypes.ToTypes())
{ {
var factoryType = typeof(TestImageFactory<>).MakeGenericType(pixelType); var factoryType = typeof(TestImageProvider<>).MakeGenericType(pixelType);
foreach (object[] originalFacoryMethodArgs in this.GetAllFactoryMethodArgs(testMethod, factoryType)) foreach (object[] originalFacoryMethodArgs in this.GetAllFactoryMethodArgs(testMethod, factoryType))
{ {

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

@ -18,12 +18,12 @@ namespace ImageSharp.Tests.TestUtilities
public class ImagingTestCaseUtility public class ImagingTestCaseUtility
{ {
/// <summary> /// <summary>
/// Name of the TColor in the owner <see cref="TestImageFactory{TColor}"/> /// Name of the TColor in the owner <see cref="TestImageProvider{TColor}"/>
/// </summary> /// </summary>
public string PixelTypeName { get; set; } = string.Empty; public string PixelTypeName { get; set; } = string.Empty;
/// <summary> /// <summary>
/// The name of the file which is provided by <see cref="TestImageFactory{TColor}"/> /// The name of the file which is provided by <see cref="TestImageProvider{TColor}"/>
/// Or a short string describing the image in the case of a non-file based image provider. /// Or a short string describing the image in the case of a non-file based image provider.
/// </summary> /// </summary>
public string SourceFileOrDescription { get; set; } = string.Empty; public string SourceFileOrDescription { get; set; } = string.Empty;

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

@ -8,7 +8,7 @@ namespace ImageSharp.Tests.TestUtilities
/// <summary> /// <summary>
/// Flags that are mapped to PackedPixel types. /// Flags that are mapped to PackedPixel types.
/// They trigger the desired parametrization for <see cref="TestImageFactory{TColor}"/>. /// They trigger the desired parametrization for <see cref="TestImageProvider{TColor}"/>.
/// </summary> /// </summary>
[Flags] [Flags]
public enum PixelTypes : uint public enum PixelTypes : uint
@ -48,7 +48,7 @@ namespace ImageSharp.Tests.TestUtilities
Short2 = 1 << 15, Short2 = 1 << 15,
Short4 = 1 << 16, Short4 = 1 << 16,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper // TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
// "All" is handled as a separate, individual case instead of using bitwise OR // "All" is handled as a separate, individual case instead of using bitwise OR

57
tests/ImageSharp.Tests/TestUtilities/TestImageFactory.cs → tests/ImageSharp.Tests/TestUtilities/TestImageProvider.cs

@ -1,4 +1,4 @@
// <copyright file="TestImageFactory.cs" company="James Jackson-South"> // <copyright file="TestImageProvider.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -13,10 +13,13 @@ namespace ImageSharp.Tests.TestUtilities
/// Provides <see cref="Image{TColor}" /> instances for parametric unit tests. /// Provides <see cref="Image{TColor}" /> instances for parametric unit tests.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format of the image</typeparam> /// <typeparam name="TColor">The pixel format of the image</typeparam>
public abstract class TestImageFactory<TColor> : ITestImageFactory public abstract class TestImageProvider<TColor> : ITestImageFactory
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
public abstract Image<TColor> Create(); /// <summary>
/// Returns an <see cref="Image{TColor}"/> instance to the test case with the necessary traits.
/// </summary>
public abstract Image<TColor> GetImage();
public virtual string SourceFileOrDescription => ""; public virtual string SourceFileOrDescription => "";
@ -25,11 +28,7 @@ namespace ImageSharp.Tests.TestUtilities
/// </summary> /// </summary>
public ImagingTestCaseUtility Utility { get; private set; } public ImagingTestCaseUtility Utility { get; private set; }
protected TestImageFactory() protected virtual TestImageProvider<TColor> InitUtility(MethodInfo testMethod)
{
}
protected virtual TestImageFactory<TColor> InitUtility(MethodInfo testMethod)
{ {
this.Utility = new ImagingTestCaseUtility() this.Utility = new ImagingTestCaseUtility()
{ {
@ -45,13 +44,13 @@ namespace ImageSharp.Tests.TestUtilities
return this; return this;
} }
private class BlankFactory : TestImageFactory<TColor> private class BlankProvider : TestImageProvider<TColor>
{ {
protected int Width { get; } protected int Width { get; }
protected int Height { get; } protected int Height { get; }
public BlankFactory(int width, int height) public BlankProvider(int width, int height)
{ {
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
@ -59,43 +58,43 @@ namespace ImageSharp.Tests.TestUtilities
public override string SourceFileOrDescription => $"Blank{this.Width}x{this.Height}"; public override string SourceFileOrDescription => $"Blank{this.Width}x{this.Height}";
public override Image<TColor> Create() => new Image<TColor>(this.Width, this.Height); public override Image<TColor> GetImage() => new Image<TColor>(this.Width, this.Height);
} }
public static TestImageFactory<TColor> Blank(int width, int height, MethodInfo testMethod = null) public static TestImageProvider<TColor> Blank(int width, int height, MethodInfo testMethod = null)
=> new BlankFactory(width, height).InitUtility(testMethod); => new BlankProvider(width, height).InitUtility(testMethod);
private class LambdaFactory : TestImageFactory<TColor> private class LambdaProvider : TestImageProvider<TColor>
{ {
private readonly Func<Image<TColor>> creator; private readonly Func<Image<TColor>> creator;
public LambdaFactory(Func<Image<TColor>> creator) public LambdaProvider(Func<Image<TColor>> creator)
{ {
this.creator = creator; this.creator = creator;
} }
public override Image<TColor> Create() => this.creator(); public override Image<TColor> GetImage() => this.creator();
} }
public static TestImageFactory<TColor> Lambda( public static TestImageProvider<TColor> Lambda(
Func<Image<TColor>> func, Func<Image<TColor>> func,
MethodInfo testMethod = null) => new LambdaFactory(func).InitUtility(testMethod); MethodInfo testMethod = null) => new LambdaProvider(func).InitUtility(testMethod);
private class FileFactory : TestImageFactory<TColor> private class FileProvider : TestImageProvider<TColor>
{ {
private static ConcurrentDictionary<string, Image<TColor>> cache = private static ConcurrentDictionary<string, Image<TColor>> cache =
new ConcurrentDictionary<string, Image<TColor>>(); new ConcurrentDictionary<string, Image<TColor>>();
private string filePath; private string filePath;
public FileFactory(string filePath) public FileProvider(string filePath)
{ {
this.filePath = filePath; this.filePath = filePath;
} }
public override string SourceFileOrDescription => this.filePath; public override string SourceFileOrDescription => this.filePath;
public override Image<TColor> Create() public override Image<TColor> GetImage()
{ {
var cachedImage = cache.GetOrAdd( var cachedImage = cache.GetOrAdd(
this.filePath, this.filePath,
@ -109,12 +108,12 @@ namespace ImageSharp.Tests.TestUtilities
} }
} }
public static TestImageFactory<TColor> File(string filePath, MethodInfo testMethod = null) public static TestImageProvider<TColor> File(string filePath, MethodInfo testMethod = null)
{ {
return new FileFactory(filePath).InitUtility(testMethod); return new FileProvider(filePath).InitUtility(testMethod);
} }
private class SolidFactory : BlankFactory private class SolidProvider : BlankProvider
{ {
private readonly byte r; private readonly byte r;
@ -124,16 +123,16 @@ namespace ImageSharp.Tests.TestUtilities
private readonly byte a; private readonly byte a;
public override Image<TColor> Create() public override Image<TColor> GetImage()
{ {
var image = base.Create(); var image = base.GetImage();
TColor color = default(TColor); TColor color = default(TColor);
color.PackFromBytes(this.r, this.g, this.b, this.a); color.PackFromBytes(this.r, this.g, this.b, this.a);
return image.Fill(color); return image.Fill(color);
} }
public SolidFactory(int width, int height, byte r, byte g, byte b, byte a) public SolidProvider(int width, int height, byte r, byte g, byte b, byte a)
: base(width, height) : base(width, height)
{ {
this.r = r; this.r = r;
@ -143,7 +142,7 @@ namespace ImageSharp.Tests.TestUtilities
} }
} }
public static TestImageFactory<TColor> Solid( public static TestImageProvider<TColor> Solid(
int width, int width,
int height, int height,
byte r, byte r,
@ -152,7 +151,7 @@ namespace ImageSharp.Tests.TestUtilities
byte a = 255, byte a = 255,
MethodInfo testMethod = null) MethodInfo testMethod = null)
{ {
return new SolidFactory(width, height, r, g, b, a).InitUtility(testMethod); return new SolidProvider(width, height, r, g, b, a).InitUtility(testMethod);
} }
} }

55
tests/ImageSharp.Tests/TestUtilities/TestImageFactoryTests.cs → tests/ImageSharp.Tests/TestUtilities/Tests/TestImageFactoryTests.cs

@ -4,10 +4,9 @@
// </copyright> // </copyright>
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.TestUtilities namespace ImageSharp.Tests.TestUtilities.Tests
{ {
using System; using System;
using System.IO;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -26,11 +25,11 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb | PixelTypes.HalfSingle, "hello")] [WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb | PixelTypes.HalfSingle, "hello")]
public void Use_WithEmptyImageAttribute<TColor>( public void Use_WithEmptyImageAttribute<TColor>(
TestImageFactory<TColor> factory, TestImageProvider<TColor> provider,
string message) string message)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var img = factory.Create(); var img = provider.GetImage();
Assert.Equal(42, img.Width); Assert.Equal(42, img.Width);
Assert.Equal(666, img.Height); Assert.Equal(666, img.Height);
@ -40,11 +39,11 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithBlankImages(42, 666, PixelTypes.All, "hello")] [WithBlankImages(42, 666, PixelTypes.All, "hello")]
public void Use_WithBlankImagesAttribute_WithAllPixelTypes<TColor>( public void Use_WithBlankImagesAttribute_WithAllPixelTypes<TColor>(
TestImageFactory<TColor> factory, TestImageProvider<TColor> provider,
string message) string message)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var img = factory.Create(); var img = provider.GetImage();
Assert.Equal(42, img.Width); Assert.Equal(42, img.Width);
Assert.Equal(666, img.Height); Assert.Equal(666, img.Height);
@ -55,16 +54,16 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)]
[WithFile(TestImages.Bmp.F, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.F, PixelTypes.All, 88)]
public void Use_WithFileAttribute<TColor>(TestImageFactory<TColor> factory, int yo) public void Use_WithFileAttribute<TColor>(TestImageProvider<TColor> provider, int yo)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
Assert.NotNull(factory.Utility.SourceFileOrDescription); Assert.NotNull(provider.Utility.SourceFileOrDescription);
var img = factory.Create(); var img = provider.GetImage();
Assert.True(img.Width * img.Height > 0); Assert.True(img.Width * img.Height > 0);
Assert.Equal(88, yo); Assert.Equal(88, yo);
string fn = factory.Utility.GetTestOutputFileName("jpg"); string fn = provider.Utility.GetTestOutputFileName("jpg");
this.Output.WriteLine(fn); this.Output.WriteLine(fn);
} }
@ -72,20 +71,20 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb)] [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb)]
public void Use_WithFileCollection<TColor>(TestImageFactory<TColor> factory) public void Use_WithFileCollection<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
Assert.NotNull(factory.Utility.SourceFileOrDescription); Assert.NotNull(provider.Utility.SourceFileOrDescription);
var image = factory.Create(); var image = provider.GetImage();
factory.Utility.SaveTestOutputFile(image, "png"); provider.Utility.SaveTestOutputFile(image, "png");
} }
[Theory] [Theory]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb)] [WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb)]
public void Use_WithSolidFilledImagesAttribute<TColor>(TestImageFactory<TColor> factory) public void Use_WithSolidFilledImagesAttribute<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var img = factory.Create(); var img = provider.GetImage();
Assert.Equal(img.Width, 10); Assert.Equal(img.Width, 10);
Assert.Equal(img.Height, 20); Assert.Equal(img.Height, 20);
@ -116,18 +115,18 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithMemberFactory(nameof(TestMemberFactory), PixelTypes.All)] [WithMemberFactory(nameof(TestMemberFactory), PixelTypes.All)]
public void Use_WithMemberFactoryAttribute<TColor>(TestImageFactory<TColor> factory) public void Use_WithMemberFactoryAttribute<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var img = factory.Create(); var img = provider.GetImage();
Assert.Equal(img.Width, 3); Assert.Equal(img.Width, 3);
} }
public static readonly TheoryData<ITestImageFactory> BasicData = new TheoryData<ITestImageFactory>() public static readonly TheoryData<ITestImageFactory> BasicData = new TheoryData<ITestImageFactory>()
{ {
TestImageFactory<Color>.Blank(10, 20), TestImageProvider<Color>.Blank(10, 20),
TestImageFactory<HalfVector4>.Blank( TestImageProvider<HalfVector4>.Blank(
10, 10,
20) 20)
}; };
@ -135,31 +134,31 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[MemberData(nameof(BasicData))] [MemberData(nameof(BasicData))]
public void Blank_MemberData<TColor>(TestImageFactory<TColor> factory) public void Blank_MemberData<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var img = factory.Create(); var img = provider.GetImage();
Assert.True(img.Width * img.Height > 0); Assert.True(img.Width * img.Height > 0);
} }
public static readonly TheoryData<ITestImageFactory> FileData = new TheoryData<ITestImageFactory>() public static readonly TheoryData<ITestImageFactory> FileData = new TheoryData<ITestImageFactory>()
{ {
TestImageFactory<Color>.File( TestImageProvider<Color>.File(
TestImages.Bmp.Car), TestImages.Bmp.Car),
TestImageFactory<HalfVector4>.File( TestImageProvider<HalfVector4>.File(
TestImages.Bmp.F) TestImages.Bmp.F)
}; };
[Theory] [Theory]
[MemberData(nameof(FileData))] [MemberData(nameof(FileData))]
public void File_MemberData<TColor>(TestImageFactory<TColor> factory) public void File_MemberData<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
this.Output.WriteLine("SRC: " + factory.Utility.SourceFileOrDescription); this.Output.WriteLine("SRC: " + provider.Utility.SourceFileOrDescription);
this.Output.WriteLine("OUT: " + factory.Utility.GetTestOutputFileName()); this.Output.WriteLine("OUT: " + provider.Utility.GetTestOutputFileName());
var img = factory.Create(); var img = provider.GetImage();
Assert.True(img.Width * img.Height > 0); Assert.True(img.Width * img.Height > 0);
} }

14
tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensionsTests.cs → tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -4,7 +4,7 @@
// </copyright> // </copyright>
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.TestUtilities namespace ImageSharp.Tests.TestUtilities.Tests
{ {
using System; using System;
using System.Linq; using System.Linq;
@ -68,11 +68,11 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.Color)] [WithFile(TestImages.Bmp.Car, PixelTypes.Color)]
public void IsEquivalentTo_WhenFalse<TColor>(TestImageFactory<TColor> factory) public void IsEquivalentTo_WhenFalse<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var a = factory.Create(); var a = provider.GetImage();
var b = factory.Create(); var b = provider.GetImage();
b = b.OilPaint(3, 2); b = b.OilPaint(3, 2);
Assert.False(a.IsEquivalentTo(b)); Assert.False(a.IsEquivalentTo(b));
@ -80,11 +80,11 @@ namespace ImageSharp.Tests.TestUtilities
[Theory] [Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565)]
public void IsEquivalentTo_WhenTrue<TColor>(TestImageFactory<TColor> factory) public void IsEquivalentTo_WhenTrue<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
var a = factory.Create(); var a = provider.GetImage();
var b = factory.Create(); var b = provider.GetImage();
Assert.True(a.IsEquivalentTo(b)); Assert.True(a.IsEquivalentTo(b));
} }

6
tests/ImageSharp.Tests/TestUtilities/WithBlankImageAttribute.cs

@ -9,13 +9,13 @@ namespace ImageSharp.Tests.TestUtilities
using System.Reflection; using System.Reflection;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which produce a blank image of size width * height. /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which produce a blank image of size width * height.
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
public class WithBlankImagesAttribute : ImageDataAttributeBase public class WithBlankImagesAttribute : ImageDataAttributeBase
{ {
/// <summary> /// <summary>
/// Triggers passing an <see cref="TestImageFactory{TColor}"/> that produces a blank image of size width * height /// Triggers passing an <see cref="TestImageProvider{TColor}"/> that produces a blank image of size width * height
/// </summary> /// </summary>
/// <param name="width">The required width</param> /// <param name="width">The required width</param>
/// <param name="height">The required height</param> /// <param name="height">The required height</param>

8
tests/ImageSharp.Tests/TestUtilities/WithFileAttribute.cs

@ -9,16 +9,16 @@ namespace ImageSharp.Tests.TestUtilities
using System.Reflection; using System.Reflection;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which read an image from the given file /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which read an image from the given file
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
public class WithFileAttribute : ImageDataAttributeBase public class WithFileAttribute : ImageDataAttributeBase
{ {
private readonly string fileName; private readonly string fileName;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which read an image from the given file /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which read an image from the given file
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
/// <param name="fileName">The name of the file</param> /// <param name="fileName">The name of the file</param>
/// <param name="pixelTypes">The requested pixel types</param> /// <param name="pixelTypes">The requested pixel types</param>

8
tests/ImageSharp.Tests/TestUtilities/WithFileCollectionAttribute.cs

@ -10,16 +10,16 @@ namespace ImageSharp.Tests.TestUtilities
using System.Reflection; using System.Reflection;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName
/// <see cref="TestImageFactory{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
public class WithFileCollectionAttribute : ImageDataAttributeBase public class WithFileCollectionAttribute : ImageDataAttributeBase
{ {
private readonly string enumeratorMemberName; private readonly string enumeratorMemberName;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName
/// <see cref="TestImageFactory{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
/// <param name="enumeratorMemberName">The name of the static test class field/property enumerating the files</param> /// <param name="enumeratorMemberName">The name of the static test class field/property enumerating the files</param>
/// <param name="pixelTypes">The requested pixel types</param> /// <param name="pixelTypes">The requested pixel types</param>

8
tests/ImageSharp.Tests/TestUtilities/WithMemberFactoryAttribute.cs

@ -9,16 +9,16 @@ namespace ImageSharp.Tests.TestUtilities
using System.Reflection; using System.Reflection;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which return the image produced by the given test class member method /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which return the image produced by the given test class member method
/// <see cref="TestImageFactory{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
public class WithMemberFactoryAttribute : ImageDataAttributeBase public class WithMemberFactoryAttribute : ImageDataAttributeBase
{ {
private readonly string memberMethodName; private readonly string memberMethodName;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which return the image produced by the given test class member method /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which return the image produced by the given test class member method
/// <see cref="TestImageFactory{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter /// <see cref="TestImageProvider{TColor}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
/// <param name="memberMethodName">The name of the static test class which returns the image</param> /// <param name="memberMethodName">The name of the static test class which returns the image</param>
/// <param name="pixelTypes">The requested pixel types</param> /// <param name="pixelTypes">The requested pixel types</param>

12
tests/ImageSharp.Tests/TestUtilities/WithSolidFilledImagesAttribute.cs

@ -8,14 +8,14 @@ namespace ImageSharp.Tests.TestUtilities
using System.Reflection; using System.Reflection;
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which produce an image of size width * height filled with the requested color. /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which produce an image of size width * height filled with the requested color.
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
public class WithSolidFilledImagesAttribute : WithBlankImagesAttribute public class WithSolidFilledImagesAttribute : WithBlankImagesAttribute
{ {
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which produce an image of size width * height filled with the requested color. /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which produce an image of size width * height filled with the requested color.
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
/// <param name="width">The width of the requested image</param> /// <param name="width">The width of the requested image</param>
/// <param name="height">The height of the requested image</param> /// <param name="height">The height of the requested image</param>
@ -37,8 +37,8 @@ namespace ImageSharp.Tests.TestUtilities
} }
/// <summary> /// <summary>
/// Triggers passing <see cref="TestImageFactory{TColor}"/> instances which produce an image of size width * height filled with the requested color. /// Triggers passing <see cref="TestImageProvider{TColor}"/> instances which produce an image of size width * height filled with the requested color.
/// One <see cref="TestImageFactory{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter /// One <see cref="TestImageProvider{TColor}"/> instance will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary> /// </summary>
/// <param name="width">The width of the requested image</param> /// <param name="width">The width of the requested image</param>
/// <param name="height">The height of the requested image</param> /// <param name="height">The height of the requested image</param>

Loading…
Cancel
Save