From 4404ca6189677c562eda2b5df0eb17b89b914550 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Thu, 9 Jun 2016 14:00:48 +0900 Subject: [PATCH] Add warn_if on test Change-Id: I7a066ad8509bdeb1f0afe4afd5a8ff6b3b39d80a Signed-off-by: Kyungwook Tak --- test/test-common.cpp | 102 +++++++++++++++++++++++++++++++++++---------------- test/test-common.h | 41 +++++++++++++++++---- 2 files changed, 104 insertions(+), 39 deletions(-) diff --git a/test/test-common.cpp b/test/test-common.cpp index 38ff458..adb44ce 100644 --- a/test/test-common.cpp +++ b/test/test-common.cpp @@ -140,12 +140,19 @@ void _assert(const csr_error_e &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - BOOST_REQUIRE_MESSAGE(value == expected, - "[" << filename << " > " << funcname << " : " << line << "]" << - " returned[" << capi_ec_to_string(value) << - "] expected[" << capi_ec_to_string(expected) << "] " << msg); + if (isAssert) + BOOST_REQUIRE_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "]" << " returned[" << capi_ec_to_string(value) << + "] expected[" << capi_ec_to_string(expected) << "] " << msg); + else + BOOST_WARN_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << capi_ec_to_string(value) << + "] expected[" << capi_ec_to_string(expected) << "] " << msg); } template <> @@ -154,13 +161,21 @@ void _assert(const csr_error_e &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - BOOST_REQUIRE_MESSAGE(value == expected, - "[" << filename << " > " << funcname << " : " << line << "]" << - " returned[" << capi_ec_to_string(value) << "] expected[" << - capi_ec_to_string(static_cast(expected)) << "]" << - " " << msg); + if (isAssert) + BOOST_REQUIRE_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << capi_ec_to_string(value) << "] expected[" << + capi_ec_to_string(static_cast(expected)) << + "] " << msg); + else + BOOST_WARN_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << capi_ec_to_string(value) << "] expected[" << + capi_ec_to_string(static_cast(expected)) << + "] " << msg); } template <> @@ -169,13 +184,18 @@ void _assert(const int &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - BOOST_REQUIRE_MESSAGE(value == expected, - "[" << filename << " > " << funcname << " : " << line << "]" << - " returned[" << - capi_ec_to_string(static_cast(value)) << - "] expected[" << capi_ec_to_string(expected) << "] " << msg); + if (isAssert) + BOOST_REQUIRE_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << capi_ec_to_string(static_cast(value)) << + "] expected[" << capi_ec_to_string(expected) << "] " << msg); + BOOST_WARN_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << capi_ec_to_string(static_cast(value)) << + "] expected[" << capi_ec_to_string(expected) << "] " << msg); } template <> @@ -184,21 +204,36 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - if (value == nullptr && expected == nullptr) - BOOST_REQUIRE(true); - else if (value != nullptr && expected != nullptr) + if (value == nullptr && expected == nullptr) { + if (isAssert) + BOOST_REQUIRE(true); + else + BOOST_WARN(true); + } else if (value != nullptr && expected != nullptr) { _assert(std::string(value), expected, filename, - funcname, line, msg); - else if (value == nullptr && expected != nullptr) - BOOST_REQUIRE_MESSAGE(std::string(expected).empty(), - "[" << filename << " > " << funcname << " : " << line << - "] returned[nullptr] expected[" << expected << "] " << msg); - else - BOOST_REQUIRE_MESSAGE(std::string(value).empty(), - "[" << filename << " > " << funcname << " : " << line << - "] returned[" << value << "] expected[nullptr] " << msg); + funcname, line, isAssert, msg); + } else if (value == nullptr && expected != nullptr) { + if (isAssert) + BOOST_REQUIRE_MESSAGE(std::string(expected).empty(), + "[" << filename << " > " << funcname << " : " << line << + "] returned[nullptr] expected[" << expected << "] " << msg); + else + BOOST_WARN_MESSAGE(std::string(expected).empty(), + "[" << filename << " > " << funcname << " : " << line << + "] returned[nullptr] expected[" << expected << "] " << msg); + } else { + if (isAssert) + BOOST_REQUIRE_MESSAGE(std::string(value).empty(), + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << value << "] expected[nullptr] " << msg); + else + BOOST_WARN_MESSAGE(std::string(value).empty(), + "[" << filename << " > " << funcname << " : " << line << + "] returned[" << value << "] expected[nullptr] " << msg); + } } template <> @@ -207,9 +242,10 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - _assert(value, expected, filename, funcname, line, msg); + _assert(value, expected, filename, funcname, line, isAssert, msg); } template <> @@ -218,9 +254,10 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - _assert(value, expected, filename, funcname, line, msg); + _assert(value, expected, filename, funcname, line, isAssert, msg); } template <> @@ -229,9 +266,10 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - _assert(value, expected, filename, funcname, line, msg); + _assert(value, expected, filename, funcname, line, isAssert, msg); } template <> @@ -240,11 +278,12 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { _assert( (value == nullptr) ? std::string() : std::string(value), - expected, filename, funcname, line, msg); + expected, filename, funcname, line, isAssert, msg); } template <> @@ -253,9 +292,10 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg) { - _assert(value, expected, filename, funcname, line, msg); + _assert(value, expected, filename, funcname, line, isAssert, msg); } void exceptionGuard(const std::function &f) diff --git a/test/test-common.h b/test/test-common.h index 66c919f..8e83223 100644 --- a/test/test-common.h +++ b/test/test-common.h @@ -49,13 +49,22 @@ 0, std::ios_base::cur) << ITEMS)).str() #define ASSERT_IF_MSG(value, expected, msg) \ - Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, TOSTRING(msg)) + Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, true, TOSTRING(msg)) + +#define WARN_IF_MSG(value, expected, msg) \ + Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, false, TOSTRING(msg)) #define ASSERT_IF(value, expected) \ - Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, "") + Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, true, "") + +#define WARN_IF(value, expected) \ + Test::_assert(value, expected, __FILENAME__, __func__, __LINE__, false, "") #define ASSERT_SUCCESS(value) \ - Test::_assert(value, CSR_ERROR_NONE, __FILENAME__, __func__, __LINE__, "") + Test::_assert(value, CSR_ERROR_NONE, __FILENAME__, __func__, __LINE__, true, "") + +#define WARN_SUCCESS(value) \ + Test::_assert(value, CSR_ERROR_NONE, __FILENAME__, __func__, __LINE__, false, "") #define ASSERT_INSTALL_APP(path, type) \ BOOST_REQUIRE_MESSAGE(Test::install_app(path, type), \ @@ -75,12 +84,19 @@ namespace Test { template void _assert(const T &value, const U &expected, const std::string &filename, - const std::string &funcname, unsigned int line, const std::string &msg) + const std::string &funcname, unsigned int line, bool isAssert, + const std::string &msg) { - BOOST_REQUIRE_MESSAGE(value == expected, - "[" << filename << " > " << funcname << " : " << line << "]" << - " returned[" << value << "] expected[" << expected << - "] " << msg); + if (isAssert) + BOOST_REQUIRE_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "]" << " returned[" << value << "] expected[" << expected << + "] " << msg); + else + BOOST_WARN_MESSAGE(value == expected, + "[" << filename << " > " << funcname << " : " << line << + "]" << " returned[" << value << "] expected[" << expected << + "] " << msg); } template <> @@ -89,6 +105,7 @@ void _assert(const csr_error_e &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -97,6 +114,7 @@ void _assert(const csr_error_e &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -105,6 +123,7 @@ void _assert(const int &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -113,6 +132,7 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -121,6 +141,7 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -129,6 +150,7 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -137,6 +159,7 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -145,6 +168,7 @@ void _assert(const char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); template <> @@ -153,6 +177,7 @@ void _assert(char * const &value, const std::string &filename, const std::string &funcname, unsigned int line, + bool isAssert, const std::string &msg); void exceptionGuard(const std::function &); -- 2.7.4