Skip to content

Commit

Permalink
Stop using massive macros in toxav_basic_test.
Browse files Browse the repository at this point in the history
Turned a huge macro into a function. Macros are a pain to debug.
  • Loading branch information
iphydf committed Aug 25, 2018
1 parent efcda6c commit 97ee97a
Showing 1 changed file with 71 additions and 64 deletions.
135 changes: 71 additions & 64 deletions auto_tests/toxav_basic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ typedef struct {
uint32_t state;
} CallControl;

static void clear_call_control(CallControl *cc)
{
CallControl empty = {0};
*cc = empty;
}


/**
* Callbacks
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
{
Expand Down Expand Up @@ -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 */
{
Expand Down Expand Up @@ -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 */
{
Expand Down

0 comments on commit 97ee97a

Please sign in to comment.