1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#include "transport/userregistry.h" #include "transport/config.h" #include "transport/storagebackend.h" #include "transport/user.h" #include "transport/transport.h" #include "transport/conversation.h" #include "transport/rosterresponder.h" #include "transport/usermanager.h" #include "transport/localbuddy.h" #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> #include <Swiften/Swiften.h> #include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/Server/Server.h> #include <Swiften/Network/DummyNetworkFactories.h> #include <Swiften/Network/DummyConnectionServer.h> #include "Swiften/Server/ServerStanzaChannel.h" #include "Swiften/Server/ServerFromClientSession.h" #include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" #include "basictest.h" using namespace Transport; class RosterResponderTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST_SUITE(RosterResponderTest); CPPUNIT_TEST(addEmptyBuddy); CPPUNIT_TEST_SUITE_END(); public: RosterResponder *m_rosterResponder; std::string m_buddy; void setUp (void) { m_buddy = "none"; setMeUp(); connectUser(); m_rosterResponder = new RosterResponder(component->getIQRouter(), userManager); m_rosterResponder->onBuddyAdded.connect(boost::bind(&RosterResponderTest::handleBuddyAdded, this, _1, _2)); m_rosterResponder->onBuddyRemoved.connect(boost::bind(&RosterResponderTest::handleBuddyRemoved, this, _1)); m_rosterResponder->onBuddyUpdated.connect(boost::bind(&RosterResponderTest::handleBuddyUpdated, this, _1, _2)); m_rosterResponder->start(); received.clear(); } void tearDown (void) { received.clear(); disconnectUser(); tearMeDown(); } void handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item) { m_buddy = buddy->getName(); } void handleBuddyRemoved(Buddy *buddy) { m_buddy = buddy->getName(); } void handleBuddyUpdated(Buddy *buddy, const Swift::RosterItemPayload &item) { m_buddy = buddy->getName(); } void addEmptyBuddy() { Swift::RosterPayload::ref p = Swift::RosterPayload::ref(new Swift::RosterPayload()); Swift::RosterItemPayload item; item.setJID("icq.localhost"); item.setSubscription(Swift::RosterItemPayload::Both); p->addItem(item); Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(p, "user@localhost", component->getIQRouter()); boost::shared_ptr<Swift::IQ> iq(new Swift::IQ(Swift::IQ::Set)); iq->setTo("icq.localhost"); iq->setFrom("user@localhost"); iq->addPayload(p); iq->setID("123"); injectIQ(iq); CPPUNIT_ASSERT_EQUAL(std::string("none"), m_buddy); } }; CPPUNIT_TEST_SUITE_REGISTRATION (RosterResponderTest);