summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Roster/UnitTest')
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidget.h20
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetFactory.h74
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetItem.cpp19
-rw-r--r--Swiften/Roster/UnitTest/MockTreeWidgetItem.h38
-rw-r--r--Swiften/Roster/UnitTest/RosterTest.cpp25
5 files changed, 9 insertions, 167 deletions
diff --git a/Swiften/Roster/UnitTest/MockTreeWidget.h b/Swiften/Roster/UnitTest/MockTreeWidget.h
deleted file mode 100644
index 97dd796..0000000
--- a/Swiften/Roster/UnitTest/MockTreeWidget.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#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
deleted file mode 100644
index d94c859..0000000
--- a/Swiften/Roster/UnitTest/MockTreeWidgetFactory.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#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(this);
- groupMembers_[group].push_back(entry);
- return entry;
- };
- virtual TreeWidgetItem* createTreeWidgetItem(TreeWidget*) {
- MockTreeWidgetItem* group = new MockTreeWidgetItem(this);
- 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;
- };
-
- typedef std::map<TreeWidgetItem*, std::vector<MockTreeWidgetItem*> > itemMap;
-
- virtual std::vector<MockTreeWidgetItem*> getGroupMembers(const String& group) {
- for (itemMap::iterator it = groupMembers_.begin(); it != groupMembers_.end(); it++) {
- if (((MockTreeWidgetItem*)(it->first))->getText() == group) {
- return it->second;
- }
- }
- return std::vector<MockTreeWidgetItem*>();
- };
-
- virtual void removeItem(MockTreeWidgetItem* item) {
- foreach (TreeWidgetItem* groupItem, groups_) {
- std::vector<MockTreeWidgetItem*>& members = groupMembers_[groupItem];
- members.erase(std::remove(members.begin(), members.end(), item), members.end());
- }
- };
- private:
- std::vector<MockTreeWidgetItem*> groups_;
- std::map<TreeWidgetItem*, std::vector<MockTreeWidgetItem*> > groupMembers_;
- MockTreeWidget* root_;
-};
-
-}
-
-#endif
-
-
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetItem.cpp b/Swiften/Roster/UnitTest/MockTreeWidgetItem.cpp
deleted file mode 100644
index 4238ead..0000000
--- a/Swiften/Roster/UnitTest/MockTreeWidgetItem.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-#include "Swiften/Roster/UnitTest/MockTreeWidgetItem.h"
-
-#include "Swiften/Roster/UnitTest/MockTreeWidgetFactory.h"
-
-namespace Swift {
-
-MockTreeWidgetItem::~MockTreeWidgetItem() {
- factory_->removeItem(this);
-}
-
-}
-
-
-
diff --git a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h b/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
deleted file mode 100644
index 08b9f1a..0000000
--- a/Swiften/Roster/UnitTest/MockTreeWidgetItem.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2010 Kevin Smith
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#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 MockTreeWidgetFactory;
-class MockTreeWidgetItem : public TreeWidgetItem {
- public:
- MockTreeWidgetItem(MockTreeWidgetFactory* factory) {factory_ = factory;};
- 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_;
- MockTreeWidgetFactory* factory_;
-};
-
-}
-#endif
-
-
diff --git a/Swiften/Roster/UnitTest/RosterTest.cpp b/Swiften/Roster/UnitTest/RosterTest.cpp
index 5a2a3e3..f9dff33 100644
--- a/Swiften/Roster/UnitTest/RosterTest.cpp
+++ b/Swiften/Roster/UnitTest/RosterTest.cpp
@@ -9,9 +9,7 @@
#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"
+#include "Swiften/Roster/GroupRosterItem.h"
using namespace Swift;
@@ -23,8 +21,6 @@ class RosterTest : public CppUnit::TestFixture
private:
Roster *roster_;
- TreeWidget *widget_;
- TreeWidgetFactory *factory_;
JID jid1_;
JID jid2_;
JID jid3_;
@@ -34,15 +30,11 @@ class RosterTest : public CppUnit::TestFixture
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_);
+ roster_ = new Roster();
}
void tearDown() {
delete roster_;
- //delete widget_;
- delete factory_;
}
void testGetGroup() {
@@ -50,12 +42,13 @@ class RosterTest : public CppUnit::TestFixture
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_ASSERT_EQUAL(2, (int)roster_->getRoot()->getChildren().size());
+ CPPUNIT_ASSERT_EQUAL(String("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(String("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(String("Bert"), ((GroupRosterItem*)roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(String("Cookie"), ((GroupRosterItem*)roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(String("Ernie"), ((GroupRosterItem*)roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
+
}
};