Skip to content

Commit 0ebc1e6

Browse files
authored
Merge branch 'develop' into feature/adding-exception-for-client-side-player-object-get
2 parents 6343644 + 75de2e0 commit 0ebc1e6

File tree

1 file changed

+75
-13
lines changed

1 file changed

+75
-13
lines changed

testproject/Assets/Tests/Runtime/RpcINetworkSerializable.cs

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class RpcINetworkSerializable
2222

2323
private bool m_FinishedTest;
2424

25+
private bool m_IsSendingNull;
26+
private bool m_IsArrayEmpty;
27+
2528
[SetUp]
2629
public void SetUp()
2730
{
@@ -149,7 +152,48 @@ private void OnClientReceivedUserSerializableClassUpdated(UserSerializableClass
149152
[UnityTest]
150153
public IEnumerator NetworkSerializableArrayTest()
151154
{
155+
return NetworkSerializableArrayTestHandler(32);
156+
}
157+
158+
/// <summary>
159+
/// Tests that an array of the same type of class that implements the
160+
/// INetworkSerializable interface can send an empty array
161+
/// </summary>
162+
/// <returns></returns>
163+
[UnityTest]
164+
public IEnumerator NetworkSerializableEmptyArrayTest()
165+
{
166+
return NetworkSerializableArrayTestHandler(0);
167+
}
168+
169+
/// <summary>
170+
/// Tests that an array of the same type of class that implements the
171+
/// INetworkSerializable interface can send a null value for the array
172+
/// </summary>
173+
/// <returns></returns>
174+
[UnityTest]
175+
public IEnumerator NetworkSerializableNULLArrayTest()
176+
{
177+
return NetworkSerializableArrayTestHandler(0,true);
178+
}
179+
180+
/// <summary>
181+
/// Handles the various tests for INetworkSerializable arrays
182+
/// </summary>
183+
/// <param name="arraySize">how many elements</param>
184+
/// <param name="sendNullArray">force to send a null as the array value</param>
185+
/// <returns></returns>
186+
public IEnumerator NetworkSerializableArrayTestHandler(int arraySize, bool sendNullArray = false)
187+
{
188+
m_IsSendingNull = sendNullArray;
152189
m_FinishedTest = false;
190+
m_IsArrayEmpty = false;
191+
192+
if (arraySize == 0)
193+
{
194+
m_IsArrayEmpty = true;
195+
}
196+
153197
var numClients = 1;
154198
var startTime = Time.realtimeSinceStartup;
155199

@@ -199,16 +243,23 @@ public IEnumerator NetworkSerializableArrayTest()
199243

200244
m_UserSerializableClassArray = new List<UserSerializableClass>();
201245

202-
// Create an array of userSerializableClass instances
203-
for (int i = 0; i < 32; i++)
246+
if (!m_IsSendingNull)
204247
{
205-
var userSerializableClass = new UserSerializableClass();
206-
//Used for testing order of the array
207-
userSerializableClass.MyintValue = i;
208-
m_UserSerializableClassArray.Add(userSerializableClass);
209-
}
248+
// Create an array of userSerializableClass instances
249+
for (int i = 0; i < arraySize; i++)
250+
{
251+
var userSerializableClass = new UserSerializableClass();
252+
//Used for testing order of the array
253+
userSerializableClass.MyintValue = i;
254+
m_UserSerializableClassArray.Add(userSerializableClass);
255+
}
210256

211-
clientSideNetworkBehaviourClass.ClientStartTest(m_UserSerializableClassArray.ToArray());
257+
clientSideNetworkBehaviourClass.ClientStartTest(m_UserSerializableClassArray.ToArray());
258+
}
259+
else
260+
{
261+
clientSideNetworkBehaviourClass.ClientStartTest(null);
262+
}
212263

213264
// Wait until the test has finished or we time out
214265
var timeOutPeriod = Time.realtimeSinceStartup + 5;
@@ -240,12 +291,23 @@ public IEnumerator NetworkSerializableArrayTest()
240291
/// <param name="userSerializableClass"></param>
241292
private void ValidateUserSerializableClasses(UserSerializableClass[] userSerializableClass)
242293
{
243-
var indexCount = 0;
244-
// Check the order of the array
245-
foreach (var customTypeEntry in userSerializableClass)
294+
if (m_IsSendingNull)
295+
{
296+
Assert.IsNull(userSerializableClass);
297+
}
298+
else if (m_IsArrayEmpty)
246299
{
247-
Assert.AreEqual(customTypeEntry.MyintValue, indexCount);
248-
indexCount++;
300+
Assert.AreEqual(userSerializableClass.Length,0);
301+
}
302+
else
303+
{
304+
var indexCount = 0;
305+
// Check the order of the array
306+
foreach (var customTypeEntry in userSerializableClass)
307+
{
308+
Assert.AreEqual(customTypeEntry.MyintValue, indexCount);
309+
indexCount++;
310+
}
249311
}
250312
}
251313

0 commit comments

Comments
 (0)