コード例 #1
0
		public void TestReadByte()
		{
			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				List<byte> result = new List<byte>();
				for ( int b = target.ReadByte(); 0 < b; b = target.ReadByte() )
				{
					result.Add( ( byte )b );
				}

				Assert.That( result, Is.EqualTo( new byte[] { 12, 13, 14, 22, 23, 24, 32, 33, 34 } ) );
			}
		}
コード例 #2
0
		public void TestRead()
		{
			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				byte[] buffer = new byte[ 2 ];
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 2 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 12, 13 } ) );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 2 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 14, 22 } ) );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 2 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 23, 24 } ) );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 2 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 32, 33 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 1 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 34, 0 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 0 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 0, 0 } ) );
			}

			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				byte[] buffer = new byte[ 3 ];
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 3 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 12, 13, 14 } ) );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 3 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 22, 23, 24 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 3 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 32, 33, 34 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 0 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 0, 0, 0 } ) );
			}

			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				byte[] buffer = new byte[ 4 ];
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 4 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 12, 13, 14, 22 } ) );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 4 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 23, 24, 32, 33 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 1 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 34, 0, 0, 0 } ) );
				Array.Clear( buffer, 0, buffer.Length );
				Assert.That( target.Read( buffer, 0, buffer.Length ), Is.EqualTo( 0 ) );
				Assert.That( buffer, Is.EqualTo( new byte[] { 0, 0, 0, 0 } ) );
			}
		}
コード例 #3
0
        public void TestRead()
        {
            using (var target = new ByteArraySegmentStream(CreateData()))
            {
                byte[] buffer = new byte[2];
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(2));
                Assert.That(buffer, Is.EqualTo(new byte[] { 12, 13 }));
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(2));
                Assert.That(buffer, Is.EqualTo(new byte[] { 14, 22 }));
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(2));
                Assert.That(buffer, Is.EqualTo(new byte[] { 23, 24 }));
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(2));
                Assert.That(buffer, Is.EqualTo(new byte[] { 32, 33 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(1));
                Assert.That(buffer, Is.EqualTo(new byte[] { 34, 0 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(0));
                Assert.That(buffer, Is.EqualTo(new byte[] { 0, 0 }));
            }

            using (var target = new ByteArraySegmentStream(CreateData()))
            {
                byte[] buffer = new byte[3];
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(3));
                Assert.That(buffer, Is.EqualTo(new byte[] { 12, 13, 14 }));
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(3));
                Assert.That(buffer, Is.EqualTo(new byte[] { 22, 23, 24 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(3));
                Assert.That(buffer, Is.EqualTo(new byte[] { 32, 33, 34 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(0));
                Assert.That(buffer, Is.EqualTo(new byte[] { 0, 0, 0 }));
            }

            using (var target = new ByteArraySegmentStream(CreateData()))
            {
                byte[] buffer = new byte[4];
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(4));
                Assert.That(buffer, Is.EqualTo(new byte[] { 12, 13, 14, 22 }));
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(4));
                Assert.That(buffer, Is.EqualTo(new byte[] { 23, 24, 32, 33 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(1));
                Assert.That(buffer, Is.EqualTo(new byte[] { 34, 0, 0, 0 }));
                Array.Clear(buffer, 0, buffer.Length);
                Assert.That(target.Read(buffer, 0, buffer.Length), Is.EqualTo(0));
                Assert.That(buffer, Is.EqualTo(new byte[] { 0, 0, 0, 0 }));
            }
        }
コード例 #4
0
			public DebuggerProxy( ByteArraySegmentStream source )
			{
				this._source = source;
			}
コード例 #5
0
		public void TestGetBuffer_Int64_Int64_Empty_Empty()
		{
			using ( var target = new ByteArraySegmentStream( new ArraySegment<byte>[ 0 ] ) )
			{
				var result = target.GetBuffer( 0, 1 );
				Assert.That( result, Is.Not.Null.And.Empty );
			}
		}
コード例 #6
0
		public void TestSeek_End()
		{
			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );
				target.Seek( -target.Length, SeekOrigin.End );
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );

				target.Seek( 0, SeekOrigin.End );
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );

				target.Seek( -4, SeekOrigin.End );
				Assert.That( target.ReadByte(), Is.EqualTo( 24 ) );
				target.Seek( -3, SeekOrigin.End );
				Assert.That( target.ReadByte(), Is.EqualTo( 32 ) );

				target.Seek( -1, SeekOrigin.End );
				Assert.That( target.ReadByte(), Is.EqualTo( 34 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
			}
		}
コード例 #7
0
		public void TestSeek_Begin()
		{
			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );
				target.Seek( 0, SeekOrigin.Begin );
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );

				target.Seek( target.Length, SeekOrigin.Begin );
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );

				target.Seek( 3, SeekOrigin.Begin );
				Assert.That( target.ReadByte(), Is.EqualTo( 22 ) );
				target.Seek( 2, SeekOrigin.Begin );
				Assert.That( target.ReadByte(), Is.EqualTo( 14 ) );

				target.Seek( target.Length - 1, SeekOrigin.Begin );
				Assert.That( target.ReadByte(), Is.EqualTo( 34 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
			}
		}
コード例 #8
0
		public void TestPosition()
		{
			using ( var target = new ByteArraySegmentStream( CreateData() ) )
			{
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );
				target.Position = 0;
				Assert.That( target.Position, Is.EqualTo( 0 ) );
				Assert.That( target.ReadByte(), Is.EqualTo( 12 ) );

				target.Position = target.Length;
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );

				target.Position = 3;
				Assert.That( target.ReadByte(), Is.EqualTo( 22 ) );
				target.Position = 2;
				Assert.That( target.ReadByte(), Is.EqualTo( 14 ) );

				target.Position = target.Length - 1;
				Assert.That( target.ReadByte(), Is.EqualTo( 34 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
				Assert.That( target.ReadByte(), Is.EqualTo( -1 ) );
				Assert.That( target.Position, Is.EqualTo( target.Length ) );
			}
		}
コード例 #9
0
 public DebuggerProxy(ByteArraySegmentStream source)
 {
     this._source = source;
 }