KDAB::UnitTest::Test Class Reference

#include <test.h>

Collaboration diagram for KDAB::UnitTest::Test:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 61 of file test.h.


Public Member Functions

unsigned int failed () const
const std::string & name () const
virtual void run ()=0
unsigned int succeeded () const
 Test (const std::string &name)
virtual ~Test ()

Protected Member Functions

template<typename T, typename S>
void _assertEqual (const T &x1, const S &x2, const char *expr1, const char *expr2, const char *file, unsigned int line)
void _assertEqualWithEpsilons (long double x1, long double x2, int prec, const char *expr1, const char *expr2, const char *exprPrec, const char *file, unsigned int line)
void _assertEqualWithEpsilons (double x1, double x2, int prec, const char *expr1, const char *expr2, const char *exprPrec, const char *file, unsigned int line)
void _assertEqualWithEpsilons (float x1, float x2, int prec, const char *expr1, const char *expr2, const char *exprPrec, const char *file, unsigned int line)
void _assertFalse (bool x, const char *expression, const char *file, unsigned int line)
template<typename T, typename S>
void _assertNotEqual (const T &x1, const S &x2, const char *expr1, const char *expr2, const char *file, unsigned int line)
void _assertNotNull (const void *x, const char *expression, const char *file, unsigned int line)
void _assertNull (const void *x, const char *expression, const char *file, unsigned int line)
void _assertTrue (bool x, const char *expression, const char *file, unsigned int line)
std::ostream & fail (const char *file, unsigned int line)
void success ()

Constructor & Destructor Documentation

KDAB::UnitTest::Test::Test ( const std::string &  name  ) 

Definition at line 12 of file test.cpp.

00013     : mName( n ), mFailed( 0 ), mSucceeded( 0 ) {}

virtual KDAB::UnitTest::Test::~Test (  )  [virtual]

Definition at line 66 of file test.h.

00066 {}


Member Function Documentation

template<typename T, typename S>
void KDAB::UnitTest::Test::_assertEqual ( const T &  x1,
const S &  x2,
const char *  expr1,
const char *  expr2,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 89 of file test.h.

References fail(), and success().

00089                                                                                                                                   {
00090       if ( x1 == x2 ) this->success();
00091       else {
00092           this->fail( file, line ) << '"' << expr1 << "\" yielded " << x1 << "; expected: " << x2 << "(\"" << expr2 << "\")" << std::endl;
00093       }
00094     }

void KDAB::UnitTest::Test::_assertEqualWithEpsilons ( long double  x1,
long double  x2,
int  prec,
const char *  expr1,
const char *  expr2,
const char *  exprPrec,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 61 of file test.cpp.

References fail(), and success().

00061                                                                                                                                                                                             {
00062     if ( qAbs( x1/x2 - 1.0l ) <= prec * std::numeric_limits<long double>::epsilon() ) success();
00063     else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
00064                             << x2 << " (" << expr2 << ") by more than "
00065                             << prec << " (" << exprP << ") epsilons." << std::endl;
00066 }

void KDAB::UnitTest::Test::_assertEqualWithEpsilons ( double  x1,
double  x2,
int  prec,
const char *  expr1,
const char *  expr2,
const char *  exprPrec,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 54 of file test.cpp.

References fail(), and success().

00054                                                                                                                                                                                   {
00055     if ( qAbs( x1/x2 - 1.0 ) <= prec * std::numeric_limits<double>::epsilon() ) success();
00056     else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
00057                             << x2 << " (" << expr2 << ") by more than "
00058                             << prec << " (" << exprP << ") epsilons." << std::endl;
00059 }

void KDAB::UnitTest::Test::_assertEqualWithEpsilons ( float  x1,
float  x2,
int  prec,
const char *  expr1,
const char *  expr2,
const char *  exprPrec,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 47 of file test.cpp.

References fail(), and success().

00047                                                                                                                                                                                 {
00048     if ( qAbs( x1/x2 - 1.0f ) <= prec * std::numeric_limits<float>::epsilon() ) success();
00049     else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
00050                             << x2 << " (" << expr2 << ") by more than "
00051                             << prec << " (" << exprP << ") epsilons." << std::endl;
00052 }

void KDAB::UnitTest::Test::_assertFalse ( bool  x,
const char *  expression,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 42 of file test.cpp.

References fail(), and success().

00042                                                                                                            {
00043     if ( !x ) success();
00044     else fail( file, line ) << '"' << expression << "\" != FALSE" << std::endl;
00045 }

template<typename T, typename S>
void KDAB::UnitTest::Test::_assertNotEqual ( const T &  x1,
const S &  x2,
const char *  expr1,
const char *  expr2,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 96 of file test.h.

References fail(), and success().

00096                                                                                                                                      {
00097       if ( x1 != x2 ) this->success();
00098       else {
00099           this->fail( file, line ) << '"' << expr1 << "\" yielded " << x1 << "; expected something not equal to: " << x2 << "(\"" << expr2 << "\")" << std::endl;
00100       }
00101     }

void KDAB::UnitTest::Test::_assertNotNull ( const void *  x,
const char *  expression,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 15 of file test.cpp.

References fail(), and success().

00015                                                                                                                      {
00016     if ( x ) success();
00017     else fail( file, line ) << '"' << expression << "\" is NULL, expected non-NULL" << std::endl;
00018 }

void KDAB::UnitTest::Test::_assertNull ( const void *  x,
const char *  expression,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 20 of file test.cpp.

References fail(), and success().

00020                                                                                                                   {
00021     if ( !x ) success();
00022     else fail( file, line ) << '"' << expression << "\" is not NULL, expected NULL" << std::endl;
00023 }

void KDAB::UnitTest::Test::_assertTrue ( bool  x,
const char *  expression,
const char *  file,
unsigned int  line 
) [protected]

Definition at line 37 of file test.cpp.

References fail(), and success().

00037                                                                                                           {
00038     if ( x ) success();
00039     else fail( file, line ) << '"' << expression << "\" != TRUE" << std::endl;
00040 }

std::ostream & KDAB::UnitTest::Test::fail ( const char *  file,
unsigned int  line 
) [protected]

Definition at line 68 of file test.cpp.

Referenced by _assertEqual(), _assertEqualWithEpsilons(), _assertFalse(), _assertNotEqual(), _assertNotNull(), _assertNull(), and _assertTrue().

00068                                                                           {
00069     ++mFailed;
00070     return std::cerr << "FAIL: " << file << ':' << line << ": ";
00071 }

unsigned int KDAB::UnitTest::Test::failed (  )  const

Definition at line 69 of file test.h.

00069 { return mFailed; }

const std::string& KDAB::UnitTest::Test::name (  )  const

Definition at line 68 of file test.h.

00068 { return mName; }

virtual void KDAB::UnitTest::Test::run (  )  [pure virtual]

unsigned int KDAB::UnitTest::Test::succeeded (  )  const

Definition at line 70 of file test.h.

00070 { return mSucceeded; }

void KDAB::UnitTest::Test::success (  )  [protected]

Definition at line 105 of file test.h.

Referenced by _assertEqual(), _assertEqualWithEpsilons(), _assertFalse(), _assertNotEqual(), _assertNotNull(), _assertNull(), and _assertTrue().

00105                    {
00106       ++mSucceeded;
00107     }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:25:15 2010 for KD Chart 2 by  doxygen 1.5.4