From 234f82e1c3e512c1810ce49e07ed6470d382b160 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 17 May 2018 18:12:23 +0200 Subject: [PATCH] Add a new group chat tester. --- tester/group_chat_tester.c | 120 ++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 79ac6e0f1..b3f8b6bf0 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -3707,6 +3707,123 @@ static void group_chat_room_list_subscription (void) { linphone_core_manager_destroy(laure); } +static void group_chat_room_complex_participant_removal_scenario (void) { + LinphoneCoreManager *marie = linphone_core_manager_create("marie_rc"); + LinphoneCoreManager *pauline = linphone_core_manager_create("pauline_rc"); + LinphoneCoreManager *laure = linphone_core_manager_create("laure_tcp_rc"); + bctbx_list_t *coresManagerList = NULL; + bctbx_list_t *participantsAddresses = NULL; + coresManagerList = bctbx_list_append(coresManagerList, marie); + coresManagerList = bctbx_list_append(coresManagerList, pauline); + coresManagerList = bctbx_list_append(coresManagerList, laure); + bctbx_list_t *coresList = init_core_for_conference(coresManagerList); + start_core_for_conference(coresManagerList); + participantsAddresses = bctbx_list_append(participantsAddresses, linphone_address_new(linphone_core_get_identity(pauline->lc))); + participantsAddresses = bctbx_list_append(participantsAddresses, linphone_address_new(linphone_core_get_identity(laure->lc))); + stats initialMarieStats = marie->stat; + stats initialPaulineStats = pauline->stat; + stats initialLaureStats = laure->stat; + + // Marie creates a new group chat room + const char *initialSubject = "Colleagues"; + LinphoneChatRoom *marieCr = create_chat_room_client_side(coresList, marie, &initialMarieStats, participantsAddresses, initialSubject, -1); + participantsAddresses = NULL; + const LinphoneAddress *confAddr = linphone_chat_room_get_conference_address(marieCr); + + // Check that the chat room is correctly created on Pauline's side and that the participants are added + LinphoneChatRoom *paulineCr = check_creation_chat_room_client_side(coresList, pauline, &initialPaulineStats, confAddr, initialSubject, 2, FALSE); + + // Check that the chat room is correctly created on Laure's side and that the participants are added + check_creation_chat_room_client_side(coresList, laure, &initialLaureStats, confAddr, initialSubject, 2, FALSE); + + // Restart Laure core + linphone_core_set_network_reachable(laure->lc, FALSE); + char *laureIdentity = linphone_core_get_device_identity(laure->lc); + LinphoneAddress *laureAddr = linphone_address_new(laureIdentity); + bctbx_free(laureIdentity); + coresList = bctbx_list_remove(coresList, laure->lc); + linphone_core_manager_reinit(laure); + bctbx_list_t *tmpCoresManagerList = bctbx_list_append(NULL, laure); + bctbx_list_t *tmpCoresList = init_core_for_conference(tmpCoresManagerList); + bctbx_list_free(tmpCoresManagerList); + coresList = bctbx_list_concat(coresList, tmpCoresList); + linphone_core_manager_start(laure, TRUE); + initialLaureStats = laure->stat; + + // Marie removes Laure from the chat room + LinphoneParticipant *laureParticipant = linphone_chat_room_find_participant(marieCr, laureAddr); + BC_ASSERT_PTR_NOT_NULL(laureParticipant); + linphone_chat_room_remove_participant(marieCr, laureParticipant); + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_participants_removed, initialMarieStats.number_of_participants_removed + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_participants_removed, initialPaulineStats.number_of_participants_removed + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateTerminated, initialLaureStats.number_of_LinphoneChatRoomStateTerminated + 1, 3000)); + + wait_for_list(coresList,0, 1, 2000); + initialLaureStats = laure->stat; + + linphone_proxy_config_refresh_register(linphone_core_get_default_proxy_config(laure->lc)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneRegistrationOk, initialLaureStats.number_of_LinphoneRegistrationOk + 1, 1000)); + BC_ASSERT_FALSE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateTerminated, initialLaureStats.number_of_LinphoneChatRoomStateTerminated + 1, 3000)); + + // Marie adds Laure to the chat room + participantsAddresses = bctbx_list_append(participantsAddresses, laureAddr); + linphone_chat_room_add_participants(marieCr, participantsAddresses); + bctbx_list_free_with_data(participantsAddresses, (bctbx_list_free_func)linphone_address_unref); + participantsAddresses = NULL; + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_participants_added, initialMarieStats.number_of_participants_added + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_participants_added, initialPaulineStats.number_of_participants_added + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateCreationPending, initialLaureStats.number_of_LinphoneChatRoomStateCreationPending + 1, 3000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateCreated, initialLaureStats.number_of_LinphoneChatRoomStateCreated + 1, 3000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomConferenceJoined, initialLaureStats.number_of_LinphoneChatRoomConferenceJoined + 1, 3000)); + BC_ASSERT_EQUAL(linphone_chat_room_get_nb_participants(marieCr), 2, int, "%d"); + BC_ASSERT_EQUAL(linphone_chat_room_get_nb_participants(paulineCr), 2, int, "%d"); + laureIdentity = linphone_core_get_device_identity(laure->lc); + laureAddr = linphone_address_new(laureIdentity); + bctbx_free(laureIdentity); + LinphoneChatRoom *newLaureCr = linphone_core_find_chat_room(laure->lc, confAddr, laureAddr); + linphone_address_unref(laureAddr); + BC_ASSERT_EQUAL(linphone_chat_room_get_nb_participants(newLaureCr), 2, int, "%d"); + BC_ASSERT_STRING_EQUAL(linphone_chat_room_get_subject(newLaureCr), initialSubject); + BC_ASSERT_FALSE(linphone_chat_room_has_been_left(newLaureCr)); + + unsigned int nbLaureConferenceCreatedEventsBeforeRestart = 0; + bctbx_list_t *laureHistory = linphone_chat_room_get_history_events(newLaureCr, 0); + for (bctbx_list_t *item = laureHistory; item; item = bctbx_list_next(item)) { + LinphoneEventLog *event = (LinphoneEventLog *)bctbx_list_get_data(item); + if (linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceCreated) + nbLaureConferenceCreatedEventsBeforeRestart++; + } + bctbx_list_free_with_data(laureHistory, (bctbx_list_free_func)linphone_event_log_unref); + BC_ASSERT_EQUAL(nbLaureConferenceCreatedEventsBeforeRestart, 2, unsigned int, "%u"); + + initialLaureStats = laure->stat; + linphone_proxy_config_refresh_register(linphone_core_get_default_proxy_config(laure->lc)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_LinphoneRegistrationOk, initialLaureStats.number_of_LinphoneRegistrationOk + 1, 1000)); + BC_ASSERT_FALSE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomConferenceJoined, initialLaureStats.number_of_LinphoneChatRoomConferenceJoined + 1, 3000)); + BC_ASSERT_FALSE(wait_for_list(coresList, &laure->stat.number_of_LinphoneChatRoomStateTerminated, initialLaureStats.number_of_LinphoneChatRoomStateTerminated + 1, 3000)); + + unsigned int nbLaureConferenceCreatedEventsAfterRestart = 0; + laureHistory = linphone_chat_room_get_history_events(newLaureCr, 0); + for (bctbx_list_t *item = laureHistory; item; item = bctbx_list_next(item)) { + LinphoneEventLog *event = (LinphoneEventLog *)bctbx_list_get_data(item); + if (linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceCreated) + nbLaureConferenceCreatedEventsAfterRestart++; + } + bctbx_list_free_with_data(laureHistory, (bctbx_list_free_func)linphone_event_log_unref); + BC_ASSERT_EQUAL(nbLaureConferenceCreatedEventsAfterRestart, nbLaureConferenceCreatedEventsBeforeRestart, unsigned int, "%u"); + + // Clean db from chat room + linphone_core_manager_delete_chat_room(marie, marieCr, coresList); + linphone_core_manager_delete_chat_room(laure, newLaureCr, coresList); + linphone_core_manager_delete_chat_room(pauline, paulineCr, coresList); + + bctbx_list_free(coresList); + bctbx_list_free(coresManagerList); + linphone_core_manager_destroy(marie); + linphone_core_manager_destroy(pauline); + linphone_core_manager_destroy(laure); +} + test_t group_chat_tests[] = { TEST_NO_TAG("Group chat room creation server", group_chat_room_creation_server), TEST_ONE_TAG("Add participant", group_chat_room_add_participant, "LeaksMemory"), @@ -3755,7 +3872,8 @@ test_t group_chat_tests[] = { TEST_ONE_TAG("IMDN sent from DB state", imdn_sent_from_db_state, "LeaksMemory"), TEST_NO_TAG("Find one to one chat room", find_one_to_one_chat_room), TEST_NO_TAG("New device after group chat room creation", group_chat_room_new_device_after_creation), - TEST_ONE_TAG("Chat room list subscription", group_chat_room_list_subscription, "LeaksMemory") + TEST_ONE_TAG("Chat room list subscription", group_chat_room_list_subscription, "LeaksMemory"), + TEST_ONE_TAG("Complex participant removal scenario", group_chat_room_complex_participant_removal_scenario, "LeaksMemory") }; test_suite_t group_chat_test_suite = {