From af56af16dad98a568d8a227cbf9694f2750cfa8e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 24 Dec 2017 04:18:44 +0100 Subject: [PATCH] introducing [GroupOutput] + apply it to all filter tests --- .../Processors/Filters/BlackWhiteTest.cs | 1 + .../Processors/Filters/BrightnessTest.cs | 1 + .../Processors/Filters/ColorBlindnessTest.cs | 7 ++-- .../Processors/Filters/ContrastTest.cs | 1 + .../Processors/Filters/FilterTest.cs | 1 + .../Processors/Filters/GrayscaleTest.cs | 1 + .../Processing/Processors/Filters/HueTest.cs | 1 + .../Processors/Filters/InvertTest.cs | 1 + .../Processors/Filters/KodachromeTest.cs | 1 + .../Processors/Filters/LomographTest.cs | 1 + .../Processors/Filters/OpacityTest.cs | 1 + .../Processors/Filters/PolaroidTest.cs | 1 + .../Processors/Filters/SaturateTest.cs | 1 + .../Processors/Filters/SepiaTest.cs | 1 + .../Attributes/GroupOutputAttribute.cs | 17 ++++++++ .../ImageProviders/TestImageProvider.cs | 24 +++++++++--- .../TestUtilities/ImagingTestCaseUtility.cs | 39 ++++++------------- .../TestUtilities/Tests/GroupOutputTests.cs | 30 ++++++++++++++ .../Tests/TestImageProviderTests.cs | 8 ++++ 19 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs create mode 100644 tests/ImageSharp.Tests/TestUtilities/Tests/GroupOutputTests.cs diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs index 2b9620ed5..b0b9aaa49 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs index 00bc60547..eccf27899 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs +++ b/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 BrightnessValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs index 36f4a3140..6c51afd00 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs +++ b/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 ColorBlindnessFilters = new TheoryData @@ -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(TestImageProvider provider, ColorBlindness colorBlindness) where TPixel : struct, IPixel { @@ -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(TestImageProvider provider, ColorBlindness colorBlindness) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs index caa09c579..337b81018 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs +++ b/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 ContrastValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs index 59d888c14..a98153087 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs +++ b/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. diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs index 9e8b9c029..711c8e10a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs +++ b/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 GrayscaleModeTypes diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs index 317dce1c0..98dd95515 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs +++ b/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 HueValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs index cac1e94ed..69df033f0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs index 1ae6fc8ad..6daef29aa 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs index ed16e3e0e..4e54828a6 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs index 4b1345bf0..9ba77b983 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs +++ b/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 AlphaValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs index 2d3cdf6d4..42bd859dc 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs index a7fc332bd..8cfbb198c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs +++ b/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 SaturationValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs index 0cc4a0520..9947d21d0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs +++ b/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] diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs new file mode 100644 index 000000000..b2967058c --- /dev/null +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/GroupOutputAttribute.cs @@ -0,0 +1,17 @@ +namespace SixLabors.ImageSharp.Tests +{ + using System; + + /// + /// The output produced by this test class should be grouped into the specified subfolder. + /// + public class GroupOutputAttribute : Attribute + { + public GroupOutputAttribute(string subfolder) + { + this.Subfolder = subfolder; + } + + public string Subfolder { get; } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 91bbd32ef..1352a2476 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/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 TestPattern( int width, @@ -101,8 +104,9 @@ namespace SixLabors.ImageSharp.Tests PixelTypes pixelType = info.GetValue("PixelType"); string typeName = info.GetValue("TypeName"); string methodName = info.GetValue("MethodName"); + string outputSubfolderName = info.GetValue("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 Init(string typeName, string methodName, PixelTypes pixelTypeOverride) + protected TestImageProvider 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 Init(MethodInfo testMethod, PixelTypes pixelTypeOverride) { - return Init(testMethod?.DeclaringType.Name, testMethod?.Name, pixelTypeOverride); + string subfolder = testMethod?.DeclaringType.GetAttribute()?.Subfolder + ?? string.Empty; + return this.Init(testMethod?.DeclaringType.Name, testMethod?.Name, subfolder, pixelTypeOverride); } public override string ToString() diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 7da0f0696..e7dfe5488 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -34,6 +34,8 @@ namespace SixLabors.ImageSharp.Tests /// public string TestGroupName { get; set; } = string.Empty; + public string OutputSubfolderName { get; set; } = string.Empty; + /// /// The name of the test case (by default) /// @@ -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); } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/GroupOutputTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/GroupOutputTests.cs new file mode 100644 index 000000000..be12678c8 --- /dev/null +++ b/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(TestImageProvider provider) + where TPixel : struct, IPixel + { + Assert.Equal("Foo", provider.Utility.OutputSubfolderName); + } + + [Theory] + [WithBlankImages(1,1, PixelTypes.Rgba32)] + public void GetTestOutputDir_ShouldDefineSubfolder(TestImageProvider provider) + where TPixel : struct, IPixel + { + string expected = $"{Path.DirectorySeparatorChar}Foo{Path.DirectorySeparatorChar}"; + Assert.Contains(expected, provider.Utility.GetTestOutputDir()); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index e3249fae9..f0adeb753 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/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(TestImageProvider provider) + where TPixel : struct, IPixel + { + Assert.Empty(provider.Utility.OutputSubfolderName); + } + [Theory] [WithBlankImages(42, 666, PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.HalfSingle, "hello")] public void Use_WithEmptyImageAttribute(TestImageProvider provider, string message)