예제 #1
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));
        }
예제 #2
0
        public void TestSetLength()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            stream.SetLength(10);
        }
예제 #3
0
        public void TestFlush()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            stream.Flush();
        }
예제 #4
0
        public void TestUnknowSeek()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            stream.Seek(11, (SeekOrigin)100);
        }
예제 #5
0
        public void TestWrite()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            stream.Write(new byte[5], 0, 1);
        }
예제 #6
0
        public void TestSeekOutOfRange()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            stream.Seek(11, SeekOrigin.Begin);
        }
예제 #7
0
        public void TestCombineStream()
        {
            var mem1 = "hello".ToStream();
            var mem2 = "world".ToStream();

            var stream = new CombineStream(mem1, mem2);

            Assert.AreEqual("helloworld", stream.ToText());
        }
예제 #8
0
        public void TestGetContstValue()
        {
            var mem1   = "hello".ToStream();
            var mem2   = "world".ToStream();
            var stream = new CombineStream(mem1, mem2);

            Assert.AreEqual(false, stream.CanWrite);
            Assert.AreEqual(true, stream.CanSeek);
            Assert.AreEqual(true, stream.CanRead);
        }
예제 #9
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));
        }
예제 #10
0
        public void TestDispose()
        {
            var mem1 = "hello".ToStream();
            var mem2 = "world".ToStream();

            Assert.AreEqual(true, mem1.CanWrite);
            Assert.AreEqual(true, mem2.CanWrite);

            using (var stream = new CombineStream(mem1, mem2, true))
            {
            }

            Assert.AreEqual(false, mem1.CanWrite);
            Assert.AreEqual(false, mem2.CanWrite);
        }
예제 #11
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));
        }
예제 #12
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));
        }
예제 #13
0
        public void TestCannotSeekStreamSetPosition()
        {
            var stream = new CombineStream("hello".ToStream(), new CannotSeekStream());

            stream.Seek(0, SeekOrigin.Begin);
        }
예제 #14
0
        public void TestCannotSeekStream()
        {
            var stream = new CombineStream("hello".ToStream(), new CannotSeekStream());

            Assert.AreEqual(false, stream.CanSeek);
        }