Skip to content

Commit 757e245

Browse files
authored
Merge pull request #193 from Unity-Technologies/Uni-29079_Unit_test_for_MapNameToSourceRecursive
Uni-29079 [ADDED] unit test for the function
2 parents 34ce706 + 69cebf5 commit 757e245

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public static void UpdateFromSourceRecursive(GameObject dest, GameObject source)
294294
/// <returns>Dictionary containing the name to source game object.</returns>
295295
/// <param name="dest">Destination GameObject.</param>
296296
/// <param name="source">Source GameObject.</param>
297-
private static Dictionary<string,GameObject> MapNameToSourceRecursive(GameObject dest, GameObject source){
297+
public static Dictionary<string,GameObject> MapNameToSourceRecursive(GameObject dest, GameObject source){
298298
var nameToGO = new Dictionary<string,GameObject> ();
299299

300300
var q = new Queue<Transform> ();

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,56 @@ public void SkinnedMeshTest()
182182
// In the future we'll want to assert the opposite!
183183
Assert.That(cubeInstance.GetComponentsInChildren<SkinnedMeshRenderer>(), Is.Empty);
184184
}
185+
186+
[Test]
187+
public void MapNameToSourceTest()
188+
{
189+
//Create a cube with 3 children game objects
190+
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
191+
var capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
192+
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
193+
var quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
194+
195+
capsule.transform.parent = cube.transform;
196+
sphere.transform.parent = cube.transform;
197+
quad.transform.parent = cube.transform;
198+
capsule.transform.SetSiblingIndex(0);
199+
200+
//Create a similar Heirarchy that we can use as our phony "exported" hierarchy.
201+
var cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
202+
var capsule2 = GameObject.CreatePrimitive(PrimitiveType.Capsule);
203+
var sphere2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
204+
var quad2 = GameObject.CreatePrimitive(PrimitiveType.Quad);
205+
206+
capsule2.transform.parent = cube2.transform;
207+
sphere2.transform.parent = cube2.transform;
208+
quad2.transform.parent = cube2.transform;
209+
capsule.transform.SetSiblingIndex(1);
210+
211+
var dictionary = ConvertToModel.MapNameToSourceRecursive(cube, cube2);
212+
213+
//We expect these to pass because we've given it an identical game object, as it would have after a normal export.
214+
Assert.AreSame(capsule2, dictionary[capsule.name]);
215+
Assert.AreSame(sphere2, dictionary[sphere.name]);
216+
Assert.AreSame(quad2, dictionary[quad.name]);
217+
Assert.True(dictionary.Count == 4);
218+
219+
//Create a broken hierarchy, one that is missing a primitive
220+
var cube3 = GameObject.CreatePrimitive(PrimitiveType.Cube);
221+
var capsule3 = GameObject.CreatePrimitive(PrimitiveType.Capsule);
222+
var sphere3 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
223+
224+
capsule3.transform.parent = cube3.transform;
225+
sphere3.transform.parent = cube3.transform;
226+
227+
var dictionaryBroken = ConvertToModel.MapNameToSourceRecursive(cube, cube3);
228+
229+
//the dictionary size should be equal to the amount of children + the parent
230+
Assert.True(dictionaryBroken.Count == 4);
231+
232+
Assert.IsNull(dictionaryBroken[quad.name]);
233+
Assert.AreSame(capsule3, dictionaryBroken[capsule.name]);
234+
Assert.AreSame(sphere3, dictionaryBroken[sphere.name]);
235+
}
185236
}
186237
}

0 commit comments

Comments
 (0)