Ejemplo n.º 1
0
        public void ReadwriteFloat(float value)
        {
            int val = (int)value;

            m_stream.WriteByte(0, 4);
            m_stream.WriteInt32(val);

            m_stream.ResetRead();
            m_stream.ReadByte(4);
            Assert.AreEqual(val, m_stream.ReadInt32());
        }
Ejemplo n.º 2
0
        public void ResetReadOffsetTest()
        {
            var arr = new byte[16];

            arr[5] = 123;

            BitStreamer bs = new BitStreamer();

            bs.ResetRead(arr, 5, 10);

            Assert.AreEqual(16, bs.ByteLength);
            Assert.AreEqual(0, bs.ByteOffset);

            Assert.AreEqual(123, bs.ReadByte());
        }
Ejemplo n.º 3
0
        public void ResetWriteOwnsBufferTest()
        {
            BitStreamer bs = new BitStreamer();

            bs.ResetWrite(16);
            bs.WriteByte(1);
            bs.WriteByte(2);

            Assert.AreEqual(16, bs.BitOffset);
            Assert.AreEqual(16, bs.ByteLength);

            // Confirm values are there.
            bs.ResetRead();
            Assert.AreEqual(1, bs.ReadByte());
            Assert.AreEqual(2, bs.ReadByte());

            bs.ResetWrite();
            Assert.AreEqual(0, bs.BitOffset);
            Assert.AreEqual(16, bs.ByteLength);

            // Confirm values have been zeroed.
            bs.ResetRead();
            Assert.AreEqual(0, bs.ReadByte());
        }
Ejemplo n.º 4
0
        public void ResetWriteCopyBufferNull()
        {
            BitStreamer bs = new BitStreamer();

            IntPtr buff = Memory.Alloc(16);

            *(byte *)buff = 212;

            bs.ResetWrite(buff, 16, true);
            Assert.AreEqual(16, bs.ByteLength);
            Assert.AreEqual(16, bs.ByteOffset);

            bs.ResetRead();
            Assert.AreEqual(212, bs.ReadByte());
            Assert.IsTrue(bs.OwnsBuffer);

            Memory.Free(buff);
        }
Ejemplo n.º 5
0
        public void NonAlignBufferSet()
        {
            IntPtr ptr = Memory.Alloc(12);

            BitStreamer bs = new BitStreamer();

            bs.ResetRead(ptr, 4);

            Assert.AreEqual(4, bs.ByteLength);
            bs.ReadFloat();

            // Should fail because we are exceeding the allowed size of 4.
            Assert.Throws <InvalidOperationException>(() =>
            {
                bs.ReadByte(1);
            });

            bs.ResetWrite();
            Assert.AreEqual(0, bs.ByteLength);
        }