// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.IO; using System.Text; using SixLabors.ImageSharp.IO; using Xunit; namespace SixLabors.ImageSharp.Tests.IO { /// /// The endian binary reader tests. /// public class EndianBinaryReaderTests { /// /// The test string. /// private const string TestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz"; /// /// The test bytes. /// private static readonly byte[] TestBytes = Encoding.ASCII.GetBytes(TestString); /// /// Tests to ensure that the reader can read beyond internal buffer size. /// [Fact] public void ReadCharsBeyondInternalBufferSize() { MemoryStream stream = new MemoryStream(TestBytes); using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length]; subject.Read(chars, 0, chars.Length); Assert.Equal(TestString, new string(chars)); } } /// /// Tests to ensure that the reader cannot read beyond the provided buffer size. /// [Fact] public void ReadCharsBeyondProvidedBufferSize() { Assert.Throws( () => { MemoryStream stream = new MemoryStream(TestBytes); using (EndianBinaryReader subject = new EndianBinaryReader(Endianness.LittleEndian, stream)) { char[] chars = new char[TestString.Length - 1]; subject.Read(chars, 0, TestString.Length); } }); } } }