Astyled test.

This commit is contained in:
irungentoo 2014-04-05 14:47:58 -04:00
parent 1efb1d341f
commit 813198a6e7
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -22,8 +22,7 @@
#endif #endif
typedef enum _CallStatus typedef enum _CallStatus {
{
none, none,
InCall, InCall,
Ringing, Ringing,
@ -33,11 +32,10 @@ typedef enum _CallStatus
} CallStatus; } CallStatus;
typedef struct _Party typedef struct _Party {
{
CallStatus status; CallStatus status;
ToxAv* av; ToxAv *av;
time_t* CallStarted; time_t *CallStarted;
} Party; } Party;
typedef struct _Status { typedef struct _Status {
@ -56,38 +54,37 @@ void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t
/******************************************************************************/ /******************************************************************************/
void callback_recv_invite ( void *_arg ) void callback_recv_invite ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
/* Bob always receives invite */ /* Bob always receives invite */
cast->Bob.status= Ringing; cast->Bob.status = Ringing;
} }
void callback_recv_ringing ( void *_arg ) void callback_recv_ringing ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
/* Alice always sends invite */ /* Alice always sends invite */
cast->Alice.status= Ringing; cast->Alice.status = Ringing;
} }
void callback_recv_starting ( void *_arg ) void callback_recv_starting ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
/* Alice always sends invite */ /* Alice always sends invite */
printf("Call started on Alice side...\n"); printf("Call started on Alice side...\n");
cast->Alice.status= InCall; cast->Alice.status = InCall;
toxav_prepare_transmission(cast->Alice.av, 1); toxav_prepare_transmission(cast->Alice.av, 1);
} }
void callback_recv_ending ( void *_arg ) void callback_recv_ending ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
if ( cast->Alice.status == Rejected) { if ( cast->Alice.status == Rejected) {
printf ( "Call ended for Bob!\n" ); printf ( "Call ended for Bob!\n" );
cast->Bob.status = Ended; cast->Bob.status = Ended;
} } else {
else {
printf ( "Call ended for Alice!\n" ); printf ( "Call ended for Alice!\n" );
cast->Alice.status = Ended; cast->Alice.status = Ended;
} }
@ -100,23 +97,23 @@ void callback_recv_error ( void *_arg )
void callback_call_started ( void *_arg ) void callback_call_started ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
/* Alice always sends invite */ /* Alice always sends invite */
printf("Call started on Bob side...\n"); printf("Call started on Bob side...\n");
cast->Bob.status= InCall; cast->Bob.status = InCall;
toxav_prepare_transmission(cast->Bob.av, 1); toxav_prepare_transmission(cast->Bob.av, 1);
} }
void callback_call_canceled ( void *_arg ) void callback_call_canceled ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
printf ( "Call Canceled for Bob!\n" ); printf ( "Call Canceled for Bob!\n" );
cast->Bob.status = Cancel; cast->Bob.status = Cancel;
} }
void callback_call_rejected ( void *_arg ) void callback_call_rejected ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
printf ( "Call rejected by Bob!\n" printf ( "Call rejected by Bob!\n"
"Call ended for Alice!\n" ); "Call ended for Alice!\n" );
@ -125,7 +122,7 @@ void callback_call_rejected ( void *_arg )
} }
void callback_call_ended ( void *_arg ) void callback_call_ended ( void *_arg )
{ {
Status* cast = _arg; Status *cast = _arg;
printf ( "Call ended for Bob!\n" ); printf ( "Call ended for Bob!\n" );
cast->Bob.status = Ended; cast->Bob.status = Ended;
@ -174,6 +171,7 @@ START_TEST(test_AV)
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
uint8_t off = 1; uint8_t off = 1;
while (1) { while (1) {
tox_do(bootstrap_node); tox_do(bootstrap_node);
tox_do(Alice); tox_do(Alice);
@ -194,8 +192,7 @@ START_TEST(test_AV)
printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time); printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
Status status_control = Status status_control = {
{
{none, toxav_new(Alice, 128, 128), NULL}, {none, toxav_new(Alice, 128, 128), NULL},
{none, toxav_new(Bob, 128, 128), NULL}, {none, toxav_new(Bob, 128, 128), NULL},
}; };
@ -219,8 +216,8 @@ START_TEST(test_AV)
int16_t sample_payload[10] = {0,1,2,3,4,5,6,7,8,9}; int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
vpx_image_t* sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1); vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10); memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10);
memcpy(sample_image->planes[VPX_PLANE_U], sample_payload, 10); memcpy(sample_image->planes[VPX_PLANE_U], sample_payload, 10);
@ -234,8 +231,7 @@ START_TEST(test_AV)
/* /*
* Call with audio only on both sides. Alice calls Bob. * Call with audio only on both sides. Alice calls Bob.
*/ */
CALL_AND_START_LOOP(TypeAudio, TypeAudio) CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
{
/* Both send */ /* Both send */
toxav_send_audio(status_control.Alice.av, sample_payload, 10); toxav_send_audio(status_control.Alice.av, sample_payload, 10);
toxav_send_audio(status_control.Bob.av, sample_payload, 10); toxav_send_audio(status_control.Bob.av, sample_payload, 10);
@ -246,6 +242,7 @@ START_TEST(test_AV)
/* Payload from Alice */ /* Payload from Alice */
recved = toxav_recv_audio(status_control.Alice.av, 10, storage); recved = toxav_recv_audio(status_control.Alice.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
memset(storage, 0, 10); memset(storage, 0, 10);
@ -253,6 +250,7 @@ START_TEST(test_AV)
/* Payload from Bob */ /* Payload from Bob */
recved = toxav_recv_audio(status_control.Bob.av, 10, storage); recved = toxav_recv_audio(status_control.Bob.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
} }
@ -272,8 +270,7 @@ START_TEST(test_AV)
/* /*
* Call with audio on both sides and video on one side. Alice calls Bob. * Call with audio on both sides and video on one side. Alice calls Bob.
*/ */
CALL_AND_START_LOOP(TypeAudio, TypeVideo) CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
{
/* Both send */ /* Both send */
toxav_send_audio(status_control.Alice.av, sample_payload, 10); toxav_send_audio(status_control.Alice.av, sample_payload, 10);
@ -282,15 +279,17 @@ START_TEST(test_AV)
/* Both receive */ /* Both receive */
int16_t storage[10]; int16_t storage[10];
vpx_image_t* video_storage; vpx_image_t *video_storage;
int recved; int recved;
/* Payload from Bob */ /* Payload from Bob */
recved = toxav_recv_audio(status_control.Alice.av, 10, storage); recved = toxav_recv_audio(status_control.Alice.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
memset(storage, 0, 10); memset(storage, 0, 10);
} }
/* Video payload */ /* Video payload */
toxav_recv_video(status_control.Alice.av, &video_storage); toxav_recv_video(status_control.Alice.av, &video_storage);
@ -305,6 +304,7 @@ START_TEST(test_AV)
/* Payload from Alice */ /* Payload from Alice */
recved = toxav_recv_audio(status_control.Bob.av, 10, storage); recved = toxav_recv_audio(status_control.Bob.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
} }
@ -324,8 +324,7 @@ START_TEST(test_AV)
/* /*
* Call with audio and video on both sides. Alice calls Bob. * Call with audio and video on both sides. Alice calls Bob.
*/ */
CALL_AND_START_LOOP(TypeVideo, TypeVideo) CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
{
/* Both send */ /* Both send */
toxav_send_audio(status_control.Alice.av, sample_payload, 10); toxav_send_audio(status_control.Alice.av, sample_payload, 10);
toxav_send_video(status_control.Alice.av, sample_image); toxav_send_video(status_control.Alice.av, sample_image);
@ -335,15 +334,17 @@ START_TEST(test_AV)
/* Both receive */ /* Both receive */
int16_t storage[10]; int16_t storage[10];
vpx_image_t* video_storage; vpx_image_t *video_storage;
int recved; int recved;
/* Payload from Bob */ /* Payload from Bob */
recved = toxav_recv_audio(status_control.Alice.av, 10, storage); recved = toxav_recv_audio(status_control.Alice.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");
memset(storage, 0, 10); memset(storage, 0, 10);
} }
/* Video payload */ /* Video payload */
toxav_recv_video(status_control.Alice.av, &video_storage); toxav_recv_video(status_control.Alice.av, &video_storage);
@ -358,9 +359,11 @@ START_TEST(test_AV)
/* Payload from Alice */ /* Payload from Alice */
recved = toxav_recv_audio(status_control.Bob.av, 10, storage); recved = toxav_recv_audio(status_control.Bob.av, 10, storage);
if ( recved ) { if ( recved ) {
ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid"); ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");
} }
/* Video payload */ /* Video payload */
toxav_recv_video(status_control.Bob.av, &video_storage); toxav_recv_video(status_control.Bob.av, &video_storage);
@ -394,27 +397,38 @@ START_TEST(test_AV)
{ {
int step = 0; int step = 0;
int running = 1; int running = 1;
while (running) { while (running) {
tox_do(bootstrap_node); tox_do(bootstrap_node);
tox_do(Alice); tox_do(Alice);
tox_do(Bob); tox_do(Bob);
switch ( step ) { switch ( step ) {
case 0: /* Alice */ case 0: /* Alice */
printf("Alice is calling...\n"); printf("Alice is calling...\n");
toxav_call(status_control.Alice.av, 0, TypeAudio, 10); toxav_call(status_control.Alice.av, 0, TypeAudio, 10);
step++; step++;
break;\ break;
\
case 1: /* Bob */ case 1: /* Bob */
if (status_control.Bob.status == Ringing) { if (status_control.Bob.status == Ringing) {
printf("Bob rejects...\n"); printf("Bob rejects...\n");
toxav_reject(status_control.Bob.av, "Who likes D's anyway?"); toxav_reject(status_control.Bob.av, "Who likes D's anyway?");
step++; step++;
} break;
case 2: /* Wait for Both to have status ended */
if (status_control.Alice.status == Rejected && status_control.Bob.status == Ended) running = 0; break;
} }
break;
case 2: /* Wait for Both to have status ended */
if (status_control.Alice.status == Rejected && status_control.Bob.status == Ended) running = 0;
break;
}
c_sleep(20); c_sleep(20);
} }
printf("\n"); printf("\n");
} }
@ -425,27 +439,38 @@ START_TEST(test_AV)
{ {
int step = 0; int step = 0;
int running = 1; int running = 1;
while (running) { while (running) {
tox_do(bootstrap_node); tox_do(bootstrap_node);
tox_do(Alice); tox_do(Alice);
tox_do(Bob); tox_do(Bob);
switch ( step ) { switch ( step ) {
case 0: /* Alice */ case 0: /* Alice */
printf("Alice is calling...\n"); printf("Alice is calling...\n");
toxav_call(status_control.Alice.av, 0, TypeAudio, 10); toxav_call(status_control.Alice.av, 0, TypeAudio, 10);
step++; step++;
break;\ break;
\
case 1: /* Alice again */ case 1: /* Alice again */
if (status_control.Bob.status == Ringing) { if (status_control.Bob.status == Ringing) {
printf("Alice cancels...\n"); printf("Alice cancels...\n");
toxav_cancel(status_control.Alice.av, 0, "Who likes D's anyway?"); toxav_cancel(status_control.Alice.av, 0, "Who likes D's anyway?");
step++; step++;
} break;
case 2: /* Wait for Both to have status ended */
if (status_control.Alice.status == Ended && status_control.Bob.status == Cancel) running = 0; break;
} }
break;
case 2: /* Wait for Both to have status ended */
if (status_control.Alice.status == Ended && status_control.Bob.status == Cancel) running = 0;
break;
}
c_sleep(20); c_sleep(20);
} }
printf("\n"); printf("\n");
} }