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
#include "transport/userregistry.h" #include "transport/config.h" #include "transport/transport.h" #include "transport/conversation.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 ComponentTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST_SUITE(ComponentTest); CPPUNIT_TEST(handlePresenceWithNode); CPPUNIT_TEST(handlePresenceWithoutNode); CPPUNIT_TEST_SUITE_END(); public: void setUp (void) { onUserPresenceReceived = false; onUserDiscoInfoReceived = false; setMeUp(); component->onUserPresenceReceived.connect(boost::bind(&ComponentTest::handleUserPresenceReceived, this, _1)); component->onUserDiscoInfoReceived.connect(boost::bind(&ComponentTest::handleUserDiscoInfoReceived, this, _1, _2)); } void tearDown (void) { tearMeDown(); } void handleUserDiscoInfoReceived(const Swift::JID& jid, boost::shared_ptr<Swift::DiscoInfo> info) { onUserDiscoInfoReceived = true; } void handleUserPresenceReceived(Swift::Presence::ref presence) { onUserPresenceReceived = true; } void handlePresenceWithNode() { Swift::Presence::ref response = Swift::Presence::create(); response->setTo("somebody@localhost"); response->setFrom("user@localhost/resource"); dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response); loop->processEvents(); CPPUNIT_ASSERT_EQUAL(0, (int) received.size()); } void handlePresenceWithoutNode() { Swift::Presence::ref response = Swift::Presence::create(); response->setTo("localhost"); response->setFrom("user@localhost/resource"); dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response); loop->processEvents(); CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>()); CPPUNIT_ASSERT(onUserPresenceReceived); } private: bool onUserPresenceReceived; bool onUserDiscoInfoReceived; }; CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest);