TestGenericLFSelectionPersistent.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file TestGenericLFSelectionPersistent.cpp
  3. * @brief CppUnit-Testcase to create a LocalFeatureRepresentation object via GenericLFSelection, to store it, and to restore it again.
  4. * @author Alexander Freytag
  5. * @date 10-02-2014 ( dd-mm-yyyy )
  6. */
  7. #ifdef NICE_USELIB_CPPUNIT
  8. // STL includes
  9. // NICE-core includes
  10. // gp-hik-core includes
  11. #include "TestGenericLFSelectionPersistent.h"
  12. using namespace std; //C basics
  13. using namespace NICE; // nice-core
  14. const bool verboseStartEnd = true;
  15. const bool verbose = true;
  16. CPPUNIT_TEST_SUITE_REGISTRATION( TestGenericLFSelectionPersistent );
  17. void TestGenericLFSelectionPersistent::setUp() {
  18. }
  19. void TestGenericLFSelectionPersistent::tearDown() {
  20. }
  21. void TestGenericLFSelectionPersistent::testPersistentMethods()
  22. {
  23. if (verboseStartEnd)
  24. std::cerr << "================== TestGenericLFSelectionPersistent::testPersistentMethods ===================== " << std::endl;
  25. NICE::Config conf;
  26. conf.sS( "GenericLFSelection", "localfeature_type", "sift" );
  27. OBJREC::LocalFeatureRepresentation * lfrep;
  28. lfrep = OBJREC::GenericLFSelection::selectLocalFeatureRep ( &conf, "GenericLFSelection");
  29. // TEST STORING ABILITIES
  30. if ( verbose )
  31. std::cerr << " TEST STORING ABILITIES " << std::endl;
  32. std::string s_destination_save ( "myLFSelection.txt" );
  33. std::filebuf fbOut;
  34. fbOut.open ( s_destination_save.c_str(), ios::out );
  35. std::ostream os (&fbOut);
  36. //
  37. lfrep->store( os );
  38. //
  39. fbOut.close();
  40. // TEST RESTORING ABILITIES
  41. if ( verbose )
  42. std::cerr << " TEST RESTORING ABILITIES " << std::endl;
  43. OBJREC::LocalFeatureRepresentation * lfrepRestore = NULL;
  44. std::string s_destination_load ( "myLFSelection.txt" );
  45. std::filebuf fbIn;
  46. fbIn.open ( s_destination_load.c_str(), ios::in );
  47. std::istream is (&fbIn);
  48. //
  49. OBJREC::GenericLFSelection::restoreLocalFeatureRep ( lfrepRestore, is );
  50. //
  51. fbIn.close();
  52. // currently, we have no possibility to actually verify that the restore-operation was successfull, i.e.,
  53. // it returned an object identical to the stored one.
  54. // However, if we reached this point, at least something went right, so we should be happy...
  55. // final clean up -- don't waste memory
  56. if ( lfrep != NULL )
  57. delete lfrep;
  58. if ( lfrepRestore != NULL )
  59. delete lfrepRestore;
  60. if (verboseStartEnd)
  61. std::cerr << "================== TestGenericLFSelectionPersistent::testPersistentMethods done ===================== " << std::endl;
  62. }
  63. #endif