Ejemplo 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());
        }
Ejemplo n.º 2
0
        public void testMarkSupported()
        {
            var u = new UnionInputStream();

            Assert.IsFalse(u.markSupported());
            u.add(new MemoryStream(new byte[] { 1, 0, 2 }));
            Assert.IsFalse(u.markSupported());
        }
Ejemplo 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();
        }
Ejemplo n.º 4
0
 internal Service(TransportHttp _enclosing, string serviceName)
 {
     this._enclosing  = _enclosing;
     this.serviceName = serviceName;
     this.requestType = "application/x-" + serviceName + "-request";
     //$NON-NLS-1$ //$NON-NLS-2$
     this.responseType = "application/x-" + serviceName + "-result";
     //$NON-NLS-1$ //$NON-NLS-2$
     this.execute = new TransportHttp.Service.HttpExecuteStream(this);
     this.@in     = new UnionInputStream(this.execute);
     this.@out    = new TransportHttp.Service.HttpOutputStream(this);
 }
Ejemplo n.º 5
0
        public void testArrayConstructor()
        {
            var u = new UnionInputStream(
                new MemoryStream(new byte[] { 1, 0, 2 }),
                new MemoryStream(new byte[] { 3 }),
                new MemoryStream(new byte[] { 4, 5 }));

            var r = new byte[5];

            Assert.AreEqual(5, u.Read(r, 0, 5));
            Assert.IsTrue(r.SequenceEqual(new byte[] { 1, 0, 2, 3, 4 }));
            Assert.AreEqual(1, u.Read(r, 0, 5));
            Assert.AreEqual(5, r[0]);
            Assert.AreEqual(-1, u.Read(r, 0, 5));
        }
Ejemplo n.º 6
0
        public void testReadByteBlocks()
        {
            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 }));

            var r = new byte[5];

            Assert.AreEqual(5, u.Read(r, 0, 5));
            Assert.IsTrue(r.SequenceEqual(new byte[] { 1, 0, 2, 3, 4 }));
            Assert.AreEqual(1, u.Read(r, 0, 5));
            Assert.AreEqual(5, r[0]);
            Assert.AreEqual(-1, u.Read(r, 0, 5));
        }
Ejemplo n.º 7
0
        public void testExceptionDuringClose()
        {
            var u = new UnionInputStream();

            u.add(new MockMemoryStream(new byte[] { 1 }, () => { throw new IOException("I AM A TEST"); }));

            try
            {
                u.Close();
                Assert.Fail("close ignored inner stream exception");
            }
            catch (IOException e)
            {
                Assert.AreEqual("I AM A TEST", e.Message);
            }
        }
Ejemplo n.º 8
0
        public void testCloseDuringClose()
        {
            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]);

            u.Close();

            Assert.IsTrue(closed[0]);
            Assert.IsTrue(closed[1]);
        }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
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]);
        }