summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-11-08 19:26:36 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-11-08 19:26:36 (GMT)
commite77d80d9258699295ad793a8a94e369be5e31a36 (patch)
treeb75f1a644740e9d216701e0095c1bd14573dbcdd /Swift/Controllers/UnitTest
parentb6003bea740e8898127ec135e230eed421924370 (diff)
downloadswift-e77d80d9258699295ad793a8a94e369be5e31a36.zip
swift-e77d80d9258699295ad793a8a94e369be5e31a36.tar.bz2
Fix for crash on login failure. Scaffoling for testing roster stuff.
Diffstat (limited to 'Swift/Controllers/UnitTest')
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindow.h20
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindowFactory.h22
-rw-r--r--Swift/Controllers/UnitTest/RosterControllerTest.cpp71
3 files changed, 113 insertions, 0 deletions
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_;
+
+};