328 #include <tqobject.h>
329 #include <tqstringlist.h>
330 #include <tqasciidict.h>
332 #include <tdelibs_export.h>
339 #define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y, false )
342 #define COMPARE CHECK
345 #define VERIFY( x ) CHECK( x, true )
355 #define XFAIL( x, y ) check( __FILE__, __LINE__, #x, x, y, true )
362 #define SKIP( x ) skip( __FILE__, __LINE__, TQString::fromLatin1(#x))
371 #define CHECK_EXCEPTION(exceptionCatch, expression) \
376 catch(exceptionCatch) \
378 setExceptionRaised(true); \
380 if(exceptionRaised()) \
382 success(TQString(__FILE__) + "[" + TQString::number(__LINE__) + "]: passed " + #expression); \
386 failure(TQString(__FILE__) + "[" + TQString::number(__LINE__) + TQString("]: failed to throw " \
387 "an exception on: ") + #expression); \
389 setExceptionRaised(false);
395 #define XFAIL_EXCEPTION(exceptionCatch, expression) \
400 catch(exceptionCatch) \
402 setExceptionRaised(true); \
404 if(exceptionRaised()) \
406 unexpectedSuccess(TQString(__FILE__) + "[" + TQString::number(__LINE__) + "]: unexpectedly threw an exception and passed: " + #expression); \
410 expectedFailure(TQString(__FILE__) + "[" + TQString::number(__LINE__) + TQString("]: failed to throw an exception on: ") + #expression); \
412 setExceptionRaised(false);
419 #define SKIP_EXCEPTION(exceptionCatch, expression) \
420 skip( __FILE__, __LINE__, TQString("Exception catch: ")\
421 .arg(TQString(#exceptionCatch)).arg(TQString(" Test expression: ")).arg(TQString(#expression)))
449 m_successList.clear();
470 int errors()
const {
return m_errorList.count(); }
473 int xfails()
const {
return m_xfailList.count(); }
476 int xpasses()
const {
return m_xpassList.count(); }
479 int skipped()
const {
return m_skipList.count(); }
482 int passed()
const {
return m_successList.count(); }
494 TQStringList
skipList()
const {
return m_skipList; }
500 TQStringList m_errorList;
501 TQStringList m_xfailList;
502 TQStringList m_xpassList;
503 TQStringList m_skipList;
504 TQStringList m_successList;
509 typedef TQAsciiDict<TestResults> TestResultsListType;
522 class TDEUNITTEST_EXPORT
Tester :
public TQObject
525 Tester(
const char *name = 0L)
526 : TQObject(0L, name), m_results(
new TestResults()), m_exceptionState(
false)
529 virtual ~
Tester() {
delete m_results; }
547 void skip(
const char *file,
int line, TQString msg )
550 TQTextStream ts( &skipEntry, IO_WriteOnly );
551 ts << file <<
"["<< line <<
"]: " << msg;
552 skipTest( skipEntry );
564 void check(
const char *file,
int line,
const char *str,
565 const T &result,
const T &expectedResult,
568 cout <<
"check: " << file <<
"["<< line <<
"]" << endl;
570 if ( result != expectedResult )
573 TQTextStream ts( &error, IO_WriteOnly );
574 ts << file <<
"["<< line <<
"]: failed on \"" << str
575 <<
"\" result = '" << result <<
"' expected = '" << expectedResult <<
"'";
578 expectedFailure( error );
590 TQTextStream ts( &err, IO_WriteOnly );
591 ts << file <<
"["<< line <<
"]: "
592 <<
" unexpectedly passed on \""
594 unexpectedSuccess( err );
599 TQTextStream ts( &succ, IO_WriteOnly );
600 ts << file <<
"["<< line <<
"]: "
607 ++m_results->m_tests;
617 void success(
const TQString &message) { m_results->m_successList.append(message); }
626 void failure(
const TQString &message) { m_results->m_errorList.append(message); }
635 void expectedFailure(
const TQString &message) { m_results->m_xfailList.append(message); }
653 void skipTest(
const TQString &message) { m_results->m_skipList.append(message); }
671 return m_exceptionState;
679 bool m_exceptionState;
697 TestResultsListType &resultsList() {
return m_resultsList; }
703 void invokeMember(
const TQString &str);
705 TestResultsListType m_resultsList;
710 TDEUNITTEST_EXPORT TQTextStream& operator<<( TQTextStream& str,
const TQRect& r );
712 TDEUNITTEST_EXPORT TQTextStream& operator<<( TQTextStream& str,
const TQPoint& r );
714 TDEUNITTEST_EXPORT TQTextStream& operator<<( TQTextStream& str,
const TQSize& r );
TQStringList skipList() const
TQStringList xpassList() const
TQStringList errorList() const
virtual void addDebugInfo(const TQString &debug)
TQStringList successList() const
int testsFinished() const
TQStringList xfailList() const
TQString debugInfo() const
virtual TestResults * results()
void expectedFailure(const TQString &message)
void check(const char *file, int line, const char *str, const T &result, const T &expectedResult, bool expectedFail)
bool exceptionRaised() const
void success(const TQString &message)
void failure(const TQString &message)
void skipTest(const TQString &message)
void skip(const char *file, int line, TQString msg)
void unexpectedSuccess(const TQString &message)
void setExceptionRaised(bool state)
virtual void allTests()=0
Namespace for Unit testing classes.
TQAsciiDictIterator< TestResults > TestResultsListIteratorType