1 // suite.h 2 3 /* 4 * C/C++ Users Journal Sept 2000 <br> 5 * The Simplest Automated Unit Test Framework That Could Possibly Work <br> 6 * Chuck Allison <br> 7 */ 8 9 #ifndef SUITE_H 10 #define SUITE_H 11 12 #include "test.h" // includes <string>, <iosfwd> 13 #include <vector> 14 using std::string; 15 using std::ostream; 16 using std::vector; 17 #include "Stack.h" 18 19 class TestSuiteError : public logic_error 20 { 21 public: 22 TestSuiteError(const string& s = "") logic_error(s)23 : logic_error(s) 24 {} 25 }; 26 27 class Suite 28 { 29 public: 30 Suite(const string& name, ostream* osptr = 0); 31 32 string getName() const; 33 long getNumPassed() const; 34 long getNumFailed() const; 35 const ostream* getStream() const; 36 void setStream(ostream* osptr); 37 38 void addTest(Test* t) throw (TestSuiteError); 39 void addSuite(const Suite&) throw(TestSuiteError); 40 void run(); // Calls Test::run() repeatedly 41 long report() const; 42 void free(); // deletes tests 43 44 private: 45 string m_name; 46 ostream* m_osptr; 47 vector<Test*> m_tests; 48 void reset(); 49 50 // Disallowed ops: 51 Suite(const Suite&); 52 Suite& operator=(const Suite&); 53 }; 54 55 inline Suite(const string & name,ostream * osptr)56Suite::Suite(const string& name, ostream* osptr) 57 : m_name(name) 58 { 59 m_osptr = osptr; 60 } 61 62 inline getName()63string Suite::getName() const 64 { 65 return m_name; 66 } 67 68 inline getStream()69const ostream* Suite::getStream() const 70 { 71 return m_osptr; 72 } 73 74 inline setStream(ostream * osptr)75void Suite::setStream(ostream* osptr) 76 { 77 m_osptr = osptr; 78 } 79 80 #endif 81 82