Browse Source

Merge branch 'master' into js/scaled-vectors

pull/511/head
James Jackson-South 8 years ago
committed by GitHub
parent
commit
86f06a70a3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      appveyor.yml
  2. 14
      build.ps1
  3. 67
      run-tests.ps1
  4. 2
      tests/CodeCoverage/CodeCoverage.cmd
  5. 19
      tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs
  6. 96
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  7. 4
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  8. 65
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  9. 42
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  10. 12
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  11. 16
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  12. 36
      tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  13. 8
      tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
  14. 5
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  15. 9
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  16. 4
      tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
  17. 3
      tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs
  18. 6
      tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs
  19. 31
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  20. 13
      tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs
  21. 7
      tests/ImageSharp.Tests/RunExtendedTests.cmd
  22. 5
      tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs
  23. 7
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  24. 4
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs
  25. 7
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
  26. 4
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  27. 11
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  28. 14
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  29. 5
      tests/ImageSharp.Tests/xunit.runner.json

35
appveyor.yml

@ -4,6 +4,39 @@ image: Visual Studio 2017
# prevent the double build when a branch has an active PR
skip_branch_with_pr: true
environment:
matrix:
- target_framework: net471
is_32bit: True
- target_framework: net462
is_32bit: False
- target_framework: net462
is_32bit: True
- target_framework: net471
is_32bit: False
- target_framework: netcoreapp2.0
is_32bit: False
#- target_framework: netcoreapp2.0 # As far as I understand, 32 bit test execution is not supported by "dotnet xunit"
# is_32bit: True
#- target_framework: mono
# is_32bit: False
#- target_framework: mono
# is_32bit: True
#- target_framework: net47
# is_32bit: False
#- target_framework: net47
# is_32bit: True
install:
- ps: |
if ($env:target_framework -eq "mono") {
if ($env:is_32bit -eq "True") {
cinst mono --x86
} else {
cinst mono
}
}
before_build:
- git submodule -q update --init
- cmd: dotnet --version
@ -12,7 +45,7 @@ build_script:
- cmd: build.cmd
test_script:
- tests\CodeCoverage\CodeCoverage.cmd
- ps: .\run-tests.ps1 $env:target_framework $env:is_32bit
after_test:
- cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.%APPVEYOR_BUILD_VERSION%.nupkg"

14
build.ps1

@ -100,9 +100,17 @@ dotnet build -c Release /p:packageversion=$version
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
if ( $env:CI -ne "True") {
dotnet test ./tests/ImageSharp.Tests/ImageSharp.Tests.csproj --no-build -c Release
}
#
# TODO: DO WE NEED TO RUN TESTS IMPLICITLY?
#
# if ( $env:CI -ne "True") {
# cd ./tests/ImageSharp.Tests/
# dotnet xunit -nobuild -c Release -f netcoreapp2.0 --fx-version 2.0.0
# ./RunExtendedTests.cmd
# cd ../..
# }
#
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
Write-Host "Packaging projects"

67
run-tests.ps1

@ -0,0 +1,67 @@
param(
[string]$targetFramework,
[string]$is32Bit = "False"
)
if (!$targetFramework){
Write-Host "run-tests.ps1 ERROR: targetFramework is undefined!"
exit 1
}
function VerifyPath($path, $errorMessage) {
if (!(Test-Path -Path $path)) {
Write-Host "run-tests.ps1 $errorMessage `n $xunitRunnerPath"
exit 1
}
}
if ( ($targetFramework -eq "netcoreapp2.0") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) {
# We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.0 + 64bit )
$testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd"
}
elseif ($targetFramework -eq "mono") {
$testDllPath = "$PSScriptRoot\tests\ImageSharp.Tests\bin\Release\net462\SixLabors.ImageSharp.Tests.dll"
VerifyPath($testDllPath, "test dll missing:")
$xunitRunnerPath = "${env:HOMEPATH}\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\"
VerifyPath($xunitRunnerPath, "xunit console runner is missing on path:")
cd "$xunitRunnerPath"
if ($is32Bit -ne "True") {
$monoPath = "${env:PROGRAMFILES}\Mono\bin\mono.exe"
}
else {
$monoPath = "${env:ProgramFiles(x86)}\Mono\bin\mono.exe"
}
VerifyPath($monoPath, "mono runtime missing:")
$testRunnerCmd = "& `"${monoPath}`" .\xunit.console.exe `"${testDllPath}`""
}
else {
cd .\tests\ImageSharp.Tests
$xunitArgs = "-nobuild -c Release -framework $targetFramework"
if ($targetFramework -eq "netcoreapp2.0") {
# There were issues matching the correct installed runtime if we do not specify it explicitly:
$xunitArgs += " --fx-version 2.0.0"
}
if ($is32Bit -eq "True") {
$xunitArgs += " -x86"
}
$testRunnerCmd = "dotnet xunit $xunitArgs"
}
Write-Host "running:"
Write-Host $testRunnerCmd
Write-Host "..."
Invoke-Expression $testRunnerCmd
cd $PSScriptRoot
exit $LASTEXITCODE

2
tests/CodeCoverage/CodeCoverage.cmd

@ -12,7 +12,7 @@ dotnet restore ImageSharp.sln
rem Clean the solution to force a rebuild with /p:codecov=true
dotnet clean ImageSharp.sln -c Release
rem The -threshold options prevents this taking ages...
tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*"
tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release -f netcoreapp2.0 /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*"
if %errorlevel% neq 0 exit /b %errorlevel%

19
tests/ImageSharp.Tests/Colorspaces/RgbAndCieXyzConversionTest.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
/// </remarks>
public class RgbAndCieXyzConversionTest
{
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(6);
private static readonly IEqualityComparer<float> FloatRoundingComparer = new FloatRoundingComparer(5);
private static readonly ApproximateFloatComparer ApproximateComparer = new ApproximateFloatComparer(0.0001F);
@ -42,10 +42,12 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
Rgb output = converter.ToRgb(input);
// Assert
IEqualityComparer<float> comparer = new ApproximateFloatComparer(0.001f);
Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace, ApproximateComparer);
Assert.Equal(r, output.R, FloatRoundingComparer);
Assert.Equal(g, output.G, FloatRoundingComparer);
Assert.Equal(b, output.B, FloatRoundingComparer);
Assert.Equal(r, output.R, comparer);
Assert.Equal(g, output.G, comparer);
Assert.Equal(b, output.B, comparer);
}
/// <summary>
@ -95,11 +97,12 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces
// Act
CieXyz output = converter.ToCieXyz(input);
// Assert
Assert.Equal(x, output.X, FloatRoundingComparer);
Assert.Equal(y, output.Y, FloatRoundingComparer);
Assert.Equal(z, output.Z, FloatRoundingComparer);
IEqualityComparer<float> comparer = new ApproximateFloatComparer(0.001f);
Assert.Equal(x, output.X, comparer);
Assert.Equal(y, output.Y, comparer);
Assert.Equal(z, output.Z, comparer);
}
/// <summary>

96
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -13,7 +13,9 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests
{
using System;
using System.Reflection;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Quantization;
@ -61,44 +63,72 @@ namespace SixLabors.ImageSharp.Tests
}
}
[Fact]
public void QuantizeImageShouldPreserveMaximumColorPrecision()
{
string path = TestEnvironment.CreateOutputDirectory("Quantize");
foreach (TestFile file in Files)
{
using (Image<Rgba32> srcImage = Image.Load<Rgba32>(file.Bytes, out var mimeType))
public static readonly TheoryData<string> QuantizerNames =
new TheoryData<string>
{
using (Image<Rgba32> image = srcImage.Clone())
{
using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}"))
{
image.Mutate(x => x.Quantize(KnownQuantizers.Octree));
image.Save(output, mimeType);
nameof(KnownQuantizers.Octree),
nameof(KnownQuantizers.Palette),
nameof(KnownQuantizers.Wu)
};
}
}
[Theory]
[WithFile(TestImages.Png.CalliphoraPartial, nameof(QuantizerNames), PixelTypes.Rgba32)]
[WithFile(TestImages.Png.Bike, nameof(QuantizerNames), PixelTypes.Rgba32)]
public void QuantizeImageShouldPreserveMaximumColorPrecision<TPixel>(TestImageProvider<TPixel> provider, string quantizerName)
where TPixel:struct,IPixel<TPixel>
{
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
using (Image<Rgba32> image = srcImage.Clone())
{
using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}"))
{
image.Mutate(x => x.Quantize(KnownQuantizers.Wu));
image.Save(output, mimeType);
}
}
IQuantizer quantizer = GetQuantizer(quantizerName);
using (Image<Rgba32> image = srcImage.Clone())
{
using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}"))
{
image.Mutate(x => x.Quantize(KnownQuantizers.Palette));
image.Save(output, mimeType);
}
}
}
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(c => c.Quantize(quantizer));
image.DebugSave(provider);
}
provider.Configuration.MemoryManager.ReleaseRetainedResources();
//string path = TestEnvironment.CreateOutputDirectory("Quantize");
//foreach (TestFile file in Files)
//{
// using (Image<Rgba32> srcImage = Image.Load<Rgba32>(file.Bytes, out IImageFormat mimeType))
// {
// using (Image<Rgba32> image = srcImage.Clone())
// {
// using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}"))
// {
// image.Mutate(x => x.Quantize(KnownQuantizers.Octree));
// image.Save(output, mimeType);
// }
// }
// using (Image<Rgba32> image = srcImage.Clone())
// {
// using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}"))
// {
// image.Mutate(x => x.Quantize(KnownQuantizers.Wu));
// image.Save(output, mimeType);
// }
// }
// using (Image<Rgba32> image = srcImage.Clone())
// {
// using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}"))
// {
// image.Mutate(x => x.Quantize(KnownQuantizers.Palette));
// image.Save(output, mimeType);
// }
// }
// }
//}
}
private static IQuantizer GetQuantizer(string name)
{
PropertyInfo property = typeof(KnownQuantizers).GetTypeInfo().GetProperty(name);
return (IQuantizer) property.GetMethod.Invoke(null, new object[0]);
}
[Fact]

4
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests
using (Image<TPixel> image = provider.GetImage())
{
image.DebugSave(provider);
image.CompareFirstFrameToReferenceOutput(provider, ImageComparer.Exact);
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider);
}
}
@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Tests
{
Assert.Equal(expectedFrameCount, image.Frames.Count);
image.DebugSave(provider);
image.CompareFirstFrameToReferenceOutput(provider, ImageComparer.Exact);
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider);
}
}

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

@ -17,6 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -96,6 +97,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return ImageComparer.Tolerant(tolerance);
}
private static bool SkipTest(ITestImageProvider provider)
{
string[] largeImagesToSkipOn32Bit =
{
TestImages.Jpeg.Baseline.Jpeg420Exif,
TestImages.Jpeg.Issues.BadZigZagProgressive385
};
return TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess
&& largeImagesToSkipOn32Bit.Contains(provider.SourceFileOrDescription);
}
public JpegDecoderTests(ITestOutputHelper output)
{
this.Output = output;
@ -128,14 +141,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void JpegDecoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider, bool useOldDecoder)
where TPixel : struct, IPixel<TPixel>
{
if (SkipTest(provider))
{
return;
}
// For 32 bit test enviroments:
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
IImageDecoder decoder = useOldDecoder ? OrigJpegDecoder : PdfJsJpegDecoder;
using (Image<TPixel> image = provider.GetImage(decoder))
{
image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.CompareToReferenceOutput(provider, ImageComparer.Tolerant(BaselineTolerance_PdfJs), appendPixelTypeToFileName: false);
image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance_PdfJs), provider, appendPixelTypeToFileName: false);
}
provider.Configuration.MemoryManager.ReleaseRetainedResources();
}
[Theory]
@ -143,15 +166,25 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeBaselineJpeg_Orig<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
if (SkipTest(provider))
{
return;
}
// For 32 bit test enviroments:
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
using (Image<TPixel> image = provider.GetImage(OrigJpegDecoder))
{
image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.CompareToReferenceOutput(
provider,
this.GetImageComparerForOrigDecoder(provider),
provider,
appendPixelTypeToFileName: false);
}
provider.Configuration.MemoryManager.ReleaseRetainedResources();
}
[Theory]
@ -159,14 +192,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeBaselineJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess)
{
// skipping to avoid OutOfMemoryException on CI
return;
}
using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder))
{
image.DebugSave(provider);
provider.Utility.TestName = DecodeBaselineJpegOutputName;
image.CompareToReferenceOutput(
provider,
ImageComparer.Tolerant(BaselineTolerance_PdfJs),
provider,
appendPixelTypeToFileName: false);
}
}
@ -187,16 +226,26 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeProgressiveJpeg_Orig<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
if (SkipTest(provider))
{
return;
}
// For 32 bit test enviroments:
provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
using (Image<TPixel> image = provider.GetImage(OrigJpegDecoder))
{
image.DebugSave(provider);
provider.Utility.TestName = DecodeProgressiveJpegOutputName;
image.CompareToReferenceOutput(
provider,
this.GetImageComparerForOrigDecoder(provider),
provider,
appendPixelTypeToFileName: false);
}
provider.Configuration.MemoryManager.ReleaseRetainedResources();
}
[Theory]
@ -204,14 +253,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DecodeProgressiveJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess)
{
// skipping to avoid OutOfMemoryException on CI
return;
}
using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder))
{
image.DebugSave(provider);
provider.Utility.TestName = DecodeProgressiveJpegOutputName;
image.CompareToReferenceOutput(
provider,
ImageComparer.Tolerant(ProgressiveTolerance_PdfJs),
provider,
appendPixelTypeToFileName: false);
}
}

42
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -11,6 +11,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests
{
using System.Linq;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -55,7 +57,8 @@ namespace SixLabors.ImageSharp.Tests
public static readonly string[] CommonTestImages =
{
TestImages.Png.Splash, TestImages.Png.Indexed,
TestImages.Png.Splash,
TestImages.Png.Indexed,
TestImages.Png.FilterVar,
TestImages.Png.Bad.ChunkLength1,
TestImages.Png.Bad.CorruptedChunk,
@ -67,6 +70,9 @@ namespace SixLabors.ImageSharp.Tests
TestImages.Png.SnakeGame,
TestImages.Png.Banner7Adam7InterlaceMode,
TestImages.Png.Banner8Index,
TestImages.Png.Bad.ChunkLength2,
TestImages.Png.VimImage2,
};
@ -78,42 +84,42 @@ namespace SixLabors.ImageSharp.Tests
// This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
// We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
public static readonly string[] WindowsOnlyTestImages =
private static readonly string[] SkipOnMono =
{
TestImages.Png.Bad.ChunkLength2,
TestImages.Png.VimImage2,
TestImages.Png.Splash,
TestImages.Png.Indexed,
TestImages.Png.Bad.ChunkLength1,
TestImages.Png.VersioningImage1,
TestImages.Png.Banner7Adam7InterlaceMode,
};
[Theory]
[WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)]
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
private static bool SkipVerification(ITestImageProvider provider)
{
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
string fn = provider.SourceFileOrDescription;
// This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
// We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
return (TestEnvironment.IsLinux || TestEnvironment.IsMono) && SkipOnMono.Contains(fn);
}
// This is a workaround for Mono-s decoder being incompatible with ours and GDI+.
// We shouldn't mix these with the Interleaved cases (which are also failing with Mono System.Drawing). Let's go AAA!
[Theory]
[WithFileCollection(nameof(WindowsOnlyTestImages), PixelTypes.Rgba32)]
public void Decode_WindowsOnlyTestImages<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)]
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(provider);
if (!TestEnvironment.IsLinux)
if (!SkipVerification(provider))
{
image.CompareToOriginal(provider, ImageComparer.Exact);
}
}
}
[Theory]
[WithFile(TestImages.Png.Interlaced, PixelTypes.Rgba32)]
public void Decode_Interlaced_DoesNotThrow<TPixel>(TestImageProvider<TPixel> provider)
@ -148,7 +154,7 @@ namespace SixLabors.ImageSharp.Tests
image.DebugSave(provider);
// Workaround a bug in mono-s System.Drawing PNG decoder. It can't deal with 48Bpp png-s :(
if (!TestEnvironment.IsLinux)
if (!TestEnvironment.IsLinux && !TestEnvironment.IsMono)
{
image.CompareToOriginal(provider, ImageComparer.Exact);
}

12
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests
public class PngEncoderTests
{
private const float ToleranceThresholdForPaletteEncoder = 0.01f / 100;
private const float ToleranceThresholdForPaletteEncoder = 0.2f / 100;
/// <summary>
/// All types except Palette
@ -124,14 +124,22 @@ namespace SixLabors.ImageSharp.Tests
// Does DebugSave & load reference CompareToReferenceInput():
string actualOutputFile = ((ITestImageProvider)provider).Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType);
if (TestEnvironment.IsMono)
{
// There are bugs in mono's System.Drawing implementation, reference decoders are not always reliable!
return;
}
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile);
string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType);
using (var actualImage = Image.Load<TPixel>(actualOutputFile, referenceDecoder))
using (var referenceImage = Image.Load<TPixel>(referenceOutputFile, referenceDecoder))
{
float paletteToleranceHack = 80f / paletteSize;
paletteToleranceHack = paletteToleranceHack * paletteToleranceHack;
ImageComparer comparer = pngColorType == PngColorType.Palette
? ImageComparer.Tolerant(ToleranceThresholdForPaletteEncoder)
? ImageComparer.Tolerant(ToleranceThresholdForPaletteEncoder * paletteToleranceHack)
: ImageComparer.Exact;
comparer.VerifySimilarity(referenceImage, actualImage);

16
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -1,24 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks>net471;netcoreapp2.0;net462;net47</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DebugType Condition="$(codecov) != ''">full</DebugType>
<DebugType Condition="$(codecov) == ''">portable</DebugType>
<DebugSymbols>True</DebugSymbols>
<RootNamespace>SixLabors.ImageSharp.Tests</RootNamespace>
<AssemblyName>SixLabors.ImageSharp.Tests</AssemblyName>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<None Include="PixelFormats\PixelOperationsTests.Blender.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Moq" Version="4.7.145" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
@ -37,6 +48,9 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

36
tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs

@ -94,6 +94,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[InlineData(MaxPooledBufferSizeInBytes + 1)]
public void LargeBuffersAreNotPooled_OfByte(int size)
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
Assert.False(this.CheckIsRentingPooledBuffer<byte>(size));
}
@ -108,6 +114,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public unsafe void LaregeBuffersAreNotPooled_OfBigValueType()
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
int count = MaxPooledBufferSizeInBytes / sizeof(LargeStruct) + 1;
Assert.False(this.CheckIsRentingPooledBuffer<LargeStruct>(count));
@ -161,6 +173,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void AllocationOverLargeArrayThreshold_UsesDifferentPool()
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
int arrayLengthThreshold = PoolSelectorThresholdInBytes / sizeof(int);
IBuffer<int> small = this.MemoryManager.Allocate<int>(arrayLengthThreshold - 1);
@ -175,6 +193,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void CreateWithAggressivePooling()
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
this.MemoryManager = ArrayPoolMemoryManager.CreateWithAggressivePooling();
Assert.True(this.CheckIsRentingPooledBuffer<Rgba32>(4096 * 4096));
@ -183,6 +207,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void CreateDefault()
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
this.MemoryManager = ArrayPoolMemoryManager.CreateDefault();
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2 * 4096 * 4096));
@ -192,6 +222,12 @@ namespace SixLabors.ImageSharp.Tests.Memory
[Fact]
public void CreateWithModeratePooling()
{
if (!TestEnvironment.Is64BitProcess)
{
// can lead to OutOfMemoryException
return;
}
this.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling();
Assert.False(this.CheckIsRentingPooledBuffer<Rgba32>(2048 * 2048));

8
tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs

@ -949,6 +949,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Rgba64()
{
if (!TestEnvironment.Is64BitProcess)
{
// Can't decide if these assertions are robust enough to be portable across CPU architectures.
// Let's just skip it for 32 bits!
// TODO: Someone should review this!
return;
}
// Test the limits.
Assert.Equal((ulong)0x0, new Rgba64(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFFFFFFFFFF, new Rgba64(Vector4.One).PackedValue);

5
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -31,6 +31,11 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
[Fact]
public void ToVector4SimdAligned()
{
if (!Vector.IsHardwareAccelerated)
{
return;
}
ImageSharp.PixelFormats.Rgba32[] source = CreatePixelTestData(64);
Vector4[] expected = CreateExpectedVector4Data(source);

9
tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs

@ -11,9 +11,12 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
using SixLabors.ImageSharp.Processing.Convolution;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
public class DetectEdgesTest : FileTestBase
{
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.001f);
public static readonly string[] CommonTestImages = { TestImages.Png.Bike };
public static readonly TheoryData<EdgeDetectionOperators> DetectEdgesFilters = new TheoryData<EdgeDetectionOperators>
@ -40,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
image.Mutate(x => x.DetectEdges(detector));
image.DebugSave(provider, detector.ToString());
image.CompareToReferenceOutput(provider, detector.ToString());
image.CompareToReferenceOutput(ValidatorComparer, provider, detector.ToString());
}
}
@ -53,7 +56,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
image.Mutate(x => x.DetectEdges());
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -80,7 +83,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
image.Mutate(x => x.DetectEdges(bounds));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
}

4
tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs

@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
}
[Theory]
[WithFile(TestImages.Png.Bike, CommonNonDefaultPixelTypes)]
[WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
public void DitherFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
}
[Theory]
[WithFile(TestImages.Png.Bike, CommonNonDefaultPixelTypes)]
[WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
public void DiffusionFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

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

@ -8,6 +8,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
using SixLabors.ImageSharp.Processing.Filters;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
[GroupOutput("Filters")]
public class BlackWhiteTest
@ -17,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
public void ApplyBlackWhiteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(ctx => ctx.BlackWhite());
provider.RunValidatingProcessorTest(ctx => ctx.BlackWhite(), comparer: ImageComparer.TolerantPercentage(0.002f));
}
}
}

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

@ -16,6 +16,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
[GroupOutput("Filters")]
public class FilterTest
{
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.005f, 3);
// Testing the generic FilterProcessor with more than one pixel type intentionally.
// There is no need to do this with the specialized ones.
[Theory]
@ -25,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
Matrix4x4 m = CreateCombinedTestFilterMatrix();
provider.RunValidatingProcessorTest(x => x.Filter(m));
provider.RunValidatingProcessorTest(x => x.Filter(m), comparer: ValidatorComparer);
}
[Theory]
@ -35,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
Matrix4x4 m = CreateCombinedTestFilterMatrix();
provider.RunRectangleConstrainedValidatingProcessorTest((x, b) => x.Filter(m, b));
provider.RunRectangleConstrainedValidatingProcessorTest((x, b) => x.Filter(m, b), comparer: ValidatorComparer);
}
private static Matrix4x4 CreateCombinedTestFilterMatrix()

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

@ -12,11 +12,14 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
public class ResizeTests : FileTestBase
{
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial };
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.005f);
public static readonly TheoryData<string, IResampler> AllReSamplers =
new TheoryData<string, IResampler>
{
@ -50,7 +53,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
string details = $"{name}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}";
image.DebugSave(provider, details);
image.CompareToReferenceOutput(provider, details);
image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.005f), provider, details);
}
}
@ -64,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Size() / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -78,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -91,7 +94,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -122,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Width, image.Height, KnownResamplers.Bicubic, sourceRectangle, destRectangle, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -136,7 +139,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(image.Width / 3, 0, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -150,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(0, image.Height / 3, false));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -169,7 +172,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -188,7 +191,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -208,7 +211,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -228,7 +231,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -248,7 +251,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -268,7 +271,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -288,7 +291,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}

13
tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs

@ -12,11 +12,14 @@ using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{
using SixLabors.ImageSharp.Processing.Transforms;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
public class AffineTransformTests
{
private readonly ITestOutputHelper Output;
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.005f, 3);
/// <summary>
/// angleDeg, sx, sy, tx, ty
/// </summary>
@ -117,7 +120,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
string testOutputDetails = $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})";
image.DebugSave(provider, testOutputDetails);
image.CompareToReferenceOutput(provider, testOutputDetails);
image.CompareToReferenceOutput(ValidatorComparer, provider, testOutputDetails);
}
}
@ -134,7 +137,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
string testOutputDetails = $"R({angleDeg})_S({s})";
image.DebugSave(provider, testOutputDetails);
image.CompareToReferenceOutput(provider, testOutputDetails);
image.CompareToReferenceOutput(ValidatorComparer, provider, testOutputDetails);
}
}
@ -166,7 +169,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -184,7 +187,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
@ -204,7 +207,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
});
image.DebugSave(provider, resamplerName);
image.CompareToReferenceOutput(provider, resamplerName);
image.CompareToReferenceOutput(ValidatorComparer, provider, resamplerName);
}
}

7
tests/ImageSharp.Tests/RunExtendedTests.cmd

@ -0,0 +1,7 @@
dotnet build -c Release
dotnet xunit -nobuild -c Release -f net462
dotnet xunit -nobuild -c Release -f net462 -x86
dotnet xunit -nobuild -c Release -f net47
dotnet xunit -nobuild -c Release -f net47 -x86
dotnet xunit -nobuild -c Release -f net471
dotnet xunit -nobuild -c Release -f net471 -x86

5
tests/ImageSharp.Tests/TestUtilities/FloatRoundingComparer.cs

@ -33,13 +33,14 @@ namespace SixLabors.ImageSharp.Tests
float xp = (float)Math.Round(x, this.Precision, MidpointRounding.AwayFromZero);
float yp = (float)Math.Round(y, this.Precision, MidpointRounding.AwayFromZero);
return Comparer<float>.Default.Compare(xp, yp) == 0;
// ReSharper disable once CompareOfFloatsByEqualityOperator
return xp == yp;
}
/// <inheritdoc />
public bool Equals(Vector4 x, Vector4 y)
{
return Equals(x.X, y.X) && Equals(x.Y, y.Y) && Equals(x.Z, y.Z) && Equals(x.W, y.W);
return this.Equals(x.X, y.X) && this.Equals(x.Y, y.Y) && this.Equals(x.Z, y.Z) && this.Equals(x.W, y.W);
}
/// <inheritdoc />

7
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

@ -25,6 +25,13 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
return new TolerantImageComparer(imageThreshold, perPixelManhattanThreshold);
}
/// <summary>
/// Returns Tolerant(imageThresholdInPercents/100)
/// </summary>
public static ImageComparer TolerantPercentage(float imageThresholdInPercents,
int perPixelManhattanThreshold = 0) =>
Tolerant(imageThresholdInPercents / 100f, perPixelManhattanThreshold);
public abstract ImageSimilarityReport<TPixelA, TPixelB> CompareImagesOrFrames<TPixelA, TPixelB>(
ImageFrame<TPixelA> expected,
ImageFrame<TPixelB> actual)

4
tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

@ -139,8 +139,8 @@ namespace SixLabors.ImageSharp.Tests
key,
fn =>
{
TestFile testFile = TestFile.Create(this.FilePath);
return Image.Load<TPixel>(testFile.Bytes, decoder);
var testFile = TestFile.Create(this.FilePath);
return Image.Load<TPixel>(this.Configuration, testFile.Bytes, decoder);
});
return cachedImage.Clone();

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

@ -13,13 +13,18 @@ namespace SixLabors.ImageSharp.Tests
{
using Castle.Core.Internal;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing;
public interface ITestImageProvider
{
PixelTypes PixelType { get; }
ImagingTestCaseUtility Utility { get; }
string SourceFileOrDescription { get; }
Configuration Configuration { get; set; }
}
/// <summary>
/// Provides <see cref="Image{TPixel}" /> instances for parametric unit tests.
/// </summary>
@ -31,6 +36,8 @@ namespace SixLabors.ImageSharp.Tests
public virtual string SourceFileOrDescription => "";
public Configuration Configuration { get; set; } = Configuration.Default.ShallowCopy();
/// <summary>
/// Utility instance to provide informations about the test image & manage input/output
/// </summary>

4
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -92,9 +92,13 @@ namespace SixLabors.ImageSharp.Tests
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput").Replace('\\', Path.DirectorySeparatorChar);
internal static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
internal static bool IsMono => Type.GetType("Mono.Runtime") != null; // https://stackoverflow.com/a/721194
internal static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
internal static bool Is64BitProcess => IntPtr.Size == 8;
/// <summary>
/// Creates the image output directory.
/// </summary>

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

@ -120,6 +120,7 @@ namespace SixLabors.ImageSharp.Tests
/// <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>
/// <param name="comparer">A custom <see cref="ImageComparer"/> for the verification</param>
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
@ -132,22 +133,22 @@ namespace SixLabors.ImageSharp.Tests
{
return CompareToReferenceOutput(
image,
provider,
ImageComparer.Tolerant(),
provider,
testOutputDetails,
extension,
grayscale,
appendPixelTypeToFileName);
}
/// <summary>
/// Compares the image against the expected Reference output, throws an exception if the images are not similar enough.
/// The output file should be named identically to the output produced by <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
/// </summary>
/// <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="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 debug save + compare against a grayscale image, smaller in size.</param>
@ -155,8 +156,8 @@ namespace SixLabors.ImageSharp.Tests
/// <returns></returns>
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
ImageComparer comparer,
ITestImageProvider provider,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false,
@ -177,8 +178,8 @@ namespace SixLabors.ImageSharp.Tests
public static Image<TPixel> CompareFirstFrameToReferenceOutput<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
ImageComparer comparer,
ITestImageProvider provider,
object testOutputDetails = null,
string extension = "png",
bool grayscale = false,

14
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -165,6 +165,11 @@ namespace SixLabors.ImageSharp.Tests
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel>
{
if (comparer == null)
{
comparer = ImageComparer.TolerantPercentage(0.001f);
}
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(process);
@ -173,7 +178,7 @@ namespace SixLabors.ImageSharp.Tests
// TODO: Investigate the cause of pixel inaccuracies under Linux
if (TestEnvironment.IsWindows)
{
image.CompareToReferenceOutput(provider, testOutputDetails);
image.CompareToReferenceOutput(comparer, provider, testOutputDetails);
}
}
}
@ -188,12 +193,17 @@ namespace SixLabors.ImageSharp.Tests
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel>
{
if (comparer == null)
{
comparer = ImageComparer.TolerantPercentage(0.001f);
}
using (Image<TPixel> image = provider.GetImage())
{
var bounds = new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => process(x, bounds));
image.DebugSave(provider, testOutputDetails);
image.CompareToReferenceOutput(provider, testOutputDetails);
image.CompareToReferenceOutput(comparer, provider, testOutputDetails);
}
}

5
tests/ImageSharp.Tests/xunit.runner.json

@ -1,4 +1,5 @@
{
"methodDisplay": "method",
"diagnosticMessages": true
"shadowCopy": false,
"methodDisplay": "method",
"diagnosticMessages": true
}
Loading…
Cancel
Save