3 // $Id: textoutput.cpp,v 1.4 2008/07/15 20:33:31 hartwork Exp $
5 // CppTest - A C++ Unit Testing Framework
6 // Copyright (c) 2003 Niklas Lundell
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
29 #if (defined(__WIN32__) || defined(WIN32))
30 # include "winconfig.h"
35 #include "cpptest-textoutput.h"
36 #include "cpptest-time.h"
45 // Outputs detailed assert source information. Used in verbose mode.
50 ShowSource(ostream
& stream
) : _stream(stream
) {}
51 void operator()(const Source
& s
)
53 _stream
<< "\tTest: " << s
.test() << endl
54 << "\tSuite: " << s
.suite() << endl
55 << "\tFile: " << s
.file() << endl
56 << "\tLine: " << s
.line() << endl
57 << "\tMessage: " << s
.message() << endl
<< endl
;
62 } // anonymous namespace
64 /// Constructs a text output handler.
66 /// \param mode Output mode.
67 /// \param stream Stream to output to.
69 TextOutput::TextOutput(Mode mode
, ostream
& stream
)
76 TextOutput::finished(int tests
, const Time
& time
)
78 _stream
<< "Total: " << tests
<< " tests, "
79 << correct(tests
, _total_errors
) << "% correct"
80 << " in " << time
<< " seconds" << endl
;
84 TextOutput::suite_start(int tests
, const string
& name
)
89 _suite_tests
= _suite_errors
= 0;
90 _suite_total_tests
= tests
;
91 _suite_error_list
.clear();
93 _stream
<< _suite_name
<< ": "
94 << "0/" << _suite_total_tests
100 TextOutput::suite_end(int tests
, const string
& name
, const Time
& time
)
104 _stream
<< name
<< ": " << tests
<< "/" << tests
<< ", "
105 << correct(tests
, _suite_errors
) << "% correct"
106 << " in " << time
<< " seconds" << endl
;
108 if (_mode
== Verbose
&& _suite_errors
)
109 for_each(_suite_error_list
.begin(), _suite_error_list
.end(),
110 ShowSource(_stream
));
112 _total_errors
+= _suite_errors
;
117 TextOutput::test_end(const string
&, bool ok
, const Time
&)
119 _stream
<< _suite_name
<< ": "
120 << ++_suite_tests
<< "/" << _suite_total_tests
127 TextOutput::assertment(const Source
& s
)
129 _suite_error_list
.push_back(s
);