diff options
Diffstat (limited to 'Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp')
-rw-r--r-- | Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp b/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp index c1d53c6..0b7fd6c 100644 --- a/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp @@ -19,14 +19,13 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture CPPUNIT_TEST(testRemove); CPPUNIT_TEST_SUITE_END(); - DummyIQChannel* channel_; - IQRouter* router_; public: XMPPRosterControllerTest() {} void setUp() { channel_ = new DummyIQChannel(); router_ = new IQRouter(channel_); + xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster()); } void tearDown() { @@ -35,52 +34,45 @@ class XMPPRosterControllerTest : public CppUnit::TestFixture } 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)); + XMPPRosterController controller(router_, xmppRoster_); + + boost::shared_ptr<RosterPayload> payload(new RosterPayload()); + payload->addItem(RosterItemPayload(JID("foo@bar.com"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "eou", payload)); + + CPPUNIT_ASSERT(xmppRoster_->containsJID(JID("foo@bar.com"))); + CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com"))); } 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)); + XMPPRosterController controller(router_, xmppRoster_); + boost::shared_ptr<RosterPayload> payload1(new RosterPayload()); + payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); + + boost::shared_ptr<RosterPayload> payload2(new RosterPayload()); + payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob2", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); + + CPPUNIT_ASSERT_EQUAL(String("Bob2"), xmppRoster_->getNameForJID(JID("foo@bar"))); } 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)); + XMPPRosterController controller(router_, xmppRoster_); + boost::shared_ptr<RosterPayload> payload1(new RosterPayload()); + payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); + + boost::shared_ptr<RosterPayload> payload2(new RosterPayload()); + payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Remove)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); + CPPUNIT_ASSERT(!xmppRoster_->containsJID(JID("foo@bar"))); } + private: + DummyIQChannel* channel_; + IQRouter* router_; + boost::shared_ptr<XMPPRoster> xmppRoster_; }; CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterControllerTest); |