NetworkIdentityTests: RebuildObserversSetsHostVisibility

This commit is contained in:
vis2k 2020-03-04 14:34:07 +01:00
parent 1ddb9ae075
commit 26c0c03fd8

View File

@ -223,6 +223,14 @@ public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bo
// OnRebuildObservers, but return no observers
return true;
}
public int hostVisibilityCalled;
public bool hostVisibilityValue;
public override void OnSetHostVisibility(bool visible)
{
++hostVisibilityCalled;
hostVisibilityValue = visible;
}
}
class IsClientServerCheckComponent : NetworkBehaviour
@ -1443,5 +1451,34 @@ public void RebuildObserversDoesNotAddServerConnectionsIfImplemented()
NetworkServer.Shutdown();
Transport.activeTransport = null;
}
[Test]
public void RebuildObserversSetsHostVisibility()
{
// set local connection for host mode
ULocalConnectionToClient localConnection = new ULocalConnectionToClient();
localConnection.connectionToServer = new ULocalConnectionToServer();
localConnection.isReady = true;
NetworkServer.SetLocalConnection(localConnection);
// add at least one observers component, otherwise it will just add
// all server connections
RebuildEmptyObserversNetworkBehaviour comp = gameObject.AddComponent<RebuildEmptyObserversNetworkBehaviour>();
Assert.That(comp.hostVisibilityCalled, Is.EqualTo(0));
// call OnStartServer so that observers dict is created
identity.OnStartServer();
// rebuild will result in 0 observers. it won't contain host
// connection so it should call OnSetHostVisibility(false)
identity.RebuildObservers(true);
Assert.That(identity.observers.Count, Is.EqualTo(0));
Assert.That(comp.hostVisibilityCalled, Is.EqualTo(1));
Assert.That(comp.hostVisibilityValue, Is.False);
// clean up
NetworkServer.RemoveLocalConnection();
NetworkServer.Shutdown();
}
}
}