Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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