Skip to content

Commit 16be718

Browse files
committed
added tests for different herarchy exports
1 parent fcaa2b5 commit 16be718

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

Assets/FbxExporters/Editor/UnitTests/DefaultSelectionTest.cs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,36 @@ public void TestDefaultSelection ()
7474
var root = CreateHierarchy ();
7575
Assert.IsNotNull (root);
7676

77-
var exportedRoot = ExportSelection (root, new Object[]{root});
78-
7977
// test Export Root
8078
// Expected result: everything gets exported
79+
var exportedRoot = ExportSelection (new Object[]{root});
80+
CompareHierarchies(root, exportedRoot, true);
8181

8282
// test Export Parent1, Child1
8383
// Expected result: Parent1, Child1, Child2
84+
var parent1 = root.transform.Find("Parent1");
85+
var child1 = parent1.Find ("Child1");
86+
exportedRoot = ExportSelection (new Object[]{parent1.gameObject, child1.gameObject});
87+
CompareHierarchies(parent1.gameObject, exportedRoot, true);
8488

8589
// test Export Child2
8690
// Expected result: Child2
91+
var child2 = parent1.Find("Child2").gameObject;
92+
exportedRoot = ExportSelection (new Object[]{child2});
93+
CompareHierarchies(child2, exportedRoot, true);
8794

8895
// test Export Child2, Parent2
8996
// Expected result: Parent2, Child3, Child2
97+
var parent2 = root.transform.Find("Parent2");
98+
exportedRoot = ExportSelection (new Object[]{child2, parent2});
99+
100+
List<GameObject> children = new List<GameObject> ();
101+
foreach (Transform child in exportedRoot.transform) {
102+
children.Add (child.gameObject);
103+
}
104+
CompareHierarchies(new GameObject[]{child2, parent2.gameObject}, children.ToArray());
90105

91-
//UnityEngine.Object.DestroyImmediate (root);
106+
UnityEngine.Object.DestroyImmediate (root);
92107
}
93108

94109
private GameObject CreateHierarchy ()
@@ -121,15 +136,40 @@ private GameObject CreateGameObject(string name, Transform parent = null)
121136
return go;
122137
}
123138

124-
private void CompareHierarchies(GameObject expectedHierarchy, GameObject actualHierarchy, bool ignoreRoot = false)
139+
private void CompareHierarchies(GameObject expectedHierarchy, GameObject actualHierarchy, bool ignoreName = false)
125140
{
126-
if (!ignoreRoot) {
141+
if (!ignoreName) {
127142
Assert.AreEqual (expectedHierarchy.name, actualHierarchy.name);
128-
Assert.AreEqual (expectedHierarchy.transform.childCount, actualHierarchy.transform.childCount);
143+
}
144+
145+
var expectedTransform = expectedHierarchy.transform;
146+
var actualTransform = actualHierarchy.transform;
147+
Assert.AreEqual (expectedTransform.childCount, actualTransform.childCount);
148+
149+
foreach (Transform expectedChild in expectedTransform) {
150+
var actualChild = actualTransform.Find (expectedChild.name);
151+
Assert.IsNotNull (actualChild);
152+
CompareHierarchies (expectedChild.gameObject, actualChild.gameObject);
153+
}
154+
}
155+
156+
private void CompareHierarchies(GameObject[] expectedHierarchy, GameObject[] actualHierarchy)
157+
{
158+
Assert.AreEqual (expectedHierarchy.Length, actualHierarchy.Length);
159+
160+
System.Array.Sort (expectedHierarchy, delegate (GameObject x, GameObject y) {
161+
return x.name.CompareTo(y.name);
162+
});
163+
System.Array.Sort (actualHierarchy, delegate (GameObject x, GameObject y) {
164+
return x.name.CompareTo(y.name);
165+
});
166+
167+
for (int i = 0; i < expectedHierarchy.Length; i++) {
168+
CompareHierarchies (expectedHierarchy [i], actualHierarchy [i]);
129169
}
130170
}
131171

132-
private GameObject ExportSelection(GameObject origRoot, Object[] selected)
172+
private GameObject ExportSelection(Object[] selected)
133173
{
134174
// export selected to a file, then return the root
135175
var filename = GetRandomFileNamePath();
@@ -138,7 +178,6 @@ private GameObject ExportSelection(GameObject origRoot, Object[] selected)
138178
var fbxFileName = FbxExporters.Editor.ModelExporter.ExportObjects (filename, selected) as string;
139179
Debug.unityLogger.logEnabled = true;
140180

141-
Debug.LogWarning (filename + ", " + fbxFileName);
142181
Assert.IsNotNull (fbxFileName);
143182

144183
// make filepath relative to project folder

0 commit comments

Comments
 (0)