Common header needed by generated stubs
This commit is contained in:
33
resources/header/stub.h
Normal file
33
resources/header/stub.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*!
|
||||||
|
* @file
|
||||||
|
* @brief General definitions for stubs
|
||||||
|
*
|
||||||
|
* Project:
|
||||||
|
* Subsystem:
|
||||||
|
* Module: unit_tests
|
||||||
|
* Code: GNU-C
|
||||||
|
*
|
||||||
|
* @date 06.07.2016
|
||||||
|
* @author Martin Winkler
|
||||||
|
*/
|
||||||
|
#ifndef STUB_H_
|
||||||
|
#define STUB_H_
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Stub run definitions
|
||||||
|
* Definitions if a stub call should be a PASS or FAIL
|
||||||
|
* @{*/
|
||||||
|
#define STUB_CALL_FAIL 0
|
||||||
|
#define STUB_CALL_PASS 1
|
||||||
|
/*!@}*/
|
||||||
|
|
||||||
|
/*! @brief How to handle pointer parameter */
|
||||||
|
typedef enum _STUB_PARAMETER_POINTER_HANDLING_T
|
||||||
|
{
|
||||||
|
STUB_PARAMETER_POINTER_HANDLING_ADDRESS, /*!< @brief Compare addresses */
|
||||||
|
STUB_PARAMETER_POINTER_HANDLING_CONTENT, /*!< @brief Compare content byte wise at given address */
|
||||||
|
STUB_PARAMETER_POINTER_HANDLING_INJECT, /*!< @brief Use init. parameter to inject values to test subject */
|
||||||
|
STUB_PARAMETER_POINTER_HANDLING_LAST_ENUM
|
||||||
|
} stub_parameter_pointer_handling_t;
|
||||||
|
|
||||||
|
#endif /* STUB_H_ */
|
117
resources/header/xasserts.h
Normal file
117
resources/header/xasserts.h
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
/*!
|
||||||
|
* @file xasserts.h
|
||||||
|
* @brief Extended asserts for use with CUnit
|
||||||
|
* @details
|
||||||
|
* Project:
|
||||||
|
* Subsystem:
|
||||||
|
* Module:
|
||||||
|
* Code: GNU-C
|
||||||
|
*
|
||||||
|
* @date 08.03.2017
|
||||||
|
* @author Martin Winkler
|
||||||
|
*/
|
||||||
|
#ifndef XASSERTS_H_
|
||||||
|
#define XASSERTS_H_
|
||||||
|
|
||||||
|
#include "CUnit/TestRun.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert a failed test with variable name and value
|
||||||
|
* @param Msg Custom string displayed before variable
|
||||||
|
* @param Name Name of the variable to display
|
||||||
|
* @param Format printf format string for variable (e.g. "%u", "0x%.2X", ...)
|
||||||
|
*/
|
||||||
|
#define CU_FAIL_OUTPUT(Msg,Name,Format)\
|
||||||
|
{\
|
||||||
|
char aErrMsg[255];\
|
||||||
|
sprintf(aErrMsg, "CU_FAIL_OUTPUT - %s%s: "Format, Msg ,#Name, Name);\
|
||||||
|
CU_assertImplementation(CU_FALSE, __LINE__, aErrMsg, __FILE__, "", CU_FALSE);\
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert a failed test only with variable value and custom text
|
||||||
|
* @param Msg Custom string displayed before variable
|
||||||
|
* @param Name Name of the variable to display
|
||||||
|
* @param Format printf format string for variable (e.g. "%u", "0x%.2X", ...)
|
||||||
|
*/
|
||||||
|
#define CU_FAIL_OUTPUT_LESS(Msg,Name,Format)\
|
||||||
|
{\
|
||||||
|
char aErrMsg[255];\
|
||||||
|
sprintf(aErrMsg, "CU_FAIL_OUTPUT - %s"Format, Msg, Name);\
|
||||||
|
CU_assertImplementation(CU_FALSE, __LINE__, aErrMsg, __FILE__, "", CU_FALSE);\
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Compare inputs and output actual value in error message
|
||||||
|
* @attention Do NOT place function calls as parameter actual, as it will be executed twice
|
||||||
|
*/
|
||||||
|
#define CU_ASSERT_EQUAL_OUTPUT(actual, expected, format)\
|
||||||
|
{\
|
||||||
|
char aErrMsg[255];\
|
||||||
|
sprintf(aErrMsg, ("CU_ASSERT_EQUAL(" #actual "," #expected ") "format), actual);\
|
||||||
|
CU_assertImplementation(((actual) == (expected)), __LINE__, aErrMsg, __FILE__, "", CU_FALSE);\
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert definition of macro for array check.
|
||||||
|
* @param pData Pointer on test data
|
||||||
|
* @param pExpected_data Pointer on expected test data
|
||||||
|
* @param u32Size Amount of array elements
|
||||||
|
*
|
||||||
|
* Macro checks if all array members in the array range defined by parameter size are equal.
|
||||||
|
* If not an error message is generated.
|
||||||
|
*/
|
||||||
|
#define CU_ASSERT_ARRAY_CHECK(Name, pData, pExpected_data, u32Size)\
|
||||||
|
{\
|
||||||
|
uint8_t bError = 0;\
|
||||||
|
uint32_t u32MemCnt;\
|
||||||
|
char aErrMsg[255];\
|
||||||
|
for (u32MemCnt = 0; u32MemCnt < u32Size; u32MemCnt++)\
|
||||||
|
{\
|
||||||
|
if (*(pData + u32MemCnt) != *(pExpected_data + u32MemCnt))\
|
||||||
|
{\
|
||||||
|
bError = 1;\
|
||||||
|
sprintf(aErrMsg, "CU_ASSERT_ARRAY_CHECK - %s[%d], act: 0x%.2X, exp: 0x%.2X", \
|
||||||
|
Name, u32MemCnt, *(pData + u32MemCnt), *(pExpected_data + u32MemCnt));\
|
||||||
|
CU_assertImplementation(CU_FALSE, __LINE__, aErrMsg, __FILE__, "", CU_FALSE);\
|
||||||
|
break;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
if (0 == bError)\
|
||||||
|
{\
|
||||||
|
CU_ASSERT(1);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert definition of macro for memory check.
|
||||||
|
* @param pData Pointer on test data
|
||||||
|
* @param pExpected_data Pointer on expected test data
|
||||||
|
* @param u32Size Memory size in bytes
|
||||||
|
*
|
||||||
|
* Macro checks if all bytes in the memory range defined by parameter size are equal.
|
||||||
|
* If not an error message is generated.
|
||||||
|
*/
|
||||||
|
#define CU_ASSERT_MEMORY_CHECK(Name, pData, pExpected_data, u32Size)\
|
||||||
|
{\
|
||||||
|
uint8_t bError = 0;\
|
||||||
|
uint32_t u32MemCnt;\
|
||||||
|
char aErrMsg[255];\
|
||||||
|
for (u32MemCnt = 0; u32MemCnt < u32Size; u32MemCnt++)\
|
||||||
|
{\
|
||||||
|
if (*((uint8_t*)pData + u32MemCnt) != *((uint8_t*)pExpected_data + u32MemCnt))\
|
||||||
|
{\
|
||||||
|
bError = 1;\
|
||||||
|
sprintf(aErrMsg, "CU_ASSERT_MEMORY_CHECK - %s, Offset: %d, act: 0x%.2X, exp: 0x%.2X", \
|
||||||
|
Name, u32MemCnt, *((uint8_t*)pData + u32MemCnt), *((uint8_t*)pExpected_data + u32MemCnt));\
|
||||||
|
CU_assertImplementation(CU_FALSE, __LINE__, aErrMsg, __FILE__, "", CU_FALSE);\
|
||||||
|
break;\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
if (0 == bError)\
|
||||||
|
{\
|
||||||
|
CU_ASSERT(1);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* XASSERTS_H_ */
|
Reference in New Issue
Block a user