using System; using System.Collections.Generic; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using Attribute = System.Attribute; namespace UnityEngine.TestTools.Graphics { /// /// Marks a test which takes GraphicsTestCase instances as wanting to have them generated automatically by /// the scene/reference-image management feature in the framework. /// public class UseGraphicsTestCasesAttribute : Attribute, ITestBuilder { /// /// The IGraphicsTestCaseProvider which will be used to generate the GraphicsTestCase instances for the tests. /// public static IGraphicsTestCaseProvider Provider { get { #if UNITY_EDITOR return new UnityEditor.TestTools.Graphics.EditorGraphicsTestCaseProvider(); #else return new RuntimeGraphicsTestCaseProvider(); #endif } } IEnumerable ITestBuilder.BuildFrom(IMethodInfo method, Test suite) { List results = new List(); IGraphicsTestCaseProvider provider = Provider; try { foreach (var testCase in provider.GetTestCases()) { var test = new TestMethod(method, suite) { parms = new TestCaseParameters(new object[] {testCase}) }; test.parms.ApplyToTest(test); test.Name = System.IO.Path.GetFileNameWithoutExtension(testCase.ScenePath); results.Add(test); } } catch (Exception ex) { Console.WriteLine("Failed to generate graphics testcases!"); Debug.LogException(ex); throw; } suite.Properties.Set("ColorSpace", provider.ColorSpace); suite.Properties.Set("RuntimePlatform", provider.Platform); suite.Properties.Set("GraphicsDevice", provider.GraphicsDevice); Console.WriteLine("Generated {0} graphics test cases.", results.Count); return results; } } }