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 QTextStreamoperator<< (QTextStream &str, const QRect &r)
KUNITTEST_EXPORT QTextStreamoperator<< (QTextStream &str, const QPoint &r)
KUNITTEST_EXPORT QTextStreamoperator<< (QTextStream &str, const QSize &r)

Define Documentation

#define CHECK ( x,
 )     check( __FILE__, __LINE__, #x, x, y, false )

Use this macro to perform an equality check. For example

 CHECK( numberOfErrors(), 0 ); 

Definition at line 339 of file tester.h.

#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);
A macro testing that 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.

Definition at line 371 of file tester.h.

#define COMPARE   CHECK

for source-compat with qttestlib: use COMPARE(x,y) if you plan to port to qttestlib later.

Definition at line 342 of file tester.h.

#define SKIP (  )     skip( __FILE__, __LINE__, QString::fromLatin1(#x))

Use this macro to indicate that a test is skipped.

 SKIP("Test skipped because of lack of foo support."); 

Definition at line 362 of file tester.h.

#define SKIP_EXCEPTION ( exceptionCatch,
expression   ) 

Value:

skip( __FILE__, __LINE__, QString("Exception catch: ")\
            .arg(QString(#exceptionCatch)).arg(QString(" Test expression: ")).arg(QString(#expression)))
This macro is similar to SKIP, but is for exceptions instead. Skip testing expression and the exceptionCatch which is supposed to catch the exception, and register the test as being skipped.

Definition at line 419 of file tester.h.

#define VERIFY (  )     CHECK( x, true )

for source-compat with qttestlib: use VERIFY(x) if you plan to port to qttestlib later.

Definition at line 345 of file tester.h.

#define XFAIL ( x,
 )     check( __FILE__, __LINE__, #x, x, y, true )

Use this macro to perform a check you expect to fail. For example

 XFAIL( numberOfErrors(), 1 ); 

If the test fails, it will be counted as such, however it will also be registered separately.

Definition at line 355 of file tester.h.

#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);
This macro is similar to XFAIL, but is for exceptions instead. Flags expression as being expected to fail to throw an exception that exceptionCatch is supposed to catch.

Definition at line 395 of file tester.h.

KDE Home | KDE Accessibility Home | Description of Access Keys