My Project  debian-1:4.1.2-p1+ds-2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
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

OutputStreamoutputStream () const
 

Private Member Functions

 ErrorFormatter (const ErrorFormatter &)
 
ErrorFormatteroperator= (const ErrorFormatter &)
 
OutputStreamstop (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.

36  :", const char *postLine = "" ) :
37  _dotting( true ),
38  _reported( false ),
39  _o(o),
40  _preLine(preLine),
41  _postLine(postLine)
42  {
43  }

◆ ErrorFormatter() [2/2]

CxxTest::ErrorFormatter::ErrorFormatter ( const ErrorFormatter )
private

Member Function Documentation

◆ dump()

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

Definition at line 240 of file ErrorFormatter.h.

241  {
242  if ( !buffer )
243  dumpNull();
244  else
245  dumpBuffer( buffer, size );
246  }

◆ dumpBuffer()

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

Definition at line 253 of file ErrorFormatter.h.

254  {
255  unsigned dumpSize = size;
256  if ( maxDumpSize() && dumpSize > maxDumpSize() )
257  dumpSize = maxDumpSize();
258 
259  const unsigned char *p = (const unsigned char *)buffer;
260  (*_o) << " { ";
261  for ( unsigned i = 0; i < dumpSize; ++ i )
262  (*_o) << byteToHex( *p++ ) << " ";
263  if ( dumpSize < size )
264  (*_o) << "... ";
265  (*_o) << "}" << endl;
266  }

◆ dumpNull()

void CxxTest::ErrorFormatter::dumpNull ( )
inlineprivate

Definition at line 248 of file ErrorFormatter.h.

249  {
250  (*_o) << " (null)" << endl;
251  }

◆ endl()

static void CxxTest::ErrorFormatter::endl ( OutputStream o)
inlinestaticprivate

Definition at line 268 of file ErrorFormatter.h.

269  {
270  OutputStream::endl( o );
271  }

◆ enterSuite()

void CxxTest::ErrorFormatter::enterSuite ( const SuiteDescription )
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 66 of file ErrorFormatter.h.

67  {
68  _reported = false;
69  }

◆ enterTest()

void CxxTest::ErrorFormatter::enterTest ( const TestDescription )
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 71 of file ErrorFormatter.h.

72  {
73  _reported = false;
74  }

◆ enterWorld()

void CxxTest::ErrorFormatter::enterWorld ( const WorldDescription )
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 51 of file ErrorFormatter.h.

52  {
53  (*_o) << "Running " << totalTests;
54  _o->flush();
55  _dotting = true;
56  _reported = false;
57  }

◆ failedAssert()

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

Reimplemented from CxxTest::TestListener.

Definition at line 114 of file ErrorFormatter.h.

115  {
116  stop( file, line ) << "Error: Assertion failed: " <<
117  expression << endl;
118  }

◆ 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 
)
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 141 of file ErrorFormatter.h.

144  {
145  stop( file, line ) << "Error: Expected (" <<
146  xStr << " == " << yStr << ") up to " << dStr << " (" << d << "), found (" <<
147  x << " != " << y << ")" << endl;
148  }

◆ failedAssertDiffers()

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

Reimplemented from CxxTest::TestListener.

Definition at line 150 of file ErrorFormatter.h.

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

◆ failedAssertEquals()

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

Reimplemented from CxxTest::TestListener.

Definition at line 120 of file ErrorFormatter.h.

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

◆ failedAssertLessThan()

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

Reimplemented from CxxTest::TestListener.

Definition at line 159 of file ErrorFormatter.h.

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

◆ failedAssertLessThanEquals()

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

Reimplemented from CxxTest::TestListener.

Definition at line 168 of file ErrorFormatter.h.

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

◆ failedAssertPredicate()

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

Reimplemented from CxxTest::TestListener.

Definition at line 185 of file ErrorFormatter.h.

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

◆ 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 
)
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 177 of file ErrorFormatter.h.

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

◆ 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 
)
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 129 of file ErrorFormatter.h.

133  {
134  stop( file, line ) << "Error: Expected " << sizeStr << " (" << size << ") bytes to be equal at (" <<
135  xStr << ") and (" << yStr << "), found:" << endl;
136  dump( x, size );
137  (*_o) << " differs from" << endl;
138  dump( y, size );
139  }

◆ failedAssertThrows()

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

Reimplemented from CxxTest::TestListener.

Definition at line 192 of file ErrorFormatter.h.

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

◆ failedAssertThrowsNot()

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

Reimplemented from CxxTest::TestListener.

Definition at line 201 of file ErrorFormatter.h.

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

◆ failedTest()

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

Reimplemented from CxxTest::TestListener.

Definition at line 108 of file ErrorFormatter.h.

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

◆ leaveTest()

void CxxTest::ErrorFormatter::leaveTest ( const TestDescription )
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 76 of file ErrorFormatter.h.

77  {
78  if ( !tracker().testFailed() ) {
79  ((*_o) << ".").flush();
80  _dotting = true;
81  }
82  }

◆ leaveWorld()

void CxxTest::ErrorFormatter::leaveWorld ( const WorldDescription desc)
inlinevirtual

Reimplemented from CxxTest::TestListener.

Definition at line 84 of file ErrorFormatter.h.

85  {
86  if ( !tracker().failedTests() ) {
87  (*_o) << "OK!" << endl;
88  return;
89  }
90  newLine();
91  (*_o) << "Failed " << tracker().failedTests() << " of " << totalTests << endl;
92  unsigned numPassed = desc.numTotalTests() - tracker().failedTests();
93  (*_o) << "Success rate: " << (numPassed * 100 / desc.numTotalTests()) << "%" << endl;
94  }

◆ newLine()

void CxxTest::ErrorFormatter::newLine ( void  )
inlineprivate

Definition at line 224 of file ErrorFormatter.h.

225  {
226  if ( _dotting ) {
227  (*_o) << endl;
228  _dotting = false;
229  }
230  }

◆ operator=()

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

◆ outputStream()

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

Definition at line 208 of file ErrorFormatter.h.

209  {
210  return _o;
211  }

◆ reportTest()

void CxxTest::ErrorFormatter::reportTest ( void  )
inlineprivate

Definition at line 232 of file ErrorFormatter.h.

233  {
234  if( _reported )
235  return;
236  (*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
237  _reported = true;
238  }

◆ run()

int CxxTest::ErrorFormatter::run ( )
inline

Definition at line 45 of file ErrorFormatter.h.

46  {
47  TestRunner::runAllTests( *this );
48  return tracker().failedTests();
49  }

◆ stop()

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

Definition at line 217 of file ErrorFormatter.h.

218  {
219  newLine();
220  reportTest();
221  return (*_o) << file << _preLine << line << _postLine << ": ";
222  }

◆ totalTests()

static void CxxTest::ErrorFormatter::totalTests ( OutputStream o)
inlinestatic

Definition at line 59 of file ErrorFormatter.h.

60  {
62  const WorldDescription &wd = tracker().world();
63  o << wd.strTotalTests( s ) << (wd.numTotalTests() == 1 ? " test" : " tests");
64  }

◆ trace()

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

Reimplemented from CxxTest::TestListener.

Definition at line 96 of file ErrorFormatter.h.

97  {
98  stop( file, line ) << "Trace: " <<
99  expression << endl;
100  }

◆ warning()

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

Reimplemented from CxxTest::TestListener.

Definition at line 102 of file ErrorFormatter.h.

103  {
104  stop( file, line ) << "Warning: " <<
105  expression << endl;
106  }

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:
CxxTest::TestRunner::runAllTests
static void runAllTests(TestListener &listener)
Definition: TestRunner.h:20
CxxTest::ErrorFormatter::dumpBuffer
void dumpBuffer(const void *buffer, unsigned size)
Definition: ErrorFormatter.h:253
x
Variable x
Definition: cfModGcd.cc:4023
y
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
CxxTest::ErrorFormatter::_dotting
bool _dotting
Definition: ErrorFormatter.h:273
CxxTest::ErrorFormatter::_reported
bool _reported
Definition: ErrorFormatter.h:274
CxxTest::TestTracker::world
const WorldDescription & world() const
Definition: TestTracker.h:30
CxxTest::TestTracker::test
const TestDescription & test() const
Definition: TestTracker.h:28
CxxTest::TestTracker::failedTests
unsigned failedTests() const
Definition: TestTracker.h:37
CxxTest::ErrorFormatter::reportTest
void reportTest(void)
Definition: ErrorFormatter.h:232
CxxTest::ErrorFormatter::dump
void dump(const void *buffer, unsigned size)
Definition: ErrorFormatter.h:240
CxxTest::ErrorFormatter::totalTests
static void totalTests(OutputStream &o)
Definition: ErrorFormatter.h:59
CxxTest::ErrorFormatter::stop
OutputStream & stop(const char *file, unsigned line)
Definition: ErrorFormatter.h:217
CxxTest::s
char * s
Definition: ValueTraits.h:143
i
int i
Definition: cfEzgcd.cc:125
CxxTest::OutputStream::flush
virtual void flush()
Definition: ErrorFormatter.h:23
CxxTest::WorldDescription::strTotalTests
char * strTotalTests(char *) const
Definition: Descriptions.cpp:16
CxxTest::ErrorFormatter::endl
static void endl(OutputStream &o)
Definition: ErrorFormatter.h:268
CxxTest::byteToHex
const char * byteToHex(unsigned char byte)
Definition: ValueTraits.cpp:21
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
CxxTest::ErrorFormatter::_postLine
const char * _postLine
Definition: ErrorFormatter.h:277
CxxTest::ErrorFormatter::newLine
void newLine(void)
Definition: ErrorFormatter.h:224
CxxTest::TestTracker::suite
const SuiteDescription & suite() const
Definition: TestTracker.h:29
CxxTest::ErrorFormatter::_preLine
const char * _preLine
Definition: ErrorFormatter.h:276
CxxTest::ErrorFormatter::dumpNull
void dumpNull()
Definition: ErrorFormatter.h:248
CxxTest::maxDumpSize
unsigned maxDumpSize()
Definition: TestSuite.cpp:43
CxxTest::WorldDescription::MAX_STRLEN_TOTAL_TESTS
Definition: Descriptions.h:62
CxxTest::OutputStream::endl
static void endl(OutputStream &o)
Definition: ErrorFormatter.h:30
CxxTest::SuiteDescription::suiteName
virtual const char * suiteName() const =0
p
int p
Definition: cfModGcd.cc:4019
CxxTest::ErrorFormatter::_o
OutputStream * _o
Definition: ErrorFormatter.h:275
CxxTest::tracker
TestTracker & tracker()
Definition: TestTracker.h:111
CxxTest::TestDescription::testName
virtual const char * testName() const =0