#include <stdlib.h>
#define assert(exp) \
- if (!(exp)) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert Fail; Following expression is not true: %s\\n", __FILE__, __LINE__, #exp); \
- return 1; \
- }
+ do { \
+ if (!(exp)) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert Fail; Following expression is not true: %s\\n", \
+ __FILE__, __LINE__, #exp); \
+ return 1; \
+ } \
+ } while (0);
#define assert_eq(var, ref) \
- if (var != ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are not equal\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var != ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are not equal\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#define assert_neq(var, ref) \
- if (var == ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are equal\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var == ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are equal\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#define assert_gt(var, ref) \
- if (var <= ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than (%s == 0x%x)\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var <= ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than (%s == 0x%x)\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#define assert_geq(var, ref) \
- if (var < ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than or equal to (%s == 0x%x)\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var < ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than or equal to (%s == 0x%x)\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#define assert_lt(var, ref) \
- if (var >= ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than (%s == 0x%x)\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var >= ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than (%s == 0x%x)\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#define assert_leq(var, ref) \
- if (var > ref) { \
- fprintf(stderr, \
- "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than or equal to (%s == 0x%x)\\n", __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
- return 1; \
- }
+ do { \
+ if (var > ref) { \
+ fprintf(stderr, \
+ "\\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than or equal to (%s == 0x%x)\\n", \
+ __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
+ return 1; \
+ } \
+ } while (0);
#endif // _ASSERT_H_