A game about forced loneliness, made by TACStudios
1using System.Reflection; 2using System.Linq; 3using NUnit.Framework; 4using UnityEngine; 5using UnityEditor.Graphing; 6using UnityEditor.Experimental.GraphView; 7using UnityEditor.ShaderGraph.Drawing; 8 9namespace UnityEditor.ShaderGraph.UnitTests 10{ 11 [TestFixture] 12 class StackTests 13 { 14 static BlockFieldDescriptor s_DescriptorA = new BlockFieldDescriptor("Test", "BlockA", string.Empty, new FloatControl(0.0f), ShaderStage.Fragment, true); 15 static BlockFieldDescriptor s_DescriptorB = new BlockFieldDescriptor("Test", "BlockA", string.Empty, new FloatControl(0.0f), ShaderStage.Fragment, true); 16 17 [OneTimeSetUp] 18 public void RunBeforeAnyTests() 19 { 20 Debug.unityLogger.logHandler = new ConsoleLogHandler(); 21 } 22 23 [Test] 24 public void CanAddBlockNodeToContext() 25 { 26 GraphData graph = new GraphData(); 27 graph.AddContexts(); 28 29 var node = new BlockNode(); 30 node.Init(s_DescriptorA); 31 graph.AddBlock(node, graph.fragmentContext, 0); 32 33 Assert.AreEqual(0, graph.edges.Count()); 34 Assert.AreEqual(1, graph.GetNodes<BlockNode>().Count()); 35 Assert.AreEqual(1, graph.fragmentContext.blocks.Count()); 36 } 37 38 [Test] 39 public void CanRemoveBlockNodeFromContext() 40 { 41 GraphData graph = new GraphData(); 42 graph.AddContexts(); 43 44 var node = new BlockNode(); 45 node.Init(s_DescriptorA); 46 graph.AddBlock(node, graph.fragmentContext, 0); 47 graph.RemoveNode(node); 48 49 Assert.AreEqual(0, graph.edges.Count()); 50 Assert.AreEqual(0, graph.GetNodes<BlockNode>().Count()); 51 Assert.AreEqual(0, graph.fragmentContext.blocks.Count()); 52 } 53 54 [Test] 55 public void CanInsertBlockNodeToContext() 56 { 57 GraphData graph = new GraphData(); 58 graph.AddContexts(); 59 60 var nodeA = new BlockNode(); 61 nodeA.Init(s_DescriptorA); 62 graph.AddBlock(nodeA, graph.fragmentContext, 0); 63 64 var nodeB = new BlockNode(); 65 nodeB.Init(s_DescriptorA); 66 graph.AddBlock(nodeB, graph.fragmentContext, 0); 67 68 Assert.AreEqual(0, graph.edges.Count()); 69 Assert.AreEqual(2, graph.GetNodes<BlockNode>().Count()); 70 Assert.AreEqual(2, graph.fragmentContext.blocks.Count()); 71 Assert.AreEqual(nodeB, graph.fragmentContext.blocks[0].value); 72 } 73 74 [Test] 75 public void CanFilterBlockNodeByShaderStage() 76 { 77 GraphData graph = new GraphData(); 78 graph.AddContexts(); 79 80 var node = new BlockNode(); 81 node.Init(s_DescriptorA); 82 83 var contextView = new ContextView("Test", graph.vertexContext, null); 84 var methodInfo = typeof(StackNode).GetMethod("AcceptsElement", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(GraphElement), typeof(int).MakeByRefType(), typeof(int) }, null); 85 Assert.IsNotNull(methodInfo); 86 87 var acceptsElement = (bool)methodInfo.Invoke(contextView, new object[] { new MaterialNodeView() { userData = node }, 0, 0 }); 88 Assert.IsFalse(acceptsElement); 89 } 90 } 91}