diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-01 08:48:42 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-01 09:24:28 (GMT) |
commit | 2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch) | |
tree | d46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp | |
download | swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2 |
Import.
Diffstat (limited to 'Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp')
-rw-r--r-- | Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp b/Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp new file mode 100644 index 0000000..3bff8f3 --- /dev/null +++ b/Swiften/Controllers/UnitTest/XMPPRosterControllerTest.cpp @@ -0,0 +1,83 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Controllers/XMPPRosterController.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" + +using namespace Swift; + +class XMPPRosterControllerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(XMPPRosterControllerTest); + CPPUNIT_TEST(testAdd); + CPPUNIT_TEST(testModify); + CPPUNIT_TEST(testRemove); + CPPUNIT_TEST_SUITE_END(); + + DummyIQChannel* channel_; + IQRouter* router_; + public: + XMPPRosterControllerTest() : channel_(new DummyIQChannel()), router_(new IQRouter(channel_)) {} + + ~XMPPRosterControllerTest() { + delete channel_; + delete router_; + } + + void testAdd() { + boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); + XMPPRosterController controller(router_, xmppRoster); + JID testling("foo@bar"); + CPPUNIT_ASSERT(!xmppRoster->containsJID(testling)); + boost::shared_ptr<Payload> payload(new RosterPayload()); + RosterItemPayload item(testling, "Bob", RosterItemPayload::Both); + dynamic_cast<RosterPayload*>(payload.get())->addItem(item); + controller.handleIQ(IQ::createRequest(IQ::Set, JID(), "eou", payload)); + CPPUNIT_ASSERT(xmppRoster->containsJID(testling)); + } + + void testModify() { + boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); + XMPPRosterController controller(router_, xmppRoster); + JID testling("foo@bar"); + CPPUNIT_ASSERT(!xmppRoster->containsJID(testling)); + boost::shared_ptr<Payload> payload1(new RosterPayload()); + RosterItemPayload item1(testling, "Bob", RosterItemPayload::Both); + dynamic_cast<RosterPayload*>(payload1.get())->addItem(item1); + controller.handleIQ(IQ::createRequest(IQ::Set, JID(), "eou", payload1)); + CPPUNIT_ASSERT(xmppRoster->containsJID(testling)); + CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster->getNameForJID(testling)); + boost::shared_ptr<Payload> payload2(new RosterPayload()); + RosterItemPayload item2(testling, "Bob2", RosterItemPayload::Both); + dynamic_cast<RosterPayload*>(payload2.get())->addItem(item2); + controller.handleIQ(IQ::createRequest(IQ::Set, JID(), "eou", payload2)); + CPPUNIT_ASSERT_EQUAL(String("Bob2"), xmppRoster->getNameForJID(testling)); + } + + void testRemove() { + boost::shared_ptr<XMPPRoster> xmppRoster(new XMPPRoster()); + XMPPRosterController controller(router_, xmppRoster); + JID testling("foo@bar"); + CPPUNIT_ASSERT(!xmppRoster->containsJID(testling)); + boost::shared_ptr<Payload> payload1(new RosterPayload()); + RosterItemPayload item1(testling, "Bob", RosterItemPayload::Both); + dynamic_cast<RosterPayload*>(payload1.get())->addItem(item1); + controller.handleIQ(IQ::createRequest(IQ::Set, JID(), "eou", payload1)); + CPPUNIT_ASSERT(xmppRoster->containsJID(testling)); + boost::shared_ptr<Payload> payload2(new RosterPayload()); + RosterItemPayload item2(testling, "Bob", RosterItemPayload::Remove); + dynamic_cast<RosterPayload*>(payload2.get())->addItem(item2); + controller.handleIQ(IQ::createRequest(IQ::Set, JID(), "eou", payload2)); + CPPUNIT_ASSERT(!xmppRoster->containsJID(testling)); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterControllerTest); + + |