FbxImporterTest.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. using NUnit.Framework;
  8. using Autodesk.Fbx;
  9. namespace Autodesk.Fbx.UnitTests
  10. {
  11. public class FbxImporterTest : FbxIOBaseTest<FbxImporter>
  12. {
  13. [Test]
  14. public override void TestBasics ()
  15. {
  16. base.TestBasics();
  17. using (FbxImporter newImporter = CreateObject("MyImporter"))
  18. {
  19. // import a null document.
  20. Assert.IsFalse (newImporter.Import (null));
  21. // set a callback function
  22. newImporter.SetProgressCallback(null);
  23. newImporter.SetProgressCallback((float a, string b) => true);
  24. newImporter.SetProgressCallback(null);
  25. }
  26. // Export an empty scene to a temp file, then import.
  27. var filename = GetRandomFile();
  28. try {
  29. using(var exporter = FbxExporter.Create(Manager, "exporter")) {
  30. using (var scene = FbxScene.Create(Manager, "exported scene")) {
  31. Assert.IsTrue(exporter.Initialize(filename));
  32. Assert.IsTrue(exporter.Export(scene));
  33. }
  34. }
  35. var scene_in = FbxScene.Create(Manager, "imported scene");
  36. using(var importer = FbxImporter.Create(Manager, "import")) {
  37. Assert.IsTrue(importer.Initialize(filename));
  38. Assert.IsTrue(importer.Import(scene_in));
  39. Assert.IsTrue(importer.IsFBX());
  40. int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;
  41. FbxManager.GetFileFormatVersion (out sdkMajor, out sdkMinor, out sdkRevision);
  42. int fileMajor = -1, fileMinor = -1, fileRevision = -1;
  43. importer.GetFileVersion (out fileMajor, out fileMinor, out fileRevision);
  44. Assert.AreNotSame(fileMajor,-1);
  45. Assert.AreNotSame(fileMinor,-1);
  46. Assert.AreNotSame(fileRevision,-1);
  47. Assert.AreEqual(sdkMajor,fileMajor);
  48. Assert.AreEqual(sdkMinor,fileMinor);
  49. Assert.AreEqual(sdkRevision,fileRevision);
  50. Assert.IsEmpty(importer.GetActiveAnimStackName());
  51. Assert.AreEqual(importer.GetAnimStackCount(), 0);
  52. // test GetFileHeaderInfo()
  53. TestGetter(importer.GetFileHeaderInfo());
  54. Assert.IsNotNull(importer.GetFileHeaderInfo());
  55. }
  56. // we actually don't care about the scene itself!
  57. } finally {
  58. System.IO.File.Delete(filename);
  59. }
  60. }
  61. string GetRandomFile()
  62. {
  63. var tmp = System.IO.Path.GetTempPath();
  64. for(int i = 0; i < 20; ++i) {
  65. var path = System.IO.Path.Combine(tmp, System.IO.Path.GetRandomFileName()) + ".fbx";
  66. if (!System.IO.File.Exists(path)) {
  67. return path;
  68. }
  69. }
  70. throw new System.IO.IOException("can't find an unused random temp filename");
  71. }
  72. }
  73. }