示例#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
        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 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());
        }
示例#4
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();
		}
示例#5
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();
        }
示例#6
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(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));
        }
示例#7
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]);
        }
示例#8
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));
 }
示例#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
        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(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));
        }
示例#11
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());
        }
示例#12
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]);
 }
示例#13
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]);
        }
示例#14
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);
            }
        }
示例#15
0
		/// <exception cref="System.IO.IOException"></exception>
		public virtual Note Merge(Note @base, Note ours, Note theirs, ObjectReader reader
			, ObjectInserter inserter)
		{
			if (ours == null)
			{
				return theirs;
			}
			if (theirs == null)
			{
				return ours;
			}
			if (ours.GetData().Equals(theirs.GetData()))
			{
				return ours;
			}
			ObjectLoader lo = reader.Open(ours.GetData());
			ObjectLoader lt = reader.Open(theirs.GetData());
			UnionInputStream union = new UnionInputStream(lo.OpenStream(), lt.OpenStream());
			ObjectId noteData = inserter.Insert(Constants.OBJ_BLOB, lo.GetSize() + lt.GetSize
				(), union);
			return new Note(ours, noteData);
		}
示例#16
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));
		}
示例#17
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);
     }
 }
示例#18
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());
		}
示例#19
0
		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);
			}
		}
示例#20
0
		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]);
		}
示例#21
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());
		}