NetworkServerTests: OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest

This commit is contained in:
vis2k 2020-02-24 10:48:39 +01:00
parent 47a4ac7ff7
commit 9c325abbd8

View File

@ -136,6 +136,37 @@ public void ConnectionsDictTest()
NetworkServer.Shutdown();
}
[Test]
public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest()
{
// OnConnected should only allow connectionIds >= 0
// 0 is for local player
// <0 is never used
// message handlers
NetworkServer.RegisterHandler<ConnectMessage>((conn, msg) => {}, false);
NetworkServer.RegisterHandler<DisconnectMessage>((conn, msg) => {}, false);
NetworkServer.RegisterHandler<ErrorMessage>((conn, msg) => {}, false);
// listen
NetworkServer.Listen(2);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
// connect 0
// (it will show an error message, which is expected)
LogAssert.ignoreFailingMessages = true;
Transport.activeTransport.OnServerConnected.Invoke(0);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
// connect <0
Transport.activeTransport.OnServerConnected.Invoke(-1);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
LogAssert.ignoreFailingMessages = false;
// shutdown
NetworkServer.Shutdown();
}
[Test]
public void SetLocalConnectionTest()
{