//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Tests
{
using System;
using Xunit;
using Xunit.Abstractions;
public class TestImageProviderTests
{
public TestImageProviderTests(ITestOutputHelper output)
{
this.Output = output;
}
private ITestOutputHelper Output { get; }
[Theory]
[WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb | PixelTypes.HalfSingle, "hello")]
public void Use_WithEmptyImageAttribute(TestImageProvider provider, string message)
where TColor : struct, IPixel
{
var img = provider.GetImage();
Assert.Equal(42, img.Width);
Assert.Equal(666, img.Height);
Assert.Equal("hello", message);
}
[Theory]
[WithBlankImages(42, 666, PixelTypes.All, "hello")]
public void Use_WithBlankImagesAttribute_WithAllPixelTypes(
TestImageProvider provider,
string message)
where TColor : struct, IPixel
{
var img = provider.GetImage();
Assert.Equal(42, img.Width);
Assert.Equal(666, img.Height);
Assert.Equal("hello", message);
}
[Theory]
[WithBlankImages(1, 1, PixelTypes.Color, PixelTypes.Color)]
[WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)]
[WithBlankImages(1, 1, PixelTypes.StandardImageClass, PixelTypes.StandardImageClass)]
public void PixelType_PropertyValueIsCorrect(TestImageProvider provider, PixelTypes expected)
where TColor : struct, IPixel
{
Assert.Equal(expected, provider.PixelType);
}
[Theory]
[WithBlankImages(1, 1, PixelTypes.StandardImageClass)]
[WithFile(TestImages.Bmp.F, PixelTypes.StandardImageClass)]
public void PixelTypes_ColorWithDefaultImageClass_TriggersCreatingTheNonGenericDerivedImageClass(
TestImageProvider provider)
where TColor : struct, IPixel
{
var img = provider.GetImage();
Assert.IsType(img);
}
[Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)]
[WithFile(TestImages.Bmp.F, PixelTypes.All, 88)]
public void Use_WithFileAttribute(TestImageProvider provider, int yo)
where TColor : struct, IPixel
{
Assert.NotNull(provider.Utility.SourceFileOrDescription);
var img = provider.GetImage();
Assert.True(img.Width * img.Height > 0);
Assert.Equal(88, yo);
string fn = provider.Utility.GetTestOutputFileName("jpg");
this.Output.WriteLine(fn);
}
public static string[] AllBmpFiles => TestImages.Bmp.All;
[Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb)]
public void Use_WithFileCollection(TestImageProvider provider)
where TColor : struct, IPixel
{
Assert.NotNull(provider.Utility.SourceFileOrDescription);
var image = provider.GetImage();
provider.Utility.SaveTestOutputFile(image, "png");
}
[Theory]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb)]
public void Use_WithSolidFilledImagesAttribute(TestImageProvider provider)
where TColor : struct, IPixel
{
var img = provider.GetImage();
Assert.Equal(img.Width, 10);
Assert.Equal(img.Height, 20);
byte[] colors = new byte[4];
using (var pixels = img.Lock())
{
for (int y = 0; y < pixels.Height; y++)
{
for (int x = 0; x < pixels.Width; x++)
{
pixels[x, y].ToXyzwBytes(colors, 0);
Assert.Equal(colors[0], 255);
Assert.Equal(colors[1], 100);
Assert.Equal(colors[2], 50);
Assert.Equal(colors[3], 200);
}
}
}
}
///
/// Need to us to create instance of when pixelType is StandardImageClass
///
///
///
///
public static Image CreateTestImage(GenericFactory factory)
where TColor : struct, IPixel
{
return factory.CreateImage(3, 3);
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.All)]
public void Use_WithMemberFactoryAttribute(TestImageProvider provider)
where TColor : struct, IPixel
{
var img = provider.GetImage();
Assert.Equal(img.Width, 3);
if (provider.PixelType == PixelTypes.StandardImageClass)
{
Assert.IsType(img);
}
}
public static readonly TheoryData