Skip to content

Commit 582000d

Browse files
Use TestProvider to load images
1 parent a4f63d7 commit 582000d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

tests/ImageSharp.Tests/IO/ChunkedMemoryStreamTests.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,43 +297,51 @@ public void CopyTo(Stream source, byte[] expected)
297297
Assert.Equal(expected, destination.ToArray());
298298
}
299299

300-
public static TheoryData<string> GetAllTestImages()
300+
public static IEnumerable<string> GetAllTestImages()
301301
{
302302
IEnumerable<string> allImageFiles = Directory.EnumerateFiles(TestEnvironment.InputImagesDirectoryFullPath, "*.*", SearchOption.AllDirectories)
303303
.Where(s => !s.EndsWith("txt", StringComparison.OrdinalIgnoreCase));
304-
var result = new TheoryData<string>();
304+
305+
var result = new List<string>();
305306
foreach (string path in allImageFiles)
306307
{
307-
result.Add(path);
308+
result.Add(path.Substring(TestEnvironment.InputImagesDirectoryFullPath.Length));
308309
}
309310

310311
return result;
311312
}
312313

314+
public static IEnumerable<string> AllTestImages = GetAllTestImages();
315+
313316
[Theory]
314-
[MemberData(nameof(GetAllTestImages))]
315-
public void DecoderIntegrationTest(string testFileFullPath)
317+
[WithFileCollection(nameof(AllTestImages), PixelTypes.Rgba32)]
318+
public void DecoderIntegrationTest<TPixel>(TestImageProvider<TPixel> provider)
319+
where TPixel : unmanaged, IPixel<TPixel>
316320
{
317321
if (!TestEnvironment.Is64BitProcess)
318322
{
319323
return;
320324
}
321325

322-
Image<Rgba32> expected;
326+
Image<TPixel> expected;
323327
try
324328
{
325-
expected = Image.Load<Rgba32>(testFileFullPath);
329+
expected = provider.GetImage();
326330
}
327331
catch
328332
{
329333
// The image is invalid
330334
return;
331335
}
332336

333-
using FileStream fs = File.OpenRead(testFileFullPath);
337+
string fullPath = Path.Combine(
338+
TestEnvironment.InputImagesDirectoryFullPath,
339+
((TestImageProvider<TPixel>.FileProvider)provider).FilePath);
340+
341+
using FileStream fs = File.OpenRead(fullPath);
334342
using var nonSeekableStream = new NonSeekableStream(fs);
335343

336-
var actual = Image.Load<Rgba32>(nonSeekableStream);
344+
var actual = Image.Load<TPixel>(nonSeekableStream);
337345

338346
ImageComparer.Exact.VerifySimilarity(expected, actual);
339347
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests
1717
public abstract partial class TestImageProvider<TPixel> : IXunitSerializable
1818
where TPixel : unmanaged, IPixel<TPixel>
1919
{
20-
private class FileProvider : TestImageProvider<TPixel>, IXunitSerializable
20+
internal class FileProvider : TestImageProvider<TPixel>, IXunitSerializable
2121
{
2222
// Need PixelTypes in the dictionary key, because result images of TestImageProvider<TPixel>.FileProvider
2323
// are shared between PixelTypes.Color & PixelTypes.Rgba32

0 commit comments

Comments
 (0)