Use C99 varadic macros instead of GCC ones

This commit is contained in:
Mike Hommey 2014-05-21 18:00:15 +09:00 committed by Jason Evans
parent 1ad4a6e9f9
commit 7330c3770a
2 changed files with 196 additions and 196 deletions

View File

@ -1,6 +1,6 @@
#define ASSERT_BUFSIZE 256 #define ASSERT_BUFSIZE 256
#define assert_cmp(t, a, b, cmp, neg_cmp, pri, fmt...) do { \ #define assert_cmp(t, a, b, cmp, neg_cmp, pri, ...) do { \
t a_ = (a); \ t a_ = (a); \
t b_ = (b); \ t b_ = (b); \
if (!(a_ cmp b_)) { \ if (!(a_ cmp b_)) { \
@ -12,205 +12,205 @@
"%"pri" "#neg_cmp" %"pri": ", \ "%"pri" "#neg_cmp" %"pri": ", \
__func__, __FILE__, __LINE__, \ __func__, __FILE__, __LINE__, \
#a, #b, a_, b_); \ #a, #b, a_, b_); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} \ } \
} while (0) } while (0)
#define assert_ptr_eq(a, b, fmt...) assert_cmp(void *, a, b, ==, \ #define assert_ptr_eq(a, b, ...) assert_cmp(void *, a, b, ==, \
!=, "p", fmt) !=, "p", __VA_ARGS__)
#define assert_ptr_ne(a, b, fmt...) assert_cmp(void *, a, b, !=, \ #define assert_ptr_ne(a, b, ...) assert_cmp(void *, a, b, !=, \
==, "p", fmt) ==, "p", __VA_ARGS__)
#define assert_ptr_null(a, fmt...) assert_cmp(void *, a, NULL, ==, \ #define assert_ptr_null(a, ...) assert_cmp(void *, a, NULL, ==, \
!=, "p", fmt) !=, "p", __VA_ARGS__)
#define assert_ptr_not_null(a, fmt...) assert_cmp(void *, a, NULL, !=, \ #define assert_ptr_not_null(a, ...) assert_cmp(void *, a, NULL, !=, \
==, "p", fmt) ==, "p", __VA_ARGS__)
#define assert_c_eq(a, b, fmt...) assert_cmp(char, a, b, ==, !=, "c", fmt) #define assert_c_eq(a, b, ...) assert_cmp(char, a, b, ==, !=, "c", __VA_ARGS__)
#define assert_c_ne(a, b, fmt...) assert_cmp(char, a, b, !=, ==, "c", fmt) #define assert_c_ne(a, b, ...) assert_cmp(char, a, b, !=, ==, "c", __VA_ARGS__)
#define assert_c_lt(a, b, fmt...) assert_cmp(char, a, b, <, >=, "c", fmt) #define assert_c_lt(a, b, ...) assert_cmp(char, a, b, <, >=, "c", __VA_ARGS__)
#define assert_c_le(a, b, fmt...) assert_cmp(char, a, b, <=, >, "c", fmt) #define assert_c_le(a, b, ...) assert_cmp(char, a, b, <=, >, "c", __VA_ARGS__)
#define assert_c_ge(a, b, fmt...) assert_cmp(char, a, b, >=, <, "c", fmt) #define assert_c_ge(a, b, ...) assert_cmp(char, a, b, >=, <, "c", __VA_ARGS__)
#define assert_c_gt(a, b, fmt...) assert_cmp(char, a, b, >, <=, "c", fmt) #define assert_c_gt(a, b, ...) assert_cmp(char, a, b, >, <=, "c", __VA_ARGS__)
#define assert_x_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "#x", fmt) #define assert_x_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "#x", __VA_ARGS__)
#define assert_x_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "#x", fmt) #define assert_x_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "#x", __VA_ARGS__)
#define assert_x_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "#x", fmt) #define assert_x_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "#x", __VA_ARGS__)
#define assert_x_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "#x", fmt) #define assert_x_le(a, b, ...) assert_cmp(int, a, b, <=, >, "#x", __VA_ARGS__)
#define assert_x_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "#x", fmt) #define assert_x_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "#x", __VA_ARGS__)
#define assert_x_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "#x", fmt) #define assert_x_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "#x", __VA_ARGS__)
#define assert_d_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "d", fmt) #define assert_d_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "d", __VA_ARGS__)
#define assert_d_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "d", fmt) #define assert_d_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "d", __VA_ARGS__)
#define assert_d_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "d", fmt) #define assert_d_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "d", __VA_ARGS__)
#define assert_d_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "d", fmt) #define assert_d_le(a, b, ...) assert_cmp(int, a, b, <=, >, "d", __VA_ARGS__)
#define assert_d_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "d", fmt) #define assert_d_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "d", __VA_ARGS__)
#define assert_d_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "d", fmt) #define assert_d_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "d", __VA_ARGS__)
#define assert_u_eq(a, b, fmt...) assert_cmp(int, a, b, ==, !=, "u", fmt) #define assert_u_eq(a, b, ...) assert_cmp(int, a, b, ==, !=, "u", __VA_ARGS__)
#define assert_u_ne(a, b, fmt...) assert_cmp(int, a, b, !=, ==, "u", fmt) #define assert_u_ne(a, b, ...) assert_cmp(int, a, b, !=, ==, "u", __VA_ARGS__)
#define assert_u_lt(a, b, fmt...) assert_cmp(int, a, b, <, >=, "u", fmt) #define assert_u_lt(a, b, ...) assert_cmp(int, a, b, <, >=, "u", __VA_ARGS__)
#define assert_u_le(a, b, fmt...) assert_cmp(int, a, b, <=, >, "u", fmt) #define assert_u_le(a, b, ...) assert_cmp(int, a, b, <=, >, "u", __VA_ARGS__)
#define assert_u_ge(a, b, fmt...) assert_cmp(int, a, b, >=, <, "u", fmt) #define assert_u_ge(a, b, ...) assert_cmp(int, a, b, >=, <, "u", __VA_ARGS__)
#define assert_u_gt(a, b, fmt...) assert_cmp(int, a, b, >, <=, "u", fmt) #define assert_u_gt(a, b, ...) assert_cmp(int, a, b, >, <=, "u", __VA_ARGS__)
#define assert_ld_eq(a, b, fmt...) assert_cmp(long, a, b, ==, \ #define assert_ld_eq(a, b, ...) assert_cmp(long, a, b, ==, \
!=, "ld", fmt) !=, "ld", __VA_ARGS__)
#define assert_ld_ne(a, b, fmt...) assert_cmp(long, a, b, !=, \ #define assert_ld_ne(a, b, ...) assert_cmp(long, a, b, !=, \
==, "ld", fmt) ==, "ld", __VA_ARGS__)
#define assert_ld_lt(a, b, fmt...) assert_cmp(long, a, b, <, \ #define assert_ld_lt(a, b, ...) assert_cmp(long, a, b, <, \
>=, "ld", fmt) >=, "ld", __VA_ARGS__)
#define assert_ld_le(a, b, fmt...) assert_cmp(long, a, b, <=, \ #define assert_ld_le(a, b, ...) assert_cmp(long, a, b, <=, \
>, "ld", fmt) >, "ld", __VA_ARGS__)
#define assert_ld_ge(a, b, fmt...) assert_cmp(long, a, b, >=, \ #define assert_ld_ge(a, b, ...) assert_cmp(long, a, b, >=, \
<, "ld", fmt) <, "ld", __VA_ARGS__)
#define assert_ld_gt(a, b, fmt...) assert_cmp(long, a, b, >, \ #define assert_ld_gt(a, b, ...) assert_cmp(long, a, b, >, \
<=, "ld", fmt) <=, "ld", __VA_ARGS__)
#define assert_lu_eq(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_eq(a, b, ...) assert_cmp(unsigned long, \
a, b, ==, !=, "lu", fmt) a, b, ==, !=, "lu", __VA_ARGS__)
#define assert_lu_ne(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_ne(a, b, ...) assert_cmp(unsigned long, \
a, b, !=, ==, "lu", fmt) a, b, !=, ==, "lu", __VA_ARGS__)
#define assert_lu_lt(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_lt(a, b, ...) assert_cmp(unsigned long, \
a, b, <, >=, "lu", fmt) a, b, <, >=, "lu", __VA_ARGS__)
#define assert_lu_le(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_le(a, b, ...) assert_cmp(unsigned long, \
a, b, <=, >, "lu", fmt) a, b, <=, >, "lu", __VA_ARGS__)
#define assert_lu_ge(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_ge(a, b, ...) assert_cmp(unsigned long, \
a, b, >=, <, "lu", fmt) a, b, >=, <, "lu", __VA_ARGS__)
#define assert_lu_gt(a, b, fmt...) assert_cmp(unsigned long, \ #define assert_lu_gt(a, b, ...) assert_cmp(unsigned long, \
a, b, >, <=, "lu", fmt) a, b, >, <=, "lu", __VA_ARGS__)
#define assert_qd_eq(a, b, fmt...) assert_cmp(long long, a, b, ==, \ #define assert_qd_eq(a, b, ...) assert_cmp(long long, a, b, ==, \
!=, "qd", fmt) !=, "qd", __VA_ARGS__)
#define assert_qd_ne(a, b, fmt...) assert_cmp(long long, a, b, !=, \ #define assert_qd_ne(a, b, ...) assert_cmp(long long, a, b, !=, \
==, "qd", fmt) ==, "qd", __VA_ARGS__)
#define assert_qd_lt(a, b, fmt...) assert_cmp(long long, a, b, <, \ #define assert_qd_lt(a, b, ...) assert_cmp(long long, a, b, <, \
>=, "qd", fmt) >=, "qd", __VA_ARGS__)
#define assert_qd_le(a, b, fmt...) assert_cmp(long long, a, b, <=, \ #define assert_qd_le(a, b, ...) assert_cmp(long long, a, b, <=, \
>, "qd", fmt) >, "qd", __VA_ARGS__)
#define assert_qd_ge(a, b, fmt...) assert_cmp(long long, a, b, >=, \ #define assert_qd_ge(a, b, ...) assert_cmp(long long, a, b, >=, \
<, "qd", fmt) <, "qd", __VA_ARGS__)
#define assert_qd_gt(a, b, fmt...) assert_cmp(long long, a, b, >, \ #define assert_qd_gt(a, b, ...) assert_cmp(long long, a, b, >, \
<=, "qd", fmt) <=, "qd", __VA_ARGS__)
#define assert_qu_eq(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_eq(a, b, ...) assert_cmp(unsigned long long, \
a, b, ==, !=, "qu", fmt) a, b, ==, !=, "qu", __VA_ARGS__)
#define assert_qu_ne(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_ne(a, b, ...) assert_cmp(unsigned long long, \
a, b, !=, ==, "qu", fmt) a, b, !=, ==, "qu", __VA_ARGS__)
#define assert_qu_lt(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_lt(a, b, ...) assert_cmp(unsigned long long, \
a, b, <, >=, "qu", fmt) a, b, <, >=, "qu", __VA_ARGS__)
#define assert_qu_le(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_le(a, b, ...) assert_cmp(unsigned long long, \
a, b, <=, >, "qu", fmt) a, b, <=, >, "qu", __VA_ARGS__)
#define assert_qu_ge(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_ge(a, b, ...) assert_cmp(unsigned long long, \
a, b, >=, <, "qu", fmt) a, b, >=, <, "qu", __VA_ARGS__)
#define assert_qu_gt(a, b, fmt...) assert_cmp(unsigned long long, \ #define assert_qu_gt(a, b, ...) assert_cmp(unsigned long long, \
a, b, >, <=, "qu", fmt) a, b, >, <=, "qu", __VA_ARGS__)
#define assert_jd_eq(a, b, fmt...) assert_cmp(intmax_t, a, b, ==, \ #define assert_jd_eq(a, b, ...) assert_cmp(intmax_t, a, b, ==, \
!=, "jd", fmt) !=, "jd", __VA_ARGS__)
#define assert_jd_ne(a, b, fmt...) assert_cmp(intmax_t, a, b, !=, \ #define assert_jd_ne(a, b, ...) assert_cmp(intmax_t, a, b, !=, \
==, "jd", fmt) ==, "jd", __VA_ARGS__)
#define assert_jd_lt(a, b, fmt...) assert_cmp(intmax_t, a, b, <, \ #define assert_jd_lt(a, b, ...) assert_cmp(intmax_t, a, b, <, \
>=, "jd", fmt) >=, "jd", __VA_ARGS__)
#define assert_jd_le(a, b, fmt...) assert_cmp(intmax_t, a, b, <=, \ #define assert_jd_le(a, b, ...) assert_cmp(intmax_t, a, b, <=, \
>, "jd", fmt) >, "jd", __VA_ARGS__)
#define assert_jd_ge(a, b, fmt...) assert_cmp(intmax_t, a, b, >=, \ #define assert_jd_ge(a, b, ...) assert_cmp(intmax_t, a, b, >=, \
<, "jd", fmt) <, "jd", __VA_ARGS__)
#define assert_jd_gt(a, b, fmt...) assert_cmp(intmax_t, a, b, >, \ #define assert_jd_gt(a, b, ...) assert_cmp(intmax_t, a, b, >, \
<=, "jd", fmt) <=, "jd", __VA_ARGS__)
#define assert_ju_eq(a, b, fmt...) assert_cmp(uintmax_t, a, b, ==, \ #define assert_ju_eq(a, b, ...) assert_cmp(uintmax_t, a, b, ==, \
!=, "ju", fmt) !=, "ju", __VA_ARGS__)
#define assert_ju_ne(a, b, fmt...) assert_cmp(uintmax_t, a, b, !=, \ #define assert_ju_ne(a, b, ...) assert_cmp(uintmax_t, a, b, !=, \
==, "ju", fmt) ==, "ju", __VA_ARGS__)
#define assert_ju_lt(a, b, fmt...) assert_cmp(uintmax_t, a, b, <, \ #define assert_ju_lt(a, b, ...) assert_cmp(uintmax_t, a, b, <, \
>=, "ju", fmt) >=, "ju", __VA_ARGS__)
#define assert_ju_le(a, b, fmt...) assert_cmp(uintmax_t, a, b, <=, \ #define assert_ju_le(a, b, ...) assert_cmp(uintmax_t, a, b, <=, \
>, "ju", fmt) >, "ju", __VA_ARGS__)
#define assert_ju_ge(a, b, fmt...) assert_cmp(uintmax_t, a, b, >=, \ #define assert_ju_ge(a, b, ...) assert_cmp(uintmax_t, a, b, >=, \
<, "ju", fmt) <, "ju", __VA_ARGS__)
#define assert_ju_gt(a, b, fmt...) assert_cmp(uintmax_t, a, b, >, \ #define assert_ju_gt(a, b, ...) assert_cmp(uintmax_t, a, b, >, \
<=, "ju", fmt) <=, "ju", __VA_ARGS__)
#define assert_zd_eq(a, b, fmt...) assert_cmp(ssize_t, a, b, ==, \ #define assert_zd_eq(a, b, ...) assert_cmp(ssize_t, a, b, ==, \
!=, "zd", fmt) !=, "zd", __VA_ARGS__)
#define assert_zd_ne(a, b, fmt...) assert_cmp(ssize_t, a, b, !=, \ #define assert_zd_ne(a, b, ...) assert_cmp(ssize_t, a, b, !=, \
==, "zd", fmt) ==, "zd", __VA_ARGS__)
#define assert_zd_lt(a, b, fmt...) assert_cmp(ssize_t, a, b, <, \ #define assert_zd_lt(a, b, ...) assert_cmp(ssize_t, a, b, <, \
>=, "zd", fmt) >=, "zd", __VA_ARGS__)
#define assert_zd_le(a, b, fmt...) assert_cmp(ssize_t, a, b, <=, \ #define assert_zd_le(a, b, ...) assert_cmp(ssize_t, a, b, <=, \
>, "zd", fmt) >, "zd", __VA_ARGS__)
#define assert_zd_ge(a, b, fmt...) assert_cmp(ssize_t, a, b, >=, \ #define assert_zd_ge(a, b, ...) assert_cmp(ssize_t, a, b, >=, \
<, "zd", fmt) <, "zd", __VA_ARGS__)
#define assert_zd_gt(a, b, fmt...) assert_cmp(ssize_t, a, b, >, \ #define assert_zd_gt(a, b, ...) assert_cmp(ssize_t, a, b, >, \
<=, "zd", fmt) <=, "zd", __VA_ARGS__)
#define assert_zu_eq(a, b, fmt...) assert_cmp(size_t, a, b, ==, \ #define assert_zu_eq(a, b, ...) assert_cmp(size_t, a, b, ==, \
!=, "zu", fmt) !=, "zu", __VA_ARGS__)
#define assert_zu_ne(a, b, fmt...) assert_cmp(size_t, a, b, !=, \ #define assert_zu_ne(a, b, ...) assert_cmp(size_t, a, b, !=, \
==, "zu", fmt) ==, "zu", __VA_ARGS__)
#define assert_zu_lt(a, b, fmt...) assert_cmp(size_t, a, b, <, \ #define assert_zu_lt(a, b, ...) assert_cmp(size_t, a, b, <, \
>=, "zu", fmt) >=, "zu", __VA_ARGS__)
#define assert_zu_le(a, b, fmt...) assert_cmp(size_t, a, b, <=, \ #define assert_zu_le(a, b, ...) assert_cmp(size_t, a, b, <=, \
>, "zu", fmt) >, "zu", __VA_ARGS__)
#define assert_zu_ge(a, b, fmt...) assert_cmp(size_t, a, b, >=, \ #define assert_zu_ge(a, b, ...) assert_cmp(size_t, a, b, >=, \
<, "zu", fmt) <, "zu", __VA_ARGS__)
#define assert_zu_gt(a, b, fmt...) assert_cmp(size_t, a, b, >, \ #define assert_zu_gt(a, b, ...) assert_cmp(size_t, a, b, >, \
<=, "zu", fmt) <=, "zu", __VA_ARGS__)
#define assert_d32_eq(a, b, fmt...) assert_cmp(int32_t, a, b, ==, \ #define assert_d32_eq(a, b, ...) assert_cmp(int32_t, a, b, ==, \
!=, PRId32, fmt) !=, PRId32, __VA_ARGS__)
#define assert_d32_ne(a, b, fmt...) assert_cmp(int32_t, a, b, !=, \ #define assert_d32_ne(a, b, ...) assert_cmp(int32_t, a, b, !=, \
==, PRId32, fmt) ==, PRId32, __VA_ARGS__)
#define assert_d32_lt(a, b, fmt...) assert_cmp(int32_t, a, b, <, \ #define assert_d32_lt(a, b, ...) assert_cmp(int32_t, a, b, <, \
>=, PRId32, fmt) >=, PRId32, __VA_ARGS__)
#define assert_d32_le(a, b, fmt...) assert_cmp(int32_t, a, b, <=, \ #define assert_d32_le(a, b, ...) assert_cmp(int32_t, a, b, <=, \
>, PRId32, fmt) >, PRId32, __VA_ARGS__)
#define assert_d32_ge(a, b, fmt...) assert_cmp(int32_t, a, b, >=, \ #define assert_d32_ge(a, b, ...) assert_cmp(int32_t, a, b, >=, \
<, PRId32, fmt) <, PRId32, __VA_ARGS__)
#define assert_d32_gt(a, b, fmt...) assert_cmp(int32_t, a, b, >, \ #define assert_d32_gt(a, b, ...) assert_cmp(int32_t, a, b, >, \
<=, PRId32, fmt) <=, PRId32, __VA_ARGS__)
#define assert_u32_eq(a, b, fmt...) assert_cmp(uint32_t, a, b, ==, \ #define assert_u32_eq(a, b, ...) assert_cmp(uint32_t, a, b, ==, \
!=, PRIu32, fmt) !=, PRIu32, __VA_ARGS__)
#define assert_u32_ne(a, b, fmt...) assert_cmp(uint32_t, a, b, !=, \ #define assert_u32_ne(a, b, ...) assert_cmp(uint32_t, a, b, !=, \
==, PRIu32, fmt) ==, PRIu32, __VA_ARGS__)
#define assert_u32_lt(a, b, fmt...) assert_cmp(uint32_t, a, b, <, \ #define assert_u32_lt(a, b, ...) assert_cmp(uint32_t, a, b, <, \
>=, PRIu32, fmt) >=, PRIu32, __VA_ARGS__)
#define assert_u32_le(a, b, fmt...) assert_cmp(uint32_t, a, b, <=, \ #define assert_u32_le(a, b, ...) assert_cmp(uint32_t, a, b, <=, \
>, PRIu32, fmt) >, PRIu32, __VA_ARGS__)
#define assert_u32_ge(a, b, fmt...) assert_cmp(uint32_t, a, b, >=, \ #define assert_u32_ge(a, b, ...) assert_cmp(uint32_t, a, b, >=, \
<, PRIu32, fmt) <, PRIu32, __VA_ARGS__)
#define assert_u32_gt(a, b, fmt...) assert_cmp(uint32_t, a, b, >, \ #define assert_u32_gt(a, b, ...) assert_cmp(uint32_t, a, b, >, \
<=, PRIu32, fmt) <=, PRIu32, __VA_ARGS__)
#define assert_d64_eq(a, b, fmt...) assert_cmp(int64_t, a, b, ==, \ #define assert_d64_eq(a, b, ...) assert_cmp(int64_t, a, b, ==, \
!=, PRId64, fmt) !=, PRId64, __VA_ARGS__)
#define assert_d64_ne(a, b, fmt...) assert_cmp(int64_t, a, b, !=, \ #define assert_d64_ne(a, b, ...) assert_cmp(int64_t, a, b, !=, \
==, PRId64, fmt) ==, PRId64, __VA_ARGS__)
#define assert_d64_lt(a, b, fmt...) assert_cmp(int64_t, a, b, <, \ #define assert_d64_lt(a, b, ...) assert_cmp(int64_t, a, b, <, \
>=, PRId64, fmt) >=, PRId64, __VA_ARGS__)
#define assert_d64_le(a, b, fmt...) assert_cmp(int64_t, a, b, <=, \ #define assert_d64_le(a, b, ...) assert_cmp(int64_t, a, b, <=, \
>, PRId64, fmt) >, PRId64, __VA_ARGS__)
#define assert_d64_ge(a, b, fmt...) assert_cmp(int64_t, a, b, >=, \ #define assert_d64_ge(a, b, ...) assert_cmp(int64_t, a, b, >=, \
<, PRId64, fmt) <, PRId64, __VA_ARGS__)
#define assert_d64_gt(a, b, fmt...) assert_cmp(int64_t, a, b, >, \ #define assert_d64_gt(a, b, ...) assert_cmp(int64_t, a, b, >, \
<=, PRId64, fmt) <=, PRId64, __VA_ARGS__)
#define assert_u64_eq(a, b, fmt...) assert_cmp(uint64_t, a, b, ==, \ #define assert_u64_eq(a, b, ...) assert_cmp(uint64_t, a, b, ==, \
!=, PRIu64, fmt) !=, PRIu64, __VA_ARGS__)
#define assert_u64_ne(a, b, fmt...) assert_cmp(uint64_t, a, b, !=, \ #define assert_u64_ne(a, b, ...) assert_cmp(uint64_t, a, b, !=, \
==, PRIu64, fmt) ==, PRIu64, __VA_ARGS__)
#define assert_u64_lt(a, b, fmt...) assert_cmp(uint64_t, a, b, <, \ #define assert_u64_lt(a, b, ...) assert_cmp(uint64_t, a, b, <, \
>=, PRIu64, fmt) >=, PRIu64, __VA_ARGS__)
#define assert_u64_le(a, b, fmt...) assert_cmp(uint64_t, a, b, <=, \ #define assert_u64_le(a, b, ...) assert_cmp(uint64_t, a, b, <=, \
>, PRIu64, fmt) >, PRIu64, __VA_ARGS__)
#define assert_u64_ge(a, b, fmt...) assert_cmp(uint64_t, a, b, >=, \ #define assert_u64_ge(a, b, ...) assert_cmp(uint64_t, a, b, >=, \
<, PRIu64, fmt) <, PRIu64, __VA_ARGS__)
#define assert_u64_gt(a, b, fmt...) assert_cmp(uint64_t, a, b, >, \ #define assert_u64_gt(a, b, ...) assert_cmp(uint64_t, a, b, >, \
<=, PRIu64, fmt) <=, PRIu64, __VA_ARGS__)
#define assert_b_eq(a, b, fmt...) do { \ #define assert_b_eq(a, b, ...) do { \
bool a_ = (a); \ bool a_ = (a); \
bool b_ = (b); \ bool b_ = (b); \
if (!(a_ == b_)) { \ if (!(a_ == b_)) { \
@ -222,11 +222,11 @@
__func__, __FILE__, __LINE__, \ __func__, __FILE__, __LINE__, \
#a, #b, a_ ? "true" : "false", \ #a, #b, a_ ? "true" : "false", \
b_ ? "true" : "false"); \ b_ ? "true" : "false"); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} \ } \
} while (0) } while (0)
#define assert_b_ne(a, b, fmt...) do { \ #define assert_b_ne(a, b, ...) do { \
bool a_ = (a); \ bool a_ = (a); \
bool b_ = (b); \ bool b_ = (b); \
if (!(a_ != b_)) { \ if (!(a_ != b_)) { \
@ -238,14 +238,14 @@
__func__, __FILE__, __LINE__, \ __func__, __FILE__, __LINE__, \
#a, #b, a_ ? "true" : "false", \ #a, #b, a_ ? "true" : "false", \
b_ ? "true" : "false"); \ b_ ? "true" : "false"); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} \ } \
} while (0) } while (0)
#define assert_true(a, fmt...) assert_b_eq(a, true, fmt) #define assert_true(a, ...) assert_b_eq(a, true, __VA_ARGS__)
#define assert_false(a, fmt...) assert_b_eq(a, false, fmt) #define assert_false(a, ...) assert_b_eq(a, false, __VA_ARGS__)
#define assert_str_eq(a, b, fmt...) do { \ #define assert_str_eq(a, b, ...) do { \
if (strcmp((a), (b))) { \ if (strcmp((a), (b))) { \
char prefix[ASSERT_BUFSIZE]; \ char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \ char message[ASSERT_BUFSIZE]; \
@ -254,11 +254,11 @@
"(%s) same as (%s) --> " \ "(%s) same as (%s) --> " \
"\"%s\" differs from \"%s\": ", \ "\"%s\" differs from \"%s\": ", \
__func__, __FILE__, __LINE__, #a, #b, a, b); \ __func__, __FILE__, __LINE__, #a, #b, a, b); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} \ } \
} while (0) } while (0)
#define assert_str_ne(a, b, fmt...) do { \ #define assert_str_ne(a, b, ...) do { \
if (!strcmp((a), (b))) { \ if (!strcmp((a), (b))) { \
char prefix[ASSERT_BUFSIZE]; \ char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \ char message[ASSERT_BUFSIZE]; \
@ -267,18 +267,18 @@
"(%s) differs from (%s) --> " \ "(%s) differs from (%s) --> " \
"\"%s\" same as \"%s\": ", \ "\"%s\" same as \"%s\": ", \
__func__, __FILE__, __LINE__, #a, #b, a, b); \ __func__, __FILE__, __LINE__, #a, #b, a, b); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} \ } \
} while (0) } while (0)
#define assert_not_reached(fmt...) do { \ #define assert_not_reached(...) do { \
char prefix[ASSERT_BUFSIZE]; \ char prefix[ASSERT_BUFSIZE]; \
char message[ASSERT_BUFSIZE]; \ char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \ malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Unreachable code reached: ", \ "%s:%s:%d: Unreachable code reached: ", \
__func__, __FILE__, __LINE__); \ __func__, __FILE__, __LINE__); \
malloc_snprintf(message, sizeof(message), fmt); \ malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
p_test_fail(prefix, message); \ p_test_fail(prefix, message); \
} while (0) } while (0)
@ -308,8 +308,8 @@ label_test_end: \
p_test_fini(); \ p_test_fini(); \
} }
#define test(tests...) \ #define test(...) \
p_test(tests, NULL) p_test(__VA_ARGS__, NULL)
#define test_skip_if(e) do { \ #define test_skip_if(e) do { \
if (e) { \ if (e) { \

View File

@ -141,8 +141,8 @@ TEST_BEGIN(test_malloc_snprintf_truncated)
char buf[BUFLEN]; char buf[BUFLEN];
int result; int result;
size_t len; size_t len;
#define TEST(expected_str_untruncated, fmt...) do { \ #define TEST(expected_str_untruncated, ...) do { \
result = malloc_snprintf(buf, len, fmt); \ result = malloc_snprintf(buf, len, __VA_ARGS__); \
assert_d_eq(strncmp(buf, expected_str_untruncated, len-1), 0, \ assert_d_eq(strncmp(buf, expected_str_untruncated, len-1), 0, \
"Unexpected string inequality (\"%s\" vs \"%s\")", \ "Unexpected string inequality (\"%s\" vs \"%s\")", \
buf, expected_str_untruncated); \ buf, expected_str_untruncated); \
@ -173,8 +173,8 @@ TEST_BEGIN(test_malloc_snprintf)
#define BUFLEN 128 #define BUFLEN 128
char buf[BUFLEN]; char buf[BUFLEN];
int result; int result;
#define TEST(expected_str, fmt...) do { \ #define TEST(expected_str, ...) do { \
result = malloc_snprintf(buf, sizeof(buf), fmt); \ result = malloc_snprintf(buf, sizeof(buf), __VA_ARGS__); \
assert_str_eq(buf, expected_str, "Unexpected output"); \ assert_str_eq(buf, expected_str, "Unexpected output"); \
assert_d_eq(result, strlen(expected_str), "Unexpected result"); \ assert_d_eq(result, strlen(expected_str), "Unexpected result"); \
} while (0) } while (0)