// CheckZInt_t.cpp #include "CheckZInt.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 "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 = "CheckZInt"; 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(); CheckZInt chk(5.0); cout << chk << endl; //******************************************************************** double x = 35.35; double y = 35.35; double z = 35.35; double dx = 0.23; double dy = 0.45; double dz = 0.67; CartesianPath cart(x,y,z,dx,dy,dz); cout << ok_prefix << "Test status." << endl; ETrack tre( SurfacePtr( new SurfTest(cart) ) ); TrackVector tv1; tv1(0) = -1.2; tv1(1) = 2.3; tv1(2) = -3.4; tv1(3) = 4.5; tv1(4) = -5.6; tre.set_vector(tv1); MTrack trm(tre); cout << ok_prefix << "Checking Track: " << endl << trm << endl; trm.set_fit(tre,2.0); assert( chk.status(trm) ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { CheckerPtr pchk( new CheckZInt(12.34) ); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("chk1",pchk); cout << mystream.str() << endl; assert( ObjTable::has_object_name("chk1") ); assert( mystream.str().find("12.34 ") != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ chk2 CheckZInt max_zint=24.68 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "chk2" ); const CheckZInt* pchk; ObjTable::get_object("chk2",pchk); assert( pchk != 0 ); assert( pchk->get_type() == CheckZInt::get_static_type() ); assert( pchk->get_max_zint() == 24.68 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }