Browse Source

Fix tests

af/merge-core
James Jackson-South 9 years ago
parent
commit
47710578f0
  1. 25
      tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs

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

@ -25,26 +25,27 @@ namespace ImageSharp.Tests
private static readonly Dictionary<PixelTypes, Type> PixelTypes2ClrTypes = new Dictionary<PixelTypes, Type>(); private static readonly Dictionary<PixelTypes, Type> PixelTypes2ClrTypes = new Dictionary<PixelTypes, Type>();
private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes() private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes()
.Except(new [] {PixelTypes.Undefined, PixelTypes.All }) .Except(new[] { PixelTypes.Undefined, PixelTypes.All })
.ToArray(); .ToArray();
static TestUtilityExtensions() static TestUtilityExtensions()
{ {
string nameSpace = typeof(Rgba32).FullName; // Add Rgba32 Our default.
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Rgba32).Name.Length - 1); Type defaultPixelFormatType = typeof(Rgba32);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass)) PixelTypes2ClrTypes[PixelTypes.Rgba32] = defaultPixelFormatType;
ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32;
// Add PixelFormat types
string nameSpace = typeof(Alpha8).FullName;
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Alpha8).Name.Length - 1);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass && pt != PixelTypes.Rgba32))
{ {
string typeName = $"{nameSpace}.{pt.ToString()}"; string typeName = $"{nameSpace}.{pt}";
Type t = ImageSharpAssembly.GetType(typeName); Type t = ImageSharpAssembly.GetType(typeName);
if (t == null) PixelTypes2ClrTypes[pt] = t ?? throw new InvalidOperationException($"Could not find: {typeName}");
{
throw new InvalidOperationException($"Could not find: {typeName}");
}
PixelTypes2ClrTypes[pt] = t;
ClrTypes2PixelTypes[t] = pt; ClrTypes2PixelTypes[t] = pt;
} }
PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Rgba32); PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = defaultPixelFormatType;
} }
public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag; public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag;

Loading…
Cancel
Save