Skip to content

Commit bb07034

Browse files
author
Benoit Hudson
committed
Fix unit tests so they pass. The test was wrong.
1 parent 6684d67 commit bb07034

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxPrefabTest.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine.TestTools;
44
using NUnit.Framework;
55
using System.Collections.Generic;
6+
using System.Linq;
67

78
namespace FbxExporters.UnitTests
89
{
@@ -84,7 +85,7 @@ public static void AssertAreIdentical(
8485
// Verify that they have the same children (by name).
8586
var achildren = a.ChildNames;
8687
var bchildren = b.ChildNames;
87-
Assert.That(achildren, Is.EquivalentTo(bchildren), aName + " children");
88+
Assert.That(bchildren, Is.EquivalentTo(achildren), aName + " children");
8889

8990
// Add the children to each stack. It's important to get the
9091
// same order for both stacks.
@@ -96,7 +97,8 @@ public static void AssertAreIdentical(
9697
// Verify that they have the same components.
9798
var atypes = a.ComponentTypes;
9899
var btypes = b.ComponentTypes;
99-
Assert.That(atypes, Is.EquivalentTo(btypes), aName + " component types");
100+
101+
Assert.That(btypes, Is.EquivalentTo(atypes), aName + " component types");
100102

101103
foreach(var t in atypes) {
102104
var avalues = a.GetComponentValues(t);
@@ -189,15 +191,14 @@ FbxPrefab.FbxRepresentation History(GameObject go) {
189191

190192
GameObject ModifySourceFbx()
191193
{
192-
// Modify the source fbx file:
194+
// Generate this change:
193195
// - delete parent1
194196
// - add parent3
195-
var newModel = PrefabUtility.InstantiatePrefab(m_source) as GameObject;
197+
// Simulate that we're doing this in Maya, so parent3 doesn't come
198+
// with a collider.
199+
var newModel = CreateHierarchy();
196200
GameObject.DestroyImmediate(newModel.transform.Find("Parent1").gameObject);
197201
var parent3 = CreateGameObject("Parent3", newModel.transform);
198-
199-
// We're not doing an apply operation, so the collider isn't
200-
// supposed to get to the prefab, so don't test that it does.
201202
Object.DestroyImmediate(parent3.GetComponent<BoxCollider>());
202203

203204
// Export it to clobber the old FBX file.
@@ -235,25 +236,21 @@ public void BasicTest() {
235236
// Make sure the fbx source changed (testing the test).
236237
AssertAreDifferent(m_originalHistory, Rep(m_source));
237238

238-
// Make sure the auto-update prefab changed.
239-
Debug.Log(string.Format("source: {0}\nprefab: {1}",
240-
newHierarchy.ToJson(), Rep(m_autoPrefab).ToJson()));
241-
AssertAreIdentical(newHierarchy, Rep(m_autoPrefab));
242-
AssertAreIdentical(newHierarchy, Rep(m_source));
243-
244-
// Make sure the manual-update prefab didn't.
239+
// Make sure the manual-update prefab didn't change.
245240
AssertAreIdentical(m_originalRep, Rep(m_manualPrefab));
246241
AssertAreIdentical(m_originalHistory, History(m_manualPrefab));
247242

248243
// Make sure we got the right changes.
249244
Assert.AreEqual (1, updateSet.NumUpdates);
250245
Assert.That (updateSet.Updated, Is.EquivalentTo (new string [] {
251-
// TODO: UNI-24579 - we should only be seeing Parent3 here,
252-
// the other two are for transform changes, but
253-
// they shouldn't have changed at all
254-
"Parent2", "Parent3", "Child3"
246+
// TODO: UNI-24579 - we should only be seeing Parent3 here.
247+
// Parent2 is for a transform change, but it shouldn't have changed.
248+
"Parent2", "Parent3"
255249
}
256250
));
251+
252+
// Make sure the auto-update prefab changed.
253+
AssertAreIdentical(newHierarchy, Rep(m_autoPrefab));
257254
}
258255

259256
// Manual update, make sure it updated.
@@ -290,16 +287,27 @@ public void BasicTest() {
290287

291288
// Switch to some other model, which looks like the original model
292289
// (but is a totally different file). This will cause an update
293-
// immediately. We expect to have lost the colliders on the objects
294-
// that were deleted in the interim.
290+
// immediately.
295291
var fbxAsset = FbxExporters.Editor.ModelExporter.ExportObject(
296292
GetRandomFbxFilePath(), m_original);
297293
var newSource = AssetDatabase.LoadMainAssetAtPath(fbxAsset) as GameObject;
298294
Assert.IsTrue(newSource);
299295
Debug.Log("Testing SetSourceModel relink");
300296
manualPrefabComponent.SetSourceModel(newSource);
301-
AssertAreIdentical(m_originalRep, Rep(m_manualPrefab));
302-
AssertAreIdentical(m_originalHistory, History(m_manualPrefab));
297+
298+
// Generate the answer we expect: the original but Parent1 and
299+
// hierarchy are without collider. That's because we deleted them,
300+
// and got them back.
301+
var expectedHierarchy = GameObject.Instantiate(m_original);
302+
var parent1 = expectedHierarchy.transform.Find("Parent1");
303+
foreach(var collider in parent1.GetComponentsInChildren<BoxCollider>()) {
304+
Object.DestroyImmediate(collider);
305+
}
306+
var expectedRep = Rep(expectedHierarchy);
307+
var expectedHistory = m_originalHistory;
308+
309+
AssertAreIdentical(expectedHistory, History(m_manualPrefab));
310+
AssertAreIdentical(expectedRep, Rep(m_manualPrefab));
303311
}
304312

305313
[Test]

0 commit comments

Comments
 (0)