Esempio n. 1
0
		public virtual void TestEmptyStream()
		{
			UnionInputStream u = new UnionInputStream();
			NUnit.Framework.Assert.IsTrue(u.IsEmpty());
			NUnit.Framework.Assert.AreEqual(-1, u.Read());
			NUnit.Framework.Assert.AreEqual(-1, u.Read(new byte[1], 0, 1));
			NUnit.Framework.Assert.AreEqual(0, u.Available());
			NUnit.Framework.Assert.AreEqual(0, u.Skip(1));
			u.Close();
		}
Esempio n. 2
0
 public virtual void TestArrayConstructor()
 {
     UnionInputStream u = new UnionInputStream(new ByteArrayInputStream(new byte[] { 1
         , 0, 2 }), new ByteArrayInputStream(new byte[] { 3 }), new ByteArrayInputStream(
         new byte[] { 4, 5 }));
     byte[] r = new byte[5];
     NUnit.Framework.Assert.AreEqual(3, u.Read(r, 0, 5));
     NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 1, 0, 2 }, Slice(r, 3)));
     NUnit.Framework.Assert.AreEqual(1, u.Read(r, 0, 5));
     NUnit.Framework.Assert.AreEqual(3, r[0]);
     NUnit.Framework.Assert.AreEqual(2, u.Read(r, 0, 5));
     NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 4, 5 }, Slice(r, 2)));
     NUnit.Framework.Assert.AreEqual(-1, u.Read(r, 0, 5));
 }
Esempio n. 3
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]);
        }
Esempio n. 4
0
        public virtual void TestNonBlockingPartialRead()
        {
            InputStream      errorReadStream = new _InputStream_245();
            UnionInputStream u = new UnionInputStream(new ByteArrayInputStream(new byte[] { 1
                                                                                            , 2, 3 }), errorReadStream);

            byte[] buf = new byte[10];
            NUnit.Framework.Assert.AreEqual(3, u.Read(buf, 0, 10));
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 1, 2, 3 }, Slice(buf, 3)
                                                        ));
            try
            {
                u.Read(buf, 0, 1);
                NUnit.Framework.Assert.Fail("Expected exception from errorReadStream");
            }
            catch (IOException e)
            {
                NUnit.Framework.Assert.AreEqual("Expected", e.Message);
            }
        }
Esempio n. 5
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());
		}
Esempio n. 6
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));
		}
Esempio n. 7
0
		public virtual void TestAutoCloseDuringRead()
		{
			UnionInputStream u = new UnionInputStream();
			bool[] closed = new bool[2];
			u.Add(new _ByteArrayInputStream_165(closed, new byte[] { 1 }));
			u.Add(new _ByteArrayInputStream_170(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]);
		}
Esempio n. 8
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(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());
		}
Esempio n. 9
0
 public virtual void TestNonBlockingPartialRead()
 {
     InputStream errorReadStream = new _InputStream_245();
     UnionInputStream u = new UnionInputStream(new ByteArrayInputStream(new byte[] { 1
         , 2, 3 }), errorReadStream);
     byte[] buf = new byte[10];
     NUnit.Framework.Assert.AreEqual(3, u.Read(buf, 0, 10));
     NUnit.Framework.Assert.IsTrue(Arrays.Equals(new byte[] { 1, 2, 3 }, Slice(buf, 3)
         ));
     try
     {
         u.Read(buf, 0, 1);
         NUnit.Framework.Assert.Fail("Expected exception from errorReadStream");
     }
     catch (IOException e)
     {
         NUnit.Framework.Assert.AreEqual("Expected", e.Message);
     }
 }