toxcore/auto_tests/toxav_basic_test.c

657 lines
20 KiB
C
Raw Normal View History

2014-04-05 23:09:44 +08:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <check.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
2014-11-18 07:46:46 +08:00
#include <vpx/vpx_image.h>
2014-04-05 23:09:44 +08:00
#include "../toxcore/tox.h"
2014-04-28 01:21:26 +08:00
#include "../toxcore/logger.h"
2014-05-24 22:02:01 +08:00
#include "../toxcore/crypto_core.h"
2014-04-05 23:09:44 +08:00
#include "../toxav/toxav.h"
#include "helpers.h"
2014-04-05 23:09:44 +08:00
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
#define c_sleep(x) Sleep(1*x)
#else
#include <unistd.h>
#define c_sleep(x) usleep(1000*x)
#endif
2014-04-28 01:21:26 +08:00
2014-04-06 02:47:58 +08:00
typedef enum _CallStatus {
2014-04-05 23:09:44 +08:00
none,
InCall,
Ringing,
Ended,
Rejected,
2014-11-18 07:46:46 +08:00
Canceled,
TimedOut
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
} CallStatus;
2014-04-06 02:47:58 +08:00
typedef struct _Party {
2014-04-05 23:09:44 +08:00
CallStatus status;
2014-04-06 02:47:58 +08:00
ToxAv *av;
time_t *CallStarted;
2014-04-28 01:21:26 +08:00
int call_index;
2014-04-05 23:09:44 +08:00
} Party;
typedef struct _Status {
Party Alice;
Party Bob;
} Status;
2014-05-11 00:00:49 +08:00
/* My default settings */
2014-07-27 06:26:58 +08:00
static ToxAvCSettings muhcaps;
2014-05-11 00:00:49 +08:00
2014-06-11 06:51:40 +08:00
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
2014-04-06 02:47:58 +08:00
{
2014-04-28 01:21:26 +08:00
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
2014-04-05 23:09:44 +08:00
tox_add_friend_norequest(m, public_key);
}
}
/******************************************************************************/
void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
// ...
}
else if (cast->Bob.av == av)
{
/* Bob always receives invite */
cast->Bob.status = Ringing;
cast->Bob.call_index = call_index;
}
2014-04-05 23:09:44 +08:00
}
void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
/* Alice always sends invite */
cast->Alice.status = Ringing;
}
else if (cast->Bob.av == av)
{
// ...
2014-04-05 23:09:44 +08:00
}
}
void callback_call_started ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
printf("Call started on Alices side...\n");
cast->Alice.status = InCall;
toxav_prepare_transmission(av, call_index, 1);
}
else if (cast->Bob.av == av)
{
printf("Call started on Bob side...\n");
cast->Bob.status = InCall;
toxav_prepare_transmission(av, call_index, 1);
}
2014-04-05 23:09:44 +08:00
}
void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
// ...
}
else if (cast->Bob.av == av)
{
printf ( "Call Canceled for Bob!\n" );
cast->Bob.status = Canceled;
}
2014-04-05 23:09:44 +08:00
}
void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-04-05 23:09:44 +08:00
printf ( "Call rejected by Bob!\n"
"Call ended for Alice!\n" );
/* If Bob rejects, call is ended for alice and she sends ending */
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
cast->Alice.status = Rejected;
}
else if (cast->Bob.av == av)
{
//... ignor
}
2014-04-05 23:09:44 +08:00
}
void callback_call_ended ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
2014-04-06 02:47:58 +08:00
Status *cast = _arg;
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
printf ( "Call ended for Alice!\n" );
cast->Alice.status = Ended;
}
else if (cast->Bob.av == av)
{
printf ( "Call ended for Bob!\n" );
cast->Bob.status = Ended;
}
2014-04-05 23:09:44 +08:00
}
2014-11-18 07:46:46 +08:00
void callback_peer_cs_change ( void *av, int32_t call_index, void *_arg )
{
2014-07-27 06:26:58 +08:00
ToxAvCSettings csettings;
2014-07-27 01:29:49 +08:00
toxav_get_peer_csettings(av, call_index, 0, &csettings);
2014-11-18 07:46:46 +08:00
printf("Peer changing settings to: \n"
"Type: %u \n"
"Video bitrate: %u \n"
"Video height: %u \n"
"Video width: %u \n"
"Audio bitrate: %u \n"
"Audio framedur: %u \n"
"Audio sample rate: %u \n"
"Audio channels: %u \n",
csettings.call_type,
csettings.video_bitrate,
csettings.max_video_height,
csettings.max_video_width,
csettings.audio_bitrate,
csettings.audio_frame_duration,
csettings.audio_sample_rate,
csettings.audio_channels
);
}
2014-07-27 09:26:32 +08:00
2014-11-18 07:46:46 +08:00
void callback_self_cs_change ( void *av, int32_t call_index, void *_arg )
{
ToxAvCSettings csettings;
toxav_get_peer_csettings(av, call_index, 0, &csettings);
printf("Changed settings to: \n"
"Type: %u \n"
"Video bitrate: %u \n"
"Video height: %u \n"
"Video width: %u \n"
"Audio bitrate: %u \n"
"Audio framedur: %u \n"
"Audio sample rate: %u \n"
"Audio channels: %u \n",
csettings.call_type,
csettings.video_bitrate,
csettings.max_video_height,
csettings.max_video_width,
csettings.audio_bitrate,
csettings.audio_frame_duration,
csettings.audio_sample_rate,
csettings.audio_channels
);
}
void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
2014-04-05 23:09:44 +08:00
{
Status *cast = _arg;
2014-07-22 04:11:59 +08:00
printf("Call timed-out!\n");
2014-11-18 07:46:46 +08:00
if (cast->Alice.av == av)
{
cast->Alice.status = TimedOut;
}
else if (cast->Bob.av == av)
{
cast->Bob.status = TimedOut;
}
2014-04-05 23:09:44 +08:00
}
2014-07-08 05:37:05 +08:00
2014-11-18 07:46:46 +08:00
void callback_audio (void* agent, int32_t call_idx, const int16_t* PCM, uint16_t size, void* data)
{}
2014-07-08 05:37:05 +08:00
2014-11-18 07:46:46 +08:00
void callback_video (void* agent, int32_t call_idx, const vpx_image_t* img, void* data)
{}
2014-07-08 05:37:05 +08:00
void register_callbacks(ToxAv *av, void *data)
2014-04-05 23:09:44 +08:00
{
toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
2014-11-18 07:46:46 +08:00
toxav_register_callstate_callback(av, callback_peer_cs_change, av_OnPeerCSChange, data);
toxav_register_callstate_callback(av, callback_self_cs_change, av_OnSelfCSChange, data);
toxav_register_audio_callback(callback_audio, NULL);
toxav_register_video_callback(callback_video, NULL);
2014-04-05 23:09:44 +08:00
}
2014-07-21 10:10:05 +08:00
2014-04-05 23:09:44 +08:00
/*************************************************************************************************/
/* Alice calls bob and the call starts.
* What happens during the call is defined after. To quit the loop use: step++;
2014-04-05 23:09:44 +08:00
*/
#define CALL_AND_START_LOOP(AliceCallType, BobCallType) \
{ int step = 0, running = 1; while (running) {\
tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \
2014-11-18 07:46:46 +08:00
toxav_do(status_control.Bob.av); toxav_do(status_control.Alice.av); \
2014-04-05 23:09:44 +08:00
switch ( step ) {\
case 0: /* Alice */ printf("Alice is calling...\n");\
2014-07-27 01:29:49 +08:00
toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10); step++; break;\
2014-04-05 23:09:44 +08:00
case 1: /* Bob */ if (status_control.Bob.status == Ringing) { printf("Bob answers...\n");\
2014-07-27 01:29:49 +08:00
cur_time = time(NULL); toxav_answer(status_control.Bob.av, status_control.Bob.call_index, &muhcaps); step++; } break; \
2014-04-05 23:09:44 +08:00
case 2: /* Rtp transmission */ \
if (status_control.Bob.status == InCall && status_control.Alice.status == InCall)
#define TERMINATE_SCOPE() break;\
case 3: /* Wait for Both to have status ended */\
if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n");
2014-04-06 02:47:58 +08:00
2014-04-28 01:21:26 +08:00
START_TEST(test_AV_flows)
2014-04-06 02:47:58 +08:00
{
2014-04-05 23:09:44 +08:00
long long unsigned int cur_time = time(NULL);
Tox *bootstrap_node = tox_new(0);
Tox *Alice = tox_new(0);
Tox *Bob = tox_new(0);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances");
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
uint32_t to_compare = 974536;
tox_callback_friend_request(Alice, accept_friend_request, &to_compare);
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(Alice, address);
2014-04-28 01:21:26 +08:00
int test = tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
uint8_t off = 1;
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
while (1) {
tox_do(bootstrap_node);
tox_do(Alice);
tox_do(Bob);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
if (tox_isconnected(bootstrap_node) && tox_isconnected(Alice) && tox_isconnected(Bob) && off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
off = 0;
}
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
if (tox_get_friend_connection_status(Alice, 0) == 1 && tox_get_friend_connection_status(Bob, 0) == 1)
break;
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
c_sleep(20);
}
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
2014-04-06 02:47:58 +08:00
2014-05-11 00:00:49 +08:00
muhcaps = av_DefaultSettings;
muhcaps.max_video_height = muhcaps.max_video_width = 128;
2014-04-06 02:47:58 +08:00
Status status_control = {
2014-05-24 22:02:01 +08:00
{none, toxav_new(Alice, 1), NULL, -1},
{none, toxav_new(Bob, 1), NULL, -1},
2014-04-05 23:09:44 +08:00
};
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances");
2014-04-06 02:47:58 +08:00
register_callbacks(status_control.Alice.av, &status_control);
register_callbacks(status_control.Bob.av, &status_control);
2014-04-06 02:47:58 +08:00
2014-05-24 22:02:01 +08:00
const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
int16_t sample_payload[frame_size];
randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);
2014-05-24 22:02:01 +08:00
uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
2014-05-11 00:00:49 +08:00
int payload_size;
2014-04-06 02:47:58 +08:00
vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
2014-04-05 23:09:44 +08:00
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_V], sample_payload, 10);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/*************************************************************************************************
* Successful flows (when call starts)
*/
2014-04-06 02:47:58 +08:00
/*
2014-04-05 23:09:44 +08:00
* Call with audio only on both sides. Alice calls Bob.
*/
2014-05-24 22:02:01 +08:00
2014-04-06 02:47:58 +08:00
CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
2014-04-05 23:09:44 +08:00
/* Both send */
payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
1000, sample_payload, frame_size);
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
2014-05-11 00:00:49 +08:00
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-11 00:00:49 +08:00
toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
sample_payload, frame_size);
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-11 00:00:49 +08:00
toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
step++; /* This terminates the loop */
2014-04-28 01:21:26 +08:00
toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/* Call over Alice hangs up */
2014-04-28 01:21:26 +08:00
toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
2014-04-05 23:09:44 +08:00
}
}
TERMINATE_SCOPE()
2014-04-06 02:47:58 +08:00
/*
2014-04-05 23:09:44 +08:00
* Call with audio on both sides and video on one side. Alice calls Bob.
*/
2014-04-06 02:47:58 +08:00
CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
2014-04-05 23:09:44 +08:00
/* Both send */
payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
1000, sample_payload, frame_size);
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
2014-05-11 00:00:49 +08:00
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-11 00:00:49 +08:00
toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
sample_payload, frame_size);
2014-04-06 02:47:58 +08:00
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-11 00:00:49 +08:00
toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
2014-05-11 00:00:49 +08:00
// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
step++; /* This terminates the loop */
2014-04-28 01:21:26 +08:00
toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/* Call over Alice hangs up */
2014-04-28 01:21:26 +08:00
toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
2014-04-05 23:09:44 +08:00
}
}
TERMINATE_SCOPE()
2014-04-06 02:47:58 +08:00
/*
2014-04-05 23:09:44 +08:00
* Call with audio and video on both sides. Alice calls Bob.
*/
2014-04-06 02:47:58 +08:00
CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
2014-04-05 23:09:44 +08:00
/* Both send */
2014-04-06 02:47:58 +08:00
payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
1000, sample_payload, frame_size);
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
2014-05-11 00:00:49 +08:00
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-24 22:02:01 +08:00
toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
sample_payload, frame_size);
2014-05-24 22:02:01 +08:00
if ( payload_size < 0 ) {
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-05-11 00:00:49 +08:00
toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
2014-05-24 22:02:01 +08:00
// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
2014-05-11 00:00:49 +08:00
// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
2014-04-06 02:47:58 +08:00
if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
step++; /* This terminates the loop */
toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
2014-04-06 02:47:58 +08:00
/* Call over Alice hangs up */
toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
2014-04-05 23:09:44 +08:00
}
}
TERMINATE_SCOPE()
2014-04-06 02:47:58 +08:00
uint64_t times_they_are_a_changin = time(NULL);
/* Media change */
CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
/* Both send */
payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
1000, sample_payload, frame_size);
2014-04-06 02:47:58 +08:00
if ( payload_size < 0 ) {
ck_assert_msg ( 0, "Failed to encode payload" );
2014-04-05 23:09:44 +08:00
}
2014-04-06 02:47:58 +08:00
toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
2014-04-06 02:47:58 +08:00
payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
sample_payload, frame_size);
2014-04-06 02:47:58 +08:00
if ( payload_size < 0 ) {
ck_assert_msg ( 0, "Failed to encode payload" );
}
2014-04-06 02:47:58 +08:00
toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
2014-04-06 02:47:58 +08:00
/* Wait 2 seconds and change transmission type */
if (time(NULL) - times_they_are_a_changin > 2) {
times_they_are_a_changin = time(NULL);
2014-07-27 01:29:49 +08:00
muhcaps.audio_bitrate ++;
toxav_change_settings(status_control.Alice.av, status_control.Alice.call_index, &muhcaps);
}
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
step++; /* This terminates the loop */
2014-04-28 01:21:26 +08:00
toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/* Call over Alice hangs up */
2014-04-28 01:21:26 +08:00
toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
2014-04-05 23:09:44 +08:00
}
}
TERMINATE_SCOPE()
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/*************************************************************************************************
* Other flows
*/
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/*
* Call and reject
*/
2014-04-06 02:47:58 +08:00
{
2014-04-05 23:09:44 +08:00
int step = 0;
int running = 1;
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
while (running) {
2014-04-06 02:47:58 +08:00
tox_do(bootstrap_node);
tox_do(Alice);
2014-04-05 23:09:44 +08:00
tox_do(Bob);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
switch ( step ) {
2014-04-06 02:47:58 +08:00
case 0: /* Alice */
2014-04-05 23:09:44 +08:00
printf("Alice is calling...\n");
2014-07-27 01:29:49 +08:00
toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
2014-04-06 02:47:58 +08:00
step++;
break;
case 1: /* Bob */
if (status_control.Bob.status == Ringing) {
printf("Bob rejects...\n");
2014-04-28 01:21:26 +08:00
toxav_reject(status_control.Bob.av, status_control.Bob.call_index, "Who likes D's anyway?");
2014-04-06 02:47:58 +08:00
step++;
}
break;
2014-04-05 23:09:44 +08:00
case 2: /* Wait for Both to have status ended */
2014-04-06 02:47:58 +08:00
if (status_control.Alice.status == Rejected && status_control.Bob.status == Ended) running = 0;
break;
}
c_sleep(20);
}
2014-04-05 23:09:44 +08:00
printf("\n");
}
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
/*
* Call and cancel
*/
2014-04-06 02:47:58 +08:00
{
2014-04-05 23:09:44 +08:00
int step = 0;
int running = 1;
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
while (running) {
2014-04-06 02:47:58 +08:00
tox_do(bootstrap_node);
tox_do(Alice);
2014-04-05 23:09:44 +08:00
tox_do(Bob);
2014-11-18 07:46:46 +08:00
toxav_do(status_control.Alice.av);
toxav_do(status_control.Bob.av);
2014-04-05 23:09:44 +08:00
switch ( step ) {
2014-04-06 02:47:58 +08:00
case 0: /* Alice */
2014-04-05 23:09:44 +08:00
printf("Alice is calling...\n");
2014-07-27 01:29:49 +08:00
toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
2014-04-06 02:47:58 +08:00
step++;
break;
2014-04-06 02:47:58 +08:00
case 1: /* Alice again */
if (status_control.Bob.status == Ringing) {
printf("Alice cancels...\n");
2014-04-28 01:21:26 +08:00
toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?");
2014-04-06 02:47:58 +08:00
step++;
}
break;
2014-04-05 23:09:44 +08:00
case 2: /* Wait for Both to have status ended */
2014-11-18 07:46:46 +08:00
if (status_control.Bob.status == Canceled) running = 0;
2014-04-06 02:47:58 +08:00
break;
}
c_sleep(20);
}
2014-04-05 23:09:44 +08:00
printf("\n");
}
2014-04-06 02:47:58 +08:00
/*
2014-07-27 01:29:49 +08:00
* Timeout
*/
{
int step = 0;
int running = 1;
while (running) {
tox_do(bootstrap_node);
tox_do(Alice);
tox_do(Bob);
2014-11-18 07:46:46 +08:00
toxav_do(status_control.Alice.av);
toxav_do(status_control.Bob.av);
switch ( step ) {
case 0:
printf("Alice is calling...\n");
2014-07-27 01:29:49 +08:00
toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
step++;
break;
case 1:
if (status_control.Alice.status == TimedOut) running = 0;
break;
}
c_sleep(20);
}
2014-04-05 23:09:44 +08:00
printf("\n");
}
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
printf("Calls ended!\n");
}
END_TEST
/*************************************************************************************************/
2014-04-28 01:21:26 +08:00
/*************************************************************************************************/
/*************************************************************************************************/
2014-04-05 23:09:44 +08:00
Suite *tox_suite(void)
{
2014-04-05 23:36:54 +08:00
Suite *s = suite_create("ToxAV");
2014-04-06 02:47:58 +08:00
DEFTESTCASE_SLOW(AV_flows, 200);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
return s;
}
int main(int argc, char *argv[])
{
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
setbuf(stdout, NULL);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
srunner_run_all(test_runner, CK_NORMAL);
int number_failed = srunner_ntests_failed(test_runner);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
srunner_free(test_runner);
2014-04-06 02:47:58 +08:00
2014-04-05 23:09:44 +08:00
return number_failed;
2014-05-24 22:02:01 +08:00
// return test_AV_flows();
2014-04-09 21:43:19 +08:00
}