From 8195f2dfe5b153c89e550424354b122458ce106f Mon Sep 17 00:00:00 2001
From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com>
Date: Fri, 21 May 2021 11:35:57 -0500
Subject: [PATCH 1/2] test
Updating this test to handle the following manual test scenarios:
T2910451 Verify empty arrays of custom types are being serialized
T2910452 Verify null arrays of custom types are being serialized
---
.../Tests/Runtime/RpcINetworkSerializable.cs | 76 +++++++++++++++----
1 file changed, 63 insertions(+), 13 deletions(-)
diff --git a/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs b/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
index 3fcb0e88d1..55a26abdf3 100644
--- a/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
+++ b/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
@@ -22,6 +22,8 @@ public class RpcINetworkSerializable
private bool m_FinishedTest;
+ private bool m_IsSendingNull;
+
[SetUp]
public void SetUp()
{
@@ -149,6 +151,40 @@ private void OnClientReceivedUserSerializableClassUpdated(UserSerializableClass
[UnityTest]
public IEnumerator NetworkSerializableArrayTest()
{
+ return NetworkSerializableArrayTestHandler(32);
+ }
+
+ ///
+ /// Tests that an array of the same type of class that implements the
+ /// INetworkSerializable interface can send an empty array
+ ///
+ ///
+ [UnityTest]
+ public IEnumerator NetworkSerializableEmptyArrayTest()
+ {
+ return NetworkSerializableArrayTestHandler(0);
+ }
+
+ ///
+ /// Tests that an array of the same type of class that implements the
+ /// INetworkSerializable interface can send a null value for the array
+ ///
+ ///
+ [UnityTest]
+ public IEnumerator NetworkSerializableNULLArrayTest()
+ {
+ return NetworkSerializableArrayTestHandler(0,true);
+ }
+
+ ///
+ /// Handles the various tests for INetworkSerializable arrays
+ ///
+ /// how many elements
+ /// force to send a null as the array value
+ ///
+ public IEnumerator NetworkSerializableArrayTestHandler(int arraySize, bool sendNullArray = false)
+ {
+ m_IsSendingNull = sendNullArray;
m_FinishedTest = false;
var numClients = 1;
var startTime = Time.realtimeSinceStartup;
@@ -199,16 +235,23 @@ public IEnumerator NetworkSerializableArrayTest()
m_UserSerializableClassArray = new List();
- // Create an array of userSerializableClass instances
- for (int i = 0; i < 32; i++)
+ if (!m_IsSendingNull)
{
- var userSerializableClass = new UserSerializableClass();
- //Used for testing order of the array
- userSerializableClass.MyintValue = i;
- m_UserSerializableClassArray.Add(userSerializableClass);
- }
+ // Create an array of userSerializableClass instances
+ for (int i = 0; i < 32; i++)
+ {
+ var userSerializableClass = new UserSerializableClass();
+ //Used for testing order of the array
+ userSerializableClass.MyintValue = i;
+ m_UserSerializableClassArray.Add(userSerializableClass);
+ }
- clientSideNetworkBehaviourClass.ClientStartTest(m_UserSerializableClassArray.ToArray());
+ clientSideNetworkBehaviourClass.ClientStartTest(m_UserSerializableClassArray.ToArray());
+ }
+ else
+ {
+ clientSideNetworkBehaviourClass.ClientStartTest(null);
+ }
// Wait until the test has finished or we time out
var timeOutPeriod = Time.realtimeSinceStartup + 5;
@@ -240,12 +283,19 @@ public IEnumerator NetworkSerializableArrayTest()
///
private void ValidateUserSerializableClasses(UserSerializableClass[] userSerializableClass)
{
- var indexCount = 0;
- // Check the order of the array
- foreach (var customTypeEntry in userSerializableClass)
+ if (m_IsSendingNull)
{
- Assert.AreEqual(customTypeEntry.MyintValue, indexCount);
- indexCount++;
+ Assert.IsNull(userSerializableClass);
+ }
+ else
+ {
+ var indexCount = 0;
+ // Check the order of the array
+ foreach (var customTypeEntry in userSerializableClass)
+ {
+ Assert.AreEqual(customTypeEntry.MyintValue, indexCount);
+ indexCount++;
+ }
}
}
From b5eb17553e75898d597d2085333ec669397531f8 Mon Sep 17 00:00:00 2001
From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com>
Date: Fri, 21 May 2021 11:49:44 -0500
Subject: [PATCH 2/2] refactor
Using the arraySize to determine how many elements to create.
Added additional logic to verify the empty array indeed was sent as an empty array.
---
.../Tests/Runtime/RpcINetworkSerializable.cs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs b/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
index 55a26abdf3..d860fb3207 100644
--- a/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
+++ b/testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs
@@ -23,6 +23,7 @@ public class RpcINetworkSerializable
private bool m_FinishedTest;
private bool m_IsSendingNull;
+ private bool m_IsArrayEmpty;
[SetUp]
public void SetUp()
@@ -186,6 +187,13 @@ public IEnumerator NetworkSerializableArrayTestHandler(int arraySize, bool sendN
{
m_IsSendingNull = sendNullArray;
m_FinishedTest = false;
+ m_IsArrayEmpty = false;
+
+ if (arraySize == 0)
+ {
+ m_IsArrayEmpty = true;
+ }
+
var numClients = 1;
var startTime = Time.realtimeSinceStartup;
@@ -238,7 +246,7 @@ public IEnumerator NetworkSerializableArrayTestHandler(int arraySize, bool sendN
if (!m_IsSendingNull)
{
// Create an array of userSerializableClass instances
- for (int i = 0; i < 32; i++)
+ for (int i = 0; i < arraySize; i++)
{
var userSerializableClass = new UserSerializableClass();
//Used for testing order of the array
@@ -287,6 +295,10 @@ private void ValidateUserSerializableClasses(UserSerializableClass[] userSeriali
{
Assert.IsNull(userSerializableClass);
}
+ else if (m_IsArrayEmpty)
+ {
+ Assert.AreEqual(userSerializableClass.Length,0);
+ }
else
{
var indexCount = 0;