Пример #1
0
        public void FlushBitsTest()
        {
            var mem    = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);

            writer.WriteBit(true);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);

            writer.FlushBits();

            mem.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0xaa, mem.ReadByte(), "Byte 0");
            Assert.AreEqual(0xc0, mem.ReadByte(), "Byte 1");

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Пример #2
0
        protected void WriteBits(Stream stream, params string[] bits)
        {
            var writer = new SwfStreamWriter(stream);

            foreach (var bitString in bits)
            {
                foreach (var ch in bitString)
                {
                    switch (ch)
                    {
                    case '0':
                        writer.WriteBit(false);
                        break;

                    case '1':
                        writer.WriteBit(true);
                        break;

                    case '.':
                        break;

                    default:
                        throw new InvalidOperationException("Invalid character " + ch);
                    }
                }
            }
            writer.FlushBits();
            stream.Seek(0, SeekOrigin.Begin);
        }
Пример #3
0
        public void FlushBitsTest()
        {
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);

            writer.WriteBit(true);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);

            writer.FlushBits();

            mem.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0xaa, mem.ReadByte(), "Byte 0");
            Assert.AreEqual(0xc0, mem.ReadByte(), "Byte 1");

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Пример #4
0
        public void WriteNegativeFixedPoint16FromBitsTest()
        {
            var mem    = new MemoryStream();
            var writer = new SwfStreamWriter(mem);
            var bits   = new SignedBitsCount(-81920).GetBits();

            writer.WriteFixedPoint16(-1.25, bits);
            writer.FlushBits();
            mem.Seek(0, SeekOrigin.Begin);
            var reader = new SwfStreamReader(mem);
            int actual = reader.ReadSignedBits(bits);

            Assert.AreEqual(-81920, actual);
        }
Пример #5
0
        public void ReadNegativeFixedPoint16FromBitsTest()
        {
            var       mem    = new MemoryStream();
            var       writer = new SwfStreamWriter(mem);
            const int val    = -81920;
            var       bits   = new SignedBitsCount(val).GetBits();

            writer.WriteSignedBits(val, bits);
            writer.FlushBits();
            mem.Seek(0, SeekOrigin.Begin);
            var    reader = new SwfStreamReader(mem);
            double actual = reader.ReadFixedPoint16(bits);

            Assert.AreEqual(-1.25, actual);
        }
Пример #6
0
        public void WriteRectTest2()
        {
            var rect = new SwfRect {
                XMin = 0x004,
                XMax = 0x48f,
                YMin = 0x008,
                YMax = 0x0ee
            };
            var mem    = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteRect(ref rect);
            writer.FlushBits();
            CheckBits(mem, "01100", "0000.00000100", "0100.10001111", "0000.00001000", "0000.11101110");
            mem.Seek(0, SeekOrigin.Begin);
        }
Пример #7
0
        public void WriteFixedPoint16FromBitsTest()
        {
            var          mem      = new MemoryStream();
            var          writer   = new SwfStreamWriter(mem);
            const int    val      = 0x03aa4523;
            const ushort hi       = val >> 16;
            const ushort low      = val & 0xffff;
            const double expected = hi + low / 65536.0;
            var          bits     = new SignedBitsCount(hi).GetBits() + 16;

            writer.WriteFixedPoint16(expected, bits);
            writer.FlushBits();
            mem.Seek(0, SeekOrigin.Begin);
            var    reader = new SwfStreamReader(mem);
            double actual = reader.ReadFixedPoint16(bits);

            Assert.AreEqual(expected, actual);
        }
Пример #8
0
 protected void WriteBits(Stream stream, params string[] bits)
 {
     var writer = new SwfStreamWriter(stream);
     foreach (var bitString in bits) {
         foreach (var ch in bitString) {
             switch (ch) {
                 case '0':
                     writer.WriteBit(false);
                     break;
                 case '1':
                     writer.WriteBit(true);
                     break;
                 case '.':
                     break;
                 default:
                     throw new InvalidOperationException("Invalid character " + ch);
             }
         }
     }
     writer.FlushBits();
     stream.Seek(0, SeekOrigin.Begin);
 }
Пример #9
0
 public void ReadFixedPoint16FromBitsTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     const int val = 0x03aa4523;
     const ushort hi = val >> 16;
     const ushort low = val & 0xffff;
     const double expected = hi + low / 65536.0;
     var bits = new SignedBitsCount(hi).GetBits();
     writer.WriteUnsignedBits(hi, bits);
     writer.WriteUnsignedBits(low, 16);
     writer.FlushBits();
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     double actual = reader.ReadFixedPoint16(bits + 16);
     Assert.AreEqual(expected, actual);
 }
Пример #10
0
 public void ReadNegativeFixedPoint16FromBitsTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     const int val = -81920;
     var bits = new SignedBitsCount(val).GetBits();
     writer.WriteSignedBits(val, bits);
     writer.FlushBits();
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     double actual = reader.ReadFixedPoint16(bits);
     Assert.AreEqual(-1.25, actual);
 }
Пример #11
0
 public void WriteRectTest2()
 {
     var rect = new SwfRect {
         XMin = 0x004,
         XMax = 0x48f,
         YMin = 0x008,
         YMax = 0x0ee
     };
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     writer.WriteRect(ref rect);
     writer.FlushBits();
     CheckBits(mem, "01100", "0000.00000100", "0100.10001111", "0000.00001000", "0000.11101110");
     mem.Seek(0, SeekOrigin.Begin);
 }
Пример #12
0
 public void WriteNegativeFixedPoint16FromBitsTest()
 {
     var mem = new MemoryStream();
     var writer = new SwfStreamWriter(mem);
     var bits = new SignedBitsCount(-81920).GetBits();
     writer.WriteFixedPoint16(-1.25, bits);
     writer.FlushBits();
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     int actual = reader.ReadSignedBits(bits);
     Assert.AreEqual(-81920, actual);
 }