spectrum2/tests/libtransport/component.cpp

85 lines
2.9 KiB
C++
Raw Permalink Normal View History

2011-08-25 14:38:35 +02:00
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
2011-10-19 14:35:27 +02:00
#include <Swiften/Swiften.h>
2011-08-25 14:38:35 +02:00
#include <Swiften/EventLoop/DummyEventLoop.h>
#include <Swiften/Server/Server.h>
#include <Swiften/Network/DummyNetworkFactories.h>
#include <Swiften/Network/DummyConnectionServer.h>
2011-10-19 14:35:27 +02:00
#include "Swiften/Server/ServerStanzaChannel.h"
#include "Swiften/Server/ServerFromClientSession.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
2011-08-25 14:38:35 +02:00
2011-10-26 00:16:03 +02:00
#include "basictest.h"
2011-08-25 14:38:35 +02:00
2011-10-26 00:16:03 +02:00
using namespace Transport;
2011-08-25 14:38:35 +02:00
2011-10-26 00:16:03 +02:00
class ComponentTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
2011-08-25 14:38:35 +02:00
CPPUNIT_TEST_SUITE(ComponentTest);
2011-10-19 14:35:27 +02:00
CPPUNIT_TEST(handlePresenceWithNode);
2011-10-20 19:42:39 +02:00
CPPUNIT_TEST(handlePresenceWithoutNode);
2012-08-09 14:57:57 +02:00
CPPUNIT_TEST(handleErrorPresence);
2011-08-25 14:38:35 +02:00
CPPUNIT_TEST_SUITE_END();
public:
void setUp (void) {
2011-10-20 19:42:39 +02:00
onUserPresenceReceived = false;
onCapabilitiesReceived = false;
2011-08-25 14:38:35 +02:00
2011-10-26 00:16:03 +02:00
setMeUp();
2011-10-20 19:42:39 +02:00
component->onUserPresenceReceived.connect(boost::bind(&ComponentTest::handleUserPresenceReceived, this, _1));
component->getFrontend()->onCapabilitiesReceived.connect(boost::bind(&ComponentTest::handleUserDiscoInfoReceived, this, _1, _2));
2011-08-25 14:38:35 +02:00
}
void tearDown (void) {
2011-10-26 00:16:03 +02:00
tearMeDown();
2011-08-25 14:38:35 +02:00
}
void handleUserDiscoInfoReceived(const Swift::JID& jid, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::DiscoInfo> info) {
onCapabilitiesReceived = true;
2011-10-20 19:42:39 +02:00
}
void handleUserPresenceReceived(Swift::Presence::ref presence) {
onUserPresenceReceived = true;
}
2011-10-19 14:35:27 +02:00
void handlePresenceWithNode() {
2011-10-20 19:42:39 +02:00
Swift::Presence::ref response = Swift::Presence::create();
response->setTo("somebody@localhost");
response->setFrom("user@localhost/resource");
dynamic_cast<Swift::ServerStanzaChannel *>(static_cast<XMPPFrontend *>(component->getFrontend())->getStanzaChannel())->onPresenceReceived(response);
2011-10-20 19:42:39 +02:00
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
}
2012-08-09 14:57:57 +02:00
// 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<Swift::ServerStanzaChannel *>(static_cast<XMPPFrontend *>(component->getFrontend())->getStanzaChannel())->onPresenceReceived(response);
2012-08-09 14:57:57 +02:00
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
}
2011-10-20 19:42:39 +02:00
void handlePresenceWithoutNode() {
2011-10-19 14:35:27 +02:00
Swift::Presence::ref response = Swift::Presence::create();
response->setTo("localhost");
response->setFrom("user@localhost/resource");
dynamic_cast<Swift::ServerStanzaChannel *>(static_cast<XMPPFrontend *>(component->getFrontend())->getStanzaChannel())->onPresenceReceived(response);
2011-08-25 14:38:35 +02:00
2011-10-19 14:35:27 +02:00
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
2011-10-20 19:42:39 +02:00
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
CPPUNIT_ASSERT(onUserPresenceReceived);
}
2011-08-25 14:38:35 +02:00
private:
2011-10-20 19:42:39 +02:00
bool onUserPresenceReceived;
bool onCapabilitiesReceived;
2011-08-25 14:38:35 +02:00
};
CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest);