From 655f5912a5550fd04ed7d2317a555545f6a4fd97 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 7 Feb 2018 17:14:28 +0100 Subject: [PATCH] add test to chatroom tester to simulate chat room deletion after app restart --- coreapi/linphonecore.c | 19 +++++++++---------- tester/group_chat_tester.c | 28 +++++++++++++++++++++++++++- tester/liblinphone_tester.h | 1 + tester/tester.c | 17 +++++++++++++++-- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index f0cc213e7..114749d3a 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1971,19 +1971,9 @@ void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const static void misc_config_read(LinphoneCore *lc) { LpConfig *config=lc->config; - const char *uuid; lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",LINPHONE_MAX_CALL_HISTORY_SIZE); lc->max_calls=lp_config_get_int(config,"misc","max_calls",NB_MAX_CALLS); - - uuid=lp_config_get_string(config,"misc","uuid",NULL); - if (!uuid){ - char tmp[64]; - lc->sal->create_uuid(tmp,sizeof(tmp)); - lp_config_set_string(config,"misc","uuid",tmp); - }else if (strcmp(uuid,"0")!=0) /*to allow to disable sip.instance*/ - lc->sal->set_uuid(uuid); - lc->user_certificates_path=ms_strdup(lp_config_get_string(config,"misc","user_certificates_path",".")); lc->send_call_stats_periodical_updates = !!lp_config_get_int(config, "misc", "send_call_stats_periodical_updates", 0); } @@ -2322,6 +2312,15 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig void linphone_core_start (LinphoneCore *lc) { linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up"); + //to give a chance to change uuid before starting + const char* uuid=lp_config_get_string(lc->config,"misc","uuid",NULL); + if (!uuid){ + char tmp[64]; + lc->sal->create_uuid(tmp,sizeof(tmp)); + lp_config_set_string(lc->config,"misc","uuid",tmp); + }else if (strcmp(uuid,"0")!=0) /*to allow to disable sip.instance*/ + lc->sal->set_uuid(uuid); + if (lc->sal->get_root_ca()) { belle_tls_crypto_config_set_root_ca(lc->http_crypto_config, lc->sal->get_root_ca()); belle_http_provider_set_tls_crypto_config(lc->http_provider, lc->http_crypto_config); diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 5ae0eb9f6..59cba3be5 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -2362,7 +2362,7 @@ static void group_chat_room_unique_one_to_one_chat_room (void) { linphone_core_manager_destroy(pauline); } -static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message (void) { +static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message_base (bool_t with_app_restart) { LinphoneCoreManager *marie = linphone_core_manager_create("marie_rc"); LinphoneCoreManager *pauline = linphone_core_manager_create("pauline_rc"); bctbx_list_t *coresManagerList = NULL; @@ -2393,6 +2393,23 @@ static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message ( BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_LinphoneMessageReceived, initialPaulineStats.number_of_LinphoneMessageReceived + 1, 10000)); BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text(pauline->stat.last_received_chat_message), message); + if (with_app_restart) { + //to simulate dialog removal + linphone_core_set_network_reachable(marie->lc, FALSE); + //linphone_core_set_network_reachable(marie->lc, TRUE); + coresList=bctbx_list_remove(coresList, marie->lc); + linphone_core_manager_reinit(marie,TRUE); + bctbx_list_t *tmpCoresManagerList = bctbx_list_append(NULL, marie); + init_core_for_conference(tmpCoresManagerList); + bctbx_list_free(tmpCoresManagerList); + coresList = bctbx_list_append(coresList, marie->lc); + linphone_core_manager_start(marie,TRUE); + wait_for_list(coresList, 0, 1, 2000); + LinphoneChatRoom *oldMarieCr = marieCr; + marieCr = linphone_core_get_chat_room(marie->lc, linphone_chat_room_get_peer_address(oldMarieCr)); + } + + // Marie deletes the chat room linphone_core_manager_delete_chat_room(marie, marieCr, coresList); wait_for_list(coresList, 0, 1, 2000); @@ -2424,6 +2441,14 @@ static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message ( linphone_core_manager_destroy(pauline); } +static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message(void) { + group_chat_room_unique_one_to_one_chat_room_recreated_from_message_base(FALSE); +} + +static void group_chat_room_unique_one_to_one_chat_room_recreated_from_message_with_app_restart(void) { + group_chat_room_unique_one_to_one_chat_room_recreated_from_message_base(TRUE); +} + static void group_chat_room_new_unique_one_to_one_chat_room_after_both_participants_left (void) { LinphoneCoreManager *marie = linphone_core_manager_create("marie_rc"); LinphoneCoreManager *pauline = linphone_core_manager_create("pauline_rc"); @@ -2513,6 +2538,7 @@ test_t group_chat_tests[] = { TEST_TWO_TAGS("Send file + text", group_chat_room_send_file_plus_text, "Server", "LeaksMemory"), TEST_TWO_TAGS("Unique one-to-one chatroom", group_chat_room_unique_one_to_one_chat_room, "Server", "LeaksMemory"), TEST_TWO_TAGS("Unique one-to-one chatroom recreated from message", group_chat_room_unique_one_to_one_chat_room_recreated_from_message, "Server", "LeaksMemory"), + TEST_TWO_TAGS("Unique one-to-one chatroom recreated from message with app restart",group_chat_room_unique_one_to_one_chat_room_recreated_from_message_with_app_restart, "Server", "LeaksMemory"), TEST_TWO_TAGS("New unique one-to-one chatroom after both participants left", group_chat_room_new_unique_one_to_one_chat_room_after_both_participants_left, "Server", "LeaksMemory") }; diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 5fecd5371..050462630 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -329,6 +329,7 @@ LinphoneCoreManager* linphone_core_manager_new3(const char* rc_file, bool_t chec LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, bool_t check_for_proxies); LinphoneCoreManager* linphone_core_manager_new(const char* rc_file); void linphone_core_manager_stop(LinphoneCoreManager *mgr); +void linphone_core_manager_reinit(LinphoneCoreManager *mgr, bool_t check_for_proxies); void linphone_core_manager_restart(LinphoneCoreManager *mgr, bool_t check_for_proxies); void linphone_core_manager_uninit(LinphoneCoreManager *mgr); void linphone_core_manager_wait_for_stun_resolution(LinphoneCoreManager *mgr); diff --git a/tester/tester.c b/tester/tester.c index 0b8a86d36..50d3bd6d4 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -459,11 +459,24 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){ } } -void linphone_core_manager_restart(LinphoneCoreManager *mgr, bool_t check_for_proxies) { - if (mgr->lc) +void linphone_core_manager_reinit(LinphoneCoreManager *mgr, bool_t check_for_proxies) { + char* uuid = NULL; + if (mgr->lc) { + if (lp_config_get_string(linphone_core_get_config(mgr->lc),"misc","uuid",NULL)) { + uuid = bctbx_strdup(lp_config_get_string(linphone_core_get_config(mgr->lc),"misc","uuid",NULL)); + } linphone_core_unref(mgr->lc); + } linphone_core_manager_configure(mgr); reset_counters(&mgr->stat); + //to make sure gruu is preserved + lp_config_set_string(linphone_core_get_config(mgr->lc),"misc","uuid",uuid); + if (uuid) + bctbx_free(uuid); +} + +void linphone_core_manager_restart(LinphoneCoreManager *mgr, bool_t check_for_proxies) { + linphone_core_manager_reinit(mgr, check_for_proxies); linphone_core_manager_start(mgr, check_for_proxies); }