summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-06 08:00:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-06 10:49:49 (GMT)
commit081fc03556708447610e9697a57235fa191a4f0d (patch)
tree505c8cc9129d2b44968d183a180f0ccddaa08810 /Swift/Controllers/UnitTest
parent8c53236875d2ca77f1b463449918458f6b424ab1 (diff)
downloadswift-081fc03556708447610e9697a57235fa191a4f0d.zip
swift-081fc03556708447610e9697a57235fa191a4f0d.tar.bz2
Rewrite of large amounts of roster code.
Now keeps widgets out of Swiften, keeps sorting inside Swiften, and keeps track of presences to show the correct presence per roster item. Resolves: #316 Resolves: #81 Resolves: #239
Diffstat (limited to 'Swift/Controllers/UnitTest')
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h2
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindow.h11
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindowFactory.h8
-rw-r--r--Swift/Controllers/UnitTest/RosterControllerTest.cpp48
4 files changed, 36 insertions, 33 deletions
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index fecd665..1ce87ff 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -27,10 +27,10 @@ namespace Swift {
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*/) {};
+ virtual void setRosterModel(Roster* /*roster*/) {};
boost::signal<void ()> onClosed;
boost::signal<void ()> onAllMessagesRead;
diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h
index f6134da..4d0c67a 100644
--- a/Swift/Controllers/UnitTest/MockMainWindow.h
+++ b/Swift/Controllers/UnitTest/MockMainWindow.h
@@ -7,20 +7,19 @@
#pragma once
#include "Swift/Controllers/UIInterfaces/MainWindow.h"
-#include "Swiften/Roster/TreeWidget.h"
namespace Swift {
+ class Roster;
class MockMainWindow : public MainWindow {
public:
- MockMainWindow(TreeWidget* treeWidget) {treeWidget_ = treeWidget;};
+ MockMainWindow() {};
virtual ~MockMainWindow() {};
- virtual TreeWidget* getTreeWidget() {return treeWidget_;};
+ virtual void setRosterModel(Roster* roster) {this->roster = roster;};
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_;
+ Roster* roster;
+
};
}
diff --git a/Swift/Controllers/UnitTest/MockMainWindowFactory.h b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
index 2f0559b..8a35d1a 100644
--- a/Swift/Controllers/UnitTest/MockMainWindowFactory.h
+++ b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
@@ -7,21 +7,19 @@
#pragma once
#include "Swift/Controllers/UIInterfaces/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;};
+ MockMainWindowFactory() {};
virtual ~MockMainWindowFactory() {};
/**
* Transfers ownership of result.
*/
- virtual MainWindow* createMainWindow(UIEventStream*) {return new MockMainWindow(factory_->createTreeWidget());};
- private:
- TreeWidgetFactory* factory_;
+ virtual MainWindow* createMainWindow(UIEventStream*) {last = new MockMainWindow();return last;};
+ MockMainWindow* last;
};
}
diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp
index 1177bd7..4bb3a08 100644
--- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp
+++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp
@@ -10,7 +10,6 @@
#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"
@@ -18,6 +17,9 @@
#include "Swiften/Client/DummyStanzaChannel.h"
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Roster/XMPPRoster.h"
+#include "Swiften/Roster/Roster.h"
+#include "Swiften/Roster/GroupRosterItem.h"
+#include "Swiften/Roster/ContactRosterItem.h"
#include "Swift/Controllers/EventController.h"
#include "Swiften/Presence/PresenceOracle.h"
#include "Swift/Controllers/NickResolver.h"
@@ -25,6 +27,7 @@
using namespace Swift;
+#define CHILDREN mainWindow_->roster->getRoot()->getChildren()
class RosterControllerTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(RosterControllerTest);
@@ -40,8 +43,7 @@ class RosterControllerTest : public CppUnit::TestFixture
jid_ = JID("testjid@swift.im/swift");
xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster());
avatarManager_ = NULL;//new AvatarManager();
- treeWidgetFactory_ = new MockTreeWidgetFactory();
- mainWindowFactory_ = new MockMainWindowFactory(treeWidgetFactory_);
+ mainWindowFactory_ = new MockMainWindowFactory();
nickResolver_ = new NickResolver(xmppRoster_);
channel_ = new DummyIQChannel();
router_ = new IQRouter(channel_);
@@ -49,9 +51,8 @@ class RosterControllerTest : public CppUnit::TestFixture
presenceOracle_ = new PresenceOracle(stanzaChannel_);
eventController_ = new EventController();
uiEventStream_ = new UIEventStream();
- rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, treeWidgetFactory_, nickResolver_, presenceOracle_, eventController_, uiEventStream_, router_);
-
-
+ rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickResolver_, presenceOracle_, eventController_, uiEventStream_, router_);
+ mainWindow_ = mainWindowFactory_->last;
};
void tearDown() {
@@ -65,16 +66,19 @@ class RosterControllerTest : public CppUnit::TestFixture
delete presenceOracle_;
delete stanzaChannel_;
delete uiEventStream_;
- delete treeWidgetFactory_;
};
+ GroupRosterItem* groupChild(size_t i) {
+ return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
+ }
+
void testAdd() {
std::vector<String> groups;
groups.push_back("testGroup1");
groups.push_back("testGroup2");
xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(2, (int)treeWidgetFactory_->getGroups().size());
+ CPPUNIT_ASSERT_EQUAL(2, (int)CHILDREN.size());
//CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
};
@@ -83,15 +87,15 @@ class RosterControllerTest : public CppUnit::TestFixture
JID jid("test@testdomain.com");
xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::None);
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroups().size());
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroupMembers("Contacts").size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)CHILDREN.size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)groupChild(0)->getChildren().size());
xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::To);
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroups().size());
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroupMembers("Contacts").size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)CHILDREN.size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)groupChild(0)->getChildren().size());
xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroups().size());
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroupMembers("Contacts").size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)CHILDREN.size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)groupChild(0)->getChildren().size());
};
@@ -100,20 +104,20 @@ class RosterControllerTest : public CppUnit::TestFixture
JID jid("test@testdomain.com");
xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroups().size());
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroupMembers("Contacts").size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)CHILDREN.size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)groupChild(0)->getChildren().size());
+ CPPUNIT_ASSERT_EQUAL(String("name"), groupChild(0)->getChildren()[0]->getDisplayName());
xmppRoster_->addContact(jid, "NewName", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroups().size());
- CPPUNIT_ASSERT_EQUAL(1, (int)treeWidgetFactory_->getGroupMembers("Contacts").size());
- CPPUNIT_ASSERT_EQUAL(String("NewName"), treeWidgetFactory_->getGroupMembers("Contacts")[0]->getText());
+ CPPUNIT_ASSERT_EQUAL(1, (int)CHILDREN.size());
+ CPPUNIT_ASSERT_EQUAL(1, (int)groupChild(0)->getChildren().size());
+ CPPUNIT_ASSERT_EQUAL(String("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
};
private:
JID jid_;
boost::shared_ptr<XMPPRoster> xmppRoster_;
AvatarManager* avatarManager_;
- MainWindowFactory* mainWindowFactory_;
- MockTreeWidgetFactory* treeWidgetFactory_;
+ MockMainWindowFactory* mainWindowFactory_;
NickResolver* nickResolver_;
RosterController* rosterController_;
DummyIQChannel* channel_;
@@ -122,6 +126,8 @@ class RosterControllerTest : public CppUnit::TestFixture
PresenceOracle* presenceOracle_;
EventController* eventController_;
UIEventStream* uiEventStream_;
+ MockMainWindow* mainWindow_;
};
+#undef children
CPPUNIT_TEST_SUITE_REGISTRATION(RosterControllerTest);