utImporter.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "utImporter.h"
  2. CPPUNIT_TEST_SUITE_REGISTRATION (ImporterTest);
  3. #define AIUT_DEF_ERROR_TEXT "sorry, this is a test"
  4. bool TestPlugin :: CanRead( const std::string& pFile,
  5. IOSystem* pIOHandler) const
  6. {
  7. std::string::size_type pos = pFile.find_last_of('.');
  8. // no file extension - can't read
  9. if( pos == std::string::npos)return false;
  10. std::string extension = pFile.substr( pos);
  11. // todo ... make case-insensitive
  12. return (extension == ".apple" || extension == ".mac" ||
  13. extension == ".linux" || extension == ".windows" );
  14. }
  15. void TestPlugin :: GetExtensionList(std::string& append)
  16. {
  17. append.append("*.apple;*.mac;*.linux;*.windows");
  18. }
  19. void TestPlugin :: InternReadFile( const std::string& pFile,
  20. aiScene* pScene, IOSystem* pIOHandler)
  21. {
  22. throw new ImportErrorException(AIUT_DEF_ERROR_TEXT);
  23. }
  24. void ImporterTest :: setUp (void)
  25. {
  26. pImp = new Importer();
  27. }
  28. void ImporterTest :: tearDown (void)
  29. {
  30. delete pImp;
  31. }
  32. void ImporterTest :: testIntProperty (void)
  33. {
  34. bool b;
  35. pImp->SetPropertyInteger("quakquak",1503,&b);
  36. CPPUNIT_ASSERT(!b);
  37. CPPUNIT_ASSERT(1503 == pImp->GetPropertyInteger("quakquak",0));
  38. CPPUNIT_ASSERT(314159 == pImp->GetPropertyInteger("not_there",314159));
  39. pImp->SetPropertyInteger("quakquak",1504,&b);
  40. CPPUNIT_ASSERT(b);
  41. }
  42. void ImporterTest :: testFloatProperty (void)
  43. {
  44. bool b;
  45. pImp->SetPropertyFloat("quakquak",1503.f,&b);
  46. CPPUNIT_ASSERT(!b);
  47. CPPUNIT_ASSERT(1503.f == pImp->GetPropertyFloat("quakquak",0.f));
  48. CPPUNIT_ASSERT(314159.f == pImp->GetPropertyFloat("not_there",314159.f));
  49. }
  50. void ImporterTest :: testStringProperty (void)
  51. {
  52. bool b;
  53. pImp->SetPropertyString("quakquak","test",&b);
  54. CPPUNIT_ASSERT(!b);
  55. CPPUNIT_ASSERT("test" == pImp->GetPropertyString("quakquak","weghwekg"));
  56. CPPUNIT_ASSERT("ILoveYou" == pImp->GetPropertyString("not_there","ILoveYou"));
  57. }
  58. void ImporterTest :: testPluginInterface (void)
  59. {
  60. pImp->RegisterLoader(new TestPlugin());
  61. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".apple"));
  62. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".mac"));
  63. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".linux"));
  64. CPPUNIT_ASSERT(pImp->IsExtensionSupported(".windows"));
  65. TestPlugin* p = (TestPlugin*) pImp->FindLoader(".windows");
  66. CPPUNIT_ASSERT(NULL != p);
  67. try {
  68. p->InternReadFile("",0,NULL);
  69. }
  70. catch ( ImportErrorException* ex)
  71. {
  72. CPPUNIT_ASSERT(ex->GetErrorText() == AIUT_DEF_ERROR_TEXT);
  73. // unregister the plugin and delete it
  74. pImp->UnregisterLoader(p);
  75. delete p;
  76. return;
  77. }
  78. CPPUNIT_ASSERT(false); // control shouldn't reach this point
  79. }
  80. void ImporterTest :: testExtensionCheck (void)
  81. {
  82. std::string s;
  83. pImp->GetExtensionList(s);
  84. // todo ..
  85. }