Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back test : Generation TestGraphAsIs #7809

Draft
wants to merge 4 commits into
base: sg2/main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,79 +518,76 @@ public void IsSubPathWorks()
}
}

// TODO (Brett) This is commented out to bring tests to a passing status.
// TODO (Brett) This test was not removed because it is indicating a valuable failure
// TODO (Brett) that should be addressed.

// [Test]
// public void TestCopyPaste()
// {
// ContextLayeredDataStorage clds = new ContextLayeredDataStorage();
// clds.AddData("a");
// clds.AddData("a.b", 13);
// clds.AddData("a.b.c", 35.4f);
// clds.AddData("a.b.c.d.e", true);
// clds.SetMetadata("a.b", "foo", new Color(1, 0, 0));
//
// List<DataReader> elements = new List<DataReader>()
// {
// clds.Search("a"),
// clds.Search("a.b"),
// clds.Search("a.b.c"),
// clds.Search("a.b.c.d.e")
// };
//
// var ser = clds.CopyElementCollection(elements);
//
// //Paste into same CLDS
// clds.PasteElementCollection(ser.layer, ser.metadata, "Root", out _);
// var copied = clds.Search("a_1");
// Assert.NotNull(copied);
// Assert.IsTrue(copied.GetChildren().Count() == 1);
// copied = copied.GetChild("b");
// Assert.NotNull(copied);
// Assert.AreEqual(13, copied.GetData<int>());
// Assert.AreEqual(new Color(1, 0, 0), clds.GetMetadata<Color>(copied.Element.ID, "foo"));
// Assert.IsTrue(copied.GetChildren().Count() == 1);
// copied = copied.GetChild("c");
// Assert.NotNull(copied);
// Assert.AreEqual(35.4f, copied.GetData<float>());
// //Okay, so this is a weird one and I want to explain it, since either myself in 3 months or
// //whoever is looking at this code later might think this is a bug. Of course "c" has a child,
// //its "d.e"! But what needs to be remembered is we act on the flat structure, and "GetChildren"
// //will only return the _immediate_ children of a reader (at least in the base DataReader case).
// //That means, if "d" were contained in this structure, it could be returned. But since its not
// //here, and "d.e" wont be seen as an immediate child, its ignored.
// Assert.AreEqual(0, copied.GetChildren().Count());
// //This part though seems to go against that; "c" has no children, why can you getchild on "d.e"
// //and get a correct value? Currently, getchild just appends the rest of the localID onto c's
// //full path ID, and then just searches the graph for that, which will search for "a.b.c.d.e"
// //and find the correct value. The name could potentially be changed, but thats really up to
// //how the reader is implemented.
// copied = copied.GetChild("d.e");
// Assert.NotNull(copied);
// Assert.AreEqual(true, copied.GetData<bool>());
// Assert.IsTrue(copied.GetChildren().Count() == 0);
//
// //Paste into new CLDS
// clds = new ContextLayeredDataStorage();
// clds.PasteElementCollection(ser.layer, ser.metadata, "Root", out _);
// copied = clds.Search("a");
// Assert.NotNull(copied);
// Assert.IsTrue(copied.GetChildren().Count() == 1);
// copied = copied.GetChild("b");
// Assert.NotNull(copied);
// Assert.AreEqual(13, copied.GetData<int>());
// Assert.AreEqual(new Color(1, 0, 0), clds.GetMetadata<Color>(copied.Element.ID, "foo"));
// Assert.IsTrue(copied.GetChildren().Count() == 1);
// copied = copied.GetChild("c");
// Assert.NotNull(copied);
// Assert.AreEqual(35.4f, copied.GetData<float>());
// Assert.AreEqual(0, copied.GetChildren().Count());
// copied = copied.GetChild("d.e");
// Assert.NotNull(copied);
// Assert.AreEqual(true, copied.GetData<bool>());
// Assert.IsTrue(copied.GetChildren().Count() == 0);
// }
[Ignore("GSG-1614", Until="2023-03-15")]
[Test]
public void TestCopyPaste()
{
ContextLayeredDataStorage clds = new ContextLayeredDataStorage();
clds.AddData("a");
clds.AddData("a.b", 13);
clds.AddData("a.b.c", 35.4f);
clds.AddData("a.b.c.d.e", true);
clds.SetMetadata("a.b", "foo", new Color(1, 0, 0));

List<DataReader> elements = new List<DataReader>()
{
clds.Search("a"),
clds.Search("a.b"),
clds.Search("a.b.c"),
clds.Search("a.b.c.d.e")
};

var ser = clds.CopyElementCollection(elements);

//Paste into same CLDS
clds.PasteElementCollection(ser.layer, ser.metadata, "Root", out _);
var copied = clds.Search("a_1");
Assert.NotNull(copied);
Assert.IsTrue(copied.GetChildren().Count() == 1);
copied = copied.GetChild("b");
Assert.NotNull(copied);
Assert.AreEqual(13, copied.GetData<int>());
Assert.AreEqual(new Color(1, 0, 0), clds.GetMetadata<Color>(copied.Element.ID, "foo"));
Assert.IsTrue(copied.GetChildren().Count() == 1);
copied = copied.GetChild("c");
Assert.NotNull(copied);
Assert.AreEqual(35.4f, copied.GetData<float>());
//Okay, so this is a weird one and I want to explain it, since either myself in 3 months or
//whoever is looking at this code later might think this is a bug. Of course "c" has a child,
//its "d.e"! But what needs to be remembered is we act on the flat structure, and "GetChildren"
//will only return the _immediate_ children of a reader (at least in the base DataReader case).
//That means, if "d" were contained in this structure, it could be returned. But since its not
//here, and "d.e" wont be seen as an immediate child, its ignored.
Assert.AreEqual(0, copied.GetChildren().Count());
//This part though seems to go against that; "c" has no children, why can you getchild on "d.e"
//and get a correct value? Currently, getchild just appends the rest of the localID onto c's
//full path ID, and then just searches the graph for that, which will search for "a.b.c.d.e"
//and find the correct value. The name could potentially be changed, but thats really up to
//how the reader is implemented.
copied = copied.GetChild("d.e");
Assert.NotNull(copied);
Assert.AreEqual(true, copied.GetData<bool>());
Assert.IsTrue(copied.GetChildren().Count() == 0);

//Paste into new CLDS
clds = new ContextLayeredDataStorage();
clds.PasteElementCollection(ser.layer, ser.metadata, "Root", out _);
copied = clds.Search("a");
Assert.NotNull(copied);
Assert.IsTrue(copied.GetChildren().Count() == 1);
copied = copied.GetChild("b");
Assert.NotNull(copied);
Assert.AreEqual(13, copied.GetData<int>());
Assert.AreEqual(new Color(1, 0, 0), clds.GetMetadata<Color>(copied.Element.ID, "foo"));
Assert.IsTrue(copied.GetChildren().Count() == 1);
copied = copied.GetChild("c");
Assert.NotNull(copied);
Assert.AreEqual(35.4f, copied.GetData<float>());
Assert.AreEqual(0, copied.GetChildren().Count());
copied = copied.GetChild("d.e");
Assert.NotNull(copied);
Assert.AreEqual(true, copied.GetData<bool>());
Assert.IsTrue(copied.GetChildren().Count() == 0);
}
}
}
54 changes: 25 additions & 29 deletions com.unity.sg2/Tests/Generation/GenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,31 @@ private static Texture2D DrawToTex(Material material, int width = 4, int height

}

// TODO (Brett) This is disabled because of Generation errors with the Dec.
// TODO (Brett) branch update.
// TODO (Brett) Re-enable ASAP.

// static object[] testAsIsSource =
// {
// ("Add1", new Color(1,0,0,1)), //Colors with Alpha 1 since target is opaque
// ("Add2", new Color(0,1,0,1)),
// ("Add3", new Color(1,1,0,1)),
// };
//
// [Test]
// [TestCaseSource("testAsIsSource")]
// public static void TestGraphAsIs((string nodeToCompile, Color expectedColor) input)
// {
// var shaderString = Interpreter.GetShaderForNode(graph.GetNodeReader(input.nodeToCompile), graph, registry, out _);
// var shader = MakeShader(shaderString);
// var rt = DrawToTex(shader);
// try
// {
// var pixelColor = rt.GetPixel(0,0);
// Assert.AreEqual(pixelColor, input.expectedColor);
// }
// catch(Exception e)
// {
// File.WriteAllBytes($"Assets/FailureImage{input.nodeToCompile}.jpg", rt.EncodeToJPG());
// throw e;
// }
// }
static object[] testAsIsSource =
{
("Add1", new Color(1,0,0,1)), //Colors with Alpha 1 since target is opaque
("Add2", new Color(0,1,0,1)),
("Add3", new Color(1,1,0,1)),
};

[Test]
[TestCaseSource("testAsIsSource")]
public static void TestGraphAsIs((string nodeToCompile, Color expectedColor) input)
{
var shaderString = Interpreter.GetShaderForNode(graph.GetNodeReader(input.nodeToCompile), graph, registry, out _);
var shader = MakeShader(shaderString);
var rt = DrawToTex(shader);
try
{
var pixelColor = rt.GetPixel(0,0);
Assert.AreEqual(pixelColor, input.expectedColor);
}
catch(Exception e)
{
File.WriteAllBytes($"Assets/FailureImage{input.nodeToCompile}.jpg", rt.EncodeToJPG());
throw e;
}
}

[Test]
public static void TestGraphReferenceNode()
Expand Down
8 changes: 0 additions & 8 deletions com.unity.sg2/Tests/GraphUI/DataModel/Searcher.meta

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 20 additions & 21 deletions com.unity.sg2/Tests/GraphUI/GraphEdgeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@ class GraphEdgeTests : BaseGraphWindowTest
/// <inheritdoc />
protected override GraphInstantiation GraphToInstantiate => GraphInstantiation.MemoryBlank;

// TODO (Brett) This is commented out to bring tests to a passing status.
// TODO (Brett) This test was not removed because it is indicating a valuable failure
// TODO (Brett) that should be addressed.
[UnityTest]
public IEnumerator TestEdgeCanBeDeleted()
{
// create and connect two nodes
var addNodeModel = SGGraphTestUtils.CreateNodeByName(GraphModel,"Add", Vector2.zero);
Assert.NotNull(addNodeModel, "Add node could not be added to the graph");
var previewNodeModel = SGGraphTestUtils.CreateNodeByName(GraphModel, "Preview", Vector2.zero);
Assert.NotNull(previewNodeModel, "Preview node model could not be added to the graph");

// [UnityTest]
// public IEnumerator TestEdgeCanBeDeleted()
// {
// // Set up the graph
// yield return m_TestInteractionHelper.CreateNodesAndConnect();
//
// var edgeModel = m_MainWindow.GetEdgeModelFromGraphByName("Add", "Preview");
//
// // Select element programmatically because it might be behind another one
// m_GraphView.Dispatch(new SelectElementsCommand(SelectElementsCommand.SelectionMode.Replace, edgeModel));
// yield return null;
//
// Assert.IsTrue(m_TestEventHelper.SendDeleteCommand());
// yield return null;
//
// edgeModel = m_MainWindow.GetEdgeModelFromGraphByName("Add", "Preview");
// Assert.IsNull(edgeModel, "Edge should be null after delete operation");
// }
var edgeModel = m_MainWindow.GetEdgeModelFromGraphByName("Add", "Preview");

// Select element programmatically because it might be behind another one
m_GraphView.Dispatch(new SelectElementsCommand(SelectElementsCommand.SelectionMode.Replace, edgeModel));
yield return null;

Assert.IsTrue(m_TestEventHelper.SendDeleteCommand());
yield return null;

edgeModel = m_MainWindow.GetEdgeModelFromGraphByName("Add", "Preview");
Assert.IsNull(edgeModel, "Edge should be null after delete operation");
}
}
}