[Test] public void CyclicRequirements() { ComponentRequirementMap map = new ComponentRequirementMap(); // In a cyclic dependency situation, behavior is undefined and there is no "right" solution. // For this test, just expect the system to not crash. Check some select results that we // can safely expect. TestingLogOutput logWatcher = new TestingLogOutput(); Logs.AddGlobalOutput(logWatcher); map.GetRequirements(typeof(TestComponentC1)); map.GetRequirements(typeof(TestComponentC2)); map.GetRequirements(typeof(TestComponentC3)); logWatcher.AssertNoErrors(); logWatcher.AssertWarning(); map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC1)); map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC2)); map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC3)); logWatcher.AssertNoErrors(); logWatcher.AssertWarning(); Assert.IsFalse(map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC1))); Assert.IsFalse(map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC2))); Assert.IsFalse(map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC3))); map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC2)); map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC3)); map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC1)); map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC3)); map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC1)); map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC2)); map.IsRequirementMet(new GameObject(), typeof(TestComponentC1)); map.IsRequirementMet(new GameObject(), typeof(TestComponentC2)); map.IsRequirementMet(new GameObject(), typeof(TestComponentC3)); map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2) }); map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3) }); map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1) }); map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2), typeof(TestComponentC3) }); map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3), typeof(TestComponentC1) }); map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1), typeof(TestComponentC2) }); Logs.RemoveGlobalOutput(logWatcher); }
[Test] public void ExecOrderLoopResolve() { // If there is a loop in the execution order requirements, make sure // a log informs the user about this. TestingLogOutput logWatcher = new TestingLogOutput(); Log.AddGlobalOutput(logWatcher); ComponentExecutionOrder order = new ComponentExecutionOrder(); List <Type> types = new List <Type>(); types.Add(typeof(TestComponentE1)); types.Add(typeof(TestComponentE2)); types.Add(typeof(TestComponentE3)); // Assert that we're still able to perform exec order sorting and // the constraint loop doesn't cause further problems. order.SortTypes(types, false); // Assert that there were no errors, but we got a warning. logWatcher.AssertNoErrors(); logWatcher.AssertWarning(); Log.RemoveGlobalOutput(logWatcher); }