ADTF  3.18.2
testmacros.h File Reference

Copyright © Audi Electronics Venture GmbH. More...

Go to the source code of this file.

Namespaces

 A_UTILS_NS
 ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
 

Macros

#define __a_utils_test_assert(_msg, _expr)    _assert((_expr), __FILE__, __LINE__)
 This macro creates an assertion if the expression fails using the given message. More...
 
#define __a_utils_test_report(_msg)    _assert(false, __FILE__, __LINE__)
 This macro creates an assertion using the given message. More...
 
#define __a_utils_test_log(_msg)    printf("%s(%d) %s\n", __FILE__, __LINE__, A_UTILS_NS::cString(_msg).GetPtr())
 This macro logs the given message to the standard output. More...
 
#define __a_utils_log_test_fail(_msg, _expr, _umsg)
 Logs a failed test and trows an exception. More...
 
#define __a_utils_log_test_succ(_msg, _expr, _umsg)
 Logs a successful test. More...
 
#define __a_utils_log_test(_msg, _expr)
 This macro. More...
 
#define __a_utils_log_test_ext(_msg, _expr, _umsg)
 This macro. More...
 
#define __a_utils_test(_expr)    __a_utils_log_test("test failed: (" #_expr ")", (_expr))
 This macro checks if the return value of the expression is true (bool) More...
 
#define __a_utils_test_err(_expr)    __a_utils_log_test("bad case test failed: (" #_expr ")", (!(_expr)))
 This macro checks if the return value of the expression is false (bool). More...
 
#define __a_utils_test_result(_expr)
 This macro checks the return value of the expression for equality to ERR_NOERROR (tResult) To report the result the __a_utils_log_test macro is used. More...
 
#define __a_utils_test_err_result(_expr)    __a_utils_log_test("bad case test failed: IS_FAILED(" #_expr ")", (IS_FAILED(_expr)))
 This macro checks the return value of the expression for inequality to ERR_NOERROR (tResult) To report the result the __a_utils_log_test macro is used. More...
 
#define __a_utils_test_pointer(_ptr)    __a_utils_log_test("test failed: (" #_ptr " != nullptr)", ((_ptr)!=nullptr))
 This macro checks the pointer to inequality to nullptr To report the result the __a_utils_log_test macro is used. More...
 
#define __a_utils_test_pointer_null(_ptr)    __a_utils_log_test("bad case test failed: (" #_ptr " != nullptr)", ((_ptr)==nullptr))
 This macro checks the pointer to equality to nullptr To report the result the __a_utils_log_test macro is used. More...
 
#define __a_utils_test_ext(_expr, _msg)    __a_utils_log_test_ext("test failed: (" #_expr ")", (_expr), (_msg))
 The same as __a_utils_test with an additional message To report the result the __a_utils_log_test_ext macro is used. More...
 
#define __a_utils_test_err_ext(_expr, _msg)    __a_utils_log_test_ext("bad case test failed: (" #_expr ")", (!(_expr)), (_msg))
 The same as __a_utils_test_err with an additional message. More...
 
#define __a_utils_test_result_ext(_expr, _msg)
 The same as __a_utils_test_result with an additional message. More...
 
#define __a_utils_test_err_result_ext(_expr, _msg)    __a_utils_log_test_ext("bad case test failed: IS_FAILED(" #_expr ")", (IS_FAILED(_expr)), (_msg))
 The same as __a_utils_test_err_result with an additional message. More...
 
#define __a_utils_test_pointer_ext(_ptr, _msg)    __a_utils_log_test_ext("test failed: (" #_ptr " != nullptr)", ((_ptr)!=nullptr), (_msg))
 The same as __a_utils_test_pointer with an additional message. More...
 
#define __a_utils_test_pointer_null_ext(_ptr, _msg)    __a_utils_log_test_ext("bad case test failed: (" #_ptr " != nullptr)", ((_ptr)==nullptr), (_msg))
 The same as __a_utils_test_pointer_null with an additional message. More...
 
#define __a_utils_test_file_exists(_filename)    __a_utils_test_ext(A_UTILS_NS::cFileSystem::Exists(_filename), _filename + A_UTILS_NS::cString(" does not exist"));
 The macro checks if the given file with the filename does exist. More...
 
#define DECLARE_TESTER_FRIEND(_tester, _whitebox)
 This macro declares a new class base on class /a _whitebox which is friend of class /a _tester. More...
 
#define __a_utils_test_friend(_whitebox)   _testable_##_whitebox
 This macro defines the name of the whitebox test class based on class /a _whitebox.
 
#define RETURN_TEST_NOERROR
 This macro returns value if test is OK. More...
 
#define RETURN_TEST_ERROR(_code)
 This macro returns _code if test failes. More...
 
#define DECLARE_TESTER_CLASS(_classname)    class _classname : public ITester
 This macro has to be used to declare a new tester class. More...
 
#define BEGIN_TESTER_MAP(_classname)
 This macro creates the tester map. More...
 
#define DECLARE_TESTER_FUNCTION(_func)
 This macro defines a test that will be executed. More...
 
#define END_TESTER_MAP()
 This macro closes the tester map. More...
 
#define DECLARE_TESTER_CLASS(_classname)    class _classname : public ITester
 This macro has to be used to declare a new tester class. More...
 
#define IMPLEMENT_TESTER_CLASS(_classname, _id, _title, _desc, _req)
 This macro implements a conrete test class / test group. More...
 

Detailed Description

Copyright © Audi Electronics Venture GmbH.

All rights reserved

Definition in file testmacros.h.

Macro Definition Documentation

◆ __a_utils_log_test

#define __a_utils_log_test (   _msg,
  _expr 
)
Value:
if (!(_expr)) \
{ \
__a_utils_log_test_fail(_msg, _expr, nullptr) \
} \
else \
{ \
__a_utils_log_test_succ(_msg, _expr, nullptr) \
}

This macro.

Parameters
[in]_msgAdditional information which will be logged
[in]_exprThe expression which will be executed

Definition at line 333 of file testmacros.h.

◆ __a_utils_log_test_ext

#define __a_utils_log_test_ext (   _msg,
  _expr,
  _umsg 
)
Value:
if (!(_expr)) \
{ \
__a_utils_log_test_fail(_msg, _expr, _umsg) \
} \
else \
{ \
__a_utils_log_test_succ(_msg, _expr, _umsg) \
}

This macro.

Parameters
[in]_msgAdditional information which will be logged
[in]_exprThe expression which will be executed
[in]_umsgUser defined message

Definition at line 351 of file testmacros.h.

◆ __a_utils_log_test_fail

#define __a_utils_log_test_fail (   _msg,
  _expr,
  _umsg 
)
Value:
{ \
__get_testbench()->Log(ITestBench::TEST_LOG_FAILED, _msg, #_expr, __FILE__, __LINE__, __FUNCTION__, _umsg); \
throw "test failed"; \
}
@ TEST_LOG_FAILED
log when failed
Definition: testbench.h:181

Logs a failed test and trows an exception.

Parameters
[in]_msgAdditional information which will be logged
[in]_exprThe expression which failed
[in]_umsgAdditional message that is logged (can be nullptr)

Definition at line 309 of file testmacros.h.

◆ __a_utils_log_test_succ

#define __a_utils_log_test_succ (   _msg,
  _expr,
  _umsg 
)
Value:
{ \
__get_testbench()->Log(ITestBench::TEST_LOG_PASSED, _msg, #_expr, __FILE__, __LINE__, __FUNCTION__, _umsg); \
}
@ TEST_LOG_PASSED
log when passed
Definition: testbench.h:180

Logs a successful test.

Parameters
[in]_msgAdditional information which will be logged
[in]_exprThe expression which failed
[in]_umsgAdditional message that is logged (can be nullptr)

Definition at line 321 of file testmacros.h.

◆ __a_utils_test

#define __a_utils_test (   _expr)     __a_utils_log_test("test failed: (" #_expr ")", (_expr))

This macro checks if the return value of the expression is true (bool)

Parameters
[in]_exprThe expression which will be executed

Definition at line 368 of file testmacros.h.

◆ __a_utils_test_assert

#define __a_utils_test_assert (   _msg,
  _expr 
)     _assert((_expr), __FILE__, __LINE__)

This macro creates an assertion if the expression fails using the given message.

Parameters
[in]_msgAdditional information which will be logged
[in]_exprThe expression which will be executed

Definition at line 66 of file testmacros.h.

◆ __a_utils_test_err

#define __a_utils_test_err (   _expr)     __a_utils_log_test("bad case test failed: (" #_expr ")", (!(_expr)))

This macro checks if the return value of the expression is false (bool).

To report the result the __a_utils_log_test macro is used.

Parameters
[in]_exprThe expression which will be executed

Definition at line 379 of file testmacros.h.

◆ __a_utils_test_err_ext

#define __a_utils_test_err_ext (   _expr,
  _msg 
)     __a_utils_log_test_ext("bad case test failed: (" #_expr ")", (!(_expr)), (_msg))

The same as __a_utils_test_err with an additional message.

Parameters
[in]_exprThe expression which will be executed
[in]_msgAdditional information which will be logged

Definition at line 457 of file testmacros.h.

◆ __a_utils_test_err_result

#define __a_utils_test_err_result (   _expr)     __a_utils_log_test("bad case test failed: IS_FAILED(" #_expr ")", (IS_FAILED(_expr)))

This macro checks the return value of the expression for inequality to ERR_NOERROR (tResult) To report the result the __a_utils_log_test macro is used.

Parameters
[in]_exprThe expression which will be executed

Definition at line 412 of file testmacros.h.

◆ __a_utils_test_err_result_ext

#define __a_utils_test_err_result_ext (   _expr,
  _msg 
)     __a_utils_log_test_ext("bad case test failed: IS_FAILED(" #_expr ")", (IS_FAILED(_expr)), (_msg))

The same as __a_utils_test_err_result with an additional message.

Parameters
[in]_exprThe expression which will be executed
[in]_msgAdditional information which will be logged

Definition at line 490 of file testmacros.h.

◆ __a_utils_test_ext

#define __a_utils_test_ext (   _expr,
  _msg 
)     __a_utils_log_test_ext("test failed: (" #_expr ")", (_expr), (_msg))

The same as __a_utils_test with an additional message To report the result the __a_utils_log_test_ext macro is used.

Parameters
[in]_exprThe expression which will be executed
[in]_msgAdditional information which will be logged

Definition at line 446 of file testmacros.h.

◆ __a_utils_test_file_exists

#define __a_utils_test_file_exists (   _filename)     __a_utils_test_ext(A_UTILS_NS::cFileSystem::Exists(_filename), _filename + A_UTILS_NS::cString(" does not exist"));

The macro checks if the given file with the filename does exist.

To report the result the __a_utils_test_ext macro is used.

Parameters
[in]_filenameThe filename which will be checked

Definition at line 523 of file testmacros.h.

◆ __a_utils_test_log

#define __a_utils_test_log (   _msg)     printf("%s(%d) %s\n", __FILE__, __LINE__, A_UTILS_NS::cString(_msg).GetPtr())

This macro logs the given message to the standard output.

Parameters
[in]_msgAdditional information which will be logged

Definition at line 86 of file testmacros.h.

◆ __a_utils_test_pointer

#define __a_utils_test_pointer (   _ptr)     __a_utils_log_test("test failed: (" #_ptr " != nullptr)", ((_ptr)!=nullptr))

This macro checks the pointer to inequality to nullptr To report the result the __a_utils_log_test macro is used.

Parameters
[in]_ptrThe pointer which will be checked

Definition at line 423 of file testmacros.h.

◆ __a_utils_test_pointer_ext

#define __a_utils_test_pointer_ext (   _ptr,
  _msg 
)     __a_utils_log_test_ext("test failed: (" #_ptr " != nullptr)", ((_ptr)!=nullptr), (_msg))

The same as __a_utils_test_pointer with an additional message.

Parameters
[in]_ptrThe pointer which will be checked
[in]_msgAdditional information which will be logged

Definition at line 501 of file testmacros.h.

◆ __a_utils_test_pointer_null

#define __a_utils_test_pointer_null (   _ptr)     __a_utils_log_test("bad case test failed: (" #_ptr " != nullptr)", ((_ptr)==nullptr))

This macro checks the pointer to equality to nullptr To report the result the __a_utils_log_test macro is used.

Parameters
[in]_ptrThe pointer which will be checked

Definition at line 434 of file testmacros.h.

◆ __a_utils_test_pointer_null_ext

#define __a_utils_test_pointer_null_ext (   _ptr,
  _msg 
)     __a_utils_log_test_ext("bad case test failed: (" #_ptr " != nullptr)", ((_ptr)==nullptr), (_msg))

The same as __a_utils_test_pointer_null with an additional message.

Parameters
[in]_ptrThe pointer which will be checked
[in]_msgAdditional information which will be logged

Definition at line 512 of file testmacros.h.

◆ __a_utils_test_report

#define __a_utils_test_report (   _msg)     _assert(false, __FILE__, __LINE__)

This macro creates an assertion using the given message.

Parameters
[in]_msgAdditional information which will be logged

Definition at line 76 of file testmacros.h.

◆ __a_utils_test_result

#define __a_utils_test_result (   _expr)
Value:
{\
tResult __nHelperResult = _expr; \
if (IS_FAILED(__nHelperResult)) \
{\
__a_utils_test_log(A_UTILS_NS::cString::Format(#_expr " returned error code: %d (description: %s)", __nHelperResult.GetErrorCode().value, __nHelperResult.GetDescription()));\
__a_utils_log_test_fail("test failed: IS_OK(" #_expr ")", IS_OK(_expr), nullptr);\
}\
else \
{ \
__a_utils_log_test_succ("test failed: IS_OK(" #_expr ")", IS_OK(_expr), nullptr);\
} \
}
static _myType Format(const value_type *strFormat,...)
Write formatted data to a string.
Definition: string.h:2399

This macro checks the return value of the expression for equality to ERR_NOERROR (tResult) To report the result the __a_utils_log_test macro is used.

Parameters
[in]_exprThe expression which will be executed

Definition at line 390 of file testmacros.h.

◆ __a_utils_test_result_ext

#define __a_utils_test_result_ext (   _expr,
  _msg 
)
Value:
{\
tResult __nHelperResult = _expr; \
if (IS_FAILED(__nHelperResult)) \
{\
__a_utils_test_log(A_UTILS_NS::cString::Format(#_expr " returned error code: %d", __nHelperResult.GetErrorCode()));\
__a_utils_log_test_fail("test failed: IS_OK(" #_expr ")", IS_OK(_expr), (_msg));\
}\
else \
{ \
__a_utils_log_test_succ("test failed: IS_OK(" #_expr ")", IS_OK(_expr), (_msg));\
} \
}

The same as __a_utils_test_result with an additional message.

Parameters
[in]_exprThe expression which will be executed
[in]_msgAdditional information which will be logged

Definition at line 468 of file testmacros.h.

◆ BEGIN_TESTER_MAP

#define BEGIN_TESTER_MAP (   _classname)
Value:
public: \
_classname(); \
const char* getClassName(); \
virtual void run() {

This macro creates the tester map.

all tests that will be executed are inserted between BEGIN_TESTER_MAP and END_TESTER_MAP

Parameters
[in]_classnamename of the test implementation class

Definition at line 584 of file testmacros.h.

◆ DECLARE_TESTER_CLASS [1/2]

#define DECLARE_TESTER_CLASS (   _classname)     class _classname : public ITester

This macro has to be used to declare a new tester class.

This macro creates the basic testclass implementation.

This has to be done at least once for a test.

Parameters
[in]_classnameThe class name i.e. cTesterAlsaPlayback
[in]_classnameThe class which includes the test cases (functions)

Definition at line 633 of file testmacros.h.

◆ DECLARE_TESTER_CLASS [2/2]

#define DECLARE_TESTER_CLASS (   _classname)     class _classname : public ITester

This macro has to be used to declare a new tester class.

This macro creates the basic testclass implementation.

This has to be done at least once for a test.

Parameters
[in]_classnameThe class name i.e. cTesterAlsaPlayback
[in]_classnameThe class which includes the test cases (functions)

Definition at line 633 of file testmacros.h.

◆ DECLARE_TESTER_FRIEND

#define DECLARE_TESTER_FRIEND (   _tester,
  _whitebox 
)
Value:
class _testable_##_whitebox : public _whitebox \
{ friend class _tester; };

This macro declares a new class base on class /a _whitebox which is friend of class /a _tester.

Definition at line 536 of file testmacros.h.

◆ DECLARE_TESTER_FUNCTION

#define DECLARE_TESTER_FUNCTION (   _func)
Value:
extern tTestDoc sFunctionDoc_##_func; \
__get_testbench()->LogStartFunction(&sFunctionDoc_##_func); \
if (sFunctionDoc_##_func.bActive) \
{ \
try \
{ \
setUp(); \
_func(); \
} \
catch (const char*) { } \
try \
{ \
tearDown(); \
} \
catch (const char*) { } \
} \
__get_testbench()->LogStopFunction(&sFunctionDoc_##_func); \
This structure defines a test case.
Definition: testbench.h:16

This macro defines a test that will be executed.

Parameters
[in]_funcThe name of the test function

Definition at line 597 of file testmacros.h.

◆ END_TESTER_MAP

#define END_TESTER_MAP ( )
Value:
} \
tTestGroupDoc* getDoc();

This macro closes the tester map.

See also
BEGIN_TESTER_MAP

Definition at line 622 of file testmacros.h.

◆ IMPLEMENT_TESTER_CLASS

#define IMPLEMENT_TESTER_CLASS (   _classname,
  _id,
  _title,
  _desc,
  _req 
)
Value:
static _classname _instance_##_classname; \
_classname::_classname() \
const char* _classname::getClassName() \
{ return #_classname; } \
tTestGroupDoc* _classname::getDoc() \
{ \
static tTestGroupDoc sDoc= { _id, _title, _desc, _req }; \
return &sDoc; \
}
virtual void RegisterTester(ITester *pTester)=0
Registers a new tester at the test bench.
This structure defines a group of test cases.
Definition: testbench.h:33
ITestBench * __get_testbench()
This function will return the pointer to the currently active test bench.

This macro implements a conrete test class / test group.

Parameters
[in]_classnameName of the testclass
[in]_idIdentifier of the group
[in]_titleTitle of the group
[in]_descProvides a short description
[in]_reqLinks to the related requirements

Definition at line 733 of file testmacros.h.

◆ RETURN_TEST_ERROR

#define RETURN_TEST_ERROR (   _code)

This macro returns _code if test failes.

Parameters
[in]_codereturn code

Definition at line 563 of file testmacros.h.

◆ RETURN_TEST_NOERROR

#define RETURN_TEST_NOERROR

This macro returns value if test is OK.

Definition at line 554 of file testmacros.h.