2 * (C) Copyright Gennadiy Rozental 2005-2008.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
7 * See http://www.boost.org/libs/test for the library home page.
10 * @file colour_log_formatter.cpp
11 * @author Zofia Abramowska (z.abramowska@samsung.com)
16 #include <colour_log_formatter.h>
17 #include <boost/test/unit_test_suite_impl.hpp>
18 #include <boost/test/framework.hpp>
19 #include <boost/test/utils/basic_cstring/io.hpp>
20 #include <boost/test/utils/lazy_ostream.hpp>
23 #include <boost/version.hpp>
29 #include <dpl/colors.h>
31 // ************************************************************************** //
32 // ************** colour_log_formatter ************** //
33 // ************************************************************************** //
35 using namespace boost::unit_test;
41 test_phase_identifier()
43 return framework::is_initialized()
44 ? const_string( framework::current_test_case().p_name.get() )
45 : BOOST_TEST_L( "Test setup" );
49 get_basename(const const_string &file_name) {
50 return basename(file_name.begin());
54 get_basename(const std::string &file_name) {
55 return basename(file_name.c_str());
60 //____________________________________________________________________________//
63 colour_log_formatter::log_start(
65 counter_t test_cases_amount )
67 if( test_cases_amount > 0 )
68 output << "Running " << test_cases_amount << " test "
69 << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
72 //____________________________________________________________________________//
75 colour_log_formatter::log_finish( std::ostream& ostr )
80 //____________________________________________________________________________//
83 colour_log_formatter::log_build_info( std::ostream& output )
85 output << "Platform: " << BOOST_PLATFORM << '\n'
86 << "Compiler: " << BOOST_COMPILER << '\n'
87 << "STL : " << BOOST_STDLIB << '\n'
88 << "Boost : " << BOOST_VERSION/100000 << "."
89 << BOOST_VERSION/100 % 1000 << "."
90 << BOOST_VERSION % 100 << std::endl;
93 //____________________________________________________________________________//
96 colour_log_formatter::test_unit_start(
100 if (tu.p_type_name->find(const_string("suite")) == 0) {
101 output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
103 output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
107 //____________________________________________________________________________//
110 colour_log_formatter::test_unit_finish(
111 std::ostream& output,
113 unsigned long elapsed )
115 if (tu.p_type_name->find(const_string("suite")) == 0) {
116 output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\""<< std::endl;
119 std::string color = CKM::Colors::Text::GREEN_BEGIN;
120 std::string status = "OK";
121 if (m_isTestCaseFailed) {
122 color = CKM::Colors::Text::RED_BEGIN;
125 output << "\t" << "[ " << color << status << CKM::Colors::Text::COLOR_END << " ]";
128 output << ", " << CKM::Colors::Text::CYAN_BEGIN << "time: ";
130 if( elapsed % 1000 == 0 )
131 output << elapsed/1000 << "ms";
133 output << elapsed << "mks";
138 output << CKM::Colors::Text::COLOR_END << std::endl;
139 m_isTestCaseFailed = false;
142 //____________________________________________________________________________//
145 colour_log_formatter::test_unit_skipped(
146 std::ostream& output,
147 test_unit const& tu )
149 output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
152 //____________________________________________________________________________//
155 colour_log_formatter::log_exception(
156 std::ostream& output,
157 log_checkpoint_data const& checkpoint_data,
158 boost::execution_exception const& ex )
160 boost::execution_exception::location const& loc = ex.where();
161 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(loc.m_file_name)
162 << '(' << loc.m_line_num << "), ";
164 output << "fatal error in \""
165 << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": ";
167 output << CKM::Colors::Text::COLOR_END << ex.what();
169 if( !checkpoint_data.m_file_name.is_empty() ) {
171 output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name)
172 << '(' << checkpoint_data.m_line_num << ")";
173 if( !checkpoint_data.m_message.empty() )
174 output << ": " << checkpoint_data.m_message;
178 m_isTestCaseFailed = true;
181 //____________________________________________________________________________//
184 colour_log_formatter::log_entry_start(
185 std::ostream& output,
186 log_entry_data const& entry_data,
187 log_entry_types let )
190 case BOOST_UTL_ET_INFO:
191 output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << "), ";
194 case BOOST_UTL_ET_MESSAGE:
196 case BOOST_UTL_ET_WARNING:
197 output << '\t' << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), ";
198 output << "warning in \"" << test_phase_identifier() << "\": ";
200 case BOOST_UTL_ET_ERROR:
201 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
202 << '(' << entry_data.m_line_num << "), ";
203 output << "error in \"" << test_phase_identifier() << "\": ";
204 m_isTestCaseFailed = true;
206 case BOOST_UTL_ET_FATAL_ERROR:
207 output << '\t' << CKM::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
208 << '(' << entry_data.m_line_num << "), ";
209 output << " fatal error in \"" << test_phase_identifier() << "\": ";
210 m_isTestCaseFailed = true;
213 output << CKM::Colors::Text::COLOR_END;
216 //____________________________________________________________________________//
219 colour_log_formatter::log_entry_value(
220 std::ostream& output,
226 //____________________________________________________________________________//
229 colour_log_formatter::log_entry_value(
230 std::ostream& output,
231 lazy_ostream const& value )
236 //____________________________________________________________________________//
239 colour_log_formatter::log_entry_finish(
240 std::ostream& output )
245 //____________________________________________________________________________//
247 //____________________________________________________________________________//
251 //____________________________________________________________________________//