Skip to content

Commit cf1f911

Browse files
committed
add unit tests for exporting animated aim properties
- refactor test function so it can test a variety of properties
1 parent 2acd94e commit cf1f911

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxConstraintTest.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,24 @@ public static IEnumerable TestCases
1313
{
1414
get
1515
{
16-
yield return new TestCaseData(new float[] { 1f, 20f, 30f }, new float[] { 0f, 0.5f, 1f }, "m_Weight").Returns(1);
17-
yield return new TestCaseData(new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1);
16+
/* Test Weight */
17+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 1f, 20f, 30f }, new float[] { 0f, 0.5f, 1f }, "m_Weight").Returns(1);
18+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1);
19+
20+
/* Test Aim */
21+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 10f, 180f, 10f }, "m_AimVector.x").Returns(1);
22+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 90f, 45f, 60f }, "m_AimVector.y").Returns(1);
23+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 10f, 180f, 10f }, "m_AimVector.z").Returns(1);
24+
25+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 2f, 4f }, new float[] { 100f, 80f, 19f }, "m_UpVector.x").Returns(1);
26+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 2f, 4f }, new float[] { 4f, 154f, 454f }, "m_UpVector.y").Returns(1);
27+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 2f, 4f }, new float[] { 8f, 14f, 6f }, "m_UpVector.z").Returns(1);
28+
29+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 2f, 30f, 77f }, new float[] { 29.3f, 322f, -190f }, "m_WorldUpVector.x").Returns(1);
30+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 2f, 30f, 77f }, new float[] { 145f, 180f, 40f }, "m_WorldUpVector.y").Returns(1);
31+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 2f, 30f, 77f }, new float[] { 10f, 180f, 10f }, "m_WorldUpVector.z").Returns(1);
32+
}
33+
}
1834
}
1935
}
2036
}
@@ -188,14 +204,14 @@ public void TestAimConstraintExport()
188204
}
189205

190206
[Test, TestCaseSource(typeof(ConstraintAnimationTestDataClass), "TestCases")]
191-
public int TestWeightAnimation(float[] keyTimes, float[] keyValues, string propertyName)
207+
public int TestConstraintAnimation(System.Type componentType, float[] keyTimes, float[] keyValues, string propertyName)
192208
{
193209
var go = new GameObject("root");
194210
var source = new GameObject("source");
195211

196212
source.transform.parent = go.transform;
197213

198-
var constraint = go.AddComponent<RotationConstraint>();
214+
var constraint = go.AddComponent(componentType) as IConstraint;
199215
Assert.That(constraint, Is.Not.Null);
200216

201217
var cSource = new ConstraintSource();
@@ -207,12 +223,12 @@ public int TestWeightAnimation(float[] keyTimes, float[] keyValues, string prope
207223
var keyData = new FbxAnimationTest.PropertyKeyData
208224
{
209225
targetObject = go,
210-
componentType = typeof(RotationConstraint),
226+
componentType = componentType,
211227
propertyName = propertyName,
212228
keyTimes = keyTimes,
213229
keyFloatValues = keyValues
214230
};
215-
var tester = new FbxAnimationTest.AnimTester { keyData = keyData, testName = "ConstraintWeightAnim_" + propertyName, path = GetRandomFbxFilePath() };
231+
var tester = new FbxAnimationTest.AnimTester { keyData = keyData, testName = "ConstraintAnim_" + propertyName, path = GetRandomFbxFilePath() };
216232

217233
return tester.DoIt();
218234
}

0 commit comments

Comments
 (0)