diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 12:26:34 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-25 13:46:47 +0000 |
commit | 853a2a10b1c305aca92e827d472722ba2211e505 (patch) | |
tree | ef2e73780d3595cb709ae1ce944c5d7473e911e2 /auto_tests | |
parent | efcda6c31980cf696beb80cd2ef41a30ccaab158 (diff) |
Stop using massive macros in `toxav_basic_test`.
Turned a huge macro into a function. Macros are a pain to debug.
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/toxav_basic_test.c | 135 |
1 files changed, 71 insertions, 64 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 859c7a0c..4289df53 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -43,6 +43,12 @@ typedef struct { | |||
43 | uint32_t state; | 43 | uint32_t state; |
44 | } CallControl; | 44 | } CallControl; |
45 | 45 | ||
46 | static void clear_call_control(CallControl *cc) | ||
47 | { | ||
48 | const CallControl empty = {0}; | ||
49 | *cc = empty; | ||
50 | } | ||
51 | |||
46 | 52 | ||
47 | /** | 53 | /** |
48 | * Callbacks | 54 | * Callbacks |
@@ -98,6 +104,55 @@ static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) | |||
98 | tox_iterate(Bob, nullptr); | 104 | tox_iterate(Bob, nullptr); |
99 | } | 105 | } |
100 | 106 | ||
107 | static void regular_call_flow( | ||
108 | Tox *Alice, Tox *Bob, Tox *bootstrap, | ||
109 | ToxAV *AliceAV, ToxAV *BobAV, | ||
110 | CallControl *AliceCC, CallControl *BobCC, | ||
111 | int a_br, int v_br) | ||
112 | { | ||
113 | clear_call_control(AliceCC); | ||
114 | clear_call_control(BobCC); | ||
115 | |||
116 | TOXAV_ERR_CALL call_err; | ||
117 | toxav_call(AliceAV, 0, a_br, v_br, &call_err); | ||
118 | |||
119 | if (call_err != TOXAV_ERR_CALL_OK) { | ||
120 | printf("toxav_call failed: %d\n", call_err); | ||
121 | ck_assert(0); | ||
122 | } | ||
123 | |||
124 | time_t start_time = time(nullptr); | ||
125 | |||
126 | while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED) { | ||
127 | if (BobCC->incoming) { | ||
128 | TOXAV_ERR_ANSWER answer_err; | ||
129 | toxav_answer(BobAV, 0, a_br, v_br, &answer_err); | ||
130 | |||
131 | if (answer_err != TOXAV_ERR_ANSWER_OK) { | ||
132 | printf("toxav_answer failed: %d\n", answer_err); | ||
133 | ck_assert(0); | ||
134 | } | ||
135 | |||
136 | BobCC->incoming = false; | ||
137 | } else { /* TODO(mannol): rtp */ | ||
138 | if (time(nullptr) - start_time >= 1) { | ||
139 | |||
140 | TOXAV_ERR_CALL_CONTROL cc_err; | ||
141 | toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); | ||
142 | |||
143 | if (cc_err != TOXAV_ERR_CALL_CONTROL_OK) { | ||
144 | printf("toxav_call_control failed: %d\n", cc_err); | ||
145 | ck_assert(0); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | iterate_tox(bootstrap, Alice, Bob); | ||
151 | } | ||
152 | |||
153 | printf("Success!\n"); | ||
154 | } | ||
155 | |||
101 | static void test_av_flows(void) | 156 | static void test_av_flows(void) |
102 | { | 157 | { |
103 | Tox *Alice, *Bob, *bootstrap; | 158 | Tox *Alice, *Bob, *bootstrap; |
@@ -181,77 +236,29 @@ static void test_av_flows(void) | |||
181 | printf("Created 2 instances of ToxAV\n"); | 236 | printf("Created 2 instances of ToxAV\n"); |
182 | printf("All set after %llu seconds!\n", time(nullptr) - cur_time); | 237 | printf("All set after %llu seconds!\n", time(nullptr) - cur_time); |
183 | 238 | ||
184 | |||
185 | #define REGULAR_CALL_FLOW(A_BR, V_BR) \ | ||
186 | do { \ | ||
187 | memset(&AliceCC, 0, sizeof(CallControl)); \ | ||
188 | memset(&BobCC, 0, sizeof(CallControl)); \ | ||
189 | \ | ||
190 | TOXAV_ERR_CALL call_err; \ | ||
191 | toxav_call(AliceAV, 0, A_BR, V_BR, &call_err); \ | ||
192 | \ | ||
193 | if (call_err != TOXAV_ERR_CALL_OK) { \ | ||
194 | printf("toxav_call failed: %d\n", call_err); \ | ||
195 | ck_assert(0); \ | ||
196 | } \ | ||
197 | \ | ||
198 | \ | ||
199 | long long unsigned int start_time = time(nullptr); \ | ||
200 | \ | ||
201 | \ | ||
202 | while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { \ | ||
203 | \ | ||
204 | if (BobCC.incoming) { \ | ||
205 | TOXAV_ERR_ANSWER answer_err; \ | ||
206 | toxav_answer(BobAV, 0, A_BR, V_BR, &answer_err); \ | ||
207 | \ | ||
208 | if (answer_err != TOXAV_ERR_ANSWER_OK) { \ | ||
209 | printf("toxav_answer failed: %d\n", answer_err); \ | ||
210 | ck_assert(0); \ | ||
211 | } \ | ||
212 | BobCC.incoming = false; \ | ||
213 | } else { \ | ||
214 | /* TODO(mannol): rtp */ \ | ||
215 | \ | ||
216 | if (time(nullptr) - start_time >= 1) { \ | ||
217 | \ | ||
218 | TOXAV_ERR_CALL_CONTROL cc_err; \ | ||
219 | toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); \ | ||
220 | \ | ||
221 | if (cc_err != TOXAV_ERR_CALL_CONTROL_OK) { \ | ||
222 | printf("toxav_call_control failed: %d\n", cc_err); \ | ||
223 | ck_assert(0); \ | ||
224 | } \ | ||
225 | } \ | ||
226 | } \ | ||
227 | \ | ||
228 | iterate_tox(bootstrap, Alice, Bob); \ | ||
229 | } \ | ||
230 | printf("Success!\n");\ | ||
231 | } while(0) | ||
232 | |||
233 | if (TEST_REGULAR_AV) { | 239 | if (TEST_REGULAR_AV) { |
234 | printf("\nTrying regular call (Audio and Video)...\n"); | 240 | printf("\nTrying regular call (Audio and Video)...\n"); |
235 | REGULAR_CALL_FLOW(48, 4000); | 241 | regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, |
242 | 48, 4000); | ||
236 | } | 243 | } |
237 | 244 | ||
238 | if (TEST_REGULAR_A) { | 245 | if (TEST_REGULAR_A) { |
239 | printf("\nTrying regular call (Audio only)...\n"); | 246 | printf("\nTrying regular call (Audio only)...\n"); |
240 | REGULAR_CALL_FLOW(48, 0); | 247 | regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, |
248 | 48, 0); | ||
241 | } | 249 | } |
242 | 250 | ||
243 | if (TEST_REGULAR_V) { | 251 | if (TEST_REGULAR_V) { |
244 | printf("\nTrying regular call (Video only)...\n"); | 252 | printf("\nTrying regular call (Video only)...\n"); |
245 | REGULAR_CALL_FLOW(0, 4000); | 253 | regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, |
254 | 0, 4000); | ||
246 | } | 255 | } |
247 | 256 | ||
248 | #undef REGULAR_CALL_FLOW | ||
249 | |||
250 | if (TEST_REJECT) { /* Alice calls; Bob rejects */ | 257 | if (TEST_REJECT) { /* Alice calls; Bob rejects */ |
251 | printf("\nTrying reject flow...\n"); | 258 | printf("\nTrying reject flow...\n"); |
252 | 259 | ||
253 | memset(&AliceCC, 0, sizeof(CallControl)); | 260 | clear_call_control(&AliceCC); |
254 | memset(&BobCC, 0, sizeof(CallControl)); | 261 | clear_call_control(&BobCC); |
255 | 262 | ||
256 | { | 263 | { |
257 | TOXAV_ERR_CALL rc; | 264 | TOXAV_ERR_CALL rc; |
@@ -288,8 +295,8 @@ static void test_av_flows(void) | |||
288 | if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */ | 295 | if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */ |
289 | printf("\nTrying cancel (while ringing) flow...\n"); | 296 | printf("\nTrying cancel (while ringing) flow...\n"); |
290 | 297 | ||
291 | memset(&AliceCC, 0, sizeof(CallControl)); | 298 | clear_call_control(&AliceCC); |
292 | memset(&BobCC, 0, sizeof(CallControl)); | 299 | clear_call_control(&BobCC); |
293 | 300 | ||
294 | { | 301 | { |
295 | TOXAV_ERR_CALL rc; | 302 | TOXAV_ERR_CALL rc; |
@@ -327,8 +334,8 @@ static void test_av_flows(void) | |||
327 | if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */ | 334 | if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */ |
328 | printf("\nTrying mute functionality...\n"); | 335 | printf("\nTrying mute functionality...\n"); |
329 | 336 | ||
330 | memset(&AliceCC, 0, sizeof(CallControl)); | 337 | clear_call_control(&AliceCC); |
331 | memset(&BobCC, 0, sizeof(CallControl)); | 338 | clear_call_control(&BobCC); |
332 | 339 | ||
333 | /* Assume sending audio and video */ | 340 | /* Assume sending audio and video */ |
334 | { | 341 | { |
@@ -417,8 +424,8 @@ static void test_av_flows(void) | |||
417 | if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */ | 424 | if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */ |
418 | printf("\nTrying stop/resume functionality...\n"); | 425 | printf("\nTrying stop/resume functionality...\n"); |
419 | 426 | ||
420 | memset(&AliceCC, 0, sizeof(CallControl)); | 427 | clear_call_control(&AliceCC); |
421 | memset(&BobCC, 0, sizeof(CallControl)); | 428 | clear_call_control(&BobCC); |
422 | 429 | ||
423 | /* Assume sending audio and video */ | 430 | /* Assume sending audio and video */ |
424 | { | 431 | { |
@@ -485,8 +492,8 @@ static void test_av_flows(void) | |||
485 | if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */ | 492 | if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */ |
486 | printf("\nTrying stop/resume functionality...\n"); | 493 | printf("\nTrying stop/resume functionality...\n"); |
487 | 494 | ||
488 | memset(&AliceCC, 0, sizeof(CallControl)); | 495 | clear_call_control(&AliceCC); |
489 | memset(&BobCC, 0, sizeof(CallControl)); | 496 | clear_call_control(&BobCC); |
490 | 497 | ||
491 | /* Assume sending audio and video */ | 498 | /* Assume sending audio and video */ |
492 | { | 499 | { |