uLib
Macros
ucontract.h File Reference

Public API parameter validation. More...

#include "azure_macro_utils/macro_utils.h"
#include "ulib_config.h"
#include "ulib_port.h"
#include "ulog.h"
#include <stdio.h>

Go to the source code of this file.

Macros

#define AZ_UCONTRACT(...)   do { MU_FOR_EACH_1(EVALUATE_REQUIRE, __VA_ARGS__) } while((void)0,0)
 Macro to define contract for public function parameters. More...
 
#define AZ_UASSERT(...)   AZ_UCONTRACT(__VA_ARGS__)
 Macro to define assertion for internal functions. More...
 
#define AZ_UCONTRACT_REQUIRE(expression, result, msg)
 Contract macro to evaluation developer expression. More...
 
#define AZ_UCONTRACT_REQUIRE_EQUALS(val, expected, result)
 Contract macro to evaluate if two values are equal. More...
 
#define AZ_UCONTRACT_REQUIRE_NOT_EQUALS(val, expected, result)
 Contract macro to evaluate if two values are not equal. More...
 
#define AZ_UCONTRACT_REQUIRE_NOT_NULL(val, result)
 Contract macro to evaluate if value is not NULL. More...
 
#define AZ_UCONTRACT_REQUIRE_HARD_FAULT(expression, msg)
 Contract macro to evaluate developer expression. More...
 
#define AZ_UCONTRACT_REQUIRE_EQUALS_HARD_FAULT(val, expected)
 Contract macro to evaluate if two values are equal. More...
 
#define AZ_UCONTRACT_REQUIRE_NOT_EQUALS_HARD_FAULT(val, expected)
 Contract macro to evaluate if two values are not equal. More...
 
#define AZ_UCONTRACT_REQUIRE_NOT_NULL_HARD_FAULT(val)
 Contract macro to evaluate if value is not NULL. More...
 

Detailed Description

Public API parameter validation.

Definition in file ucontract.h.

Macro Definition Documentation

◆ AZ_UASSERT

#define AZ_UASSERT (   ...)    AZ_UCONTRACT(__VA_ARGS__)

Macro to define assertion for internal functions.

Parameters to this macro shall be a comma separated list of AZ_UCONTRACT_... macros as listed below.

Definition at line 48 of file ucontract.h.

◆ AZ_UCONTRACT

#define AZ_UCONTRACT (   ...)    do { MU_FOR_EACH_1(EVALUATE_REQUIRE, __VA_ARGS__) } while((void)0,0)

Macro to define contract for public function parameters.

Parameters to this macro shall be a comma separated list of AZ_UCONTRACT_... macros as listed below.

Each public function shall have one AZ_UCONTRACT() macro with the listed requirements inside.

Definition at line 37 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE

#define AZ_UCONTRACT_REQUIRE (   expression,
  result,
  msg 
)
Value:
do { \
if(!(expression)) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, msg); \
return result; \
} \
} while((void)0,0)

Contract macro to evaluation developer expression.

Parameters
expressionboolean expression to be evaluated
resultreturn value if expression is false
msgmessage to log if expression is false

Definition at line 58 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_EQUALS

#define AZ_UCONTRACT_REQUIRE_EQUALS (   val,
  expected,
  result 
)
Value:
do { \
if(val != expected) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
return result; \
} \
} while((void)0,0)

Contract macro to evaluate if two values are equal.

Parameters
valvalue to check
expectedvalue expected
resultreturned result if values are not equal

Definition at line 74 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_EQUALS_HARD_FAULT

#define AZ_UCONTRACT_REQUIRE_EQUALS_HARD_FAULT (   val,
  expected 
)
Value:
do { \
if(val != expected) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
AZ_ULIB_PORT_THROW_HARD_FAULT; \
} \
} while((void)0,0)

Contract macro to evaluate if two values are equal.

Warning
Throws hard fault if values are not equal
Parameters
valvalue to check
expectedvalue expected

Definition at line 139 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_HARD_FAULT

#define AZ_UCONTRACT_REQUIRE_HARD_FAULT (   expression,
  msg 
)
Value:
do { \
if(!(expression)) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, msg); \
AZ_ULIB_PORT_THROW_HARD_FAULT; \
} \
} while((void)0,0)

Contract macro to evaluate developer expression.

Warning
Throws hard fault if developer expression is false
Parameters
expressionexpression to check
msgmessage to log if expression is false

Definition at line 122 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_NOT_EQUALS

#define AZ_UCONTRACT_REQUIRE_NOT_EQUALS (   val,
  expected,
  result 
)
Value:
do { \
if(val == expected) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
return result; \
} \
} while((void)0,0)

Contract macro to evaluate if two values are not equal.

Parameters
valvalue to check
expectedvalue not expected
resultreturned result if values are equal.

Definition at line 90 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_NOT_EQUALS_HARD_FAULT

#define AZ_UCONTRACT_REQUIRE_NOT_EQUALS_HARD_FAULT (   val,
  expected 
)
Value:
do { \
if(val == expected) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
AZ_ULIB_PORT_THROW_HARD_FAULT; \
} \
} while((void)0,0)

Contract macro to evaluate if two values are not equal.

Warning
Throws hard fault if values are equal
Parameters
valvalue to check
expectedvalue not expected

Definition at line 156 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_NOT_NULL

#define AZ_UCONTRACT_REQUIRE_NOT_NULL (   val,
  result 
)
Value:
do { \
if(val == NULL) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_NULL_STRING, MU_TOSTRING(val)); \
return result; \
} \
} while((void)0,0)

Contract macro to evaluate if value is not NULL.

Parameters
valvalue to check
resultreturned result if value is NULL

Definition at line 105 of file ucontract.h.

◆ AZ_UCONTRACT_REQUIRE_NOT_NULL_HARD_FAULT

#define AZ_UCONTRACT_REQUIRE_NOT_NULL_HARD_FAULT (   val)
Value:
do { \
if(val == NULL) \
{ \
AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_NULL_STRING, MU_TOSTRING(val)); \
AZ_ULIB_PORT_THROW_HARD_FAULT; \
} \
} while((void)0,0)

Contract macro to evaluate if value is not NULL.

Warning
Throws hard fault if value is NULL
Parameters
valvalue to check

Definition at line 172 of file ucontract.h.