diff --git a/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs b/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs index 87adead33..fcf484f49 100644 --- a/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs +++ b/tests/ImageSharp.Tests/IO/EndianBinaryReaderTests.cs @@ -30,8 +30,8 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void ReadCharsBeyondInternalBufferSize() { - MemoryStream stream = new MemoryStream(TestBytes); - using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) + var stream = new MemoryStream(TestBytes); + using (var subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length]; subject.Read(chars, 0, chars.Length); @@ -48,8 +48,8 @@ namespace SixLabors.ImageSharp.Tests.IO Assert.Throws( () => { - MemoryStream stream = new MemoryStream(TestBytes); - using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) + var stream = new MemoryStream(TestBytes); + using (var subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length - 1]; diff --git a/tests/ImageSharp.Tests/IO/EndianBinaryReaderWriterTests.cs b/tests/ImageSharp.Tests/IO/EndianBinaryReaderWriterTests.cs new file mode 100644 index 000000000..6c639693a --- /dev/null +++ b/tests/ImageSharp.Tests/IO/EndianBinaryReaderWriterTests.cs @@ -0,0 +1,58 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.IO; +using SixLabors.ImageSharp.IO; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.IO +{ + public class EndianBinaryReaderWriterTests + { + /// + /// Ensures that the data written through a binary writer can be read back through the reader + /// + [Fact] + public void RoundtripValues() + { + foreach (Endianness endianness in new[] { Endianness.BigEndian, Endianness.LittleEndian }) + { + var stream = new MemoryStream(); + + var writer = new EndianBinaryWriter(endianness, stream); + + writer.Write(true); // Bool + writer.Write((byte)1); // Byte + writer.Write((short)1); // Int16 + writer.Write(1); // Int32 + writer.Write(1L); // Int64 + writer.Write(1f); // Single + writer.Write(1d); // Double + writer.Write((sbyte)1); // SByte + writer.Write((ushort)1); // UInt16 + writer.Write((uint)1); // UInt32 + writer.Write(1UL); // ULong + + Assert.Equal(43, stream.Length); + + stream.Position = 0; + + var reader = new EndianBinaryReader(endianness, stream); + + Assert.True(reader.ReadBoolean()); // Bool + Assert.Equal((byte)1, reader.ReadByte()); // Byte + Assert.Equal((short)1, reader.ReadInt16()); // Int16 + Assert.Equal(1, reader.ReadInt32()); // Int32 + Assert.Equal(1L, reader.ReadInt64()); // Int64 + Assert.Equal(1f, reader.ReadSingle()); // Single + Assert.Equal(1d, reader.ReadDouble()); // Double + Assert.Equal((sbyte)1, reader.ReadSByte()); // SByte + Assert.Equal((ushort)1, reader.ReadUInt16()); // UInt16 + Assert.Equal((uint)1, reader.ReadUInt32()); // UInt32 + Assert.Equal(1UL, reader.ReadUInt64()); // ULong + + stream.Dispose(); + } + } + } +}