34 #include <tqmetaobject.h>
37 #include <klibloader.h>
38 #include <tdeglobal.h>
39 #include <kstandarddirs.h>
46 Runner *Runner::s_self = 0L;
47 bool Runner::s_debugCapturingEnabled =
false;
49 void Runner::registerTester(
const char *name,
Tester *test)
51 Runner::self()->m_registry.insert(name, test);
54 void Runner::loadModules(
const TQString &folder,
const TQString &query)
56 TQRegExp reQuery(query);
57 TQDir dir(folder,
"tdeunittest_*.la");
61 TDEGlobal::dirs()->addResourceDir(
"module", folder);
62 kdDebug() <<
"Looking in folder: " << dir.absPath() << endl;
65 TQStringList modules = dir.entryList();
67 for ( uint i = 0; i < modules.count(); ++i )
69 TQString module = modules[i];
70 kdDebug() <<
"Module: " << dir.absPath() +
"/" + module << endl;
72 if ( reQuery.search(module) != -1 )
75 module.truncate(module.length()-3);
76 KLibFactory *factory = KLibLoader::self()->factory(module.local8Bit());
80 kdWarning() <<
"\tError loading " << module <<
" : " << KLibLoader::self()->lastErrorMessage() << endl;
85 kdDebug() <<
"\tModule doesn't match." << endl;
89 void Runner::setDebugCapturingEnabled(
bool enabled)
91 s_debugCapturingEnabled = enabled;
99 int Runner::numberOfTestCases()
101 return m_registry.count();
106 if ( s_self == 0L ) s_self =
new Runner();
116 int Runner::numberOfTests()
const
121 int Runner::numberOfPassedTests()
const
126 int Runner::numberOfFailedTests()
const
131 int Runner::numberOfExpectedFailures()
const
136 int Runner::numberOfSkippedTests()
const
138 return globalSkipped;
151 int Runner::runTests()
160 cout <<
"# Running normal tests... #" << endl << endl;
163 for( ; it.current(); ++it )
164 runTest(it.currentKey());
167 cout <<
"# Done with normal tests:" << endl;
168 cout <<
" Total test cases: " << m_registry.count() << endl;
169 cout <<
" Total test steps : " << globalSteps << endl;
170 cout <<
" Total passed test steps (including unexpected) : " << globalPasses << endl;
171 cout <<
" Total unexpected passed test steps : " << globalXPasses << endl;
172 cout <<
" Total failed test steps (including expected) : " << globalFails << endl;
173 cout <<
" Total expected failed test steps : " << globalXFails << endl;
174 cout <<
" Total skipped test steps : " << globalSkipped << endl;
176 unsigned int numTests = m_registry.count();
178 if ( globalFails == 0 )
179 if ( globalXFails == 0 )
180 str = TQString(
"All %1 tests passed" ).arg( numTests );
182 str = TQString(
"All %1 tests behaved as expected (%2 expected failures)" ).arg( numTests ).arg( globalXFails );
184 if ( globalXPasses == 0 )
185 str = TQString(
"%1 of %2 tests failed" ).arg( globalFails ).arg( numTests );
187 str = TQString(
"%1 of %2 tests did not behave as expected (%1 unexpected passes)" ).arg( globalFails ).arg( numTests ).arg( globalXPasses );
189 str += TQString(
" (%1 tests skipped)" ).arg( globalSkipped );
190 cout << str.local8Bit().data() << endl;
193 return m_registry.count();
196 void Runner::runMatchingTests(
const TQString &prefix)
199 for( ; it.current(); ++it )
200 if ( TQString(it.currentKey()).startsWith(prefix) )
201 runTest(it.currentKey());
204 void Runner::runTest(
const char *name)
206 Tester *test = m_registry.find(name);
207 if ( test == 0L )
return;
209 if ( s_debugCapturingEnabled )
211 cout <<
"KUnitTest_Debug_Start[" << name <<
"]" << endl;
217 if ( s_debugCapturingEnabled )
219 cout <<
"KUnitTest_Debug_End[" << name <<
"]" << endl << endl << flush;
227 TQStringList xpassList;
228 TQStringList errorList;
229 TQStringList xfailList;
230 TQStringList skipList;
232 if ( test->inherits(
"KUnitTest::SlotTester") )
236 for ( ; it.current(); ++it)
238 numPass += it.current()->passed() + it.current()->xpasses();
239 numFail += it.current()->errors() + it.current()->xfails();
240 numXFail += it.current()->xfails();
241 numXPass += it.current()->xpasses();
242 numSkip += it.current()->skipped();
243 globalSteps += it.current()->testsFinished();
245 xpassList += it.current()->xpassList();
246 errorList += it.current()->errorList();
247 xfailList += it.current()->xfailList();
248 skipList += it.current()->skipList();
267 globalPasses += numPass;
268 globalFails += numFail;
269 globalXFails += numXFail;
270 globalXPasses += numXPass;
271 globalSkipped += numSkip;
273 cout << name <<
" - ";
274 cout << numPass <<
" test" << ( ( 1 == numPass )?
"":
"s") <<
" passed";
275 if ( 0 < xpassList.count() ) {
276 cout <<
" (" << numXPass <<
" unexpected pass" << ( ( 1 == numXPass )?
"":
"es") <<
")";
278 cout <<
", " << numFail <<
" test" << ( ( 1 == numFail )?
"":
"s") <<
" failed";
279 if ( 0 < numXFail ) {
280 cout <<
" (" << numXFail <<
" expected failure" << ( ( 1 == numXFail )?
"":
"s") <<
")";
283 cout <<
"; also " << numSkip <<
" skipped";
287 if ( 0 < numXPass ) {
288 cout <<
" Unexpected pass" << ( ( 1 == numXPass )?
"":
"es") <<
":" << endl;
289 TQStringList list = xpassList;
290 for ( TQStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
291 cout <<
"\t" << (*itr).latin1() << endl;
294 if ( 0 < (numFail - numXFail) ) {
295 cout <<
" Unexpected failure" << ( ( 1 == numFail )?
"":
"s") <<
":" << endl;
296 TQStringList list = errorList;
297 for ( TQStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
298 cout <<
"\t" << (*itr).latin1() << endl;
301 if ( 0 < numXFail ) {
302 cout <<
" Expected failure" << ( ( 1 == numXFail)?
"":
"s") <<
":" << endl;
303 TQStringList list = xfailList;
304 for ( TQStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
305 cout <<
"\t" << (*itr).latin1() << endl;
309 cout <<
" Skipped test" << ( ( 1 == numSkip )?
"":
"s") <<
":" << endl;
310 TQStringList list = skipList;
311 for ( TQStringList::Iterator itr = list.begin(); itr != list.end(); ++itr ) {
312 cout <<
"\t" << (*itr).latin1() << endl;
317 emit finished(name, test);
321 #include "runner.moc"
TQStringList skipList() const
TQStringList xpassList() const
TQStringList errorList() const
int testsFinished() const
TQStringList xfailList() const
virtual TestResults * results()
virtual void allTests()=0
Namespace for Unit testing classes.
TQAsciiDict< Tester > RegistryType
TQAsciiDictIterator< TestResults > TestResultsListIteratorType
TQAsciiDictIterator< Tester > RegistryIteratorType