tester.h File Reference
Detailed Description
Defines macros for unit testing as well as some test classes.Definition in file tester.h.
#include <iostream>
#include <qobject.h>
#include <qstringlist.h>
#include <qasciidict.h>
#include <kdelibs_export.h>
Go to the source code of this file.
Namespaces | |
namespace | KUnitTest |
Classes | |
class | KUnitTest::TestResults |
class | KUnitTest::Tester |
class | KUnitTest::SlotTester |
Defines | |
#define | CHECK(x, y) check( __FILE__, __LINE__, #x, x, y, false ) |
#define | COMPARE CHECK |
#define | VERIFY(x) CHECK( x, true ) |
#define | XFAIL(x, y) check( __FILE__, __LINE__, #x, x, y, true ) |
#define | SKIP(x) skip( __FILE__, __LINE__, QString::fromLatin1(#x)) |
#define | CHECK_EXCEPTION(exceptionCatch, expression) |
#define | XFAIL_EXCEPTION(exceptionCatch, expression) |
#define | SKIP_EXCEPTION(exceptionCatch, expression) |
Typedefs | |
typedef QAsciiDict< TestResults > | KUnitTest::TestResultsListType |
typedef QAsciiDictIterator< TestResults > | KUnitTest::TestResultsListIteratorType |
Functions | |
KUNITTEST_EXPORT QTextStream & | operator<< (QTextStream &str, const QRect &r) |
KUNITTEST_EXPORT QTextStream & | operator<< (QTextStream &str, const QPoint &r) |
KUNITTEST_EXPORT QTextStream & | operator<< (QTextStream &str, const QSize &r) |
Define Documentation
#define CHECK | ( | x, | |||
y | ) | check( __FILE__, __LINE__, #x, x, y, false ) |
#define CHECK_EXCEPTION | ( | exceptionCatch, | |||
expression | ) |
Value:
try \ { \ expression; \ } \ catch(exceptionCatch) \ { \ setExceptionRaised(true); \ } \ if(exceptionRaised()) \ { \ success(QString(__FILE__) + "[" + QString::number(__LINE__) + "]: passed " + #expression); \ } \ else \ { \ failure(QString(__FILE__) + "[" + QString::number(__LINE__) + QString("]: failed to throw " \ "an exception on: ") + #expression); \ } \ setExceptionRaised(false);
expression
throws an exception that is catched with exceptionCatch
. Use it to test that an expression, such as a function call, throws a certain exception.
- Note:
- this macro assumes it's used in a function which is a sub-class of the Tester class.
#define COMPARE CHECK |
for source-compat with qttestlib: use COMPARE(x,y) if you plan to port to qttestlib later.
#define SKIP | ( | x | ) | skip( __FILE__, __LINE__, QString::fromLatin1(#x)) |
#define SKIP_EXCEPTION | ( | exceptionCatch, | |||
expression | ) |
Value:
skip( __FILE__, __LINE__, QString("Exception catch: ")\ .arg(QString(#exceptionCatch)).arg(QString(" Test expression: ")).arg(QString(#expression)))
expression
and the exceptionCatch
which is supposed to catch the exception, and register the test as being skipped.
#define VERIFY | ( | x | ) | CHECK( x, true ) |
#define XFAIL | ( | x, | |||
y | ) | check( __FILE__, __LINE__, #x, x, y, true ) |
#define XFAIL_EXCEPTION | ( | exceptionCatch, | |||
expression | ) |
Value:
try \ { \ expression; \ } \ catch(exceptionCatch) \ { \ setExceptionRaised(true); \ } \ if(exceptionRaised()) \ { \ unexpectedSuccess(QString(__FILE__) + "[" + QString::number(__LINE__) + "]: unexpectedly threw an exception and passed: " + #expression); \ }\ else \ { \ expectedFailure(QString(__FILE__) + "[" + QString::number(__LINE__) + QString("]: failed to throw an exception on: ") + #expression); \ } \ setExceptionRaised(false);
expression
as being expected to fail to throw an exception that exceptionCatch
is supposed to catch.