From d5b7802ae323495cdbbe6961b9253d0b2e81c7cb Mon Sep 17 00:00:00 2001 From: vis2k Date: Sat, 7 Mar 2020 20:38:58 +0100 Subject: [PATCH] NetworkBehaviourTests: SerializeAndDeserializeObjectsAll --- .../Tests/Editor/NetworkBehaviourTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index d8fb6cedd..2f8279bde 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -1466,6 +1466,35 @@ public void DirtyObjectBits() cleanList.Add(43); Assert.That(comp.DirtyObjectBits(), Is.EqualTo(0b11)); } + + [Test] + public void SerializeAndDeserializeObjectsAll() + { + // we need a component that exposes InitSyncObject so we can add some + NetworkBehaviourInitSyncObjectExposed comp = gameObject.AddComponent(); + + // add a synclist + SyncListInt list = new SyncListInt(); + list.Add(42); + list.Add(43); + Assert.That(list.IsDirty, Is.True); + comp.InitSyncObjectExposed(list); + + // serialize it + NetworkWriter writer = new NetworkWriter(); + comp.SerializeObjectsAll(writer); + + // clear original list + list.Clear(); + Assert.That(list.Count, Is.EqualTo(0)); + + // deserialize it + NetworkReader reader = new NetworkReader(writer.ToArray()); + comp.DeSerializeObjectsAll(reader); + Assert.That(list.Count, Is.EqualTo(2)); + Assert.That(list[0], Is.EqualTo(42)); + Assert.That(list[1], Is.EqualTo(43)); + } } // we need to inherit from networkbehaviour to test protected functions