Browse Source

Use TestProvider to load images

pull/1574/head
James Jackson-South 6 years ago
parent
commit
300273fd11
  1. 26
      tests/ImageSharp.Tests/IO/ChunkedMemoryStreamTests.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs

26
tests/ImageSharp.Tests/IO/ChunkedMemoryStreamTests.cs

@ -297,32 +297,36 @@ namespace SixLabors.ImageSharp.Tests.IO
Assert.Equal(expected, destination.ToArray());
}
public static TheoryData<string> GetAllTestImages()
public static IEnumerable<string> GetAllTestImages()
{
IEnumerable<string> allImageFiles = Directory.EnumerateFiles(TestEnvironment.InputImagesDirectoryFullPath, "*.*", SearchOption.AllDirectories)
.Where(s => !s.EndsWith("txt", StringComparison.OrdinalIgnoreCase));
var result = new TheoryData<string>();
var result = new List<string>();
foreach (string path in allImageFiles)
{
result.Add(path);
result.Add(path.Substring(TestEnvironment.InputImagesDirectoryFullPath.Length));
}
return result;
}
public static IEnumerable<string> AllTestImages = GetAllTestImages();
[Theory]
[MemberData(nameof(GetAllTestImages))]
public void DecoderIntegrationTest(string testFileFullPath)
[WithFileCollection(nameof(AllTestImages), PixelTypes.Rgba32)]
public void DecoderIntegrationTest<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
if (!TestEnvironment.Is64BitProcess)
{
return;
}
Image<Rgba32> expected;
Image<TPixel> expected;
try
{
expected = Image.Load<Rgba32>(testFileFullPath);
expected = provider.GetImage();
}
catch
{
@ -330,10 +334,14 @@ namespace SixLabors.ImageSharp.Tests.IO
return;
}
using FileStream fs = File.OpenRead(testFileFullPath);
string fullPath = Path.Combine(
TestEnvironment.InputImagesDirectoryFullPath,
((TestImageProvider<TPixel>.FileProvider)provider).FilePath);
using FileStream fs = File.OpenRead(fullPath);
using var nonSeekableStream = new NonSeekableStream(fs);
var actual = Image.Load<Rgba32>(nonSeekableStream);
var actual = Image.Load<TPixel>(nonSeekableStream);
ImageComparer.Exact.VerifySimilarity(expected, actual);
}

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

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests
public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
where TPixel : unmanaged, IPixel<TPixel>
{
private class FileProvider : TestImageProvider<TPixel>, IXunitSerializable
internal class FileProvider : TestImageProvider<TPixel>, IXunitSerializable
{
// Need PixelTypes in the dictionary key, because result images of TestImageProvider<TPixel>.FileProvider
// are shared between PixelTypes.Color & PixelTypes.Rgba32

Loading…
Cancel
Save