From 853a2a10b1c305aca92e827d472722ba2211e505 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 25 Aug 2018 12:26:34 +0000 Subject: Stop using massive macros in `toxav_basic_test`. Turned a huge macro into a function. Macros are a pain to debug. --- auto_tests/toxav_basic_test.c | 135 ++++++++++++++++++++++-------------------- 1 file 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 { uint32_t state; } CallControl; +static void clear_call_control(CallControl *cc) +{ + const CallControl empty = {0}; + *cc = empty; +} + /** * Callbacks @@ -98,6 +104,55 @@ static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) tox_iterate(Bob, nullptr); } +static void regular_call_flow( + Tox *Alice, Tox *Bob, Tox *bootstrap, + ToxAV *AliceAV, ToxAV *BobAV, + CallControl *AliceCC, CallControl *BobCC, + int a_br, int v_br) +{ + clear_call_control(AliceCC); + clear_call_control(BobCC); + + TOXAV_ERR_CALL call_err; + toxav_call(AliceAV, 0, a_br, v_br, &call_err); + + if (call_err != TOXAV_ERR_CALL_OK) { + printf("toxav_call failed: %d\n", call_err); + ck_assert(0); + } + + time_t start_time = time(nullptr); + + while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED) { + if (BobCC->incoming) { + TOXAV_ERR_ANSWER answer_err; + toxav_answer(BobAV, 0, a_br, v_br, &answer_err); + + if (answer_err != TOXAV_ERR_ANSWER_OK) { + printf("toxav_answer failed: %d\n", answer_err); + ck_assert(0); + } + + BobCC->incoming = false; + } else { /* TODO(mannol): rtp */ + if (time(nullptr) - start_time >= 1) { + + TOXAV_ERR_CALL_CONTROL cc_err; + toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); + + if (cc_err != TOXAV_ERR_CALL_CONTROL_OK) { + printf("toxav_call_control failed: %d\n", cc_err); + ck_assert(0); + } + } + } + + iterate_tox(bootstrap, Alice, Bob); + } + + printf("Success!\n"); +} + static void test_av_flows(void) { Tox *Alice, *Bob, *bootstrap; @@ -181,77 +236,29 @@ static void test_av_flows(void) printf("Created 2 instances of ToxAV\n"); printf("All set after %llu seconds!\n", time(nullptr) - cur_time); - -#define REGULAR_CALL_FLOW(A_BR, V_BR) \ - do { \ - memset(&AliceCC, 0, sizeof(CallControl)); \ - memset(&BobCC, 0, sizeof(CallControl)); \ - \ - TOXAV_ERR_CALL call_err; \ - toxav_call(AliceAV, 0, A_BR, V_BR, &call_err); \ - \ - if (call_err != TOXAV_ERR_CALL_OK) { \ - printf("toxav_call failed: %d\n", call_err); \ - ck_assert(0); \ - } \ - \ - \ - long long unsigned int start_time = time(nullptr); \ - \ - \ - while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { \ - \ - if (BobCC.incoming) { \ - TOXAV_ERR_ANSWER answer_err; \ - toxav_answer(BobAV, 0, A_BR, V_BR, &answer_err); \ - \ - if (answer_err != TOXAV_ERR_ANSWER_OK) { \ - printf("toxav_answer failed: %d\n", answer_err); \ - ck_assert(0); \ - } \ - BobCC.incoming = false; \ - } else { \ - /* TODO(mannol): rtp */ \ - \ - if (time(nullptr) - start_time >= 1) { \ - \ - TOXAV_ERR_CALL_CONTROL cc_err; \ - toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); \ - \ - if (cc_err != TOXAV_ERR_CALL_CONTROL_OK) { \ - printf("toxav_call_control failed: %d\n", cc_err); \ - ck_assert(0); \ - } \ - } \ - } \ - \ - iterate_tox(bootstrap, Alice, Bob); \ - } \ - printf("Success!\n");\ - } while(0) - if (TEST_REGULAR_AV) { printf("\nTrying regular call (Audio and Video)...\n"); - REGULAR_CALL_FLOW(48, 4000); + regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, + 48, 4000); } if (TEST_REGULAR_A) { printf("\nTrying regular call (Audio only)...\n"); - REGULAR_CALL_FLOW(48, 0); + regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, + 48, 0); } if (TEST_REGULAR_V) { printf("\nTrying regular call (Video only)...\n"); - REGULAR_CALL_FLOW(0, 4000); + regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC, + 0, 4000); } -#undef REGULAR_CALL_FLOW - if (TEST_REJECT) { /* Alice calls; Bob rejects */ printf("\nTrying reject flow...\n"); - memset(&AliceCC, 0, sizeof(CallControl)); - memset(&BobCC, 0, sizeof(CallControl)); + clear_call_control(&AliceCC); + clear_call_control(&BobCC); { TOXAV_ERR_CALL rc; @@ -288,8 +295,8 @@ static void test_av_flows(void) if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */ printf("\nTrying cancel (while ringing) flow...\n"); - memset(&AliceCC, 0, sizeof(CallControl)); - memset(&BobCC, 0, sizeof(CallControl)); + clear_call_control(&AliceCC); + clear_call_control(&BobCC); { TOXAV_ERR_CALL rc; @@ -327,8 +334,8 @@ static void test_av_flows(void) if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */ printf("\nTrying mute functionality...\n"); - memset(&AliceCC, 0, sizeof(CallControl)); - memset(&BobCC, 0, sizeof(CallControl)); + clear_call_control(&AliceCC); + clear_call_control(&BobCC); /* Assume sending audio and video */ { @@ -417,8 +424,8 @@ static void test_av_flows(void) if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */ printf("\nTrying stop/resume functionality...\n"); - memset(&AliceCC, 0, sizeof(CallControl)); - memset(&BobCC, 0, sizeof(CallControl)); + clear_call_control(&AliceCC); + clear_call_control(&BobCC); /* Assume sending audio and video */ { @@ -485,8 +492,8 @@ static void test_av_flows(void) if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */ printf("\nTrying stop/resume functionality...\n"); - memset(&AliceCC, 0, sizeof(CallControl)); - memset(&BobCC, 0, sizeof(CallControl)); + clear_call_control(&AliceCC); + clear_call_control(&BobCC); /* Assume sending audio and video */ { -- cgit v1.2.3