Skip to content

Commit f158abe

Browse files
committed
Added buffer request unit tests
1 parent 27c529a commit f158abe

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics.CodeAnalysis;
77
using System.IO;
88
using System.Linq;
9+
using System.Reflection;
910
using Microsoft.Toolkit.HighPerformance.Buffers;
1011
using Microsoft.Toolkit.HighPerformance.Extensions;
1112
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -17,6 +18,37 @@ namespace UnitTests.HighPerformance.Buffers
1718
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649", Justification = "Test class for generic type")]
1819
public class Test_ArrayPoolBufferWriterOfT
1920
{
21+
[TestCategory("ArrayPoolBufferWriterOfT")]
22+
[TestMethod]
23+
[DataRow(0, 256)] // 256 is the default initial size for ArrayPoolBufferWriter<T>
24+
[DataRow(4, 256)]
25+
[DataRow(7, 256)]
26+
[DataRow(27, 256)]
27+
[DataRow(188, 256)]
28+
[DataRow(257, 512)]
29+
[DataRow(358, 512)]
30+
[DataRow(799, 1024)]
31+
[DataRow(1024, 1024)]
32+
[DataRow(1025, 2048)]
33+
[DataRow((1024 * 1024) - 1, 1024 * 1024)]
34+
[DataRow(1024 * 1024, 1024 * 1024)]
35+
[DataRow((1024 * 1024) + 1, 2 * 1024 * 1024)]
36+
[DataRow(2 * 1024 * 1024, 2 * 1024 * 1024)]
37+
[DataRow((2 * 1024 * 1024) + 1, 4 * 1024 * 1024)]
38+
[DataRow(3 * 1024 * 1024, 4 * 1024 * 1024)]
39+
public void Test_ArrayPoolBufferWriterOfT_BufferSize(int request, int expected)
40+
{
41+
using var writer = new ArrayPoolBufferWriter<byte>();
42+
43+
writer.GetSpan(request);
44+
45+
var arrayFieldInfo = typeof(ArrayPoolBufferWriter<byte>).GetField("array", BindingFlags.Instance | BindingFlags.NonPublic);
46+
47+
byte[] array = (byte[])arrayFieldInfo!.GetValue(writer);
48+
49+
Assert.AreEqual(array!.Length, expected);
50+
}
51+
2052
[TestCategory("ArrayPoolBufferWriterOfT")]
2153
[TestMethod]
2254
public void Test_ArrayPoolBufferWriterOfT_AllocateAndGetMemoryAndSpan()

0 commit comments

Comments
 (0)