summaryrefslogtreecommitdiff
path: root/src/cppunit
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit')
-rw-r--r--src/cppunit/CompilerOutputter.cpp78
-rw-r--r--src/cppunit/TestComposite.cpp39
-rw-r--r--src/cppunit/TestResult.cpp28
3 files changed, 126 insertions, 19 deletions
diff --git a/src/cppunit/CompilerOutputter.cpp b/src/cppunit/CompilerOutputter.cpp
index 025dd34..a828a40 100644
--- a/src/cppunit/CompilerOutputter.cpp
+++ b/src/cppunit/CompilerOutputter.cpp
@@ -10,9 +10,11 @@ namespace CppUnit
{
CompilerOutputter::CompilerOutputter( TestResultCollector *result,
- std::ostream &stream ) :
- m_result( result ),
- m_stream( stream )
+ std::ostream &stream,
+ const std::string &locationFormat )
+ : m_result( result )
+ , m_stream( stream )
+ , m_locationFormat( locationFormat )
{
}
@@ -22,13 +24,18 @@ CompilerOutputter::~CompilerOutputter()
}
+void
+CompilerOutputter::setLocationFormat( const std::string &locationFormat )
+{
+ m_locationFormat = locationFormat;
+}
+
+
CompilerOutputter *
CompilerOutputter::defaultOutputter( TestResultCollector *result,
std::ostream &stream )
{
return new CompilerOutputter( result, stream );
-// For automatic adpatation...
-// return new CPPUNIT_DEFAULT_OUTPUTTER( result, stream );
}
@@ -81,11 +88,64 @@ CompilerOutputter::printFailureDetail( TestFailure *failure )
void
CompilerOutputter::printFailureLocation( SourceLine sourceLine )
{
- if ( sourceLine.isValid() )
- m_stream << sourceLine.fileName()
- << "(" << sourceLine.lineNumber() << ") : ";
- else
+ if ( !sourceLine.isValid() )
+ {
m_stream << "##Failure Location unknown## : ";
+ return;
+ }
+
+ std::string location;
+ for ( int index = 0; index < m_locationFormat.length(); ++index )
+ {
+ char c = m_locationFormat[ index ];
+ if ( c == '%' && ( index+1 < m_locationFormat.length() ) )
+ {
+ char command = m_locationFormat[index+1];
+ if ( processLocationFormatCommand( command, sourceLine ) )
+ {
+ ++index;
+ continue;
+ }
+ }
+
+ m_stream << c;
+ }
+}
+
+
+bool
+CompilerOutputter::processLocationFormatCommand( char command,
+ const SourceLine &sourceLine )
+{
+ switch ( command )
+ {
+ case 'p':
+ m_stream << sourceLine.fileName();
+ return true;
+ case 'l':
+ m_stream << sourceLine.lineNumber();
+ return true;
+ case 'f':
+ m_stream << extractBaseName( sourceLine.fileName() );
+ return true;
+ }
+
+ return false;
+}
+
+
+std::string
+CompilerOutputter::extractBaseName( const std::string &fileName ) const
+{
+ int indexLastDirectorySeparator = fileName.find_last_of( '/' );
+
+ if ( indexLastDirectorySeparator < 0 )
+ indexLastDirectorySeparator = fileName.find_last_of( '\\' );
+
+ if ( indexLastDirectorySeparator < 0 )
+ return fileName;
+
+ return fileName.substr( indexLastDirectorySeparator +1 );
}
diff --git a/src/cppunit/TestComposite.cpp b/src/cppunit/TestComposite.cpp
index e5f38c3..1127a4c 100644
--- a/src/cppunit/TestComposite.cpp
+++ b/src/cppunit/TestComposite.cpp
@@ -18,14 +18,9 @@ TestComposite::~TestComposite()
void
TestComposite::run( TestResult *result )
{
- int childCount = getChildTestCount();
- for ( int index =0; index < childCount; ++index )
- {
- if ( result->shouldStop() )
- break;
-
- getChildTestAt( index )->run( result );
- }
+ doStartSuite( result );
+ doRunChildTests( result );
+ doEndSuite( result );
}
@@ -49,5 +44,33 @@ TestComposite::getName() const
}
+void
+TestComposite::doStartSuite( TestResult *controller )
+{
+ controller->startSuite( this );
+}
+
+
+void
+TestComposite::doRunChildTests( TestResult *controller )
+{
+ int childCount = getChildTestCount();
+ for ( int index =0; index < childCount; ++index )
+ {
+ if ( controller->shouldStop() )
+ break;
+
+ getChildTestAt( index )->run( controller );
+ }
+}
+
+
+void
+TestComposite::doEndSuite( TestResult *controller )
+{
+ controller->endSuite( this );
+}
+
+
} // namespace CppUnit
diff --git a/src/cppunit/TestResult.cpp b/src/cppunit/TestResult.cpp
index d5644a4..aacb9a4 100644
--- a/src/cppunit/TestResult.cpp
+++ b/src/cppunit/TestResult.cpp
@@ -66,7 +66,7 @@ TestResult::addFailure( const TestFailure &failure )
}
-/// Informs the result that a test will be started.
+/// Informs TestListener that a test will be started.
void
TestResult::startTest( Test *test )
{
@@ -78,7 +78,7 @@ TestResult::startTest( Test *test )
}
-/// Informs the result that a test was completed.
+/// Informs TestListener that a test was completed.
void
TestResult::endTest( Test *test )
{
@@ -90,6 +90,30 @@ TestResult::endTest( Test *test )
}
+/// Informs TestListener that a test suite will be started.
+void
+TestResult::startSuite( Test *test )
+{
+ ExclusiveZone zone( m_syncObject );
+ for ( TestListeners::iterator it = m_listeners.begin();
+ it != m_listeners.end();
+ ++it )
+ (*it)->startSuite( test );
+}
+
+
+/// Informs TestListener that a test suite was completed.
+void
+TestResult::endSuite( Test *test )
+{
+ ExclusiveZone zone( m_syncObject );
+ for ( TestListeners::iterator it = m_listeners.begin();
+ it != m_listeners.end();
+ ++it )
+ (*it)->endSuite( test );
+}
+
+
/// Returns whether testing should be stopped
bool
TestResult::shouldStop() const