Browse Source

Merge remote-tracking branch 'origin/antonfirsov/qa-lab' into jpeg-lab

# Conflicts:
#	tests/Images/External
af/merge-core
Anton Firszov 9 years ago
parent
commit
8f0340a831
  1. 3
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 28
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  3. 82
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  4. 35
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  5. 13
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageExtensionsTests.cs
  6. 2
      tests/Images/External

3
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -37,7 +37,8 @@ namespace ImageSharp.Tests
{
using (Image<TPixel> image = provider.GetImage())
{
image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer);
image.DebugSave(provider);
image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer, appendPixelTypeToFileName: false);
}
}

28
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -16,7 +16,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
public class ResizeTests : FileTestBase
{
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial };
public static readonly TheoryData<string, IResampler> AllReSamplers =
new TheoryData<string, IResampler>
{
@ -47,6 +47,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
SizeF newSize = image.Size() * ratio;
image.Mutate(x => x.Resize((Size)newSize, sampler, false));
string details = $"{name}-{ratio}";
image.DebugSave(provider, details);
image.CompareToReferenceOutput(provider, details);
}
}
@ -59,6 +61,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Size() / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -71,6 +75,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -100,6 +106,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Resize(image.Width, image.Height, new BicubicResampler(), sourceRectangle, destRectangle, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -112,6 +120,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Width / 3, 0, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -124,6 +134,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(0, image.Height / 3, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -141,6 +153,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -158,6 +172,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -176,6 +192,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -194,6 +212,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -212,6 +232,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -230,6 +252,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
@ -248,6 +272,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}

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

@ -23,100 +23,106 @@ namespace ImageSharp.Tests
/// <summary>
/// Name of the TPixel in the owner <see cref="TestImageProvider{TPixel}"/>
/// </summary>
public string PixelTypeName { get; set; } = String.Empty;
public string PixelTypeName { get; set; } = string.Empty;
/// <summary>
/// The name of the file which is provided by <see cref="TestImageProvider{TPixel}"/>
/// Or a short string describing the image in the case of a non-file based image provider.
/// </summary>
public string SourceFileOrDescription { get; set; } = String.Empty;
public string SourceFileOrDescription { get; set; } = string.Empty;
/// <summary>
/// By default this is the name of the test class, but it's possible to change it
/// </summary>
public string TestGroupName { get; set; } = String.Empty;
public string TestGroupName { get; set; } = string.Empty;
/// <summary>
/// The name of the test case (by default)
/// </summary>
public string TestName { get; set; } = String.Empty;
public string TestName { get; set; } = string.Empty;
private string GetTestOutputFileNameImpl(string extension, string tag)
private string GetTestOutputFileNameImpl(string extension, string details, bool appendPixelTypeToFileName)
{
string fn = String.Empty;
string fn = string.Empty;
if (String.IsNullOrWhiteSpace(extension))
if (string.IsNullOrWhiteSpace(extension))
{
extension = null;
}
fn = Path.GetFileNameWithoutExtension(this.SourceFileOrDescription);
if (String.IsNullOrWhiteSpace(extension))
if (string.IsNullOrWhiteSpace(extension))
{
extension = Path.GetExtension(this.SourceFileOrDescription);
}
if (String.IsNullOrWhiteSpace(extension))
if (string.IsNullOrWhiteSpace(extension))
{
extension = ".bmp";
}
extension = extension.ToLower();
if (extension[0] != '.')
{
extension = '.' + extension;
}
if (fn != String.Empty) fn = '_' + fn;
if (fn != string.Empty) fn = '_' + fn;
string pixName = "";
string pixName = this.PixelTypeName;
if (pixName != String.Empty)
if (appendPixelTypeToFileName)
{
pixName = '_' + pixName;
pixName = this.PixelTypeName;
if (pixName != string.Empty)
{
pixName = '_' + pixName;
}
}
tag = tag ?? String.Empty;
if (tag != String.Empty)
details = details ?? string.Empty;
if (details != string.Empty)
{
tag = '_' + tag;
details = '_' + details;
}
return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{tag}{extension}";
return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}";
}
/// <summary>
/// Gets the recommended file name for the output of the test
/// </summary>
/// <param name="extension">The required extension</param>
/// <param name="settings">The settings modifying the output path</param>
/// <param name="testOutputDetails">The settings modifying the output path</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to output file name.</param>
/// <returns>The file test name</returns>
public string GetTestOutputFileName(string extension = null, object settings = null)
public string GetTestOutputFileName(string extension = null, object testOutputDetails = null, bool appendPixelTypeToFileName = true)
{
string tag = null;
string s = settings as string;
string detailsString = null;
string s = testOutputDetails as string;
if (s != null)
{
tag = s;
detailsString = s;
}
else if (settings != null)
else if (testOutputDetails != null)
{
Type type = settings.GetType();
Type type = testOutputDetails.GetType();
TypeInfo info = type.GetTypeInfo();
if (info.IsPrimitive || info.IsEnum || type == typeof(decimal))
{
tag = settings.ToString();
detailsString = testOutputDetails.ToString();
}
else
{
IEnumerable<PropertyInfo> properties = settings.GetType().GetRuntimeProperties();
IEnumerable<PropertyInfo> properties = testOutputDetails.GetType().GetRuntimeProperties();
tag = String.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(settings)).Select(x => $"{x.Key}-{x.Value}"));
detailsString = String.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(testOutputDetails)).Select(x => $"{x.Key}-{x.Value}"));
}
}
return this.GetTestOutputFileNameImpl(extension, tag);
return this.GetTestOutputFileNameImpl(extension, detailsString, appendPixelTypeToFileName);
}
@ -132,10 +138,11 @@ namespace ImageSharp.Tests
string extension = null,
IImageEncoder encoder = null,
object testOutputDetails = null,
bool grayscale = false)
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
string path = this.GetTestOutputFileName(extension: extension, settings: testOutputDetails);
string path = this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
string extension1 = Path.GetExtension(path);
encoder = encoder ?? GetImageFormatByExtension(extension1, grayscale);
@ -145,8 +152,15 @@ namespace ImageSharp.Tests
}
}
internal string GetReferenceOutputFileName(string extension = null, object settings = null) =>
TestEnvironment.GetReferenceOutputFileName(this.GetTestOutputFileName(extension, settings));
internal string GetReferenceOutputFileName(
string extension,
object settings,
bool appendPixelTypeToFileName)
{
return TestEnvironment.GetReferenceOutputFileName(
this.GetTestOutputFileName(extension, settings, appendPixelTypeToFileName)
);
}
internal void Init(string typeName, string methodName)
{

35
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -22,13 +22,15 @@ namespace ImageSharp.Tests
/// <param name="provider">The image provider</param>
/// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
/// <param name="extension">The extension</param>
/// /// <param name="grayscale">A boolean indicating whether we should save a smaller in size.</param>
/// <param name="grayscale">A boolean indicating whether we should save a smaller in size.</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
public static Image<TPixel> DebugSave<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false)
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI)
@ -41,7 +43,8 @@ namespace ImageSharp.Tests
image,
extension,
testOutputDetails: testOutputDetails,
grayscale: grayscale);
grayscale: grayscale,
appendPixelTypeToFileName: appendPixelTypeToFileName);
return image;
}
@ -52,17 +55,18 @@ namespace ImageSharp.Tests
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="image">The image</param>
/// <param name="provider">The image provider</param>
/// <param name="comparer">The <see cref="ImageComparer"/> to use</param>
/// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
/// <param name="extension">The extension</param>
/// <param name="grayscale">A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size.</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false)
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
return CompareToReferenceOutput(
@ -71,7 +75,8 @@ namespace ImageSharp.Tests
ImageComparer.Tolerant(),
testOutputDetails,
extension,
grayscale);
grayscale,
appendPixelTypeToFileName);
}
/// <summary>
@ -85,6 +90,7 @@ namespace ImageSharp.Tests
/// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
/// <param name="extension">The extension</param>
/// <param name="grayscale">A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size.</param>
/// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the output file name.</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
@ -92,21 +98,12 @@ namespace ImageSharp.Tests
ImageComparer comparer,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false)
bool grayscale = false,
bool appendPixelTypeToFileName = true)
where TPixel : struct, IPixel<TPixel>
{
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails);
extension = extension.ToLower();
if (!TestEnvironment.RunsOnCI)
{
provider.Utility.SaveTestOutputFile(
image,
extension,
testOutputDetails: testOutputDetails,
grayscale: grayscale);
}
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
if (!File.Exists(referenceOutputFile))
{
throw new Exception("Reference output file missing: " + referenceOutputFile);

13
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageExtensionsTests.cs

@ -36,6 +36,19 @@ namespace ImageSharp.Tests
}
}
[Theory]
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
public void CompareToReferenceOutput_DoNotAppendPixelType<TPixel>(
TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.DebugSave(provider, appendPixelTypeToFileName: false);
image.CompareToReferenceOutput(provider, appendPixelTypeToFileName: false);
}
}
[Theory]
[WithSolidFilledImages(10, 10, 0, 0, 255, PixelTypes.Rgba32)]
public void CompareToReferenceOutput_WhenReferenceFileMissing_Throws<TPixel>(TestImageProvider<TPixel> provider)

2
tests/Images/External

@ -1 +1 @@
Subproject commit 58aaf3b6ef7f6a344d6ac33f23751ed3343ac7c7
Subproject commit a91dd59e1cc2abbfa5ff2a8fb5690143343a3434
Loading…
Cancel
Save