Commit c15905c9 authored by Ghislain MARY's avatar Ghislain MARY

Add presence list test.

parent 1d93356d
......@@ -39,7 +39,9 @@ const char *liblinphone_tester_get_notify_content(void){
void linphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *eventname, const LinphoneContent *content){
LinphoneCoreManager *mgr;
BC_ASSERT_PTR_NOT_NULL_FATAL(content);
BC_ASSERT_STRING_EQUAL(notify_content,(const char*)linphone_content_get_buffer(content));
if (!linphone_content_is_multipart(content)) {
BC_ASSERT_STRING_EQUAL(notify_content,(const char*)linphone_content_get_buffer(content));
}
mgr=get_manager(lc);
mgr->stat.number_of_NotifyReceived++;
}
......
......@@ -153,6 +153,7 @@ typedef struct _stats {
int number_of_NewSubscriptionRequest;
int number_of_NotifyReceived;
int number_of_NotifyPresenceReceived;
int number_of_LinphonePresenceActivityOffline;
int number_of_LinphonePresenceActivityOnline;
int number_of_LinphonePresenceActivityAppointment;
......
......@@ -46,10 +46,10 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {
stats* counters;
LinphonePresenceActivity *activity = NULL;
char* from=linphone_address_as_string(linphone_friend_get_address(lf));
ms_message("New Notify request from [%s] ",from);
ms_message("New Notify request from [%s] ",from);
ms_free(from);
counters = get_stats(lc);
counters->number_of_NotifyReceived++;
counters->number_of_NotifyPresenceReceived++;
counters->last_received_presence = linphone_friend_get_presence_model(lf);
activity = linphone_presence_model_get_activity(counters->last_received_presence);
......@@ -173,9 +173,9 @@ static bool_t subscribe_to_callee_presence(LinphoneCoreManager* caller_mgr,Linph
BC_ASSERT_EQUAL(callee_mgr->stat.number_of_NewSubscriptionRequest,initial_callee.number_of_NewSubscriptionRequest+1, int, "%d");
/*without proxy, callee cannot subscribe to caller
BC_ASSERT_EQUAL(callee_mgr->stat.number_of_NotifyReceived,initial_callee.number_of_NotifyReceived+1, int, "%d");
BC_ASSERT_EQUAL(callee_mgr->stat.number_of_NotifyPresenceReceived,initial_callee.number_of_NotifyPresenceReceived+1, int, "%d");
*/
BC_ASSERT_EQUAL(caller_mgr->stat.number_of_NotifyReceived,initial_caller.number_of_NotifyReceived+1, int, "%d");
BC_ASSERT_EQUAL(caller_mgr->stat.number_of_NotifyPresenceReceived,initial_caller.number_of_NotifyPresenceReceived+1, int, "%d");
ms_free(identity);
return result;
......@@ -448,7 +448,7 @@ static void test_subscribe_notify_publish(void) {
linphone_core_add_friend(pauline->lc,lf);
/*wait for subscribe acknowledgment*/
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,1,2000);
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyPresenceReceived,1,2000);
BC_ASSERT_EQUAL(LinphoneStatusOffline,linphone_friend_get_status(lf), int, "%d");
/*enable publish*/
......@@ -461,23 +461,23 @@ static void test_subscribe_notify_publish(void) {
linphone_proxy_config_done(proxy);
/*wait for marie status*/
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,2,2000);
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyPresenceReceived,2,2000);
BC_ASSERT_EQUAL(LinphoneStatusOnline,linphone_friend_get_status(lf), int, "%d");
presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityBusy,NULL);
linphone_core_set_presence_model(marie->lc,presence);
/*wait for new status*/
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,3,2000);
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyPresenceReceived,3,2000);
BC_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf), int, "%d");
/*wait for refresh*/
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,4,5000);
wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyPresenceReceived,4,5000);
BC_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf), int, "%d");
/*linphone_core_remove_friend(pauline->lc,lf);*/
/*wait for final notify*/
/*wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyReceived,4,5000);
/*wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_NotifyPresenceReceived,4,5000);
BC_ASSERT_EQUAL(LinphonePresenceActivityOffline,linphone_friend_get_status(lf), int, "%d");
*/
linphone_core_manager_destroy(marie);
......@@ -507,7 +507,7 @@ static void test_forked_subscribe_notify_publish(void) {
linphone_core_add_friend(pauline->lc,lf);
/*wait for subscribe acknowledgment*/
wait_for_list(lcs,&pauline->stat.number_of_NotifyReceived,1,2000);
wait_for_list(lcs,&pauline->stat.number_of_NotifyPresenceReceived,1,2000);
BC_ASSERT_EQUAL(LinphoneStatusOffline,linphone_friend_get_status(lf), int, "%d");
/*enable publish*/
......@@ -526,21 +526,21 @@ static void test_forked_subscribe_notify_publish(void) {
/*wait for marie status*/
wait_for_list(lcs,&pauline->stat.number_of_NotifyReceived,3,2000);
wait_for_list(lcs,&pauline->stat.number_of_NotifyPresenceReceived,3,2000);
BC_ASSERT_EQUAL(LinphoneStatusOnline,linphone_friend_get_status(lf), int, "%d");
presence =linphone_presence_model_new_with_activity(LinphonePresenceActivityBusy,NULL);
linphone_core_set_presence_model(marie->lc,presence);
/*wait for new status*/
wait_for_list(lcs,&pauline->stat.number_of_NotifyReceived,4,2000);
wait_for_list(lcs,&pauline->stat.number_of_NotifyPresenceReceived,4,2000);
BC_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf), int, "%d");
presence =linphone_presence_model_new_with_activity( LinphonePresenceActivityMeeting,NULL);
linphone_core_set_presence_model(marie2->lc,presence);
/*wait for new status*/
wait_for_list(lcs,&pauline->stat.number_of_NotifyReceived,5,2000);
wait_for_list(lcs,&pauline->stat.number_of_NotifyPresenceReceived,5,2000);
BC_ASSERT_EQUAL(LinphoneStatusBusy,linphone_friend_get_status(lf), int, "%d"); /*because liblinphone compositor is very simple for now (I.E only take first occurence)*/
linphone_core_manager_destroy(marie);
......@@ -551,6 +551,117 @@ static void test_forked_subscribe_notify_publish(void) {
#endif
const char * get_identity(LinphoneCoreManager *mgr) {
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(mgr->lc);
return linphone_proxy_config_get_identity(cfg);
}
static void enable_publish(LinphoneCoreManager *mgr, bool_t enable) {
LinphoneProxyConfig *cfg = linphone_core_get_default_proxy_config(mgr->lc);
linphone_proxy_config_edit(cfg);
linphone_proxy_config_enable_publish(cfg, enable);
linphone_proxy_config_set_publish_expires(cfg, 3);
linphone_proxy_config_done(cfg);
}
static void test_presence_list(void) {
LinphoneCoreManager *laure = linphone_core_manager_new("laure_tcp_rc");
LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc");
const char *rls_uri = "sip:rls@sip.example.org";
LinphoneFriendList *lfl;
LinphoneFriend *lf;
const char *laure_identity;
const char *marie_identity;
const char *pauline_identity;
MSList* lcs = NULL;
laure_identity = get_identity(laure);
marie_identity = get_identity(marie);
pauline_identity = get_identity(pauline);
enable_publish(marie, TRUE);
enable_publish(pauline, TRUE);
linphone_core_set_presence_model(marie->lc, linphone_core_create_presence_model_with_activity(marie->lc, LinphonePresenceActivityBusy, NULL));
linphone_core_set_presence_model(pauline->lc, linphone_core_create_presence_model_with_activity(pauline->lc, LinphonePresenceActivityVacation, NULL));
lfl = linphone_core_create_friend_list(laure->lc);
linphone_friend_list_set_rls_uri(lfl, rls_uri);
lf = linphone_core_create_friend_with_address(laure->lc, marie_identity);
linphone_friend_list_add_friend(lfl, lf);
lf = linphone_core_create_friend_with_address(laure->lc, pauline_identity);
linphone_friend_list_add_friend(lfl, lf);
lf = linphone_core_create_friend_with_address(laure->lc, "sip:michelle@sip.inexistentdomain.com");
linphone_friend_list_add_friend(lfl, lf);
linphone_core_set_friend_list(laure->lc, lfl);
linphone_core_set_presence_model(laure->lc, linphone_core_create_presence_model_with_activity(laure->lc, LinphonePresenceActivityOnline, NULL));
lcs = ms_list_append(lcs, laure->lc);
lcs = ms_list_append(lcs, marie->lc);
lcs = ms_list_append(lcs, pauline->lc);
wait_for_list(lcs, &laure->stat.number_of_NotifyReceived, 1, 2000);
wait_for_list(lcs, &laure->stat.number_of_NotifyPresenceReceived, 2, 2000);
BC_ASSERT_EQUAL(laure->stat.number_of_NotifyReceived, 1, int, "%d");
BC_ASSERT_EQUAL(laure->stat.number_of_NotifyPresenceReceived, 2, int, "%d");
BC_ASSERT_EQUAL(laure->lc->friendlist->expected_notification_version, 1, int, "%d");
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, marie_identity);
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusBusy, int, "%d");
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, pauline_identity);
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusVacation, int, "%d");
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
lf = linphone_friend_list_find_friend_by_uri(laure->lc->friendlist, "sip:michelle@sip.inexistentdomain.com");
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOffline, int, "%d");
BC_ASSERT_EQUAL(lf->presence_received, FALSE, int, "%d");
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
enable_publish(laure, TRUE);
lfl = linphone_core_create_friend_list(marie->lc);
linphone_friend_list_set_rls_uri(lfl, rls_uri);
lf = linphone_core_create_friend_with_address(marie->lc, laure_identity);
linphone_friend_list_add_friend(lfl, lf);
linphone_core_set_friend_list(marie->lc, lfl);
linphone_friend_list_update_subscriptions(pauline->lc->friendlist, NULL, FALSE);
wait_for_list(lcs, &marie->stat.number_of_NotifyReceived, 1, 2000);
wait_for_list(lcs, &marie->stat.number_of_NotifyPresenceReceived, 1, 2000);
BC_ASSERT_EQUAL(marie->stat.number_of_NotifyReceived, 1, int, "%d");
BC_ASSERT_EQUAL(marie->stat.number_of_NotifyPresenceReceived, 1, int, "%d");
BC_ASSERT_EQUAL(marie->lc->friendlist->expected_notification_version, 1, int, "%d");
lf = linphone_friend_list_find_friend_by_uri(marie->lc->friendlist, laure_identity);
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusOnline, int, "%d");
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
lfl = linphone_core_create_friend_list(pauline->lc);
linphone_friend_list_set_rls_uri(lfl, rls_uri);
lf = linphone_core_create_friend_with_address(pauline->lc, marie_identity);
linphone_friend_list_add_friend(lfl, lf);
linphone_core_set_friend_list(pauline->lc, lfl);
linphone_friend_list_update_subscriptions(pauline->lc->friendlist, NULL, FALSE);
wait_for_list(lcs, &pauline->stat.number_of_NotifyReceived, 1, 2000);
wait_for_list(lcs, &pauline->stat.number_of_NotifyPresenceReceived, 1, 2000);
BC_ASSERT_EQUAL(pauline->stat.number_of_NotifyReceived, 1, int, "%d");
BC_ASSERT_EQUAL(pauline->stat.number_of_NotifyPresenceReceived, 1, int, "%d");
BC_ASSERT_EQUAL(pauline->lc->friendlist->expected_notification_version, 1, int, "%d");
lf = linphone_friend_list_find_friend_by_uri(pauline->lc->friendlist, marie_identity);
BC_ASSERT_EQUAL(linphone_friend_get_status(lf), LinphoneStatusBusy, int, "%d");
BC_ASSERT_EQUAL(lf->presence_received, TRUE, int, "%d");
BC_ASSERT_EQUAL(lf->subscribe_active, TRUE, int, "%d");
enable_publish(laure, FALSE);
enable_publish(marie, FALSE);
enable_publish(pauline, FALSE);
linphone_core_manager_destroy(laure);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
test_t presence_tests[] = {
{ "Simple Subscribe", simple_subscribe },
{ "Simple Publish", simple_publish },
......@@ -565,6 +676,7 @@ test_t presence_tests[] = {
{ "Subscribe with late publish", test_subscribe_notify_publish },
{ "Forked subscribe with late publish", test_forked_subscribe_notify_publish },
#endif
{ "Presence list", test_presence_list }
};
test_suite_t presence_test_suite = {"Presence", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
......
[sip]
sip_port=5092
sip_tcp_port=5092
sip_tls_port=5093
default_proxy=0
ping_with_options=0
register_only_when_network_is_up=0
[auth_info_0]
username=laure
userid=laure
passwd=secret
realm="sip.example.org"
[proxy_0]
reg_proxy=sip.example.org;transport=tcp
reg_identity=sip:laure@sip.example.org
reg_expires=3600
reg_sendregister=1
publish=0
dial_escape_plus=0
[rtp]
audio_rtp_port=9010-9390
video_rtp_port=9410-9910
[video]
display=0
capture=0
show_local=0
size=qcif
enabled=0
self_view=0
automatically_initiate=0
automatically_accept=0
device=StaticImage: Static picture
[sound]
echocancellation=0 #to not overload cpu in case of VG
[net]
dns_srv_enabled=0 #no srv needed in general
stun_server=stun.linphone.org
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment