34 #include <QtCore/QRegExp> 
   35 #include <QtCore/QDir> 
   36 #include <QtCore/QMetaEnum> 
   48     Runner *Runner::s_self = 0L;
 
   49     bool    Runner::s_debugCapturingEnabled = 
false;
 
   51     void Runner::registerTester(
const char *name, 
Tester *test)
 
   53         Runner::self()->m_registry.insert(name, test);
 
   58         QRegExp reQuery(query);
 
   59         QDir dir(folder, 
"kunittest_*.la");
 
   64         kDebug() << 
"Looking in folder: " << dir.absolutePath();
 
   69         for ( 
int i = 0; i < modules.count(); ++i )
 
   72             kDebug() << 
"Module: " << dir.absolutePath() + 
'/' + module;
 
   74             if ( reQuery.indexIn(module) != -1 )
 
   77                 module.truncate(module.length()-3);
 
   83                     kWarning() << 
"\tError loading " << module << 
" : " << loader.errorString();
 
   88                 kDebug() << 
"\tModule doesn't match.";
 
   92     void Runner::setDebugCapturingEnabled(
bool enabled)
 
   94       s_debugCapturingEnabled = enabled;
 
  103     int Runner::numberOfTestCases()
 
  105         return m_registry.count();
 
  122     int Runner::numberOfTests()
 const 
  127     int Runner::numberOfPassedTests()
 const 
  132     int Runner::numberOfFailedTests()
 const 
  137     int Runner::numberOfExpectedFailures()
 const 
  142     int Runner::numberOfSkippedTests()
 const 
  144         return globalSkipped;
 
  157     int Runner::runTests()
 
  166         cout << 
"# Running normal tests... #" << endl << endl;
 
  168         Registry::const_iterator it = m_registry.constBegin();
 
  169         for( ; it != m_registry.constEnd(); ++it )
 
  170             runTest( it.key( ) );
 
  172 #if 0 // very thorough, but not very readable 
  173         cout << 
"# Done with normal tests:" << endl;
 
  174         cout << 
"  Total test cases: " << m_registry.count() << endl;
 
  175         cout << 
"  Total test steps                                 : " << globalSteps << endl;
 
  176         cout << 
"    Total passed test steps (including unexpected) : " << globalPasses << endl;
 
  177         cout << 
"      Total unexpected passed test steps           :  " << globalXPasses << endl;
 
  178         cout << 
"    Total failed test steps (including expected)   :  " << globalFails << endl;
 
  179         cout << 
"      Total expected failed test steps             :  " << globalXFails << endl;
 
  180         cout << 
"    Total skipped test steps                       :  " << globalSkipped << endl;
 
  182         unsigned int numTests = m_registry.count(); 
 
  184         if ( globalFails == 0 )
 
  185             if ( globalXFails == 0 )
 
  186                 str = 
QString( 
"All %1 tests passed" ).arg( numTests );
 
  188                 str = 
QString( 
"All %1 tests behaved as expected (%2 expected failures)" ).arg( numTests ).arg( globalXFails );
 
  190             if ( globalXPasses == 0 )
 
  191                 str = 
QString( 
"%1 of %2 tests failed" ).arg( globalFails ).arg( numTests );
 
  193                 str = 
QString( 
"%1 of %2 tests did not behave as expected (%1 unexpected passes)" ).arg( globalFails ).arg( numTests ).arg( globalXPasses );
 
  195             str += 
QString( 
" (%1 tests skipped)" ).arg( globalSkipped );
 
  196         cout << str.toLocal8Bit().constData() << endl;
 
  199         return m_registry.count();
 
  202     void Runner::runMatchingTests(
const QString &prefix)
 
  204         Registry::const_iterator it = m_registry.constBegin();
 
  205         for( ; it != m_registry.constEnd(); ++it )
 
  206             if ( 
QString( it.key() ).startsWith(prefix) )
 
  210     void Runner::runTest(
const char *name)
 
  212         Tester *test = m_registry.value( name );
 
  215         if ( s_debugCapturingEnabled )
 
  217           cout << 
"KUnitTest_Debug_Start[" << name << 
"]" << endl;
 
  223         if ( s_debugCapturingEnabled )
 
  225           cout << 
"KUnitTest_Debug_End[" << name << 
"]" << endl << endl << flush;
 
  234         if ( test->inherits(
"KUnitTest::SlotTester") )
 
  241                 numXFail += res->
xfails();
 
  258         globalPasses += numPass;
 
  259         globalFails += numFail;
 
  260         globalXFails += numXFail;
 
  261         globalXPasses += numXPass;
 
  262         globalSkipped += numSkip;
 
  264         cout << name << 
" - ";
 
  265         cout << numPass << 
" test" << ( ( 1 == numPass )?
"":
"s") << 
" passed";
 
  267             cout << 
" (" << numXPass << 
" unexpected pass" << ( ( 1 == numXPass )?
"":
"es") << 
")";
 
  269         cout << 
", " << numFail << 
" test" << ( ( 1 == numFail )?
"":
"s") << 
" failed";
 
  270         if ( 0 < numXFail  ) {
 
  271             cout << 
" (" << numXFail << 
" expected failure" << ( ( 1 == numXFail )?
"":
"s") << 
")";
 
  274             cout << 
"; also " << numSkip << 
" skipped";
 
  278         if ( 0 < numXPass  ) {
 
  279         cout << 
"    Unexpected pass" << ( ( 1 == numXPass )?
"":
"es") << 
":" << endl;
 
  281         for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
 
  282             cout << 
"\t" << (*itr).toLatin1().constData() << endl;
 
  285         if ( 0 < (numFail - numXFail) ) {
 
  286         cout << 
"    Unexpected failure" << ( ( 1 == numFail )?
"":
"s") << 
":" << endl;
 
  288         for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
 
  289             cout << 
"\t" << (*itr).toLatin1().constData() << endl;
 
  292         if ( 0 < numXFail ) {
 
  293         cout << 
"    Expected failure" << ( ( 1 == numXFail)?
"":
"s") << 
":" << endl;
 
  295         for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
 
  296             cout << 
"\t" << (*itr).toLatin1().constData() << endl;
 
  300             cout << 
"    Skipped test" << ( ( 1 == numSkip )?
"":
"s") << 
":" << endl;
 
  302             for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
 
  303             cout << 
"\t" << (*itr).toLatin1().constData() << endl;
 
  308         emit finished(name, test);
 
  312 #include "runner.moc" 
virtual TestResults * results() const 
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QStringList xpassList() const 
int testsFinished() const 
const TestResultsList & resultsList() const 
Return the list of results - used internally by Runner. 
QStringList skipList() const 
QStringList errorList() const 
QStringList xfailList() const 
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
virtual void allTests()=0
bool addResourceDir(const char *type, const QString &absdir, bool priority=true)