NetworkBehaviourTests: SerializeAndDeserializeObjectsAll

This commit is contained in:
vis2k 2020-03-07 20:38:58 +01:00
parent 2ff53580ba
commit d5b7802ae3

View File

@ -1466,6 +1466,35 @@ public void DirtyObjectBits()
cleanList.Add(43); cleanList.Add(43);
Assert.That(comp.DirtyObjectBits(), Is.EqualTo(0b11)); 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<NetworkBehaviourInitSyncObjectExposed>();
// 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 // we need to inherit from networkbehaviour to test protected functions