mcl_assert.h
Go to the documentation of this file.
1 
11 #ifndef MCL_ASSERT_H_
12 #define MCL_ASSERT_H_
13 
14 #include "mcl_core/mcl_log_util.h"
15 
16 #ifdef __cplusplus
17 extern "C"
18 {
19 #endif
20 
21 #define MCL_ERROR_RETURN_POINTER(return_value, ...) \
22  MCL_ERROR(__VA_ARGS__); \
23  MCL_DEBUG_LEAVE("retVal = <%p>", (return_value)); \
24  return (return_value);
25 
26 #define MCL_ERROR_RETURN(return_value, ...) \
27  MCL_ERROR(__VA_ARGS__); \
28  MCL_DEBUG_LEAVE("retVal = <%d>", (return_value)); \
29  return (return_value);
30 
31 #define MCL_ASSERT_OK(code) \
32  if(MCL_OK != code) \
33  { \
34  MCL_ERROR("Expected: 0, actual: %d for " #code".", code); \
35  goto MCL_FUNCTION_LEAVE_LABEL; \
36  }
37 
38 #define MCL_ASSERT_NOT_NULL(argument, return_variable) \
39  if(MCL_NULL == argument) \
40  { \
41  MCL_ERROR_STRING("Null function argument (" #argument ")."); \
42  return_variable = MCL_TRIGGERED_WITH_NULL; \
43  goto MCL_FUNCTION_LEAVE_LABEL; \
44  }
45 
46 #define MCL_ASSERT(condition) \
47  if(!(condition)) \
48  { \
49  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
50  MCL_DEBUG_LEAVE("retVal = <%p>", MCL_NULL); \
51  return MCL_NULL; \
52  }
53 
54 #define MCL_ASSERT_MESSAGE(condition, ...) \
55  if(!(condition)) \
56  { \
57  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
58  MCL_ERROR_RETURN_POINTER(MCL_NULL, __VA_ARGS__); \
59  }
60 
61 #define MCL_ASSERT_STATEMENT_MESSAGE(condition, statement, ...) \
62  if(!(condition)) \
63  { \
64  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
65  (statement); \
66  MCL_ERROR_RETURN_POINTER(MCL_NULL, __VA_ARGS__); \
67  }
68 
69 #define MCL_ASSERT_CODE(condition, return_code) \
70  if(!(condition)) \
71  { \
72  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
73  MCL_DEBUG_LEAVE("retVal = <%d>", (return_code)); \
74  return (return_code); \
75  }
76 
77 #define MCL_ASSERT_CODE_MESSAGE(condition, return_code, ...) \
78  if(!(condition)) \
79  { \
80  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
81  MCL_ERROR_RETURN(return_code, __VA_ARGS__); \
82  }
83 
84 #define MCL_ASSERT_STATEMENT_CODE(condition, statement, return_code) \
85  if(!(condition)) \
86  { \
87  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
88  (statement); \
89  MCL_DEBUG_LEAVE("retVal = <%d>", (return_code)); \
90  return (return_code); \
91  }
92 
93 #define MCL_ASSERT_STATEMENT_CODE_MESSAGE(condition, statement, return_code, ...) \
94  if(!(condition)) \
95  { \
96  MCL_ERROR_STRING("Assertion failed for condition = <" #condition ">."); \
97  (statement); \
98  MCL_ERROR_RETURN(return_code, __VA_ARGS__); \
99  }
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif //MCL_ASSERT_H_
Log utility module interface header file.