00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_TEST_H
00019 #define CU_TEST_H
00020
00021 #include <cu/fwd.h>
00022 #include <atomic_ops.h>
00023 #include <stdarg.h>
00024
00025 CU_BEGIN_DECLARATIONS
00026
00027
00028
00029 typedef enum {
00030 cu_test_bugaction_cont,
00031 cu_test_bugaction_abort,
00032 cu_test_bugaction_exit,
00033 } cu_test_bugaction_t;
00034
00035 void cu_test_on_bug(cu_test_bugaction_t action, unsigned long max_bug_cnt);
00036 int cu_test_bug_count(void);
00037
00038 void cuP_test_vbugf(char const *file, int line, char const *msg, va_list);
00039 void cuP_test_bugf(char const *file, int line, char const *msg, ...);
00040
00041 #define cu_test_bugf(...) cuP_test_bugf(__FILE__, __LINE__, __VA_ARGS__)
00042 #define cu_test_vbugf(...) cuP_test_vbugf(__FILE__, __LINE__, __VA_ARGS__)
00043
00044 #define cu_test_assert(EXPR) \
00045 do { \
00046 if (!(EXPR)) \
00047 cu_test_bugf("Assertion '%s' failed.", #EXPR); \
00048 } while (0)
00049
00050 #define cuP_test_str(expr) cuP_test_strp(expr)
00051 #define cuP_test_strp(expr) #expr
00052 #define cu_test_assert_binary(OP, type, PRI, LHS, RHS) \
00053 do { \
00054 type lhs = (LHS); \
00055 type rhs = (RHS); \
00056 if (!(OP(lhs, rhs))) \
00057 cu_test_bugf("Assertion '%s' failed. LHS = %"PRI", RHS = %"PRI"", \
00058 cuP_test_str(OP(LHS, RHS)), lhs, rhs); \
00059 } while (0)
00060
00061 #define cu_test_op_eq(x, y) ((x) == (y))
00062 #define cu_test_op_lt(x, y) ((x) < (y))
00063 #define cu_test_op_leq(x, y) ((x) <= (y))
00064 #define cu_test_op_gt(x, y) ((x) > (y))
00065 #define cu_test_op_geq(x, y) ((x) >= (y))
00066
00067 #define cu_test_assert_int_eq(LHS, RHS) \
00068 cu_test_assert_binary(cu_test_op_eq, int, "d", LHS, RHS)
00069 #define cu_test_assert_int_lt(LHS, RHS) \
00070 cu_test_assert_binary(cu_test_op_lt, int, "d", LHS, RHS)
00071 #define cu_test_assert_int_leq(LHS, RHS) \
00072 cu_test_assert_binary(cu_test_op_leq, int, "d", LHS, RHS)
00073 #define cu_test_assert_int_gt(LHS, RHS) \
00074 cu_test_assert_binary(cu_test_op_gt, int, "d", LHS, RHS)
00075 #define cu_test_assert_int_geq(LHS, RHS) \
00076 cu_test_assert_binary(cu_test_op_geq, int, "d", LHS, RHS)
00077
00078 #define cu_test_assert_ptr_eq(LHS, RHS) \
00079 cu_test_assert_binary(cu_test_op_eq, void *, "p", LHS, RHS)
00080 #define cu_test_assert_size_eq(LHS, RHS) \
00081 cu_test_assert_binary(cu_test_op_eq, size_t, "zd", LHS, RHS)
00082 #define cu_test_assert_word_eq(LHS, RHS) \
00083 cu_test_assert_binary(cu_test_op_eq, cu_word_t, CU_PRIxWORD, LHS, RHS)
00084
00085
00086 CU_END_DECLARATIONS
00087
00088 #endif