#include <TestLib_Listener.h>
#include <cppunit/Test.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/SourceLine.h>
#include <iostream>
+#include <QStringList>
#ifdef WIN32
#include <windows.h>
\brief Constructor
*/
TestLib_Listener::TestLib_Listener()
-: myStart( 0 ), myComplete( 0 )
+: myStart( 0 ), myComplete( 0 ), myNbTests( 0 ), myNbSuites( 0 )
{
}
INT64 anExecTimeMS = aCurTime - myStart;
myComplete += anExecTimeMS;
std::cout << " " << anExecTimeMS << " ms" << std::endl;
+
+ myNbTests++;
+}
+
+int TestLib_Listener::GetNbTests() const
+{
+ return myNbTests;
+}
+
+int TestLib_Listener::GetNbSuites() const
+{
+ return myNbSuites;
}
/**
*/
void TestLib_Listener::endSuite( CppUnit::Test* theTest )
{
+ myNbSuites++;
}
/**
*/
void TestLib_Listener::addFailure( const CppUnit::TestFailure& theFailure )
{
+ std::string failedTest = theFailure.failedTest()->getName();
+ CppUnit::SourceLine failedLocation = theFailure.sourceLine();
+
+ QString aFile = QString::fromStdString( failedLocation.fileName() );
+ aFile.replace( '\\', '/' );
+ QStringList parts = aFile.split( '/' );
+ aFile = parts.last();
+ std::string cFile = aFile.toStdString();
+
+ int aLine = failedLocation.lineNumber();
+
+ static char aBuf[1024];
+ sprintf( aBuf, "Failed %s: %s : %i", failedTest.c_str(), cFile.c_str(), aLine );
+
+ myFailures.push_back( aBuf );
}
+void TestLib_Listener::DumpFailures()
+{
+ int n = (int)myFailures.size();
+ printf( "FAILED TESTS: %i\n", n );
+ for( int i=0; i<n; i++ )
+ printf( " %s\n", myFailures[i].c_str() );
+}