Browse Source

build fix + clean up ImageDataAttributeBase code duplication

pull/298/head
Anton Firszov 9 years ago
parent
commit
572db70eb4
  1. 3
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  2. 3
      tests/ImageSharp.Tests/TestFile.cs
  3. 10
      tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
  4. 57
      tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs
  5. 8
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  6. 4
      tests/ImageSharp.Tests/TestUtilities/Integration/ReferenceDecoder.cs
  7. 2
      tests/ImageSharp.Tests/TestUtilities/Integration/ReferencePngEncoder.cs

3
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -56,8 +56,7 @@ namespace ImageSharp.Tests.Formats.Png
// ms.Position = 0;
// using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
// {
ImageComparer.VerifySimilarity(image, img2, 0.03f);
// ImageComparer.CheckSimilarity(image, img2, 0.03f);
// ImageComparer.VerifySimilarity(image, img2, 0.03f);
// }
// }
//}

3
tests/ImageSharp.Tests/TestFile.cs

@ -27,7 +27,8 @@ namespace ImageSharp.Tests
/// <summary>
/// The formats directory, as lazy value
/// </summary>
private static readonly string FormatsDirectory = TestEnvironment.GetInputImagesDirectoryFullPath();
// ReSharper disable once InconsistentNaming
private static readonly Lazy<string> formatsDirectory = new Lazy<string>(TestEnvironment.GetInputImagesDirectoryFullPath);
/// <summary>
/// The image.

10
tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs

@ -54,7 +54,7 @@ namespace ImageSharp.Tests
if (!string.IsNullOrWhiteSpace(this.MemberName))
{
Type type = this.MemberType ?? testMethod.DeclaringType;
Func<object> accessor = this.GetPropertyAccessor(type) ?? this.GetFieldAccessor(type);
Func<object> accessor = this.GetPropertyAccessor(type, this.MemberName) ?? this.GetFieldAccessor(type, this.MemberName);
if (accessor != null)
{
@ -156,12 +156,12 @@ namespace ImageSharp.Tests
/// <summary>
/// Gets the field accessor for the given type.
/// </summary>
Func<object> GetFieldAccessor(Type type)
protected Func<object> GetFieldAccessor(Type type, string memberName)
{
FieldInfo fieldInfo = null;
for (Type reflectionType = type; reflectionType != null; reflectionType = reflectionType.GetTypeInfo().BaseType)
{
fieldInfo = reflectionType.GetRuntimeField(this.MemberName);
fieldInfo = reflectionType.GetRuntimeField(memberName);
if (fieldInfo != null)
break;
}
@ -175,12 +175,12 @@ namespace ImageSharp.Tests
/// <summary>
/// Gets the property accessor for the given type.
/// </summary>
Func<object> GetPropertyAccessor(Type type)
protected Func<object> GetPropertyAccessor(Type type, string memberName)
{
PropertyInfo propInfo = null;
for (Type reflectionType = type; reflectionType != null; reflectionType = reflectionType.GetTypeInfo().BaseType)
{
propInfo = reflectionType.GetRuntimeProperty(this.MemberName);
propInfo = reflectionType.GetRuntimeProperty(memberName);
if (propInfo != null)
{
break;

57
tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs

@ -38,18 +38,18 @@ namespace ImageSharp.Tests
/// Triggers passing <see cref="TestImageProvider{TPixel}"/> instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName
/// <see cref="TestImageProvider{TPixel}"/> instances will be passed for each the pixel format defined by the pixelTypes parameter
/// </summary>
/// <param name="enumeratorMemberName">The name of the static test class field/property enumerating the files</param>
/// <param name="fileEnumeratorMemberName">The name of the static test class field/property enumerating the files</param>
/// <param name="memberName">The member name for enumerating method parameters</param>
/// <param name="pixelTypes">The requested pixel types</param>
/// <param name="additionalParameters">Additional theory parameter values</param>
public WithFileCollectionAttribute(
string enumeratorMemberName,
string fileEnumeratorMemberName,
string memberName,
PixelTypes pixelTypes,
params object[] additionalParameters)
: base(memberName, pixelTypes, additionalParameters)
{
this.fileEnumeratorMemberName = enumeratorMemberName;
this.fileEnumeratorMemberName = fileEnumeratorMemberName;
}
/// <summary>
@ -60,8 +60,8 @@ namespace ImageSharp.Tests
/// <returns>The <see cref="IEnumerable{T}"/></returns>
protected override IEnumerable<object[]> GetAllFactoryMethodArgs(MethodInfo testMethod, Type factoryType)
{
Func<object> accessor = this.GetPropertyAccessor(testMethod.DeclaringType);
accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType);
Func<object> accessor = this.GetPropertyAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName);
accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName);
var files = (IEnumerable<string>)accessor();
return files.Select(f => new object[] { f });
@ -69,52 +69,5 @@ namespace ImageSharp.Tests
/// <inheritdoc/>
protected override string GetFactoryMethodName(MethodInfo testMethod) => "File";
/// <summary>
/// Gets the field accessor for the given type.
/// </summary>
private Func<object> GetFieldAccessor(Type type)
{
FieldInfo fieldInfo = null;
for (Type reflectionType = type;
reflectionType != null;
reflectionType = reflectionType.GetTypeInfo().BaseType)
{
fieldInfo = reflectionType.GetRuntimeField(this.fileEnumeratorMemberName);
if (fieldInfo != null)
{
break;
}
}
if (fieldInfo == null || !fieldInfo.IsStatic)
{
return null;
}
return () => fieldInfo.GetValue(null);
}
/// <summary>
/// Gets the property accessor for the given type.
/// </summary>
private Func<object> GetPropertyAccessor(Type type)
{
PropertyInfo propInfo = null;
for (Type reflectionType = type;
reflectionType != null;
reflectionType = reflectionType.GetTypeInfo().BaseType)
{
propInfo = reflectionType.GetRuntimeProperty(this.fileEnumeratorMemberName);
if (propInfo != null) break;
}
if (propInfo?.GetMethod == null || !propInfo.GetMethod.IsStatic)
{
return null;
}
return () => propInfo.GetValue(null, null);
}
}
}

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

@ -127,20 +127,16 @@ namespace ImageSharp.Tests
/// <param name="image">The image instance</param>
/// <param name="extension">The requested extension</param>
/// <param name="encoder">Optional encoder</param>
/// <param name="options">Optional encoder options</param>
public void SaveTestOutputFile<TPixel>(
Image<TPixel> image,
string extension = null,
IImageEncoder encoder = null,
IEncoderOptions options = null,
object settings = null)
where TPixel : struct, IPixel<TPixel>
{
string path = this.GetTestOutputFileName(extension: extension, settings: settings);
string extension1 = Path.GetExtension(path);
encoder = encoder ?? GetImageFormatByExtension(extension);
IImageFormat format = GetImageFormatByExtension(extension1);
encoder = encoder ?? GetImageFormatByExtension(extension1);
using (FileStream stream = File.OpenWrite(path))
{
@ -172,7 +168,7 @@ namespace ImageSharp.Tests
private string GetTestOutputDir()
{
string testGroupName = Path.GetFileNameWithoutExtension(this.TestGroupName);
return CreateOutputDirectory(testGroupName);
return this.CreateOutputDirectory(testGroupName);
}
}
}

4
tests/ImageSharp.Tests/TestUtilities/Integration/ReferenceDecoder.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Tests.TestUtilities.Integration
{
public static ReferenceDecoder Instance { get; } = new ReferenceDecoder();
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
@ -32,8 +32,6 @@ namespace ImageSharp.Tests.TestUtilities.Integration
}
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(convertedBitmap);
}
}
}
}

2
tests/ImageSharp.Tests/TestUtilities/Integration/ReferencePngEncoder.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Tests.TestUtilities.Integration
{
public static ReferencePngEncoder Instance { get; } = new ReferencePngEncoder();
public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
using (System.Drawing.Bitmap sdBitmap = IntegrationTestUtils.ToSystemDrawingBitmap(image))

Loading…
Cancel
Save