From 6e602d845479a0701421d4077d7f1f199b001ffc Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Mon, 24 Apr 2017 12:35:09 +0200 Subject: [PATCH] Adjust tests to boost 1.62 * Fix missing file * Fix missing virtual methods * Fix missing semicolons after macros * Support boost version before 1.59 * Fix custom types printing * Still support boost before 1.59 version Change-Id: I872dff727aef3f4253e4995e36654ad93d1b979d --- test/colour_log_formatter.cpp | 78 ++++++++++++++++++++++++++++++++------ test/colour_log_formatter.h | 50 ++++++++++-------------- test/security-manager-tests.cpp | 4 +- test/test_privilege_db_sharing.cpp | 50 ++++++++++++++++++++---- 4 files changed, 131 insertions(+), 51 deletions(-) diff --git a/test/colour_log_formatter.cpp b/test/colour_log_formatter.cpp index 69ae6f0..eefaa6c 100644 --- a/test/colour_log_formatter.cpp +++ b/test/colour_log_formatter.cpp @@ -14,7 +14,12 @@ */ // Boost.Test #include +#include +#if BOOST_VERSION >= 105900 +#include +#else #include +#endif #include #include #include @@ -36,13 +41,30 @@ using namespace boost::unit_test; namespace SecurityManager { 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 @@ -57,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 //____________________________________________________________________________// @@ -99,13 +127,14 @@ 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; + } //____________________________________________________________________________// @@ -116,8 +145,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; } @@ -156,14 +185,14 @@ colour_log_formatter::test_unit_skipped( std::ostream &output, test_unit const &tu) { - output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << + output << "Test " << test_unit_type_name(tu) << " \"" << test_unit_name(tu) << "\"" << "is skipped" << std::endl; } //____________________________________________________________________________// void -colour_log_formatter::log_exception( +colour_log_formatter::log_exception_start( std::ostream &output, log_checkpoint_data const &checkpoint_data, boost::execution_exception const &ex) @@ -195,6 +224,14 @@ colour_log_formatter::log_exception( //____________________________________________________________________________// void +colour_log_formatter::log_exception_finish(std::ostream &os) +{ + (void)os; +} + +//____________________________________________________________________________// + +void colour_log_formatter::log_entry_start( std::ostream &output, log_entry_data const &entry_data, @@ -267,6 +304,23 @@ colour_log_formatter::log_entry_finish( //____________________________________________________________________________// +void +colour_log_formatter::entry_context_start(std::ostream& os, boost::unit_test::log_level l) +{ + (void)os; + (void)l; +} +void +colour_log_formatter::log_entry_context(std::ostream& os, boost::unit_test::const_string value) +{ + (void)os; + (void)value; +} +void +colour_log_formatter::entry_context_finish(std::ostream& os) +{ + (void)os; +} //____________________________________________________________________________// } // namespace SecurityManager diff --git a/test/colour_log_formatter.h b/test/colour_log_formatter.h index f245713..5a38e0a 100644 --- a/test/colour_log_formatter.h +++ b/test/colour_log_formatter.h @@ -20,39 +20,29 @@ class colour_log_formatter : public boost::unit_test::unit_test_log_formatter { public: // Formatter interface colour_log_formatter() : m_isTestCaseFailed(false) {} - void log_start( - std::ostream &, - boost::unit_test::counter_t test_cases_amount); - void log_finish(std::ostream &); - void log_build_info(std::ostream &); + void log_start(std::ostream &, boost::unit_test::counter_t test_cases_amount); + void log_finish(std::ostream &); + void log_build_info(std::ostream &); - void test_unit_start( - std::ostream &, - boost::unit_test::test_unit const &tu); - void test_unit_finish( - std::ostream &, - boost::unit_test::test_unit const &tu, - unsigned long elapsed); - void test_unit_skipped( - std::ostream &, - boost::unit_test::test_unit const &tu); + void test_unit_start(std::ostream &, boost::unit_test::test_unit const &tu); + void test_unit_finish(std::ostream &, boost::unit_test::test_unit const &tu, + unsigned long elapsed); + void test_unit_skipped(std::ostream &, boost::unit_test::test_unit const &tu); - void log_exception( - 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 &, - boost::unit_test::log_entry_data const &, - log_entry_types let); - void log_entry_value( - std::ostream &, - boost::unit_test::const_string value); - void log_entry_value( - std::ostream &, - boost::unit_test::lazy_ostream const &value); - void log_entry_finish(std::ostream &); + void log_entry_start(std::ostream &, boost::unit_test::log_entry_data const &, + log_entry_types let); + void log_entry_value(std::ostream &, boost::unit_test::const_string value); + void log_entry_value(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; diff --git a/test/security-manager-tests.cpp b/test/security-manager-tests.cpp index 2f160c5..90eb391 100644 --- a/test/security-manager-tests.cpp +++ b/test/security-manager-tests.cpp @@ -49,5 +49,5 @@ struct LogSetup { ~LogSetup() {} }; -BOOST_GLOBAL_FIXTURE(TestConfig) -BOOST_GLOBAL_FIXTURE(LogSetup) +BOOST_GLOBAL_FIXTURE(TestConfig); +BOOST_GLOBAL_FIXTURE(LogSetup); diff --git a/test/test_privilege_db_sharing.cpp b/test/test_privilege_db_sharing.cpp index 0a0a920..c1e3ef4 100644 --- a/test/test_privilege_db_sharing.cpp +++ b/test/test_privilege_db_sharing.cpp @@ -19,6 +19,7 @@ * @version 1.0 */ +#include #include #include #include @@ -32,30 +33,65 @@ #include "privilege_db.h" #include "privilege_db_fixture.h" +#if BOOST_VERSION >= 105900 + +namespace boost { + +namespace test_tools { + +namespace tt_detail { + +// tell boost howto print pair of std::string and std::vector +template +struct print_log_value>> { + void operator()(std::ostream& os, std::pair> const& pr) { + os << "<" << std::get<0>(pr) << ","; + os << '['; + bool first = true; + for (auto &element : std::get<1>(pr)) { + os << (!first ? "," : "") << element; + first = false; + } + os << ']'; + } +}; + +} //namespace tt_detail + +} //namespace test_tools + +} //namespace boost + +#else + namespace boost { -// tell boost howto print vector -template wrap_stringstream& -operator<<(wrap_stringstream &wrapped, const std::vector &elements) + +// tell Boost.Test how to print std::vector +template +inline wrap_stringstream& +operator<<(wrap_stringstream &wrapped, const std::vector &item) { wrapped << '['; bool first = true; - for (auto &element : elements) { + for (const auto& element : item) { wrapped << (!first ? "," : "") << element; first = false; } return wrapped << ']'; } -// tell boost howto print pair -template wrap_stringstream& -operator<<(wrap_stringstream &wrapped, const std::pair &item) +// teach Boost.Test how to print std::pair +template +inline wrap_stringstream &operator<<(wrap_stringstream &wrapped, const std::pair &item) { return wrapped << '<' << item.first << ',' << item.second << '>'; } } //namespace boost +#endif + typedef std::map> PrivateSharingMap; //Fixture for sharing -- 2.7.4