#ifndef SUITE_H #define SUITE_H /////////////////////////////////////////////////////////////////// // suite.h - declares test harness classes, Suite and // // ver 2.0 TestSuiteError // // // // Language: Visual C++, ver 6.0, SP 4 // // Platform: Dell XPS1000, Windows 2000 Professional, SP 1 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // jfawcett@twcny.rr.com, 315-443-3948 // // Source: // // The origianl design and implementation are by Chuck // // Allison (see ref, below), but I have modified his code // // and so take responsibility for this product. // /////////////////////////////////////////////////////////////////// // Notes: // // - This is a demonstration of a test harness that provides // // semi-automated low-level testing. // // - Goal is to run a suite of tests that return pass/fail // // information. // // - The intent is that you will use the test harness after // // every modification to your code, getting quick evidence // // that the change did or did not break anything. // // // // - To use harness you have to implement simple test classes, // // derived from class Test, provided by test harness. // // - You then declare an instance of class Suite, provided // // by this module and add an instance of each test class. // // The test harness: // // - sequences through all your tests, // // - keeps records of passes and failures // // - handles display of the results // // // // Reference: // // The Simplest Automated Unit Test Framework That Could // // Possibly Work, Chuck Allison, C/C++ Users Journal, // // September 2000 // /////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////// // Build Process // // Required Files: // // suite.h, suite.cpp, test.h, test.cpp // // // // Building in IDE: // // - create a workspace and project including these files // // - set Project/Settings/C\C++/Category=C++ Language // // check Enable Run-Time Type Information (RTTI) // // - set Project/Settings/C\C++/Category=general // // add ,TEST_SUITE to Preprocessor definitions // // - compile, link, and run // // // // Command line build: // // cl /GX /GR /DTEST_SUITE suite.cpp test.cpp // /////////////////////////////////////////////////////////////////// // Maintenance History // // ver 1.0 : Sep 2000 // // - first release, Chuck Allison, see Reference, above // // ver 2.0 : 2 Oct 2000 // // - added all manual, maintenance page information // // - removed all using declarations from header files // // - made cosmetic modifications to output display code // // - provided construction test stub for suite.cpp // // // /////////////////////////////////////////////////////////////////// #include "test.h" // includes , #include // ///////////////////////////////////////////////////////////////// // forward declaration of error class // class TestSuiteError; ///////////////////////////////////////////////////////////////// // Suite class provides the capability to incorporate a // series of tests, as implemented with derivations from // Test class, that can all be run as a single test operation. // class Suite { public: Suite(const std::string& name, std::ostream* osptr = 0); std::string getName() const; long getNumPassed() const; long getNumFailed() const; const std::ostream* getStream() const; void setStream(std::ostream* osptr); void addTest(Test* t) throw (TestSuiteError); void addSuite(const Suite&) throw(TestSuiteError); void run(); // Calls Test::run() repeatedly long report() const; void free(); // deletes tests private: std::string m_name; std::ostream* m_osptr; std::vector m_tests; void reset(); // Disallows copy construction and assignment: Suite(const Suite&); Suite& operator=(const Suite&); }; //----< construct Suite instance >------------------------------- inline Suite::Suite(const std::string& name, std::ostream* osptr) : m_name(name) { m_osptr = osptr; } // //----< return suite name >-------------------------------------- inline std::string Suite::getName() const { return m_name; } //----< return suite stream pointer >---------------------------- inline const std::ostream* Suite::getStream() const { return m_osptr; } //----< give suite a pointer to an output stream >--------------- inline void Suite::setStream(std::ostream* osptr) { m_osptr = osptr; } #endif