TestGenericClusterAlgorithmSelectionPersistent.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @file TestGenericClusterAlgoSelectionPersistent.cpp
  3. * @brief CppUnit-Testcase to create a ClusterAlgoRepresentation object via GenericClusterAlgoSelection, to store it, and to restore it again.
  4. * @author Alexander Freytag
  5. * @date 12-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 "TestGenericClusterAlgorithmSelectionPersistent.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( TestGenericClusterAlgoSelectionPersistent );
  17. void TestGenericClusterAlgoSelectionPersistent::setUp() {
  18. }
  19. void TestGenericClusterAlgoSelectionPersistent::tearDown() {
  20. }
  21. void TestGenericClusterAlgoSelectionPersistent::testPersistentMethods()
  22. {
  23. if (verboseStartEnd)
  24. std::cerr << "================== TestGenericClusterAlgoSelectionPersistent::testPersistentMethods ===================== " << std::endl;
  25. NICE::Config conf;
  26. conf.sS( "GenericClusterAlgoSelection", "clusterTechnique", "KMeans" );
  27. OBJREC::ClusterAlgorithm * cluster;
  28. cluster = OBJREC::GenericClusterAlgorithmSelection::selectClusterAlgorithm ( &conf, "GenericClusterAlgoSelection");
  29. // TEST STORING ABILITIES
  30. if ( verbose )
  31. std::cerr << " TEST STORING ABILITIES FOR STANDARD LOCALFEATURE" << std::endl;
  32. std::string s_destination_save ( "myClusterAlgoSelection.txt" );
  33. std::filebuf fbOut;
  34. fbOut.open ( s_destination_save.c_str(), ios::out );
  35. std::ostream os (&fbOut);
  36. //
  37. cluster->store( os );
  38. //
  39. fbOut.close();
  40. // TEST RESTORING ABILITIES
  41. if ( verbose )
  42. std::cerr << " TEST RESTORING ABILITIES FOR STANDARD LOCALFEATURE" << std::endl;
  43. OBJREC::ClusterAlgorithm * clusterRestore = NULL;
  44. std::string s_destination_load ( "myClusterAlgoSelection.txt" );
  45. std::filebuf fbIn;
  46. fbIn.open ( s_destination_load.c_str(), ios::in );
  47. std::istream is (&fbIn);
  48. //
  49. OBJREC::GenericClusterAlgorithmSelection::restoreClusterAlgorithm ( clusterRestore, 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 ( cluster != NULL )
  57. delete cluster;
  58. if ( clusterRestore != NULL )
  59. delete clusterRestore;
  60. if (verboseStartEnd)
  61. std::cerr << "================== TestGenericClusterAlgoSelectionPersistent::testPersistentMethods done ===================== " << std::endl;
  62. }
  63. #endif