diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs
index e0e84dbda..0dbf13299 100644
--- a/tests/ImageSharp.Tests/FileTestBase.cs
+++ b/tests/ImageSharp.Tests/FileTestBase.cs
@@ -6,12 +6,11 @@
namespace ImageSharp.Tests
{
using System.Collections.Generic;
- using System.IO;
///
/// The test base class for reading and writing to files.
///
- public abstract class FileTestBase
+ public abstract class FileTestBase : TestBase
{
///
/// The collection of image files to test against.
@@ -45,26 +44,5 @@ namespace ImageSharp.Tests
// TestFile.Create(TestImages.Gif.Cheers),
// TestFile.Create(TestImages.Gif.Giphy) // Perf: Enable for local testing only
};
-
- // TODO: Find a better place for this
- internal const string TestOutputRoot = "TestOutput/";
-
- protected string CreateOutputDirectory(string path, params string[] pathParts)
- {
- var postFix = "";
- if (pathParts != null && pathParts.Length > 0)
- {
- postFix = "/" + string.Join("/", pathParts);
- }
-
- path = TestOutputRoot + path + postFix;
-
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
-
- return path;
- }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
index 85bc18d11..11d535fb8 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
@@ -21,9 +21,7 @@ namespace ImageSharp.Tests
}
public static IEnumerable AllJpegFiles => TestImages.Jpeg.All;
- // TODO: Turned off PixelTypes.All to be CI-friendly, what should be the practice?
[Theory]
- //[WithFileCollection(nameof(AllJpegFiles), PixelTypes.All)]
[WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
public void OpenJpeg_SaveBmp(TestImageProvider provider)
where TColor : struct, IPackedPixel, IEquatable
diff --git a/tests/ImageSharp.Tests/TestBase.cs b/tests/ImageSharp.Tests/TestBase.cs
new file mode 100644
index 000000000..91c7adef1
--- /dev/null
+++ b/tests/ImageSharp.Tests/TestBase.cs
@@ -0,0 +1,32 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Tests
+{
+ using System.IO;
+
+ ///
+ /// The test base class.
+ ///
+ public abstract class TestBase
+ {
+ protected string CreateOutputDirectory(string path, params string[] pathParts)
+ {
+ path = Path.Combine("TestOutput", path);
+
+ if (pathParts != null && pathParts.Length > 0)
+ {
+ path = Path.Combine(path, Path.Combine(pathParts));
+ }
+
+ if (!Directory.Exists(path))
+ {
+ Directory.CreateDirectory(path);
+ }
+
+ return path;
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageDataAttributeBase.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
similarity index 95%
rename from tests/ImageSharp.Tests/TestUtilities/ImageDataAttributeBase.cs
rename to tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
index 18600085d..4d18da025 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageDataAttributeBase.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
@@ -2,11 +2,11 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
+
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
- using System.Diagnostics;
using System.Linq;
using System.Reflection;
@@ -29,8 +29,8 @@ namespace ImageSharp.Tests
public override IEnumerable
public abstract Image GetImage();
-
+
protected TestImageProvider Init(MethodInfo testMethod, PixelTypes pixelTypeOverride)
{
if (pixelTypeOverride != PixelTypes.Undefined)
@@ -75,10 +74,9 @@ namespace ImageSharp.Tests
if (pixelTypeOverride == PixelTypes.StandardImageClass)
{
- this.Factory = new DefaultImageClassSpecificFactory() as GenericFactory;
+ this.Factory = new ImageFactory() as GenericFactory;
}
-
this.Utility = new ImagingTestCaseUtility()
{
SourceFileOrDescription = this.SourceFileOrDescription,
@@ -92,101 +90,5 @@ namespace ImageSharp.Tests
return this;
}
-
- private class BlankProvider : TestImageProvider
- {
- public BlankProvider(int width, int height)
- {
- this.Width = width;
- this.Height = height;
- }
-
- public override string SourceFileOrDescription => $"Blank{this.Width}x{this.Height}";
-
- protected int Height { get; }
-
- protected int Width { get; }
-
- public override Image GetImage() => this.Factory.CreateImage(this.Width, this.Height);
- }
-
- private class FileProvider : TestImageProvider
- {
- private static ConcurrentDictionary> cache =
- new ConcurrentDictionary>();
-
- private string filePath;
-
- public FileProvider(string filePath)
- {
- this.filePath = filePath;
- }
-
- public override string SourceFileOrDescription => this.filePath;
-
- public override Image GetImage()
- {
- var cachedImage = cache.GetOrAdd(
- this.filePath,
- fn =>
- {
- var testFile = TestFile.Create(this.filePath);
- return this.Factory.CreateImage(testFile.Bytes);
- });
-
- return new Image(cachedImage);
- }
- }
-
- private class LambdaProvider : TestImageProvider
- {
- private readonly Func, Image> creator;
-
- public LambdaProvider(Func, Image> creator)
- {
- this.creator = creator;
- }
-
- public override Image GetImage() => this.creator(this.Factory);
- }
-
- private class SolidProvider : BlankProvider
- {
- private readonly byte a;
-
- private readonly byte b;
-
- private readonly byte g;
-
- private readonly byte r;
-
- public SolidProvider(int width, int height, byte r, byte g, byte b, byte a)
- : base(width, height)
- {
- this.r = r;
- this.g = g;
- this.b = b;
- this.a = a;
- }
-
- public override string SourceFileOrDescription
- => $"Solid{this.Width}x{this.Height}_({this.r},{this.g},{this.b},{this.a})";
-
- public override Image GetImage()
- {
- var image = base.GetImage();
- TColor color = default(TColor);
- color.PackFromBytes(this.r, this.g, this.b, this.a);
-
- return image.Fill(color);
- }
- }
- }
-
- ///
- /// Marker
- ///
- public interface ITestImageFactory
- {
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
index e2b885034..ad8cfe157 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
@@ -2,6 +2,7 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
+
namespace ImageSharp.Tests
{
using System;
@@ -15,7 +16,7 @@ namespace ImageSharp.Tests
/// Utility class to provide information about the test image & the test case for the test code,
/// and help managing IO.
///
- public class ImagingTestCaseUtility
+ public class ImagingTestCaseUtility : TestBase
{
///
/// Name of the TColor in the owner
@@ -38,20 +39,6 @@ namespace ImageSharp.Tests
///
public string TestName { get; set; } = string.Empty;
- ///
- /// Root directory for output images
- ///
- public string TestOutputRoot { get; set; } = FileTestBase.TestOutputRoot;
-
- public string GetTestOutputDir()
- {
- string testGroupName = Path.GetFileNameWithoutExtension(this.TestGroupName);
-
- string dir = $@"{this.TestOutputRoot}{testGroupName}";
- Directory.CreateDirectory(dir);
- return dir;
- }
-
///
/// Gets the recommended file name for the output of the test
///
@@ -81,12 +68,6 @@ namespace ImageSharp.Tests
return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{extension}";
}
- private static IImageFormat GetImageFormatByExtension(string extension)
- {
- extension = extension.ToLower();
- return Bootstrapper.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
- }
-
///
/// Encodes image by the format matching the required extension, than saves it to the recommended output file.
///
@@ -111,5 +92,18 @@ namespace ImageSharp.Tests
this.TestGroupName = method.DeclaringType.Name;
this.TestName = method.Name;
}
+
+ private static IImageFormat GetImageFormatByExtension(string extension)
+ {
+ extension = extension.ToLower();
+ return Bootstrapper.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
+ }
+
+ private string GetTestOutputDir()
+ {
+ string testGroupName = Path.GetFileNameWithoutExtension(this.TestGroupName);
+
+ return CreateOutputDirectory(testGroupName);
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
index dd1460678..547efaa6f 100644
--- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
@@ -2,12 +2,13 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
+
namespace ImageSharp.Tests
{
using System;
///
- /// Flags that are mapped to PackedPixel types.
+ /// Flags that are mapped to PackedPixel types.
/// They trigger the desired parametrization for .
///
[Flags]
diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
index a4e0a959a..bb517dda9 100644
--- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
@@ -22,8 +22,7 @@ namespace ImageSharp.Tests
private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary();
- private static readonly PixelTypes[] AllConcretePixelTypes = FlagsHelper
- .GetSortedValues()
+ private static readonly PixelTypes[] AllConcretePixelTypes = EnumHelper.GetSortedValues()
.Except(new [] {PixelTypes.Undefined, PixelTypes.All })
.ToArray();
@@ -33,13 +32,15 @@ namespace ImageSharp.Tests
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color).Name.Length - 1);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass))
{
- string typeName = $"{nameSpace}.{FlagsHelper.ToString(pt)}";
+ string typeName = $"{nameSpace}.{pt.ToString()}";
var t = ImageSharpAssembly.GetType(typeName);
- if (t != null)
+ if (t == null)
{
- PixelTypes2ClrTypes[pt] = t;
- ClrTypes2PixelTypes[t] = pt;
+ throw new InvalidOperationException($"Could not find: {typeName}");
}
+
+ PixelTypes2ClrTypes[pt] = t;
+ ClrTypes2PixelTypes[t] = pt;
}
PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color);
}
diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
index 974fe35cc..28e5ad2c2 100644
--- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
@@ -3,8 +3,6 @@
// Licensed under the Apache License, Version 2.0.
//
-// ReSharper disable InconsistentNaming
-
namespace ImageSharp.Tests
{
using System;
@@ -68,7 +66,6 @@ namespace ImageSharp.Tests
Assert.IsType(img);
}
- // TODO: @dlemstra this works only with constant strings!
[Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)]
[WithFile(TestImages.Bmp.F, PixelTypes.All, 88)]
@@ -151,7 +148,7 @@ namespace ImageSharp.Tests
}
- public static readonly TheoryData BasicData = new TheoryData()
+ public static readonly TheoryData