浏览代码

[Material graph]Logging

/main
Tim Cooper 9 年前
当前提交
c142890b
共有 2 个文件被更改,包括 78 次插入3 次删除
  1. 62
      UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/SerializedGraphTests.cs
  2. 19
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/Logging.cs

62
UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/SerializedGraphTests.cs


using System.Linq;
using NUnit.Framework;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Tests
{

[SetUpFixture]
public class SetUpClass
{
[SetUp]
void RunBeforeAnyTests()
{
Debug.logger.logHandler = new ConsoleLogHandler();
}
}
[Test]
public void TestCreate()
{

Assert.AreEqual(2, graph.nodes.Count());
graph.Connect(outputNode.FindOutputSlot("output"), inputNode.FindInputSlot("input"));
var createdEdge = graph.Connect(outputNode.FindOutputSlot("output"), inputNode.FindInputSlot("input"));
Assert.AreEqual(createdEdge, edge);
var foundOutputNode = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var foundOutputSlot = foundOutputNode.FindOutputSlot(edge.outputSlot.slotName);
Assert.AreEqual(foundOutputNode, outputNode);

var foundInputSlot = foundOutputNode.FindInputSlot(edge.inputSlot.slotName);
var foundInputSlot = foundInputNode.FindInputSlot(edge.inputSlot.slotName);
Assert.AreEqual(foundInputSlot, outputSlot);
Assert.AreEqual(foundInputSlot, inputSlot);
}
[Test]
public void TestCanNotConnectTwoOuputSlots()
{
var graph = new SerializableGraph();
var outputNode = new SerializableNode(graph);
var outputSlot = new SerializableSlot(outputNode, "output", "output", SlotType.Output);
outputNode.AddSlot(outputSlot);
graph.AddNode(outputNode);
var outputNode2 = new SerializableNode(graph);
var outputSlot2 = new SerializableSlot(outputNode2, "output", "output", SlotType.Output);
outputNode2.AddSlot(outputSlot2);
graph.AddNode(outputNode2);
Assert.AreEqual(2, graph.nodes.Count());
var createdEdge = graph.Connect(outputNode.FindOutputSlot("output"), outputNode2.FindOutputSlot("output"));
Assert.IsNull(createdEdge);
Assert.AreEqual(0, graph.edges.Count());
}
[Test]
public void TestCanNotConnectTwoInputSlots()
{
var graph = new SerializableGraph();
var inputNode = new SerializableNode(graph);
var inputSlot = new SerializableSlot(inputNode, "input", "input", SlotType.Input);
inputNode.AddSlot(inputSlot);
graph.AddNode(inputNode);
var inputNode2 = new SerializableNode(graph);
var inputSlot2 = new SerializableSlot(inputNode2, "input", "input", SlotType.Input);
inputNode2.AddSlot(inputSlot2);
graph.AddNode(inputNode2);
Assert.AreEqual(2, graph.nodes.Count());
var createdEdge = graph.Connect(inputNode.FindInputSlot("input"), inputNode.FindInputSlot("input"));
Assert.IsNull(createdEdge);
Assert.AreEqual(0, graph.edges.Count());
}
}

19
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/Logging.cs


using System;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class ConsoleLogHandler : ILogHandler
{
public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
{
var formatted = string.Format(format, args);
Console.WriteLine("{0}:{1} - {2}", logType, context, formatted);
}
public void LogException(Exception exception, UnityEngine.Object context)
{
Console.WriteLine("{0} - {1}", context, exception);
}
}
}
正在加载...
取消
保存