Stop using massive macros in toxav_basic_test.

Turned a huge macro into a function. Macros are a pain to debug.
This commit is contained in:
iphydf 2018-08-25 12:26:34 +00:00
parent efcda6c319
commit 853a2a10b1
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9

View File

@ -43,6 +43,12 @@ typedef struct {
uint32_t state; uint32_t state;
} CallControl; } CallControl;
static void clear_call_control(CallControl *cc)
{
const CallControl empty = {0};
*cc = empty;
}
/** /**
* Callbacks * Callbacks
@ -98,6 +104,55 @@ static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
tox_iterate(Bob, nullptr); 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) static void test_av_flows(void)
{ {
Tox *Alice, *Bob, *bootstrap; Tox *Alice, *Bob, *bootstrap;
@ -181,77 +236,29 @@ static void test_av_flows(void)
printf("Created 2 instances of ToxAV\n"); printf("Created 2 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(nullptr) - cur_time); 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) { if (TEST_REGULAR_AV) {
printf("\nTrying regular call (Audio and Video)...\n"); 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) { if (TEST_REGULAR_A) {
printf("\nTrying regular call (Audio only)...\n"); 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) { if (TEST_REGULAR_V) {
printf("\nTrying regular call (Video only)...\n"); 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 */ if (TEST_REJECT) { /* Alice calls; Bob rejects */
printf("\nTrying reject flow...\n"); printf("\nTrying reject flow...\n");
memset(&AliceCC, 0, sizeof(CallControl)); clear_call_control(&AliceCC);
memset(&BobCC, 0, sizeof(CallControl)); clear_call_control(&BobCC);
{ {
TOXAV_ERR_CALL rc; TOXAV_ERR_CALL rc;
@ -288,8 +295,8 @@ static void test_av_flows(void)
if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */ if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */
printf("\nTrying cancel (while ringing) flow...\n"); printf("\nTrying cancel (while ringing) flow...\n");
memset(&AliceCC, 0, sizeof(CallControl)); clear_call_control(&AliceCC);
memset(&BobCC, 0, sizeof(CallControl)); clear_call_control(&BobCC);
{ {
TOXAV_ERR_CALL rc; TOXAV_ERR_CALL rc;
@ -327,8 +334,8 @@ static void test_av_flows(void)
if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */ if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */
printf("\nTrying mute functionality...\n"); printf("\nTrying mute functionality...\n");
memset(&AliceCC, 0, sizeof(CallControl)); clear_call_control(&AliceCC);
memset(&BobCC, 0, sizeof(CallControl)); clear_call_control(&BobCC);
/* Assume sending audio and video */ /* 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 */ if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */
printf("\nTrying stop/resume functionality...\n"); printf("\nTrying stop/resume functionality...\n");
memset(&AliceCC, 0, sizeof(CallControl)); clear_call_control(&AliceCC);
memset(&BobCC, 0, sizeof(CallControl)); clear_call_control(&BobCC);
/* Assume sending audio and video */ /* 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 */ if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */
printf("\nTrying stop/resume functionality...\n"); printf("\nTrying stop/resume functionality...\n");
memset(&AliceCC, 0, sizeof(CallControl)); clear_call_control(&AliceCC);
memset(&BobCC, 0, sizeof(CallControl)); clear_call_control(&BobCC);
/* Assume sending audio and video */ /* Assume sending audio and video */
{ {