1
// ==> Implementation of cppunit/ui/text/TestRunner.h
3
#include <cppunit/config/SourcePrefix.h>
4
#include <cppunit/TestSuite.h>
5
#include <cppunit/TextTestResult.h>
6
#include <cppunit/TextOutputter.h>
7
#include <cppunit/TextTestProgressListener.h>
8
#include <cppunit/TestResult.h>
9
#include <cppunit/ui/text/TextTestRunner.h>
10
#include <cppunit/portability/Stream.h>
17
/*! Constructs a new text runner.
18
* \param outputter used to print text result. Owned by the runner.
20
TextTestRunner::TextTestRunner( Outputter *outputter )
21
: m_result( new TestResultCollector() )
22
, m_eventManager( new TestResult() )
23
, m_outputter( outputter )
26
m_outputter = new TextOutputter( m_result, stdCOut() );
27
m_eventManager->addListener( m_result );
31
TextTestRunner::~TextTestRunner()
33
delete m_eventManager;
39
/*! Runs the named test case.
41
* \param testName Name of the test case to run. If an empty is given, then
42
* all added tests are run. The name can be the name of any
43
* test in the hierarchy.
44
* \param doWait if \c true then the user must press the RETURN key
45
* before the run() method exit.
46
* \param doPrintResult if \c true (default) then the test result are printed
47
* on the standard output.
48
* \param doPrintProgress if \c true (default) then TextTestProgressListener is
49
* used to show the progress.
50
* \return \c true is the test was successful, \c false if the test
51
* failed or was not found.
54
TextTestRunner::run( std::string testName,
57
bool doPrintProgress )
59
TextTestProgressListener progress;
60
if ( doPrintProgress )
61
m_eventManager->addListener( &progress );
63
TestRunner *pThis = this;
64
pThis->run( *m_eventManager, testName );
66
if ( doPrintProgress )
67
m_eventManager->removeListener( &progress );
69
printResult( doPrintResult );
72
return m_result->wasSuccessful();
77
TextTestRunner::wait( bool doWait )
79
#if !defined( CPPUNIT_NO_STREAM )
82
stdCOut() << "<RETURN> to continue\n";
91
TextTestRunner::printResult( bool doPrintResult )
99
/*! Returns the result of the test run.
100
* Use this after calling run() to access the result of the test run.
102
TestResultCollector &
103
TextTestRunner::result() const
109
/*! Returns the event manager.
110
* The instance of TestResult results returned is the one that is used to run the
111
* test. Use this to register additional TestListener before running the tests.
114
TextTestRunner::eventManager() const
116
return *m_eventManager;
120
/*! Specifies an alternate outputter.
122
* Notes that the outputter will be use after the test run only if \a printResult was
124
* \param outputter New outputter to use. The previous outputter is destroyed.
125
* The TextTestRunner assumes ownership of the outputter.
126
* \see CompilerOutputter, XmlOutputter, TextOutputter.
129
TextTestRunner::setOutputter( Outputter *outputter )
132
m_outputter = outputter;
137
TextTestRunner::run( TestResult &controller,
138
const std::string &testPath )
140
TestRunner::run( controller, testPath );