[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); }
[Test] public void SaveMultipleResourcesToStream() { // In this test, we will check whether it's possible to save and load multiple // Resources sequentially into the same stream without problems. Note that this // is specifically about Resources, not "data" in general. Pixmap[] sourceData = new Pixmap[] { new Pixmap(new PixelData(1, 1, ColorRgba.Red)), new Pixmap(new PixelData(1, 1, ColorRgba.Green)), new Pixmap(new PixelData(1, 1, ColorRgba.Blue)), }; Pixmap[] targetData = new Pixmap[sourceData.Length]; TestingLogOutput logWatcher = new TestingLogOutput(); Log.AddGlobalOutput(logWatcher); // Save and load resources into a memory stream sequentially. // We expect no errors. using (MemoryStream stream = new MemoryStream()) { for (int i = 0; i < sourceData.Length; i++) { sourceData[i].Save(stream); } stream.Position = 0; for (int i = 0; i < targetData.Length; i++) { targetData[i] = Resource.Load <Pixmap>(stream); } } // Assert that there were no errors or warnings, i.e. everything // went allright. this.logWatcher.AssertNoErrorsOrWarnings(); // Do a simple sanity check of the data. No extensive comparison, // we've dealt with that in lots of other tests. for (int i = 0; i < sourceData.Length; i++) { Assert.IsNotNull(targetData[i]); Assert.IsNotNull(targetData[i].MainLayer); Assert.AreNotSame(sourceData[i], targetData[i]); Assert.AreNotSame(sourceData[i].MainLayer, targetData[i].MainLayer); } }
[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); }