blob: 1f0aaac66d2e86f70d3884928c65e8ef79d7226b [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2005-2008.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8// File : $RCSfile$
9//
10// Version : $Revision: 49312 $
11//
12// Description : plain report formatter definition
13// ***************************************************************************
14
15#ifndef BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
16#define BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER
17
18// Boost.Test
19#include <ndnboost/test/output/plain_report_formatter.hpp>
20#include <ndnboost/test/utils/custom_manip.hpp>
21#include <ndnboost/test/results_collector.hpp>
22#include <ndnboost/test/unit_test_suite_impl.hpp>
23
24#include <ndnboost/test/utils/basic_cstring/io.hpp>
25
26// STL
27#include <iomanip>
28#include <ndnboost/config/no_tr1/cmath.hpp>
29#include <iostream>
30
31#include <ndnboost/test/detail/suppress_warnings.hpp>
32
33# ifdef BOOST_NO_STDC_NAMESPACE
34namespace std { using ::log10; }
35# endif
36
37//____________________________________________________________________________//
38
39namespace ndnboost {
40
41namespace unit_test {
42
43namespace output {
44
45namespace {
46
47typedef custom_manip<struct quote_t> quote;
48
49template<typename T>
50inline std::ostream&
51operator<<( custom_printer<quote> const& p, T const& value )
52{
53 *p << '"' << value << '"';
54
55 return *p;
56}
57
58//____________________________________________________________________________//
59
60void
61print_stat_value( std::ostream& ostr, counter_t v, counter_t indent, counter_t total,
62 const_string name, const_string res )
63{
64 if( v > 0 ) {
65 ostr << std::setw( indent ) << ""
66 << v << ' ' << name << ( v != 1 ? "s" : "" );
67 if( total > 0 )
68 ostr << " out of " << total;
69
70 ostr << ' ' << res << '\n';
71 }
72}
73
74//____________________________________________________________________________//
75
76} // local namespace
77
78// ************************************************************************** //
79// ************** plain_report_formatter ************** //
80// ************************************************************************** //
81
82void
83plain_report_formatter::results_report_start( std::ostream& ostr )
84{
85 m_indent = 0;
86 ostr << '\n';
87}
88
89//____________________________________________________________________________//
90
91void
92plain_report_formatter::results_report_finish( std::ostream& ostr )
93{
94 ostr.flush();
95}
96
97//____________________________________________________________________________//
98
99void
100plain_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& ostr )
101{
102 test_results const& tr = results_collector.results( tu.p_id );
103
104 const_string descr;
105
106 if( tr.passed() )
107 descr = "passed";
108 else if( tr.p_skipped )
109 descr = "skipped";
110 else if( tr.p_aborted )
111 descr = "aborted";
112 else
113 descr = "failed";
114
115 ostr << std::setw( m_indent ) << ""
116 << "Test " << (tu.p_type == tut_case ? "case " : "suite " ) << quote() << tu.p_name << ' ' << descr;
117
118 if( tr.p_skipped ) {
119 ostr << " due to " << (tu.check_dependencies() ? "test aborting\n" : "failed dependancy\n" );
120 m_indent += 2;
121 return;
122 }
123
124 counter_t total_assertions = tr.p_assertions_passed + tr.p_assertions_failed;
125 counter_t total_tc = tr.p_test_cases_passed + tr.p_test_cases_failed + tr.p_test_cases_skipped;
126
127 if( total_assertions > 0 || total_tc > 0 )
128 ostr << " with:";
129
130 ostr << '\n';
131 m_indent += 2;
132
133 print_stat_value( ostr, tr.p_assertions_passed, m_indent, total_assertions, "assertion", "passed" );
134 print_stat_value( ostr, tr.p_assertions_failed, m_indent, total_assertions, "assertion", "failed" );
135 print_stat_value( ostr, tr.p_expected_failures, m_indent, 0 , "failure" , "expected" );
136 print_stat_value( ostr, tr.p_test_cases_passed, m_indent, total_tc , "test case", "passed" );
137 print_stat_value( ostr, tr.p_test_cases_failed, m_indent, total_tc , "test case", "failed" );
138 print_stat_value( ostr, tr.p_test_cases_skipped, m_indent, total_tc , "test case", "skipped" );
139 print_stat_value( ostr, tr.p_test_cases_aborted, m_indent, total_tc , "test case", "aborted" );
140
141 ostr << '\n';
142}
143
144//____________________________________________________________________________//
145
146void
147plain_report_formatter::test_unit_report_finish( test_unit const&, std::ostream& )
148{
149 m_indent -= 2;
150}
151
152//____________________________________________________________________________//
153
154void
155plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr )
156{
157 test_results const& tr = results_collector.results( tu.p_id );
158
159 if( tr.passed() ) {
160 ostr << "*** No errors detected\n";
161 return;
162 }
163
164 if( tr.p_skipped ) {
165 ostr << "*** Test " << tu.p_type_name << " skipped due to "
166 << (tu.check_dependencies() ? "test aborting\n" : "failed dependancy\n" );
167 return;
168 }
169
170 if( tr.p_assertions_failed == 0 ) {
171 ostr << "*** errors detected in test " << tu.p_type_name << " " << quote() << tu.p_name
172 << "; see standard output for details\n";
173 return;
174 }
175
176 counter_t num_failures = tr.p_assertions_failed;
177
178 ostr << "*** " << num_failures << " failure" << ( num_failures != 1 ? "s" : "" ) << " detected";
179
180 if( tr.p_expected_failures > 0 )
181 ostr << " (" << tr.p_expected_failures << " failure" << ( tr.p_expected_failures != 1 ? "s" : "" ) << " expected)";
182
183 ostr << " in test " << tu.p_type_name << " " << quote() << tu.p_name << "\n";
184}
185
186//____________________________________________________________________________//
187
188} // namespace output
189
190} // namespace unit_test
191
192} // namespace ndnboost
193
194//____________________________________________________________________________//
195
196#include <ndnboost/test/detail/enable_warnings.hpp>
197
198#endif // BOOST_TEST_PLAIN_REPORT_FORMATTER_IPP_020105GER