diff --git a/tests/libtransport/gatewayresponder.cpp b/tests/libtransport/gatewayresponder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50e1f51dbccd398c1771bc42c6b71f225ce6b8a5 --- /dev/null +++ b/tests/libtransport/gatewayresponder.cpp @@ -0,0 +1,75 @@ +#include "gatewayresponder.h" +#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 GatewayResponderTest : public CPPUNIT_NS :: TestFixture, public BasicTest { + CPPUNIT_TEST_SUITE(GatewayResponderTest); + CPPUNIT_TEST(escape); + CPPUNIT_TEST(noEscapeEscaped); + CPPUNIT_TEST_SUITE_END(); + + public: + GatewayResponder *m_gatewayResponder; + + void setUp (void) { + setMeUp(); + connectUser(); + + m_gatewayResponder = new GatewayResponder(static_cast(component->getFrontend())->getIQRouter(), userManager); + m_gatewayResponder->start(); + + received.clear(); + } + + void tearDown (void) { + received.clear(); + disconnectUser(); + delete m_gatewayResponder; + tearMeDown(); + } + + void escape() { + boost::shared_ptr iq(new Swift::IQ(Swift::IQ::Set)); + iq->setTo("icq.localhost"); + iq->setFrom("user@localhost"); + iq->addPayload(boost::shared_ptr(new Swift::GatewayPayload(Swift::JID(), "", "a@b"))); + iq->setID("123"); + injectIQ(iq); + + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[0]))); + CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast(getStanza(received[0]))->getType()); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("a\\40b@localhost"), getStanza(received[0])->getPayload()->getJID().toString()); + } + + void noEscapeEscaped() { + boost::shared_ptr iq(new Swift::IQ(Swift::IQ::Set)); + iq->setTo("icq.localhost"); + iq->setFrom("user@localhost"); + iq->addPayload(boost::shared_ptr(new Swift::GatewayPayload(Swift::JID(), "", "a\\40b"))); + iq->setID("123"); + injectIQ(iq); + CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); + + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[0]))); + CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast(getStanza(received[0]))->getType()); + CPPUNIT_ASSERT(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT_EQUAL(std::string("a\\40b@localhost"), getStanza(received[0])->getPayload()->getJID().toString()); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION (GatewayResponderTest);