forked from mirrors/linphone-iphone
313 lines
13 KiB
C
313 lines
13 KiB
C
/*
|
|
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 char* message_external_body_url;
|
|
|
|
void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message) {
|
|
stats* counters = get_stats(lc);
|
|
counters->number_of_LinphoneMessageReceivedLegacy++;
|
|
}
|
|
|
|
void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message) {
|
|
char* from=linphone_address_as_string(linphone_chat_message_get_from(message));
|
|
stats* counters;
|
|
ms_message("Message from [%s] is [%s] , external URL [%s]",from
|
|
,linphone_chat_message_get_text(message)
|
|
,linphone_chat_message_get_external_body_url(message));
|
|
ms_free(from);
|
|
counters = get_stats(lc);
|
|
counters->number_of_LinphoneMessageReceived++;
|
|
if (linphone_chat_message_get_external_body_url(message)) {
|
|
counters->number_of_LinphoneMessageExtBodyReceived++;
|
|
CU_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(message),message_external_body_url);
|
|
}
|
|
}
|
|
|
|
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);
|
|
ms_message("Message [%s] [%s]",linphone_chat_message_get_text(msg),linphone_chat_message_state_to_string(state));
|
|
switch (state) {
|
|
case LinphoneChatMessageStateDelivered:
|
|
counters->number_of_LinphoneMessageDelivered++;
|
|
break;
|
|
case LinphoneChatMessageStateNotDelivered:
|
|
counters->number_of_LinphoneMessageNotDelivered++;
|
|
break;
|
|
case LinphoneChatMessageStateInProgress:
|
|
counters->number_of_LinphoneMessageInProgress++;
|
|
break;
|
|
default:
|
|
ms_error("Unexpected state [%s] for message [%p]",linphone_chat_message_state_to_string(state),msg);
|
|
}
|
|
|
|
}
|
|
|
|
static void text_message(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);
|
|
ms_free(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));
|
|
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedLegacy,1);
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity));
|
|
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void text_message_with_privacy(void) {
|
|
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
|
|
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
|
|
LinphoneProxyConfig* pauline_proxy;
|
|
char* to = linphone_address_as_string(marie->identity);
|
|
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to);
|
|
ms_free(to);
|
|
|
|
/*test proxy config privacy*/
|
|
linphone_core_get_default_proxy(pauline->lc,&pauline_proxy);
|
|
linphone_proxy_config_set_privacy(pauline_proxy,LinphonePrivacyId);
|
|
|
|
CU_ASSERT_PTR_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity));
|
|
|
|
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));
|
|
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedLegacy,1);
|
|
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void text_message_compatibility_mode(void) {
|
|
char route[256];
|
|
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
|
|
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
|
|
LinphoneProxyConfig* proxy;
|
|
LinphoneAddress* proxy_address;
|
|
char*tmp;
|
|
LCSipTransports transport;
|
|
char* to = linphone_address_as_string(pauline->identity);
|
|
LinphoneChatRoom* chat_room;
|
|
|
|
linphone_core_get_default_proxy(marie->lc,&proxy);
|
|
CU_ASSERT_PTR_NOT_NULL (proxy);
|
|
proxy_address=linphone_address_new(linphone_proxy_config_get_addr(proxy));
|
|
linphone_address_clean(proxy_address);
|
|
tmp=linphone_address_as_string_uri_only(proxy_address);
|
|
linphone_proxy_config_set_server_addr(proxy,tmp);
|
|
sprintf(route,"sip:%s",test_route);
|
|
linphone_proxy_config_set_route(proxy,route);
|
|
ms_free(tmp);
|
|
linphone_address_destroy(proxy_address);
|
|
linphone_core_get_sip_transports(marie->lc,&transport);
|
|
transport.udp_port=0;
|
|
transport.tls_port=0;
|
|
transport.dtls_port=0;
|
|
/*only keep tcp*/
|
|
linphone_core_set_sip_transports(marie->lc,&transport);
|
|
marie->stat.number_of_LinphoneRegistrationOk=0;
|
|
|
|
CU_ASSERT_TRUE (wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationOk,1));
|
|
|
|
chat_room = linphone_core_create_chat_room(marie->lc,to);
|
|
linphone_chat_room_send_message(chat_room,"Bla bla bla bla");
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1));
|
|
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceivedLegacy,1);
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void text_message_with_ack(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);
|
|
LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
|
|
linphone_chat_room_send_message2(chat_room,message,linphone_chat_message_state_change,pauline->lc);
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1));
|
|
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1);
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void text_message_with_external_body(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);
|
|
LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
|
|
linphone_chat_message_set_external_body_url(message,message_external_body_url="http://www.linphone.org");
|
|
linphone_chat_room_send_message2(chat_room,message,linphone_chat_message_state_change,pauline->lc);
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1));
|
|
|
|
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1);
|
|
CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1);
|
|
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void text_message_with_send_error(void) {
|
|
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
|
|
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
|
|
char* to = linphone_address_as_string(pauline->identity);
|
|
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(marie->lc,to);
|
|
LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
|
|
/*simultate a network error*/
|
|
sal_set_send_error(marie->lc->sal, -1);
|
|
linphone_chat_room_send_message2(chat_room,message,linphone_chat_message_state_change,marie->lc);
|
|
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1));
|
|
/*CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageInProgress,1);*/
|
|
CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0);
|
|
|
|
sal_set_send_error(marie->lc->sal, 0);
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static const char *info_content="<somexml>blabla</somexml>";
|
|
|
|
void info_message_received(LinphoneCore *lc, LinphoneCall* call, const LinphoneInfoMessage *msg){
|
|
stats* counters = get_stats(lc);
|
|
|
|
if (counters->last_received_info_message) {
|
|
linphone_info_message_destroy(counters->last_received_info_message);
|
|
}
|
|
counters->last_received_info_message=linphone_info_message_copy(msg);
|
|
counters->number_of_inforeceived++;
|
|
}
|
|
|
|
|
|
|
|
static void info_message_with_args(bool_t with_content) {
|
|
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
|
|
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
|
|
LinphoneInfoMessage *info;
|
|
const LinphoneContent *content;
|
|
const char *hvalue;
|
|
|
|
CU_ASSERT_TRUE(call(pauline,marie));
|
|
|
|
info=linphone_core_create_info_message(marie->lc);
|
|
linphone_info_message_add_header(info,"Weather","still bad");
|
|
if (with_content) {
|
|
LinphoneContent ct={0};
|
|
ct.type="application";
|
|
ct.subtype="somexml";
|
|
ct.data=(void*)info_content;
|
|
ct.size=strlen(info_content);
|
|
linphone_info_message_set_content(info,&ct);
|
|
}
|
|
linphone_call_send_info_message(linphone_core_get_current_call(marie->lc),info);
|
|
linphone_info_message_destroy(info);
|
|
|
|
CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_inforeceived,1));
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_info_message);
|
|
hvalue=linphone_info_message_get_header(pauline->stat.last_received_info_message, "Weather");
|
|
content=linphone_info_message_get_content(pauline->stat.last_received_info_message);
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(hvalue);
|
|
if (hvalue)
|
|
CU_ASSERT_TRUE(strcmp(hvalue,"still bad")==0);
|
|
|
|
if (with_content){
|
|
CU_ASSERT_PTR_NOT_NULL(content);
|
|
if (content) {
|
|
CU_ASSERT_PTR_NOT_NULL(content->data);
|
|
CU_ASSERT_PTR_NOT_NULL(content->type);
|
|
CU_ASSERT_PTR_NOT_NULL(content->subtype);
|
|
if (content->type) CU_ASSERT_TRUE(strcmp(content->type,"application")==0);
|
|
if (content->subtype) CU_ASSERT_TRUE(strcmp(content->subtype,"somexml")==0);
|
|
if (content->data)CU_ASSERT_TRUE(strcmp((const char*)content->data,info_content)==0);
|
|
CU_ASSERT_EQUAL(content->size,strlen(info_content));
|
|
}
|
|
}
|
|
linphone_core_manager_destroy(marie);
|
|
linphone_core_manager_destroy(pauline);
|
|
}
|
|
|
|
static void info_message(){
|
|
info_message_with_args(FALSE);
|
|
}
|
|
|
|
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 },
|
|
{ "Text message compatibility mode", text_message_compatibility_mode },
|
|
{ "Text message with ack", text_message_with_ack },
|
|
{ "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 },
|
|
{ "IsComposing notification", is_composing_notification }
|
|
};
|
|
|
|
test_suite_t message_test_suite = {
|
|
"Message",
|
|
NULL,
|
|
NULL,
|
|
sizeof(message_tests) / sizeof(message_tests[0]),
|
|
message_tests
|
|
};
|
|
|