summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/MainController.cpp6
-rw-r--r--Swift/Controllers/SConscript1
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindow.h20
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindowFactory.h22
-rw-r--r--Swift/Controllers/UnitTest/RosterControllerTest.cpp71
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetFactory.h29
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetItem.h7
7 files changed, 147 insertions, 9 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 6b3b002..6c60783 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -314,8 +314,10 @@ void MainController::logout() {
if (client_ && client_->isAvailable()) {
client_->disconnect();
}
- rosterController_->getWindow()->setMyStatusType(StatusShow::None);
- rosterController_->getWindow()->setMyStatusText("");
+ if (rosterController_) {
+ rosterController_->getWindow()->setMyStatusType(StatusShow::None);
+ rosterController_->getWindow()->setMyStatusText("");
+ }
setManagersEnabled(false);
}
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index ac06e9a..dfcf878 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -22,5 +22,6 @@ myenv.StaticLibrary("SwiftControllers", [
env.Append(UNITTEST_SOURCES = [
File("UnitTest/NickResolverTest.cpp"),
+ File("UnitTest/RosterControllerTest.cpp"),
File("UnitTest/XMPPRosterControllerTest.cpp")
])
diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h
new file mode 100644
index 0000000..9d2389b
--- /dev/null
+++ b/Swift/Controllers/UnitTest/MockMainWindow.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Swift/Controllers/MainWindow.h"
+#include "Swiften/Roster/TreeWidget.h"
+
+namespace Swift {
+ class MockMainWindow : public MainWindow {
+ public:
+ MockMainWindow(TreeWidget* treeWidget) {treeWidget_ = treeWidget;};
+ virtual ~MockMainWindow() {};
+ virtual TreeWidget* getTreeWidget() {return treeWidget_;};
+ virtual void setMyName(const String& /*name*/) {};;
+ virtual void setMyAvatarPath(const String& /*path*/) {};
+ virtual void setMyStatusText(const String& /*status*/) {};
+ virtual void setMyStatusType(StatusShow::Type /*type*/) {};
+
+ private:
+ TreeWidget* treeWidget_;
+ };
+}
diff --git a/Swift/Controllers/UnitTest/MockMainWindowFactory.h b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
new file mode 100644
index 0000000..c67df72
--- /dev/null
+++ b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swift/Controllers/MainWindowFactory.h"
+#include "Swiften/Roster/TreeWidgetFactory.h"
+#include "Swift/Controllers/UnitTest/MockMainWindow.h"
+
+namespace Swift {
+
+ class MockMainWindowFactory : public MainWindowFactory {
+ public:
+ MockMainWindowFactory(TreeWidgetFactory* treeWidgetFactory) {factory_ = treeWidgetFactory;};
+ virtual ~MockMainWindowFactory() {};
+ /**
+ * Transfers ownership of result.
+ */
+ virtual MainWindow* createMainWindow() {return new MockMainWindow(factory_->createTreeWidget());};
+ private:
+ TreeWidgetFactory* factory_;
+ };
+}
+
+
diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp
new file mode 100644
index 0000000..0296cdc
--- /dev/null
+++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp
@@ -0,0 +1,71 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swift/Controllers/RosterController.h"
+#include "Swift/Controllers/UnitTest/MockMainWindowFactory.h"
+#include "Swiften/Roster/UnitTest/MockTreeWidgetFactory.h"
+// #include "Swiften/Elements/Payload.h"
+// #include "Swiften/Elements/RosterItemPayload.h"
+// #include "Swiften/Elements/RosterPayload.h"
+#include "Swiften/Queries/DummyIQChannel.h"
+#include "Swiften/Queries/IQRouter.h"
+#include "Swiften/Roster/XMPPRoster.h"
+#include "Swift/Controllers/NickResolver.h"
+
+using namespace Swift;
+
+class RosterControllerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(RosterControllerTest);
+ CPPUNIT_TEST(testAdd);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ RosterControllerTest() {};
+
+ void setUp() {
+ jid_ = JID("testjid@swift.im/swift");
+ xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster());
+ avatarManager_ = NULL;//new AvatarManager();
+ treeWidgetFactory_ = new MockTreeWidgetFactory();
+ mainWindowFactory_ = new MockMainWindowFactory(treeWidgetFactory_);
+ nickResolver_ = new NickResolver(xmppRoster_);
+ rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, treeWidgetFactory_, nickResolver_);
+
+ channel_ = new DummyIQChannel();
+ router_ = new IQRouter(channel_);
+
+ };
+
+ void tearDown() {
+ delete rosterController_;
+ delete nickResolver_;
+ delete treeWidgetFactory_;
+ delete mainWindowFactory_;
+ delete avatarManager_;
+ delete channel_;
+ delete router_;
+ };
+
+ void testAdd() {
+ std::vector<String> groups;
+ groups.push_back("testGroup1");
+ groups.push_back("testGroup2");
+ xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups);
+
+ CPPUNIT_ASSERT_EQUAL(2, (int)treeWidgetFactory_->getGroups().size());
+ //CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
+ };
+
+ private:
+ JID jid_;
+ boost::shared_ptr<XMPPRoster> xmppRoster_;
+ AvatarManager* avatarManager_;
+ MainWindowFactory* mainWindowFactory_;
+ MockTreeWidgetFactory* treeWidgetFactory_;
+ NickResolver* nickResolver_;
+ RosterController* rosterController_;
+ DummyIQChannel* channel_;
+ IQRouter* router_;
+
+};
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h b/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
index 09e4742..b2b4f10 100644
--- a/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
+++ b/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
@@ -2,6 +2,9 @@
#define SWIFTEN_MockTreeWidgetFactory_H
#include "Swiften/Roster/TreeWidgetFactory.h"
+
+#include <vector>
+#include "Swiften/Base/foreach.h"
#include "Swiften/Roster/UnitTest/MockTreeWidget.h"
#include "Swiften/Roster/UnitTest/MockTreeWidgetItem.h"
@@ -14,14 +17,30 @@ class MockTreeWidgetFactory : public TreeWidgetFactory {
public:
virtual ~MockTreeWidgetFactory() {}
virtual TreeWidget* createTreeWidget() {
- return new MockTreeWidget();
+ root_ = new MockTreeWidget();
+ return root_;
};
- virtual TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem*) {
- return new MockTreeWidgetItem();
+ virtual TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem* group) {
+ MockTreeWidgetItem* entry = new MockTreeWidgetItem();
+ groupMembers_[group].push_back(entry);
+ return entry;
};
virtual TreeWidgetItem* createTreeWidgetItem(TreeWidget*) {
- return new MockTreeWidgetItem();
- }
+ MockTreeWidgetItem* group = new MockTreeWidgetItem();
+ groups_.push_back(group);
+ return group;
+ };
+ virtual std::vector<String> getGroups() {
+ std::vector<String> groupNames;
+ foreach (MockTreeWidgetItem* group, groups_) {
+ groupNames.push_back(group->getText());
+ }
+ return groupNames;
+ };
+ private:
+ std::vector<MockTreeWidgetItem*> groups_;
+ std::map<TreeWidgetItem*, std::vector<MockTreeWidgetItem*> > groupMembers_;
+ MockTreeWidget* root_;
};
}
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
index eee0962..a40aca7 100644
--- a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
+++ b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
@@ -12,13 +12,16 @@ namespace Swift {
class MockTreeWidgetItem : public TreeWidgetItem {
public:
virtual ~MockTreeWidgetItem() {};
- virtual void setText(const String&) {};
+ virtual void setText(const String& text) {text_ = text;};
+ String getText() {return text_;};
virtual void setStatusText(const String&) {};
virtual void setAvatarPath(const String&) {};
virtual void setExpanded(bool) {};
- virtual void setStatusShow(StatusShow::Type show) {};
+ virtual void setStatusShow(StatusShow::Type /*show*/) {};
virtual void show() {};
virtual void hide() {};
+ private:
+ String text_;
};
}