123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- // ***********************************************************************
- // 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 Autodesk.Fbx;
- using System.IO;
- namespace Autodesk.Fbx.UnitTests
- {
- public class FbxExporterTest : FbxIOBaseTest<FbxExporter>
- {
- FbxExporter m_exporter;
- string m_testFolderPrefix = "to_delete_";
- string m_testFolder;
- private string GetRandomDirectory()
- {
- string randomDir = Path.Combine(Path.GetTempPath(), m_testFolderPrefix);
- string temp;
- do {
- // check that the directory does not already exist
- temp = randomDir + Path.GetRandomFileName ();
- } while(Directory.Exists (temp));
- return temp;
- }
- private string GetRandomFilename(string path, bool fbxExtension = true)
- {
- string temp;
- do {
- // check that the directory does not already exist
- temp = Path.Combine (path, Path.GetRandomFileName ());
- if(fbxExtension){
- temp = Path.ChangeExtension(temp, ".fbx");
- }
- } while(File.Exists (temp));
- return temp;
- }
- public override void Init()
- {
- base.Init ();
- m_exporter = FbxExporter.Create (Manager, "exporter");
- Assert.IsNotNull (m_exporter);
- var testDirectories = Directory.GetDirectories(Path.GetTempPath(), m_testFolderPrefix + "*");
- foreach (var directory in testDirectories)
- {
- Directory.Delete(directory, true);
- }
- m_testFolder = GetRandomDirectory ();
- Directory.CreateDirectory (m_testFolder);
- }
- public override void Term()
- {
- try{
- m_exporter.Destroy();
- }
- catch(System.ArgumentNullException){
- // already destroyed in test
- }
- base.Term ();
- // delete all files that were created
- Directory.Delete(m_testFolder, true);
- }
- [Test]
- public override void TestBasics()
- {
- base.TestBasics();
- // Call each function that doesn't write a file, just to see whether it crashes.
- m_exporter.Initialize("foo.fbx");
- m_exporter.SetFileExportVersion("FBX201400");
- m_exporter.GetCurrentWritableVersions();
- m_exporter.SetProgressCallback(null);
- m_exporter.SetProgressCallback((float a, string b) => true);
- m_exporter.SetProgressCallback(null);
- // test GetFileHeaderInfo()
- TestGetter(m_exporter.GetFileHeaderInfo());
- Assert.IsNotNull (m_exporter.GetFileHeaderInfo ());
- }
- [Test]
- public void TestExportEmptyFbxDocument ()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter.
- bool exportStatus = m_exporter.Initialize (filename, -1, Manager.GetIOSettings());
- Assert.IsTrue (exportStatus);
- m_exporter.SetProgressCallback((float a, string b) => true);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestExportNull ()
- {
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter.
- bool exportStatus = m_exporter.Initialize (filename, -1, Manager.GetIOSettings());
- Assert.IsTrue (exportStatus);
- // Export a null document. This is documented to fail.
- bool status = m_exporter.Export (null);
- Assert.IsFalse (status);
- // FbxSdk creates an empty file even though the export status was false
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestInitializeInvalidFilenameOnly()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- // Build the filename without the extension.
- string filename = GetRandomFilename (m_testFolder, false);
- // Initialize the exporter. Use default file type and IO settings.
- bool exportStatus = m_exporter.Initialize (filename);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- // FbxSdk doesn't create a file in this situation
- Assert.IsFalse (File.Exists (filename));
- }
- [Test]
- public void TestInitializeValidFilenameOnly()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter. Use default file type and IO settings.
- bool exportStatus = m_exporter.Initialize (filename);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestInitializeFileFormatNegative()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter. Pass it a negative file format different than -1.
- bool exportStatus = m_exporter.Initialize (filename, int.MinValue);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestInitializeFileFormatInvalid()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter. Pass it a file format that's not valid.
- bool exportStatus = m_exporter.Initialize (filename, int.MaxValue);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsFalse (status);
- Assert.IsFalse (File.Exists (filename));
- }
- [Test]
- public void TestInitializeValidFileFormat()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter. Use a valid non-default file format.
- bool exportStatus = m_exporter.Initialize (filename, 1);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestInitializeNullIOSettings()
- {
- FbxDocument emptyDoc = FbxDocument.Create (Manager, "empty");
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter with explicit null IO settings (which is
- // also the default).
- bool exportStatus = m_exporter.Initialize (filename, -1, null);
- Assert.IsTrue (exportStatus);
- bool status = m_exporter.Export (emptyDoc);
- Assert.IsTrue (status);
- Assert.IsTrue (File.Exists (filename));
- }
- [Test]
- public void TestInitializeInvalidIOSettings()
- {
- string filename = GetRandomFilename (m_testFolder);
- // Initialize the exporter. Pass it zombie IO settings.
- var ioSettings = FbxIOSettings.Create(Manager, "");
- ioSettings.Destroy();
- Assert.That (() => { m_exporter.Initialize (filename, -1, ioSettings); }, Throws.Exception.TypeOf<System.ArgumentNullException>());
- }
- }
- }
|