// CheckHitCount_t.cpp #include "CheckHitCount.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" #include "trffit/MTrack.h" #include "trfbase/HitTest.h" #include "CheckerPtr.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 = "CheckHitCount"; 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 << "Create checker." << endl; ObjTable::register_type(); CheckHitCount chk(2); cout << chk << endl; //******************************************************************** cout << ok_prefix << "Test status." << endl; ETrack tre( SurfacePtr(new SurfTest(1)) ); MTrack trm(tre); assert( ! chk.status(trm) ); HitPtr phit( HitPtr(new HitTest(1)) ); trm.add_hit(phit); assert( ! chk.status(trm) ); trm.add_hit(phit); assert( chk.status(trm) ); trm.add_hit(phit); assert( chk.status(trm) ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { CheckerPtr pchk( new CheckHitCount(123) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("chk1",pchk); cout << mystream.str() << endl; assert( ObjTable::has_object_name("chk1") ); assert( mystream.str().find( "123 ") != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ chk2 CheckHitCount min_hit_count=24 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "chk2" ); const CheckHitCount* pchk; ObjTable::get_object("chk2",pchk); assert( pchk != 0 ); assert( pchk->get_type() == CheckHitCount::get_static_type() ); assert( pchk->get_min_hit_count() == 24 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }