utExport.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "UnitTestPCH.h"
  2. #include <assimp/cexport.h>
  3. #include <assimp/Exporter.hpp>
  4. #ifndef ASSIMP_BUILD_NO_EXPORT
  5. class ExporterTest : public ::testing::Test {
  6. public:
  7. virtual void SetUp()
  8. {
  9. ex = new Assimp::Exporter();
  10. im = new Assimp::Importer();
  11. pTest = im->ReadFile("../../test/models/X/test.x",0);
  12. }
  13. virtual void TearDown()
  14. {
  15. delete ex;
  16. delete im;
  17. }
  18. protected:
  19. const aiScene* pTest;
  20. Assimp::Exporter* ex;
  21. Assimp::Importer* im;
  22. };
  23. // ------------------------------------------------------------------------------------------------
  24. TEST_F(ExporterTest, testExportToFile)
  25. {
  26. const char* file = "unittest_output.dae";
  27. EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
  28. // check if we can read it again
  29. EXPECT_TRUE(im->ReadFile(file,0));
  30. }
  31. // ------------------------------------------------------------------------------------------------
  32. TEST_F(ExporterTest, testExportToBlob)
  33. {
  34. const aiExportDataBlob* blob = ex->ExportToBlob(pTest,"collada");
  35. ASSERT_TRUE(blob);
  36. EXPECT_TRUE(blob->data);
  37. EXPECT_GT(blob->size, 0U);
  38. EXPECT_EQ(0U, blob->name.length);
  39. // XXX test chained blobs (i.e. obj file with accompanying mtl script)
  40. // check if we can read it again
  41. EXPECT_TRUE(im->ReadFileFromMemory(blob->data,blob->size,0,"dae"));
  42. }
  43. // ------------------------------------------------------------------------------------------------
  44. TEST_F(ExporterTest, testCppExportInterface)
  45. {
  46. EXPECT_TRUE(ex->GetExportFormatCount() > 0);
  47. for(size_t i = 0; i < ex->GetExportFormatCount(); ++i) {
  48. const aiExportFormatDesc* const desc = ex->GetExportFormatDescription(i);
  49. ASSERT_TRUE(desc);
  50. EXPECT_TRUE(desc->description && strlen(desc->description));
  51. EXPECT_TRUE(desc->fileExtension && strlen(desc->fileExtension));
  52. EXPECT_TRUE(desc->id && strlen(desc->id));
  53. }
  54. EXPECT_TRUE(ex->IsDefaultIOHandler());
  55. }
  56. // ------------------------------------------------------------------------------------------------
  57. TEST_F(ExporterTest, testCExportInterface)
  58. {
  59. EXPECT_TRUE(aiGetExportFormatCount() > 0);
  60. for(size_t i = 0; i < aiGetExportFormatCount(); ++i) {
  61. const aiExportFormatDesc* const desc = aiGetExportFormatDescription(i);
  62. EXPECT_TRUE(desc);
  63. // rest has aleady been validated by testCppExportInterface
  64. }
  65. }
  66. #endif