public void Instantiate_SingleObjectInstantiatedFromPopulated_AddedToSystem(ObjectToggleConfig config) { // Validatate test case input FakeEnvironment.GetExpectedUpdateFlagsFromConfig( config, out bool updateExpected, out bool fixedUpdateExpected ); if (!(updateExpected || fixedUpdateExpected)) { throw new ArgumentException( "Invalid input for test. Config must be expected to have at least one type of update callback registered:\n" + config ); } // Arrange PopulateEnvironment(); // Act _environment.InstantiateManagedComponents <TestBasicManagedUpdatesComponent>( out TestBasicManagedUpdatesComponent[] components, TestData.DEFAULT_GROUP_NAME, config ); // Assert _environment.system.FindComponent(components[0].GetInstanceID(), out bool updateFound, out bool fixedUpdateFound); Assert.That( (updateExpected == updateFound) && (fixedUpdateExpected == fixedUpdateFound), $"Instantiated component should have at least one update callback registered with the system, matching what was expected.\n" + $"Update Expected/Result: {updateExpected}/{updateFound}\n" + $"FixedUpdate Expected/Result: {fixedUpdateExpected}/{fixedUpdateFound}" ); }
public void Instantiate_SingleObjectInstantiatedFromEmpty_NotAddedToSystem(ObjectToggleConfig config) { // Validate test case input FakeEnvironment.GetExpectedUpdateFlagsFromConfig( config, out bool updateExpected, out bool fixedUpdateExpected ); if (updateExpected || fixedUpdateExpected) { throw new ArgumentException( "Invalid input for test. Config must specify NONE of the update callbacks to be registered:\n" + config ); } // Act _environment.InstantiateManagedComponents <TestBasicManagedUpdatesComponent>( out TestBasicManagedUpdatesComponent[] components, TestData.DEFAULT_GROUP_NAME, config ); // Assert _environment.system.FindComponent(components[0].GetInstanceID(), out bool updateFound, out bool fixedUpdateFound); Assert.That( (updateExpected == updateFound) && (fixedUpdateExpected == fixedUpdateFound), $"Instantiated component should not have any update callbacks registered with the system.\n" + $"Update Expected/Result: {updateExpected}/{updateFound}\n" + $"FixedUpdate Expected/Result: {fixedUpdateExpected}/{fixedUpdateFound}" ); }
public void SetToggleConfig(ManagedUpdatesBehaviour component, ObjectToggleConfig toggleConfig) { component.gameObject.SetActive(toggleConfig.HasFlag(ObjectToggleConfig.GameObjectActive)); component.enabled = toggleConfig.HasFlag(ObjectToggleConfig.ComponentEnabled); component.updateConfig.update = toggleConfig.HasFlag(ObjectToggleConfig.Update); component.updateConfig.fixedUpdate = toggleConfig.HasFlag(ObjectToggleConfig.FixedUpdate); }
private static void RunToggleTest(FakeEnvironment env, ObjectToggleConfig initialConfig, ObjectToggleConfig finalConfig) { // Arrange TestBasicManagedUpdatesComponent[] components; env.InstantiateManagedComponents <TestBasicManagedUpdatesComponent>( out components, TestData.DEFAULT_GROUP_NAME, initialConfig ); FakeEnvironment.GetExpectedUpdateFlagsFromConfig( finalConfig, out bool updateExpectedFinal, out bool fixedUpdateExpectedFinal ); // Act ManagedUpdatesBehaviour component = components[0]; env.SetToggleConfig(component, finalConfig); // Assert env.system.FindComponent(component.GetInstanceID(), out bool updateFound, out bool fixedUpdateFound); Assert.That( (updateExpectedFinal == updateFound) && (fixedUpdateExpectedFinal == fixedUpdateFound), $"Configuration's expected state was not reflected in the system.\n" + $"Update Expected/Result: {updateExpectedFinal}/{updateFound}\n" + $"FixedUpdate Expected/Result: {fixedUpdateExpectedFinal}/{fixedUpdateFound}" ); }
internal static void GetExpectedUpdateFlagsFromConfig(ObjectToggleConfig config, out bool updateExpected, out bool fixedUpdateExpected) { updateExpected = config.HasFlag( ObjectToggleConfig.GameObjectActive | ObjectToggleConfig.ComponentEnabled | ObjectToggleConfig.Update ); fixedUpdateExpected = config.HasFlag( ObjectToggleConfig.GameObjectActive | ObjectToggleConfig.ComponentEnabled | ObjectToggleConfig.FixedUpdate ); }
private T InstantiateManagedUpdateGameObject <T>( ManagedExecutionGroup group, ObjectToggleConfig config, Transform parent = null) where T : ManagedUpdatesBehaviour { return(ManagedUpdatesBehaviour.Create <T>( new ManagedUpdatesBehaviour.Config( group, config.HasFlag(ObjectToggleConfig.Update), config.HasFlag(ObjectToggleConfig.FixedUpdate)), config.HasFlag(ObjectToggleConfig.GameObjectActive), config.HasFlag(ObjectToggleConfig.ComponentEnabled), parent )); }
public IEnumerator DestroyGameObject_SelfDestructAllOneByOneFromManagedCallbacks_AllRemovedFromSystem( [ValueSource(typeof(TestData), nameof(TestData.allActiveTogglePermutations))] ObjectToggleConfig config) { // Arrange string groupName = TestData.DEFAULT_GROUP_NAME; _environment.InstantiateManagedComponents <TestManagedUpdatesSelfDestruct>( out TestManagedUpdatesSelfDestruct[] components, groupName, config, config // Test requires at least two components to cover different states of the callback lists ); int originalComponentCount = components.Length; int numDestroyed = 0; // Store the instance ids so we can check the system for components that were theoretically destroyed. var componentInstanceIds = new int[originalComponentCount]; for (int i = 0; i < originalComponentCount; i++) { TestManagedUpdatesSelfDestruct component = components[i]; component.OnSelfDestruct.AddListener(() => { numDestroyed++; }); componentInstanceIds[i] = component.GetInstanceID(); } // Act float expectedLifetime = 0.2f; foreach (var component in components) { component.StartCountdown(expectedLifetime); yield return(new WaitForSeconds(expectedLifetime)); } float timeout = Time.time + 0.3333f; while (numDestroyed < originalComponentCount) { yield return(new WaitForEndOfFrame()); if (Time.time >= timeout) { throw new System.Exception("Self destruct test timed out."); } } // Assert bool noUpdatesFound = true; bool noFixedUpdatesFound = true; foreach (var id in componentInstanceIds) { _environment.system.FindComponent( id, out bool updateFound, out bool fixedUpdateFound ); noUpdatesFound &= !updateFound; noFixedUpdatesFound &= !fixedUpdateFound; } Assert.That( noUpdatesFound && noFixedUpdatesFound, "At least one component did not successfully self-destruct and remove itself from the execution system:\n" + $"Updates found? {!noUpdatesFound}\n" + $"FixedUpdates found? {!noFixedUpdatesFound}" ); }
public void TryRemove_SingleFixedUpdateToggledOff_RemovedFromSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig & ~ObjectToggleConfig.FixedUpdate); }
public void TryRemove_SingleComponentToggledOff_RemovedFromSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig & ~ObjectToggleConfig.ComponentEnabled); }
public void TryRemove_SingleGameObjectToggledOff_RemovedFromSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig & ~ObjectToggleConfig.GameObjectActive); }
public void TryAdd_SingleFixedUpdateFlagToggledOn_CorrectFlagsAddedToSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig | ObjectToggleConfig.FixedUpdate); }
public void TryAdd_SingleComponentToggledOn_CorrectFlagsAddedToSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig | ObjectToggleConfig.ComponentEnabled); }
public void TryAdd_SingleGameObjectToggledOn_CorrectFlagsAddedToSystem(ObjectToggleConfig initialConfig) { RunToggleTest(_environment, initialConfig, initialConfig | ObjectToggleConfig.GameObjectActive); }