1 #ifndef _BASE64_MORETAP_H
2 #define _BASE64_MORETAP_H
4 #include <ccan/str/str.h>
7 * is_str - OK if strings are equal
8 * @e1: expression for the variable string
9 * @e2: expression for the expected string
11 * If the strings are equal, the test passes.
14 * is_str(give_me_a_fred(),"fred");
16 static void _is_str(char *got,const char *expected, const char *got_string, const char *expected_string, const char *func, const char *file, int line) {
17 if (streq(expected,got)) {
18 _gen_result(1, func, file, line,"%s eq %s",
19 got_string,expected_string);
21 _gen_result(0, func, file, line,"%s eq %s",
22 got_string,expected_string);
23 diag("Expected: %s",expected);
27 # define is_str(got,expected) _is_str(got,expected,#got,#expected,__func__, __FILE__, __LINE__)
31 * is_int - OK if arguments are equal when cast to integers
32 * @e1: expression for the number
33 * @e2: expression for the expected number
35 * If the numbers are equal, the test passes.
38 * is_int(give_me_17(),17);
40 # define is_int(e1,e2 ...) \
41 (((int)e1)==((int)e2) ? \
42 _gen_result(1, __func__, __FILE__, __LINE__,"%s == %s",#e1,#e2) : \
43 (_gen_result(0, __func__, __FILE__, __LINE__,"%s == %s",#e1,#e2)) || (diag("Expected: %d",e2),diag(" Got: %d",e1),0)) /* diag is void; note commas. */
48 * is_mem - OK if arguments are identical up to length @e3
49 * @e1: expression for the buffer
50 * @e2: expression for the expected buffer
51 * @e2: length to compare in buffers
53 * If the buffers are equal up to @e2, the test passes.
56 * is_mem(give_me_foo(),"foo",3);
58 static void _is_mem(const char *got, const char *expected, const size_t len,
59 const char *got_string, const char *expected_string, const char *len_string,
60 const char *func, const char *file, int line) {
63 for (offset=0; offset<len; offset++) {
64 if (got[offset] != expected[offset]) {
65 _gen_result(0, func, file, line,"%s eq %s",got_string,expected_string);
66 /* diag("Expected: %s",e2); */
67 /* diag(" Got: %s",e1); */
68 diag("Buffers differ at offset %zd (got=0x%02x expected=0x%02x)",
69 offset,got[offset],expected[offset]);
74 _gen_result(1, __func__, __FILE__, __LINE__,"%s eq %s",
75 expected_string,got_string);
77 # define is_mem(got,expected,len) \
78 _is_mem(got,expected,len,#got,#expected,#len,__func__, __FILE__, __LINE__)
81 * is_size_t - OK if arguments are equal when cast to size_t
82 * @e1: expression for the number
83 * @e2: expression for the expected number
85 * If the numbers are equal, the test passes.
88 * is_size_t(give_me_17(),17);
90 # define is_size_t(e1,e2 ...) \
91 ((size_t)(e1)==((size_t)e2) ? \
92 _gen_result(1, __func__, __FILE__, __LINE__,"%s == %s",#e1,#e2) : \
93 (_gen_result(0, __func__, __FILE__, __LINE__, \
94 "%s == %s",#e1,#e2)) || (diag("Expected: %zd",(size_t)e2),diag(" Got: %zd",(size_t)e1),0)) /* diag is void; note commas. */