Implemented a bunch more combinators

This commit is contained in:
Dan Hirsch 2012-05-13 01:01:26 +01:00
parent 0e9bcb31ca
commit 3afe324aaa
5 changed files with 212 additions and 70 deletions

View file

@ -19,7 +19,7 @@
#define HAMMER_TEST_SUITE__H
// Equivalent to g_assert_*, but not using g_assert...
#define g_check_inttype(fmt, typ, n1, op, n2) { \
#define g_check_inttype(fmt, typ, n1, op, n2) do { \
typ _n1 = (n1); \
typ _n2 = (n2); \
if (!(_n1 op _n2)) { \
@ -28,9 +28,9 @@
_n1, #op, _n2); \
g_test_fail(); \
} \
}
} while(0)
#define g_check_bytes(len, n1, op, n2) { \
#define g_check_bytes(len, n1, op, n2) do { \
const uint8_t *_n1 = (n1); \
const uint8_t *_n2 = (n2); \
if (!(memcmp(_n1, _n2, len) op 0)) { \
@ -38,37 +38,37 @@
#n1 " " #op " " #n2); \
g_test_fail(); \
} \
}
} while(0)
#define g_check_string(n1, op, n2) { \
#define g_check_string(n1, op, n2) do { \
const char *_n1 = (n1); \
const char *_n2 = (n2); \
if (!(strcmp(_n1, _n2) op 0)) { \
if (!(strcmp(_n1, _n2) op 0)) { \
g_test_message("Check failed: (%s) (%s %s %s)", \
#n1 " " #op " " #n2, \
_n1, #op, _n2); \
g_test_fail(); \
} \
}
} while(0)
// TODO: replace uses of this with g_check_parse_failed
#define g_check_failed(res) { \
const parse_result_t *result = (res); \
if (NULL != result) { \
#define g_check_failed(res) do { \
const parse_result_t *result = (res); \
if (NULL != result) { \
g_test_message("Check failed: shouldn't have succeeded, but did"); \
g_test_fail(); \
} \
}
g_test_fail(); \
} \
} while(0)
#define g_check_parse_failed(parser, input, inp_len) { \
#define g_check_parse_failed(parser, input, inp_len) do { \
const parse_result_t *result = parse(parser, (const uint8_t*)input, inp_len); \
if (NULL != result) { \
g_test_message("Check failed: shouldn't have succeeded, but did"); \
g_test_fail(); \
} \
}
} while(0)
#define g_check_parse_ok(parser, input, inp_len, result) { \
#define g_check_parse_ok(parser, input, inp_len, result) do { \
parse_result_t *res = parse(parser, (const uint8_t*)input, inp_len); \
if (!res) { \
g_test_message("Parse failed on line %d", __LINE__); \
@ -83,7 +83,7 @@
stats.used, stats.wasted, \
stats.wasted * 100. / (stats.used+stats.wasted)); \
} \
}
} while(0)
#define g_check_cmpint(n1, op, n2) g_check_inttype("%d", int, n1, op, n2)