diff options
Diffstat (limited to 'auto_tests/toxav_basic_test.c')
-rw-r--r-- | auto_tests/toxav_basic_test.c | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 0dc330e0..5fe17b40 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -126,7 +126,7 @@ void callback_call_rejected ( void *av, int32_t call_index, void *_arg ) | |||
126 | void callback_call_ended ( void *av, int32_t call_index, void *_arg ) | 126 | void callback_call_ended ( void *av, int32_t call_index, void *_arg ) |
127 | { | 127 | { |
128 | Status *cast = _arg; | 128 | Status *cast = _arg; |
129 | 129 | ||
130 | printf ( "Call ended for Bob!\n" ); | 130 | printf ( "Call ended for Bob!\n" ); |
131 | cast->Bob.status = Ended; | 131 | cast->Bob.status = Ended; |
132 | } | 132 | } |
@@ -134,7 +134,7 @@ void callback_call_ended ( void *av, int32_t call_index, void *_arg ) | |||
134 | void callback_call_type_change ( void *av, int32_t call_index, void *_arg ) | 134 | void callback_call_type_change ( void *av, int32_t call_index, void *_arg ) |
135 | { | 135 | { |
136 | printf("Call type changed; new type: %s!\n", toxav_get_peer_transmission_type | 136 | printf("Call type changed; new type: %s!\n", toxav_get_peer_transmission_type |
137 | (av, call_index, 0) == TypeAudio ? "audio" : "video"); | 137 | (av, call_index, 0) == TypeAudio ? "audio" : "video"); |
138 | } | 138 | } |
139 | 139 | ||
140 | void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) | 140 | void callback_requ_timeout ( void *av, int32_t call_index, void *_arg ) |
@@ -152,22 +152,22 @@ static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img) | |||
152 | { | 152 | { |
153 | } | 153 | } |
154 | 154 | ||
155 | void register_callbacks(ToxAv* av, void* data) | 155 | void register_callbacks(ToxAv *av, void *data) |
156 | { | 156 | { |
157 | toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data); | 157 | toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data); |
158 | toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data); | 158 | toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data); |
159 | toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data); | 159 | toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data); |
160 | toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data); | 160 | toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data); |
161 | toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data); | 161 | toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data); |
162 | 162 | ||
163 | toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data); | 163 | toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data); |
164 | toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data); | 164 | toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data); |
165 | toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data); | 165 | toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data); |
166 | 166 | ||
167 | toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); | 167 | toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data); |
168 | toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data); | 168 | toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data); |
169 | 169 | ||
170 | 170 | ||
171 | toxav_register_audio_recv_callback(av, callback_audio); | 171 | toxav_register_audio_recv_callback(av, callback_audio); |
172 | toxav_register_video_recv_callback(av, callback_video); | 172 | toxav_register_video_recv_callback(av, callback_video); |
173 | } | 173 | } |
@@ -378,49 +378,49 @@ START_TEST(test_AV_flows) | |||
378 | } | 378 | } |
379 | TERMINATE_SCOPE() | 379 | TERMINATE_SCOPE() |
380 | 380 | ||
381 | 381 | ||
382 | uint64_t times_they_are_a_changin = time(NULL); | 382 | uint64_t times_they_are_a_changin = time(NULL); |
383 | /* Media change */ | 383 | /* Media change */ |
384 | CALL_AND_START_LOOP(TypeAudio, TypeAudio) { | 384 | CALL_AND_START_LOOP(TypeAudio, TypeAudio) { |
385 | /* Both send */ | 385 | /* Both send */ |
386 | payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, | 386 | payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, |
387 | 1000, sample_payload, frame_size); | 387 | 1000, sample_payload, frame_size); |
388 | 388 | ||
389 | if ( payload_size < 0 ) { | 389 | if ( payload_size < 0 ) { |
390 | ck_assert_msg ( 0, "Failed to encode payload" ); | 390 | ck_assert_msg ( 0, "Failed to encode payload" ); |
391 | } | 391 | } |
392 | 392 | ||
393 | toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); | 393 | toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); |
394 | 394 | ||
395 | payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, | 395 | payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, |
396 | sample_payload, frame_size); | 396 | sample_payload, frame_size); |
397 | 397 | ||
398 | if ( payload_size < 0 ) { | 398 | if ( payload_size < 0 ) { |
399 | ck_assert_msg ( 0, "Failed to encode payload" ); | 399 | ck_assert_msg ( 0, "Failed to encode payload" ); |
400 | } | 400 | } |
401 | 401 | ||
402 | toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); | 402 | toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); |
403 | 403 | ||
404 | /* Wait 2 seconds and change transmission type */ | 404 | /* Wait 2 seconds and change transmission type */ |
405 | if (time(NULL) - times_they_are_a_changin > 2) { | 405 | if (time(NULL) - times_they_are_a_changin > 2) { |
406 | times_they_are_a_changin = time(NULL); | 406 | times_they_are_a_changin = time(NULL); |
407 | toxav_change_type(status_control.Alice.av, status_control.Alice.call_index, | 407 | toxav_change_type(status_control.Alice.av, status_control.Alice.call_index, |
408 | toxav_get_peer_transmission_type(status_control.Bob.av, status_control.Bob.call_index, 0) | 408 | toxav_get_peer_transmission_type(status_control.Bob.av, status_control.Bob.call_index, 0) |
409 | == TypeAudio ? TypeVideo : TypeAudio); | 409 | == TypeAudio ? TypeVideo : TypeAudio); |
410 | } | 410 | } |
411 | 411 | ||
412 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ | 412 | if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ |
413 | step++; /* This terminates the loop */ | 413 | step++; /* This terminates the loop */ |
414 | toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); | 414 | toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); |
415 | toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); | 415 | toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); |
416 | 416 | ||
417 | /* Call over Alice hangs up */ | 417 | /* Call over Alice hangs up */ |
418 | toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); | 418 | toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); |
419 | } | 419 | } |
420 | } | 420 | } |
421 | TERMINATE_SCOPE() | 421 | TERMINATE_SCOPE() |
422 | 422 | ||
423 | 423 | ||
424 | /************************************************************************************************* | 424 | /************************************************************************************************* |
425 | * Other flows | 425 | * Other flows |
426 | */ | 426 | */ |
@@ -465,78 +465,80 @@ START_TEST(test_AV_flows) | |||
465 | printf("\n"); | 465 | printf("\n"); |
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||
469 | /* | 469 | /* |
470 | * Call and cancel | 470 | * Call and cancel |
471 | */ | 471 | */ |
472 | { | 472 | { |
473 | int step = 0; | 473 | int step = 0; |
474 | int running = 1; | 474 | int running = 1; |
475 | 475 | ||
476 | while (running) { | 476 | while (running) { |
477 | tox_do(bootstrap_node); | 477 | tox_do(bootstrap_node); |
478 | tox_do(Alice); | 478 | tox_do(Alice); |
479 | tox_do(Bob); | 479 | tox_do(Bob); |
480 | 480 | ||
481 | switch ( step ) { | 481 | switch ( step ) { |
482 | case 0: /* Alice */ | 482 | case 0: /* Alice */ |
483 | printf("Alice is calling...\n"); | 483 | printf("Alice is calling...\n"); |
484 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); | 484 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); |
485 | step++; | 485 | step++; |
486 | break; | 486 | break; |
487 | 487 | ||
488 | 488 | ||
489 | case 1: /* Alice again */ | 489 | case 1: /* Alice again */ |
490 | if (status_control.Bob.status == Ringing) { | 490 | if (status_control.Bob.status == Ringing) { |
491 | printf("Alice cancels...\n"); | 491 | printf("Alice cancels...\n"); |
492 | toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?"); | 492 | toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?"); |
493 | step++; | 493 | step++; |
494 | } | 494 | } |
495 | 495 | ||
496 | break; | 496 | break; |
497 | 497 | ||
498 | case 2: /* Wait for Both to have status ended */ | 498 | case 2: /* Wait for Both to have status ended */ |
499 | if (status_control.Bob.status == Cancel) running = 0; | 499 | if (status_control.Bob.status == Cancel) running = 0; |
500 | 500 | ||
501 | break; | 501 | break; |
502 | } | 502 | } |
503 | 503 | ||
504 | c_sleep(20); | 504 | c_sleep(20); |
505 | } | 505 | } |
506 | 506 | ||
507 | printf("\n"); | 507 | printf("\n"); |
508 | } | 508 | } |
509 | 509 | ||
510 | /* | 510 | /* |
511 | * Timeout | 511 | * Timeout |
512 | */ | 512 | */ |
513 | { | 513 | { |
514 | int step = 0; | 514 | int step = 0; |
515 | int running = 1; | 515 | int running = 1; |
516 | |||
516 | while (running) { | 517 | while (running) { |
517 | tox_do(bootstrap_node); | 518 | tox_do(bootstrap_node); |
518 | tox_do(Alice); | 519 | tox_do(Alice); |
519 | tox_do(Bob); | 520 | tox_do(Bob); |
520 | 521 | ||
521 | switch ( step ) { | 522 | switch ( step ) { |
522 | case 0: | 523 | case 0: |
523 | printf("Alice is calling...\n"); | 524 | printf("Alice is calling...\n"); |
524 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); | 525 | toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); |
525 | step++; | 526 | step++; |
526 | break; | 527 | break; |
527 | 528 | ||
528 | case 1: | 529 | case 1: |
529 | if (status_control.Alice.status == TimedOut) running = 0; | 530 | if (status_control.Alice.status == TimedOut) running = 0; |
531 | |||
530 | break; | 532 | break; |
531 | } | 533 | } |
532 | 534 | ||
533 | c_sleep(20); | 535 | c_sleep(20); |
534 | } | 536 | } |
535 | 537 | ||
536 | printf("\n"); | 538 | printf("\n"); |
537 | } | 539 | } |
538 | 540 | ||
539 | 541 | ||
540 | 542 | ||
541 | 543 | ||
542 | printf("Calls ended!\n"); | 544 | printf("Calls ended!\n"); |