Loading...
Searching...
No Matches
CxxTest::ErrorFormatter Class Reference

`#include <ErrorFormatter.h>`

## Public Member Functions

| ErrorFormatter (OutputStream *o, const char *preLine=":", const char *postLine="")
int | run ()
void | enterWorld (const WorldDescription &)
void | enterSuite (const SuiteDescription &)
void | enterTest (const TestDescription &)
void | leaveTest (const TestDescription &)
void | leaveWorld (const WorldDescription &desc)
void | trace (const char *file, unsigned line, const char *expression)
void | warning (const char *file, unsigned line, const char *expression)
void | failedTest (const char *file, unsigned line, const char *expression)
void | failedAssert (const char *file, unsigned line, const char *expression)
void | failedAssertEquals (const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
void | failedAssertSameData (const char *file, unsigned line, const char *xStr, const char *yStr, const char *sizeStr, const void *x, const void *y, unsigned size)
void | failedAssertDelta (const char *file, unsigned line, const char *xStr, const char *yStr, const char *dStr, const char *x, const char *y, const char *d)
void | failedAssertDiffers (const char *file, unsigned line, const char *xStr, const char *yStr, const char *value)
void | failedAssertLessThan (const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
void | failedAssertLessThanEquals (const char *file, unsigned line, const char *xStr, const char *yStr, const char *x, const char *y)
void | failedAssertRelation (const char *file, unsigned line, const char *relation, const char *xStr, const char *yStr, const char *x, const char *y)
void | failedAssertPredicate (const char *file, unsigned line, const char *predicate, const char *xStr, const char *x)
void | failedAssertThrows (const char *file, unsigned line, const char *expression, const char *type, bool otherThrown)
void | failedAssertThrowsNot (const char *file, unsigned line, const char *expression)
Public Member Functions inherited from CxxTest::TestListener
| TestListener ()
virtual | ~TestListener ()
virtual void | leaveSuite (const SuiteDescription &)

## Static Public Member Functions

static void | totalTests (OutputStream &o)

## Protected Member Functions

OutputStream * | outputStream () const

## Private Member Functions

| ErrorFormatter (const ErrorFormatter &)
ErrorFormatter & | operator= (const ErrorFormatter &)
OutputStream & | stop (const char *file, unsigned line)
void | newLine (void)
void | reportTest (void)
void | dump (const void *buffer, unsigned size)
void | dumpNull ()
void | dumpBuffer (const void *buffer, unsigned size)

## Static Private Member Functions

static void | endl (OutputStream &o)

## Private Attributes

bool | _dotting
bool | _reported
OutputStream * | _o
const char * | _preLine
const char * | _postLine

## Detailed Description

Definition at line 33 of file ErrorFormatter.h.

## Constructor & Destructor Documentation

## ErrorFormatter() [1/2]

CxxTest::ErrorFormatter::ErrorFormatter | ( | OutputStream * | o,
|  | const char * | preLine = ":",
|  | const char * | postLine = "" )

inline

Definition at line 36 of file ErrorFormatter.h.

:", const char *postLine = "" ) :
_dotting( true ),
_reported( false ),
_o(o),
_preLine(preLine),
_postLine(postLine)
{
}

## ErrorFormatter() [2/2]

CxxTest::ErrorFormatter::ErrorFormatter | ( | const ErrorFormatter & |  | ) |

private

## Member Function Documentation

## dump()

void CxxTest::ErrorFormatter::dump | ( | const void * | buffer,
|  | unsigned | size )

inline private

Definition at line 240 of file ErrorFormatter.h.

{
if ( !buffer )
dumpNull();
else
dumpBuffer( buffer, size );
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
CxxTest::ErrorFormatter::dumpNull
void dumpNull()
Definition ErrorFormatter.h:248
CxxTest::ErrorFormatter::dumpBuffer
void dumpBuffer(const void *buffer, unsigned size)
Definition ErrorFormatter.h:253

## dumpBuffer()

void CxxTest::ErrorFormatter::dumpBuffer | ( | const void * | buffer,
|  | unsigned | size )

inline private

Definition at line 253 of file ErrorFormatter.h.

{
unsigned dumpSize = size;
if ( maxDumpSize() && dumpSize > maxDumpSize() )
dumpSize = maxDumpSize();
const unsigned char *p = (const unsigned char *)buffer;
(*_o) << " { ";
for ( unsigned i = 0; i < dumpSize; ++ i )
(*_o) << byteToHex( *p++ ) << " ";
if ( dumpSize < size )
(*_o) << "... ";
(*_o) << "}" << endl;
}
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
CxxTest::ErrorFormatter::_o
OutputStream * _o
Definition ErrorFormatter.h:275
CxxTest::ErrorFormatter::endl
static void endl(OutputStream &o)
Definition ErrorFormatter.h:268
CxxTest::maxDumpSize
unsigned maxDumpSize()
Definition TestSuite.cpp:43
CxxTest::byteToHex
const char * byteToHex(unsigned char byte)
Definition ValueTraits.cpp:21

## dumpNull()

void CxxTest::ErrorFormatter::dumpNull | ( |  | ) |

inline private

Definition at line 248 of file ErrorFormatter.h.

{
(*_o) << " (null)" << endl;
}

## endl()

void CxxTest::ErrorFormatter::endl | ( | OutputStream & | o | ) |

inline static private

Definition at line 268 of file ErrorFormatter.h.

{
OutputStream::endl( o );
}
CxxTest::OutputStream::endl
static void endl(OutputStream &o)
Definition ErrorFormatter.h:30

## enterSuite()

void CxxTest::ErrorFormatter::enterSuite | ( | const SuiteDescription & |  | ) |

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 66 of file ErrorFormatter.h.

{
_reported = false;
}
CxxTest::ErrorFormatter::_reported
bool _reported
Definition ErrorFormatter.h:274

## enterTest()

void CxxTest::ErrorFormatter::enterTest | ( | const TestDescription & |  | ) |

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 71 of file ErrorFormatter.h.

{
_reported = false;
}

## enterWorld()

void CxxTest::ErrorFormatter::enterWorld | ( | const WorldDescription & |  | ) |

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 51 of file ErrorFormatter.h.

{
(*_o) << "Running " << totalTests;
_o->flush();
_dotting = true;
_reported = false;
}
CxxTest::ErrorFormatter::totalTests
static void totalTests(OutputStream &o)
Definition ErrorFormatter.h:59
CxxTest::ErrorFormatter::_dotting
bool _dotting
Definition ErrorFormatter.h:273

## failedAssert()

void CxxTest::ErrorFormatter::failedAssert | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 114 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Assertion failed: " <<
expression << endl;
}
CxxTest::ErrorFormatter::stop
OutputStream & stop(const char *file, unsigned line)
Definition ErrorFormatter.h:217

## failedAssertDelta()

void CxxTest::ErrorFormatter::failedAssertDelta | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | dStr,
|  | const char * | x,
|  | const char * | y,
|  | const char * | d )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 141 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" <<
xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" <<
x << " != " << y << ")" << endl;
}
x
Variable x
Definition cfModGcd.cc:4090
y
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53

## failedAssertDiffers()

void CxxTest::ErrorFormatter::failedAssertDiffers | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | value )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 150 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" <<
xStr << " != " << yStr << "), found (" <<
value << ")" << endl;
}

## failedAssertEquals()

void CxxTest::ErrorFormatter::failedAssertEquals | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | x,
|  | const char * | y )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 120 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" <<
xStr << " == " << yStr << "), found (" <<
x << " != " << y << ")" << endl;
}

## failedAssertLessThan()

void CxxTest::ErrorFormatter::failedAssertLessThan | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | x,
|  | const char * | y )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 159 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" <<
xStr << " < " << yStr << "), found (" <<
x << " >= " << y << ")" << endl;
}

## failedAssertLessThanEquals()

void CxxTest::ErrorFormatter::failedAssertLessThanEquals | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | x,
|  | const char * | y )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 168 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" <<
xStr << " <= " << yStr << "), found (" <<
x << " > " << y << ")" << endl;
}

## failedAssertPredicate()

void CxxTest::ErrorFormatter::failedAssertPredicate | ( | const char * | file,
|  | unsigned | line,
|  | const char * | predicate,
|  | const char * | xStr,
|  | const char * | x )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 185 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected " << predicate << "( " <<
xStr << " ), found !" << predicate << "( " << x << " )" << endl;
}

## failedAssertRelation()

void CxxTest::ErrorFormatter::failedAssertRelation | ( | const char * | file,
|  | unsigned | line,
|  | const char * | relation,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | x,
|  | const char * | y )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 177 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected " << relation << "( " <<
xStr << ", " << yStr << " ), found !" << relation << "( " << x << ", " << y << " )" << endl;
}

## failedAssertSameData()

void CxxTest::ErrorFormatter::failedAssertSameData | ( | const char * | file,
|  | unsigned | line,
|  | const char * | xStr,
|  | const char * | yStr,
|  | const char * | sizeStr,
|  | const void * | x,
|  | const void * | y,
|  | unsigned | size )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 129 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected " << sizeStr << " (" << size << ") bytes to be equal at (" <<
xStr << ") and (" << yStr << "), found:" << endl;
dump( x, size );
(*_o) << " differs from" << endl;
dump( y, size );
}
CxxTest::ErrorFormatter::dump
void dump(const void *buffer, unsigned size)
Definition ErrorFormatter.h:240

## failedAssertThrows()

void CxxTest::ErrorFormatter::failedAssertThrows | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression,
|  | const char * | type,
|  | bool | otherThrown )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 192 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" << expression << ") to throw (" <<
type << ") but it " << (otherThrown ? "threw something else" : "didn't throw") <<
endl;
}

## failedAssertThrowsNot()

void CxxTest::ErrorFormatter::failedAssertThrowsNot | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 201 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Expected (" << expression << ") not to throw, but it did" <<
endl;
}

## failedTest()

void CxxTest::ErrorFormatter::failedTest | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 108 of file ErrorFormatter.h.

{
stop( file, line ) << "Error: Test failed: " <<
expression << endl;
}

## leaveTest()

void CxxTest::ErrorFormatter::leaveTest | ( | const TestDescription & |  | ) |

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 76 of file ErrorFormatter.h.

{
if ( !tracker().testFailed() ) {
((*_o) << ".").flush();
_dotting = true;
}
}
CxxTest::tracker
TestTracker & tracker()
Definition TestTracker.h:111

## leaveWorld()

void CxxTest::ErrorFormatter::leaveWorld | ( | const WorldDescription & | desc | ) |

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 84 of file ErrorFormatter.h.

{
if ( !tracker().failedTests() ) {
(*_o) << "OK!" << endl;
return;
}
newLine();
(*_o) << "Failed " << tracker().failedTests() << " of " << totalTests << endl;
unsigned numPassed = desc.numTotalTests() - tracker().failedTests();
(*_o) << "Success rate: " << (numPassed * 100 / desc.numTotalTests()) << "%" << endl;
}
CxxTest::ErrorFormatter::newLine
void newLine(void)
Definition ErrorFormatter.h:224
CxxTest::TestTracker::failedTests
unsigned failedTests() const
Definition TestTracker.h:37

## newLine()

void CxxTest::ErrorFormatter::newLine | ( | void |  | ) |

inline private

Definition at line 224 of file ErrorFormatter.h.

{
if ( _dotting ) {
(*_o) << endl;
_dotting = false;
}
}

## operator=()

ErrorFormatter & CxxTest::ErrorFormatter::operator= | ( | const ErrorFormatter & |  | ) |

private

## outputStream()

OutputStream * CxxTest::ErrorFormatter::outputStream | ( |  | ) | const

inline protected

Definition at line 208 of file ErrorFormatter.h.

{
return _o;
}

## reportTest()

void CxxTest::ErrorFormatter::reportTest | ( | void |  | ) |

inline private

Definition at line 232 of file ErrorFormatter.h.

{
if( _reported )
return;
(*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
_reported = true;
}
CxxTest::SuiteDescription::suiteName
virtual const char * suiteName() const =0
CxxTest::TestDescription::testName
virtual const char * testName() const =0
CxxTest::TestTracker::suite
const SuiteDescription & suite() const
Definition TestTracker.h:29
CxxTest::TestTracker::test
const TestDescription & test() const
Definition TestTracker.h:28

## run()

int CxxTest::ErrorFormatter::run | ( |  | ) |

inline

Definition at line 45 of file ErrorFormatter.h.

{
TestRunner::runAllTests( *this );
return tracker().failedTests();
}
CxxTest::TestRunner::runAllTests
static void runAllTests(TestListener &listener)
Definition TestRunner.h:20

## stop()

OutputStream & CxxTest::ErrorFormatter::stop | ( | const char * | file,
|  | unsigned | line )

inline private

Definition at line 217 of file ErrorFormatter.h.

{
newLine();
reportTest();
return (*_o) << file << _preLine << line << _postLine << ": ";
}
CxxTest::ErrorFormatter::_preLine
const char * _preLine
Definition ErrorFormatter.h:276
CxxTest::ErrorFormatter::_postLine
const char * _postLine
Definition ErrorFormatter.h:277
CxxTest::ErrorFormatter::reportTest
void reportTest(void)
Definition ErrorFormatter.h:232

## totalTests()

void CxxTest::ErrorFormatter::totalTests | ( | OutputStream & | o | ) |

inline static

Definition at line 59 of file ErrorFormatter.h.

{
char s[WorldDescription::MAX_STRLEN_TOTAL_TESTS];
const WorldDescription &wd = tracker().world();
o << wd.strTotalTests( s ) << (wd.numTotalTests() == 1 ? " test" : " tests");
}
CxxTest::TestTracker::world
const WorldDescription & world() const
Definition TestTracker.h:30
CxxTest::WorldDescription::MAX_STRLEN_TOTAL_TESTS
@ MAX_STRLEN_TOTAL_TESTS
Definition Descriptions.h:62
CxxTest::WorldDescription::strTotalTests
char * strTotalTests(char *) const
Definition Descriptions.cpp:16
CxxTest::s
char * s
Definition ValueTraits.h:143

## trace()

void CxxTest::ErrorFormatter::trace | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 96 of file ErrorFormatter.h.

{
stop( file, line ) << "Trace: " <<
expression << endl;
}

## warning()

void CxxTest::ErrorFormatter::warning | ( | const char * | file,
|  | unsigned | line,
|  | const char * | expression )

inline virtual

Reimplemented from CxxTest::TestListener.

Definition at line 102 of file ErrorFormatter.h.

{
stop( file, line ) << "Warning: " <<
expression << endl;
}

## Field Documentation

## _dotting

bool CxxTest::ErrorFormatter::_dotting

private

Definition at line 273 of file ErrorFormatter.h.

## _o

OutputStream* CxxTest::ErrorFormatter::_o

private

Definition at line 275 of file ErrorFormatter.h.

## _postLine

const char* CxxTest::ErrorFormatter::_postLine

private

Definition at line 277 of file ErrorFormatter.h.

## _preLine

const char* CxxTest::ErrorFormatter::_preLine

private

Definition at line 276 of file ErrorFormatter.h.

## _reported

bool CxxTest::ErrorFormatter::_reported

private

Definition at line 274 of file ErrorFormatter.h.

The documentation for this class was generated from the following file:

- libpolys/tests/cxxtest/ErrorFormatter.h