Commit 9f1fbf40 authored by jehan's avatar jehan

add presence status tester

parent a5a49f8f
......@@ -48,6 +48,7 @@ void sal_op_release_impl(SalOp *op){
if(op->referred_by) belle_sip_object_unref(op->referred_by);
if (op->pending_client_trans) belle_sip_object_unref(op->pending_client_trans);
if (op->pending_server_trans) belle_sip_object_unref(op->pending_server_trans);
__sal_op_free(op);
return ;
}
......
......@@ -475,7 +475,7 @@ static void presence_process_timeout(void *user_ctx, const belle_sip_timeout_eve
ms_error("presence_process_timeout not implemented yet");
}
static void presence_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
ms_error("presence_process_timeout not implemented yet");
ms_message("presence_process_transaction_terminated not implemented yet");
}
static void presence_process_request_event(void *op_base, const belle_sip_request_event_t *event) {
SalOp* op = (SalOp*)op_base;
......@@ -537,7 +537,7 @@ static void presence_process_request_event(void *op_base, const belle_sip_reques
}else{
estatus=SalPresenceOffline;
}
ms_message("We are notified that [%s] has online status %i",sal_op_get_from(op),estatus);
ms_message("We are notified that [%s] has online status [%s]",sal_op_get_from(op),sal_presence_status_to_string(estatus));
if (!subscription_state_header || strcasecmp(BELLE_SIP_SUBSCRIPTION_STATE_TERMINATED,belle_sip_header_subscription_state_get_state(subscription_state_header)) ==0) {
sub_state=SalSubscribeTerminated;
ms_message("And outgoing subscription terminated by remote [%s]",sal_op_get_to(op));
......@@ -578,8 +578,16 @@ void sal_op_presence_fill_cbs(SalOp*op) {
/*presence publish */
int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus status){
ms_error("sal_publish not implemented yet");
return -1;
belle_sip_request_t *req=NULL;
if (from)
sal_op_set_from(op,from);
if (to)
sal_op_set_to(op,to);
sal_op_presence_fill_cbs(op);
req=sal_op_build_request(op,"PUBLISH");
add_presence_info(BELLE_SIP_MESSAGE(req),status);
return sal_op_send_request(op,req);
}
/*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
......
......@@ -595,3 +595,20 @@ void sal_op_set_service_route(SalOp *op,const SalAddress* service_route) {
((SalOpBase*)op)->service_route=service_route?sal_address_clone(service_route):NULL;
}
const char* sal_presence_status_to_string(const SalPresenceStatus status) {
switch (status) {
case SalPresenceOffline: return "SalPresenceOffline";
case SalPresenceOnline: return "SalPresenceOnline";
case SalPresenceBusy: return "SalPresenceBusy";
case SalPresenceBerightback: return "SalPresenceBerightback";
case SalPresenceAway: return "SalPresenceAway";
case SalPresenceOnthephone: return "SalPresenceOnthephone";
case SalPresenceOuttolunch: return "SalPresenceOuttolunch";
case SalPresenceDonotdisturb: return "SalPresenceDonotdisturb";
case SalPresenceMoved: return "SalPresenceMoved";
case SalPresenceAltService: return "SalPresenceAltService";
default : return "unknown";
}
}
......@@ -287,6 +287,8 @@ typedef enum SalPresenceStatus{
SalPresenceAltService,
}SalPresenceStatus;
const char* sal_presence_status_to_string(const SalPresenceStatus status);
typedef enum SalReferStatus{
SalReferTrying,
SalReferSuccess,
......
......@@ -92,7 +92,7 @@ static void linphone_call_cb(LinphoneCall *call,void * user_data) {
counters->number_of_IframeDecoded++;
}
static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) {
bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) {
LinphoneProxyConfig* proxy;
int retry=0;
stats initial_caller=caller_mgr->stat;
......
......@@ -117,11 +117,24 @@ typedef struct _stats {
int number_of_LinphoneMessageNotDelivered;
int number_of_IframeDecoded;
int number_of_NewSubscriptionRequest;
int number_of_NotifyReceived;
int number_of_LinphoneStatusOffline;
int number_of_LinphoneStatusOnline;
int number_of_LinphoneStatusBusy;
int number_of_LinphoneStatusBeRightBack;
int number_of_LinphoneStatusAway;
int number_of_LinphoneStatusOnThePhone;
int number_of_LinphoneStatusOutToLunch;
int number_of_LinphoneStatusDoNotDisturb;
int number_of_LinphoneStatusMoved;
int number_of_LinphoneStatusAltService;
int number_of_LinphoneStatusPending;
int number_of_LinphoneStatusEnd;
int number_of_IframeDecoded;
}stats;
typedef struct _LinphoneCoreManager {
......@@ -152,6 +165,6 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, c
bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value);
bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms);
bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr);
#endif /* LIBLINPHONE_TESTER_H_ */
......@@ -40,19 +40,66 @@ void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {
ms_free(from);
counters = (stats*)linphone_core_get_user_data(lc);
counters->number_of_NotifyReceived++;
switch(linphone_friend_get_status(lf)) {
case LinphoneStatusOffline: counters->number_of_LinphoneStatusOffline++; break;
case LinphoneStatusOnline: counters->number_of_LinphoneStatusOnline++; break;
case LinphoneStatusBusy: counters->number_of_LinphoneStatusBusy++; break;
case LinphoneStatusBeRightBack: counters->number_of_LinphoneStatusBeRightBack++; break;
case LinphoneStatusAway: counters->number_of_LinphoneStatusAway++; break;
case LinphoneStatusOnThePhone: counters->number_of_LinphoneStatusOnThePhone++; break;
case LinphoneStatusOutToLunch: counters->number_of_LinphoneStatusOutToLunch++; break;
case LinphoneStatusDoNotDisturb: counters->number_of_LinphoneStatusDoNotDisturb++; break;
case LinphoneStatusMoved: counters->number_of_LinphoneStatusMoved++; break;
case LinphoneStatusAltService: counters->number_of_LinphoneStatusMoved++; break;
case LinphoneStatusPending: counters->number_of_LinphoneStatusPending++; break;
case LinphoneStatusEnd: counters->number_of_LinphoneStatusEnd++; break;
}
}
static void simple_publish(void) {
LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
LinphoneProxyConfig* proxy;
int i=0;
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);
for (i=0;i<10;i++) {
linphone_core_iterate(marie->lc);
ms_usleep(100000);
}
linphone_core_manager_destroy(marie);
}
static bool_t subscribe_to_callee_presence(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) {
stats initial_caller=caller_mgr->stat;
stats initial_callee=callee_mgr->stat;
LinphoneProxyConfig* proxy;
bool_t result=FALSE;
LinphoneFriend * friend;
linphone_core_get_default_proxy(callee_mgr->lc,&proxy);
if (!proxy) return 0;
friend=linphone_friend_new_with_addr(linphone_proxy_config_get_identity(proxy));
linphone_friend_edit(friend);
linphone_friend_enable_subscribes(friend,TRUE);
linphone_friend_done(friend);
linphone_core_add_friend(caller_mgr->lc,friend);
result=wait_for(caller_mgr->lc,callee_mgr->lc,&callee_mgr->stat.number_of_LinphoneStatusOnline,initial_callee.number_of_LinphoneStatusOnline+1);
result&=wait_for(caller_mgr->lc,callee_mgr->lc,&caller_mgr->stat.number_of_LinphoneStatusOnline,initial_caller.number_of_LinphoneStatusOnline+1);
CU_ASSERT_EQUAL(callee_mgr->stat.number_of_NewSubscriptionRequest,initial_callee.number_of_NewSubscriptionRequest+1);
CU_ASSERT_EQUAL(callee_mgr->stat.number_of_NotifyReceived,initial_callee.number_of_NotifyReceived+1);
CU_ASSERT_EQUAL(caller_mgr->stat.number_of_NotifyReceived,initial_caller.number_of_NotifyReceived+1);
return result;
}
static void simple_subscribe(void) {
LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new(liblinphone_tester_file_prefix, "pauline_rc");
......@@ -84,10 +131,28 @@ static void unsubscribe_while_subscribing(void) {
linphone_core_manager_destroy(marie);
}
static void call_with_presence(void) {
LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new(liblinphone_tester_file_prefix, "pauline_rc");
CU_ASSERT_TRUE(subscribe_to_callee_presence(marie,pauline));
CU_ASSERT_TRUE(call(marie,pauline));
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneStatusOnThePhone,1);
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneStatusOnThePhone,1);
reset_counters(&marie->stat);
reset_counters(&pauline->stat);
linphone_core_terminate_all_calls(marie->lc);
CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_LinphoneStatusOnline,1));
CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneStatusOnline,1));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
test_t presence_tests[] = {
{ "Simple Subscribe", simple_subscribe },
{ "Simple Publish", simple_publish },
{ "Call with Presence", call_with_presence },
{ "Unsubscribe while subscribing", unsubscribe_while_subscribing },
};
......
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