Skip to content

Commit 20eb987

Browse files
authored
Merge pull request #69 from Unity-Technologies/UNI-22532-add-missing-unit-tests
Uni 22532 add ModelExporter function unit tests
2 parents ca8440b + fe1c9c6 commit 20eb987

File tree

3 files changed

+149
-2
lines changed

3 files changed

+149
-2
lines changed

Assets/FbxExporters/Editor/UnitTests/DefaultSelectionTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
using UnityEngine;
1+
// ***********************************************************************
2+
// Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
//
4+
// Licensed under the ##LICENSENAME##.
5+
// See LICENSE.md file in the project root for full license information.
6+
// ***********************************************************************
7+
8+
using UnityEngine;
29
using UnityEditor;
310
using UnityEngine.TestTools;
411
using NUnit.Framework;

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
using UnityEngine;
1+
// ***********************************************************************
2+
// Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
//
4+
// Licensed under the ##LICENSENAME##.
5+
// See LICENSE.md file in the project root for full license information.
6+
// ***********************************************************************
7+
8+
using UnityEngine;
29
using UnityEditor;
310
using UnityEngine.TestTools;
411
using NUnit.Framework;
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// ***********************************************************************
2+
// Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
//
4+
// Licensed under the ##LICENSENAME##.
5+
// See LICENSE.md file in the project root for full license information.
6+
// ***********************************************************************
7+
8+
using UnityEngine;
9+
using UnityEditor;
10+
using UnityEngine.TestTools;
11+
using NUnit.Framework;
12+
using System.Collections.Generic;
13+
14+
namespace FbxExporters.UnitTests
15+
{
16+
public class ModelExporterTest
17+
{
18+
// add any GameObject that gets created to this list
19+
// so that it gets deleted in the TearDown
20+
private List<GameObject> m_createdObjects;
21+
22+
[SetUp]
23+
public void Init()
24+
{
25+
m_createdObjects = new List<GameObject> ();
26+
}
27+
28+
[TearDown]
29+
public void Term()
30+
{
31+
foreach (var obj in m_createdObjects) {
32+
GameObject.DestroyImmediate (obj);
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Creates a GameObject.
38+
/// Adds the object to the list of objects to be deleted
39+
/// on TearDown.
40+
/// </summary>
41+
/// <returns>The game object.</returns>
42+
/// <param name="name">Name.</param>
43+
/// <param name="parent">Parent.</param>
44+
/// <param name="type">Primitive Type.</param>
45+
private GameObject CreateGameObject (string name, Transform parent = null, PrimitiveType type = PrimitiveType.Cube)
46+
{
47+
var go = GameObject.CreatePrimitive (type);
48+
go.name = name;
49+
go.transform.SetParent (parent);
50+
m_createdObjects.Add (go);
51+
return go;
52+
}
53+
54+
[Test]
55+
public void TestFindCenter ()
56+
{
57+
// Create 3 objects
58+
var cube = CreateGameObject ("cube");
59+
var cube1 = CreateGameObject ("cube1");
60+
var cube2 = CreateGameObject ("cube2");
61+
62+
// Set their transforms
63+
cube.transform.localPosition = new Vector3 (23, -5, 10);
64+
cube1.transform.localPosition = new Vector3 (23, -5, 4);
65+
cube1.transform.localScale = new Vector3 (1, 1, 2);
66+
cube2.transform.localPosition = new Vector3 (28, 0, 10);
67+
cube2.transform.localScale = new Vector3 (3, 1, 1);
68+
69+
// Find the center
70+
var center = FbxExporters.Editor.ModelExporter.FindCenter(new GameObject[]{cube,cube1,cube2});
71+
72+
// Check that it is what we expect
73+
Assert.AreEqual(center, new Vector3(26, -2.5f, 6.75f));
74+
}
75+
76+
[Test]
77+
public void TestRemoveRedundantObjects ()
78+
{
79+
var root = CreateGameObject ("root");
80+
var child1 = CreateGameObject ("child1", root.transform);
81+
var child2 = CreateGameObject ("child2", root.transform);
82+
var root2 = CreateGameObject ("root2");
83+
84+
// test set: root
85+
// expected result: root
86+
var result = FbxExporters.Editor.ModelExporter.RemoveRedundantObjects(new Object[]{root});
87+
Assert.AreEqual (1, result.Count);
88+
Assert.IsTrue (result.Contains (root));
89+
90+
// test set: root, child1
91+
// expected result: root
92+
result = FbxExporters.Editor.ModelExporter.RemoveRedundantObjects(new Object[]{root, child1});
93+
Assert.AreEqual (1, result.Count);
94+
Assert.IsTrue (result.Contains (root));
95+
96+
// test set: root, child1, child2, root2
97+
// expected result: root, root2
98+
result = FbxExporters.Editor.ModelExporter.RemoveRedundantObjects(new Object[]{root, root2, child2, child1});
99+
Assert.AreEqual (2, result.Count);
100+
Assert.IsTrue (result.Contains (root));
101+
Assert.IsTrue (result.Contains (root2));
102+
103+
// test set: child1, child2
104+
// expected result: child1, child2
105+
result = FbxExporters.Editor.ModelExporter.RemoveRedundantObjects(new Object[]{child2, child1});
106+
Assert.AreEqual (2, result.Count);
107+
Assert.IsTrue (result.Contains (child1));
108+
Assert.IsTrue (result.Contains (child2));
109+
}
110+
111+
[Test]
112+
public void TestConvertToValidFilename()
113+
{
114+
// test already valid filenames
115+
var filename = "foobar.fbx";
116+
var result = FbxExporters.Editor.ModelExporter.ConvertToValidFilename (filename);
117+
Assert.AreEqual (filename, result);
118+
119+
filename = "foo_bar 1.fbx";
120+
result = FbxExporters.Editor.ModelExporter.ConvertToValidFilename (filename);
121+
Assert.AreEqual (filename, result);
122+
123+
// test invalid filenames
124+
filename = "?foo**bar///.fbx";
125+
result = FbxExporters.Editor.ModelExporter.ConvertToValidFilename (filename);
126+
Assert.AreEqual ("_foo__bar___.fbx", result);
127+
128+
filename = "foo$?ba%r 2.fbx";
129+
result = FbxExporters.Editor.ModelExporter.ConvertToValidFilename (filename);
130+
Assert.AreEqual ("foo$_ba%r 2.fbx", result);
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)