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/MockTreeWidgetItem.h2
6 files changed, 119 insertions, 3 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 15947b6..9df2308 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..84a1063
--- /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(treeWidgetFactory_->);
+ //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/MockTreeWidgetItem.h b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
index eee0962..9b05d40 100644
--- a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
+++ b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
@@ -16,7 +16,7 @@ class MockTreeWidgetItem : public TreeWidgetItem {
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() {};
};