KUnitTest
Go to the documentation of this file.
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(
"");
451 virtual void addDebugInfo(
const QString &debug)
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(); }
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); }
665 bool exceptionRaised()
const
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 );
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jun 1 2013 22:10:09 by
doxygen 1.8.3.1 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.