From: Kyungwook Tak Date: Mon, 13 Jun 2016 06:13:19 +0000 (+0900) Subject: Change assert to warn on init state on test X-Git-Tag: accepted/tizen/common/20160614.143943^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F86%2F74186%2F1;p=platform%2Fupstream%2Fcsr-framework.git Change assert to warn on init state on test Change-Id: Iccbdb614c48ef1036a7cf8bd1b439a0a162a6103 Signed-off-by: Kyungwook Tak --- diff --git a/test/test-api-content-screening-async.cpp b/test/test-api-content-screening-async.cpp index 96b70b9..2b26cd4 100644 --- a/test/test-api-content-screening-async.cpp +++ b/test/test-api-content-screening-async.cpp @@ -109,10 +109,10 @@ void on_error(int ec, void *userdata) BOOST_REQUIRE_MESSAGE(ctx->apiReturned, "API not returned yet but error callback called with error: " << - Test::capi_ec_to_string(static_cast(ec))); + Test::capi_ec_to_string(ec)); BOOST_MESSAGE("on_error. async request done with error: " << - Test::capi_ec_to_string(static_cast(ec))); + Test::capi_ec_to_string(ec)); ctx->errorCnt++; ctx->errorCode = ec; diff --git a/test/test-common.cpp b/test/test-common.cpp index d2c00bf..44e49d9 100644 --- a/test/test-common.cpp +++ b/test/test-common.cpp @@ -135,6 +135,11 @@ std::string capi_ec_to_string(csr_error_e ec) } #undef ERRORDESCRIBE +std::string capi_ec_to_string(int ec) +{ + return capi_ec_to_string(static_cast(ec)); +} + template <> void _assert(const csr_error_e &value, const csr_error_e &expected, @@ -169,14 +174,12 @@ void _assert(const csr_error_e &value, BOOST_REQUIRE_MESSAGE(value == expected, "[" << filename << " > " << funcname << " : " << line << "] returned[" << capi_ec_to_string(value) << "] expected[" << - capi_ec_to_string(static_cast(expected)) << - "] " << msg); + 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(static_cast(expected)) << - "] " << msg); + capi_ec_to_string(expected) << "] " << msg); } template <> @@ -191,11 +194,11 @@ void _assert(const int &value, if (isAssert) BOOST_REQUIRE_MESSAGE(value == expected, "[" << filename << " > " << funcname << " : " << line << - "] returned[" << capi_ec_to_string(static_cast(value)) << + "] returned[" << capi_ec_to_string(value) << "] expected[" << capi_ec_to_string(expected) << "] " << msg); BOOST_WARN_MESSAGE(value == expected, "[" << filename << " > " << funcname << " : " << line << - "] returned[" << capi_ec_to_string(static_cast(value)) << + "] returned[" << capi_ec_to_string(value) << "] expected[" << capi_ec_to_string(expected) << "] " << msg); } diff --git a/test/test-common.h b/test/test-common.h index 76fa328..6d86c39 100644 --- a/test/test-common.h +++ b/test/test-common.h @@ -183,6 +183,7 @@ void _assert(char * const &value, void exceptionGuard(const std::function &); std::string capi_ec_to_string(csr_error_e ec); +std::string capi_ec_to_string(int ec); void make_dir(const char *dir); void make_dir_assert(const char *dir); diff --git a/test/test-main.cpp b/test/test-main.cpp index 9623b46..8f0207f 100644 --- a/test/test-main.cpp +++ b/test/test-main.cpp @@ -29,6 +29,8 @@ #include +#include "test-common.h" + namespace { csr_state_e setEngineState(csr_engine_id_e id, csr_state_e state) @@ -36,27 +38,37 @@ csr_state_e setEngineState(csr_engine_id_e id, csr_state_e state) csr_engine_h handle; auto ret = csr_get_current_engine(id, &handle); if (ret == CSR_ERROR_ENGINE_NOT_EXIST) { - std::cerr << "Engine not exist! engine id: " << static_cast(id) << std::endl; + BOOST_MESSAGE("engine not exist! engine id: " << static_cast(id)); + return CSR_STATE_DISABLE; } else if (ret != CSR_ERROR_NONE) { - throw std::logic_error("Failed to csr_get_current_engine."); + BOOST_MESSAGE( + "Failed to csr_get_current_engine with ret: " << + Test::capi_ec_to_string(ret)); + + return CSR_STATE_DISABLE; } - csr_state_e current; + csr_state_e current = CSR_STATE_DISABLE; ret = csr_engine_get_state(handle, ¤t); if (ret == CSR_ERROR_ENGINE_NOT_EXIST) { - std::cerr << "Engine not exist! engine id: " << static_cast(id) << std::endl; + BOOST_MESSAGE("Engine not exist! engine id: " << static_cast(id)); return CSR_STATE_DISABLE; } else if (ret != CSR_ERROR_NONE) { - throw std::logic_error("Failed to csr_get_state."); + BOOST_MESSAGE( + "Failed to csr_engine_get_state with ret: " << + Test::capi_ec_to_string(ret)); + + return CSR_STATE_DISABLE; } if (current == state) return current; ret = csr_engine_set_state(handle, state); - if (ret != CSR_ERROR_NONE) - throw std::logic_error("Failed to csr_engine_set_state."); + BOOST_WARN_MESSAGE(ret != CSR_ERROR_NONE, + "Failed to csr_engine_set_state with ret: " << + Test::capi_ec_to_string(ret)); return current; }