323 #include <QtCore/QObject> 324 #include <QtCore/QStringList> 325 #include <QtCore/QHash> 326 #include <QtCore/QTextStream> 335 #define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y, false ) 342 #define VERIFY( cond ) check( __FILE__, __LINE__, #cond, cond, true, false ) 352 #define XFAIL( x, y ) check( __FILE__, __LINE__, #x, x, y, true ) 359 #define SKIP( x ) skip( __FILE__, __LINE__, QLatin1String(#x)) 368 #define CHECK_EXCEPTION(exceptionCatch, expression) \ 373 catch(exceptionCatch) \ 375 setExceptionRaised(true); \ 377 if(exceptionRaised()) \ 379 success(QString(__FILE__) + "[" + QString::number(__LINE__) + "]: passed " + #expression); \ 383 failure(QString(__FILE__) + "[" + QString::number(__LINE__) + QString("]: failed to throw " \ 384 "an exception on: ") + #expression); \ 386 setExceptionRaised(false); 392 #define XFAIL_EXCEPTION(exceptionCatch, expression) \ 397 catch(exceptionCatch) \ 399 setExceptionRaised(true); \ 401 if(exceptionRaised()) \ 403 unexpectedSuccess(QString(__FILE__) + "[" + QString::number(__LINE__) + "]: unexpectedly threw an exception and passed: " + #expression); \ 407 expectedFailure(QString(__FILE__) + "[" + QString::number(__LINE__) + QString("]: failed to throw an exception on: ") + #expression); \ 409 setExceptionRaised(false); 416 #define SKIP_EXCEPTION(exceptionCatch, expression) \ 417 skip( __FILE__, __LINE__, QString("Exception catch: ")\ 418 .arg(QString(#exceptionCatch)).arg(QString(" Test expression: ")).arg(QString(#expression))) 443 m_successList.clear();
444 m_debug = QLatin1String(
"");
464 int errors()
const {
return m_errorList.count(); }
467 int xfails()
const {
return m_xfailList.count(); }
470 int xpasses()
const {
return m_xpassList.count(); }
473 int skipped()
const {
return m_skipList.count(); }
476 int passed()
const {
return m_successList.count(); }
488 QStringList
skipList()
const {
return m_skipList; }
494 QStringList m_errorList;
495 QStringList m_xfailList;
496 QStringList m_xpassList;
497 QStringList m_skipList;
498 QStringList m_successList;
522 setObjectName( QLatin1String(name) );
530 virtual void allTests() = 0;
543 void skip(
const char *file,
int line, QString msg )
546 QTextStream ts( &skipEntry, QIODevice::WriteOnly );
547 ts << file <<
"["<< line <<
"]: " << msg;
548 skipTest( skipEntry );
560 void check(
const char *file,
int line,
const char *str,
561 const T &result,
const T &expectedResult,
564 cout <<
"check: " << file <<
"["<< line <<
"]" << endl;
566 if ( result != expectedResult )
569 QTextStream ts( &error, QIODevice::WriteOnly );
570 ts << file <<
"["<< line <<
"]: failed on \"" << str
571 <<
"\" result = '" << result <<
"' expected = '" << expectedResult <<
"'";
574 expectedFailure( error );
586 QTextStream ts( &err, QIODevice::WriteOnly );
587 ts << file <<
"["<< line <<
"]: " 588 <<
" unexpectedly passed on \"" 590 unexpectedSuccess( err );
595 QTextStream ts( &succ, QIODevice::WriteOnly );
596 ts << file <<
"["<< line <<
"]: " 603 ++m_results->m_tests;
613 void success(
const QString &message) { m_results->m_successList.append(
message); }
667 return m_exceptionState;
675 bool m_exceptionState;
704 void invokeMember(
const QString &str);
712 KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QRect& r );
715 KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QPoint& r );
718 KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QSize& r );
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
QHash< QByteArray, TestResults * > TestResultsList
void setExceptionRaised(bool state)
void success(const QString &message)
Copyright (C) 2004 Zack Rusin zack@kde.org Copyright (C) 2005 Jeroen Wijnhout Jeroen.Wijnhout@kdemail.net
virtual TestResults * results() const
void check(const char *file, int line, const char *str, const T &result, const T &expectedResult, bool expectedFail)
int testsFinished() const
Copyright (C) 2005 Jeroen Wijnhout Jeroen.Wijnhout@kdemail.net
const TestResultsList & resultsList() const
Return the list of results - used internally by Runner.
void failure(const QString &message)
virtual void addDebugInfo(const QString &debug)
QStringList errorList() const
QStringList xfailList() const
QStringList successList() const
QStringList skipList() const
void skip(const char *file, int line, QString msg)
Tester(const char *name=0L)
void unexpectedSuccess(const QString &message)
QTextStream & operator<<(QTextStream &str, const QRect &r)
QString debugInfo() const
bool exceptionRaised() const
void expectedFailure(const QString &message)
void skipTest(const QString &message)
QStringList xpassList() const
virtual TestResults * results() const