123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // ***********************************************************************
- // Copyright (c) 2017 Unity Technologies. All rights reserved.
- //
- // Licensed under the ##LICENSENAME##.
- // See LICENSE.md file in the project root for full license information.
- // ***********************************************************************
- using NUnit.Framework;
- using System.Collections;
- using Autodesk.Fbx;
- namespace Autodesk.Fbx.UnitTests
- {
- public class FbxLayerTest : TestBase<FbxLayer>
- {
- private FbxMesh m_fbxMesh;
- private FbxManager m_fbxManager;
- private FbxLayer m_fbxLayer;
- [SetUp]
- public void Init ()
- {
- m_fbxManager = FbxManager.Create ();
- m_fbxMesh = FbxMesh.Create (m_fbxManager, "");
- m_fbxLayer = m_fbxMesh.GetLayer (0);
- if (m_fbxLayer == null)
- {
- m_fbxMesh.CreateLayer ();
- m_fbxLayer = m_fbxMesh.GetLayer (0 /* default layer */);
- }
- }
- [TearDown]
- public void Term ()
- {
- m_fbxManager.Destroy ();
- }
- [Test]
- public void TestSetNormals ()
- {
- // make sure nothing crashes
- m_fbxLayer.SetNormals (FbxLayerElementNormal.Create (m_fbxMesh, ""));
- Assert.IsNotNull (m_fbxLayer.GetNormals ());
- // test null
- m_fbxLayer.SetNormals(null);
- Assert.IsNull (m_fbxLayer.GetNormals ());
- // test destroyed
- FbxLayerElementNormal normals = FbxLayerElementNormal.Create (m_fbxMesh, "");
- normals.Dispose ();
- m_fbxLayer.SetNormals (normals);
- }
- [Test]
- public void TestSetBinormals ()
- {
- // make sure nothing crashes
- m_fbxLayer.SetBinormals (FbxLayerElementBinormal.Create (m_fbxMesh, ""));
- Assert.IsNotNull (m_fbxLayer.GetBinormals ());
- // test null
- m_fbxLayer.SetBinormals(null);
- Assert.IsNull (m_fbxLayer.GetBinormals ());
- // test destroyed
- FbxLayerElementBinormal binormals = FbxLayerElementBinormal.Create (m_fbxMesh, "");
- binormals.Dispose ();
- m_fbxLayer.SetBinormals (binormals);
- }
- [Test]
- public void TestSetTangents ()
- {
- // make sure nothing crashes
- m_fbxLayer.SetTangents (FbxLayerElementTangent.Create (m_fbxMesh, ""));
- Assert.IsNotNull (m_fbxLayer.GetTangents ());
- // test null
- m_fbxLayer.SetTangents(null);
- Assert.IsNull (m_fbxLayer.GetTangents ());
- // test destroyed
- FbxLayerElementTangent tangents = FbxLayerElementTangent.Create (m_fbxMesh, "");
- tangents.Dispose ();
- m_fbxLayer.SetTangents (tangents);
- }
- [Test]
- public void TestSetVertexColors ()
- {
- // make sure nothing crashes
- m_fbxLayer.SetVertexColors (FbxLayerElementVertexColor.Create (m_fbxMesh, ""));
- Assert.IsNotNull (m_fbxLayer.GetVertexColors ());
- // test null
- m_fbxLayer.SetVertexColors(null);
- Assert.IsNull (m_fbxLayer.GetVertexColors ());
- // test destroyed
- FbxLayerElementVertexColor vertexColor = FbxLayerElementVertexColor.Create (m_fbxMesh, "");
- vertexColor.Dispose ();
- m_fbxLayer.SetVertexColors(vertexColor);
- }
- [Test]
- public void TestSetMaterials()
- {
- // make sure nothing crashes
- m_fbxLayer.SetMaterials(FbxLayerElementMaterial.Create (m_fbxMesh, ""));
- Assert.IsNotNull (m_fbxLayer.GetMaterials ());
- // test null
- m_fbxLayer.SetMaterials(null);
- Assert.IsNull (m_fbxLayer.GetMaterials ());
- // test destroyed
- FbxLayerElementMaterial material = FbxLayerElementMaterial.Create (m_fbxMesh, "");
- material.Dispose ();
- m_fbxLayer.SetMaterials(material);
- }
- [Test]
- public void TestSetUVs ()
- {
- // make sure nothing crashes
- m_fbxLayer.SetUVs (FbxLayerElementUV.Create (m_fbxMesh, ""));
- // test with type identifier
- m_fbxLayer.SetUVs(FbxLayerElementUV.Create (m_fbxMesh, ""), FbxLayerElement.EType.eEdgeCrease);
- // TODO: why does this return null?
- Assert.IsNull(m_fbxLayer.GetUVs(FbxLayerElement.EType.eEdgeCrease));
- // test null
- m_fbxLayer.SetUVs(null);
- Assert.IsNull (m_fbxLayer.GetUVs ());
- // test destroyed
- FbxLayerElementUV uvs = FbxLayerElementUV.Create (m_fbxMesh, "");
- uvs.Dispose ();
- m_fbxLayer.SetUVs (uvs);
- }
- [Test]
- public void TestDispose()
- {
- // make sure that calling SetNormals on a disposed layer throws
- m_fbxLayer.Dispose ();
- Assert.That(() => m_fbxLayer.SetNormals (FbxLayerElementNormal.Create(m_fbxMesh, "")),
- Throws.Exception.TypeOf<System.ArgumentNullException>());
- }
- /* Test all the equality functions we can find. */
- [Test]
- public void TestEquality() {
- var aIndex = m_fbxMesh.CreateLayer();
- var bIndex = m_fbxMesh.CreateLayer();
- var a = m_fbxMesh.GetLayer(aIndex);
- var b = m_fbxMesh.GetLayer(bIndex);
- var acopy = m_fbxMesh.GetLayer(aIndex);
- EqualityTester<FbxLayer>.TestEquality(a, b, acopy);
- }
- }
- }
|