-
-
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.
- Loading branch information
1 parent
f605c46
commit 90e9f24
Showing
6 changed files
with
261 additions
and
49 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
74 changes: 74 additions & 0 deletions
74
Assets/Tests/Runtime/ClientServer/Generics/WithGenericSyncVarEvent.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.ClientServer.Generics | ||
{ | ||
public class WithGenericSyncVarEvent_behaviour<T> : NetworkBehaviour | ||
{ | ||
public event Action<T, T> hook; | ||
|
||
[SyncVar(hook = nameof(hook))] | ||
public T value; | ||
} | ||
|
||
public class WithGenericSyncVarEvent_behaviourInt : WithGenericSyncVarEvent_behaviour<int> | ||
{ | ||
} | ||
public class WithGenericSyncVarEvent_behaviourObject : WithGenericSyncVarEvent_behaviour<MyClass> | ||
{ | ||
} | ||
|
||
public class WithGenericSyncVarEventInt : ClientServerSetup<WithGenericSyncVarEvent_behaviourInt> | ||
{ | ||
[Test] | ||
public void DoesNotError() | ||
{ | ||
// passes setup without errors | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator HookEventCalled() | ||
{ | ||
const int num = 32; | ||
Action<int, int> hook = Substitute.For<Action<int, int>>(); | ||
clientComponent.hook += hook; | ||
serverComponent.value = num; | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
hook.Received(1).Invoke(0, num); | ||
} | ||
} | ||
public class WithGenericSyncVarEventObject : ClientServerSetup<WithGenericSyncVarEvent_behaviourObject> | ||
{ | ||
[Test] | ||
public void DoesNotError() | ||
{ | ||
// passes setup without errors | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator HookEventCalled() | ||
{ | ||
const int num = 32; | ||
Action<MyClass, MyClass> hook = Substitute.For<Action<MyClass, MyClass>>(); | ||
|
||
clientComponent.hook += hook; | ||
serverComponent.value = new MyClass { Value = num }; | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
hook.Received(1).Invoke( | ||
Arg.Is<MyClass>(x => x == null), | ||
Arg.Is<MyClass>(x => x != null && x.Value == num) | ||
); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/ClientServer/Generics/WithGenericSyncVarEvent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
133 changes: 133 additions & 0 deletions
133
Assets/Tests/Runtime/ClientServer/Generics/WithGenericSyncVarHookBig.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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Collections; | ||
using Mirage.Serialization; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
namespace Mirage.Tests.Runtime.ClientServer.Generics | ||
{ | ||
public class WithGenericSyncVarBig_behaviour<T> : NetworkBehaviour | ||
{ | ||
public event Action<T, T> hookMethod; | ||
|
||
[SyncVar(hook = nameof(onValueChanged))] | ||
public T value1; | ||
|
||
void onValueChanged(T oldValue, T newValue) | ||
{ | ||
hookMethod?.Invoke(oldValue, newValue); | ||
} | ||
|
||
public event Action<T, T> hookEvent; | ||
|
||
[SyncVar(hook = nameof(hookEvent))] | ||
public T value2; | ||
[SyncVar] | ||
public int value3; | ||
[SyncVar] | ||
public T value4; | ||
|
||
public T valueNotVar; | ||
} | ||
|
||
public class WithGenericSyncVarBig_behaviourInt : WithGenericSyncVarBig_behaviour<int> | ||
{ | ||
} | ||
public class WithGenericSyncVarBig_behaviourObject : WithGenericSyncVarBig_behaviour<MyClass> | ||
{ | ||
} | ||
|
||
public class WithGenericSyncVarBigInt : ClientServerSetup<WithGenericSyncVarBig_behaviourInt> | ||
{ | ||
[Test] | ||
public void DoesNotError() | ||
{ | ||
// passes setup without errors | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator HookEventCalled() | ||
{ | ||
const int num1 = 32; | ||
const int num2 = 132; | ||
const int num3 = 232; | ||
const int num4 = 332; | ||
Action<int, int> hook1 = Substitute.For<Action<int, int>>(); | ||
Action<int, int> hook2 = Substitute.For<Action<int, int>>(); | ||
clientComponent.hookMethod += hook1; | ||
clientComponent.hookEvent += hook2; | ||
|
||
serverComponent.value1 = num1; | ||
serverComponent.value2 = num2; | ||
serverComponent.value3 = num3; | ||
serverComponent.value4 = num4; | ||
|
||
|
||
var writer = new NetworkWriter(500); | ||
serverComponent.SerializeSyncVars(writer, false); | ||
var reader = new NetworkReader(); | ||
reader.Reset(writer.ToArraySegment()); | ||
|
||
clientComponent.DeserializeSyncVars(reader, false); | ||
|
||
hook1.Received(1).Invoke(0, num1); | ||
//hook2.Received(1).Invoke(0, num2); | ||
Assert.That(clientComponent.value1, Is.EqualTo(num1)); | ||
Assert.That(clientComponent.value2, Is.EqualTo(num2)); | ||
Assert.That(clientComponent.value3, Is.EqualTo(num3)); | ||
Assert.That(clientComponent.value4, Is.EqualTo(num4)); | ||
|
||
yield return null; | ||
yield return null; | ||
} | ||
} | ||
public class WithGenericSyncVarBigObject : ClientServerSetup<WithGenericSyncVarBig_behaviourObject> | ||
{ | ||
[Test] | ||
public void DoesNotError() | ||
{ | ||
// passes setup without errors | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator HookEventCalled() | ||
{ | ||
const int num1 = 32; | ||
const int num2 = 132; | ||
const int num3 = 232; | ||
const int num4 = 332; | ||
Action<MyClass, MyClass> hook1 = Substitute.For<Action<MyClass, MyClass>>(); | ||
Action<MyClass, MyClass> hook2 = Substitute.For<Action<MyClass, MyClass>>(); | ||
clientComponent.hookMethod += hook1; | ||
clientComponent.hookEvent += hook2; | ||
|
||
serverComponent.value1 = new MyClass { Value = num1 }; | ||
serverComponent.value2 = new MyClass { Value = num2 }; | ||
serverComponent.value3 = num3; | ||
serverComponent.value4 = new MyClass { Value = num4 }; | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
hook1.Received(1).Invoke( | ||
Arg.Is<MyClass>(x => x == null), | ||
Arg.Is<MyClass>(x => x != null && x.Value == num1) | ||
); | ||
hook2.Received(1).Invoke( | ||
Arg.Is<MyClass>(x => x == null), | ||
Arg.Is<MyClass>(x => x != null && x.Value == num2) | ||
); | ||
Assert.That(clientComponent.value1, Is.Not.Null); | ||
Assert.That(clientComponent.value2, Is.Not.Null); | ||
Assert.That(clientComponent.value3, Is.Not.Null); | ||
Assert.That(clientComponent.value4, Is.Not.Null); | ||
Assert.That(clientComponent.value1.Value, Is.EqualTo(num1)); | ||
Assert.That(clientComponent.value2.Value, Is.EqualTo(num2)); | ||
Assert.That(clientComponent.value3, Is.EqualTo(num3)); | ||
Assert.That(clientComponent.value4.Value, Is.EqualTo(num4)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/Runtime/ClientServer/Generics/WithGenericSyncVarHookBig.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.