uLib
ucontract.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
10 #ifndef AZ_UCONTRACT_H
11 #define AZ_UCONTRACT_H
12 
13 #include "azure_macro_utils/macro_utils.h"
14 #include "ulib_config.h"
15 #include "ulib_port.h"
16 #include "ulog.h"
17 
18 #include <stdio.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
25 #define EVALUATE_REQUIRE(x) x;
26 
37 #define AZ_UCONTRACT(...) do { MU_FOR_EACH_1(EVALUATE_REQUIRE, __VA_ARGS__) } while((void)0,0)
38 
45 #ifdef NDEBUG
46 #define AZ_UASSERT(...)
47 #else
48 #define AZ_UASSERT(...) AZ_UCONTRACT(__VA_ARGS__)
49 #endif
50 
58 #define AZ_UCONTRACT_REQUIRE(expression, result, msg) \
59  do { \
60  if(!(expression)) \
61  { \
62  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, msg); \
63  return result; \
64  } \
65  } while((void)0,0)
66 
74 #define AZ_UCONTRACT_REQUIRE_EQUALS(val, expected, result) \
75  do { \
76  if(val != expected) \
77  { \
78  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
79  return result; \
80  } \
81  } while((void)0,0)
82 
90 #define AZ_UCONTRACT_REQUIRE_NOT_EQUALS(val, expected, result) \
91  do { \
92  if(val == expected) \
93  { \
94  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
95  return result; \
96  } \
97  } while((void)0,0)
98 
105 #define AZ_UCONTRACT_REQUIRE_NOT_NULL(val, result) \
106  do { \
107  if(val == NULL) \
108  { \
109  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_NULL_STRING, MU_TOSTRING(val)); \
110  return result; \
111  } \
112  } while((void)0,0)
113 
122 #define AZ_UCONTRACT_REQUIRE_HARD_FAULT(expression, msg) \
123  do { \
124  if(!(expression)) \
125  { \
126  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, msg); \
127  AZ_ULIB_PORT_THROW_HARD_FAULT; \
128  } \
129  } while((void)0,0)
130 
139 #define AZ_UCONTRACT_REQUIRE_EQUALS_HARD_FAULT(val, expected) \
140  do { \
141  if(val != expected) \
142  { \
143  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
144  AZ_ULIB_PORT_THROW_HARD_FAULT; \
145  } \
146  } while((void)0,0)
147 
156 #define AZ_UCONTRACT_REQUIRE_NOT_EQUALS_HARD_FAULT(val, expected) \
157  do { \
158  if(val == expected) \
159  { \
160  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_EQUALS_STRING, MU_TOSTRING(val), MU_TOSTRING(expected)); \
161  AZ_ULIB_PORT_THROW_HARD_FAULT; \
162  } \
163  } while((void)0,0)
164 
172 #define AZ_UCONTRACT_REQUIRE_NOT_NULL_HARD_FAULT(val) \
173  do { \
174  if(val == NULL) \
175  { \
176  AZ_ULIB_CONFIG_LOG(AZ_ULOG_TYPE_ERROR, AZ_ULOG_REQUIRE_NOT_NULL_STRING, MU_TOSTRING(val)); \
177  AZ_ULIB_PORT_THROW_HARD_FAULT; \
178  } \
179  } while((void)0,0)
180 
181 
182 #ifdef __cplusplus
183 }
184 #endif /* __cplusplus */
185 
186 #endif /* AZ_UCONTRACT_H */
Small footprint logging functionality.
Configuration options for ulib.