From: Lukasz Pawelczyk Date: Tue, 1 Dec 2020 16:52:09 +0000 (+0100) Subject: Fix style, coding rules and overall esthetics of log formatter code X-Git-Tag: accepted/tizen/unified/20210111.024859~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F248704%2F2;p=platform%2Fcore%2Fsecurity%2Fyaca.git Fix style, coding rules and overall esthetics of log formatter code Change-Id: I96da85bbe6b24f37a79d76365a69707afd430752 --- diff --git a/tests/colour_log_formatter.cpp b/tests/colour_log_formatter.cpp index bd1e323..81ffd06 100644 --- a/tests/colour_log_formatter.cpp +++ b/tests/colour_log_formatter.cpp @@ -12,6 +12,7 @@ * @version * @brief */ + // Boost.Test #include "colour_log_formatter.h" #include @@ -37,17 +38,14 @@ const char* CYAN_BEGIN = "\033[0;36m"; const char* BOLD_YELLOW_BEGIN = "\033[1;33m"; const char* COLOR_END = "\033[m"; -// ************************************************************************** // -// ************** colour_log_formatter ************** // -// ************************************************************************** // - using namespace boost::unit_test; + + namespace Yaca { namespace { -const_string -test_unit_type_name(const test_unit &tu) +const_string test_unit_type_name(const test_unit &tu) { #if BOOST_VERSION >= 105900 return const_string(tu.p_type_name); @@ -56,8 +54,7 @@ test_unit_type_name(const test_unit &tu) #endif } -const_string -test_unit_name(const test_unit &tu) +const_string test_unit_name(const test_unit &tu) { #if BOOST_VERSION >= 105900 return const_string(tu.p_name); @@ -66,73 +63,59 @@ test_unit_name(const test_unit &tu) #endif } -const_string -test_phase_identifier() +const_string test_phase_identifier() { return test_unit_name(framework::current_test_case()); } -const_string -get_basename(const const_string &file_name) +const_string get_basename(const const_string &file_name) { return basename(file_name.begin()); } -std::string -get_basename(const std::string &file_name) +std::string get_basename(const std::string &file_name) { return basename(file_name.c_str()); } -bool -test_unit_type_name_contains(const test_unit &tu, const std::string &substr) +bool test_unit_type_name_contains(const test_unit &tu, const std::string &substr) { return test_unit_type_name(tu).find(const_string(substr)) == 0; } } // local namespace -//____________________________________________________________________________// -void -colour_log_formatter::log_start( +void colour_log_formatter::log_start( std::ostream &output, counter_t test_cases_amount) { - if (test_cases_amount > 0) - output << "Running " << test_cases_amount << " test " - << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; + if (test_cases_amount > 0) { + output << "Running " << test_cases_amount << " test " + << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; + } } -//____________________________________________________________________________// - -void -colour_log_formatter::log_finish(std::ostream &ostr) +void colour_log_formatter::log_finish(std::ostream &ostr) { ostr.flush(); } -//____________________________________________________________________________// - -void #if BOOST_VERSION >= 107000 -colour_log_formatter::log_build_info(std::ostream &output, bool) +void colour_log_formatter::log_build_info(std::ostream &output, bool) #else -colour_log_formatter::log_build_info(std::ostream &output) +void colour_log_formatter::log_build_info(std::ostream &output) #endif { - output << "Platform: " << BOOST_PLATFORM << '\n' - << "Compiler: " << BOOST_COMPILER << '\n' - << "STL : " << BOOST_STDLIB << '\n'; - output << "Boost : " << BOOST_VERSION / 100000 << '.' - << BOOST_VERSION / 100 % 1000 << '.' - << BOOST_VERSION % 100 << std::endl; + output << "Platform: " << BOOST_PLATFORM << '\n' + << "Compiler: " << BOOST_COMPILER << '\n' + << "STL : " << BOOST_STDLIB << '\n'; + output << "Boost : " << BOOST_VERSION / 100000 << '.' + << BOOST_VERSION / 100 % 1000 << '.' + << BOOST_VERSION % 100 << '\n'; } -//____________________________________________________________________________// - -void -colour_log_formatter::test_unit_start( +void colour_log_formatter::test_unit_start( std::ostream &output, test_unit const &tu) { @@ -141,22 +124,17 @@ colour_log_formatter::test_unit_start( } else { output << "Running test "; } - output << test_unit_type_name(tu) << " \"" << test_unit_name(tu) - << "\"" << std::endl; - + output << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"\n"; } -//____________________________________________________________________________// - -void -colour_log_formatter::test_unit_finish( +void colour_log_formatter::test_unit_finish( std::ostream &output, test_unit const &tu, unsigned long elapsed) { if (test_unit_type_name_contains(tu, "suite")) { - output << "Finished test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" << - std::endl; + output << "Finished test " << test_unit_type_name(tu) + << " \"" << test_unit_name(tu) << "\"\n"; return; } @@ -168,52 +146,44 @@ colour_log_formatter::test_unit_finish( status = "FAIL"; } - output << "\t" << "[ " << color << status << COLOR_END << - " ]"; - - - output << ", " << CYAN_BEGIN << "time: "; + output << "\t" << "[ " << color << status << COLOR_END << " ], " + << ", " << CYAN_BEGIN << "time: "; if (elapsed > 0) { - if (elapsed % 1000 == 0) + if (elapsed % 1000 == 0) { output << elapsed / 1000 << "ms"; - else + } else { output << elapsed << "mks"; + } } else { output << "N/A"; } - output << COLOR_END << std::endl; + output << COLOR_END << '\n'; m_isTestCaseFailed = false; } -//____________________________________________________________________________// - -void -colour_log_formatter::test_unit_skipped( +void colour_log_formatter::test_unit_skipped( std::ostream &output, test_unit const &tu) { - output << "Test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" << - "is skipped" << std::endl; + output << "Test " << test_unit_type_name(tu) + << " \"" << test_unit_name(tu) << "\" is skipped\n"; } -//____________________________________________________________________________// - -void -colour_log_formatter::log_exception( +void colour_log_formatter::log_exception( std::ostream &output, log_checkpoint_data const &checkpoint_data, boost::execution_exception const &ex) { boost::execution_exception::location const &loc = ex.where(); - output << '\t' << BOLD_YELLOW_BEGIN << get_basename( - loc.m_file_name) + output << '\t' << BOLD_YELLOW_BEGIN + << get_basename(loc.m_file_name) << '(' << loc.m_line_num << "), "; output << "fatal error in \"" - << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function) << - "\": "; + << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function) + << "\": "; output << COLOR_END << ex.what(); @@ -222,26 +192,24 @@ colour_log_formatter::log_exception( output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name) << '(' << checkpoint_data.m_line_num << ")"; - if (!checkpoint_data.m_message.empty()) + if (!checkpoint_data.m_message.empty()) { output << ": " << checkpoint_data.m_message; + } } - output << std::endl; + output << '\n'; m_isTestCaseFailed = true; } -//____________________________________________________________________________// - -void -colour_log_formatter::log_entry_start( +void colour_log_formatter::log_entry_start( std::ostream &output, log_entry_data const &entry_data, log_entry_types let) { switch (let) { case BOOST_UTL_ET_INFO: - output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << - "), "; + output << '\t' << entry_data.m_file_name + << '(' << entry_data.m_line_num << "), "; output << "info: "; break; @@ -249,22 +217,22 @@ colour_log_formatter::log_entry_start( break; case BOOST_UTL_ET_WARNING: - output << '\t' << get_basename(entry_data.m_file_name) << '(' << - entry_data.m_line_num << "), "; + output << '\t' << get_basename(entry_data.m_file_name) + << '(' << entry_data.m_line_num << "), "; output << "warning in \"" << test_phase_identifier() << "\": "; break; case BOOST_UTL_ET_ERROR: - output << '\t' << BOLD_YELLOW_BEGIN << get_basename( - entry_data.m_file_name) + output << '\t' << BOLD_YELLOW_BEGIN + << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), "; output << "error in \"" << test_phase_identifier() << "\": "; m_isTestCaseFailed = true; break; case BOOST_UTL_ET_FATAL_ERROR: - output << '\t' << BOLD_YELLOW_BEGIN << get_basename( - entry_data.m_file_name) + output << '\t' << BOLD_YELLOW_BEGIN + << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), "; output << " fatal error in \"" << test_phase_identifier() << "\": "; m_isTestCaseFailed = true; @@ -274,40 +242,28 @@ colour_log_formatter::log_entry_start( output << COLOR_END; } -//____________________________________________________________________________// - -void -colour_log_formatter::log_entry_value( +void colour_log_formatter::log_entry_value( std::ostream &output, const_string value) { output << value; } -//____________________________________________________________________________// - -void -colour_log_formatter::log_entry_value( +void colour_log_formatter::log_entry_value( std::ostream &output, lazy_ostream const &value) { output << value; } -//____________________________________________________________________________// - -void -colour_log_formatter::log_entry_finish( +void colour_log_formatter::log_entry_finish( std::ostream &output) { - output << std::endl; + output << '\n'; } -//____________________________________________________________________________// - #if BOOST_VERSION >= 106501 -void -colour_log_formatter::log_exception_start( +void colour_log_formatter::log_exception_start( std::ostream& os, boost::unit_test::log_checkpoint_data const& lcd, boost::execution_exception const& ex) @@ -315,14 +271,12 @@ colour_log_formatter::log_exception_start( log_exception(os, lcd, ex); } -void -colour_log_formatter::log_exception_finish(std::ostream& os) +void colour_log_formatter::log_exception_finish(std::ostream& os) { (void)os; } -void -colour_log_formatter::entry_context_start( +void colour_log_formatter::entry_context_start( std::ostream& os, boost::unit_test::log_level l) { @@ -330,8 +284,7 @@ colour_log_formatter::entry_context_start( (void)l; } -void -colour_log_formatter::log_entry_context( +void colour_log_formatter::log_entry_context( std::ostream& os, boost::unit_test::log_level l, boost::unit_test::const_string value) @@ -341,8 +294,7 @@ colour_log_formatter::log_entry_context( (void)value; } -void -colour_log_formatter::entry_context_finish( +void colour_log_formatter::entry_context_finish( std::ostream& os, boost::unit_test::log_level l) { @@ -351,8 +303,4 @@ colour_log_formatter::entry_context_finish( } #endif -//____________________________________________________________________________// - } // namespace Yaca - -//____________________________________________________________________________// diff --git a/tests/colour_log_formatter.h b/tests/colour_log_formatter.h index 10c4b76..8760a74 100644 --- a/tests/colour_log_formatter.h +++ b/tests/colour_log_formatter.h @@ -12,66 +12,69 @@ * @version * @brief */ + #pragma once #include + namespace Yaca { + class colour_log_formatter : public boost::unit_test::unit_test_log_formatter { public: // Formatter interface colour_log_formatter() : m_isTestCaseFailed(false) {} - void log_start( + void log_start( std::ostream &, boost::unit_test::counter_t test_cases_amount); - void log_finish(std::ostream &); + void log_finish(std::ostream &); #if BOOST_VERSION >= 107000 - void log_build_info(std::ostream &, bool); + void log_build_info(std::ostream &, bool); #else - void log_build_info(std::ostream &); + void log_build_info(std::ostream &); #endif - void test_unit_start( + void test_unit_start( std::ostream &, boost::unit_test::test_unit const &tu); - void test_unit_finish( + void test_unit_finish( std::ostream &, boost::unit_test::test_unit const &tu, unsigned long elapsed); - void test_unit_skipped( + void test_unit_skipped( std::ostream &, boost::unit_test::test_unit const &tu); - void log_exception( + void log_exception( std::ostream &, boost::unit_test::log_checkpoint_data const &, boost::execution_exception const &ex); - void log_entry_start( + void log_entry_start( std::ostream &, boost::unit_test::log_entry_data const &, log_entry_types let); - void log_entry_value( + void log_entry_value( std::ostream &, boost::unit_test::const_string value); - void log_entry_value( + void log_entry_value( std::ostream &, boost::unit_test::lazy_ostream const &value); - void log_entry_finish(std::ostream &); + void log_entry_finish(std::ostream &); #if BOOST_VERSION >= 106501 - void log_exception_start( + void log_exception_start( std::ostream& os, boost::unit_test::log_checkpoint_data const& lcd, boost::execution_exception const& ex); - void log_exception_finish(std::ostream& os); - void entry_context_start( + void log_exception_finish(std::ostream& os); + void entry_context_start( std::ostream& os, boost::unit_test::log_level l); - void log_entry_context( + void log_entry_context( std::ostream& os, boost::unit_test::log_level l, boost::unit_test::const_string value); - void entry_context_finish( + void entry_context_finish( std::ostream& os, boost::unit_test::log_level l); #endif @@ -79,4 +82,5 @@ public: private: bool m_isTestCaseFailed; }; + } // namespace Yaca