public void ListOfStructsAsListOfSBytes() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(1).WriteData(0, sbyte.MinValue); DeserializerState d = ds; var asListOfSBytes = d.RequireList().CastSByte(); Assert.AreEqual(2, asListOfSBytes.Count); Assert.AreEqual((sbyte)0, asListOfSBytes[0]); Assert.AreEqual(sbyte.MinValue, asListOfSBytes[1]); }
public void ListOfStructsAsListOfULongs() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(1).WriteData(0, ulong.MaxValue); DeserializerState d = ds; var asListOfULongs = d.RequireList().CastULong(); Assert.AreEqual(2, asListOfULongs.Count); Assert.AreEqual(0ul, asListOfULongs[0]); Assert.AreEqual(ulong.MaxValue, asListOfULongs[1]); }
public void ListOfStructsAsListOfDoubles() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(0).WriteData(0, double.NegativeInfinity); ds.ListBuildStruct(1).WriteData(0, double.MaxValue); DeserializerState d = ds; var asListOfDoubles = d.RequireList().CastDouble(); Assert.AreEqual(2, asListOfDoubles.Count); Assert.AreEqual(double.NegativeInfinity, asListOfDoubles[0]); Assert.AreEqual(double.MaxValue, asListOfDoubles[1]); }
public void ListOfStructsAsListOfFloats() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(0).WriteData(0, float.NaN); ds.ListBuildStruct(1).WriteData(0, float.PositiveInfinity); DeserializerState d = ds; var asListOfFloats = d.RequireList().CastFloat(); Assert.AreEqual(2, asListOfFloats.Count); Assert.AreEqual(float.NaN, asListOfFloats[0]); Assert.AreEqual(float.PositiveInfinity, asListOfFloats[1]); }
public void ListOfStructsAsListOfBytes() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(3, 1, 0); ds.ListBuildStruct(1).WriteData(0, (byte)0x11); ds.ListBuildStruct(2).WriteData(0, (byte)0x22); DeserializerState d = ds; var asListOfBytes = d.RequireList().CastByte(); Assert.AreEqual(3, asListOfBytes.Count); Assert.AreEqual(0, asListOfBytes[0]); Assert.AreEqual((byte)0x11, asListOfBytes[1]); Assert.AreEqual((byte)0x22, asListOfBytes[2]); }
public void ListOfStructsAsListOfBools() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(3, 1, 0); ds.ListBuildStruct(1).WriteData(0, false); ds.ListBuildStruct(2).WriteData(0, true); DeserializerState d = ds; var asListOfBools = d.RequireList().CastBool(); Assert.AreEqual(3, asListOfBools.Count); Assert.AreEqual(false, asListOfBools[0]); Assert.AreEqual(false, asListOfBools[1]); Assert.AreEqual(true, asListOfBools[2]); }
public void Struct() { var mb = MessageBuilder.Create(8); var ds = new DynamicSerializerState(mb); var alloc = mb.Allocator; ds.SetStruct(3, 2); Assert.IsFalse(ds.IsAllocated); Assert.ThrowsException <InvalidOperationException>(() => ds.SetListOfPointers(1)); Assert.ThrowsException <InvalidOperationException>(() => ds.SetListOfStructs(3, 2, 1)); Assert.ThrowsException <InvalidOperationException>(() => ds.SetListOfValues(8, 3)); Assert.ThrowsException <InvalidOperationException>(() => ds.SetStruct(2, 3)); ds.SetStruct(3, 2); ds.Allocate(); Assert.IsTrue(ds.IsAllocated); Assert.AreEqual(3, ds.StructDataSection.Length); ds.StructWriteData(0, 16, 0x4321); ds.StructWriteData(64, 32, 0x87654321); ds.StructWriteData(128, 64, 0x1234567812345678); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.StructWriteData(191, 2, 1)); var ds2 = ds.BuildPointer(0); ds2.SetStruct(1, 0); ds2.WriteData(0, 1.23); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.Link(2, ds)); Assert.AreEqual(1, alloc.Segments.Count); Assert.AreEqual(7, alloc.Segments[0].Length); DeserializerState d = ds; Assert.AreEqual(ObjectKind.Struct, d.Kind); Assert.AreEqual(3, d.StructDataCount); Assert.AreEqual(2, d.StructPtrCount); Assert.AreEqual(0x4321, d.ReadDataUShort(0)); Assert.AreEqual(0x87654321, d.ReadDataUInt(64)); Assert.IsTrue(0x1234567812345678 == d.ReadDataULong(128)); var p0 = d.StructReadPointer(0); Assert.AreEqual(ObjectKind.Struct, p0.Kind); Assert.AreEqual(1.23, p0.ReadDataDouble(0)); var p1 = d.StructReadPointer(1); Assert.AreEqual(ObjectKind.Nil, p1.Kind); }
public void Abuse() { var mb = MessageBuilder.Create(1); var alloc = mb.Allocator; var ds = new DynamicSerializerState(mb); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.SetListOfPointers(-1)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.SetListOfStructs(-10, 100, 200)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.SetListOfValues(2, 1)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.SetListOfValues(1, -1)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => ds.SetListOfValues(65, 1)); }
public void ListOfStructs() { var mb = MessageBuilder.Create(1); var alloc = mb.Allocator; var ds = new DynamicSerializerState(mb); int count = 23; ds.SetListOfStructs(count, 2, 1); var dse0 = ds.ListBuildStruct(0); dse0.WriteData(0, 1); dse0.WriteData(64, 2); var dse1 = ds.ListBuildStruct(1); dse1.WriteData(0, 3); dse1.WriteData(64, 4); Assert.ThrowsException <InvalidOperationException>( () => ds.Link(2, ds)); Assert.ThrowsException <InvalidOperationException>( () => ds.BuildPointer(2)); DeserializerState d = ds; Assert.AreEqual(ObjectKind.ListOfStructs, d.Kind); Assert.AreEqual(count, d.ListElementCount); var pointers = d.RequireList().Cast(_ => _); Assert.AreEqual(ObjectKind.Struct, pointers[0].Kind); Assert.AreEqual(1, pointers[0].ReadDataInt(0)); Assert.AreEqual(2, pointers[0].ReadDataInt(64)); Assert.AreEqual(ObjectKind.Struct, pointers[1].Kind); Assert.AreEqual(3, pointers[1].ReadDataInt(0)); Assert.AreEqual(4, pointers[1].ReadDataInt(64)); Assert.AreEqual(ObjectKind.Struct, pointers[2].Kind); Assert.AreEqual(0, pointers[2].ReadDataInt(0)); Assert.AreEqual(0, pointers[2].ReadDataInt(64)); Assert.ThrowsException <IndexOutOfRangeException>(() => { var dummy = pointers[-1]; }); Assert.ThrowsException <IndexOutOfRangeException>(() => { var dummy = pointers[count]; }); }