コード例 #1
0
        public virtual void TestReadSingleBytes()
        {
            UnionInputStream u = new UnionInputStream();

            NUnit.Framework.Assert.IsTrue(u.IsEmpty());
            u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
            u.Add(new ByteArrayInputStream(new byte[] { 3 }));
            u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
            NUnit.Framework.Assert.IsFalse(u.IsEmpty());
            NUnit.Framework.Assert.AreEqual(3, u.Available());
            NUnit.Framework.Assert.AreEqual(1, u.Read());
            NUnit.Framework.Assert.AreEqual(0, u.Read());
            NUnit.Framework.Assert.AreEqual(2, u.Read());
            NUnit.Framework.Assert.AreEqual(0, u.Available());
            NUnit.Framework.Assert.AreEqual(3, u.Read());
            NUnit.Framework.Assert.AreEqual(0, u.Available());
            NUnit.Framework.Assert.AreEqual(4, u.Read());
            NUnit.Framework.Assert.AreEqual(1, u.Available());
            NUnit.Framework.Assert.AreEqual(5, u.Read());
            NUnit.Framework.Assert.AreEqual(0, u.Available());
            NUnit.Framework.Assert.AreEqual(-1, u.Read());
            NUnit.Framework.Assert.IsTrue(u.IsEmpty());
            u.Add(new ByteArrayInputStream(new byte[] { unchecked ((byte)255) }));
            NUnit.Framework.Assert.AreEqual(255, u.Read());
            NUnit.Framework.Assert.AreEqual(-1, u.Read());
            NUnit.Framework.Assert.IsTrue(u.IsEmpty());
        }
コード例 #2
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestReadSingleBytes()
		{
			UnionInputStream u = new UnionInputStream();
			NUnit.Framework.Assert.IsTrue(u.IsEmpty());
			u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
			u.Add(new ByteArrayInputStream(new byte[] { 3 }));
			u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
			NUnit.Framework.Assert.IsFalse(u.IsEmpty());
			NUnit.Framework.Assert.AreEqual(3, u.Available());
			NUnit.Framework.Assert.AreEqual(1, u.Read());
			NUnit.Framework.Assert.AreEqual(0, u.Read());
			NUnit.Framework.Assert.AreEqual(2, u.Read());
			NUnit.Framework.Assert.AreEqual(0, u.Available());
			NUnit.Framework.Assert.AreEqual(3, u.Read());
			NUnit.Framework.Assert.AreEqual(0, u.Available());
			NUnit.Framework.Assert.AreEqual(4, u.Read());
			NUnit.Framework.Assert.AreEqual(1, u.Available());
			NUnit.Framework.Assert.AreEqual(5, u.Read());
			NUnit.Framework.Assert.AreEqual(0, u.Available());
			NUnit.Framework.Assert.AreEqual(-1, u.Read());
			NUnit.Framework.Assert.IsTrue(u.IsEmpty());
			u.Add(new ByteArrayInputStream(new byte[] { unchecked((byte)255) }));
			NUnit.Framework.Assert.AreEqual(255, u.Read());
			NUnit.Framework.Assert.AreEqual(-1, u.Read());
			NUnit.Framework.Assert.IsTrue(u.IsEmpty());
		}
コード例 #3
0
        public virtual void TestCloseDuringClose()
        {
            UnionInputStream u = new UnionInputStream();

            bool[] closed = new bool[2];
            u.Add(new _ByteArrayInputStream_207(closed, new byte[] { 1 }));
            u.Add(new _ByteArrayInputStream_212(closed, new byte[] { 2 }));
            NUnit.Framework.Assert.IsFalse(closed[0]);
            NUnit.Framework.Assert.IsFalse(closed[1]);
            u.Close();
            NUnit.Framework.Assert.IsTrue(closed[0]);
            NUnit.Framework.Assert.IsTrue(closed[1]);
        }
コード例 #4
0
        public virtual void TestReadByteBlocks()
        {
            UnionInputStream u = new UnionInputStream();

            u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
            u.Add(new ByteArrayInputStream(new byte[] { 3 }));
            u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
            byte[] r = new byte[5];
            NUnit.Framework.Assert.AreEqual(5, u.Read(r, 0, 5));
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 1, 0, 2, 3, 4 }, r));
            NUnit.Framework.Assert.AreEqual(1, u.Read(r, 0, 5));
            NUnit.Framework.Assert.AreEqual(5, r[0]);
            NUnit.Framework.Assert.AreEqual(-1, u.Read(r, 0, 5));
        }
コード例 #5
0
        public virtual void TestSkip()
        {
            UnionInputStream u = new UnionInputStream();

            u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
            u.Add(new ByteArrayInputStream(new byte[] { 3 }));
            u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
            NUnit.Framework.Assert.AreEqual(0, u.Skip(0));
            NUnit.Framework.Assert.AreEqual(3, u.Skip(3));
            NUnit.Framework.Assert.AreEqual(3, u.Read());
            NUnit.Framework.Assert.AreEqual(2, u.Skip(5));
            NUnit.Framework.Assert.AreEqual(0, u.Skip(5));
            NUnit.Framework.Assert.AreEqual(-1, u.Read());
            u.Add(new _ByteArrayInputStream_163(new byte[] { 20, 30 }));
            NUnit.Framework.Assert.AreEqual(2, u.Skip(8));
            NUnit.Framework.Assert.AreEqual(-1, u.Read());
        }
コード例 #6
0
        public virtual void TestMarkSupported()
        {
            UnionInputStream u = new UnionInputStream();

            NUnit.Framework.Assert.IsFalse(u.MarkSupported());
            u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
            NUnit.Framework.Assert.IsFalse(u.MarkSupported());
        }
コード例 #7
0
 public virtual void TestAutoCloseDuringRead()
 {
     UnionInputStream u = new UnionInputStream();
     bool[] closed = new bool[2];
     u.Add(new _ByteArrayInputStream_176(closed, new byte[] { 1 }));
     u.Add(new _ByteArrayInputStream_181(closed, new byte[] { 2 }));
     NUnit.Framework.Assert.IsFalse(closed[0]);
     NUnit.Framework.Assert.IsFalse(closed[1]);
     NUnit.Framework.Assert.AreEqual(1, u.Read());
     NUnit.Framework.Assert.IsFalse(closed[0]);
     NUnit.Framework.Assert.IsFalse(closed[1]);
     NUnit.Framework.Assert.AreEqual(2, u.Read());
     NUnit.Framework.Assert.IsTrue(closed[0]);
     NUnit.Framework.Assert.IsFalse(closed[1]);
     NUnit.Framework.Assert.AreEqual(-1, u.Read());
     NUnit.Framework.Assert.IsTrue(closed[0]);
     NUnit.Framework.Assert.IsTrue(closed[1]);
 }
コード例 #8
0
        public virtual void TestAutoCloseDuringRead()
        {
            UnionInputStream u = new UnionInputStream();

            bool[] closed = new bool[2];
            u.Add(new _ByteArrayInputStream_176(closed, new byte[] { 1 }));
            u.Add(new _ByteArrayInputStream_181(closed, new byte[] { 2 }));
            NUnit.Framework.Assert.IsFalse(closed[0]);
            NUnit.Framework.Assert.IsFalse(closed[1]);
            NUnit.Framework.Assert.AreEqual(1, u.Read());
            NUnit.Framework.Assert.IsFalse(closed[0]);
            NUnit.Framework.Assert.IsFalse(closed[1]);
            NUnit.Framework.Assert.AreEqual(2, u.Read());
            NUnit.Framework.Assert.IsTrue(closed[0]);
            NUnit.Framework.Assert.IsFalse(closed[1]);
            NUnit.Framework.Assert.AreEqual(-1, u.Read());
            NUnit.Framework.Assert.IsTrue(closed[0]);
            NUnit.Framework.Assert.IsTrue(closed[1]);
        }
コード例 #9
0
        public virtual void TestExceptionDuringClose()
        {
            UnionInputStream u = new UnionInputStream();

            u.Add(new _ByteArrayInputStream_230(new byte[] { 1 }));
            try
            {
                u.Close();
                NUnit.Framework.Assert.Fail("close ignored inner stream exception");
            }
            catch (IOException e)
            {
                NUnit.Framework.Assert.AreEqual("I AM A TEST", e.Message);
            }
        }
コード例 #10
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestReadByteBlocks()
		{
			UnionInputStream u = new UnionInputStream();
			u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
			u.Add(new ByteArrayInputStream(new byte[] { 3 }));
			u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
			byte[] r = new byte[5];
			NUnit.Framework.Assert.AreEqual(5, u.Read(r, 0, 5));
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 1, 0, 2, 3, 4 }, r));
			NUnit.Framework.Assert.AreEqual(1, u.Read(r, 0, 5));
			NUnit.Framework.Assert.AreEqual(5, r[0]);
			NUnit.Framework.Assert.AreEqual(-1, u.Read(r, 0, 5));
		}
コード例 #11
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestExceptionDuringClose()
		{
			UnionInputStream u = new UnionInputStream();
			u.Add(new _ByteArrayInputStream_219(new byte[] { 1 }));
			try
			{
				u.Close();
				NUnit.Framework.Assert.Fail("close ignored inner stream exception");
			}
			catch (IOException e)
			{
				NUnit.Framework.Assert.AreEqual("I AM A TEST", e.Message);
			}
		}
コード例 #12
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestCloseDuringClose()
		{
			UnionInputStream u = new UnionInputStream();
			bool[] closed = new bool[2];
			u.Add(new _ByteArrayInputStream_196(closed, new byte[] { 1 }));
			u.Add(new _ByteArrayInputStream_201(closed, new byte[] { 2 }));
			NUnit.Framework.Assert.IsFalse(closed[0]);
			NUnit.Framework.Assert.IsFalse(closed[1]);
			u.Close();
			NUnit.Framework.Assert.IsTrue(closed[0]);
			NUnit.Framework.Assert.IsTrue(closed[1]);
		}
コード例 #13
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestSkip()
		{
			UnionInputStream u = new UnionInputStream();
			u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
			u.Add(new ByteArrayInputStream(new byte[] { 3 }));
			u.Add(new ByteArrayInputStream(new byte[] { 4, 5 }));
			NUnit.Framework.Assert.AreEqual(0, u.Skip(0));
			NUnit.Framework.Assert.AreEqual(4, u.Skip(4));
			NUnit.Framework.Assert.AreEqual(4, u.Read());
			NUnit.Framework.Assert.AreEqual(1, u.Skip(5));
			NUnit.Framework.Assert.AreEqual(0, u.Skip(5));
			NUnit.Framework.Assert.AreEqual(-1, u.Read());
			u.Add(new _ByteArrayInputStream_152(new byte[] { 20, 30 }));
			NUnit.Framework.Assert.AreEqual(2, u.Skip(8));
			NUnit.Framework.Assert.AreEqual(-1, u.Read());
		}
コード例 #14
0
ファイル: UnionInputStreamTest.cs プロジェクト: shoff/ngit
		public virtual void TestMarkSupported()
		{
			UnionInputStream u = new UnionInputStream();
			NUnit.Framework.Assert.IsFalse(u.MarkSupported());
			u.Add(new ByteArrayInputStream(new byte[] { 1, 0, 2 }));
			NUnit.Framework.Assert.IsFalse(u.MarkSupported());
		}