public void SerializeTest() { SuperStream expectedStream = new SuperStream(Endianess.Little); var expectedObject = new StreamDataTestData { A = -15, B = "Test one!", C = "Test two!", D = new List <int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), E = ByteEnum.Hello, F = LongEnum.Max }; expectedStream.WriteInt32(expectedObject.A); expectedStream.WriteString(expectedObject.B); expectedStream.WriteCString(expectedObject.C); expectedStream.WriteUInt32((uint)expectedObject.D.Count); foreach (var i in expectedObject.D) { expectedStream.WriteInt32(i); } expectedStream.WriteByte((byte)ByteEnum.Hello); expectedStream.WriteInt64((Int64)LongEnum.Max); var expected = ((MemoryStream)expectedStream.BaseStream).ToArray(); var actualStream = new SuperStream(Endianess.Little); StreamData.Serialize(expectedObject, actualStream); var actual = ((MemoryStream)actualStream.BaseStream).ToArray(); Assert.IsTrue(actual.SequenceEqual(expected)); }
public void CreateTest() { Type t = typeof(int); SuperStream ms = new SuperStream(Endianess.Little); var expected = new StreamDataTestData { A = -15, B = "Test one!", C = "Test two!", D = new List <int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }), E = ByteEnum.Hello, F = LongEnum.Max }; ms.WriteInt32(expected.A); ms.WriteString(expected.B); ms.WriteCString(expected.C); ms.WriteUInt32((uint)expected.D.Count); foreach (var i in expected.D) { ms.WriteInt32(i); } ms.WriteByte((byte)ByteEnum.Hello); ms.WriteInt64((Int64)LongEnum.Max); ms.Position = 0; StreamDataTestData actual; actual = StreamData.Create <StreamDataTestData>(ms); Assert.AreEqual(expected, actual); }
public void StringTest() { string expected = "Hello there!\0Yo!"; SuperStream target = new SuperStream(Endianess.Little); target.WriteString(expected); target.Position = 0; var actual = target.ReadString(); Assert.AreEqual(expected, actual); }