Skip to content

Commit 25a7559

Browse files
committed
Added ReadString test.
1 parent 04662b4 commit 25a7559

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

ReClass.NET_Tests/Memory/MemoryBufferTest.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Text;
23
using NFluent;
34
using ReClassNET.Memory;
45
using Xunit;
@@ -129,7 +130,6 @@ public void TestReadFloat(MemoryBuffer sut, int offset, float expected)
129130
{
130131
{ CreateFromBytes(), 0, 0.0 },
131132
{ CreateFromBytes(), 4, 0.0 },
132-
//409349ba786c2268
133133
{ CreateFromBytes(0x54, 0x74, 0x24, 0x97, 0x1F, 0xE1, 0xB0, 0x40), 0, 4321.1234 },
134134
{ CreateFromBytes(1, 2, 0x68, 0x22, 0x6C, 0x78, 0xBA, 0x49, 0x93, 0x40), 2, 1234.4321 }
135135
};
@@ -140,5 +140,29 @@ public void TestReadDouble(MemoryBuffer sut, int offset, double expected)
140140
{
141141
Check.That(sut.ReadDouble(offset)).IsCloseTo(expected, 0.0001);
142142
}
143+
144+
public static TheoryData<MemoryBuffer, Encoding, int, int, string> GetTestReadStringData() => new TheoryData<MemoryBuffer, Encoding, int, int, string>
145+
{
146+
{ CreateFromBytes(), Encoding.ASCII, 0, 0, string.Empty },
147+
{ CreateFromBytes(), Encoding.ASCII, 4, 0, string.Empty },
148+
{ CreateFromBytes(), Encoding.ASCII, 0, 4, string.Empty },
149+
{ CreateFromBytes(0x31, 0x32, 0x33, 0x61, 0x62, 0x63), Encoding.ASCII, 0, 6, "123abc" },
150+
{ CreateFromBytes(0x31, 0x32, 0x33, 0x61, 0x62, 0x63), Encoding.ASCII, 2, 3, "3ab" },
151+
{ CreateFromBytes(0, 0, 0, 0, 0, 0), Encoding.GetEncoding(1252), 0, 6, "......" },
152+
{ CreateFromBytes(0, 0, 0, 0, 0, 0), Encoding.UTF8, 0, 6, "......" },
153+
{ CreateFromBytes(0, 1, 2, 3, 4, 5), Encoding.UTF8, 0, 6, "......" },
154+
{ CreateFromBytes(0x31, 0x32, 0x33, 0x61, 0x62, 0x63, 0xC4, 0xD6, 0xDC), Encoding.GetEncoding(1252), 0, 9, "123abcÄÖÜ" },
155+
{ CreateFromBytes(0x31, 0x32, 0x33, 0x61, 0x62, 0x63, 0xC3, 0x84, 0xC3, 0x96, 0xC3, 0x9C), Encoding.UTF8, 0, 12, "123abcÄÖÜ" },
156+
{ CreateFromBytes(0x61, 0xC3), Encoding.UTF8, 0, 2, "a." },
157+
{ CreateFromBytes(0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0xC4, 0x00, 0xD6, 0x00, 0xDC, 0x00), Encoding.Unicode, 0, 18, "123abcÄÖÜ" },
158+
{ CreateFromBytes(0x31, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0xC4, 0x00, 0x00, 0x00, 0xD6, 0x00, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x00), Encoding.UTF32, 0, 36, "123abcÄÖÜ" }
159+
};
160+
161+
[Theory]
162+
[MemberData(nameof(GetTestReadStringData))]
163+
public void TestReadString(MemoryBuffer sut, Encoding encoding, int offset, int length, string expected)
164+
{
165+
Check.That(sut.ReadString(encoding, offset, length)).IsEqualTo(expected);
166+
}
143167
}
144168
}

0 commit comments

Comments
 (0)