Esempio n. 1
0
        public void TestCombineStream2()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            var buffer = new byte[5];

            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("hello", Str.Encoding.GetString(buffer));
            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("world", Str.Encoding.GetString(buffer));
        }
Esempio n. 2
0
        public void TestSetPosition()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            var buffer = new byte[5];

            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("hello", Util.Encoding.GetString(buffer));

            Assert.AreEqual(5, stream.Position);
            stream.Position = 0;
            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("hello", Util.Encoding.GetString(buffer));
        }
Esempio n. 3
0
        public void TestCombineSeek2()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            var buffer = new byte[5];

            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("hello", Str.Encoding.GetString(buffer));
            stream.Seek(2, SeekOrigin.Current);
            Assert.AreEqual(3, stream.Read(buffer, 0, 5));
            Assert.AreEqual("rld", Str.Encoding.GetString(buffer, 0, 3));
            stream.Seek(-3, SeekOrigin.End);
            Assert.AreEqual(3, stream.Read(buffer, 0, 5));
            Assert.AreEqual("rld", Str.Encoding.GetString(buffer, 0, 3));
        }
Esempio n. 4
0
        public void TestCombineSeek()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            var buffer = new byte[5];

            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("hello", Str.Encoding.GetString(buffer));
            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("world", Str.Encoding.GetString(buffer));

            stream.Seek(5, SeekOrigin.Begin);
            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("world", Str.Encoding.GetString(buffer));

            stream.Seek(4, SeekOrigin.Begin);
            Assert.AreEqual(5, stream.Read(buffer, 0, 5));
            Assert.AreEqual("oworl", Str.Encoding.GetString(buffer));
            stream.Seek(6, SeekOrigin.Begin);
            Assert.AreEqual(4, stream.Read(buffer, 0, 5));
            Assert.AreEqual("orld", Str.Encoding.GetString(buffer, 0, 4));
            stream.Seek(10, SeekOrigin.Begin);
            Assert.AreEqual(0, stream.Read(buffer, 0, 5));
            Assert.AreEqual(0, stream.Read(buffer, 0, 5));
        }