예제 #1
0
        public void BlockOffset()
        {
            BlockStream s;
            BlockArray  ba;

            s = new BlockStream(0, 10, 5);
            for (int i = 0; i < 20; i++)
            {
                s.WriteByte((byte)i);
            }

            ba = s.ToBlocks(false);
            Assert.Equal(4, ba.Count);
            for (int i = 0; i < ba.Count; i++)
            {
                Block b = ba.GetBlock(i);

                Assert.Equal(5, b.Length);
                Assert.Equal(5, b.Offset);
                for (int j = 0; j < 5; j++)
                {
                    Assert.Equal(i * 5 + j, (int)b.Buffer[b.Offset + j]);
                }
            }
        }
예제 #2
0
        public void ReadWriteByte()
        {
            BlockStream s;
            int         cb;

            s  = new BlockStream();
            cb = 1024 * 1024;

            Assert.Equal(-1, s.ReadByte());
            Assert.Equal(0, s.Length);
            Assert.Equal(0, s.Position);

            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
            }

            s.Position = 0;

            for (int i = 0; i < cb; i++)
            {
                Assert.Equal((byte)i, s.ReadByte());
            }

            Assert.Equal(cb, s.Length);
            Assert.Equal(cb, s.Position);
            Assert.Equal(-1, s.ReadByte());
            Assert.Equal(cb, s.Length);
            Assert.Equal(cb, s.Position);
        }
예제 #3
0
        public void Basic()
        {
            BlockStream s;
            byte        b;
            int         cb;

            byte[] buf;
            byte[] cmp;

            //-------------------------

            cb = 1024;

            s = new BlockStream();
            Assert.Equal(0, s.Length);
            Assert.Equal(0, s.Position);
            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal((long)(i + 1), s.Length);
            }

            s.Position = 0;
            for (int i = 0; i < cb; i++)
            {
                b = (byte)s.ReadByte();
                Assert.Equal((byte)i, b);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal(cb, s.Length);
            }

            cmp = new byte[cb];
            for (int i = 0; i < cb; i++)
            {
                cmp[i] = (byte)i;
            }

            buf        = new byte[cb];
            s.Position = 0;
            s.Read(buf, 0, cb);
            Assert.Equal(cmp, buf);
            Assert.Equal((long)cb, s.Position);
            Assert.Equal((long)cb, s.Length);

            //-------------------------

            cb = 256;

            s = new BlockStream(cb);
            Assert.Equal(0, s.Length);
            Assert.Equal(0, s.Position);
            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal((long)(i + 1), s.Length);
            }

            s.Position = 0;
            for (int i = 0; i < cb; i++)
            {
                b = (byte)s.ReadByte();
                Assert.Equal((byte)i, b);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal(cb, s.Length);
            }

            cmp = new byte[cb];
            for (int i = 0; i < cb; i++)
            {
                cmp[i] = (byte)i;
            }

            buf        = new byte[cb];
            s.Position = 0;
            s.Read(buf, 0, cb);
            Assert.Equal(cmp, buf);
            Assert.Equal((long)cb, s.Position);
            Assert.Equal((long)cb, s.Length);

            //-------------------------

            cb = 3 * 256 + 1;

            s = new BlockStream(cb, 256);
            Assert.Equal(0, s.Length);
            Assert.Equal(0, s.Position);
            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal((long)(i + 1), s.Length);
            }

            s.Position = 0;
            for (int i = 0; i < cb; i++)
            {
                b = (byte)s.ReadByte();
                Assert.Equal((byte)i, b);
                Assert.Equal((long)(i + 1), s.Position);
                Assert.Equal(cb, s.Length);
            }

            cmp = new byte[cb];
            for (int i = 0; i < cb; i++)
            {
                cmp[i] = (byte)i;
            }

            buf        = new byte[cb];
            s.Position = 0;
            s.Read(buf, 0, cb);
            Assert.Equal(cmp, buf);
            Assert.Equal((long)cb, s.Position);
            Assert.Equal((long)cb, s.Length);

            //-------------------------

            cb = 300;

            s = new BlockStream(new Block(cb / 3), new Block(cb / 3), new Block(cb / 3));
            Assert.Equal(cb, s.Length);
            Assert.Equal(0, s.Position);
            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
                Assert.Equal((long)(i + 1), s.Position);
            }

            s.Position = 0;
            for (int i = 0; i < cb; i++)
            {
                b = (byte)s.ReadByte();
                Assert.Equal((byte)i, b);
                Assert.Equal((long)(i + 1), s.Position);
            }

            cmp = new byte[cb];
            for (int i = 0; i < cb; i++)
            {
                cmp[i] = (byte)i;
            }

            buf        = new byte[cb];
            s.Position = 0;
            s.Read(buf, 0, cb);
            Assert.Equal(cmp, buf);
            Assert.Equal((long)cb, s.Position);

            //-------------------------

            cb = 300;

            s = new BlockStream(new BlockArray(new Block[] { new Block(cb / 3), new Block(cb / 3), new Block(cb / 3) }));
            Assert.Equal(cb, s.Length);
            Assert.Equal(0, s.Position);
            for (int i = 0; i < cb; i++)
            {
                s.WriteByte((byte)i);
                Assert.Equal((long)(i + 1), s.Position);
            }

            s.Position = 0;
            for (int i = 0; i < cb; i++)
            {
                b = (byte)s.ReadByte();
                Assert.Equal((byte)i, b);
                Assert.Equal((long)(i + 1), s.Position);
            }

            cmp = new byte[cb];
            for (int i = 0; i < cb; i++)
            {
                cmp[i] = (byte)i;
            }

            buf        = new byte[cb];
            s.Position = 0;
            s.Read(buf, 0, cb);
            Assert.Equal(cmp, buf);
            Assert.Equal((long)cb, s.Position);
        }