diff options
Diffstat (limited to 'Swift/Controllers/Chat/UnitTest')
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp index 32639f6..59dcd77 100644 --- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp @@ -62,6 +62,8 @@ class MUCControllerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testSubjectChangeIncorrectA); CPPUNIT_TEST(testSubjectChangeIncorrectB); CPPUNIT_TEST(testSubjectChangeIncorrectC); + CPPUNIT_TEST(testHandleOccupantNicknameChanged); + CPPUNIT_TEST(testHandleOccupantNicknameChangedRoster); CPPUNIT_TEST_SUITE_END(); public: @@ -501,6 +503,61 @@ public: } } + void testHandleOccupantNicknameChanged() { + const auto occupantCount = [&](const std::string & nick) { + auto roster = window_->getRosterModel(); + CPPUNIT_ASSERT(roster != nullptr); + const auto currentOccupantsJIDs = roster->getJIDs(); + int count = 0; + for (auto & p : currentOccupantsJIDs) { + if (p.getResource() == nick) { + ++count; + } + } + return count; + }; + + muc_->insertOccupant(MUCOccupant("TestUserOne", MUCOccupant::Participant, MUCOccupant::Owner)); + muc_->insertOccupant(MUCOccupant("TestUserTwo", MUCOccupant::Participant, MUCOccupant::Owner)); + muc_->insertOccupant(MUCOccupant("TestUserThree", MUCOccupant::Participant, MUCOccupant::Owner)); + + muc_->onOccupantNicknameChanged("TestUserOne", "TestUserTwo"); + + CPPUNIT_ASSERT_EQUAL(0, occupantCount("TestUserOne")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserTwo")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserThree")); + } + + void testHandleOccupantNicknameChangedRoster() { + const auto occupantCount = [&](const std::string & nick) { + auto roster = window_->getRosterModel(); + CPPUNIT_ASSERT(roster != nullptr); + const auto participants = roster->getGroup("Participants"); + CPPUNIT_ASSERT(participants != nullptr); + const auto displayedParticipants = participants->getDisplayedChildren(); + int count = 0; + for (auto & p : displayedParticipants) { + if (p->getDisplayName() == nick) { + ++count; + } + } + return count; + }; + + muc_->insertOccupant(MUCOccupant("TestUserOne", MUCOccupant::Participant, MUCOccupant::Owner)); + muc_->insertOccupant(MUCOccupant("TestUserTwo", MUCOccupant::Participant, MUCOccupant::Owner)); + muc_->insertOccupant(MUCOccupant("TestUserThree", MUCOccupant::Participant, MUCOccupant::Owner)); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserOne")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserTwo")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserThree")); + + muc_->onOccupantNicknameChanged("TestUserOne", "TestUserTwo"); + + CPPUNIT_ASSERT_EQUAL(0, occupantCount("TestUserOne")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserTwo")); + CPPUNIT_ASSERT_EQUAL(1, occupantCount("TestUserThree")); + } + void testRoleAffiliationStatesVerify(const std::map<std::string, MUCOccupant> &occupants) { /* verify that the roster is in sync */ GroupRosterItem* group = window_->getRosterModel()->getRoot(); |