00001 #ifndef TESTCOMPONENT_HH 00002 #define TESTCOMPONENT_HH 00003 00004 // Grab all the iostream forward declarations 00005 #include <iosfwd> 00006 00007 #include <string> 00008 00009 #include <list> 00010 00011 #include <boost/smart_ptr.hpp> 00012 #include "TestForward.hh" 00013 00015 namespace ccunit 00016 { 00017 00033 class TestComponent 00034 { 00035 public: 00037 class ErrorReport 00038 { 00039 public: 00041 ErrorReport(const char* type_name, const string& lbl, 00042 const char* fname, const char* fnt_name, long lineno); 00043 00045 friend ostream & operator<<(ostream &ostr, const TestComponent::ErrorReport &my_error_report); 00046 00048 // (useful?) 00049 const string& getObject() const { return m_to_name; } 00050 00052 const string& getLabel() const { return m_lbl; } 00053 00055 const string& getFileName() const { return m_to_name; } 00056 00058 const string& getLineNumber() const { return m_to_name; } 00059 00061 const string& getTestFunctionName() const { return m_to_name; } 00062 00063 private: 00065 string m_to_name; 00066 00068 string m_lbl; 00069 00071 string m_fname; 00072 00074 string m_fnt_name; 00075 00077 long m_lineno; 00078 }; 00079 00081 TestComponent(const string &name = "(no name)"); 00082 00084 virtual ~TestComponent(); 00085 00086 // ********** Container Manipulations ********** 00087 00089 virtual void Add(TestComponentPtr) { return ; } 00090 00092 virtual void Remove(TestComponentPtr) { return; } 00093 00095 virtual bool CheckRecursion(TestComponent*) const {return false;} 00096 00097 // ********** Testing Methods ********** 00098 // These method relate to the creation and execution of tests and 00099 // the reporting of results. 00100 00107 virtual void run(); 00108 00110 bool hasRun(); 00111 00113 unsigned long getNumPassed(); 00114 00116 unsigned long getNumFailed(); 00117 00119 virtual void report(ostream &ostr) = 0; 00120 00122 virtual void reset(); 00123 00125 friend ostream & operator<<(ostream &ostr, TestComponentPtr my_test_component); 00126 00128 friend ostream & operator<<(ostream &ostr, TestComponent& my_test_component); 00129 00131 void setName(const string &name) {m_name = name;} 00132 00134 const string &getName() const {return m_name;} 00135 00137 void checkRun(); 00138 00140 const list<ErrorReport> &getFailures() const { return m_failures; } 00141 00142 protected: 00143 00144 // ********** Test Methods ********** 00146 virtual void run_tests() = 0; 00147 00148 // ********** Test Results ********** 00150 unsigned long m_nPass; 00151 00153 unsigned long m_nFail; 00154 00156 bool m_hasRun; 00157 00159 string m_name; 00160 00162 list<ErrorReport> m_failures; 00163 00164 private: 00165 }; 00166 00167 } // namespace ccunit 00168 00169 #endif