blob: d04ce924ab7fec3757b5419bc66f68ca346a5b0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#include <iostream>
#include "cppunit/TextTestResult.h"
#include "cppunit/Exception.h"
#include "cppunit/NotEqualException.h"
#include "cppunit/Test.h"
namespace CppUnit {
std::ostream&
operator<< (std::ostream& stream, TextTestResult& result)
{
result.print (stream); return stream;
}
void
TextTestResult::addError (Test *test, Exception *e)
{
TestResult::addError (test, e);
std::cerr << "E";
}
void
TextTestResult::addFailure (Test *test, Exception *e)
{
TestResult::addFailure (test, e);
std::cerr << "F";
}
void
TextTestResult::startTest (Test *test)
{
TestResult::startTest (test);
std::cerr << ".";
}
void
TextTestResult::printErrors (std::ostream& stream)
{
if ( testErrors() == 0 )
return;
if (testErrors () == 1)
stream << "There was 1 error: " << std::endl;
else
stream << "There were " << testErrors () << " errors: " << std::endl;
int i = 1;
for (std::vector<TestFailure *>::iterator it = errors ().begin (); it != errors ().end (); ++it) {
TestFailure* failure = *it;
Exception* e = failure->thrownException ();
stream << i
<< ")"
<< " test: " << failure->failedTest()->getName();
if ( e )
stream << " line: " << e->lineNumber()
<< ' ' << e->fileName();
stream << " \"" << failure->thrownException()->what() << "\""
<< std::endl;
i++;
}
}
void
TextTestResult::printFailures (std::ostream& stream)
{
if ( testFailures() == 0 )
return;
if (testFailures () == 1)
stream << "There was 1 failure: " << std::endl;
else
stream << "There were " << testFailures () << " failures: " << std::endl;
int i = 1;
for (std::vector<TestFailure *>::iterator it = failures ().begin (); it != failures ().end (); ++it) {
TestFailure* failure = *it;
Exception* e = failure->thrownException();
stream << i
<< ")"
<< " test: " << failure->failedTest()->getName();
if ( e )
stream << " line: " << e->lineNumber()
<< ' ' << e->fileName();
if ( failure->thrownException()->isInstanceOf( NotEqualException::type() ) )
{
NotEqualException *e = (NotEqualException*)failure->thrownException();
stream << std::endl
<< "expected: " << e->expectedValue() << std::endl
<< "but was: " << e->actualValue();
}
else
{
stream << " \"" << failure->thrownException ()->what () << "\"";
}
stream << std::endl;
i++;
}
}
void
TextTestResult::print (std::ostream& stream)
{
printHeader (stream);
printErrors (stream);
printFailures (stream);
}
void
TextTestResult::printHeader (std::ostream& stream)
{
if (wasSuccessful ())
stream << std::endl << "OK (" << runTests () << " tests)" << std::endl;
else
stream << std::endl
<< "!!!FAILURES!!!" << std::endl
<< "Test Results:" << std::endl
<< "Run: "
<< runTests ()
<< " Failures: "
<< testFailures ()
<< " Errors: "
<< testErrors ()
<< std::endl;
}
} // namespace CppUnit
|