NodeSystemTests.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Immutable;
  2. using System.Reflection;
  3. using ChunkyImageLib.DataHolders;
  4. using PixiEditor.ChangeableDocument.Changeables.Animations;
  5. using PixiEditor.ChangeableDocument.Changeables.Graph;
  6. using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
  7. using PixiEditor.ChangeableDocument.Changeables.Interfaces;
  8. using PixiEditor.ChangeableDocument.Changes.NodeGraph;
  9. using PixiEditor.ChangeableDocument.Rendering;
  10. using PixiEditor.DrawingApi.Core.Bridge;
  11. using PixiEditor.DrawingApi.Skia;
  12. using PixiEditor.Numerics;
  13. namespace PixiEditor.Backend.Tests;
  14. public class NodeSystemTests
  15. {
  16. public NodeSystemTests()
  17. {
  18. DrawingBackendApi.SetupBackend(new SkiaDrawingBackend());
  19. }
  20. [Fact]
  21. public void TestThatNodeGraphExecutesEmptyOutputNode()
  22. {
  23. NodeGraph graph = new NodeGraph();
  24. OutputNode outputNode = new OutputNode();
  25. graph.AddNode(outputNode);
  26. using RenderingContext context = new RenderingContext(0, VecI.Zero, ChunkResolution.Full, new VecI(1, 1));
  27. graph.Execute(context);
  28. Assert.Null(outputNode.CachedResult);
  29. }
  30. [Fact]
  31. public void TestThatCreateSimpleNodeDoesntThrow()
  32. {
  33. var allNodeTypes = typeof(Node).Assembly.GetTypes()
  34. .Where(x =>
  35. x.IsAssignableTo(typeof(Node))
  36. && x is { IsAbstract: false, IsInterface: false }
  37. && x.GetCustomAttribute<PairNodeAttribute>() == null).ToList();
  38. IReadOnlyDocument target = new MockDocument();
  39. foreach (var type in allNodeTypes)
  40. {
  41. var node = NodeOperations.CreateNode(type, target);
  42. Assert.NotNull(node);
  43. }
  44. }
  45. [Fact]
  46. public void TestThatCreatePairNodeDoesntThrow()
  47. {
  48. var allNodeTypes = typeof(Node).Assembly.GetTypes()
  49. .Where(x =>
  50. x.IsAssignableTo(typeof(Node))
  51. && x is { IsAbstract: false, IsInterface: false }
  52. && x.GetCustomAttribute<PairNodeAttribute>() != null).ToList();
  53. IReadOnlyDocument target = new MockDocument();
  54. Dictionary<Type, Type> pairs = new();
  55. for (var i = 0; i < allNodeTypes.Count; i++)
  56. {
  57. var type = allNodeTypes[i];
  58. var pairAttribute = type.GetCustomAttribute<PairNodeAttribute>();
  59. if(pairAttribute == null) continue;
  60. if(!pairAttribute.IsStartingType) continue;
  61. pairs[type] = pairAttribute.OtherType;
  62. }
  63. foreach (var type in pairs)
  64. {
  65. var startNode = NodeOperations.CreateNode(type.Key, target);
  66. var endNode = NodeOperations.CreateNode(type.Value, target, startNode);
  67. Assert.NotNull(startNode);
  68. Assert.NotNull(endNode);
  69. }
  70. }
  71. }