mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkBehaviourTests: RegisterDelegateDoesntOverwrite
This commit is contained in:
parent
7071794e46
commit
f22188ff0b
@ -93,6 +93,13 @@ public void CallSendEventInternal()
|
||||
}
|
||||
}
|
||||
|
||||
// we need to inherit from networkbehaviour to test protected functions
|
||||
public class NetworkBehaviourDelegateComponent : NetworkBehaviour
|
||||
{
|
||||
public static void Delegate(NetworkBehaviour comp, NetworkReader reader) {}
|
||||
public static void Delegate2(NetworkBehaviour comp, NetworkReader reader) {}
|
||||
}
|
||||
|
||||
public class NetworkBehaviourTests
|
||||
{
|
||||
GameObject gameObject;
|
||||
@ -611,6 +618,25 @@ public void InvokeSyncEvent()
|
||||
// clean up
|
||||
NetworkBehaviour.ClearDelegates();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RegisterDelegateDoesntOverwrite()
|
||||
{
|
||||
// registerdelegate is protected, but we can use
|
||||
// RegisterCommandDelegate which calls RegisterDelegate
|
||||
NetworkBehaviour.RegisterCommandDelegate(
|
||||
typeof(NetworkBehaviourDelegateComponent),
|
||||
nameof(NetworkBehaviourDelegateComponent.Delegate),
|
||||
NetworkBehaviourDelegateComponent.Delegate);
|
||||
|
||||
// registering the same name with a different callback shouldn't
|
||||
// work
|
||||
LogAssert.Expect(LogType.Error, "Function " + typeof(NetworkBehaviourDelegateComponent) + "." + nameof(NetworkBehaviourDelegateComponent.Delegate) + " and " + typeof(NetworkBehaviourDelegateComponent) + "." + nameof(NetworkBehaviourDelegateComponent.Delegate2) + " have the same hash. Please rename one of them");
|
||||
NetworkBehaviour.RegisterCommandDelegate(
|
||||
typeof(NetworkBehaviourDelegateComponent),
|
||||
nameof(NetworkBehaviourDelegateComponent.Delegate),
|
||||
NetworkBehaviourDelegateComponent.Delegate2);
|
||||
}
|
||||
}
|
||||
|
||||
// we need to inherit from networkbehaviour to test protected functions
|
||||
|
Loading…
Reference in New Issue
Block a user