summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2017-05-12 14:11:02 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2017-05-12 14:11:02 +0900
commit0eecf5c7803707224969d71a7ca3c06838b787bd (patch)
tree61a304a0d43b01c12e434eaf0fc8a4716ea6831a
parent66e03d5f1993d5bdf9c0c0b778afdf99eefff847 (diff)
downloadlibwebappenc-0eecf5c7803707224969d71a7ca3c06838b787bd.tar.gz
libwebappenc-0eecf5c7803707224969d71a7ca3c06838b787bd.tar.bz2
libwebappenc-0eecf5c7803707224969d71a7ca3c06838b787bd.zip
Fix log fomatter according to boost version upgrade
Change-Id: I45ebc7ad1e47ae1c6be71be50a50d5ad4a1330c9 Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
-rw-r--r--tests/colour_log_formatter.cpp112
-rw-r--r--tests/colour_log_formatter.h10
-rw-r--r--tests/test-helper.h5
3 files changed, 115 insertions, 12 deletions
diff --git a/tests/colour_log_formatter.cpp b/tests/colour_log_formatter.cpp
index 50bd43c..087951f 100644
--- a/tests/colour_log_formatter.cpp
+++ b/tests/colour_log_formatter.cpp
@@ -14,7 +14,12 @@
#include <iostream>
#include <string>
+#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 @@ const char *BOLD_YELLOW_BEGIN = "\033[1;33m";
const char *COLOR_END = "\033[m";
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
@@ -56,6 +79,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
//____________________________________________________________________________//
@@ -98,11 +127,12 @@ 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;
- else
- output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" <<
+ if (test_unit_type_name_contains(tu, "suite")) {
+ output << "Starting test ";
+ } else {
+ output << "Running test ";
+ }
+ output << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" <<
std::endl;
}
@@ -114,8 +144,8 @@ 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 << "\"" <<
+ if (test_unit_type_name_contains(tu, "suite")) {
+ output << "Finished test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" <<
std::endl;
return;
}
@@ -152,8 +182,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;
}
//____________________________________________________________________________//
@@ -187,6 +217,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' << 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 << 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
@@ -260,6 +325,29 @@ colour_log_formatter::log_entry_finish(
//____________________________________________________________________________//
+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 Test
} // namespace Wae
diff --git a/tests/colour_log_formatter.h b/tests/colour_log_formatter.h
index 7c5dee3..968f6be 100644
--- a/tests/colour_log_formatter.h
+++ b/tests/colour_log_formatter.h
@@ -41,6 +41,11 @@ 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 &,
@@ -54,6 +59,11 @@ public:
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;
};
diff --git a/tests/test-helper.h b/tests/test-helper.h
index cd2fae2..8ec45c0 100644
--- a/tests/test-helper.h
+++ b/tests/test-helper.h
@@ -22,6 +22,11 @@
#include "types.h"
+#ifndef BOOST_MESSAGE
+#include <iostream>
+#define BOOST_MESSAGE(x) std::cout << x << std::endl;
+#endif
+
namespace Wae {
namespace Test {