summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
commitf53a1ef582494458301b97bf6e546be52d7ff7e8 (patch)
tree7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /Swiften/Roster/UnitTest
parent638345680d72ca6acaf123f2c8c1c391f696e371 (diff)
downloadswift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip
swift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2
Moving submodule contents back.
Diffstat (limited to 'Swiften/Roster/UnitTest')
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidget.h14
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetFactory.h50
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetItem.h30
-rw-r--r--Swiften/Roster/UnitTest/OfflineRosterFilterTest.cpp0
-rw-r--r--Swiften/Roster/UnitTest/RosterTest.cpp57
-rw-r--r--Swiften/Roster/UnitTest/XMPPRosterTest.cpp164
6 files changed, 315 insertions, 0 deletions
diff --git a/Swiften/Roster/UnitTest/MockTreeWidget.h b/Swiften/Roster/UnitTest/MockTreeWidget.h
new file mode 100644
index 0000000..e6f6def
--- /dev/null
+++ b/Swiften/Roster/UnitTest/MockTreeWidget.h
@@ -0,0 +1,14 @@
+#ifndef SWIFTEN_MockTreeWidget_H
+#define SWIFTEN_MockTreeWidget_H
+
+#include "Swiften/Roster/TreeWidget.h"
+
+namespace Swift {
+
+class MockTreeWidget : public TreeWidget {
+ public:
+ virtual ~MockTreeWidget() {}
+};
+
+}
+#endif
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h b/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
new file mode 100644
index 0000000..b2b4f10
--- /dev/null
+++ b/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
@@ -0,0 +1,50 @@
+#ifndef SWIFTEN_MockTreeWidgetFactory_H
+#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"
+
+namespace Swift {
+
+class MockTreeWidgetItem;
+class MockTreeWidget;
+
+class MockTreeWidgetFactory : public TreeWidgetFactory {
+ public:
+ virtual ~MockTreeWidgetFactory() {}
+ virtual TreeWidget* createTreeWidget() {
+ root_ = new MockTreeWidget();
+ return root_;
+ };
+ virtual TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem* group) {
+ MockTreeWidgetItem* entry = new MockTreeWidgetItem();
+ groupMembers_[group].push_back(entry);
+ return entry;
+ };
+ virtual TreeWidgetItem* createTreeWidgetItem(TreeWidget*) {
+ 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_;
+};
+
+}
+
+#endif
+
+
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
new file mode 100644
index 0000000..a40aca7
--- /dev/null
+++ b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
@@ -0,0 +1,30 @@
+#ifndef SWIFTEN_MockTreeWidgetItem_H
+#define SWIFTEN_MockTreeWidgetItem_H
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Roster/TreeWidgetItem.h"
+
+#include <boost/signal.hpp>
+#include <boost/shared_ptr.hpp>
+
+namespace Swift {
+
+class MockTreeWidgetItem : public TreeWidgetItem {
+ public:
+ virtual ~MockTreeWidgetItem() {};
+ 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 show() {};
+ virtual void hide() {};
+ private:
+ String text_;
+};
+
+}
+#endif
+
+
diff --git a/Swiften/Roster/UnitTest/OfflineRosterFilterTest.cpp b/Swiften/Roster/UnitTest/OfflineRosterFilterTest.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Swiften/Roster/UnitTest/OfflineRosterFilterTest.cpp
diff --git a/Swiften/Roster/UnitTest/RosterTest.cpp b/Swiften/Roster/UnitTest/RosterTest.cpp
new file mode 100644
index 0000000..b43a41c
--- /dev/null
+++ b/Swiften/Roster/UnitTest/RosterTest.cpp
@@ -0,0 +1,57 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Roster/Roster.h"
+#include "Swiften/Roster/UnitTest/MockTreeWidget.h"
+#include "Swiften/Roster/UnitTest/MockTreeWidgetFactory.h"
+#include "Swiften/Roster/UnitTest/MockTreeWidgetItem.h"
+
+using namespace Swift;
+
+class RosterTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(RosterTest);
+ CPPUNIT_TEST(testGetGroup);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ Roster *roster_;
+ TreeWidget *widget_;
+ TreeWidgetFactory *factory_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
+
+ public:
+
+ RosterTest() : jid1_(JID("a@b.c")), jid2_(JID("b@c.d")), jid3_(JID("c@d.e")) {}
+
+ void setUp() {
+ factory_ = new MockTreeWidgetFactory();
+ widget_ = factory_->createTreeWidget();
+ roster_ = new Roster(widget_, factory_);
+ }
+
+ void tearDown() {
+ delete roster_;
+ //delete widget_;
+ delete factory_;
+ }
+
+ void testGetGroup() {
+ roster_->addContact(jid1_, "Bert", "group1");
+ roster_->addContact(jid2_, "Ernie", "group2");
+ roster_->addContact(jid3_, "Cookie", "group1");
+
+ CPPUNIT_ASSERT_EQUAL(roster_->getGroup("group1"), roster_->getGroup("group1"));
+ CPPUNIT_ASSERT_EQUAL(roster_->getGroup("group2"), roster_->getGroup("group2"));
+ CPPUNIT_ASSERT_EQUAL(roster_->getGroup("group3"), roster_->getGroup("group3"));
+ CPPUNIT_ASSERT(roster_->getGroup("group1") != roster_->getGroup("group2"));
+ CPPUNIT_ASSERT(roster_->getGroup("group2") != roster_->getGroup("group3"));
+ CPPUNIT_ASSERT(roster_->getGroup("group3") != roster_->getGroup("group1"));
+ }
+
+};
+CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest);
+
diff --git a/Swiften/Roster/UnitTest/XMPPRosterTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterTest.cpp
new file mode 100644
index 0000000..d03953e
--- /dev/null
+++ b/Swiften/Roster/UnitTest/XMPPRosterTest.cpp
@@ -0,0 +1,164 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+
+#include <vector>
+
+#include "Swiften/Roster/XMPPRoster.h"
+
+
+using namespace Swift;
+
+enum XMPPRosterEvents {None, Add, Remove, Update};
+
+class XMPPRosterSignalHandler {
+public:
+ XMPPRosterSignalHandler(XMPPRoster* roster) {
+ lastEvent_ = None;
+ roster->onJIDAdded.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDAdded, this, _1));
+ roster->onJIDRemoved.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDRemoved, this, _1));
+ roster->onJIDUpdated.connect(boost::bind(&XMPPRosterSignalHandler::handleJIDUpdated, this, _1, _2, _3));
+ }
+
+ XMPPRosterEvents getLastEvent() {
+ return lastEvent_;
+ }
+
+ JID getLastJID() {
+ return lastJID_;
+ }
+
+ String getLastOldName() {
+ return lastOldName_;
+ }
+
+ std::vector<String> getLastOldGroups() {
+ return lastOldGroups_;
+ }
+
+ void reset() {
+ lastEvent_ = None;
+ }
+
+private:
+ void handleJIDAdded(const JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Add;
+ }
+
+ void handleJIDRemoved(const JID& jid) {
+ lastJID_ = jid;
+ lastEvent_ = Remove;
+ }
+
+ void handleJIDUpdated(const JID& jid, const String& oldName, const std::vector<String>& oldGroups) {
+ CPPUNIT_ASSERT_EQUAL(None, lastEvent_);
+ lastJID_ = jid;
+ lastOldName_ = oldName;
+ lastOldGroups_ = oldGroups;
+ lastEvent_ = Update;
+ }
+
+ XMPPRosterEvents lastEvent_;
+ JID lastJID_;
+ String lastOldName_;
+ std::vector<String> lastOldGroups_;
+
+};
+
+class XMPPRosterTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(XMPPRosterTest);
+ CPPUNIT_TEST(testJIDAdded);
+ CPPUNIT_TEST(testJIDRemoved);
+ CPPUNIT_TEST(testJIDUpdated);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ XMPPRoster* roster_;
+ XMPPRosterSignalHandler* handler_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
+ std::vector<String> groups1_;
+ std::vector<String> groups2_;
+
+
+ public:
+
+ XMPPRosterTest() : jid1_(JID("a@b.c")), jid2_(JID("b@c.d")), jid3_(JID("c@d.e")) {}
+
+ void setUp() {
+ roster_ = new XMPPRoster();
+ handler_ = new XMPPRosterSignalHandler(roster_);
+ groups1_.push_back("bobs");
+ groups1_.push_back("berts");
+ groups2_.push_back("ernies");
+ }
+
+ void tearDown() {
+ delete roster_;
+ }
+
+ void testJIDAdded() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid2_, "NameTwo", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NameTwo"), roster_->getNameForJID(jid2_));
+ CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid2_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid3_, "NewName", groups2_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid3_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid3_));
+ CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid3_));
+ }
+
+ void testJIDRemoved() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ handler_->reset();
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ handler_->reset();
+ roster_->addContact(jid1_, "NewName2", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NewName2"), roster_->getNameForJID(jid1_));
+ roster_->addContact(jid2_, "NewName3", groups1_, RosterItemPayload::Both);
+ handler_->reset();
+ roster_->removeContact(jid2_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid2_, handler_->getLastJID());
+ handler_->reset();
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(Remove, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ }
+
+ void testJIDUpdated() {
+ roster_->addContact(jid1_, "NewName", groups1_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Add, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NewName"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups1_ == roster_->getGroupsForJID(jid1_));
+ handler_->reset();
+ roster_->addContact(jid1_, "NameTwo", groups2_, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(Update, handler_->getLastEvent());
+ CPPUNIT_ASSERT_EQUAL(jid1_, handler_->getLastJID());
+ CPPUNIT_ASSERT_EQUAL(String("NameTwo"), roster_->getNameForJID(jid1_));
+ CPPUNIT_ASSERT(groups2_ == roster_->getGroupsForJID(jid1_));
+ }
+
+};
+CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterTest);
+