Skip to content

Commit 1f6aed0

Browse files
committed
Added tests for invalid allocation sizes
1 parent f4da592 commit 1f6aed0

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Buffers/Test_ArrayPoolBufferWriter{T}.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public void Test_ArrayPoolBufferWriterOfT_AllocateAndGetMemoryAndSpan()
5454
Assert.ThrowsException<ObjectDisposedException>(() => writer.Advance(1));
5555
}
5656

57+
[TestCategory("ArrayPoolBufferWriterOfT")]
58+
[TestMethod]
59+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
60+
public void Test_ArrayPoolBufferWriterOfT_InvalidRequestedSize()
61+
{
62+
var writer = new ArrayPoolBufferWriter<byte>(-1);
63+
64+
Assert.Fail("You shouldn't be here");
65+
}
66+
5767
[TestCategory("ArrayPoolBufferWriterOfT")]
5868
[TestMethod]
5969
public void Test_ArrayPoolBufferWriterOfT_Clear()

UnitTests/UnitTests.HighPerformance.Shared/Buffers/Test_MemoryOwner{T}.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public void Test_MemoryOwnerOfT_AllocateAndGetMemoryAndSpan()
3030
Assert.IsTrue(buffer.Span.ToArray().All(i => i == 42));
3131
}
3232

33+
[TestCategory("MemoryOwnerOfT")]
34+
[TestMethod]
35+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
36+
public void Test_MemoryOwnerOfT_InvalidRequestedSize()
37+
{
38+
using var buffer = MemoryOwner<int>.Allocate(-1);
39+
40+
Assert.Fail("You shouldn't be here");
41+
}
42+
3343
[TestCategory("MemoryOwnerOfT")]
3444
[TestMethod]
3545
[ExpectedException(typeof(ObjectDisposedException))]

UnitTests/UnitTests.HighPerformance.Shared/Buffers/Test_SpanOwner{T}.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using Microsoft.Toolkit.HighPerformance.Buffers;
@@ -27,6 +28,16 @@ public void Test_SpanOwnerOfT_AllocateAndGetMemoryAndSpan()
2728
Assert.IsTrue(buffer.Span.ToArray().All(i => i == 42));
2829
}
2930

31+
[TestCategory("SpanOwnerOfT")]
32+
[TestMethod]
33+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
34+
public void Test_SpanOwnerOfT_InvalidRequestedSize()
35+
{
36+
using var buffer = SpanOwner<int>.Allocate(-1);
37+
38+
Assert.Fail("You shouldn't be here");
39+
}
40+
3041
[TestCategory("HashCodeOfT")]
3142
[TestMethod]
3243
public void Test_SpanOwnerOfT_PooledBuffersAndClear()

0 commit comments

Comments
 (0)