// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // // ReSharper disable InconsistentNaming namespace ImageSharp.Tests { using System.Linq; using Xunit; /// /// Tests the class. /// public class PixelDataPoolTests { [Fact] public void PixelDataPoolRentsMinimumSize() { Color[] pixels = PixelDataPool.Rent(1024); Assert.True(pixels.Length >= 1024); } [Fact] public void PixelDataPool_Clean_RentsCleanArray() { for (int i = 16; i < 1024; i += 16) { Color[] pixels = PixelDataPool.Rent(i); Assert.True(pixels.All(p => p == default(Color))); PixelDataPool.Return(pixels); } for (int i = 16; i < 1024; i += 16) { Color[] pixels = PixelDataPool.Rent(i); Assert.True(pixels.All(p => p == default(Color))); PixelDataPool.Return(pixels); } } [Fact] public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { Color[] pixels = new Color[1024]; PixelDataPool.Return(pixels); Assert.True(pixels.Length >= 1024); } [Fact] public void PixelDataPool_Clean_CleansRentedArray() { Color[] pixels = PixelDataPool.Rent(256); for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.Azure; } Assert.True(pixels.All(p => p == Color.Azure)); PixelDataPool.Return(pixels); Assert.True(pixels.All(p => p == default(Color))); } [Theory] [InlineData(false)] [InlineData(true)] public void CalculateMaxArrayLength(bool isRawData) { int max = isRawData ? PixelDataPool.CalculateMaxArrayLength() : PixelDataPool.CalculateMaxArrayLength(); Assert.Equal(max < int.MaxValue, !isRawData); } [Fact] public void RentNonIPixelData() { byte[] data = PixelDataPool.Rent(16384); Assert.True(data.Length >= 16384); } } }