Browse Source

introducing [GroupOutput] + apply it to all filter tests

af/merge-core
Anton Firszov 8 years ago
parent
commit
c4940aedae
  1. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs
  2. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs
  3. 7
      tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs
  4. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs
  5. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs
  6. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs
  7. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs
  8. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs
  9. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs
  10. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs
  11. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs
  12. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs
  13. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs
  14. 1
      tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs
  15. 17
      tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs
  16. 24
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
  17. 39
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  18. 30
      tests/ImageSharp.Tests/TestUtilities/Tests/GroupOutputTests.cs
  19. 8
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

1
tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class BlackWhiteTest
{
[Theory]

1
tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
[GroupOutput("Filters")]
public class BrightnessTest
{
public static readonly TheoryData<float> BrightnessValues

7
tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs

@ -10,7 +10,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
public class ColorBlindnessTest : FileTestBase
[GroupOutput("Filters")]
public class ColorBlindnessTest
{
public static readonly TheoryData<ColorBlindness> ColorBlindnessFilters
= new TheoryData<ColorBlindness>
@ -26,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
};
[Theory]
[WithTestPatternImages(nameof(ColorBlindnessFilters), 100, 100, DefaultPixelType)]
[WithTestPatternImages(nameof(ColorBlindnessFilters), 48, 48, PixelTypes.Rgba32)]
public void ApplyColorBlindnessFilter<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{
@ -38,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
}
[Theory]
[WithTestPatternImages(nameof(ColorBlindnessFilters), 100, 100, DefaultPixelType)]
[WithTestPatternImages(nameof(ColorBlindnessFilters), 48, 48, PixelTypes.Rgba32)]
public void ApplyColorBlindnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{

1
tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
[GroupOutput("Filters")]
public class ContrastTest
{
public static readonly TheoryData<float> ContrastValues

1
tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs

@ -11,6 +11,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class FilterTest
{
// Testing the generic FilterProcessor with more than one pixel type intentionally.

1
tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs

@ -11,6 +11,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class GrayscaleTest
{
public static readonly TheoryData<GrayscaleMode> GrayscaleModeTypes

1
tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class HueTest
{
public static readonly TheoryData<int> HueValues

1
tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
[GroupOutput("Filters")]
public class InvertTest
{
[Theory]

1
tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class KodachromeTest
{
[Theory]

1
tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class LomographTest
{
[Theory]

1
tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
[GroupOutput("Filters")]
public class OpacityTest
{
public static readonly TheoryData<float> AlphaValues

1
tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class PolaroidTest
{
[Theory]

1
tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class SaturateTest
{
public static readonly TheoryData<float> SaturationValues

1
tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs

@ -9,6 +9,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
[GroupOutput("Filters")]
public class SepiaTest
{
[Theory]

17
tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs

@ -0,0 +1,17 @@
namespace SixLabors.ImageSharp.Tests
{
using System;
/// <summary>
/// The output produced by this test class should be grouped into the specified subfolder.
/// </summary>
public class GroupOutputAttribute : Attribute
{
public GroupOutputAttribute(string subfolder)
{
this.Subfolder = subfolder;
}
public string Subfolder { get; }
}
}

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

@ -11,7 +11,9 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests
{
public interface ITestImageProvider
using Castle.Core.Internal;
public interface ITestImageProvider
{
PixelTypes PixelType { get; }
ImagingTestCaseUtility Utility { get; }
@ -34,6 +36,7 @@ namespace SixLabors.ImageSharp.Tests
public string TypeName { get; private set; }
public string MethodName { get; private set; }
public string OutputSubfolderName { get; private set; }
public static TestImageProvider<TPixel> TestPattern(
int width,
@ -101,8 +104,9 @@ namespace SixLabors.ImageSharp.Tests
PixelTypes pixelType = info.GetValue<PixelTypes>("PixelType");
string typeName = info.GetValue<string>("TypeName");
string methodName = info.GetValue<string>("MethodName");
string outputSubfolderName = info.GetValue<string>("OutputSubfolderName");
this.Init(typeName, methodName, pixelType);
this.Init(typeName, methodName, outputSubfolderName, pixelType);
}
public virtual void Serialize(IXunitSerializationInfo info)
@ -110,9 +114,14 @@ namespace SixLabors.ImageSharp.Tests
info.AddValue("PixelType", this.PixelType);
info.AddValue("TypeName", this.TypeName);
info.AddValue("MethodName", this.MethodName);
info.AddValue("OutputSubfolderName", this.OutputSubfolderName);
}
protected TestImageProvider<TPixel> Init(string typeName, string methodName, PixelTypes pixelTypeOverride)
protected TestImageProvider<TPixel> Init(
string typeName,
string methodName,
string outputSubfolerName,
PixelTypes pixelTypeOverride)
{
if (pixelTypeOverride != PixelTypes.Undefined)
{
@ -120,7 +129,8 @@ namespace SixLabors.ImageSharp.Tests
}
this.TypeName = typeName;
this.MethodName = methodName;
this.OutputSubfolderName = outputSubfolerName;
this.Utility = new ImagingTestCaseUtility
{
SourceFileOrDescription = this.SourceFileOrDescription,
@ -129,7 +139,7 @@ namespace SixLabors.ImageSharp.Tests
if (methodName != null)
{
this.Utility.Init(typeName, methodName);
this.Utility.Init(typeName, methodName, outputSubfolerName);
}
return this;
@ -137,7 +147,9 @@ namespace SixLabors.ImageSharp.Tests
protected TestImageProvider<TPixel> Init(MethodInfo testMethod, PixelTypes pixelTypeOverride)
{
return Init(testMethod?.DeclaringType.Name, testMethod?.Name, pixelTypeOverride);
string subfolder = testMethod?.DeclaringType.GetAttribute<GroupOutputAttribute>()?.Subfolder
?? string.Empty;
return this.Init(testMethod?.DeclaringType.Name, testMethod?.Name, subfolder, pixelTypeOverride);
}
public override string ToString()

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

@ -34,6 +34,8 @@ namespace SixLabors.ImageSharp.Tests
/// </summary>
public string TestGroupName { get; set; } = string.Empty;
public string OutputSubfolderName { get; set; } = string.Empty;
/// <summary>
/// The name of the test case (by default)
/// </summary>
@ -165,41 +167,22 @@ namespace SixLabors.ImageSharp.Tests
);
}
internal void Init(string typeName, string methodName)
internal void Init(string typeName, string methodName, string outputSubfolderName)
{
this.TestGroupName = typeName;
this.TestName = methodName;
this.OutputSubfolderName = outputSubfolderName;
}
internal void Init(MethodInfo method)
{
this.Init(method.DeclaringType.Name, method.Name);
}
//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;
//}
internal string GetTestOutputDir()
{
string testGroupName = Path.GetFileNameWithoutExtension(this.TestGroupName);
if (!string.IsNullOrEmpty(this.OutputSubfolderName))
{
testGroupName = Path.Combine(this.OutputSubfolderName, testGroupName);
}
return TestEnvironment.CreateOutputDirectory(testGroupName);
}

30
tests/ImageSharp.Tests/TestUtilities/Tests/GroupOutputTests.cs

@ -0,0 +1,30 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests
{
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
[GroupOutput("Foo")]
public class GroupOutputTests
{
[Theory]
[WithBlankImages(1, 1, PixelTypes.Rgba32)]
public void OutputSubfolderName_ValueIsTakeFromGroupOutputAttribute<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
Assert.Equal("Foo", provider.Utility.OutputSubfolderName);
}
[Theory]
[WithBlankImages(1,1, PixelTypes.Rgba32)]
public void GetTestOutputDir_ShouldDefineSubfolder<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
string expected = $"{Path.DirectorySeparatorChar}Foo{Path.DirectorySeparatorChar}";
Assert.Contains(expected, provider.Utility.GetTestOutputDir());
}
}
}

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

@ -22,6 +22,14 @@ namespace SixLabors.ImageSharp.Tests
private ITestOutputHelper Output { get; }
[Theory]
[WithBlankImages(1, 1, PixelTypes.Rgba32)]
public void NoOutputSubfolderIsPresentByDefault<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
Assert.Empty(provider.Utility.OutputSubfolderName);
}
[Theory]
[WithBlankImages(42, 666, PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.HalfSingle, "hello")]
public void Use_WithEmptyImageAttribute<TPixel>(TestImageProvider<TPixel> provider, string message)

Loading…
Cancel
Save