Browse Source

fixed IsEquivalentTo, renamed ColorWithDefaultImageClass to StandardImageClass

pull/57/head
antonfirsov 10 years ago
parent
commit
8be1a38e4f
  1. 6
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  3. 2
      tests/ImageSharp.Tests/TestUtilities/TestImageProvider.cs
  4. 11
      tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
  5. 10
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  6. 24
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

6
tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs

@ -24,7 +24,7 @@ namespace ImageSharp.Tests
// TODO: Turned off PixelTypes.All to be CI-friendly, what should be the practice?
[Theory]
//[WithFileCollection(nameof(AllJpegFiles), PixelTypes.All)]
[WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.ColorWithDefaultImageClass | PixelTypes.Argb)]
[WithFileCollection(nameof(AllJpegFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb)]
public void OpenJpeg_SaveBmp<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
@ -37,8 +37,8 @@ namespace ImageSharp.Tests
public static IEnumerable<string> AllBmpFiles => TestImages.Bmp.All;
[Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.ColorWithDefaultImageClass | PixelTypes.Argb, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.ColorWithDefaultImageClass | PixelTypes.Argb, JpegSubsample.Ratio444, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb, JpegSubsample.Ratio444, 75)]
public void OpenBmp_SaveJpeg<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{

2
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -52,7 +52,7 @@ namespace ImageSharp.Tests
/// <summary>
/// Triggers instantiating the <see cref="Image"/> subclass of <see cref="Image{TColor}"/>
/// </summary>
ColorWithDefaultImageClass = 1 << 29,
StandardImageClass = 1 << 29,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper

2
tests/ImageSharp.Tests/TestUtilities/TestImageProvider.cs

@ -73,7 +73,7 @@ namespace ImageSharp.Tests
this.PixelType = pixelTypeOverride;
}
if (pixelTypeOverride == PixelTypes.ColorWithDefaultImageClass)
if (pixelTypeOverride == PixelTypes.StandardImageClass)
{
this.Factory = new DefaultImageClassSpecificFactory() as GenericFactory<TColor>;
}

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

@ -31,7 +31,7 @@ namespace ImageSharp.Tests
{
string nameSpace = typeof(Color).FullName;
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color).Name.Length - 1);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.ColorWithDefaultImageClass))
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass))
{
string typeName = $"{nameSpace}.{FlagsHelper<PixelTypes>.ToString(pt)}";
var t = ImageSharpAssembly.GetType(typeName);
@ -41,7 +41,7 @@ namespace ImageSharp.Tests
ClrTypes2PixelTypes[t] = pt;
}
}
PixelTypes2ClrTypes[PixelTypes.ColorWithDefaultImageClass] = typeof(Color);
PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color);
}
public static Type GetPackedType(Type pixelType)
@ -88,6 +88,13 @@ namespace ImageSharp.Tests
{
ca.ToBytes(bytesA, 0, ComponentOrder.XYZ);
cb.ToBytes(bytesB, 0, ComponentOrder.XYZ);
if (bytesA[0] != bytesB[0] ||
bytesA[1] != bytesB[1] ||
bytesA[2] != bytesB[2])
{
return false;
}
}
}
}

10
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -5,7 +5,7 @@
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Tests
namespace ImageSharp.Tests
{
using System;
@ -50,7 +50,7 @@ namespace ImageSharp.Tests.Tests
[Theory]
[WithBlankImages(1, 1, PixelTypes.Color, PixelTypes.Color)]
[WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)]
[WithBlankImages(1, 1, PixelTypes.ColorWithDefaultImageClass, PixelTypes.ColorWithDefaultImageClass)]
[WithBlankImages(1, 1, PixelTypes.StandardImageClass, PixelTypes.StandardImageClass)]
public void PixelType_PropertyValueIsCorrect<TColor>(TestImageProvider<TColor> provider, PixelTypes expected)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Tests
}
[Theory]
[WithBlankImages(1, 1, PixelTypes.ColorWithDefaultImageClass)]
[WithBlankImages(1, 1, PixelTypes.StandardImageClass)]
public void PixelTypes_ColorWithDefaultImageClass_TriggersCreatingTheNonGenericDerivedImageClass<TColor>(
TestImageProvider<TColor> provider)
where TColor : struct, IPackedPixel, IEquatable<TColor>
@ -126,7 +126,7 @@ namespace ImageSharp.Tests.Tests
}
/// <summary>
/// Need to us <see cref="GenericFactory{TColor}"/> to create instance of <see cref="Image"/> when pixelType is ColorWithDefaultImageClass
/// Need to us <see cref="GenericFactory{TColor}"/> to create instance of <see cref="Image"/> when pixelType is StandardImageClass
/// </summary>
/// <typeparam name="TColor"></typeparam>
/// <param name="factory"></param>
@ -144,7 +144,7 @@ namespace ImageSharp.Tests.Tests
{
var img = provider.GetImage();
Assert.Equal(img.Width, 3);
if (provider.PixelType == PixelTypes.ColorWithDefaultImageClass)
if (provider.PixelType == PixelTypes.StandardImageClass)
{
Assert.IsType<Image>(img);
}

24
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -4,7 +4,7 @@
// </copyright>
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Tests
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
@ -68,33 +68,35 @@ namespace ImageSharp.Tests.Tests
}
[Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.Color)]
public void IsEquivalentTo_WhenFalse<TColor>(TestImageProvider<TColor> provider)
[WithFile(TestImages.Bmp.Car, PixelTypes.Color, true)]
[WithFile(TestImages.Bmp.Car, PixelTypes.Color, false)]
public void IsEquivalentTo_WhenFalse<TColor>(TestImageProvider<TColor> provider, bool compareAlpha)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
var a = provider.GetImage();
var b = provider.GetImage();
b = b.OilPaint(3, 2);
Assert.False(a.IsEquivalentTo(b));
Assert.False(a.IsEquivalentTo(b, compareAlpha));
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565)]
public void IsEquivalentTo_WhenTrue<TColor>(TestImageProvider<TColor> provider)
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565, true)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565, false)]
public void IsEquivalentTo_WhenTrue<TColor>(TestImageProvider<TColor> provider, bool compareAlpha)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
var a = provider.GetImage();
var b = provider.GetImage();
Assert.True(a.IsEquivalentTo(b));
Assert.True(a.IsEquivalentTo(b, compareAlpha));
}
[Theory]
[InlineData(PixelTypes.Color, typeof(Color))]
[InlineData(PixelTypes.Argb, typeof(Argb))]
[InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))]
[InlineData(PixelTypes.ColorWithDefaultImageClass, typeof(Color))]
[InlineData(PixelTypes.StandardImageClass, typeof(Color))]
public void ToType(PixelTypes pt, Type expectedType)
{
Assert.Equal(pt.ToType(), expectedType);
@ -119,7 +121,7 @@ namespace ImageSharp.Tests.Tests
[Fact]
public void ToTypes()
{
PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.Color | PixelTypes.HalfVector2 | PixelTypes.ColorWithDefaultImageClass;
PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.Color | PixelTypes.HalfVector2 | PixelTypes.StandardImageClass;
var expanded = pixelTypes.ExpandAllTypes();
@ -129,7 +131,7 @@ namespace ImageSharp.Tests.Tests
AssertContainsPixelType<Bgr565>(PixelTypes.Bgr565, expanded);
AssertContainsPixelType<Color>(PixelTypes.Color, expanded);
AssertContainsPixelType<HalfVector2>(PixelTypes.HalfVector2, expanded);
AssertContainsPixelType<Color>(PixelTypes.ColorWithDefaultImageClass, expanded);
AssertContainsPixelType<Color>(PixelTypes.StandardImageClass, expanded);
}
[Fact]
@ -139,7 +141,7 @@ namespace ImageSharp.Tests.Tests
Assert.True(expanded.Length >= FlagsHelper<PixelTypes>.GetSortedValues().Length - 2);
AssertContainsPixelType<Color>(PixelTypes.Color, expanded);
AssertContainsPixelType<Color>(PixelTypes.ColorWithDefaultImageClass, expanded);
AssertContainsPixelType<Color>(PixelTypes.StandardImageClass, expanded);
}
}
}
Loading…
Cancel
Save