00001 // TestSuite from Chuck Allison in C/C++ Users Journal, September 2000: 00002 // "The Simplest Automated Unit Test Framework That Could Possibly Work" 00003 00004 #ifndef testSUITE_H 00005 #define testSUITE_H 00006 00007 #include "testcase.hh" 00008 #include "exceptions.hh" 00009 #include <vector> 00010 using std::string; 00011 using std::ostream; 00012 using std::vector; 00013 00014 namespace test { 00015 00016 // ******************************************************** TestSuiteError ** 00017 00021 class TestSuiteError : public concepts::MissingFeature { 00022 public: 00023 TestSuiteError(const std::string& error) throw(); 00024 protected: 00025 virtual std::ostream& info(std::ostream& os) const throw(); 00026 }; 00027 00028 // ************************************************************* TestSuite ** 00029 00038 class TestSuite { 00039 public: 00044 TestSuite(const string& name, ostream* osptr = 0); 00045 00047 string getName() const { return m_name; } 00049 long getNumPassed() const; 00051 long getNumFailed() const; 00053 const ostream* getStream() const { return m_osptr; } 00055 void setStream(ostream* osptr) { m_osptr = osptr; } 00056 00058 void addTest(TestCase* t) throw (TestSuiteError); 00060 void addSuite(const TestSuite&) throw(TestSuiteError); 00062 void run(); 00067 long report() const; 00069 void free(); 00070 private: 00071 string m_name; 00072 ostream* m_osptr; 00073 vector<TestCase*> m_tests; 00074 void reset(); 00075 00077 TestSuite(const TestSuite&); 00079 TestSuite& operator=(const TestSuite&); 00080 }; 00081 00082 inline TestSuite::TestSuite(const string& name, ostream* osptr) : 00083 m_name(name), m_osptr(osptr) { 00084 if (m_osptr == 0) 00085 m_osptr = &std::cout; 00086 } 00087 00088 } // namespace test 00089 00090 #endif // testSUITE_H