summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2017-04-28 14:20:27 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2017-05-11 15:34:14 +0900
commitbe4d3c878d664c050df88c00e6b9557c9f4ca45e (patch)
tree6152589c5a096364461b04a926f70e6f2c16039d
parent7a29f6023922d7e11ca319941b59e6a3083895c8 (diff)
downloadcsr-framework-be4d3c878d664c050df88c00e6b9557c9f4ca45e.tar.gz
csr-framework-be4d3c878d664c050df88c00e6b9557c9f4ca45e.tar.bz2
csr-framework-be4d3c878d664c050df88c00e6b9557c9f4ca45e.zip
Fix log fomatter according to boost version upgrade
Change-Id: Iba8af0d1900230375550258f0daaf68db641925e Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
-rw-r--r--test/colour_log_formatter.cpp112
-rw-r--r--test/colour_log_formatter.h56
-rw-r--r--test/internals/CMakeLists.txt1
-rw-r--r--test/internals/test-main.cpp6
-rw-r--r--test/popup/test-main.cpp2
-rw-r--r--test/test-common.h2
-rw-r--r--test/test-macro.h27
-rw-r--r--test/test-main.cpp4
-rw-r--r--test/thread-pool/test-main.cpp2
-rw-r--r--test/thread-pool/test-thread-pool.cpp2
10 files changed, 169 insertions, 45 deletions
diff --git a/test/colour_log_formatter.cpp b/test/colour_log_formatter.cpp
index e90df77..6240b3a 100644
--- a/test/colour_log_formatter.cpp
+++ b/test/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 Csr
diff --git a/test/colour_log_formatter.h b/test/colour_log_formatter.h
index aa47acd..998188e 100644
--- a/test/colour_log_formatter.h
+++ b/test/colour_log_formatter.h
@@ -22,40 +22,42 @@ 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_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(std::ostream &,
+ boost::unit_test::log_checkpoint_data const &,
+ boost::execution_exception const &ex);
- 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_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 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/internals/CMakeLists.txt b/test/internals/CMakeLists.txt
index 67c4f95..aac9ecc 100644
--- a/test/internals/CMakeLists.txt
+++ b/test/internals/CMakeLists.txt
@@ -70,6 +70,7 @@ INCLUDE_DIRECTORIES(
)
INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/test
${PROJECT_SOURCE_DIR}/src/include/csr
${PROJECT_SOURCE_DIR}/src/include/csre
${CSR_FW_SRC_PATH}
diff --git a/test/internals/test-main.cpp b/test/internals/test-main.cpp
index c9c16b3..84333d2 100644
--- a/test/internals/test-main.cpp
+++ b/test/internals/test-main.cpp
@@ -28,6 +28,8 @@
#include <csre-content-screening.h>
#include <csre-web-protection.h>
+#include "test-macro.h"
+
struct TestConfig {
TestConfig()
{
@@ -39,7 +41,7 @@ struct TestConfig {
}
};
-BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(TestConfig);
#ifdef WITH_SAMPLE_ENGINE
bool isEngineInitialized = false;
@@ -75,5 +77,5 @@ struct Initializer {
}
};
-BOOST_GLOBAL_FIXTURE(Initializer)
+BOOST_GLOBAL_FIXTURE(Initializer);
#endif
diff --git a/test/popup/test-main.cpp b/test/popup/test-main.cpp
index 446e5bd..ad3c19e 100644
--- a/test/popup/test-main.cpp
+++ b/test/popup/test-main.cpp
@@ -36,4 +36,4 @@ struct TestConfig {
}
};
-BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(TestConfig);
diff --git a/test/test-common.h b/test/test-common.h
index 1a99416..e886c02 100644
--- a/test/test-common.h
+++ b/test/test-common.h
@@ -40,6 +40,8 @@
#include <csre-content-screening.h>
#include <csre-web-protection.h>
+#include "test-macro.h"
+
#ifndef __FILENAME__
#define __FILENAME__ (::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
diff --git a/test/test-macro.h b/test/test-macro.h
new file mode 100644
index 0000000..3c29fc7
--- /dev/null
+++ b/test/test-macro.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file test-macro.h
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @version 1.0
+ */
+#pragma once
+
+#include <iostream>
+
+#ifndef BOOST_MESSAGE
+#define BOOST_MESSAGE(x) std::cout << x << std::endl;
+#endif
diff --git a/test/test-main.cpp b/test/test-main.cpp
index 8f0207f..f661504 100644
--- a/test/test-main.cpp
+++ b/test/test-main.cpp
@@ -103,5 +103,5 @@ struct Initializer {
csr_state_e m_oldWpState;
};
-BOOST_GLOBAL_FIXTURE(TestConfig)
-BOOST_GLOBAL_FIXTURE(Initializer)
+BOOST_GLOBAL_FIXTURE(TestConfig);
+BOOST_GLOBAL_FIXTURE(Initializer);
diff --git a/test/thread-pool/test-main.cpp b/test/thread-pool/test-main.cpp
index 82d38ff..35c4440 100644
--- a/test/thread-pool/test-main.cpp
+++ b/test/thread-pool/test-main.cpp
@@ -36,4 +36,4 @@ struct TestConfig {
}
};
-BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(TestConfig);
diff --git a/test/thread-pool/test-thread-pool.cpp b/test/thread-pool/test-thread-pool.cpp
index e5ed8e9..70a61c6 100644
--- a/test/thread-pool/test-thread-pool.cpp
+++ b/test/thread-pool/test-thread-pool.cpp
@@ -30,6 +30,8 @@
#include <ctime>
#include <boost/test/unit_test.hpp>
+#include "test-macro.h"
+
using namespace std::chrono;
namespace {