#ifndef TESTHARNESS_H #define TESTHARNESS_H /////////////////////////////////////////////////////////////////////////// // TestHarness.h - Declares test aggregator and test functior base class // // ver 1.0 // // // // Language: Visual C++, ver 7.0 // // Platform: Dell Dimension 8300, Windows XP Prof, SP 1 // // Application: CSE687 prototype for project #1, Spring 2004 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////////////// /* * Module Operations: * ================== * Provides a test aggregator, e.g., a container of test objects, and a base * class for all test objects. * * Public Interface: * ================= * tester t; * class myTest : public test { ... } * t.register(new myTest); * t.register(new yourTest); * t.showTestData(0); * t.execute(); */ /* * Maintenance History: * ==================== * ver 1.0 : 21 Feb 04 * - first release * * Build Process: * ============== * Required Files: * TestHarness.h, TestHarness.cpp * * Compiler Command: * cl /DTEST_TESTHARNESS /EHsc TestHarness.cpp; */ // #include #include #include #include namespace TestHarness { /////////////////////////////////////////////////////////////////////// // Test I/O classes class output : public std::ostringstream { public: output() : _showAll(false) {} virtual ~output() {} virtual void write()=0; void showAll(bool show) { _showAll = show; } protected: bool _showAll; }; class stdOutput : public output { public: ~stdOutput() { std::cout << str(); std::cout.flush(); } void write() { std::cout << str(); str(""); std::cout.flush(); } }; class nullOutput : public output { public: ~nullOutput() { if(_showAll) { std::cout << str(); std::cout.flush(); } } void write() { if(_showAll) { std::cout << str(); str(""); std::cout.flush(); } } }; // ///////////////////////////////////////////////////////////////////// // generic function to display STL container contents // - works for vectors, sets, and lists template class showCont { public: void operator()(const T& cont) { Output out; out << " "; T::const_iterator it; for(it = cont.begin(); it != cont.end(); it++) out << *it << " "; out << "\n\n"; out.write(); } }; /////////////////////////////////////////////////////////////////////// // test class is base for all concrete tests class test { public: test(output& out) : tout(out) {} virtual bool operator()()=0; virtual ~test() {}; void title(const std::string& t); protected: output& tout; static unsigned int count; }; /////////////////////////////////////////////////////////////////////// // tester class is a test aggregator, e.g., a container for tests class tester { public: tester(output& out, const std::string& msg); bool execute(output& out); void registerTest(test *to); private: std::vector _test; unsigned failed; }; } #endif