IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Macros
UnitTestMacros.h File Reference

Predefined macros for unit test management. More...

#include <IPSDKUtil/Tools/ProcessingResult.h>
#include <UnitTest/IPSDKUnitTestTools/ImgComparison.h>

Go to the source code of this file.

Macros

#define IPSDK_UT_CHECK_BOOLRESULT(predicate)
 macro allowing to test (in unit test case meaning) a BoolResult value More...
 
#define IPSDK_UT_CHECK_BOOLRESULT_FALSE(predicate)
 macro allowing to test (in unit test case meaning) that a BoolResult value is false More...
 
#define IPSDK_UT_GET_LOG()
 Allow to obtain the instance of UnitTestLog. More...
 
#define IPSDK_UT_LOG_TEST_RES(strPrefix, boolRes)
 Notify the UnitTestLog of the test result. More...
 
#define IPSDK_UT_SUITE_START(UnitTestSuiteName)
 Defines a fixture that initializes a pointer to the UnitTestLog instance and notify for the start of the test suite UnitTestSuiteName. More...
 
#define IPSDK_UT_SUITE_END()
 
#define IPSDK_UT_CASE_START(UnitTestCaseName)
 Starts the test case "UnitTestCaseName" and notifies the UnitTestLog instance. More...
 
#define IPSDK_UT_CASE_END()
 Ends the test case. More...
 
#define IPSDK_UT_CHECK(P)
 Calls and complete BOOST_CHECK by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_MESSAGE(P, M)
 Calls and complete BOOST_CHECK_MESSAGE by notifying the UnitTestLog instance. More...
 
#define IPSDK_TEST_MESSAGE(M)
 Calls and complete BOOST_TEST_MESSAGE by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_EQUAL(V1, V2)
 Calls and complete BOOST_CHECK_EQUAL by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_NE(V1, V2)
 Calls and complete BOOST_CHECK_NE by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_NE_STR(V1, V2)
 Calls and complete BOOST_CHECK_NE by notifying the UnitTestLog instance when V1 and V2 are strings. More...
 
#define IPSDK_CHECK_LT(V1, V2)
 Calls and complete BOOST_CHECK_LT by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_GE(V1, V2)
 Calls and complete BOOST_CHECK_GE by notifying the UnitTestLog instance. More...
 
#define IPSDK_CHECK_CLOSE(V1, V2, TOL)
 Calls and complete BOOST_CHECK_CLOSE by notifying the UnitTestLog instance The test succeeds if abs(V1-V2)/V1*100 < TOL. More...
 
#define IPSDK_CHECK_THROW(statement, exception)
 Check if statement throws an exception and calls BOOST_CHECK_THROW. More...
 
#define IPSDK_CHECK_NO_THROW(statement)
 Check if statement throws an exception and calls BOOST_CHECK_NO_THROW. More...
 
#define IPSDK_REQUIRE(P)
 Check if the predicate P is respected. More...
 
#define IPSDK_REQUIRE_MESSAGE(P, M)
 Check if the predicate P is respected and displays the message M. More...
 
#define IPSDK_WARN_LT(V1, V2)
 Calls and complete BOOST_WARN_LT by notifying the UnitTestLog instance. More...
 

Detailed Description

Predefined macros for unit test management.

Author
E. Noirfalise
Date
2015/07/23

Macro Definition Documentation

◆ IPSDK_UT_CHECK_BOOLRESULT

#define IPSDK_UT_CHECK_BOOLRESULT (   predicate)
Value:
{ \
BoolResult bRes = predicate; \
BOOST_CHECK_MESSAGE(bRes == true, bRes.getMsg()); \
}

macro allowing to test (in unit test case meaning) a BoolResult value

◆ IPSDK_UT_CHECK_BOOLRESULT_FALSE

#define IPSDK_UT_CHECK_BOOLRESULT_FALSE (   predicate)
Value:
{ \
BoolResult bRes = predicate; \
BOOST_CHECK_MESSAGE(bRes == false, bRes.getMsg()); \
}

macro allowing to test (in unit test case meaning) that a BoolResult value is false

◆ IPSDK_UT_GET_LOG

#define IPSDK_UT_GET_LOG ( )
Value:
boost::unit_test::unit_test_log_formatter* pLogFormatter = boost::unit_test::unit_test_log.get_formatter(boost::unit_test::OF_CUSTOM_LOGGER); \
ipsdk::unittest::UnitTestLog* pUnitTestLog = static_cast<ipsdk::unittest::UnitTestLog*>(pLogFormatter);
Custom log formatter for unit tests.
Definition: UnitTestLog.h:43

Allow to obtain the instance of UnitTestLog.

◆ IPSDK_UT_LOG_TEST_RES

#define IPSDK_UT_LOG_TEST_RES (   strPrefix,
  boolRes 
)
Value:
if(boolRes.getResult()) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, strPrefix + " Success : " + boolRes.getMsg()); \
} \
else{ \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, " Failure : " + boolRes.getMsg()); \
}
#define IPSDK_UT_GET_LOG()
Allow to obtain the instance of UnitTestLog.
Definition: UnitTestMacros.h:44

Notify the UnitTestLog of the test result.

◆ IPSDK_UT_SUITE_START

#define IPSDK_UT_SUITE_START (   UnitTestSuiteName)
Value:
namespace { \
struct Fixture { \
Fixture() \
{ \
boost::unit_test::unit_test_log_formatter* pLogFormatter = \
boost::unit_test::unit_test_log.get_formatter(boost::unit_test::OF_CUSTOM_LOGGER); \
pUnitTestLog = static_cast<ipsdk::unittest::UnitTestLog*>(pLogFormatter); \
} \
~Fixture() {} \
ipsdk::unittest::UnitTestLog* pUnitTestLog; \
}; \
} \
BOOST_FIXTURE_TEST_SUITE(UnitTestSuiteName, Fixture) \
BOOST_AUTO_TEST_CASE(SuiteStart) \
{ \
pUnitTestLog->notifyTestSuiteStart(BOOST_PP_STRINGIZE(UnitTestSuiteName)); \
}
void notifyTestSuiteStart(const std::string &testSuiteName)
method allowing to notify of test suite start
Custom log formatter for unit tests.
Definition: UnitTestLog.h:43

Defines a fixture that initializes a pointer to the UnitTestLog instance and notify for the start of the test suite UnitTestSuiteName.

Ends of the test suite.

Note
An aditional test case named "SuiteStart" is necessary and is created by the macro

◆ IPSDK_UT_SUITE_END

#define IPSDK_UT_SUITE_END ( )
Value:
BOOST_AUTO_TEST_CASE(SuiteStop) \
{ \
pUnitTestLog->notifyTestSuiteEnd(); \
} \
BOOST_AUTO_TEST_SUITE_END()

◆ IPSDK_UT_CASE_START

#define IPSDK_UT_CASE_START (   UnitTestCaseName)
Value:
BOOST_AUTO_TEST_CASE(UnitTestCaseName) \
{ \
pUnitTestLog->notifyTestCaseStart(BOOST_PP_STRINGIZE(UnitTestCaseName));

Starts the test case "UnitTestCaseName" and notifies the UnitTestLog instance.

◆ IPSDK_UT_CASE_END

#define IPSDK_UT_CASE_END ( )
Value:
pUnitTestLog->notifyTestCaseEnd(); \
}

Ends the test case.

◆ IPSDK_UT_CHECK

#define IPSDK_UT_CHECK (   P)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(P) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : for ") + BOOST_PP_STRINGIZE(P)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : for " ) + BOOST_PP_STRINGIZE(P)); \
} \
BOOST_CHECK(P); \
} while(0)

Calls and complete BOOST_CHECK by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_MESSAGE

#define IPSDK_CHECK_MESSAGE (   P,
 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(P) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + M + " for " + BOOST_PP_STRINGIZE(P)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + M + " for " + BOOST_PP_STRINGIZE(P)); \
} \
BOOST_CHECK_MESSAGE(P, M); \
} while(0)

Calls and complete BOOST_CHECK_MESSAGE by notifying the UnitTestLog instance.

◆ IPSDK_TEST_MESSAGE

#define IPSDK_TEST_MESSAGE (   M)
Value:
do { \
IPSDK_UT_GET_LOG() \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + M); \
BOOST_TEST_MESSAGE(M); \
} while(0)

Calls and complete BOOST_TEST_MESSAGE by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_EQUAL

#define IPSDK_CHECK_EQUAL (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 == V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + BOOST_PP_STRINGIZE(V1 == V2)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + BOOST_PP_STRINGIZE(V1 == V2)); \
} \
BOOST_CHECK_EQUAL(V1, V2); \
} while(0)

Calls and complete BOOST_CHECK_EQUAL by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_NE

#define IPSDK_CHECK_NE (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 != V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \
std::to_string(V1) + " != " + std::to_string(V2)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \
std::to_string(V1) + " != " + std::to_string(V2)); \
} \
BOOST_CHECK_NE(V1, V2); \
} while(0)

Calls and complete BOOST_CHECK_NE by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_NE_STR

#define IPSDK_CHECK_NE_STR (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 != V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + V1 + " != " + V2); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + V1 + " != " + V2); \
} \
BOOST_CHECK_NE(V1, V2); \
} while(0)

Calls and complete BOOST_CHECK_NE by notifying the UnitTestLog instance when V1 and V2 are strings.

◆ IPSDK_CHECK_LT

#define IPSDK_CHECK_LT (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 < V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \
std::to_string(V1) + " < " + std::to_string(V2)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \
std::to_string(V1) + " < " + std::to_string(V2)); \
} \
BOOST_CHECK_LT(V1, V2); \
} while(0)

Calls and complete BOOST_CHECK_LT by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_GE

#define IPSDK_CHECK_GE (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 >= V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \
std::to_string(V1) + " >= " + std::to_string(V2)); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : ") + \
std::to_string(V1) + " >= " + std::to_string(V2)); \
} \
BOOST_CHECK_GE(V1, V2); \
} while(0)

Calls and complete BOOST_CHECK_GE by notifying the UnitTestLog instance.

◆ IPSDK_CHECK_CLOSE

#define IPSDK_CHECK_CLOSE (   V1,
  V2,
  TOL 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if((V1 != 0 ? std::abs((V1)-(V2)) / V1 * 100 : 0) < TOL) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : Comparison between ") + \
BOOST_PP_STRINGIZE(V1) + "(" + std::to_string(V1) + ") and " + \
BOOST_PP_STRINGIZE(V2) + "(" + std::to_string(V2) + ") doesn't exceed " + \
std::to_string(TOL) + "%"); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Failure : Comparison between ") + \
BOOST_PP_STRINGIZE(V1) + "(" + std::to_string(V1) + ") and " + \
BOOST_PP_STRINGIZE(V2) + "(" + std::to_string(V2) + ") doesn't exceed " + \
std::to_string(TOL) + "%"); \
} \
BOOST_CHECK_CLOSE(V1, V2, TOL); \
} while(0)
IPSDK_FORCEINLINE PackT abs(const PackT &in)
returns the absolute value of a pack
Definition: abs.h:41

Calls and complete BOOST_CHECK_CLOSE by notifying the UnitTestLog instance The test succeeds if abs(V1-V2)/V1*100 < TOL.

◆ IPSDK_CHECK_THROW

#define IPSDK_CHECK_THROW (   statement,
  exception 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
try { \
statement; \
} \
catch (...) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, "Exception correctly caught"); \
BOOST_CHECK_THROW(statement, exception); \
} \
} while(0)

Check if statement throws an exception and calls BOOST_CHECK_THROW.

◆ IPSDK_CHECK_NO_THROW

#define IPSDK_CHECK_NO_THROW (   statement)
Value:
do { \
IPSDK_UT_GET_LOG() \
try { \
statement; \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, "No Exception thrown"); \
} \
catch (const std::exception& e) { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string("Exception caught : ") + e.what()); \
BOOST_CHECK_NO_THROW(statement); \
} \
} while(0)

Check if statement throws an exception and calls BOOST_CHECK_NO_THROW.

◆ IPSDK_REQUIRE

#define IPSDK_REQUIRE (   P)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(P) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Check ") + BOOST_PP_STRINGIZE(P) + " has passed"); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Check " ) + BOOST_PP_STRINGIZE(P) + " has passed"); \
} \
BOOST_REQUIRE(P); \
} while(0)

Check if the predicate P is respected.

◆ IPSDK_REQUIRE_MESSAGE

#define IPSDK_REQUIRE_MESSAGE (   P,
 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(P) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Check ") + BOOST_PP_STRINGIZE(P) + " has passed :" + M); \
} \
else { \
pUnitTestLog->notifyTestFailure(__FILE__, __LINE__, std::string(" Check " ) + BOOST_PP_STRINGIZE(P) + " has passed:" + M); \
} \
BOOST_REQUIRE_MESSAGE(P, M); \
} while(0)

Check if the predicate P is respected and displays the message M.

◆ IPSDK_WARN_LT

#define IPSDK_WARN_LT (   V1,
  V2 
)
Value:
do { \
IPSDK_UT_GET_LOG() \
if(V1 < V2) { \
pUnitTestLog->notifyTestSuccess(__FILE__, __LINE__, std::string(" Success : ") + \
std::to_string(V1) + " < " + std::to_string(V2)); \
} \
else { \
pUnitTestLog->notifyTestWarning(__FILE__, __LINE__, std::string(" Warning: ") + \
std::to_string(V1) + " < " + std::to_string(V2)); \
} \
BOOST_WARN_LT(V1, V2); \
} while(0)

Calls and complete BOOST_WARN_LT by notifying the UnitTestLog instance.