示例#1
0
        public void WriteBit_Seek_WriteBit()
        {
            var stream = new MemoryStream();

            using (var writer = new BitStreamWriter(stream, true))
            {
                Assert.AreEqual(false, writer.CanRead);
                Assert.AreEqual(true, writer.CanWrite);
                Assert.AreEqual(true, writer.CanSeek);

                Assert.AreEqual(0, writer.Length);
                Assert.AreEqual(0, writer.BitLength);
                Assert.AreEqual(0, writer.BitPosition);
                Assert.AreEqual(0, writer.Position);

                writer.Write(true);

                Assert.AreEqual(1, writer.Length);
                Assert.AreEqual(1, writer.BitLength);
                Assert.AreEqual(1, writer.BitPosition);
                Assert.AreEqual(0, writer.Position);

                writer.Seek(0, SeekOrigin.Begin);

                Assert.AreEqual(1, stream.Length);
                Assert.AreEqual(0, stream.Position);
                Assert.AreEqual(0x80, stream.GetBuffer()[0]);

                writer.Write(false);
            }
            Assert.AreEqual(1, stream.Length);
            Assert.AreEqual(1, stream.Position);
            Assert.AreEqual(0, stream.GetBuffer()[0]);
        }
示例#2
0
        public void leaveOpen_False()
        {
            var stream = new MemoryStream();

            using (var writer = new BitStreamWriter(stream, false))
            {
                Assert.AreEqual(false, writer.CanRead);
                Assert.AreEqual(true, writer.CanWrite);
                Assert.AreEqual(true, writer.CanSeek);

                Assert.AreEqual(0, writer.Length);
                Assert.AreEqual(0, writer.BitLength);
                Assert.AreEqual(0, writer.BitPosition);
                Assert.AreEqual(0, writer.Position);

                writer.Write(true);

                Assert.AreEqual(1, writer.Length);
                Assert.AreEqual(1, writer.BitLength);
                Assert.AreEqual(1, writer.BitPosition);
                Assert.AreEqual(0, writer.Position);

                writer.Seek(0, SeekOrigin.Begin);

                Assert.AreEqual(1, stream.Length);
                Assert.AreEqual(0, stream.Position);
                Assert.AreEqual(0x80, stream.GetBuffer()[0]);

                writer.Write(false);
            }
            Assert.AreEqual(1, stream.Length);
            Assert.AreEqual(1, stream.Position);
            Assert.AreEqual(0, stream.GetBuffer()[0]);

            using (var writer = new BitStreamWriter(stream, false))
            {
                var data = new byte[] { 0x3c, 0x4b, 0x1a, 0x54, 0x22, 0x10, 0xaf, 0x89, 0x97, 0x65 };
                writer.Write(data, 0, data.Length);
                writer.Flush();

                Assert.AreEqual(11, stream.Length);
                Assert.AreEqual(11, stream.Position);
            }
        }