// ClusterFindAll_t.cpp #include "ClusterFindAll.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" #include "trfbase/HitTest.h" using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; using namespace trf; int main( ) { string component = "ClusterFindAll"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "-------- Testing component " + component + ". --------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Test constructor." << endl; ObjTable::register_type(); ObjTable::register_type(); Ptr psrf6(new SurfTest(6.0)); ClusterFindAll find(psrf6); cout << find << endl; assert( find.get_surface().get_parameter(0) == 6.0 ); assert( find.get_clusters().size() == 0 ); ETrack tre(psrf6); assert( find.get_clusters(tre).size() == 0 ); //******************************************************************** cout << ok_prefix << "Add some clusters." << endl; find.add_cluster( new ClusterTest(*psrf6,1) ); find.add_cluster( new ClusterTest(*psrf6,2) ); find.add_cluster( new ClusterTest(*psrf6,3) ); cout << find << endl; assert( find.get_clusters().size() == 3 ); assert( find.get_clusters(tre).size() == 3 ); //******************************************************************** cout << ok_prefix << "Drop the clusters." << endl; find.drop_clusters(); cout << find << endl; assert( find.get_clusters().size() == 0 ); assert( find.get_clusters(tre).size() == 0 ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; SurfacePtr psrf1(new SurfTest(1.0)); Ptr pclf1( new ClusterFindAll(psrf1) ); { ostringstream sstrm; StdObjStream obstrm(sstrm); obstrm.write_object("surf1", psrf1); obstrm.write_object("clus_find1", pclf1); cout << sstrm.str() << endl; assert( sstrm.str().length() > 10 ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string str; str += "[ surf2 SurfTest x=2. ]"; str += "\n[ clus_find2 ClusterFindAll srf=@surf2 ]"; istringstream sstrm(str); StdObjStream obstrm(sstrm); assert( obstrm.read_object() == "surf2" ); assert( obstrm.read_object() == "clus_find2" ); Ptr pclf; ObjTable::get_object("clus_find2",pclf); assert( pclf->get_surface() == SurfTest(2.0) ); } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }