utImporter.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "UnitTestPCH.h"
  2. #include "utImporter.h"
  3. #define InputData_BLOCK_SIZE 1310
  4. // test data for Importer::ReadFileFromMemory() - ./test/3DS/CameraRollAnim.3ds
  5. static unsigned char InputData_abRawBlock[1310] = {
  6. 77,77,30,5,0,0,2,0,10,0,0,0,3,0,0,0,61,61,91,3,0,0,62,61,10,0,0,0,3,0,0,0,
  7. 0,1,10,0,0,0,0,0,128,63,0,64,254,2,0,0,66,111,120,48,49,0,0,65,242,2,0,0,16,65,64,1,
  8. 0,0,26,0,102,74,198,193,102,74,198,193,0,0,0,0,205,121,55,66,102,74,198,193,0,0,0,0,102,74,198,193,
  9. 138,157,184,65,0,0,0,0,205,121,55,66,138,157,184,65,0,0,0,0,102,74,198,193,102,74,198,193,90,252,26,66,
  10. 205,121,55,66,102,74,198,193,90,252,26,66,102,74,198,193,138,157,184,65,90,252,26,66,205,121,55,66,138,157,184,65,
  11. 90,252,26,66,102,74,198,193,102,74,198,193,0,0,0,0,205,121,55,66,102,74,198,193,0,0,0,0,205,121,55,66,
  12. 102,74,198,193,90,252,26,66,205,121,55,66,102,74,198,193,90,252,26,66,102,74,198,193,102,74,198,193,90,252,26,66,
  13. 102,74,198,193,102,74,198,193,0,0,0,0,205,121,55,66,138,157,184,65,0,0,0,0,205,121,55,66,102,74,198,193,
  14. 90,252,26,66,205,121,55,66,138,157,184,65,0,0,0,0,102,74,198,193,138,157,184,65,0,0,0,0,102,74,198,193,
  15. 138,157,184,65,90,252,26,66,102,74,198,193,138,157,184,65,90,252,26,66,205,121,55,66,138,157,184,65,90,252,26,66,
  16. 205,121,55,66,138,157,184,65,0,0,0,0,102,74,198,193,138,157,184,65,0,0,0,0,102,74,198,193,102,74,198,193,
  17. 90,252,26,66,102,74,198,193,102,74,198,193,90,252,26,66,102,74,198,193,138,157,184,65,0,0,0,0,64,65,216,0,
  18. 0,0,26,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,63,0,0,128,63,0,0,0,0,
  19. 0,0,128,63,0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,128,63,0,0,128,63,
  20. 0,0,128,63,0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0,0,0,128,63,0,0,128,63,0,0,128,63,
  21. 0,0,128,63,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,
  22. 0,0,128,63,0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0,0,0,128,63,0,0,128,63,0,0,128,63,
  23. 0,0,128,63,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,63,
  24. 0,0,128,63,0,0,128,63,0,0,128,63,0,0,0,0,0,0,0,0,96,65,54,0,0,0,0,0,128,63,0,0,
  25. 0,0,0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,63,53,169,
  26. 40,65,176,205,90,191,0,0,0,0,32,65,158,0,0,0,12,0,0,0,2,0,3,0,6,0,3,0,1,0,0,0,
  27. 6,0,4,0,5,0,7,0,6,0,7,0,6,0,4,0,6,0,8,0,9,0,10,0,6,0,11,0,12,0,13,0,
  28. 6,0,1,0,14,0,7,0,6,0,7,0,15,0,1,0,6,0,16,0,17,0,18,0,6,0,19,0,20,0,21,0,
  29. 6,0,22,0,0,0,23,0,6,0,24,0,6,0,25,0,6,0,80,65,54,0,0,0,2,0,0,0,2,0,0,0,
  30. 4,0,0,0,4,0,0,0,8,0,0,0,8,0,0,0,16,0,0,0,16,0,0,0,32,0,0,0,32,0,0,0,
  31. 64,0,0,0,64,0,0,0,0,64,67,0,0,0,67,97,109,101,114,97,48,49,0,0,71,52,0,0,0,189,19,25,
  32. 195,136,104,81,64,147,56,182,65,96,233,20,194,67,196,97,190,147,56,182,65,0,0,0,0,85,85,85,66,32,71,14,
  33. 0,0,0,0,0,0,0,0,0,122,68,0,176,179,1,0,0,10,176,21,0,0,0,5,0,77,65,88,83,67,69,78,
  34. 69,0,44,1,0,0,8,176,14,0,0,0,0,0,0,0,44,1,0,0,9,176,10,0,0,0,128,2,0,0,2,176,
  35. 168,0,0,0,48,176,8,0,0,0,0,0,16,176,18,0,0,0,66,111,120,48,49,0,0,64,0,0,255,255,19,176,
  36. 18,0,0,0,0,0,0,128,0,0,0,128,0,0,0,128,32,176,38,0,0,0,0,0,0,0,0,0,0,0,0,0,
  37. 1,0,0,0,0,0,0,0,0,0,53,169,40,65,176,205,90,191,0,0,0,0,33,176,42,0,0,0,0,0,0,0,
  38. 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  39. 34,176,38,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,128,63,0,0,
  40. 128,63,0,0,128,63,3,176,143,0,0,0,48,176,8,0,0,0,1,0,16,176,21,0,0,0,67,97,109,101,114,97,
  41. 48,49,0,0,64,0,0,255,255,32,176,38,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,
  42. 0,0,0,189,19,25,195,136,104,81,64,147,56,182,65,35,176,30,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
  43. 0,0,0,0,0,0,0,0,0,0,0,52,66,36,176,40,0,0,0,0,0,0,0,0,0,120,0,0,0,2,0,0,
  44. 0,0,0,0,0,0,0,120,13,90,189,120,0,0,0,0,0,99,156,154,194,4,176,73,0,0,0,48,176,8,0,0,
  45. 0,2,0,16,176,21,0,0,0,67,97,109,101,114,97,48,49,0,0,64,0,0,255,255,32,176,38,0,0,0,0,0,
  46. 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,96,233,20,194,67,196,97,190,147,56,182,65,
  47. };
  48. CPPUNIT_TEST_SUITE_REGISTRATION (ImporterTest);
  49. #define AIUT_DEF_ERROR_TEXT "sorry, this is a test"
  50. bool TestPlugin :: CanRead( const std::string& pFile,
  51. IOSystem* pIOHandler, bool test) const
  52. {
  53. std::string::size_type pos = pFile.find_last_of('.');
  54. // no file extension - can't read
  55. if( pos == std::string::npos)
  56. return false;
  57. std::string extension = pFile.substr( pos);
  58. // todo ... make case-insensitive
  59. return (extension == ".apple" || extension == ".mac" ||
  60. extension == ".linux" || extension == ".windows" );
  61. }
  62. void TestPlugin :: GetExtensionList(std::set<std::string>& extensions)
  63. {
  64. extensions.insert("apple");
  65. extensions.insert("mac");
  66. extensions.insert("linux");
  67. extensions.insert("windows");
  68. }
  69. void TestPlugin :: InternReadFile( const std::string& pFile,
  70. aiScene* pScene, IOSystem* pIOHandler)
  71. {
  72. throw DeadlyImportError(AIUT_DEF_ERROR_TEXT);
  73. }
  74. void ImporterTest :: setUp (void)
  75. {
  76. pImp = new Importer();
  77. }
  78. void ImporterTest :: tearDown (void)
  79. {
  80. delete pImp;
  81. }
  82. void ImporterTest :: testMemoryRead (void)
  83. {
  84. const aiScene* sc = pImp->ReadFileFromMemory(InputData_abRawBlock,InputData_BLOCK_SIZE,
  85. aiProcessPreset_TargetRealtime_Quality,"3ds");
  86. CPPUNIT_ASSERT(sc != NULL);
  87. CPPUNIT_ASSERT(sc->mRootNode->mName == aiString("<3DSRoot>"));
  88. CPPUNIT_ASSERT(sc->mNumMeshes == 1 && sc->mMeshes[0]->mNumVertices ==24 && sc->mMeshes[0]->mNumFaces ==12);
  89. }
  90. void ImporterTest :: testIntProperty (void)
  91. {
  92. bool b;
  93. pImp->SetPropertyInteger("quakquak",1503,&b);
  94. CPPUNIT_ASSERT(!b);
  95. CPPUNIT_ASSERT(1503 == pImp->GetPropertyInteger("quakquak",0));
  96. CPPUNIT_ASSERT(314159 == pImp->GetPropertyInteger("not_there",314159));
  97. pImp->SetPropertyInteger("quakquak",1504,&b);
  98. CPPUNIT_ASSERT(b);
  99. }
  100. void ImporterTest :: testFloatProperty (void)
  101. {
  102. bool b;
  103. pImp->SetPropertyFloat("quakquak",1503.f,&b);
  104. CPPUNIT_ASSERT(!b);
  105. CPPUNIT_ASSERT(1503.f == pImp->GetPropertyFloat("quakquak",0.f));
  106. CPPUNIT_ASSERT(314159.f == pImp->GetPropertyFloat("not_there",314159.f));
  107. }
  108. void ImporterTest :: testStringProperty (void)
  109. {
  110. bool b;
  111. pImp->SetPropertyString("quakquak","test",&b);
  112. CPPUNIT_ASSERT(!b);
  113. CPPUNIT_ASSERT("test" == pImp->GetPropertyString("quakquak","weghwekg"));
  114. CPPUNIT_ASSERT("ILoveYou" == pImp->GetPropertyString("not_there","ILoveYou"));
  115. }
  116. void ImporterTest :: testPluginInterface (void)
  117. {
  118. pImp->RegisterLoader(new TestPlugin());
  119. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".apple"));
  120. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".mac"));
  121. CPPUNIT_ASSERT(pImp->IsExtensionSupported("*.linux"));
  122. CPPUNIT_ASSERT(pImp->IsExtensionSupported("windows"));
  123. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".x")); /* x and 3ds must be available in this Assimp build, of course! */
  124. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".3ds"));
  125. CPPUNIT_ASSERT(!pImp->IsExtensionSupported("."));
  126. TestPlugin* p = (TestPlugin*) pImp->FindLoader(".windows");
  127. CPPUNIT_ASSERT(NULL != p);
  128. try {
  129. p->InternReadFile("",0,NULL);
  130. }
  131. catch ( const DeadlyImportError& dead)
  132. {
  133. CPPUNIT_ASSERT(!strcmp(dead.what(),AIUT_DEF_ERROR_TEXT));
  134. // unregister the plugin and delete it
  135. pImp->UnregisterLoader(p);
  136. delete p;
  137. return;
  138. }
  139. CPPUNIT_ASSERT(false); // control shouldn't reach this point
  140. }
  141. void ImporterTest :: testExtensionCheck (void)
  142. {
  143. std::string s;
  144. pImp->GetExtensionList(s);
  145. // TODO
  146. }
  147. void ImporterTest :: testMultipleReads (void)
  148. {
  149. // see http://sourceforge.net/projects/assimp/forums/forum/817654/topic/3591099
  150. // Check whether reading and post-processing multiple times using
  151. // the same objects is *generally* fine. This test doesn't target
  152. // importers. Testing post-processing stability is the main point.
  153. const unsigned int flags =
  154. aiProcess_Triangulate |
  155. aiProcess_JoinIdenticalVertices |
  156. aiProcess_GenSmoothNormals |
  157. aiProcess_ValidateDataStructure |
  158. aiProcess_RemoveRedundantMaterials |
  159. aiProcess_SortByPType |
  160. aiProcess_FindDegenerates |
  161. aiProcess_FindInvalidData |
  162. aiProcess_GenUVCoords |
  163. aiProcess_OptimizeMeshes |
  164. aiProcess_OptimizeGraph;
  165. CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/test.x",flags));
  166. //CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/dwarf.x",flags)); # is in nonbsd
  167. CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/Testwuson.x",flags));
  168. CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/anim_test.x",flags));
  169. //CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/dwarf.x",flags)); # is in nonbsd
  170. CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/anim_test.x",flags));
  171. CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/bcn_epileptic.x",flags));
  172. //CPPUNIT_ASSERT(pImp->ReadFile("../../test/models/X/dwarf.x",flags)); # is in nonbsd
  173. }