NetworkIdentityTests HandleRpc tests invalid component index / function hash too

This commit is contained in:
vis2k 2020-03-03 13:19:03 +01:00
parent b9dab2ca7a
commit bbcc3599ef

View File

@ -1268,10 +1268,21 @@ public void HandleRpc()
NetworkIdentity.spawned[identity.netId] = identity;
// call HandleRpc and check if the rpc was called in the component
int componentIndex = 0;
int functionHash = NetworkBehaviour.GetMethodHash(typeof(RpcTestNetworkBehaviour), nameof(RpcTestNetworkBehaviour.RpcGenerated));
NetworkReader payload = new NetworkReader(new byte[0]);
identity.HandleRPC(componentIndex, functionHash, payload);
identity.HandleRPC(0, functionHash, payload);
Assert.That(comp0.called, Is.EqualTo(1));
// try wrong component index. rpc shouldn't be called again.
LogAssert.ignoreFailingMessages = true; // warning is expected
identity.HandleRPC(1, functionHash, payload);
LogAssert.ignoreFailingMessages = false;
Assert.That(comp0.called, Is.EqualTo(1));
// try wrong function hash. rpc shouldn't be called again.
LogAssert.ignoreFailingMessages = true; // warning is expected
identity.HandleRPC(0, functionHash+1, payload);
LogAssert.ignoreFailingMessages = false;
Assert.That(comp0.called, Is.EqualTo(1));
// clean up