Fix log fomatter according to boost version upgrade 13/128713/1
authorsangwan.kwon <sangwan.kwon@samsung.com>
Thu, 11 May 2017 04:12:31 +0000 (13:12 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Thu, 11 May 2017 06:28:11 +0000 (15:28 +0900)
Change-Id: Ie85dd3af6ba12968bddfdb2dbececc7ee01f719c
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
test/colour_log_formatter.cpp
test/colour_log_formatter.h
test/main.cpp
test/popup_test_main.cpp

index 08ef10d..a40d2c2 100644 (file)
  * @version     1.0
  * @brief       color formatter for test output.
  */
+#include <boost/test/impl/execution_monitor.ipp>
+#if BOOST_VERSION >= 105900
+#include <boost/test/tree/test_unit.hpp>
+#else
 #include <boost/test/unit_test_suite_impl.hpp>
+#endif
 #include <boost/test/framework.hpp>
 #include <boost/test/utils/basic_cstring/io.hpp>
 #include <boost/test/utils/lazy_ostream.hpp>
@@ -37,11 +42,29 @@ namespace TPKP {
 namespace {
 
 const_string
+test_unit_type_name(const test_unit &tu)
+{
+#if BOOST_VERSION >= 105900
+    return const_string(tu.p_type_name);
+#else
+    return tu.p_type_name.get();
+#endif
+}
+
+const_string
+test_unit_name(const test_unit &tu)
+{
+#if BOOST_VERSION >= 105900
+    return const_string(tu.p_name);
+#else
+    return tu.p_name.get();
+#endif
+}
+
+const_string
 test_phase_identifier()
 {
-    return framework::is_initialized()
-            ? const_string( framework::current_test_case().p_name.get() )
-            : BOOST_TEST_L( "Test setup" );
+    return test_unit_name(framework::current_test_case());
 }
 
 const_string
@@ -54,6 +77,12 @@ 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)
+{
+    return test_unit_type_name(tu).find(const_string(substr)) == 0;
+}
+
 } // local namespace
 
 //____________________________________________________________________________//
@@ -96,11 +125,13 @@ colour_log_formatter::test_unit_start(
         std::ostream& output,
         test_unit const& tu )
 {
-    if (tu.p_type_name->find(const_string("suite")) == 0) {
-        output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
+    if (test_unit_type_name_contains(tu, "suite")) {
+        output << "Starting test ";
     } else {
-        output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
+        output << "Running test ";
     }
+    output << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" <<
+              std::endl;
 }
 
 //____________________________________________________________________________//
@@ -111,10 +142,12 @@ colour_log_formatter::test_unit_finish(
         test_unit const& tu,
         unsigned long elapsed )
 {
-    if (tu.p_type_name->find(const_string("suite")) == 0) {
-        output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\""<< std::endl;
+    if (test_unit_type_name_contains(tu, "suite")) {
+        output << "Finished test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu)
+               << "\"" << std::endl;
         return;
     }
+
     std::string color = TPKP::Colors::Text::GREEN_BEGIN;
     std::string status = "OK";
     if (m_isTestCaseFailed) {
@@ -145,7 +178,8 @@ colour_log_formatter::test_unit_skipped(
         std::ostream& output,
         test_unit const& tu )
 {
-    output  << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
+    output << "Test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu)
+           << "\"" << "is skipped" << std::endl;
 }
 
 //____________________________________________________________________________//
@@ -177,6 +211,41 @@ colour_log_formatter::log_exception(
     m_isTestCaseFailed = true;
 }
 
+void
+colour_log_formatter::log_exception_start(
+    std::ostream &output,
+    log_checkpoint_data const &checkpoint_data,
+    boost::execution_exception const &ex)
+{
+    boost::execution_exception::location const &loc = ex.where();
+    output << '\t' << TPKP::Colors::Text::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) <<
+           "\": ";
+
+    output << TPKP::Colors::Text::COLOR_END << ex.what();
+
+    if (!checkpoint_data.m_file_name.is_empty()) {
+        output << '\n';
+        output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name)
+               << '(' << checkpoint_data.m_line_num << ")";
+
+        if (!checkpoint_data.m_message.empty())
+            output << ": " << checkpoint_data.m_message;
+    }
+
+    output << std::endl;
+    m_isTestCaseFailed = true;
+}
+
+void
+colour_log_formatter::log_exception_finish(std::ostream &os)
+{
+    os.flush();
+}
+
 //____________________________________________________________________________//
 
 void
@@ -241,4 +310,27 @@ colour_log_formatter::log_entry_finish(
     output << std::endl;
 }
 
+void
+colour_log_formatter::entry_context_start(
+        std::ostream& output,
+        boost::unit_test::log_level l)
+{
+    output << (l == log_successful_tests ? "\nAssertion" : "\nFailure")
+           << " occurred in a following context:";
+}
+
+void
+colour_log_formatter::log_entry_context(
+        std::ostream& output,
+        boost::unit_test::const_string value)
+{
+    output << "\n    " << value;
+}
+
+void
+colour_log_formatter::entry_context_finish(std::ostream& output)
+{
+    output.flush();
+}
+
 } // namespace TPKP
index b36838a..cadb4d4 100644 (file)
@@ -49,6 +49,10 @@ public:
                 std::ostream&,
                 boost::unit_test::log_checkpoint_data const&,
                 boost::execution_exception const& ex );
+    void    log_exception_start(std::ostream &,
+                                boost::unit_test::log_checkpoint_data const &,
+                                boost::execution_exception const &ex);
+    void    log_exception_finish(std::ostream &os);
 
     void    log_entry_start(
                 std::ostream&,
@@ -61,6 +65,11 @@ public:
                 std::ostream&,
                 boost::unit_test::lazy_ostream const& value );
     void    log_entry_finish( std::ostream& );
+    void    entry_context_start(std::ostream& os, boost::unit_test::log_level l);
+    void    log_entry_context(std::ostream& os,
+                              boost::unit_test::const_string value);
+    void    entry_context_finish(std::ostream& os);
+
 private:
     bool m_isTestCaseFailed;
 };
index cb9670f..7e06b47 100644 (file)
@@ -35,4 +35,4 @@ struct TestConfig {
        }
 };
 
-BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(TestConfig);
index 21b2e4e..fa1e757 100644 (file)
@@ -35,4 +35,4 @@ struct TestConfig {
        }
 };
 
-BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(TestConfig);