// McCluster_t.cpp // Test component McCluster. #include "McClusterTest.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "Hit.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 = "McCluster"; 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; } //******************************************************************** ObjTable::register_type(); ObjTable::register_type(); ObjTable::register_type(); //******************************************************************** cout << ok_prefix << "Check MC ID's." << endl; Ptr pstest( new SurfTest(3) ); const SurfTest& stest(*pstest); McIdList ids; ids.push_back(1); ids.push_back(22); ids.push_back(333); McClusterTest* pbare = new McClusterTest(stest,ids); ClusterPtr pclu1(pbare); { const McIdList& oids = pclu1->get_mc_ids(); assert( oids.size() == 3 ); assert( oids[0] == 1 ); assert( oids[1] == 22 ); assert( oids[2] == 333 ); } //******************************************************************** cout << ok_prefix << "Copy." << endl; ClusterPtr pclu2 = new McClusterTest(*pbare); { const McIdList& oids = pclu2->get_mc_ids(); assert( oids.size() == 3 ); assert( oids[0] == 1 ); assert( oids[1] == 22 ); assert( oids[2] == 333 ); } //******************************************************************** cout << ok_prefix << "Test output object stream." << endl; { ostringstream osstrm; StdObjStream objstrm(osstrm); assert( osstrm.str() == "" ); objstrm.write_object("stest1",pstest); objstrm.write_object("clus1",*pclu1); cout << osstrm.str() << endl; assert( osstrm.str() != "" ); } //******************************************************************** cout << ok_prefix << "Test input object stream." << endl; { string str; str += "[ stest2 SurfTest x=2. ]\n"; str += "[ clus5 McClusterTest surface=*stest1 "; #ifdef ObjData_supports_lists str += "mcids=int( 1 22 333 ) "; #endif str += "]"; istringstream isstrm(str); StdObjStream objstrm(isstrm); // Read objects. assert( objstrm.read_object() == "stest2" ); assert( objstrm.read_object() == "clus5" ); // Fetch surface. Ptr pstest2; ObjTable::get_object("stest2",pstest2); cout << *pstest2 << endl; assert( *pstest2 == SurfTest(2) ); // Fetch cluster. ClusterPtr pclu; ObjTable::get_object("clus5",pclu); cout << *pclu << endl; #ifdef ObjData_supports_lists assert( *pclu == McClusterTest(*pstest2,ids) ); #endif } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }