From 4cb2ddcfad938991517eb1b946bdd0bf32893392 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 9 Nov 2016 17:27:53 +0100 Subject: [PATCH] Forgot to commit changes to message_tester --- tester/message_tester.c | 59 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/tester/message_tester.c b/tester/message_tester.c index 70604d337..babf00259 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -74,9 +74,17 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess * */ void file_transfer_received(LinphoneChatMessage *msg, const LinphoneContent* content, const LinphoneBuffer *buffer){ FILE* file=NULL; - char *receive_file = bc_tester_file("receive_file.dump"); + char *receive_file = NULL; LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); LinphoneCore *lc = linphone_chat_room_get_core(cr); + + if (linphone_chat_message_get_file_transfer_filepath(msg) != NULL) { + stats* counters = get_stats(lc); + counters->number_of_LinphoneFileTransferDownloadSuccessful++; + return; + } + + receive_file = bc_tester_file("receive_file.dump"); if (!linphone_chat_message_get_user_data(msg)) { /*first chunk, creating file*/ file = fopen(receive_file,"wb"); @@ -196,7 +204,7 @@ void compare_files(const char *path1, const char *path2) { buf2 = (uint8_t*)ms_load_path_content(path2, &size2); BC_ASSERT_PTR_NOT_NULL(buf1); BC_ASSERT_PTR_NOT_NULL(buf2); - BC_ASSERT_EQUAL((uint8_t)size1, (uint8_t)size2, uint8_t, "%u"); + BC_ASSERT_EQUAL((uint8_t)size2, (uint8_t)size1, uint8_t, "%u"); BC_ASSERT_EQUAL(memcmp(buf1, buf2, size1), 0, int, "%d"); ms_free(buf1); ms_free(buf2); @@ -234,6 +242,30 @@ LinphoneChatMessage* create_message_from_nowebcam(LinphoneChatRoom *chat_room) { return msg; } +LinphoneChatMessage* create_file_transfer_message_from_nowebcam(LinphoneChatRoom *chat_room) { + LinphoneChatMessageCbs *cbs; + LinphoneContent* content; + LinphoneChatMessage* msg; + char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg"); + + content = linphone_core_create_content(chat_room->lc); + belle_sip_object_set_name(&content->base, "nowebcam content"); + linphone_content_set_type(content,"image"); + linphone_content_set_subtype(content,"jpeg"); + linphone_content_set_name(content,"nowebcamCIF.jpg"); + + + msg = linphone_chat_room_create_file_transfer_message(chat_room, content); + linphone_chat_message_set_file_transfer_filepath(msg, send_filepath); + cbs = linphone_chat_message_get_callbacks(msg); + linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); + linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); + + linphone_content_unref(content); + ms_free(send_filepath); + return msg; +} + void text_message_base(LinphoneCoreManager* marie, LinphoneCoreManager* pauline) { LinphoneChatMessage* msg = linphone_chat_room_create_message(linphone_core_get_chat_room(pauline->lc,marie->identity),"Bli bli bli \n blu"); LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg); @@ -857,7 +889,7 @@ end: linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } -void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_stored_msg) { +void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_stored_msg, bool_t use_file_body_handler) { FILE *ZIDCacheMarieFD, *ZIDCachePaulineFD; LinphoneCoreManager *marie, *pauline; LinphoneChatMessage *msg; @@ -906,7 +938,11 @@ void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_st linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php"); /* create a file transfer msg */ - msg = create_message_from_nowebcam(linphone_core_get_chat_room(pauline->lc, marie->identity)); + if (use_file_body_handler) { + msg = create_file_transfer_message_from_nowebcam(linphone_core_get_chat_room(pauline->lc, marie->identity)); + } else { + msg = create_message_from_nowebcam(linphone_core_get_chat_room(pauline->lc, marie->identity)); + } linphone_chat_room_send_chat_message(msg->chat_room, msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1)); @@ -932,6 +968,10 @@ void lime_transfer_message_base(bool_t encrypt_file,bool_t download_file_from_st BC_ASSERT_PTR_NOT_NULL(linphone_content_get_key(content)); else BC_ASSERT_PTR_NULL(linphone_content_get_key(content)); + + if (use_file_body_handler) { + linphone_chat_message_set_file_transfer_filepath(recv_msg, receive_filepath); + } linphone_chat_message_download_file(recv_msg); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1)); compare_files(send_filepath, receive_filepath); @@ -948,15 +988,19 @@ end: } static void lime_transfer_message(void) { - lime_transfer_message_base(TRUE,FALSE); + lime_transfer_message_base(TRUE,FALSE,FALSE); +} + +static void lime_transfer_message_2(void) { + lime_transfer_message_base(TRUE,FALSE,TRUE); } static void lime_transfer_message_from_history(void) { - lime_transfer_message_base(TRUE,TRUE); + lime_transfer_message_base(TRUE,TRUE,FALSE); } static void lime_transfer_message_without_encryption(void) { - lime_transfer_message_base(FALSE,FALSE); + lime_transfer_message_base(FALSE,FALSE,FALSE); } static void printHex(char *title, uint8_t *data, size_t length) { @@ -1856,6 +1900,7 @@ test_t message_tests[] = { TEST_NO_TAG("Lime text message", lime_text_message), TEST_NO_TAG("Lime text message to non lime", lime_text_message_to_non_lime), TEST_NO_TAG("Lime transfer message", lime_transfer_message), + TEST_NO_TAG("Lime transfer message 2", lime_transfer_message_2), TEST_NO_TAG("Lime transfer message from history", lime_transfer_message_from_history), TEST_NO_TAG("Lime transfer message without encryption", lime_transfer_message_without_encryption), TEST_NO_TAG("Lime unitary", lime_unit),