summaryrefslogtreecommitdiff
path: root/src/cppunit/TestRunner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit/TestRunner.cpp')
-rw-r--r--src/cppunit/TestRunner.cpp180
1 files changed, 50 insertions, 130 deletions
diff --git a/src/cppunit/TestRunner.cpp b/src/cppunit/TestRunner.cpp
index 44c11d9..9bce34d 100644
--- a/src/cppunit/TestRunner.cpp
+++ b/src/cppunit/TestRunner.cpp
@@ -1,179 +1,99 @@
-#include <cppunit/TestSuite.h>
-#include <cppunit/TextTestResult.h>
-#include <cppunit/TextOutputter.h>
-#include <cppunit/TextTestProgressListener.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/ui/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 );
-}
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestPath.h>
-TestRunner::~TestRunner()
+namespace CppUnit
{
- 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 )
+TestRunner::WrappingSuite::WrappingSuite( const std::string &name )
+ : TestSuite( name )
{
- 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 )
+int
+TestRunner::WrappingSuite::getChildTestCount() const
{
- runTestByName( testName, doPrintProgress );
- printResult( doPrintResult );
- wait( doWait );
- return m_result->wasSuccessful();
+ if ( hasOnlyOneTest() )
+ return getUniqueChildTest()->getChildTestCount();
+ return TestSuite::getChildTestCount();
}
-bool
-TestRunner::runTestByName( std::string testName,
- bool doPrintProgress )
+std::string
+TestRunner::WrappingSuite::getName() const
{
- if ( testName.empty() )
- return runTest( m_suite, doPrintProgress );
+ if ( hasOnlyOneTest() )
+ return getUniqueChildTest()->getName();
+ return TestSuite::getName();
+}
- Test *test = findTestByName( testName );
- if ( test != NULL )
- return runTest( test, doPrintProgress );
- std::cout << "Test " << testName << " not found." << std::endl;
- return false;
+Test *
+TestRunner::WrappingSuite::doGetChildTestAt( int index ) const
+{
+ if ( hasOnlyOneTest() )
+ return getUniqueChildTest()->getChildTestAt( index );
+ return TestSuite::doGetChildTestAt( index );
}
void
-TestRunner::wait( bool doWait )
+TestRunner::WrappingSuite::run( TestResult *result )
{
- if ( doWait )
- {
- std::cout << "<RETURN> to continue" << std::endl;
- std::cin.get ();
- }
+ if ( hasOnlyOneTest() )
+ getUniqueChildTest()->run( result );
+ else
+ TestSuite::run( result );
}
-void
-TestRunner::printResult( bool doPrintResult )
+bool
+TestRunner::WrappingSuite::hasOnlyOneTest() const
{
- std::cout << std::endl;
- if ( doPrintResult )
- m_outputter->write();
+ return TestSuite::getChildTestCount() == 1;
}
-Test *
-TestRunner::findTestByName( std::string name ) const
+Test *
+TestRunner::WrappingSuite::getUniqueChildTest() 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;
+ return TestSuite::doGetChildTestAt( 0 );
}
-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();
+
+TestRunner::TestRunner()
+ : m_suite( new WrappingSuite() )
+{
}
-/*! Returns the result of the test run.
- * Use this after calling run() to access the result of the test run.
- */
-TestResultCollector &
-TestRunner::result() const
+TestRunner::~TestRunner()
{
- return *m_result;
+ delete m_suite;
}
-/*! 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
+void
+TestRunner::addTest( Test *test )
{
- return *m_eventManager;
+ m_suite->addTest( test );
}
-/*! 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 )
+TestRunner::run( TestResult &controller,
+ const std::string &testPath )
{
- delete m_outputter;
- m_outputter = outputter;
+ TestPath path = m_suite->resolveTestPath( testPath );
+ Test *testToRun = path.getChildTest();
+
+ testToRun->run( &controller );
}
-} // namespace TextUi
-} // namespace CppUnit
+} // namespace CppUnit
+