From 016927324bbf638bba843152937d8350eb4699a2 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Thu, 12 Apr 2018 09:58:47 +0200 Subject: [PATCH] add test to list subscription --- .../remote-conference-event-handler.cpp | 4 + .../remote-conference-list-event-handler.cpp | 18 ++- tester/group_chat_tester.c | 150 +++++++++++++++++- 3 files changed, 166 insertions(+), 6 deletions(-) diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index bb45a18b9..e52c32970 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -24,6 +24,7 @@ #include "conference/remote-conference.h" #include "content/content-manager.h" +#include "content/content-type.h" #include "content/content.h" #include "core/core-p.h" #include "logger/logger.h" @@ -290,6 +291,9 @@ void RemoteConferenceEventHandler::multipartNotifyReceived (const string &xmlBod Content multipart; multipart.setBody(xmlBody); + ContentType contentType(ContentType::Multipart); + contentType.addParameter("boundary", MultipartBoundary); + multipart.setContentType(contentType); for (const auto &content : ContentManager::multipartToContentList(multipart)) d->simpleNotifyReceived(content.getBodyAsString()); diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index bfb283536..6b24f9a7b 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -160,7 +160,11 @@ void RemoteConferenceListEventHandler::notifyReceived (const Content *notifyCont if (cid.empty()) continue; - IdentityAddress peer = addresses[cid]; + map::const_iterator it = addresses.find(cid); + if (it == addresses.cend()) + continue; + + IdentityAddress peer = it->second; ChatRoomId id(peer, local); RemoteConferenceEventHandler *handler = findHandler(id); if (!handler) @@ -209,13 +213,17 @@ map RemoteConferenceListEventHandler::parseRlmi (const if (resource.getInstance().empty()) continue; - IdentityAddress peer(resource.getUri()); + const string &uri = string(resource.getUri()); + if (uri.empty()) + continue; + + IdentityAddress peer(uri); for (const auto &instance : resource.getInstance()) { - if (!instance.getCid().present()) + const string &cid = string(instance.getId()); + if (cid.empty()) continue; - string cid = instance.getCid().get(); - addresses[cid] = peer; + addresses.emplace(cid, peer); } } return addresses; diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 504339e31..154df1847 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -3232,6 +3232,153 @@ static void group_chat_room_new_device_after_creation (void) { linphone_core_manager_destroy(laure); } +static void group_chat_room_list_subscription (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); + stats initialMarieStats = marie->stat; + stats initialPaulineStats = pauline->stat; + stats initialLaureStats = laure->stat; + 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))); + int dummy = 0; + + // Marie creates a new group chat room + const char *initialSubject = "Colleagues"; + LinphoneChatRoom *marieCr1 = create_chat_room_client_side(coresList, marie, &initialMarieStats, participantsAddresses, initialSubject, -1); + const LinphoneAddress *confAddr1 = linphone_chat_room_get_conference_address(marieCr1); + // Check that the chat room is correctly created on Pauline1 and Pauline2's sides and that the participants are added + LinphoneChatRoom *paulineCr1 = check_creation_chat_room_client_side(coresList, pauline, &initialPaulineStats, confAddr1, initialSubject, 2, FALSE); + LinphoneChatRoom *laureCr1 = check_creation_chat_room_client_side(coresList, laure, &initialLaureStats, confAddr1, initialSubject, 2, FALSE); + initialMarieStats = marie->stat; + initialPaulineStats = pauline->stat; + initialLaureStats = laure->stat; + + // Marie creates a new group chat room + initialSubject = "Friends"; + participantsAddresses = NULL; + 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))); + LinphoneChatRoom *marieCr2 = create_chat_room_client_side(coresList, marie, &initialMarieStats, participantsAddresses, initialSubject, -1); + const LinphoneAddress *confAddr2 = linphone_chat_room_get_conference_address(marieCr2); + // Check that the chat room is correctly created on Pauline1 and Pauline2's sides and that the participants are added + LinphoneChatRoom *paulineCr2 = check_creation_chat_room_client_side(coresList, pauline, &initialPaulineStats, confAddr2, initialSubject, 2, FALSE); + LinphoneChatRoom *laureCr2 = check_creation_chat_room_client_side(coresList, laure, &initialLaureStats, confAddr2, initialSubject, 2, FALSE); + initialMarieStats = marie->stat; + initialPaulineStats = pauline->stat; + initialLaureStats = laure->stat; + + // Marie creates a new group chat room + initialSubject = "Bros"; + participantsAddresses = NULL; + 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))); + LinphoneChatRoom *marieCr3 = create_chat_room_client_side(coresList, marie, &initialMarieStats, participantsAddresses, initialSubject, -1); + const LinphoneAddress *confAddr3 = linphone_chat_room_get_conference_address(marieCr3); + // Check that the chat room is correctly created on Pauline1 and Pauline2's sides and that the participants are added + LinphoneChatRoom *paulineCr3 = check_creation_chat_room_client_side(coresList, pauline, &initialPaulineStats, confAddr3, initialSubject, 2, FALSE); + LinphoneChatRoom *laureCr3 = check_creation_chat_room_client_side(coresList, laure, &initialLaureStats, confAddr3, initialSubject, 2, FALSE); + + participantsAddresses = NULL; + + // Marie designates Pauline as admin in chat room 1 + LinphoneAddress *paulineAddr = linphone_address_new(linphone_core_get_identity(pauline->lc)); + LinphoneParticipant *paulineParticipant = linphone_chat_room_find_participant(marieCr1, paulineAddr); + linphone_address_unref(paulineAddr); + BC_ASSERT_PTR_NOT_NULL(paulineParticipant); + linphone_chat_room_set_participant_admin_status(marieCr1, paulineParticipant, TRUE); + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_participant_admin_statuses_changed, initialMarieStats.number_of_participant_admin_statuses_changed + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_participant_admin_statuses_changed, initialPaulineStats.number_of_participant_admin_statuses_changed + 1, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_participant_admin_statuses_changed, initialLaureStats.number_of_participant_admin_statuses_changed + 1, 1000)); + BC_ASSERT_TRUE(linphone_participant_is_admin(paulineParticipant)); + + // Pauline's device goes off + paulineAddr = linphone_address_clone(linphone_chat_room_get_local_address(paulineCr1)); + coresList = bctbx_list_remove(coresList, pauline->lc); + linphone_core_set_network_reachable(pauline->lc, FALSE); + wait_for_list(coresList, &dummy, 1, 1000); + + // Marie designates Laure as admin in chat rooms 1 & 3 + LinphoneAddress *laureAddr = linphone_address_new(linphone_core_get_identity(laure->lc)); + LinphoneParticipant *laureParticipant1 = linphone_chat_room_find_participant(marieCr1, laureAddr); + LinphoneParticipant *laureParticipant2 = linphone_chat_room_find_participant(marieCr2, laureAddr); + LinphoneParticipant *laureParticipant3 = linphone_chat_room_find_participant(marieCr3, laureAddr); + BC_ASSERT_PTR_NOT_NULL(laureParticipant1); + BC_ASSERT_PTR_NOT_NULL(laureParticipant2); + BC_ASSERT_PTR_NOT_NULL(laureParticipant3); + linphone_chat_room_set_participant_admin_status(marieCr1, laureParticipant1, TRUE); + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_participant_admin_statuses_changed, initialMarieStats.number_of_participant_admin_statuses_changed + 2, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_participant_admin_statuses_changed, initialLaureStats.number_of_participant_admin_statuses_changed + 2, 1000)); + BC_ASSERT_TRUE(linphone_participant_is_admin(laureParticipant1)); + linphone_chat_room_set_participant_admin_status(marieCr3, laureParticipant3, TRUE); + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_participant_admin_statuses_changed, initialMarieStats.number_of_participant_admin_statuses_changed + 3, 1000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_participant_admin_statuses_changed, initialLaureStats.number_of_participant_admin_statuses_changed + 3, 1000)); + BC_ASSERT_TRUE(linphone_participant_is_admin(laureParticipant3)); + + // Marie now changes the subject or chat room 1 + const char *newSubject = "New subject"; + linphone_chat_room_set_subject(marieCr1, newSubject); + BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_subject_changed, initialMarieStats.number_of_subject_changed + 1, 10000)); + BC_ASSERT_TRUE(wait_for_list(coresList, &laure->stat.number_of_subject_changed, initialLaureStats.number_of_subject_changed + 1, 10000)); + BC_ASSERT_STRING_EQUAL(linphone_chat_room_get_subject(marieCr1), newSubject); + BC_ASSERT_STRING_EQUAL(linphone_chat_room_get_subject(laureCr1), newSubject); + + // Pauline is back + linphone_core_manager_reinit(pauline); + bctbx_list_t *tmpCoresManagerList = bctbx_list_append(NULL, pauline); + bctbx_list_t *tmpCoresList = init_core_for_conference(tmpCoresManagerList); + bctbx_list_free(tmpCoresManagerList); + coresList = bctbx_list_concat(coresList, tmpCoresList); + linphone_core_manager_start(pauline, TRUE); + paulineCr1 = linphone_core_find_chat_room(pauline->lc, confAddr1, paulineAddr); + paulineCr2 = linphone_core_find_chat_room(pauline->lc, confAddr2, paulineAddr); + paulineCr3 = linphone_core_find_chat_room(pauline->lc, confAddr3, paulineAddr); + BC_ASSERT_PTR_NOT_NULL(paulineCr1); + BC_ASSERT_PTR_NOT_NULL(paulineCr2); + BC_ASSERT_PTR_NOT_NULL(paulineCr3); + linphone_address_unref(paulineAddr); + LinphoneParticipant *laureParticipantOfPauline1 = linphone_chat_room_find_participant(paulineCr1, laureAddr); + LinphoneParticipant *laureParticipantOfPauline2 = linphone_chat_room_find_participant(paulineCr2, laureAddr); + LinphoneParticipant *laureParticipantOfPauline3 = linphone_chat_room_find_participant(paulineCr3, laureAddr); + BC_ASSERT_PTR_NOT_NULL(laureParticipantOfPauline1); + BC_ASSERT_PTR_NOT_NULL(laureParticipantOfPauline2); + BC_ASSERT_PTR_NOT_NULL(laureParticipantOfPauline3); + linphone_address_unref(laureAddr); + wait_for_list(coresList, &dummy, 1, 5000); + + // Check that Pauline receive the missing info and not more + BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_participant_admin_statuses_changed, initialPaulineStats.number_of_participant_admin_statuses_changed + 3, 1000)); + BC_ASSERT_TRUE(linphone_participant_is_admin(laureParticipantOfPauline1)); + BC_ASSERT_TRUE(linphone_participant_is_admin(laureParticipantOfPauline3)); + BC_ASSERT_FALSE(linphone_participant_is_admin(laureParticipantOfPauline2)); + BC_ASSERT_TRUE(wait_for_list(coresList, &pauline->stat.number_of_subject_changed, initialPaulineStats.number_of_subject_changed + 1, 10000)); + BC_ASSERT_STRING_EQUAL(linphone_chat_room_get_subject(paulineCr1), newSubject); + + // Clean db from chat room + linphone_core_manager_delete_chat_room(marie, marieCr1, coresList); + linphone_core_manager_delete_chat_room(pauline, paulineCr1, coresList); + linphone_core_manager_delete_chat_room(laure, laureCr1, coresList); + linphone_core_manager_delete_chat_room(marie, marieCr2, coresList); + linphone_core_manager_delete_chat_room(pauline, paulineCr2, coresList); + linphone_core_manager_delete_chat_room(laure, laureCr2, coresList); + linphone_core_manager_delete_chat_room(marie, marieCr3, coresList); + linphone_core_manager_delete_chat_room(pauline, paulineCr3, coresList); + linphone_core_manager_delete_chat_room(laure, laureCr3, 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"), @@ -3276,7 +3423,8 @@ test_t group_chat_tests[] = { TEST_NO_TAG("Unique one-to-one chatroom re-created from the party that deleted it, with inactive devices", group_chat_room_unique_one_to_one_chat_room_recreated_from_message_2), TEST_NO_TAG("IMDN for group chat room", imdn_for_group_chat_room), 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_NO_TAG("New device after group chat room creation", group_chat_room_new_device_after_creation), + TEST_NO_TAG("Chat room list subscription", group_chat_room_list_subscription) }; test_suite_t group_chat_test_suite = {