public void IntegerLimits() { var limits = new[] { new BasicTypes { _int8 = sbyte.MaxValue, _int16 = short.MaxValue, _int32 = int.MaxValue, _int64 = long.MaxValue, _uint8 = byte.MaxValue, _uint16 = ushort.MaxValue, _uint32 = uint.MaxValue, _uint64 = ulong.MaxValue }, new BasicTypes { _int8 = sbyte.MinValue, _int16 = short.MinValue, _int32 = int.MinValue, _int64 = long.MinValue, _uint8 = byte.MinValue, _uint16 = ushort.MinValue, _uint32 = uint.MinValue, _uint64 = ulong.MinValue } }; Util.RoundtripMemory <BasicTypes, BasicTypes> memoryRoundtrip = (serialize, deserialize) => { foreach (var from in limits) { var data = serialize(from); var to = deserialize(data); Assert.IsTrue(from.IsEqual <BasicTypes>(to)); } }; memoryRoundtrip(Util.SerializeUnsafeCB, Util.DeserializeSafeCB <BasicTypes>); memoryRoundtrip(Util.SerializeUnsafeCB, Util.DeserializeUnsafeCB <BasicTypes>); memoryRoundtrip(Util.SerializeSP, Util.DeserializeSafeSP <BasicTypes, BasicTypes>); memoryRoundtrip(Util.SerializeSP, Util.DeserializeUnsafeSP <BasicTypes, BasicTypes>); }
public void IntegerLimits() { var limits = new[] { new BasicTypes { _int8 = sbyte.MaxValue, _int16 = short.MaxValue, _int32 = int.MaxValue, _int64 = long.MaxValue, _uint8 = byte.MaxValue, _uint16 = ushort.MaxValue, _uint32 = uint.MaxValue, _uint64 = ulong.MaxValue }, new BasicTypes { _int8 = sbyte.MinValue, _int16 = short.MinValue, _int32 = int.MinValue, _int64 = long.MinValue, _uint8 = byte.MinValue, _uint16 = ushort.MinValue, _uint32 = uint.MinValue, _uint64 = ulong.MinValue } }; Util.RoundtripMemory <BasicTypes, BasicTypes> memoryRoundtrip = (serialize, deserialize) => { foreach (var from in limits) { var data = serialize(from); var to = deserialize(data); Assert.IsTrue(from.IsEqual <BasicTypes>(to)); } }; Util.RoundtripPtrMemory <BasicTypes, BasicTypes> ptrMemoryRoundtrip = (serialize, deserialize) => { foreach (var from in limits) { unsafe { var data = serialize(from); fixed(byte *ptr = data.Array) { var tuple = new Tuple <IntPtr, int>((IntPtr)(ptr + data.Offset), data.Count); var to = deserialize(tuple); Assert.IsTrue(from.IsEqual <BasicTypes>(to)); } } } }; memoryRoundtrip(Util.SerializeUnsafeCB, Util.DeserializeSafeCB <BasicTypes>); memoryRoundtrip(Util.SerializeUnsafeCB, Util.DeserializeUnsafeCB <BasicTypes>); memoryRoundtrip(Util.SerializeUnsafeCBWithPtr, Util.DeserializeSafeCB <BasicTypes>); memoryRoundtrip(Util.SerializeUnsafeCBWithPtr, Util.DeserializeUnsafeCB <BasicTypes>); ptrMemoryRoundtrip(Util.SerializeUnsafeCB, Util.DeserializeUnsafeCBWithPtr <BasicTypes>); ptrMemoryRoundtrip(Util.SerializeUnsafeCBWithPtr, Util.DeserializeUnsafeCBWithPtr <BasicTypes>); memoryRoundtrip(Util.SerializeSP, Util.DeserializeSafeSP <BasicTypes, BasicTypes>); memoryRoundtrip(Util.SerializeSP, Util.DeserializeUnsafeSP <BasicTypes, BasicTypes>); ptrMemoryRoundtrip(Util.SerializeSP, Util.DeserializeUnsafeSPWithPtr <BasicTypes, BasicTypes>); }