summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp')
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index 52537a9..20c959c 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -125,60 +125,61 @@ class ChatsManagerTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testPresenceChangeDoesNotReplaceMUCInvite);
CPPUNIT_TEST(testNotSplittingMUCPresenceJoinLeaveLinesOnChatStateNotifications);
// MUC PM Tests
CPPUNIT_TEST(testChatControllerPMPresenceHandling);
CPPUNIT_TEST(testChatControllerMucPmUnavailableErrorHandling);
// Highlighting tests
CPPUNIT_TEST(testChatControllerHighlightingNotificationTesting);
CPPUNIT_TEST(testChatControllerHighlightingNotificationDeduplicateSounds);
CPPUNIT_TEST(testChatControllerHighlightingNotificationKeyword);
CPPUNIT_TEST(testChatControllerMeMessageHandling);
CPPUNIT_TEST(testRestartingMUCComponentCrash);
CPPUNIT_TEST(testChatControllerMeMessageHandlingInMUC);
// Carbons tests
CPPUNIT_TEST(testCarbonsForwardedIncomingMessageToSecondResource);
CPPUNIT_TEST(testCarbonsForwardedOutgoingMessageFromSecondResource);
CPPUNIT_TEST(testCarbonsForwardedIncomingDuplicates);
// Message correction tests
CPPUNIT_TEST(testChatControllerMessageCorrectionCorrectReplaceID);
CPPUNIT_TEST(testChatControllerMessageCorrectionIncorrectReplaceID);
CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceBySameResource);
CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceByOtherResource);
CPPUNIT_TEST(testMUCControllerMessageCorrectionNoIDMatchRequired);
//Imptomptu test
CPPUNIT_TEST(testImpromptuChatTitle);
+ CPPUNIT_TEST(testImpromptuChatWindowTitle);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
mocks_ = new MockRepository();
notifier_ = std::unique_ptr<DummyNotifier>(new DummyNotifier());
jid_ = JID("test@test.com/resource");
stanzaChannel_ = new DummyStanzaChannel();
iqRouter_ = new IQRouter(stanzaChannel_);
eventController_ = new EventController();
chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
joinMUCWindowFactory_ = mocks_->InterfaceMock<JoinMUCWindowFactory>();
xmppRoster_ = new XMPPRosterImpl();
mucRegistry_ = new MUCRegistry();
nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, nullptr, mucRegistry_);
presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
serverDiscoInfo_ = std::make_shared<DiscoInfo>();
presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
mucManager_ = new MUCManager(stanzaChannel_, iqRouter_, directedPresenceSender_, mucRegistry_);
uiEventStream_ = new UIEventStream();
entityCapsProvider_ = new DummyEntityCapsProvider();
chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>();
mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>();
settings_ = new DummySettingsProvider();
profileSettings_ = new ProfileSettingsProvider("a", settings_);
chatListWindow_ = new MockChatListWindow();
ftManager_ = new DummyFileTransferManager();
ftOverview_ = new FileTransferOverview(ftManager_);
@@ -1484,123 +1485,133 @@ public:
userPayload->addItem(MUCItem(MUCOccupant::Member, JID("foo@bar.com"), MUCOccupant::Moderator));
presence->addPayload(userPayload);
stanzaChannel_->onPresenceReceived(presence);
}
{
Message::ref mucMirrored = std::make_shared<Message>();
mucMirrored->setFrom(mucJID.withResource(nickname));
mucMirrored->setTo(jid_);
mucMirrored->setType(Message::Groupchat);
mucMirrored->setID("fooBlaID_1");
mucMirrored->setBody("Some misssssspelled message.");
manager_->handleIncomingMessage(mucMirrored);
}
CPPUNIT_ASSERT_EQUAL(std::string("Some misssssspelled message."), window->bodyFromMessage(window->lastAddedMessage_));
// Replace message with non-matching ID
{
Message::ref mucMirrored = std::make_shared<Message>();
mucMirrored->setFrom(mucJID.withResource(nickname));
mucMirrored->setTo(jid_);
mucMirrored->setType(Message::Groupchat);
mucMirrored->setID("fooBlaID_3");
mucMirrored->setBody("Some correctly spelled message.");
mucMirrored->addPayload(std::make_shared<Replace>("fooBlaID_2"));
manager_->handleIncomingMessage(mucMirrored);
}
CPPUNIT_ASSERT_EQUAL(std::string("Some correctly spelled message."), window->bodyFromMessage(window->lastReplacedMessage_));
}
- void testImpromptuChatTitle() {
+ void impromptuChatSetup(MockChatWindow* window) {
stanzaChannel_->uniqueIDs_ = true;
JID mucJID("795B7BBE-9099-4A0D-81BA-C816F78E275C@test.com");
manager_->setOnline(true);
- // Open chat window to a sender.
- MockChatWindow* window = new MockChatWindow();
std::shared_ptr<IQ> infoRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[1]);
CPPUNIT_ASSERT(infoRequest);
std::shared_ptr<IQ> infoResponse = IQ::createResult(infoRequest->getFrom(), infoRequest->getTo(), infoRequest->getID());
DiscoInfo info;
info.addIdentity(DiscoInfo::Identity("Shakespearean Chat Service", "conference", "text"));
info.addFeature("http://jabber.org/protocol/muc");
infoResponse->addPayload(std::make_shared<DiscoInfo>(info));
stanzaChannel_->onIQReceived(infoResponse);
std::vector<JID> jids;
jids.emplace_back("foo@test.com");
jids.emplace_back("bar@test.com");
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(mucJID, uiEventStream_).Return(window);
uiEventStream_->send(std::make_shared<CreateImpromptuMUCUIEvent>(jids, mucJID, ""));
CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
auto mucJoinPresence = std::dynamic_pointer_cast<Presence>(stanzaChannel_->sentStanzas[2]);
CPPUNIT_ASSERT(mucJoinPresence);
// MUC presence reply
auto mucResponse = Presence::create();
mucResponse->setTo(jid_);
mucResponse->setFrom(mucJoinPresence->getTo());
mucResponse->addPayload([]() {
auto mucUser = std::make_shared<MUCUserPayload>();
mucUser->addItem(MUCItem(MUCOccupant::Member, MUCOccupant::Participant));
mucUser->addStatusCode(MUCUserPayload::StatusCode(110));
mucUser->addStatusCode(MUCUserPayload::StatusCode(210));
return mucUser;
}());
stanzaChannel_->onPresenceReceived(mucResponse);
// Before people join the impromptu room, the title is based on names coming from Roster
CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
auto mucParticipantJoined = [&](const JID& jid) {
auto participantJoinedPresence = Presence::create();
participantJoinedPresence->setTo(jid_);
participantJoinedPresence->setFrom(mucJID.withResource(jid.toString()));
auto mucUser = std::make_shared<MUCUserPayload>();
mucUser->addItem(MUCItem(MUCOccupant::Member, MUCOccupant::Participant));
participantJoinedPresence->addPayload(mucUser);
return participantJoinedPresence;
};
for (const auto& participantJID : jids) {
stanzaChannel_->onPresenceReceived(mucParticipantJoined(participantJID));
}
+ }
+ void testImpromptuChatTitle() {
+ // Open a new chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ impromptuChatSetup(window);
// After people joined, the title is the list of participant nicknames or names coming from Roster (if nicknames are unavailable)
CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
}
+ void testImpromptuChatWindowTitle() {
+ // Open a new chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ impromptuChatSetup(window);
+ // After people joined, the title of chat window is combined of participant nicknames or names coming from Roster (if nicknames are unavailable)
+ CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), window->name_);
+ }
private:
std::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) {
std::shared_ptr<Message> message = std::make_shared<Message>();
message->setFrom(from);
message->setID(id);
message->setBody("This will cause the window to open");
message->addPayload(std::make_shared<DeliveryReceiptRequest>());
return message;
}
size_t st(int i) {
return static_cast<size_t>(i);
}
void handleHighlightAction(const HighlightAction& action) {
handledHighlightActions_++;
if (action.getSoundFilePath()) {
soundsPlayed_.insert(action.getSoundFilePath().get_value_or(""));
}
}
private:
JID jid_;
std::unique_ptr<DummyNotifier> notifier_;
ChatsManager* manager_;
DummyStanzaChannel* stanzaChannel_;
IQRouter* iqRouter_;
EventController* eventController_;
ChatWindowFactory* chatWindowFactory_;