diff options
Diffstat (limited to 'Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp')
| -rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | 84 |
1 files changed, 81 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 1502dc9..08609ee 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2017 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -32,9 +32,12 @@ | |||
| 32 | #include <Swiften/Elements/Forwarded.h> | 32 | #include <Swiften/Elements/Forwarded.h> |
| 33 | #include <Swiften/Elements/MUCInvitationPayload.h> | 33 | #include <Swiften/Elements/MUCInvitationPayload.h> |
| 34 | #include <Swiften/Elements/MUCUserPayload.h> | 34 | #include <Swiften/Elements/MUCUserPayload.h> |
| 35 | #include <Swiften/Elements/PrivateStorage.h> | ||
| 36 | #include <Swiften/Elements/Storage.h> | ||
| 35 | #include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h> | 37 | #include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h> |
| 36 | #include <Swiften/Jingle/JingleSessionManager.h> | 38 | #include <Swiften/Jingle/JingleSessionManager.h> |
| 37 | #include <Swiften/MUC/MUCManager.h> | 39 | #include <Swiften/MUC/MUCManager.h> |
| 40 | #include <Swiften/MUC/UnitTest/MockMUC.h> | ||
| 38 | #include <Swiften/Network/DummyTimerFactory.h> | 41 | #include <Swiften/Network/DummyTimerFactory.h> |
| 39 | #include <Swiften/Presence/DirectedPresenceSender.h> | 42 | #include <Swiften/Presence/DirectedPresenceSender.h> |
| 40 | #include <Swiften/Presence/PresenceOracle.h> | 43 | #include <Swiften/Presence/PresenceOracle.h> |
| @@ -71,7 +74,6 @@ | |||
| 71 | #include <SwifTools/Notifier/Notifier.h> | 74 | #include <SwifTools/Notifier/Notifier.h> |
| 72 | 75 | ||
| 73 | #include <Swift/QtUI/QtSwiftUtil.h> | 76 | #include <Swift/QtUI/QtSwiftUtil.h> |
| 74 | #include <Swiften/MUC/UnitTest/MockMUC.h> | ||
| 75 | 77 | ||
| 76 | using namespace Swift; | 78 | using namespace Swift; |
| 77 | 79 | ||
| @@ -155,6 +157,11 @@ class ChatsManagerTest : public CppUnit::TestFixture { | |||
| 155 | CPPUNIT_TEST(testImpromptuChatWindowTitle); | 157 | CPPUNIT_TEST(testImpromptuChatWindowTitle); |
| 156 | CPPUNIT_TEST(testStandardMUCChatWindowTitle); | 158 | CPPUNIT_TEST(testStandardMUCChatWindowTitle); |
| 157 | 159 | ||
| 160 | // Bookmark tests | ||
| 161 | CPPUNIT_TEST(testReceivingBookmarksWithDomainJID); | ||
| 162 | CPPUNIT_TEST(testReceivingBookmarksWithBareJID); | ||
| 163 | CPPUNIT_TEST(testReceivingBookmarksWithFullJID); | ||
| 164 | |||
| 158 | CPPUNIT_TEST_SUITE_END(); | 165 | CPPUNIT_TEST_SUITE_END(); |
| 159 | 166 | ||
| 160 | public: | 167 | public: |
| @@ -1598,6 +1605,78 @@ public: | |||
| 1598 | CPPUNIT_ASSERT_EQUAL(std::string("mucroom"), window->name_); | 1605 | CPPUNIT_ASSERT_EQUAL(std::string("mucroom"), window->name_); |
| 1599 | } | 1606 | } |
| 1600 | 1607 | ||
| 1608 | static std::shared_ptr<Storage> createBookmarkStorageWithJID(const JID& jid) { | ||
| 1609 | auto storage = std::make_shared<Storage>(); | ||
| 1610 | auto room = Storage::Room(); | ||
| 1611 | room.jid = jid; | ||
| 1612 | room.autoJoin = true; | ||
| 1613 | storage->addRoom(room); | ||
| 1614 | return storage; | ||
| 1615 | } | ||
| 1616 | |||
| 1617 | void testReceivingBookmarksWithDomainJID() { | ||
| 1618 | auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]); | ||
| 1619 | CPPUNIT_ASSERT(bookmarkRequest); | ||
| 1620 | CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType()); | ||
| 1621 | |||
| 1622 | auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>(); | ||
| 1623 | CPPUNIT_ASSERT(privateStorage); | ||
| 1624 | |||
| 1625 | auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload()); | ||
| 1626 | CPPUNIT_ASSERT(storage); | ||
| 1627 | |||
| 1628 | auto response = IQ::createResult( | ||
| 1629 | bookmarkRequest->getFrom(), | ||
| 1630 | bookmarkRequest->getTo(), | ||
| 1631 | bookmarkRequest->getID(), | ||
| 1632 | std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("montague.lit")) | ||
| 1633 | ); | ||
| 1634 | stanzaChannel_->onIQReceived(response); | ||
| 1635 | } | ||
| 1636 | |||
| 1637 | void testReceivingBookmarksWithBareJID() { | ||
| 1638 | auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]); | ||
| 1639 | CPPUNIT_ASSERT(bookmarkRequest); | ||
| 1640 | CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType()); | ||
| 1641 | |||
| 1642 | auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>(); | ||
| 1643 | CPPUNIT_ASSERT(privateStorage); | ||
| 1644 | |||
| 1645 | auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload()); | ||
| 1646 | CPPUNIT_ASSERT(storage); | ||
| 1647 | |||
| 1648 | MockChatWindow* window = new MockChatWindow(); | ||
| 1649 | mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID("example@montague.lit"), uiEventStream_).Return(window); | ||
| 1650 | |||
| 1651 | auto response = IQ::createResult( | ||
| 1652 | bookmarkRequest->getFrom(), | ||
| 1653 | bookmarkRequest->getTo(), | ||
| 1654 | bookmarkRequest->getID(), | ||
| 1655 | std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("example@montague.lit")) | ||
| 1656 | ); | ||
| 1657 | stanzaChannel_->onIQReceived(response); | ||
| 1658 | } | ||
| 1659 | |||
| 1660 | void testReceivingBookmarksWithFullJID() { | ||
| 1661 | auto bookmarkRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[0]); | ||
| 1662 | CPPUNIT_ASSERT(bookmarkRequest); | ||
| 1663 | CPPUNIT_ASSERT_EQUAL(IQ::Get, bookmarkRequest->getType()); | ||
| 1664 | |||
| 1665 | auto privateStorage = bookmarkRequest->getPayload<PrivateStorage>(); | ||
| 1666 | CPPUNIT_ASSERT(privateStorage); | ||
| 1667 | |||
| 1668 | auto storage = std::dynamic_pointer_cast<Storage>(privateStorage->getPayload()); | ||
| 1669 | CPPUNIT_ASSERT(storage); | ||
| 1670 | |||
| 1671 | auto response = IQ::createResult( | ||
| 1672 | bookmarkRequest->getFrom(), | ||
| 1673 | bookmarkRequest->getTo(), | ||
| 1674 | bookmarkRequest->getID(), | ||
| 1675 | std::make_shared<PrivateStorage>(createBookmarkStorageWithJID("example@montague.lit/someresource")) | ||
| 1676 | ); | ||
| 1677 | stanzaChannel_->onIQReceived(response); | ||
| 1678 | } | ||
| 1679 | |||
| 1601 | private: | 1680 | private: |
| 1602 | std::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) { | 1681 | std::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) { |
| 1603 | std::shared_ptr<Message> message = std::make_shared<Message>(); | 1682 | std::shared_ptr<Message> message = std::make_shared<Message>(); |
| @@ -1664,4 +1743,3 @@ private: | |||
| 1664 | }; | 1743 | }; |
| 1665 | 1744 | ||
| 1666 | CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest); | 1745 | CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest); |
| 1667 | |||
Swift