diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-03-28 14:50:09 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-03-28 14:50:09 +0000 |
| commit | 82d51cba4c7cc8d756ab14fdfc28181f007f3848 (patch) | |
| tree | d28a09b421cb1802e5720cd112a577958b2c9d0f /src/cppunit/TestRunner.cpp | |
| parent | 686e4865001cb14c36e8e3e81fc7c57786ff0542 (diff) | |
| download | cppunit-82d51cba4c7cc8d756ab14fdfc28181f007f3848.tar.gz | |
Doc/cookbook.
doc/cookbook.html: removed. Replaced by cookbook.doc.
* doc/cookbook.dox: added, conversion of cookbook.html to Doxygen format.
* doc/other_documentation.dox: added groups definition.
* doc/Makefile.am: replaced cookbook.html by cookbook.dox
* doc/Doxyfile.in: added predefined CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION.
Replaced cookbook.html by cookbook.dox.
* include/cppunitui/mfc/TestRunner.h: added, extracted from
include/msvc6/testrunner/TestRunner.h. Moved class TestRunner to namespace
CppUnit::MfcUi.
* include/msvc6/testrunner/TestRunner.h: deprecated. A simple typedef to
CppUnit::MfcUi::TestRunner.
* include/textui/TestRuner.h: added, extracted from
include/cppunit/TextTestRunner.h.
* src/cppunit/TextTestRunner.cpp: renamed TestRunner.cpp. Moved into
namespace CppUnit::TextUi.
* src/msvc6/testruner/TestRunner.cpp: moved into namespace CppUnit::MfcUi.
* src/cppunit/CompilerOutputter.cpp: removed printing "- " before
NotEqualException addional message, for consistency between different
TestRunner (Mfc,Text...)
* include/cppunit/Asserter.h:
* include/cppunit/CompilerOutputter.h:
* include/cppunit/Exception.h:
* include/cppunit/NotEqualException.h:
* include/cppunit/Outputter.h:
* include/cppunit/SourceLine.h:
* include/cppunit/TestAssert.h:
* include/cppunit/TestCaller.h:
* include/cppunit/TestFailure.h:
* include/cppunit/TestFixture.h:
* include/cppunit/TestListener.h:
* include/cppunit/TestResult.h:
* include/cppunit/TestResultCollector.h:
* include/cppunit/TestSucessListener.h:
* include/cppunit/TestSuite.h:
* include/cppunit/TextTestProgressListener.h:
* include/cppunit/TextTestRunner.h:
* include/cppunit/XmlOutputter.h:
* include/cppunit/extensions/AutoRegisterSuite.h:
* include/cppunit/extensions/HelperMacros.h:
* include/cppunit/extensions/TestFactoryRegistry.h:
* include/cppunit/extensions/TestSuiteBuilder.h:
* include/cppunit/extensions/TestSuiteFactory.h: doc update. organization
in groups.
* examples/msvc6/CppUnitTestApp/CppUnitTestApp.cpp:
* examples/msvc6/HostApp/HostApp.cpp: updated to use
CppUnit::MfcUi::TestRunner.
* examples/cppunittest/CppUnitTestMain.cpp: updated to use
CppUnit::TextUi::TestRunner.
Diffstat (limited to 'src/cppunit/TestRunner.cpp')
| -rw-r--r-- | src/cppunit/TestRunner.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/src/cppunit/TestRunner.cpp b/src/cppunit/TestRunner.cpp new file mode 100644 index 0000000..6c1a110 --- /dev/null +++ b/src/cppunit/TestRunner.cpp @@ -0,0 +1,179 @@ +#include <cppunit/TestSuite.h> +#include <cppunit/TextTestResult.h> +#include <cppunit/TextOutputter.h> +#include <cppunit/TextTestProgressListener.h> +#include <cppunit/TestResult.h> +#include <cppunitui/text/TestRunner.h> +#include <iostream> + + +namespace CppUnit { +namespace TextUi { + +/*! Constructs a new text runner. + * \param outputter used to print text result. Owned by the runner. + */ +TestRunner::TestRunner( Outputter *outputter ) + : m_outputter( outputter ) + , m_suite( new TestSuite( "All Tests" ) ) + , m_result( new TestResultCollector() ) + , m_eventManager( new TestResult() ) +{ + if ( !m_outputter ) + m_outputter = new TextOutputter( m_result, std::cout ); + m_eventManager->addListener( m_result ); +} + + +TestRunner::~TestRunner() +{ + delete m_eventManager; + delete m_outputter; + delete m_result; + delete m_suite; +} + + +/*! Adds the specified test. + * + * \param test Test to add. + */ +void +TestRunner::addTest( Test *test ) +{ + if ( test != NULL ) + m_suite->addTest( test ); +} + + +/*! Runs the named test case. + * + * \param testName Name of the test case to run. If an empty is given, then + * all added test are run. The name must be the name of + * of an added test. + * \param doWait if \c true then the user must press the RETURN key + * before the run() method exit. + * \param doPrintResult if \c true (default) then the test result are printed + * on the standard output. + * \param doPrintProgress if \c true (default) then TextTestProgressListener is + * used to show the progress. + * \return \c true is the test was successful, \c false if the test + * failed or was not found. + */ +bool +TestRunner::run( std::string testName, + bool doWait, + bool doPrintResult, + bool doPrintProgress ) +{ + runTestByName( testName, doPrintProgress ); + printResult( doPrintResult ); + wait( doWait ); + return m_result->wasSuccessful(); +} + + +bool +TestRunner::runTestByName( std::string testName, + bool doPrintProgress ) +{ + if ( testName.empty() ) + return runTest( m_suite, doPrintProgress ); + + Test *test = findTestByName( testName ); + if ( test != NULL ) + return runTest( test, doPrintProgress ); + + std::cout << "Test " << testName << " not found." << std::endl; + return false; +} + + +void +TestRunner::wait( bool doWait ) +{ + if ( doWait ) + { + std::cout << "<RETURN> to continue" << std::endl; + std::cin.get (); + } +} + + +void +TestRunner::printResult( bool doPrintResult ) +{ + std::cout << std::endl; + if ( doPrintResult ) + m_outputter->write(); +} + + +Test * +TestRunner::findTestByName( std::string name ) const +{ + for ( std::vector<Test *>::const_iterator it = m_suite->getTests().begin(); + it != m_suite->getTests().end(); + ++it ) + { + Test *test = *it; + if ( test->getName() == name ) + return test; + } + return NULL; +} + + +bool +TestRunner::runTest( Test *test, + bool doPrintProgress ) +{ + TextTestProgressListener progress; + if ( doPrintProgress ) + m_eventManager->addListener( &progress ); + + test->run( m_eventManager ); + + if ( doPrintProgress ) + m_eventManager->removeListener( &progress ); + return m_result->wasSuccessful(); +} + + +/*! Returns the result of the test run. + * Use this after calling run() to access the result of the test run. + */ +TestResultCollector & +TestRunner::result() const +{ + return *m_result; +} + + +/*! Returns the event manager. + * The instance of TestResult results returned is the one that is used to run the + * test. Use this to register additional TestListener before running the tests. + */ +TestResult & +TestRunner::eventManager() const +{ + return *m_eventManager; +} + + +/*! Specifies an alternate outputter. + * + * Notes that the outputter will be use after the test run only if \a printResult was + * \c true. + * \see CompilerOutputter, XmlOutputter, TextOutputter. + */ +void +TestRunner::setOutputter( Outputter *outputter ) +{ + delete m_outputter; + m_outputter = outputter; +} + + +} // namespace TextUi +} // namespace CppUnit |
