public static UnpackByteStream ( Stream source ) : |
||
source | Stream | The |
return |
public void TestUnpackByteStream_Nil_AsEmpty() { var target = Unpacking.UnpackByteStream(new MemoryStream(new byte[] { 0xC0 })); Assert.That(target, Is.Not.Null); Assert.That(target.Length, Is.EqualTo(0)); }
public void TestUnseekableByteStream_setPosition() { using (var target = Unpacking.UnpackByteStream(new WrapperStream(new MemoryStream(new byte[] { 0xA1, 0xFF }), canSeek: false))) { Assert.Throws <NotSupportedException>(() => target.Position = 0); } }
public void TestUnpackByteStream_EofInHeader() { using (var underlying = new MemoryStream(new byte[] { 0xDA, 0x1 })) { Assert.Throws <UnpackException>(() => Unpacking.UnpackByteStream(underlying)); } }
public void TestUnseekableByteStream_Seek() { using (var target = Unpacking.UnpackByteStream(new WrapperStream(new MemoryStream(new byte[] { 0xA1, 0xFF }), canSeek: false))) { Assert.Throws <NotSupportedException>(() => target.Seek(0, SeekOrigin.Current)); } }
public void TestUnpackByteStream_Stream_SeekableStream_CanSeekIsFalse() { using (var stream = new WrapperStream(new MemoryStream(new byte[] { 0xA0, 0x57 }), canRead: true, canSeek: false)) { using (var result = Unpacking.UnpackByteStream(stream)) { Assert.That(result.CanSeek, Is.False); } } }
public void TestUnpackByteStream_Stream_0x10000Byte_AsIsAndBounded() { using (var stream = new MemoryStream(new byte[] { 0xDB, 0x00, 0x01, 0x00, 0x00 }.Concat(Enumerable.Repeat(( byte )0xFF, 0x10000)).Concat(Enumerable.Repeat(( byte )0x57, 1)).ToArray())) { using (var result = Unpacking.UnpackByteStream(stream)) { AssertRawStream(result, 0x10000); } // Assert is valid position on unerlying stream. Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(0x57)); } }
public void TestUnpackByteStream_Stream_1Byte_AsIsAndBounded() { using (var stream = new MemoryStream(new byte[] { 0xA1, 0xFF, 0x57 })) { using (var result = Unpacking.UnpackByteStream(stream)) { AssertRawStream(result, 1); } // Assert is valid position on unerlying stream. Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(0x57)); } }
public void TestUnpackByteStream_EofInBody_CanFeed() { using (var underlying = new MemoryStream()) { underlying.WriteByte(0xA1); underlying.Position = 0; var target = Unpacking.UnpackByteStream(underlying); Assert.That(target.Length, Is.EqualTo(1)); // Check precondition var b = target.ReadByte(); Assert.That(b, Is.EqualTo(-1)); // Feed // Assume that underlying supports Feed (appends bytes to tail, and does not move Position). underlying.WriteByte(0x57); underlying.Position -= 1; b = target.ReadByte(); Assert.That(b, Is.EqualTo(0x57)); } }
public void TestUnpackByteStream_Stream_LengthIsGreaterThanInt32MaxValue_CanReadToEnd() { // Header + Body Length ( Int32.MaxValue + 1 ) var bodyLength = Int32.MaxValue + 1L; var length = 1L + 4L + bodyLength; string filePath = Path.GetTempFileName(); try { File.SetAttributes(filePath, FileAttributes.SparseFile); using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 64 * 1024)) { fileStream.SetLength(length); fileStream.Position = 0; fileStream.Write(new byte[] { 0xDB, 0x80, 0x00, 0x00, 0x00 }, 0, 5); fileStream.Flush(); fileStream.Position = 0; using (var target = Unpacking.UnpackByteStream(fileStream)) { Assert.That(target.Length, Is.EqualTo(bodyLength)); byte[] buffer = new byte[64 * 1024]; long totalLength = 0; for (int read = target.Read(buffer, 0, buffer.Length); read > 0; read = target.Read(buffer, 0, buffer.Length)) { totalLength += read; } Assert.That(totalLength, Is.EqualTo(bodyLength)); } } } finally { File.Delete(filePath); } }
private static Stream CreateStreamForByteStreamTest() { // Positin == Value return(Unpacking.UnpackByteStream(new MemoryStream(new byte[] { 0xA3, 0x0, 0x1, 0x2 }))); }
public void TestUnpackByteStream_NotRaw() { Assert.Throws <MessageTypeException>(() => Unpacking.UnpackByteStream(new MemoryStream(new byte[] { 0x80 }))); }
public void TestUnpackByteStream_Empty() { Assert.Throws <UnpackException>(() => Unpacking.UnpackByteStream(new MemoryStream())); }
public void TestUnpackByteStream_Stream_Null() { Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackByteStream(null)); }