Commit 3e09aff6 authored by Ghislain MARY's avatar Ghislain MARY

Add unit test for RFC3994: is-composing notification.

parent d124b030
......@@ -284,7 +284,7 @@ static void process_im_is_composing_notification(LinphoneChatRoom *cr, xmlparsin
xmlXPathObjectPtr iscomposing_object;
const char *state_str = NULL;
const char *refresh_str = NULL;
int refresh_duration = COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT;
int refresh_duration = lp_config_get_int(cr->lc->config, "sip", "composing_remote_refresh_timeout", COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT);
int i;
LinphoneIsComposingState state = LinphoneIsComposingIdle;
......@@ -475,7 +475,8 @@ static char * linphone_chat_room_create_is_composing_xml(LinphoneChatRoom *cr) {
}
if ((err >= 0) && (cr->is_composing == LinphoneIsComposingActive)) {
char refresh_str[4] = { 0 };
snprintf(refresh_str, sizeof(refresh_str), "%u", COMPOSING_DEFAULT_REFRESH_TIMEOUT);
int refresh_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT);
snprintf(refresh_str, sizeof(refresh_str), "%u", refresh_timeout);
err = xmlTextWriterWriteElement(writer, (const xmlChar *)"refresh", (const xmlChar *)refresh_str);
}
if (err >= 0) {
......@@ -547,19 +548,21 @@ static int linphone_chat_room_refresh_composing(void *data, unsigned int revents
}
void linphone_chat_room_compose(LinphoneChatRoom *cr) {
int idle_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_idle_timeout", COMPOSING_DEFAULT_IDLE_TIMEOUT);
int refresh_timeout = lp_config_get_int(cr->lc->config, "sip", "composing_refresh_timeout", COMPOSING_DEFAULT_REFRESH_TIMEOUT);
if (cr->is_composing == LinphoneIsComposingIdle) {
cr->is_composing = LinphoneIsComposingActive;
linphone_chat_room_send_is_composing_notification(cr);
if (!cr->composing_refresh_timer) {
cr->composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_refresh_composing, cr, COMPOSING_DEFAULT_REFRESH_TIMEOUT * 1000, "composing refresh timeout");
cr->composing_refresh_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_refresh_composing, cr, refresh_timeout * 1000, "composing refresh timeout");
} else {
belle_sip_source_set_timeout(cr->composing_refresh_timer, COMPOSING_DEFAULT_REFRESH_TIMEOUT * 1000);
belle_sip_source_set_timeout(cr->composing_refresh_timer, refresh_timeout * 1000);
}
if (!cr->composing_idle_timer) {
cr->composing_idle_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_stop_composing, cr, COMPOSING_DEFAULT_IDLE_TIMEOUT * 1000, "composing idle timeout");
cr->composing_idle_timer = sal_create_timer(cr->lc->sal, linphone_chat_room_stop_composing, cr, idle_timeout * 1000, "composing idle timeout");
}
}
belle_sip_source_set_timeout(cr->composing_idle_timer, COMPOSING_DEFAULT_IDLE_TIMEOUT * 1000);
belle_sip_source_set_timeout(cr->composing_idle_timer, idle_timeout * 1000);
}
/**
......
......@@ -191,6 +191,7 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f
mgr->v_table.call_state_changed=call_state_changed;
mgr->v_table.text_received=text_message_received;
mgr->v_table.message_received=message_received;
mgr->v_table.is_composing_received=is_composing_received;
mgr->v_table.new_subscription_requested=new_subscription_requested;
mgr->v_table.notify_presence_received=notify_presence_received;
mgr->v_table.transfer_state_changed=linphone_transfer_state_changed;
......
......@@ -117,7 +117,8 @@ typedef struct _stats {
int number_of_LinphoneMessageInProgress;
int number_of_LinphoneMessageDelivered;
int number_of_LinphoneMessageNotDelivered;
int number_of_LinphoneIsComposingActiveReceived;
int number_of_LinphoneIsComposingIdleReceived;
int number_of_IframeDecoded;
......@@ -194,6 +195,7 @@ void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered,
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf);
void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message);
void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message);
void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room);
void info_message_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain);
......
......@@ -5,6 +5,7 @@ sip_tls_port=5083
default_proxy=0
ping_with_options=0
register_only_when_network_is_up=0
composing_idle_timeout=1
[auth_info_0]
username=marie
......
......@@ -44,6 +44,15 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess
}
}
void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
stats *counters = get_stats(lc);
if (room->remote_is_composing == LinphoneIsComposingActive) {
counters->number_of_LinphoneIsComposingActiveReceived++;
} else {
counters->number_of_LinphoneIsComposingIdleReceived++;
}
}
void linphone_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud) {
LinphoneCore* lc=(LinphoneCore*)ud;
stats* counters = get_stats(lc);
......@@ -264,6 +273,24 @@ static void info_message_with_body(){
info_message_with_args(TRUE);
}
static void is_composing_notification(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
char* to = linphone_address_as_string(marie->identity);
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc, to);
int dummy = 0;
ms_free(to);
linphone_chat_room_compose(chat_room);
wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /*just to sleep while iterating*/
linphone_chat_room_send_message(chat_room, "Composing a message");
CU_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1));
CU_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 2));
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
test_t message_tests[] = {
{ "Text message", text_message },
{ "Text message with privacy", text_message_with_privacy },
......@@ -272,7 +299,8 @@ test_t message_tests[] = {
{ "Text message with send error", text_message_with_send_error },
{ "Text message with external body", text_message_with_external_body },
{ "Info message", info_message },
{ "Info message with body", info_message_with_body }
{ "Info message with body", info_message_with_body },
{ "IsComposing notification", is_composing_notification }
};
test_suite_t message_test_suite = {
......
......@@ -5,6 +5,7 @@ sip_tls_port=5073
default_proxy=0
ping_with_options=0
register_only_when_network_is_up=0
composing_idle_timeout=1
[auth_info_0]
username=pauline
......
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