1 /** 2 * @file test.h Selftest for Baresip core -- internal API 3 * 4 * Copyright (C) 2010 Creytiv.com 5 */ 6 7 8 #define ASSERT_TRUE(cond) \ 9 if (!(cond)) { \ 10 warning("selftest: ASSERT_TRUE: %s:%u:\n", \ 11 __FILE__, __LINE__); \ 12 err = EINVAL; \ 13 goto out; \ 14 } 15 16 #define ASSERT_EQ(expected, actual) \ 17 if ((expected) != (actual)) { \ 18 warning("selftest: ASSERT_EQ: %s:%u:" \ 19 " expected=%d, actual=%d\n", \ 20 __FILE__, __LINE__, \ 21 (int)(expected), (int)(actual)); \ 22 err = EINVAL; \ 23 goto out; \ 24 } 25 26 #define ASSERT_DOUBLE_EQ(expected, actual, prec) \ 27 if (!test_cmp_double((expected), (actual), (prec))) { \ 28 warning("selftest: ASSERT_DOUBLE_EQ: %s:%u:" \ 29 " expected=%f, actual=%f\n", \ 30 __FILE__, __LINE__, \ 31 (double)(expected), (double)(actual)); \ 32 err = EINVAL; \ 33 goto out; \ 34 } 35 36 #define ASSERT_STREQ(expected, actual) \ 37 if (0 != str_cmp((expected), (actual))) { \ 38 warning("selftest: ASSERT_STREQ: %s:%u:" \ 39 " expected = '%s', actual = '%s'\n", \ 40 __FILE__, __LINE__, \ 41 (expected), (actual)); \ 42 err = EBADMSG; \ 43 goto out; \ 44 } 45 46 #define TEST_ERR(err) \ 47 if ((err)) { \ 48 (void)re_fprintf(stderr, "\n"); \ 49 warning("TEST_ERR: %s:%u:" \ 50 " (%m)\n", \ 51 __FILE__, __LINE__, \ 52 (err)); \ 53 goto out; \ 54 } 55 56 #define TEST_MEMCMP(expected, expn, actual, actn) \ 57 if (expn != actn || \ 58 0 != memcmp((expected), (actual), (expn))) { \ 59 (void)re_fprintf(stderr, "\n"); \ 60 warning("TEST_MEMCMP: %s:%u:" \ 61 " %s(): failed\n", \ 62 __FILE__, __LINE__, __func__); \ 63 test_hexdump_dual(stderr, \ 64 expected, expn, \ 65 actual, actn); \ 66 err = EINVAL; \ 67 goto out; \ 68 } 69 70 #define TEST_STRCMP(expected, expn, actual, actn) \ 71 if (expn != actn || \ 72 0 != memcmp((expected), (actual), (expn))) { \ 73 (void)re_fprintf(stderr, "\n"); \ 74 warning("TEST_STRCMP: %s:%u:" \ 75 " failed\n", \ 76 __FILE__, __LINE__); \ 77 (void)re_fprintf(stderr, \ 78 "expected string: (%zu bytes)\n" \ 79 "\"%b\"\n", \ 80 (size_t)(expn), \ 81 (expected), (size_t)(expn)); \ 82 (void)re_fprintf(stderr, \ 83 "actual string: (%zu bytes)\n" \ 84 "\"%b\"\n", \ 85 (size_t)(actn), \ 86 (actual), (size_t)(actn)); \ 87 err = EINVAL; \ 88 goto out; \ 89 } 90 91 92 /* helpers */ 93 94 int re_main_timeout(uint32_t timeout_ms); 95 bool test_cmp_double(double a, double b, double precision); 96 void test_hexdump_dual(FILE *f, 97 const void *ep, size_t elen, 98 const void *ap, size_t alen); 99 100 101 #ifdef USE_TLS 102 extern const char test_certificate[]; 103 #endif 104 105 106 /* 107 * Mock DNS-Server 108 */ 109 110 struct dns_server { 111 struct udp_sock *us; 112 struct sa addr; 113 struct list rrl; 114 bool rotate; 115 }; 116 117 int dns_server_alloc(struct dns_server **srvp, bool rotate); 118 int dns_server_add_a(struct dns_server *srv, 119 const char *name, uint32_t addr); 120 int dns_server_add_srv(struct dns_server *srv, const char *name, 121 uint16_t pri, uint16_t weight, uint16_t port, 122 const char *target); 123 124 /* 125 * Mock Audio-codec 126 */ 127 128 void mock_aucodec_register(void); 129 void mock_aucodec_unregister(void); 130 131 /* 132 * Mock Audio-source 133 */ 134 135 struct ausrc; 136 137 int mock_ausrc_register(struct ausrc **ausrcp); 138 139 140 /* 141 * Mock Audio-player 142 */ 143 144 struct auplay; 145 146 typedef void (mock_sample_h)(const void *sampv, size_t sampc, void *arg); 147 148 int mock_auplay_register(struct auplay **auplayp, 149 mock_sample_h *sampleh, void *arg); 150 151 152 /* 153 * Mock Video-source 154 */ 155 156 struct vidsrc; 157 158 int mock_vidsrc_register(struct vidsrc **vidsrcp); 159 160 161 /* 162 * Mock Video-codec 163 */ 164 165 void mock_vidcodec_register(void); 166 void mock_vidcodec_unregister(void); 167 168 169 /* 170 * Mock Video-display 171 */ 172 173 struct vidisp; 174 175 int mock_vidisp_register(struct vidisp **vidispp); 176 177 178 /* test cases */ 179 180 int test_account(void); 181 int test_aulevel(void); 182 int test_cmd(void); 183 int test_cmd_long(void); 184 int test_event(void); 185 int test_contact(void); 186 int test_ua_alloc(void); 187 int test_uag_find_param(void); 188 int test_ua_register(void); 189 int test_ua_register_dns(void); 190 int test_ua_register_auth(void); 191 int test_ua_register_auth_dns(void); 192 int test_ua_options(void); 193 int test_message(void); 194 int test_mos(void); 195 int test_network(void); 196 int test_play(void); 197 198 int test_call_answer(void); 199 int test_call_reject(void); 200 int test_call_af_mismatch(void); 201 int test_call_answer_hangup_a(void); 202 int test_call_answer_hangup_b(void); 203 int test_call_rtp_timeout(void); 204 int test_call_multiple(void); 205 int test_call_max(void); 206 int test_call_dtmf(void); 207 int test_call_video(void); 208 int test_call_aulevel(void); 209 int test_call_progress(void); 210 int test_call_format_float(void); 211 212 #ifdef USE_VIDEO 213 int test_video(void); 214 #endif 215 216 217 #ifdef __cplusplus 218 extern "C" { 219 #endif 220 221 int test_cplusplus(void); 222 223 #ifdef __cplusplus 224 } 225 #endif 226