Skip to content
Prev Previous commit
Use TestProvider to load images
  • Loading branch information
JimBobSquarePants committed Aug 21, 2020
commit 582000d49a14d0598262891f0c99e34213b57182
26 changes: 17 additions & 9 deletions tests/ImageSharp.Tests/IO/ChunkedMemoryStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,43 +297,51 @@ public void CopyTo(Stream source, byte[] expected)
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
{
// The image is invalid
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down