|
|
|
@ -15,17 +15,10 @@ namespace ImageSharp.Tests |
|
|
|
/// </summary>
|
|
|
|
public class PixelDataPoolTests |
|
|
|
{ |
|
|
|
private static PixelDataPool<Color> GetPool(bool clean) |
|
|
|
{ |
|
|
|
return clean ? PixelDataPool<Color>.Clean : PixelDataPool<Color>.Dirty; |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(false)] |
|
|
|
[InlineData(true)] |
|
|
|
public void PixelDataPoolRentsMinimumSize(bool clean) |
|
|
|
[Fact] |
|
|
|
public void PixelDataPoolRentsMinimumSize() |
|
|
|
{ |
|
|
|
Color[] pixels = GetPool(clean).Rent(1024); |
|
|
|
Color[] pixels = PixelDataPool<Color>.Rent(1024); |
|
|
|
|
|
|
|
Assert.True(pixels.Length >= 1024); |
|
|
|
} |
|
|
|
@ -35,31 +28,29 @@ namespace ImageSharp.Tests |
|
|
|
{ |
|
|
|
for (int i = 16; i < 1024; i += 16) |
|
|
|
{ |
|
|
|
Color[] pixels = PixelDataPool<Color>.Clean.Rent(i); |
|
|
|
Color[] pixels = PixelDataPool<Color>.Rent(i); |
|
|
|
|
|
|
|
Assert.True(pixels.All(p => p == default(Color))); |
|
|
|
|
|
|
|
PixelDataPool<Color>.Clean.Return(pixels); |
|
|
|
PixelDataPool<Color>.Return(pixels); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 16; i < 1024; i += 16) |
|
|
|
{ |
|
|
|
Color[] pixels = PixelDataPool<Color>.Clean.Rent(i); |
|
|
|
Color[] pixels = PixelDataPool<Color>.Rent(i); |
|
|
|
|
|
|
|
Assert.True(pixels.All(p => p == default(Color))); |
|
|
|
|
|
|
|
PixelDataPool<Color>.Clean.Return(pixels); |
|
|
|
PixelDataPool<Color>.Return(pixels); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(false)] |
|
|
|
[InlineData(true)] |
|
|
|
public void PixelDataPoolDoesNotThrowWhenReturningNonPooled(bool clean) |
|
|
|
[Fact] |
|
|
|
public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() |
|
|
|
{ |
|
|
|
Color[] pixels = new Color[1024]; |
|
|
|
|
|
|
|
GetPool(clean).Return(pixels); |
|
|
|
PixelDataPool<Color>.Return(pixels); |
|
|
|
|
|
|
|
Assert.True(pixels.Length >= 1024); |
|
|
|
} |
|
|
|
@ -67,7 +58,7 @@ namespace ImageSharp.Tests |
|
|
|
[Fact] |
|
|
|
public void PixelDataPool_Clean_CleansRentedArray() |
|
|
|
{ |
|
|
|
Color[] pixels = PixelDataPool<Color>.Clean.Rent(256); |
|
|
|
Color[] pixels = PixelDataPool<Color>.Rent(256); |
|
|
|
|
|
|
|
for (int i = 0; i < pixels.Length; i++) |
|
|
|
{ |
|
|
|
@ -76,7 +67,7 @@ namespace ImageSharp.Tests |
|
|
|
|
|
|
|
Assert.True(pixels.All(p => p == Color.Azure)); |
|
|
|
|
|
|
|
PixelDataPool<Color>.Clean.Return(pixels); |
|
|
|
PixelDataPool<Color>.Return(pixels); |
|
|
|
|
|
|
|
Assert.True(pixels.All(p => p == default(Color))); |
|
|
|
} |
|
|
|
@ -95,7 +86,7 @@ namespace ImageSharp.Tests |
|
|
|
[Fact] |
|
|
|
public void RentNonIPixelData() |
|
|
|
{ |
|
|
|
byte[] data = PixelDataPool<byte>.Clean.Rent(16384); |
|
|
|
byte[] data = PixelDataPool<byte>.Rent(16384); |
|
|
|
|
|
|
|
Assert.True(data.Length >= 16384); |
|
|
|
} |
|
|
|
|