public IEnumerator BufferDataValidation() { Guid gameObjectId = NetworkManagerHelper.AddGameNetworkObject("GrowingBufferObject"); var growingRpcBufferSizeComponent = NetworkManagerHelper.AddComponentToObject <BufferDataValidationComponent>(gameObjectId); NetworkManagerHelper.SpawnNetworkObject(gameObjectId); // Start Testing growingRpcBufferSizeComponent.EnableTesting = true; var testsAreComplete = growingRpcBufferSizeComponent.IsTestComplete(); // Wait for the RPC pipeline test to complete or if we exceeded the maximum iterations bail while (!testsAreComplete) { yield return(new WaitForSeconds(0.003f)); testsAreComplete = growingRpcBufferSizeComponent.IsTestComplete(); } // Stop Testing growingRpcBufferSizeComponent.EnableTesting = false; // Just disable this once we are done. growingRpcBufferSizeComponent.gameObject.SetActive(false); Assert.IsTrue(testsAreComplete); }
public IEnumerator UpdateStagesInvocation() { Guid updateStagesTestId = NetworkManagerHelper.AddGameNetworkObject("UpdateStagesTest"); var rpcPipelineTestComponent = NetworkManagerHelper.AddComponentToObject <NetworkUpdateStagesComponent>(updateStagesTestId); NetworkManagerHelper.SpawnNetworkObject(updateStagesTestId); var testsAreComplete = rpcPipelineTestComponent.IsTestComplete(); var exceededMaximumStageIterations = rpcPipelineTestComponent.ExceededMaxIterations(); // Start testing rpcPipelineTestComponent.EnableTesting = true; Debug.Log("Running TestNetworkUpdateStages: "); // Wait for the RPC pipeline test to complete or if we exceeded the maximum iterations bail while (!testsAreComplete && !exceededMaximumStageIterations) { yield return(new WaitForSeconds(0.003f)); testsAreComplete = rpcPipelineTestComponent.IsTestComplete(); Assert.IsFalse(rpcPipelineTestComponent.ExceededMaxIterations()); } var testsAreValidated = rpcPipelineTestComponent.ValidateUpdateStages(); // Stop testing rpcPipelineTestComponent.EnableTesting = false; Debug.Log($"Exiting status => {nameof(testsAreComplete)}: {testsAreComplete} - {nameof(testsAreValidated)}: {testsAreValidated} -{nameof(exceededMaximumStageIterations)}: {exceededMaximumStageIterations}"); Assert.IsTrue(testsAreComplete && testsAreValidated); // Disable this so it isn't running any longer. rpcPipelineTestComponent.gameObject.SetActive(false); }
public void NetworkConfigInvalidNetworkPrefabTest() { var testPrefabObjectName = "NetworkPrefabHandlerTestObject"; Guid baseObjectID = NetworkManagerHelper.AddGameNetworkObject(testPrefabObjectName); NetworkObject baseObject = NetworkManagerHelper.InstantiatedNetworkObjects[baseObjectID]; // Add null entry NetworkManagerHelper.NetworkManagerObject.NetworkConfig.NetworkPrefabs.Add(null); // Add a NetworkPrefab with no prefab NetworkManagerHelper.NetworkManagerObject.NetworkConfig.NetworkPrefabs.Add(new Configuration.NetworkPrefab()); var validNetworkPrefab = new Configuration.NetworkPrefab(); validNetworkPrefab.Prefab = baseObject.gameObject; //Add a valid prefab NetworkManagerHelper.NetworkManagerObject.NetworkConfig.NetworkPrefabs.Add(validNetworkPrefab); var exceptionOccurred = false; try { NetworkManagerHelper.NetworkManagerObject.StartHost(); } catch { exceptionOccurred = true; } Assert.False(exceptionOccurred); }
public IEnumerator TestAllNetworkVariableTypes() { Guid gameObjectId = NetworkManagerHelper.AddGameNetworkObject("NetworkVariableTestComponent"); var networkVariableTestComponent = NetworkManagerHelper.AddComponentToObject <NetworkVariableTestComponent>(gameObjectId); NetworkManagerHelper.SpawnNetworkObject(gameObjectId); // Start Testing networkVariableTestComponent.EnableTesting = true; var testsAreComplete = networkVariableTestComponent.IsTestComplete(); // Wait for the NetworkVariable tests to complete while (!testsAreComplete) { yield return(new WaitForSeconds(0.003f)); testsAreComplete = networkVariableTestComponent.IsTestComplete(); } // Stop Testing networkVariableTestComponent.EnableTesting = false; Assert.IsTrue(networkVariableTestComponent.DidAllValuesChange()); // Disable this once we are done. networkVariableTestComponent.gameObject.SetActive(false); Assert.IsTrue(testsAreComplete); }
public void NetworkPrefabHandlerClass() { Assert.IsTrue(NetworkManagerHelper.StartNetworkManager(out _)); var testPrefabObjectName = "NetworkPrefabHandlerTestObject"; Guid baseObjectID = NetworkManagerHelper.AddGameNetworkObject(testPrefabObjectName); NetworkObject baseObject = NetworkManagerHelper.InstantiatedNetworkObjects[baseObjectID]; var networkPrefabHandler = new NetworkPrefabHandler(); var networkPrefaInstanceHandler = new NetworkPrefaInstanceHandler(baseObject); var prefabPosition = new Vector3(1.0f, 5.0f, 3.0f); var prefabRotation = new Quaternion(1.0f, 0.5f, 0.4f, 0.1f); //Register via GameObject var gameObjectRegistered = networkPrefabHandler.AddHandler(baseObject.gameObject, networkPrefaInstanceHandler); //Test result of registering via GameObject reference Assert.True(gameObjectRegistered); var spawnedObject = networkPrefabHandler.HandleNetworkPrefabSpawn(baseObject.GlobalObjectIdHash, 0, prefabPosition, prefabRotation); //Test that something was instantiated Assert.NotNull(spawnedObject); //Test that this is indeed an instance of our original object Assert.True(spawnedObject.name.Contains(testPrefabObjectName)); //Test for position and rotation Assert.True(prefabPosition == spawnedObject.transform.position); Assert.True(prefabRotation == spawnedObject.transform.rotation); networkPrefabHandler.HandleNetworkPrefabDestroy(spawnedObject); //Destroy our prefab instance networkPrefabHandler.RemoveHandler(baseObject); //Remove our handler //Register via NetworkObject gameObjectRegistered = networkPrefabHandler.AddHandler(baseObject, networkPrefaInstanceHandler); //Test result of registering via NetworkObject reference Assert.True(gameObjectRegistered); //Change it up prefabPosition = new Vector3(2.0f, 1.0f, 5.0f); prefabRotation = new Quaternion(4.0f, 1.5f, 5.4f, 5.1f); spawnedObject = networkPrefabHandler.HandleNetworkPrefabSpawn(baseObject.GlobalObjectIdHash, 0, prefabPosition, prefabRotation); //Test that something was instantiated Assert.NotNull(spawnedObject); //Test that this is indeed an instance of our original object Assert.True(spawnedObject.name.Contains(testPrefabObjectName)); //Test for position and rotation Assert.True(prefabPosition == spawnedObject.transform.position); Assert.True(prefabRotation == spawnedObject.transform.rotation); networkPrefabHandler.HandleNetworkPrefabDestroy(spawnedObject); //Destroy our prefab instance networkPrefabHandler.RemoveHandler(baseObject); //Remove our handler //Register via GlobalObjectIdHash gameObjectRegistered = networkPrefabHandler.AddHandler(baseObject.GlobalObjectIdHash, networkPrefaInstanceHandler); //Test result of registering via GlobalObjectIdHash reference Assert.True(gameObjectRegistered); //Change it up prefabPosition = new Vector3(6.0f, 4.0f, 1.0f); prefabRotation = new Quaternion(3f, 2f, 4f, 1f); spawnedObject = networkPrefabHandler.HandleNetworkPrefabSpawn(baseObject.GlobalObjectIdHash, 0, prefabPosition, prefabRotation); //Test that something was instantiated Assert.NotNull(spawnedObject); //Test that this is indeed an instance of our original object Assert.True(spawnedObject.name.Contains(testPrefabObjectName)); //Test for position and rotation Assert.True(prefabPosition == spawnedObject.transform.position); Assert.True(prefabRotation == spawnedObject.transform.rotation); networkPrefabHandler.HandleNetworkPrefabDestroy(spawnedObject); //Destroy our prefab instance networkPrefabHandler.RemoveHandler(baseObject); //Remove our handler Assert.False(networkPrefaInstanceHandler.StillHasInstances()); }