summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/UnitTest')
-rw-r--r--Swift/Controllers/UnitTest/ChatsManagerTest.cpp99
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.cpp7
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h36
3 files changed, 142 insertions, 0 deletions
diff --git a/Swift/Controllers/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/UnitTest/ChatsManagerTest.cpp
new file mode 100644
index 0000000..6f6958e
--- /dev/null
+++ b/Swift/Controllers/UnitTest/ChatsManagerTest.cpp
@@ -0,0 +1,99 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include "3rdParty/hippomocks.h"
+
+#include "Swift/Controllers/ChatsManager.h"
+
+#include "Swift/Controllers/ChatWindow.h"
+#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swiften/Roster/TreeWidgetFactory.h"
+#include "Swiften/Client/Client.h"
+#include "Swift/Controllers/ChatController.h"
+#include "Swift/Controllers/EventController.h"
+#include "Swift/Controllers/MUCController.h"
+#include "Swiften/Presence/PresenceSender.h"
+#include "Swiften/Avatars/UnitTest/MockAvatarManager.h"
+#include "Swift/Controllers/NickResolver.h"
+#include "Swiften/Roster/XMPPRoster.h"
+#include "Swift/Controllers/UnitTest/MockChatWindow.h"
+#include "Swiften/Client/DummyStanzaChannel.h"
+#include "Swiften/Queries/DummyIQChannel.h"
+#include "Swiften/Presence/PresenceOracle.h"
+
+
+using namespace Swift;
+
+class ChatsManagerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ChatsManagerTest);
+ CPPUNIT_TEST(testFirstOpenWindow);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ ChatsManagerTest() {};
+
+ void setUp() {
+ mocks_ = new MockRepository();
+ jid_ = JID("test@test.com/resource");
+ stanzaChannel_ = new DummyStanzaChannel();
+ iqChannel_ = new DummyIQChannel();
+ iqRouter_ = new IQRouter(iqChannel_);
+ eventController_ = new EventController();
+ chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
+ treeWidgetFactory_ = NULL;
+ xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster());
+ nickResolver_ = new NickResolver(xmppRoster_);
+ presenceOracle_ = new PresenceOracle(stanzaChannel_);
+ serverDiscoInfo_ = boost::shared_ptr<DiscoInfo>(new DiscoInfo());
+ presenceSender_ = NULL;
+ manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, treeWidgetFactory_, nickResolver_, presenceOracle_, serverDiscoInfo_, presenceSender_);
+ avatarManager_ = new MockAvatarManager();
+ manager_->setAvatarManager(avatarManager_);
+ };
+
+ void tearDown() {
+ delete manager_;
+ delete presenceSender_;
+ delete avatarManager_;
+ delete presenceOracle_;
+ delete nickResolver_;
+ delete treeWidgetFactory_;
+ //delete chatWindowFactory_;
+ delete stanzaChannel_;
+ delete iqChannel_;
+ delete iqRouter_;
+ delete mocks_;
+ }
+
+ void testFirstOpenWindow() {
+ JID messageJID("testling@test.com/resource1");
+
+ ChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID).Return(window);
+
+ boost::shared_ptr<Message> message(new Message());
+ message->setFrom(messageJID);
+ message->setBody("This is a legible message.");
+ manager_->handleIncomingMessage(message);
+ }
+
+private:
+ JID jid_;
+ ChatsManager* manager_;
+ StanzaChannel* stanzaChannel_;
+ IQChannel* iqChannel_;
+ IQRouter* iqRouter_;
+ EventController* eventController_;
+ ChatWindowFactory* chatWindowFactory_;
+ TreeWidgetFactory* treeWidgetFactory_;
+ NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
+ boost::shared_ptr<XMPPRoster> xmppRoster_;
+ PresenceSender* presenceSender_;
+ MockRepository* mocks_;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest);
+
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.cpp b/Swift/Controllers/UnitTest/MockChatWindow.cpp
new file mode 100644
index 0000000..406bb55
--- /dev/null
+++ b/Swift/Controllers/UnitTest/MockChatWindow.cpp
@@ -0,0 +1,7 @@
+#include "Swift/Controllers/UnitTest/MockChatWindow.h"
+
+namespace Swift {
+MockChatWindow::~MockChatWindow() {
+
+}
+}
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
new file mode 100644
index 0000000..015bb9b
--- /dev/null
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Swift/Controllers/ChatWindow.h"
+
+namespace Swift {
+ class MockChatWindow : public ChatWindow {
+ public:
+ MockChatWindow() {};
+ virtual ~MockChatWindow();
+
+ virtual void addMessage(const String& /*message*/, const String& /*senderName*/, bool /*senderIsSelf*/, const boost::optional<SecurityLabel>& /*label*/, const String& /*avatarPath*/) {};
+ virtual void addSystemMessage(const String& /*message*/) {};
+ virtual void addErrorMessage(const String& /*message*/) {};
+
+ virtual void setName(const String& name) {name_ = name;};
+ virtual void show() {};
+ virtual void activate() {};
+ virtual void setAvailableSecurityLabels(const std::vector<SecurityLabel>& labels) {labels_ = labels;};
+ virtual void setSecurityLabelsEnabled(bool enabled) {labelsEnabled_ = enabled;};
+ virtual void setUnreadMessageCount(int /*count*/) {};
+ virtual void convertToMUC() {};
+ virtual TreeWidget *getTreeWidget() {return NULL;};
+ virtual void setSecurityLabelsError() {};
+ virtual SecurityLabel getSelectedSecurityLabel() {return SecurityLabel();};
+ virtual void setInputEnabled(bool /*enabled*/) {};
+
+ boost::signal<void ()> onClosed;
+ boost::signal<void ()> onAllMessagesRead;
+ boost::signal<void (const String&)> onSendMessageRequest;
+
+ String name_;
+ std::vector<SecurityLabel> labels_;
+ bool labelsEnabled_;
+ };
+}
+