diff options
Diffstat (limited to 'Swiften/Roster/UnitTest/RosterTest.cpp')
-rw-r--r-- | Swiften/Roster/UnitTest/RosterTest.cpp | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/Swiften/Roster/UnitTest/RosterTest.cpp b/Swiften/Roster/UnitTest/RosterTest.cpp deleted file mode 100644 index 0300188..0000000 --- a/Swiften/Roster/UnitTest/RosterTest.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <boost/shared_ptr.hpp> - -#include "Swiften/Roster/Roster.h" -#include "Swiften/Roster/GroupRosterItem.h" -#include "Swiften/Roster/SetPresence.h" - -using namespace Swift; - -class RosterTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterTest); - CPPUNIT_TEST(testGetGroup); - CPPUNIT_TEST(testRemoveContact); - CPPUNIT_TEST(testRemoveSecondContact); - CPPUNIT_TEST(testRemoveSecondContactSameBare); - CPPUNIT_TEST(testApplyPresenceLikeMUC); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - jid1_ = JID("a@b.c"); - jid2_ = JID("b@c.d"); - jid3_ = JID("c@d.e"); - roster_ = new Roster(); - } - - void tearDown() { - delete roster_; - } - - void testGetGroup() { - roster_->addContact(jid1_, JID(), "Bert", "group1", ""); - roster_->addContact(jid2_, JID(), "Ernie", "group2", ""); - roster_->addContact(jid3_, JID(), "Cookie", "group1", ""); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<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"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName()); - CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName()); - CPPUNIT_ASSERT_EQUAL(String("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName()); - - } - - void testRemoveContact() { - roster_->addContact(jid1_, jid1_, "Bert", "group1", ""); - CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName()); - - roster_->removeContact(jid1_); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size())); - } - - void testRemoveSecondContact() { - roster_->addContact(jid1_, jid1_, "Bert", "group1", ""); - roster_->addContact(jid2_, jid2_, "Cookie", "group1", ""); - CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName()); - - roster_->removeContact(jid2_); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size())); - CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName()); - } - - void testRemoveSecondContactSameBare() { - JID jid4a("a@b/c"); - JID jid4b("a@b/d"); - roster_->addContact(jid4a, JID(), "Bert", "group1", ""); - roster_->addContact(jid4b, JID(), "Cookie", "group1", ""); - CPPUNIT_ASSERT_EQUAL(String("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName()); - - roster_->removeContact(jid4b); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size())); - CPPUNIT_ASSERT_EQUAL(String("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName()); - } - - void testApplyPresenceLikeMUC() { - JID jid4a("a@b/c"); - JID jid4b("a@b/d"); - JID jid4c("a@b/e"); - roster_->addContact(jid4a, JID(), "Bird", "group1", ""); - roster_->addContact(jid4b, JID(), "Cookie", "group1", ""); - roster_->removeContact(jid4b); - roster_->addContact(jid4c, JID(), "Bert", "group1", ""); - roster_->addContact(jid4b, JID(), "Ernie", "group1", ""); - boost::shared_ptr<Presence> presence(new Presence()); - presence->setShow(StatusShow::DND); - presence->setFrom(jid4a); - roster_->applyOnItems(SetPresence(presence, JID::WithResource)); - presence->setFrom(jid4b); - roster_->applyOnItems(SetPresence(presence, JID::WithResource)); - presence->setFrom(jid4c); - roster_->applyOnItems(SetPresence(presence, JID::WithResource)); - - presence = boost::shared_ptr<Presence>(new Presence()); - presence->setFrom(jid4b); - presence->setShow(StatusShow::Online); - roster_->applyOnItems(SetPresence(presence, JID::WithResource)); - std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren(); - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size())); - - /* Check order */ - CPPUNIT_ASSERT_EQUAL(String("Ernie"), children[0]->getDisplayName()); - CPPUNIT_ASSERT_EQUAL(String("Bert"), children[1]->getDisplayName()); - CPPUNIT_ASSERT_EQUAL(String("Bird"), children[2]->getDisplayName()); - - presence = boost::shared_ptr<Presence>(new Presence()); - presence->setFrom(jid4c); - presence->setType(Presence::Unavailable); - roster_->removeContact(jid4c); - roster_->applyOnItems(SetPresence(presence, JID::WithResource)); - - } - - private: - Roster *roster_; - JID jid1_; - JID jid2_; - JID jid3_; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest); - |