mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.3 KiB
58 lines
2.3 KiB
// 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
|
|
{
|
|
/// <summary>
|
|
/// Ensures that the data written through a binary writer can be read back through the reader
|
|
/// </summary>
|
|
[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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|