15 #ifndef __IPSDKUNITTESTTOOLS_UNITTESTMACROS_H__ 16 #define __IPSDKUNITTESTTOOLS_UNITTESTMACROS_H__ 18 #include <IPSDKUtil/Tools/ProcessingResult.h> 26 #define IPSDK_UT_CHECK_BOOLRESULT(predicate) \ 28 BoolResult bRes = predicate; \ 29 BOOST_CHECK_MESSAGE(bRes == true, bRes.getMsg()); \ 35 #define IPSDK_UT_CHECK_BOOLRESULT_FALSE(predicate) \ 37 BoolResult bRes = predicate; \ 38 BOOST_CHECK_MESSAGE(bRes == false, bRes.getMsg()); \ 44 #define IPSDK_UT_GET_LOG() \ 45 boost::unit_test::unit_test_log_formatter* pLogFormatter = boost::unit_test::unit_test_log.get_formatter(boost::unit_test::OF_CUSTOM_LOGGER); \ 46 ipsdk::unittest::UnitTestLog* pUnitTestLog = static_cast<ipsdk::unittest::UnitTestLog*>(pLogFormatter); 50 #define IPSDK_UT_LOG_TEST_RES(strPrefix, boolRes) \ 52 if(boolRes.getResult()) { \ 53 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, strPrefix + " Success : " + boolRes.getMsg()); \ 56 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, " Failure : " + boolRes.getMsg()); \ 63 #define IPSDK_UT_SUITE_START(UnitTestSuiteName) \ 68 boost::unit_test::unit_test_log_formatter* pLogFormatter = \ 69 boost::unit_test::unit_test_log.get_formatter(boost::unit_test::OF_CUSTOM_LOGGER); \ 70 pUnitTestLog = static_cast<ipsdk::unittest::UnitTestLog*>(pLogFormatter); \ 73 ipsdk::unittest::UnitTestLog* pUnitTestLog; \ 76 BOOST_FIXTURE_TEST_SUITE(UnitTestSuiteName, Fixture) \ 77 BOOST_AUTO_TEST_CASE(SuiteStart) \ 79 pUnitTestLog->notifyTestSuiteStart(BOOST_PP_STRINGIZE(UnitTestSuiteName)); \ 85 #define IPSDK_UT_SUITE_END() \ 86 BOOST_AUTO_TEST_CASE(SuiteStop) \ 88 pUnitTestLog->notifyTestSuiteEnd(); \ 90 BOOST_AUTO_TEST_SUITE_END() 94 #define IPSDK_UT_CASE_START(UnitTestCaseName) \ 95 BOOST_AUTO_TEST_CASE(UnitTestCaseName) \ 97 pUnitTestLog->notifyTestCaseStart(BOOST_PP_STRINGIZE(UnitTestCaseName)); 101 #define IPSDK_UT_CASE_END() \ 102 pUnitTestLog->notifyTestCaseEnd(); \ 107 #define IPSDK_UT_CHECK(P) \ 111 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : for ") + BOOST_PP_STRINGIZE(P)); \ 114 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : for " ) + BOOST_PP_STRINGIZE(P)); \ 121 #define IPSDK_CHECK_MESSAGE(P, M) \ 125 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + M + " for " + BOOST_PP_STRINGIZE(P)); \ 128 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + M + " for " + BOOST_PP_STRINGIZE(P)); \ 130 BOOST_CHECK_MESSAGE(P, M); \ 135 #define IPSDK_TEST_MESSAGE(M) \ 138 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + M); \ 139 BOOST_TEST_MESSAGE(M); \ 144 #define IPSDK_CHECK_EQUAL(V1, V2) \ 148 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + BOOST_PP_STRINGIZE(V1 == V2)); \ 151 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + BOOST_PP_STRINGIZE(V1 == V2)); \ 153 BOOST_CHECK_EQUAL(V1, V2); \ 158 #define IPSDK_CHECK_NE(V1, V2) \ 162 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \ 163 std::to_string(V1) + " != " + std::to_string(V2)); \ 166 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \ 167 std::to_string(V1) + " != " + std::to_string(V2)); \ 169 BOOST_CHECK_NE(V1, V2); \ 174 #define IPSDK_CHECK_NE_STR(V1, V2) \ 178 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + V1 + " != " + V2); \ 181 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + V1 + " != " + V2); \ 183 BOOST_CHECK_NE(V1, V2); \ 188 #define IPSDK_CHECK_LT(V1, V2) \ 192 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \ 193 std::to_string(V1) + " < " + std::to_string(V2)); \ 196 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \ 197 std::to_string(V1) + " < " + std::to_string(V2)); \ 199 BOOST_CHECK_LT(V1, V2); \ 204 #define IPSDK_CHECK_GE(V1, V2) \ 208 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \ 209 std::to_string(V1) + " >= " + std::to_string(V2)); \ 212 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \ 213 std::to_string(V1) + " >= " + std::to_string(V2)); \ 215 BOOST_CHECK_GE(V1, V2); \ 221 #define IPSDK_CHECK_CLOSE(V1, V2, TOL) \ 224 if((V1 != 0 ? std::abs((V1)-(V2)) / V1 * 100 : 0) < TOL) { \ 225 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : Comparison between ") + \ 226 BOOST_PP_STRINGIZE(V1) + "(" + std::to_string(V1) + ") and " + \ 227 BOOST_PP_STRINGIZE(V2) + "(" + std::to_string(V2) + ") doesn't exceed " + \ 228 std::to_string(TOL) + "%"); \ 231 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : Comparison between ") + \ 232 BOOST_PP_STRINGIZE(V1) + "(" + std::to_string(V1) + ") and " + \ 233 BOOST_PP_STRINGIZE(V2) + "(" + std::to_string(V2) + ") doesn't exceed " + \ 234 std::to_string(TOL) + "%"); \ 236 BOOST_CHECK_CLOSE(V1, V2, TOL); \ 241 #define IPSDK_CHECK_THROW(statement, exception) \ 248 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, "Exception correctly caught"); \ 249 BOOST_CHECK_THROW(statement, exception); \ 255 #define IPSDK_CHECK_NO_THROW(statement) \ 260 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, "No Exception thrown"); \ 262 catch (const std::exception& e) { \ 263 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string("Exception caught : ") + e.what()); \ 264 BOOST_CHECK_NO_THROW(statement); \ 270 #define IPSDK_REQUIRE(P) \ 274 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Check ") + BOOST_PP_STRINGIZE(P) + " has passed"); \ 277 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Check " ) + BOOST_PP_STRINGIZE(P) + " has passed"); \ 284 #define IPSDK_REQUIRE_MESSAGE(P, M) \ 288 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Check ") + BOOST_PP_STRINGIZE(P) + " has passed :" + M); \ 291 pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Check " ) + BOOST_PP_STRINGIZE(P) + " has passed:" + M); \ 293 BOOST_REQUIRE_MESSAGE(P, M); \ 299 #define IPSDK_WARN_LT(V1, V2) \ 303 pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \ 304 std::to_string(V1) + " < " + std::to_string(V2)); \ 307 pUnitTestLog->notifyTestWarning(__FILE__, __LINE__, std::string(" Warning: ") + \ 308 std::to_string(V1) + " < " + std::to_string(V2)); \ 310 BOOST_WARN_LT(V1, V2); \ 317 #endif // __IPSDKUNITTESTTOOLS_UNITTESTMACROS_H__ Predefined types for unit tests management.