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) );
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);
712KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QRect& r );
715KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QPoint& r );
718KUNITTEST_EXPORT QTextStream&
operator<<( QTextStream& str,
const QSize& r );
virtual TestResults * results() const
const TestResultsList & resultsList() const
Return the list of results - used internally by Runner.
QStringList skipList() const
QStringList successList() const
QStringList xfailList() const
virtual void addDebugInfo(const QString &debug)
QStringList errorList() const
QString debugInfo() const
QStringList xpassList() const
int testsFinished() const
void check(const char *file, int line, const char *str, const T &result, const T &expectedResult, bool expectedFail)
Tester(const char *name=0L)
virtual TestResults * results() const
void expectedFailure(const QString &message)
bool exceptionRaised() const
void success(const QString &message)
void skipTest(const QString &message)
void failure(const QString &message)
void setExceptionRaised(bool state)
void unexpectedSuccess(const QString &message)
void skip(const char *file, int line, QString msg)
virtual void allTests()=0
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
Copyright (C) 2005 Jeroen Wijnhout Jeroen.Wijnhout@kdemail.net
QHash< QByteArray, TestResults * > TestResultsList
QTextStream & operator<<(QTextStream &str, const QRect &r)