// Algorithm_t.cpp // Test algorithm class. #include "Algorithm.h" #include #include #include #include "objstream/ObjData.hpp" using std::ostream; using std::cout; using std::cerr; using std::endl; using std::string; using trf::Algorithm; //********************************************************************** // Test base class. ObjPtr create(const ObjData& data); class TestAlgo : public Algorithm { private: static TypeName get_type_name() { return "TestAlgo"; } static ObjCreator get_creator() { return create; } static Type get_static_type() { return get_creator(); } void ostr(ostream& stream) const { stream << "Test algorithm"; } public: Type get_generic_type() const { return get_static_type(); } Type get_type() const { return get_static_type(); } ObjData write_data() const { return ObjData("TestAlgo"); } }; ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "TestAlgo" ); return ObjPtr( new TestAlgo() ); } //********************************************************************** int main( ) { string ok_prefix = "Algorithm test (I): "; string error_prefix = "Algorithm test (E): "; cout << ok_prefix << "------ Testing component Algorithm. ------" << 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 << ok_prefix << "Test constructor and default debug." << endl; TestAlgo talg; assert( ! talg.get_debug() ); //******************************************************************** cout << ok_prefix << "Test printing:" << endl; cout << talg << endl; //******************************************************************** cout << ok_prefix << "Test get/set debug flag." << endl; talg.set_debug(7); assert( talg.get_debug() == 7 ); talg.set_debug(0); assert( talg.get_debug() == 0 ); //******************************************************************** cout << ok_prefix << " ------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }