This commit is contained in:
vis2k 2021-09-16 14:36:38 +08:00
parent b5b3d33704
commit cc22fabe1d

View File

@ -13,48 +13,6 @@ class NetworkBehaviourWithSyncCollections : NetworkBehaviour
public class NetworkBehaviourDirtyBitsTests : MirrorEditModeTest
{
[Test]
public void ClearAllDirtyBitsClearsSyncVarDirtyBits()
{
CreateNetworked(out GameObject _, out NetworkIdentity _, out EmptyBehaviour emptyBehaviour);
// set syncinterval so dirtybit works fine
emptyBehaviour.syncInterval = 0;
Assert.That(emptyBehaviour.IsDirty(), Is.False);
// set one syncvar dirty bit
emptyBehaviour.SetDirtyBit(1);
Assert.That(emptyBehaviour.IsDirty(), Is.True);
// clear it
emptyBehaviour.ClearAllDirtyBits();
Assert.That(emptyBehaviour.IsDirty(), Is.False);
}
[Test]
public void ClearAllDirtyBitsClearsSyncObjectsDirtyBits()
{
CreateNetworked(out GameObject _, out NetworkIdentity _, out NetworkBehaviourInitSyncObjectExposed comp);
// set syncinterval so dirtybit works fine
comp.syncInterval = 0;
Assert.That(comp.IsDirty(), Is.False);
// create a synclist and dirty it
SyncList<int> obj = new SyncList<int>();
obj.Add(42);
Assert.That(obj.IsDirty, Is.True);
// add it
comp.InitSyncObjectExposed(obj);
Assert.That(comp.IsDirty, Is.True);
// clear bits should clear synclist bits too
comp.ClearAllDirtyBits();
Assert.That(comp.IsDirty, Is.False);
Assert.That(obj.IsDirty, Is.False);
}
[Test]
public void DirtyObjectBits()
{
@ -102,6 +60,47 @@ public void AnySyncObjectDirty()
comp.list.Flush();
Assert.That(comp.AnySyncObjectDirty(), Is.True);
}
[Test]
public void ClearAllDirtyBitsClearsSyncVarDirtyBits()
{
CreateNetworked(out GameObject _, out NetworkIdentity _, out EmptyBehaviour emptyBehaviour);
// set syncinterval so dirtybit works fine
emptyBehaviour.syncInterval = 0;
Assert.That(emptyBehaviour.IsDirty(), Is.False);
// set one syncvar dirty bit
emptyBehaviour.SetDirtyBit(1);
Assert.That(emptyBehaviour.IsDirty(), Is.True);
// clear it
emptyBehaviour.ClearAllDirtyBits();
Assert.That(emptyBehaviour.IsDirty(), Is.False);
}
[Test]
public void ClearAllDirtyBitsClearsSyncObjectsDirtyBits()
{
CreateNetworked(out GameObject _, out NetworkIdentity _, out NetworkBehaviourInitSyncObjectExposed comp);
// set syncinterval so dirtybit works fine
comp.syncInterval = 0;
Assert.That(comp.IsDirty(), Is.False);
// create a synclist and dirty it
SyncList<int> obj = new SyncList<int>();
obj.Add(42);
Assert.That(obj.IsDirty, Is.True);
// add it
comp.InitSyncObjectExposed(obj);
Assert.That(comp.IsDirty, Is.True);
// clear bits should clear synclist bits too
comp.ClearAllDirtyBits();
Assert.That(comp.IsDirty, Is.False);
Assert.That(obj.IsDirty, Is.False);
}
}
// hook tests can only be ran when inheriting from NetworkBehaviour