-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(RPC): fixing rpc calls to base methods and overloads
adding more test for overload and base class rpcs
- Loading branch information
1 parent
4dcd604
commit 8bc165d
Showing
14 changed files
with
350 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 64 additions & 6 deletions
70
Assets/Tests/Runtime/ClientServer/RpcTests/CallToNonRpcBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,80 @@ | ||
using System; | ||
using System.Collections; | ||
using NSubstitute; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.ClientServer.RpcTests | ||
{ | ||
class CallToNonRpcBase_behaviour : CallToNonRpcBase_base | ||
public class CallToNonRpcBase_behaviour : CallToNonRpcBase_base | ||
{ | ||
public event Action<int> clientRpcCalled; | ||
public event Action<int> serverRpcCalled; | ||
|
||
[ClientRpc] | ||
public override void RpcThatIsTotallyValid(int a) | ||
public override void MyRpc(int arg1) | ||
{ | ||
clientRpcCalled?.Invoke(arg1); | ||
|
||
// should call normal base method, no swapping to rpc (that doesn't exist) | ||
base.RpcThatIsTotallyValid(a); | ||
base.MyRpc(arg1); | ||
} | ||
|
||
[ServerRpc(requireAuthority = false)] | ||
public void MyRpc(int arg1, INetworkPlayer sender) | ||
{ | ||
serverRpcCalled?.Invoke(arg1); | ||
|
||
// should call normal base method, no swapping to rpc (that doesn't exist) | ||
base.MyRpc(arg1); | ||
} | ||
} | ||
|
||
class CallToNonRpcBase_base : NetworkBehaviour | ||
public class CallToNonRpcBase_base : NetworkBehaviour | ||
{ | ||
public event Action<int> baseCalled; | ||
|
||
// not an rpc, override is, so it should just be called normally on receiver | ||
public virtual void RpcThatIsTotallyValid(int a) { } | ||
public virtual void MyRpc(int arg1) | ||
{ | ||
baseCalled?.Invoke(arg1); | ||
} | ||
} | ||
|
||
public class CallToNonRpcBase : ClientServerSetup<MockComponent> | ||
public class CallToNonRpcBase : ClientServerSetup<CallToNonRpcBase_behaviour> | ||
{ | ||
|
||
[UnityTest] | ||
public IEnumerator CanCallServerRpc() | ||
{ | ||
const int num = 32; | ||
Action<int> sub = Substitute.For<Action<int>>(); | ||
Action<int> baseSub = Substitute.For<Action<int>>(); | ||
serverComponent.serverRpcCalled += sub; | ||
serverComponent.baseCalled += baseSub; | ||
clientComponent.MyRpc(num, default(INetworkPlayer)); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
sub.Received(1).Invoke(num); | ||
baseSub.Received(1).Invoke(num); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator CanCallClientRpc() | ||
{ | ||
const int num = 32; | ||
Action<int> sub = Substitute.For<Action<int>>(); | ||
Action<int> baseSub = Substitute.For<Action<int>>(); | ||
clientComponent.clientRpcCalled += sub; | ||
clientComponent.baseCalled += baseSub; | ||
serverComponent.MyRpc(num); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
sub.Received(1).Invoke(num); | ||
baseSub.Received(1).Invoke(num); | ||
} | ||
} | ||
} |
73 changes: 67 additions & 6 deletions
73
Assets/Tests/Runtime/ClientServer/RpcTests/CallToNonRpcOverLoad.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,81 @@ | ||
using System; | ||
using System.Collections; | ||
using NSubstitute; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.ClientServer.RpcTests | ||
{ | ||
class CallToNonRpcOverLoad_behaviour : NetworkBehaviour | ||
// normal and rpc method in same class | ||
public class CallToNonRpcOverLoad_behaviour : NetworkBehaviour | ||
{ | ||
// normal and rpc method in same class | ||
public event Action<int> clientRpcCalled; | ||
public event Action<int> serverRpcCalled; | ||
public event Action<int> overloadCalled; | ||
|
||
[ClientRpc(target = RpcTarget.Player)] | ||
public void RpcThatIsTotallyValid(INetworkPlayer player, int a) | ||
public void MyRpc(INetworkPlayer player, int arg1) | ||
{ | ||
clientRpcCalled?.Invoke(arg1); | ||
|
||
// should call overload without any problem | ||
RpcThatIsTotallyValid(a); | ||
MyRpc(arg1); | ||
} | ||
|
||
public void RpcThatIsTotallyValid(int a) { } | ||
[ServerRpc(requireAuthority = false)] | ||
public void MyRpc(int arg1, INetworkPlayer sender) | ||
{ | ||
serverRpcCalled?.Invoke(arg1); | ||
|
||
// should call base user code, not generated rpc | ||
MyRpc(arg1); | ||
} | ||
|
||
public void MyRpc(int arg1) | ||
{ | ||
overloadCalled?.Invoke(arg1); | ||
} | ||
} | ||
|
||
public class CallToNonRpcOverLoad : ClientServerSetup<MockComponent> | ||
public class CallToNonRpcOverLoad : ClientServerSetup<CallToNonRpcOverLoad_behaviour> | ||
{ | ||
[UnityTest] | ||
public IEnumerator CanCallServerRpc() | ||
{ | ||
const int num = 32; | ||
Action<int> clientSub = Substitute.For<Action<int>>(); | ||
Action<int> serverSub = Substitute.For<Action<int>>(); | ||
Action<int> overloadSub = Substitute.For<Action<int>>(); | ||
serverComponent.clientRpcCalled += clientSub; | ||
serverComponent.serverRpcCalled += serverSub; | ||
serverComponent.overloadCalled += overloadSub; | ||
clientComponent.MyRpc(num, default(INetworkPlayer)); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
clientSub.DidNotReceive().Invoke(num); | ||
serverSub.Received(1).Invoke(num); | ||
overloadSub.Received(1).Invoke(num); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator CanCallClientRpc() | ||
{ | ||
const int num = 32; | ||
Action<int> clientSub = Substitute.For<Action<int>>(); | ||
Action<int> serverSub = Substitute.For<Action<int>>(); | ||
Action<int> overloadSub = Substitute.For<Action<int>>(); | ||
clientComponent.clientRpcCalled += clientSub; | ||
clientComponent.serverRpcCalled += serverSub; | ||
clientComponent.overloadCalled += overloadSub; | ||
serverComponent.MyRpc(serverPlayer, num); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
clientSub.Received(1).Invoke(num); | ||
serverSub.DidNotReceive().Invoke(num); | ||
overloadSub.Received(1).Invoke(num); | ||
} | ||
} | ||
} |
Oops, something went wrong.