Esempio n. 1
0
        public void testReadSingleBytes()
        {
            var u = new UnionInputStream();

            Assert.IsTrue(u.isEmpty());
            u.add(new MemoryStream(new byte[] { 1, 0, 2 }));
            u.add(new MemoryStream(new byte[] { 3 }));
            u.add(new MemoryStream(new byte[] { 4, 5 }));

            Assert.IsFalse(u.isEmpty());
            Assert.AreEqual(3, u.available());
            Assert.AreEqual(1, u.read());
            Assert.AreEqual(0, u.read());
            Assert.AreEqual(2, u.read());
            Assert.AreEqual(0, u.available());

            Assert.AreEqual(3, u.read());
            Assert.AreEqual(0, u.available());

            Assert.AreEqual(4, u.read());
            Assert.AreEqual(1, u.available());
            Assert.AreEqual(5, u.read());
            Assert.AreEqual(0, u.available());
            Assert.AreEqual(-1, u.read());

            Assert.IsTrue(u.isEmpty());
            u.add(new MemoryStream(new byte[] { (byte)255 }));
            Assert.AreEqual(255, u.read());
            Assert.AreEqual(-1, u.read());
            Assert.IsTrue(u.isEmpty());
        }
Esempio n. 2
0
        public void testSkip()
        {
            var u = new UnionInputStream();

            u.add(new MemoryStream(new byte[] { 1, 0, 2 }));
            u.add(new MemoryStream(new byte[] { 3 }));
            u.add(new MemoryStream(new byte[] { 4, 5 }));
            Assert.AreEqual(0, u.skip(0));
            Assert.AreEqual(4, u.skip(4));
            Assert.AreEqual(4, u.read());
            Assert.AreEqual(1, u.skip(5));
            Assert.AreEqual(0, u.skip(5));
            Assert.AreEqual(-1, u.read());

            u.add(new MockMemoryStream(new byte[] { 20, 30 }, null)); // can't mock skip behavior :-(
            Assert.AreEqual(2, u.skip(8));
            Assert.AreEqual(-1, u.read());
        }
Esempio n. 3
0
        public void testEmptyStream()
        {
            var u = new UnionInputStream();

            Assert.IsTrue(u.isEmpty());
            Assert.AreEqual(-1, u.read());
            Assert.AreEqual(-1, u.Read(new byte[1], 0, 1));
            Assert.AreEqual(0, u.available());
            Assert.AreEqual(0, u.skip(1));
            u.Close();
        }
Esempio n. 4
0
        public void testAutoCloseDuringRead()
        {
            var u      = new UnionInputStream();
            var closed = new bool[2];

            u.add(new MockMemoryStream(new byte[] { 1 }, () => { closed[0] = true; }));
            u.add(new MockMemoryStream(new byte[] { 2 }, () => { closed[1] = true; }));

            Assert.IsFalse(closed[0]);
            Assert.IsFalse(closed[1]);

            Assert.AreEqual(1, u.read());
            Assert.IsFalse(closed[0]);
            Assert.IsFalse(closed[1]);

            Assert.AreEqual(2, u.read());
            Assert.IsTrue(closed[0]);
            Assert.IsFalse(closed[1]);

            Assert.AreEqual(-1, u.read());
            Assert.IsTrue(closed[0]);
            Assert.IsTrue(closed[1]);
        }