diff --git a/tests/libtransport/component.cpp b/tests/libtransport/component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ccd2f6f71a9b32f69d9492a3b693629668d243dd --- /dev/null +++ b/tests/libtransport/component.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#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(handleErrorPresence); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp (void) { + onUserPresenceReceived = false; + onCapabilitiesReceived = false; + + setMeUp(); + component->onUserPresenceReceived.connect(boost::bind(&ComponentTest::handleUserPresenceReceived, this, _1)); + component->getFrontend()->onCapabilitiesReceived.connect(boost::bind(&ComponentTest::handleUserDiscoInfoReceived, this, _1, _2)); + } + + void tearDown (void) { + tearMeDown(); + } + + void handleUserDiscoInfoReceived(const Swift::JID& jid, boost::shared_ptr info) { + onCapabilitiesReceived = 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(static_cast(component->getFrontend())->getStanzaChannel())->onPresenceReceived(response); + + loop->processEvents(); + CPPUNIT_ASSERT_EQUAL(0, (int) received.size()); + } + + // Error presence should be ignored + void handleErrorPresence() { + Swift::Presence::ref response = Swift::Presence::create(); + response->setTo("localhost"); + response->setFrom("user@localhost/resource"); + response->setType(Swift::Presence::Error); + dynamic_cast(static_cast(component->getFrontend())->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(static_cast(component->getFrontend())->getStanzaChannel())->onPresenceReceived(response); + + loop->processEvents(); + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT(onUserPresenceReceived); + } + + private: + bool onUserPresenceReceived; + bool onCapabilitiesReceived; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest);