Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / TextOutputter.cpp
1 #include <cppunit/Exception.h>
2 #include <cppunit/SourceLine.h>
3 #include <cppunit/TestFailure.h>
4 #include <cppunit/TextOutputter.h>
5 #include <cppunit/TestResultCollector.h>
6
7
8 CPPUNIT_NS_BEGIN
9
10
11 TextOutputter::TextOutputter( TestResultCollector *result,
12                               OStream &stream )
13     : m_result( result )
14     , m_stream( stream )
15 {
16 }
17
18
19 TextOutputter::~TextOutputter()
20 {
21 }
22
23
24 void 
25 TextOutputter::write() 
26 {
27   printHeader();
28   m_stream << "\n";
29   printFailures();
30   m_stream << "\n";
31 }
32
33
34 void 
35 TextOutputter::printFailures()
36 {
37   TestResultCollector::TestFailures::const_iterator itFailure = m_result->failures().begin();
38   int failureNumber = 1;
39   while ( itFailure != m_result->failures().end() ) 
40   {
41     m_stream  <<  "\n";
42     printFailure( *itFailure++, failureNumber++ );
43   }
44 }
45
46
47 void 
48 TextOutputter::printFailure( TestFailure *failure,
49                              int failureNumber )
50 {
51   printFailureListMark( failureNumber );
52   m_stream << ' ';
53   printFailureTestName( failure );
54   m_stream << ' ';
55   printFailureType( failure );
56   m_stream << ' ';
57   printFailureLocation( failure->sourceLine() );
58   m_stream << "\n";
59   printFailureDetail( failure->thrownException() );
60   m_stream << "\n";
61 }
62
63
64 void 
65 TextOutputter::printFailureListMark( int failureNumber )
66 {
67   m_stream << failureNumber << ")";
68 }
69
70
71 void 
72 TextOutputter::printFailureTestName( TestFailure *failure )
73 {
74   m_stream << "test: " << failure->failedTestName();
75 }
76
77
78 void 
79 TextOutputter::printFailureType( TestFailure *failure )
80 {
81   m_stream << "("
82            << (failure->isError() ? "E" : "F")
83            << ")";
84 }
85
86
87 void 
88 TextOutputter::printFailureLocation( SourceLine sourceLine )
89 {
90   if ( !sourceLine.isValid() )
91     return;
92
93   m_stream << "line: " << sourceLine.lineNumber()
94            << ' ' << sourceLine.fileName();
95 }
96
97
98 void 
99 TextOutputter::printFailureDetail( Exception *thrownException )
100 {
101   m_stream  <<  thrownException->message().shortDescription()  <<  "\n";
102   m_stream  <<  thrownException->message().details();
103 }
104
105
106 void 
107 TextOutputter::printHeader()
108 {
109   if ( m_result->wasSuccessful() )
110     m_stream << "\nOK (" << m_result->runTests () << " tests)\n" ;
111   else
112   {
113     m_stream << "\n";
114     printFailureWarning();
115     printStatistics();
116   }
117 }
118
119
120 void 
121 TextOutputter::printFailureWarning()
122 {
123   m_stream  << "!!!FAILURES!!!\n";
124 }
125
126
127 void 
128 TextOutputter::printStatistics()
129 {
130   m_stream  << "Test Results:\n";
131
132   m_stream  <<  "Run:  "  <<  m_result->runTests()
133             <<  "   Failures: "  <<  m_result->testFailures()
134             <<  "   Errors: "  <<  m_result->testErrors()
135             <<  "\n";
136 }
137
138
139 CPPUNIT_NS_END
140