34#include <QtCore/QRegExp>
36#include <QtCore/QMetaEnum>
48 Runner *Runner::s_self = 0L;
49 bool Runner::s_debugCapturingEnabled =
false;
58 QRegExp reQuery(query);
59 QDir dir(folder,
"kunittest_*.la");
64 kDebug() <<
"Looking in folder: " << dir.absolutePath();
67 QStringList modules = dir.entryList();
69 for (
int i = 0; i < modules.count(); ++i )
71 QString module = modules[i];
72 kDebug() <<
"Module: " << dir.absolutePath() +
'/' +
module;
74 if ( reQuery.indexIn(module) != -1 )
77 module.truncate(module.length()-3);
78 KPluginLoader loader(module.toLocal8Bit());
79 KPluginFactory *factory = loader.factory();
81 factory->
create<QObject>();
83 kWarning() <<
"\tError loading " <<
module << " : " << loader.errorString();
88 kDebug() <<
"\tModule doesn't match.";
94 s_debugCapturingEnabled = enabled;
105 return m_registry.count();
111 s_self =
new Runner();
144 return globalSkipped;
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( ) );
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();
204 Registry::const_iterator it = m_registry.constBegin();
205 for( ; it != m_registry.constEnd(); ++it )
206 if ( QString( it.key() ).startsWith(prefix) )
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") )
239 numPass += res->passed() + res->xpasses();
240 numFail += res->errors() + res->xfails();
241 numXFail += res->xfails();
242 numXPass += res->xpasses();
243 numSkip += res->skipped();
244 globalSteps += res->testsFinished();
249 numPass= test->results()->passed() + test->results()->xpasses();
250 numFail= test->results()->errors() + test->results()->xfails();
251 numXFail = test->results()->xfails();
252 numXPass = test->results()->xpasses();
253 numSkip= test->results()->skipped();
254 globalSteps += test->results()->testsFinished();
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";
266 if ( 0 < test->results()->xpassList().count() ) {
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;
280 QStringList list = test->results()->xpassList();
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;
287 QStringList list = test->results()->errorList();
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;
294 QStringList list = test->results()->xfailList();
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;
301 QStringList list = test->results()->skipList();
302 for ( QStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
303 cout <<
"\t" << (*itr).toLatin1().constData() << endl;
308 emit finished(name, test);
T * create(const QString &keyword, QObject *parent=0, const QVariantList &args=QVariantList())
bool addResourceDir(const char *type, const QString &absdir, bool priority=true)
virtual TestResults * results() const
int numberOfFailedTests() const
int numberOfPassedTests() const
static void registerTester(const char *name, Tester *test)
int numberOfSkippedTests() const
int numberOfTests() const
static void setDebugCapturingEnabled(bool enabled)
static void loadModules(const QString &folder, const QString &query)
int numberOfExpectedFailures() const
void runTest(const char *name)
void runMatchingTests(const QString &prefix)
QHash< QByteArray, Tester * > Registry