Browse Source

Use shared ArrayPoolMemoryAllocator in tests

pull/1771/head
Anton Firszov 4 years ago
parent
commit
a75f106392
  1. 3
      tests/ImageSharp.Tests/Image/ImageFrameTests.cs
  2. 3
      tests/ImageSharp.Tests/Image/ImageTests.cs
  3. 11
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
  4. 3
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

3
tests/ImageSharp.Tests/Image/ImageFrameTests.cs

@ -16,7 +16,8 @@ namespace SixLabors.ImageSharp.Tests
private void LimitBufferCapacity(int bufferCapacityInBytes)
{
var allocator = (ArrayPoolMemoryAllocator)this.configuration.MemoryAllocator;
var allocator = ArrayPoolMemoryAllocator.CreateDefault();
this.configuration.MemoryAllocator = allocator;
allocator.BufferCapacityInBytes = bufferCapacityInBytes;
}

3
tests/ImageSharp.Tests/Image/ImageTests.cs

@ -99,7 +99,8 @@ namespace SixLabors.ImageSharp.Tests
private void LimitBufferCapacity(int bufferCapacityInBytes)
{
var allocator = (ArrayPoolMemoryAllocator)this.configuration.MemoryAllocator;
var allocator = ArrayPoolMemoryAllocator.CreateDefault();
this.configuration.MemoryAllocator = allocator;
allocator.BufferCapacityInBytes = bufferCapacityInBytes;
}

11
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs

@ -21,11 +21,20 @@ namespace SixLabors.ImageSharp.Tests
public abstract partial class TestImageProvider<TPixel> : ITestImageProvider, IXunitSerializable
where TPixel : unmanaged, IPixel<TPixel>
{
// Create a Configuration with Configuration.CreateDefaultInstance(),
// but use the shared MemoryAllocator from Configuration.Default.MemoryAllocator
private static Configuration CreateDefaultConfiguration()
{
var configuration = Configuration.CreateDefaultInstance();
configuration.MemoryAllocator = ImageSharp.Configuration.Default.MemoryAllocator;
return configuration;
}
public PixelTypes PixelType { get; private set; } = typeof(TPixel).GetPixelType();
public virtual string SourceFileOrDescription => string.Empty;
public Configuration Configuration { get; set; } = Configuration.CreateDefaultInstance();
public Configuration Configuration { get; set; } = CreateDefaultConfiguration();
/// <summary>
/// Gets the utility instance to provide information about the test image & manage input/output.

3
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -663,7 +663,8 @@ namespace SixLabors.ImageSharp.Tests
this TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var allocator = (ArrayPoolMemoryAllocator)provider.Configuration.MemoryAllocator;
var allocator = ArrayPoolMemoryAllocator.CreateDefault();
provider.Configuration.MemoryAllocator = allocator;
return new AllocatorBufferCapacityConfigurator(allocator, Unsafe.SizeOf<TPixel>());
}

Loading…
Cancel
Save