diff --git a/src/tests/component.cpp b/src/tests/component.cpp index ac02a5b049d76f29dde70536c3b69e965d8de3e2..8d4b3be9247c1f02b201c967eae888dfff9d2e4d 100644 --- a/src/tests/component.cpp +++ b/src/tests/component.cpp @@ -55,10 +55,13 @@ class TestingFactory : public Factory { class ComponentTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParserClient { CPPUNIT_TEST_SUITE(ComponentTest); CPPUNIT_TEST(handlePresenceWithNode); + CPPUNIT_TEST(handlePresenceWithoutNode); CPPUNIT_TEST_SUITE_END(); public: void setUp (void) { + onUserPresenceReceived = false; + onUserDiscoInfoReceived = false; std::istringstream ifs("service.server_mode = 1\n"); cfg = new Config(); cfg->load(ifs); @@ -71,6 +74,8 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParser userRegistry = new UserRegistry(cfg, factories); component = new Component(loop, factories, cfg, factory, userRegistry); + component->onUserPresenceReceived.connect(boost::bind(&ComponentTest::handleUserPresenceReceived, this, _1)); + component->onUserDiscoInfoReceived.connect(boost::bind(&ComponentTest::handleUserDiscoInfoReceived, this, _1, _2)); component->start(); payloadSerializers = new Swift::FullPayloadSerializerCollection(); @@ -101,6 +106,14 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParser received.clear(); } + void handleUserDiscoInfoReceived(const Swift::JID& jid, boost::shared_ptr info) { + onUserDiscoInfoReceived = true; + } + + void handleUserPresenceReceived(Swift::Presence::ref presence) { + onUserPresenceReceived = true; + } + void handleDataReceived(const Swift::SafeByteArray &data) { parser->parse(safeByteArrayToString(data)); } @@ -118,15 +131,35 @@ class ComponentTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParser } void handlePresenceWithNode() { + Swift::Presence::ref response = Swift::Presence::create(); + response->setTo("somebody@localhost"); + response->setFrom("user@localhost/resource"); + dynamic_cast(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(component->getStanzaChannel())->onPresenceReceived(response); loop->processEvents(); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT(onUserPresenceReceived); + } + + Swift::Stanza *getStanza(boost::shared_ptr element) { + Swift::Stanza *stanza = dynamic_cast(element.get()); + CPPUNIT_ASSERT(stanza); + return stanza; } private: + bool onUserPresenceReceived; + bool onUserDiscoInfoReceived; boost::shared_ptr serverFromClientSession; Swift::FullPayloadSerializerCollection* payloadSerializers; Swift::FullPayloadParserFactoryCollection* payloadParserFactories;