Add some more tests for BinaryReader

This commit is contained in:
Matt Nadareski
2024-04-25 20:29:21 -04:00
parent 245ca9010a
commit 8d1bc3957c
3 changed files with 47 additions and 1 deletions

View File

@@ -9,10 +9,12 @@ using Xunit;
namespace SabreTools.IO.Test.Extensions
{
// TODO: Add byte[], char[] tests
// TODO: Add string reading tests
public class BinaryReaderExtensionsTests
{
/// <summary>
/// Test pattern from 0x00-0x0F
/// </summary>
private static readonly byte[] _bytes =
[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -28,6 +30,44 @@ namespace SabreTools.IO.Test.Extensions
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00,
];
[Fact]
public void ReadByteTest()
{
var stream = new MemoryStream(_bytes);
var br = new BinaryReader(stream);
byte read = br.ReadByte();
Assert.Equal(0x00, read);
}
[Fact]
public void ReadBytesTest()
{
var stream = new MemoryStream(_bytes);
var br = new BinaryReader(stream);
int length = 4;
byte[] read = br.ReadBytes(length);
Assert.Equal(length, read.Length);
Assert.True(read.SequenceEqual(_bytes.Take(length)));
}
[Fact]
public void ReadSByteTest()
{
var stream = new MemoryStream(_bytes);
var br = new BinaryReader(stream);
sbyte read = br.ReadSByte();
Assert.Equal(0x00, read);
}
[Fact]
public void ReadCharTest()
{
var stream = new MemoryStream(_bytes);
var br = new BinaryReader(stream);
char read = br.ReadChar();
Assert.Equal('\0', read);
}
[Fact]
public void ReadInt16Test()
{

View File

@@ -11,6 +11,9 @@ namespace SabreTools.IO.Test.Extensions
// TODO: Add string reading tests
public class ByteArrayExtensionsReadTests
{
/// <summary>
/// Test pattern from 0x00-0x0F
/// </summary>
private static readonly byte[] _bytes =
[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,

View File

@@ -12,6 +12,9 @@ namespace SabreTools.IO.Test.Extensions
// TODO: Add string reading tests
public class StreamExtensionsReadTests
{
/// <summary>
/// Test pattern from 0x00-0x0F
/// </summary>
private static readonly byte[] _bytes =
[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,