From ef7993cac1f249ff337465954b9cf4ea0773c33a Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 27 Jan 2020 14:31:50 +0100 Subject: [PATCH] MessageTests: SyncEventMessageTest --- Assets/Mirror/Tests/Editor/MessageTests.cs | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/MessageTests.cs b/Assets/Mirror/Tests/Editor/MessageTests.cs index c3846cf29..b23273e0e 100644 --- a/Assets/Mirror/Tests/Editor/MessageTests.cs +++ b/Assets/Mirror/Tests/Editor/MessageTests.cs @@ -79,5 +79,33 @@ public void RpcMessageTest() Assert.That(fresh.payload.Array[fresh.payload.Offset + i], Is.EqualTo(message.payload.Array[message.payload.Offset + i])); } + + [Test] + public void SyncEventMessageTest() + { + // try setting value with constructor + SyncEventMessage message = new SyncEventMessage { + netId = 42, + componentIndex = 4, + functionHash = 0xABCDEF, + payload = new ArraySegment(new byte[]{0x01, 0x02}) + }; + + // serialize + NetworkWriter writer = new NetworkWriter(); + message.Serialize(writer); + byte[] writerData = writer.ToArray(); + + // deserialize the same data - do we get the same result? + SyncEventMessage fresh = new SyncEventMessage(); + fresh.Deserialize(new NetworkReader(writerData)); + Assert.That(fresh.netId, Is.EqualTo(message.netId)); + Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex)); + Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash)); + Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count)); + for (int i = 0; i < fresh.payload.Count; ++i) + Assert.That(fresh.payload.Array[fresh.payload.Offset + i], + Is.EqualTo(message.payload.Array[message.payload.Offset + i])); + } } }