My Project
Loading...
Searching...
No Matches
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 enterWorld (const WorldDescription &)
 
virtual void enterSuite (const SuiteDescription &)
 
virtual void enterTest (const TestDescription &)
 
virtual void trace (const char *, unsigned, const char *)
 
virtual void warning (const char *, unsigned, const char *)
 
virtual void failedTest (const char *, unsigned, const char *)
 
virtual void failedAssert (const char *, unsigned, const char *)
 
virtual void failedAssertEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertSameData (const char *, unsigned, const char *, const char *, const char *, const void *, const void *, unsigned)
 
virtual void failedAssertDelta (const char *, unsigned, const char *, const char *, const char *, const char *, const char *, const char *)
 
virtual void failedAssertDiffers (const char *, unsigned, const char *, const char *, const char *)
 
virtual void failedAssertLessThan (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertLessThanEquals (const char *, unsigned, const char *, const char *, const char *, const char *)
 
virtual void failedAssertPredicate (const char *, unsigned, const char *, const char *, const char *)
 
virtual void failedAssertRelation (const char *, unsigned, const char *, const char *, const char *, const char *, const char *)
 
virtual void failedAssertThrows (const char *, unsigned, const char *, const char *, bool)
 
virtual void failedAssertThrowsNot (const char *, unsigned, const char *)
 
virtual void leaveTest (const TestDescription &)
 
virtual void leaveSuite (const SuiteDescription &)
 
virtual void leaveWorld (const WorldDescription &)
 

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 }
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
void dumpBuffer(const void *buffer, unsigned size)

◆ 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 }
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
static void endl(OutputStream &o)
unsigned maxDumpSize()
Definition: TestSuite.cpp:43
const char * byteToHex(unsigned char byte)
Definition: ValueTraits.cpp:21

◆ 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 {
271 }
static void endl(OutputStream &o)

◆ 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 }
static void totalTests(OutputStream &o)
virtual void flush()

◆ 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 }
OutputStream & stop(const char *file, unsigned line)

◆ 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 }
Variable x
Definition: cfModGcd.cc:4082
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 
)
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 }
void dump(const void *buffer, unsigned size)

◆ 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 }
TestTracker & tracker()
Definition: TestTracker.h:111

◆ 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 }
unsigned failedTests() const
Definition: TestTracker.h:37

◆ 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 }
virtual const char * suiteName() const =0
virtual const char * testName() const =0
const SuiteDescription & suite() const
Definition: TestTracker.h:29
const TestDescription & test() const
Definition: TestTracker.h:28

◆ run()

int CxxTest::ErrorFormatter::run ( )
inline

Definition at line 45 of file ErrorFormatter.h.

46 {
48 return tracker().failedTests();
49 }
static void runAllTests(TestListener &listener)
Definition: TestRunner.h:20

◆ 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 }
const WorldDescription & world() const
Definition: TestTracker.h:30
char * strTotalTests(char *) const
char * s
Definition: ValueTraits.h:143

◆ 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: