-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.h
More file actions
52 lines (45 loc) · 1.36 KB
/
Copy pathtest.h
File metadata and controls
52 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#define TEST_STRCMP_OP(r, op, x, ...) \
do { if(! (strcmp(((r), (x)) op 0)) { \
printf(__FILE__ ":%d ", __LINE__); \
printf(__VA_ARGS__); \
printf("\n\t" #r " " #op " " #x "\n" \
"\treceived: %s\n" \
"\texpected: %s\n", \
(r), (x));\
return -1; \
} } while(0)
#define TEST_MEMCMP_OP(r, op, x, n, ...) \
do { if(! (memcmp((r), (x), (n)) op 0)) { \
printf(__FILE__ ":%d ", __LINE__); \
printf(__VA_ARGS__); \
printf("\n\t" #r " " #op " " #x "\n" \
"\treceived: %.*s\n" \
"\texpected: %.*s\n", \
(int)(n), (r), (int)(n), (x));\
return -1; \
} } while(0)
#define TEST_OP(f, r, op, x, ...) \
do { if(! ((r) op (x)) ) { \
printf(__FILE__ ":%d ", __LINE__); \
printf(__VA_ARGS__); \
printf("\n\t" #r " " #op " " #x "\n" \
"\treceived: " f "\n" \
"\texpected: " f "\n", \
(r), (x));\
return -1; \
} } while(0)
static __attribute__ ((format (printf, 1, 2))) void
test_check_format(const char *format, ...)
{
(void)format;
}
#define STRIP_PARENS(...) __VA_ARGS__
#define TEST_CALL(buf, size, format, func, args) \
(test_check_format((format), STRIP_PARENS args), \
snprintf((buf), (size), ("%s(" format ")"), #func, STRIP_PARENS args), \
func args)
#define DEBUG_CALL(format, func, args) \
(test_check_format((format), STRIP_PARENS args), \
fprintf(stderr, ("%s(" format ")"), #func, STRIP_PARENS args), \
func args)