Commit 8fdfb416 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improved chat_message_put_char method to store message if end of line...

Improved chat_message_put_char method to store message if end of line character is passed + improved tester
parent 89f62e10
......@@ -329,7 +329,6 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
if (cr->call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(cr->call))) {
uint32_t new_line = 0x2028;
linphone_chat_message_put_char(msg, new_line); // New Line
linphone_chat_message_set_state(msg, LinphoneChatMessageStateDelivered);
linphone_chat_message_unref(msg);
return;
}
......@@ -867,7 +866,7 @@ void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *c
if (character == new_line || character == crlf || character == lf) {
// End of message
LinphoneChatMessage *msg = cr->pending_message;
ms_message("New line received, forge a message with content %s", cr->pending_message->message);
ms_debug("New line received, forge a message with content %s", cr->pending_message->message);
linphone_chat_message_set_from(msg, cr->peer_url);
if (msg->to)
......@@ -890,7 +889,7 @@ void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *c
} else {
char *value = utf8_to_char(character);
cr->pending_message->message = ms_strcat_printf(cr->pending_message->message, value);
ms_message("Received RTT character: %s (%lu), pending text is %s", value, (unsigned long)character, cr->pending_message->message);
ms_debug("Received RTT character: %s (%lu), pending text is %s", value, (unsigned long)character, cr->pending_message->message);
ms_free(value);
}
}
......@@ -911,15 +910,36 @@ uint32_t linphone_chat_room_get_char(const LinphoneChatRoom *cr) {
return 0;
}
int linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t charater) {
int linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t character) {
LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg);
LinphoneCall *call = cr->call;
uint32_t new_line = 0x2028;
uint32_t crlf = 0x0D0A;
uint32_t lf = 0x0A;
if (!call || !call->textstream) {
return -1;
}
text_stream_putchar32(call->textstream, charater);
if (character == new_line || character == crlf || character == lf) {
ms_debug("New line sent, forge a message with content %s", msg->message);
msg->time = ms_time(0);
msg->state = LinphoneChatMessageStateDelivered;
msg->is_read = TRUE;
msg->dir = LinphoneChatMessageOutgoing;
if (msg->from) linphone_address_destroy(msg->from);
msg->from = linphone_address_new(linphone_core_get_identity(cr->lc));
msg->storage_id = linphone_chat_message_store(msg);
ms_free(msg->message);
msg->message = NULL;
} else {
char *value = utf8_to_char(character);
msg->message = ms_strcat_printf(msg->message, value);
ms_debug("Sent RTT character: %s (%lu), pending text is %s", value, (unsigned long)character, msg->message);
ms_free(value);
}
text_stream_putchar32(call->textstream, character);
return 0;
}
......
......@@ -1333,12 +1333,19 @@ static void file_transfer_io_error_after_destroying_chatroom(void) {
file_transfer_io_error_base("https://www.linphone.org:444/lft.php", TRUE);
}
static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled, bool_t mess_with_marie_payload_number, bool_t mess_with_pauline_payload_number, bool_t ice_enabled) {
static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled, bool_t mess_with_marie_payload_number, bool_t mess_with_pauline_payload_number, bool_t ice_enabled, bool_t sql_storage) {
LinphoneChatRoom *pauline_chat_room;
LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
LinphoneCallParams *marie_params = NULL;
LinphoneCall *pauline_call, *marie_call;
char *marie_db = bc_tester_file("marie.db");
char *pauline_db = bc_tester_file("pauline.db");
if (sql_storage) {
linphone_core_set_chat_database_path(marie->lc, marie_db);
linphone_core_set_chat_database_path(pauline->lc, pauline_db);
}
if (mess_with_marie_payload_number) {
MSList *elem;
......@@ -1405,6 +1412,19 @@ static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled, boo
}
linphone_chat_room_send_chat_message(pauline_chat_room, rtt_message);
BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1));
if (sql_storage) {
MSList *marie_messages = linphone_chat_room_get_history(marie_chat_room, 0);
MSList *pauline_messages = linphone_chat_room_get_history(pauline_chat_room, 0);
LinphoneChatMessage *marie_msg = (LinphoneChatMessage *)marie_messages->data;
LinphoneChatMessage *pauline_msg = (LinphoneChatMessage *)pauline_messages->data;
BC_ASSERT_EQUAL(ms_list_size(marie_messages), 1, int , "%i");
BC_ASSERT_EQUAL(ms_list_size(pauline_messages), 1, int , "%i");
BC_ASSERT_STRING_EQUAL(marie_msg->message, message);
BC_ASSERT_STRING_EQUAL(pauline_msg->message, message);
ms_list_free_with_data(marie_messages, (void (*)(void *))linphone_chat_message_unref);
ms_list_free_with_data(pauline_messages, (void (*)(void *))linphone_chat_message_unref);
}
}
if (!audio_stream_enabled) {
......@@ -1423,10 +1443,18 @@ static void real_time_text(bool_t audio_stream_enabled, bool_t srtp_enabled, boo
linphone_call_params_destroy(marie_params);
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
remove(marie_db);
bc_free(marie_db);
remove(pauline_db);
bc_free(pauline_db);
}
static void real_time_text_message(void) {
real_time_text(TRUE, FALSE, FALSE, FALSE, FALSE);
real_time_text(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
}
static void real_time_text_sql_storage(void) {
real_time_text(TRUE, FALSE, FALSE, FALSE, FALSE, TRUE);
}
static void real_time_text_conversation(void) {
......@@ -1529,15 +1557,15 @@ static void real_time_text_conversation(void) {
}
static void real_time_text_without_audio(void) {
real_time_text(FALSE, FALSE, FALSE, FALSE, FALSE);
real_time_text(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
}
static void real_time_text_srtp(void) {
real_time_text(TRUE, TRUE, FALSE, FALSE, FALSE);
real_time_text(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
}
static void real_time_text_ice(void) {
real_time_text(TRUE, FALSE, FALSE, FALSE, TRUE);
real_time_text(TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);
}
static void real_time_text_message_compat(bool_t end_with_crlf, bool_t end_with_lf) {
......@@ -1646,11 +1674,11 @@ static void real_time_text_message_accented_chars(void) {
}
static void real_time_text_message_different_text_codecs_payload_numbers_sender_side(void) {
real_time_text(FALSE, FALSE, TRUE, FALSE, FALSE);
real_time_text(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);
}
static void real_time_text_message_different_text_codecs_payload_numbers_receiver_side(void) {
real_time_text(FALSE, FALSE, FALSE, TRUE, FALSE);
real_time_text(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE);
}
static void real_time_text_copy_paste(void) {
......@@ -1748,6 +1776,7 @@ test_t message_tests[] = {
TEST_ONE_TAG("Transfer not sent if url moved permanently", file_transfer_not_sent_if_url_moved_permanently, "LeaksMemory"),
TEST_ONE_TAG("Transfer io error after destroying chatroom", file_transfer_io_error_after_destroying_chatroom, "LeaksMemory"),
TEST_NO_TAG("Real Time Text message", real_time_text_message),
TEST_NO_TAG("Real Time Text SQL storage", real_time_text_sql_storage),
TEST_NO_TAG("Real Time Text conversation", real_time_text_conversation),
TEST_NO_TAG("Real Time Text without audio", real_time_text_without_audio),
TEST_NO_TAG("Real Time Text with srtp", real_time_text_srtp),
......
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