public void ReadInvalidateTest() { BitStreamer bs = new BitStreamer(false); IntPtr ptr = Memory.Alloc(4); Assert.IsFalse(bs.ThrowsOnExceededBuffer); Assert.IsFalse(bs.IsValid); bs.ResetRead(ptr, 4); Assert.IsTrue(bs.IsValid); bs.ReadInt32(); Assert.IsTrue(bs.IsValid); bs.ReadInt32(); Assert.IsFalse(bs.IsValid); // Confirm offset hasn't increased. Assert.AreEqual(4, bs.ByteOffset); bs.ResetRead(); Assert.IsTrue(bs.IsValid); Memory.Free(ptr); }
public void ReadwriteTest(int value) { m_stream.WriteInt32(value); Assert.AreEqual(32, m_stream.BitOffset); m_stream.ResetRead(); Assert.AreEqual(value, m_stream.ReadInt32()); Assert.AreEqual(32, m_stream.BitOffset); }
public void WriteResizeTest() { BitStreamer bs = new BitStreamer(false); Assert.IsFalse(bs.ThrowsOnExceededBuffer); Assert.IsFalse(bs.IsValid); bs.ResetWrite(8); Assert.IsTrue(bs.IsValid); bs.WriteULong(123); Assert.IsTrue(bs.IsValid); Assert.AreEqual(8, bs.ByteLength); bs.WriteInt32(321); Assert.IsTrue(bs.IsValid); Assert.AreEqual(16, bs.ByteLength); // Confirm offset has increased. Assert.AreEqual(12, bs.ByteOffset); bs.ResetRead(); Assert.AreEqual(123, bs.ReadULong()); Assert.AreEqual(321, bs.ReadInt32()); Assert.IsTrue(bs.IsValid); }
public void ReadWriteIntTest() { int val = 123456789; BitStreamer bs = new BitStreamer(); bs.ResetWrite(64); bs.WriteInt32(val); Assert.AreEqual(32, bs.BitOffset); bs.ResetRead(); Assert.AreEqual(val, bs.ReadInt32()); }
public void BitStream() { BitStreamer stream = new BitStreamer(); stream.ResetWrite(m_ptrBuf, SIZE, false); for (int i = 0; i < AMOUNT / 2; i++) { stream.WriteBool(i % 2 == 0); stream.WriteInt32(i); } stream.ResetRead(); for (int i = 0; i < AMOUNT / 2; i++) { bool b = stream.ReadBool(); int num = stream.ReadInt32(); } }
public unsafe void SizePrefixTest() { BitStreamer bs = new BitStreamer(); bs.ResetWrite(64); bs.ReserveSizePrefix(); Assert.AreEqual(4, bs.ByteOffset); // Write some random data. var bits = 32; for (int i = 0; i < 8; i++) { bs.WriteInt32(i + 1, 7); bits += 7; } Assert.AreEqual(bits, bs.BitOffset); int bytesUsed = bs.BytesUsed; // Prefix the size and make sure the offset remains unchanged. Assert.AreEqual(bytesUsed, bs.PrefixSize()); Assert.AreEqual(bits, bs.BitOffset); var newbs = new BitStreamer(); newbs.ResetRead(bs.Buffer, bs.ByteLength, false); // Read the length of the buffer. // Must be read as uint due to Zig/Zagging of int value. Assert.AreEqual(bytesUsed, newbs.ReadUInt32()); for (int i = 0; i < 8; i++) { Assert.AreEqual(i + 1, newbs.ReadInt32(7)); } Assert.AreEqual(bs.BitOffset, newbs.BitOffset); }