Add warn_if on test 45/73645/2
authorKyungwook Tak <k.tak@samsung.com>
Thu, 9 Jun 2016 05:00:48 +0000 (14:00 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Thu, 9 Jun 2016 09:18:24 +0000 (18:18 +0900)
Change-Id: I7a066ad8509bdeb1f0afe4afd5a8ff6b3b39d80a
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
test/test-common.cpp
test/test-common.h

index 38ff458..adb44ce 100644 (file)
@@ -140,12 +140,19 @@ void _assert<csr_error_e, csr_error_e>(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<csr_error_e, int>(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<csr_error_e>(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<csr_error_e>(expected)) <<
+                                                         "] " << msg);
+       else
+               BOOST_WARN_MESSAGE(value == expected,
+                                                         "[" << filename << " > " << funcname << " : " << line <<
+                                                         "] returned[" << capi_ec_to_string(value) << "] expected[" <<
+                                                         capi_ec_to_string(static_cast<csr_error_e>(expected)) <<
+                                                         "] " << msg);
 }
 
 template <>
@@ -169,13 +184,18 @@ void _assert<int, csr_error_e>(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<csr_error_e>(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<csr_error_e>(value)) <<
+                                                         "] expected[" << capi_ec_to_string(expected) << "] " << msg);
+               BOOST_WARN_MESSAGE(value == expected,
+                                                  "[" << filename << " > " << funcname << " : " << line <<
+                                                  "] returned[" << capi_ec_to_string(static_cast<csr_error_e>(value)) <<
+                                                  "] expected[" << capi_ec_to_string(expected) << "] " << msg);
 }
 
 template <>
@@ -184,21 +204,36 @@ void _assert<const char *, const char *>(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, const char *>(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 char *>(char * const &value,
                                                                   const std::string &filename,
                                                                   const std::string &funcname,
                                                                   unsigned int line,
+                                                                  bool isAssert,
                                                                   const std::string &msg)
 {
-       _assert<const char *, const char *>(value, expected, filename, funcname, line, msg);
+       _assert<const char *, const char *>(value, expected, filename, funcname, line, isAssert, msg);
 }
 
 template <>
@@ -218,9 +254,10 @@ void _assert<const char *, char *>(const char * const &value,
                                                                   const std::string &filename,
                                                                   const std::string &funcname,
                                                                   unsigned int line,
+                                                                  bool isAssert,
                                                                   const std::string &msg)
 {
-       _assert<const char *, const char *>(value, expected, filename, funcname, line, msg);
+       _assert<const char *, const char *>(value, expected, filename, funcname, line, isAssert, msg);
 }
 
 template <>
@@ -229,9 +266,10 @@ void _assert<char *, char *>(char * const &value,
                                                         const std::string &filename,
                                                         const std::string &funcname,
                                                         unsigned int line,
+                                                        bool isAssert,
                                                         const std::string &msg)
 {
-       _assert<const char *, const char *>(value, expected, filename, funcname, line, msg);
+       _assert<const char *, const char *>(value, expected, filename, funcname, line, isAssert, msg);
 }
 
 template <>
@@ -240,11 +278,12 @@ void _assert<const char *, std::string>(const char * const &value,
                                                                                const std::string &filename,
                                                                                const std::string &funcname,
                                                                                unsigned int line,
+                                                                               bool isAssert,
                                                                                const std::string &msg)
 {
        _assert<std::string, std::string>(
                        (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 *, std::string>(char * const &value,
                                                                  const std::string &filename,
                                                                  const std::string &funcname,
                                                                  unsigned int line,
+                                                                 bool isAssert,
                                                                  const std::string &msg)
 {
-       _assert<const char *, std::string>(value, expected, filename, funcname, line, msg);
+       _assert<const char *, std::string>(value, expected, filename, funcname, line, isAssert, msg);
 }
 
 void exceptionGuard(const std::function<void()> &f)
index 66c919f..8e83223 100644 (file)
                                                                                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 <typename T, typename U>
 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<csr_error_e, csr_error_e>(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<csr_error_e, int>(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<int, csr_error_e>(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 char *>(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 char *>(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 *, char *>(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 *, char *>(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 *, std::string>(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 *, std::string>(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<void()> &);