Commit fce34adb authored by jehan's avatar jehan

split liblinphone_tester

parent 54c81a8c
......@@ -473,6 +473,12 @@ int sal_call_accept(SalOp*h){
belle_sip_response_t *response;
belle_sip_header_address_t* contact= (belle_sip_header_address_t*)sal_op_get_contact_address(h);
belle_sip_header_contact_t* contact_header;
if (!h->pending_server_trans) {
ms_error("No transaction to accept for op [%p]",h);
return -1;
}
/* sends a 200 OK */
response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(h->pending_server_trans)),200);
......
......@@ -4,7 +4,7 @@ if BUILD_CUNIT_TESTS
noinst_PROGRAMS=liblinphone_tester
TESTS=$(noinst_PROGRAMS)
liblinphone_tester_SOURCES= liblinphone_tester.c
liblinphone_tester_SOURCES= liblinphone_tester.c register_tester.c message_tester.c call_tester.c presence_tester.c
#liblinphone_tester_CFLAGS=$(CUNIT_CFLAGS)
......@@ -12,7 +12,7 @@ liblinphone_tester_SOURCES= liblinphone_tester.c
#liblinphone_tester_LDFLAGS=$(CUNIT_LIBS)
INCLUDES=-I$(top_srcdir)/include -I$(top_srcdir)/coreapi
AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/coreapi
LDADD=$(top_builddir)/coreapi/liblinphone.la
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"
static int init(void) {
return 0;
}
static int uninit(void) {
return 0;
}
static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) {
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy(callee_mgr->lc,&proxy);
int retry=0;
CU_ASSERT_PTR_NOT_NULL_FATAL(proxy);
CU_ASSERT_PTR_NOT_NULL_FATAL(linphone_core_invite_address(caller_mgr->lc,callee_mgr->identity));
/*linphone_core_invite(caller_mgr->lc,"pauline");*/
CU_ASSERT_TRUE_FATAL(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived,1));
CU_ASSERT_TRUE(linphone_core_inc_invite_pending(callee_mgr->lc));
CU_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,1);
while ((caller_mgr->stat.number_of_LinphoneCallOutgoingRinging<1
|| caller_mgr->stat.number_of_LinphoneCallOutgoingEarlyMedia<1) && retry++ <20) {
linphone_core_iterate(caller_mgr->lc);
linphone_core_iterate(callee_mgr->lc);
ms_usleep(100000);
}
CU_ASSERT_TRUE_FATAL(caller_mgr->stat.number_of_LinphoneCallOutgoingRinging|caller_mgr->stat.number_of_LinphoneCallOutgoingEarlyMedia);
linphone_core_get_default_proxy(caller_mgr->lc,&proxy);
CU_ASSERT_PTR_NOT_NULL_FATAL(proxy);
LinphoneAddress* identity = linphone_address_new(linphone_proxy_config_get_identity(proxy));
CU_ASSERT_TRUE(linphone_address_weak_equal(identity,linphone_core_get_current_call_remote_address(callee_mgr->lc)));
linphone_address_destroy(identity);
linphone_core_accept_call(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc));
CU_ASSERT_TRUE_FATAL(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallConnected,1));
CU_ASSERT_TRUE_FATAL(wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallConnected,1));
/*just to sleep*/
return wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallStreamsRunning,1)
&&
wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallStreamsRunning,1);
}
static void simple_call() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCore* lc_marie=marie->lc;
LinphoneCore* lc_pauline=pauline->lc;
stats* stat_marie=&marie->stat;
stats* stat_pauline=&pauline->stat;
linphone_core_invite(lc_marie,"pauline");
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallIncomingReceived,1));
CU_ASSERT_TRUE(linphone_core_inc_invite_pending(lc_pauline));
CU_ASSERT_EQUAL(stat_marie->number_of_LinphoneCallOutgoingProgress,1);
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallOutgoingRinging,1));
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy(lc_marie,&proxy);
CU_ASSERT_PTR_NOT_NULL_FATAL(proxy);
LinphoneAddress* identity = linphone_address_new(linphone_proxy_config_get_identity(proxy));
CU_ASSERT_TRUE(linphone_address_weak_equal(identity,linphone_core_get_current_call_remote_address(lc_pauline)));
linphone_address_destroy(identity);
linphone_core_accept_call(lc_pauline,linphone_core_get_current_call(lc_pauline));
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallConnected,1));
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallConnected,1));
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallStreamsRunning,1));
CU_ASSERT_TRUE_FATAL(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallStreamsRunning,1));
/*just to sleep*/
wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallStreamsRunning,3);
linphone_core_terminate_all_calls(lc_pauline);
CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallEnd,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_canceled() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* out_call = linphone_core_invite(pauline->lc,"marie");
linphone_call_ref(out_call);
CU_ASSERT_TRUE_FATAL(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));
linphone_core_terminate_call(pauline->lc,out_call);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
//CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonCanceled);
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingReceived,0);
linphone_call_unref(out_call);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_ringing_canceled() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* out_call = linphone_core_invite(pauline->lc,"marie");
linphone_call_ref(out_call);
CU_ASSERT_TRUE_FATAL(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
linphone_core_terminate_call(pauline->lc,out_call);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
//CU_ASSERT_EQUAL(linphone_call_get_reason(in_call),LinphoneReasonDeclined);
//CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonDeclined);
linphone_call_unref(out_call);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_early_declined() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* out_call = linphone_core_invite(pauline->lc,"marie");
linphone_call_ref(out_call);
CU_ASSERT_TRUE_FATAL(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
LinphoneCall* in_call=linphone_core_get_current_call(marie->lc);
linphone_call_ref(in_call);
linphone_core_terminate_call(marie->lc,in_call);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_EQUAL(linphone_call_get_reason(in_call),LinphoneReasonDeclined);
CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonDeclined);
linphone_call_unref(in_call);
linphone_call_unref(out_call);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_terminated_by_caller() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
CU_ASSERT_TRUE(call(pauline,marie));
/*just to sleep*/
linphone_core_terminate_all_calls(pauline->lc);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_paused_resumed() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* call_obj;
CU_ASSERT_TRUE(call(pauline,marie));
call_obj = linphone_core_get_current_call(pauline->lc);
linphone_core_pause_call(pauline->lc,call_obj);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallPaused,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallPausedByRemote,1));
linphone_core_resume_call(pauline->lc,call_obj);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2));
/*just to sleep*/
linphone_core_terminate_all_calls(pauline->lc);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_srtp() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
linphone_core_set_media_encryption(marie->lc,LinphoneMediaEncryptionSRTP);
linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP);
CU_ASSERT_TRUE(call(pauline,marie));
CU_ASSERT_EQUAL(linphone_core_get_media_encryption(marie->lc),LinphoneMediaEncryptionSRTP);
CU_ASSERT_EQUAL(linphone_core_get_media_encryption(pauline->lc),LinphoneMediaEncryptionSRTP);
/*just to sleep*/
linphone_core_terminate_all_calls(marie->lc);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_early_media() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_early_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
CU_ASSERT_TRUE(call(pauline,marie));
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1);
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1);
/*just to sleep*/
linphone_core_terminate_all_calls(marie->lc);
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
int call_test_suite () {
CU_pSuite pSuite = CU_add_suite("Call", init, uninit);
if (NULL == CU_add_test(pSuite, "call_early_declined", call_early_declined)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_canceled", call_canceled)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_ringing_canceled", call_ringing_canceled)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_call", simple_call)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_early_media", call_early_media)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_terminated_by_caller", call_terminated_by_caller)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_paused_resumed", call_paused_resumed)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_srtp", call_srtp)) {
return CU_get_error();
}
return 0;
}
This diff is collapsed.
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBLINPHONE_TESTER_H_
#define LIBLINPHONE_TESTER_H_
const char* test_domain;
const char* auth_domain;
const char* test_username;
const char* test_password;
typedef struct _stats {
int number_of_LinphoneRegistrationNone;
int number_of_LinphoneRegistrationProgress ;
int number_of_LinphoneRegistrationOk ;
int number_of_LinphoneRegistrationCleared ;
int number_of_LinphoneRegistrationFailed ;
int number_of_auth_info_requested ;
int number_of_LinphoneCallIncomingReceived;
int number_of_LinphoneCallOutgoingInit;
int number_of_LinphoneCallOutgoingProgress;
int number_of_LinphoneCallOutgoingRinging;
int number_of_LinphoneCallOutgoingEarlyMedia;
int number_of_LinphoneCallConnected;
int number_of_LinphoneCallStreamsRunning;
int number_of_LinphoneCallPausing;
int number_of_LinphoneCallPaused;
int number_of_LinphoneCallResuming;
int number_of_LinphoneCallRefered;
int number_of_LinphoneCallError;
int number_of_LinphoneCallEnd;
int number_of_LinphoneCallPausedByRemote;
int number_of_LinphoneCallUpdatedByRemote;
int number_of_LinphoneCallIncomingEarlyMedia;
int number_of_LinphoneCallUpdating;
int number_of_LinphoneCallReleased;
int number_of_LinphoneMessageReceived;
int number_of_NewSubscriptionRequest;
int number_of_NotifyReceived;
}stats;
typedef struct _LinphoneCoreManager {
LinphoneCoreVTable v_table;
LinphoneCore* lc;
stats stat;
LinphoneAddress* identity;
} LinphoneCoreManager;
LinphoneCoreManager* linphone_core_manager_new(const char* rc_file);
void linphone_core_manager_destroy(LinphoneCoreManager* mgr);
void reset_counters( stats* counters);
void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message);
void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username);
LinphoneCore* create_lc_with_auth(unsigned int with_auth) ;
LinphoneAddress * create_linphone_address(const char * domain);
LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* file,int proxy_count);
bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value);
int call_test_suite ();
int register_test_suite ();
int message_test_suite ();
int presence_test_suite ();
#endif /* LIBLINPHONE_TESTER_H_ */
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"
static void text_message() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
char* to = linphone_address_as_string(marie->identity);
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to);
linphone_chat_room_send_message(chat_room,"Bla bla bla bla");
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
int message_test_suite () {
CU_pSuite pSuite = CU_add_suite("Message", NULL, NULL);
if (NULL == CU_add_test(pSuite, "text_message", text_message)) {
return CU_get_error();
}
return 0;
}
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"
static void simple_publish() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy(marie->lc,&proxy);
linphone_proxy_config_edit(proxy);
linphone_proxy_config_enable_publish(proxy,TRUE);
linphone_proxy_config_done(proxy);
linphone_core_iterate(marie->lc);
linphone_core_manager_destroy(marie);
}
static void simple_subscribe() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
const MSList* marie_friends = linphone_core_get_friend_list(marie->lc);
CU_ASSERT_PTR_NOT_NULL_FATAL(marie_friends);
LinphoneFriend* friend = (LinphoneFriend*) marie_friends->data;
linphone_friend_edit(friend);
linphone_friend_enable_subscribes(friend,TRUE);
linphone_friend_done(friend);
CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,1));
CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_NotifyReceived,1));
linphone_core_manager_destroy(marie);
CU_ASSERT_FALSE(wait_for(NULL,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,2)); /*just to wait for unsubscription even if not notified*/
linphone_core_manager_destroy(pauline);
}
static void unsubscribe_while_subscribing() {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneFriend* friend = linphone_friend_new_with_addr("sip:toto@git.linphone.org"); /*any unexisting address*/
linphone_friend_edit(friend);
linphone_friend_enable_subscribes(friend,TRUE);
linphone_friend_done(friend);
linphone_core_add_friend(marie->lc,friend);
linphone_core_iterate(marie->lc);
linphone_core_manager_destroy(marie);
}
int presence_test_suite () {
CU_pSuite pSuite = CU_add_suite("Presence", NULL, NULL);
if (NULL == CU_add_test(pSuite, "simple_subscribe", simple_subscribe)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_publish", simple_publish)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "unsubscribe_while_subscribing", unsubscribe_while_subscribing)) {
return CU_get_error();
}
return 0;
}
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"
static LinphoneCore* create_lc() {
return create_lc_with_auth(0);
}
void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){
ms_message("New registration state %s for user id [%s] at proxy [%s]\n"
,linphone_registration_state_to_string(cstate)
,linphone_proxy_config_get_identity(cfg)
,linphone_proxy_config_get_addr(cfg));
stats* counters = (stats*)linphone_core_get_user_data(lc);
switch (cstate) {
case LinphoneRegistrationNone:counters->number_of_LinphoneRegistrationNone++;break;
case LinphoneRegistrationProgress:counters->number_of_LinphoneRegistrationProgress++;break;
case LinphoneRegistrationOk:counters->number_of_LinphoneRegistrationOk++;break;
case LinphoneRegistrationCleared:counters->number_of_LinphoneRegistrationCleared++;break;
case LinphoneRegistrationFailed:counters->number_of_LinphoneRegistrationFailed++;break;
default:
CU_FAIL("unexpected event");break;
}
}
static void register_with_refresh_base(LinphoneCore* lc, bool_t refresh,const char* domain,const char* route) {
int retry=0;
LCSipTransports transport = {5070,5070,0,5071};
CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
stats* counters = (stats*)linphone_core_get_user_data(lc);
reset_counters(counters);
linphone_core_set_sip_transports(lc,&transport);
LinphoneProxyConfig* proxy_cfg;
proxy_cfg = linphone_proxy_config_new();
LinphoneAddress *from = create_linphone_address(domain);
linphone_proxy_config_set_identity(proxy_cfg,linphone_address_as_string(from));
const char* server_addr = linphone_address_get_domain(from);
linphone_proxy_config_enable_register(proxy_cfg,TRUE);
linphone_proxy_config_expires(proxy_cfg,1);
if (route) {
linphone_proxy_config_set_route(proxy_cfg,route);
linphone_proxy_config_set_server_addr(proxy_cfg,route);
} else {
linphone_proxy_config_set_server_addr(proxy_cfg,server_addr);
}
linphone_address_destroy(from);
linphone_core_add_proxy_config(lc,proxy_cfg);
linphone_core_set_default_proxy(lc,proxy_cfg);
while (counters->number_of_LinphoneRegistrationOk<1+(refresh!=0) && retry++ <310) {
linphone_core_iterate(lc);
ms_usleep(100000);
}
CU_ASSERT_TRUE_FATAL(linphone_proxy_config_is_registered(proxy_cfg));
CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationNone,0);
CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationProgress,1+(refresh!=0));