summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-08-17 09:02:24 (GMT)
committerTobias Markmann <tm@ayena.de>2017-04-18 15:38:43 (GMT)
commit57a611f942f2387e497334888a4bc4f68b9275c9 (patch)
tree4785288a4aca2ac31f1de50c71a1d782b7d5ae6a /Swift/Controllers/Chat/UnitTest
parent476e2b32106449dc52a0b237caeb0492fe6c9c32 (diff)
downloadswift-57a611f942f2387e497334888a4bc4f68b9275c9.zip
swift-57a611f942f2387e497334888a4bc4f68b9275c9.tar.bz2
Support Last Message Correction in multi client scenarios
Previously Last Message Correction edits are only applied if they came from the same resource. This makes sense in MUC scenarios but does not in 1-to-1 chats. This changes the Last Message Correction behaviour for MUC and 1-to-1 chats so that different clients from the same bare JID can edit each others messages. Test-Information: Added unit test to verify Last Message Corrections work as expected when coming from the same client and from different clients. Manually verified that the receiving client correctly shows a corrected message if the sending client reconnected between first message and edit. All unit tests pass on OS X 10.11.6 with Qt 5.5.1. Change-Id: If533ecc7032e59e324979c577726f2da739012e6
Diffstat (limited to 'Swift/Controllers/Chat/UnitTest')
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp84
1 files changed, 70 insertions, 14 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index d104fbd..0356c6a 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -139,2 +139,7 @@ class ChatsManagerTest : public CppUnit::TestFixture {
+
+ // Message correction tests
+ CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceBySameResource);
+ CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceByOtherResource);
+
CPPUNIT_TEST_SUITE_END();
@@ -219,3 +224,2 @@ public:
delete settings_;
-
}
@@ -734,3 +738,3 @@ public:
stanzaChannel_->onPresenceReceived(presence);
- CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedLastMessage_));
}
@@ -1099,3 +1103,3 @@ public:
stanzaChannel_->onPresenceReceived(generateIncomingPresence(Presence::Unavailable));
- CPPUNIT_ASSERT_EQUAL(std::string(""), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), MockChatWindow::bodyFromMessage(window->lastReplacedLastMessage_));
CPPUNIT_ASSERT_EQUAL(std::string("testling@test.com has gone offline."), MockChatWindow::bodyFromMessage(window->lastAddedPresence_));
@@ -1136,3 +1140,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname has entered the room."), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastReplacedLastMessage_));
window->resetLastMessages();
@@ -1147,3 +1151,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname and Romeo have entered the room"), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname and Romeo have entered the room"), window->bodyFromMessage(window->lastReplacedLastMessage_));
window->resetLastMessages();
@@ -1167,3 +1171,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname, Romeo and Juliet have entered the room"), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname, Romeo and Juliet have entered the room"), window->bodyFromMessage(window->lastReplacedLastMessage_));
}
@@ -1267,3 +1271,3 @@ public:
}
-
+
void testCarbonsForwardedIncomingDuplicates() {
@@ -1271,6 +1275,6 @@ public:
JID jid2 = jid_.toBare().withResource("someOtherResource");
-
+
MockChatWindow* window = new MockChatWindow();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
-
+
std::shared_ptr<Message> message(new Message());
@@ -1281,3 +1285,3 @@ public:
CPPUNIT_ASSERT_EQUAL(body, MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
-
+
// incoming carbons message from another resource and duplicate of it
@@ -1291,7 +1295,7 @@ public:
originalMessage->setBody(forwardedBody);
-
+
auto messageWrapper = createCarbonsMessage(std::make_shared<CarbonsReceived>(), originalMessage);
-
+
manager_->handleIncomingMessage(messageWrapper);
-
+
CPPUNIT_ASSERT_EQUAL(forwardedBody, MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
@@ -1299,3 +1303,3 @@ public:
window->resetLastMessages();
-
+
messageWrapper = createCarbonsMessage(std::make_shared<CarbonsReceived>(), originalMessage);
@@ -1307,2 +1311,54 @@ public:
+ void testChatControllerMessageCorrectionReplaceBySameResource() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ auto message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text before edit");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text before edit"), MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
+
+ message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text after edit");
+ message->addPayload(std::make_shared<Replace>("someID"));
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text after edit"), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ }
+
+ void testChatControllerMessageCorrectionReplaceByOtherResource() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ auto message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text before edit");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text before edit"), MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
+
+ message = std::make_shared<Message>();
+ message->setFrom(messageJID.toBare().withResource("resource2"));
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text after edit");
+ message->addPayload(std::make_shared<Replace>("someID"));
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text after edit"), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ }
+
private: