@@ -22,6 +22,9 @@ public class RpcINetworkSerializable
22
22
23
23
private bool m_FinishedTest ;
24
24
25
+ private bool m_IsSendingNull ;
26
+ private bool m_IsArrayEmpty ;
27
+
25
28
[ SetUp ]
26
29
public void SetUp ( )
27
30
{
@@ -149,7 +152,48 @@ private void OnClientReceivedUserSerializableClassUpdated(UserSerializableClass
149
152
[ UnityTest ]
150
153
public IEnumerator NetworkSerializableArrayTest ( )
151
154
{
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 ;
152
189
m_FinishedTest = false ;
190
+ m_IsArrayEmpty = false ;
191
+
192
+ if ( arraySize == 0 )
193
+ {
194
+ m_IsArrayEmpty = true ;
195
+ }
196
+
153
197
var numClients = 1 ;
154
198
var startTime = Time . realtimeSinceStartup ;
155
199
@@ -199,16 +243,23 @@ public IEnumerator NetworkSerializableArrayTest()
199
243
200
244
m_UserSerializableClassArray = new List < UserSerializableClass > ( ) ;
201
245
202
- // Create an array of userSerializableClass instances
203
- for ( int i = 0 ; i < 32 ; i ++ )
246
+ if ( ! m_IsSendingNull )
204
247
{
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
+ }
210
256
211
- clientSideNetworkBehaviourClass . ClientStartTest ( m_UserSerializableClassArray . ToArray ( ) ) ;
257
+ clientSideNetworkBehaviourClass . ClientStartTest ( m_UserSerializableClassArray . ToArray ( ) ) ;
258
+ }
259
+ else
260
+ {
261
+ clientSideNetworkBehaviourClass . ClientStartTest ( null ) ;
262
+ }
212
263
213
264
// Wait until the test has finished or we time out
214
265
var timeOutPeriod = Time . realtimeSinceStartup + 5 ;
@@ -240,12 +291,23 @@ public IEnumerator NetworkSerializableArrayTest()
240
291
/// <param name="userSerializableClass"></param>
241
292
private void ValidateUserSerializableClasses ( UserSerializableClass [ ] userSerializableClass )
242
293
{
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 )
246
299
{
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
+ }
249
311
}
250
312
}
251
313
0 commit comments