mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Tests for static syncvar hooks (#1912)
* tests for static hooks * csproj
This commit is contained in:
parent
0b2dd5fd36
commit
1c2bb2c6a3
@ -43,6 +43,19 @@ void OnValueChanged(NetworkIdentity oldValue, NetworkIdentity newValue)
|
||||
HookCalled.Invoke(oldValue, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
class StaticHookBehaviour : NetworkBehaviour
|
||||
{
|
||||
[SyncVar(hook = nameof(OnValueChanged))]
|
||||
public int value = 0;
|
||||
|
||||
public static event Action<int, int> HookCalled;
|
||||
|
||||
static void OnValueChanged(int oldValue, int newValue)
|
||||
{
|
||||
HookCalled.Invoke(oldValue, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
class VirtualHookBase : NetworkBehaviour
|
||||
{
|
||||
@ -202,6 +215,32 @@ public void Hook_NotCalledWhenSyncingSameValue(bool intialState)
|
||||
Assert.That(callCount, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void StaticMethod_HookCalledWhenSyncingChangedValue(bool intialState)
|
||||
{
|
||||
StaticHookBehaviour serverObject = CreateObject<StaticHookBehaviour>();
|
||||
StaticHookBehaviour clientObject = CreateObject<StaticHookBehaviour>();
|
||||
|
||||
const int clientValue = 10;
|
||||
const int serverValue = 24;
|
||||
|
||||
serverObject.value = serverValue;
|
||||
clientObject.value = clientValue;
|
||||
|
||||
int hookcallCount = 0;
|
||||
StaticHookBehaviour.HookCalled += (oldValue, newValue) =>
|
||||
{
|
||||
hookcallCount++;
|
||||
Assert.That(oldValue, Is.EqualTo(clientValue));
|
||||
Assert.That(newValue, Is.EqualTo(serverValue));
|
||||
};
|
||||
|
||||
bool written = SyncToClient(serverObject, clientObject, intialState);
|
||||
Assert.IsTrue(written);
|
||||
Assert.That(hookcallCount, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
|
@ -198,6 +198,7 @@
|
||||
<Compile Include="WeaverSyncVarHookTests~\ErrorWhenNoHookWithCorrectParametersFound.cs" />
|
||||
<Compile Include="WeaverSyncVarHookTests~\ErrorWhenNoHookFound.cs" />
|
||||
<Compile Include="WeaverSyncVarHookTests~\FindsHookWhenOverMethodsWithSameNameExist.cs" />
|
||||
<Compile Include="WeaverSyncVarHookTests~\FindsStaticHook.cs" />
|
||||
<Compile Include="WeaverSyncVarTests~\SyncVarsCantBeArray.cs" />
|
||||
<Compile Include="WeaverSyncVarTests~\SyncVarsDerivedNetworkBehaviour.cs" />
|
||||
<Compile Include="WeaverSyncVarTests~\SyncVarsDifferentModule.cs" />
|
||||
|
@ -10,6 +10,18 @@ public void FindsPrivateHook()
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindsPublicHook()
|
||||
{
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindsStaticHook()
|
||||
{
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindsHookWithGameObjects()
|
||||
{
|
||||
@ -22,12 +34,6 @@ public void FindsHookWithNetworkIdentity()
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindsPublicHook()
|
||||
{
|
||||
Assert.That(weaverErrors, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindsHookWhenOverMethodsWithSameNameExist()
|
||||
{
|
||||
|
@ -0,0 +1,15 @@
|
||||
using Mirror;
|
||||
|
||||
namespace WeaverSyncVarHookTests.FindsStaticHook
|
||||
{
|
||||
class FindsStaticHook : NetworkBehaviour
|
||||
{
|
||||
[SyncVar(hook = nameof(onChangeHealth))]
|
||||
int health;
|
||||
|
||||
static void onChangeHealth(int oldValue, int newValue)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user