component tests
This commit is contained in:
parent
75bc454c85
commit
dd11e43325
7 changed files with 135 additions and 17 deletions
|
@ -117,7 +117,7 @@ class NetworkPluginServer {
|
|||
RosterResponder *m_rosterResponder;
|
||||
BlockResponder *m_blockResponder;
|
||||
Config *m_config;
|
||||
boost::shared_ptr<Swift::BoostConnectionServer> m_server;
|
||||
boost::shared_ptr<Swift::ConnectionServer> m_server;
|
||||
std::list<Backend *> m_clients;
|
||||
Swift::Timer::ref m_pingTimer;
|
||||
Swift::Timer::ref m_collectTimer;
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace Transport {
|
|||
/// - service.port
|
||||
/// - service.server_mode
|
||||
/// \param factory Transport Abstract factory used to create basic transport structures.
|
||||
Component(Swift::EventLoop *loop, Swift::BoostNetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry = NULL);
|
||||
Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry = NULL);
|
||||
|
||||
/// Component destructor.
|
||||
~Component();
|
||||
|
@ -121,7 +121,7 @@ namespace Transport {
|
|||
/// Returns Swift::NetworkFactories which can be used to create new connections.
|
||||
|
||||
/// \return Swift::NetworkFactories which can be used to create new connections.
|
||||
Swift::BoostNetworkFactories *getNetworkFactories() { return m_factories; }
|
||||
Swift::NetworkFactories *getNetworkFactories() { return m_factories; }
|
||||
|
||||
/// Returns Transport Factory used to create basic Transport components.
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace Transport {
|
|||
// void handleDiscoInfoResponse(boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid);
|
||||
void handleCapsChanged(const Swift::JID& jid);
|
||||
|
||||
Swift::BoostNetworkFactories *m_factories;
|
||||
Swift::NetworkFactories *m_factories;
|
||||
Swift::Component *m_component;
|
||||
Swift::Server *m_server;
|
||||
Swift::Timer::ref m_reconnectTimer;
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
#include "transport/admininterface.h"
|
||||
#include "Swiften/EventLoop/SimpleEventLoop.h"
|
||||
#include "sys/signal.h"
|
||||
#include "log4cxx/logger.h"
|
||||
#include "log4cxx/patternlayout.h"
|
||||
#include "log4cxx/propertyconfigurator.h"
|
||||
#include "log4cxx/consoleappender.h"
|
||||
|
||||
using namespace log4cxx;
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
|
@ -74,6 +80,14 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (CONFIG_STRING(&config, "logging.config").empty()) {
|
||||
LoggerPtr root = log4cxx::Logger::getRootLogger();
|
||||
root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
|
||||
}
|
||||
else {
|
||||
log4cxx::PropertyConfigurator::configure(CONFIG_STRING(&config, "logging.config"));
|
||||
}
|
||||
|
||||
Swift::SimpleEventLoop eventLoop;
|
||||
|
||||
Swift::BoostNetworkFactories *factories = new Swift::BoostNetworkFactories(&eventLoop);
|
||||
|
|
|
@ -202,7 +202,7 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
|
|||
m_blockResponder->onBlockToggled.connect(boost::bind(&NetworkPluginServer::handleBlockToggled, this, _1));
|
||||
m_blockResponder->start();
|
||||
|
||||
m_server = Swift::BoostConnectionServer::create(Swift::HostAddress(CONFIG_STRING(m_config, "service.backend_host")), boost::lexical_cast<int>(CONFIG_STRING(m_config, "service.backend_port")), component->getNetworkFactories()->getIOServiceThread()->getIOService(), component->m_loop);
|
||||
m_server = component->getNetworkFactories()->getConnectionServerFactory()->createConnectionServer(Swift::HostAddress(CONFIG_STRING(m_config, "service.backend_host")), boost::lexical_cast<int>(CONFIG_STRING(m_config, "service.backend_port")));
|
||||
m_server->onNewConnection.connect(boost::bind(&NetworkPluginServer::handleNewClientConnection, this, _1));
|
||||
m_server->start();
|
||||
|
||||
|
|
100
src/tests/component.cpp
Normal file
100
src/tests/component.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
#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/EventLoop/DummyEventLoop.h>
|
||||
#include <Swiften/Server/Server.h>
|
||||
#include <Swiften/Network/DummyNetworkFactories.h>
|
||||
#include <Swiften/Network/DummyConnectionServer.h>
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
class TestingConversation : public Conversation {
|
||||
public:
|
||||
TestingConversation(ConversationManager *conversationManager, const std::string &legacyName, bool muc = false) : Conversation(conversationManager, legacyName, muc) {
|
||||
}
|
||||
|
||||
// Called when there's new message to legacy network from XMPP network
|
||||
void sendMessage(boost::shared_ptr<Swift::Message> &message) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class TestingFactory : public Factory {
|
||||
public:
|
||||
TestingFactory() {
|
||||
}
|
||||
|
||||
// Creates new conversation (NetworkConversation in this case)
|
||||
Conversation *createConversation(ConversationManager *conversationManager, const std::string &legacyName) {
|
||||
Conversation *nc = new TestingConversation(conversationManager, legacyName);
|
||||
return nc;
|
||||
}
|
||||
|
||||
// Creates new LocalBuddy
|
||||
Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) {
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id);
|
||||
buddy->setAlias(buddyInfo.alias);
|
||||
buddy->setName(buddyInfo.legacyName);
|
||||
buddy->setSubscription(buddyInfo.subscription);
|
||||
buddy->setGroups(buddyInfo.groups);
|
||||
buddy->setFlags((BuddyFlag) buddyInfo.flags);
|
||||
if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end())
|
||||
buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s);
|
||||
return buddy;
|
||||
}
|
||||
};
|
||||
|
||||
class ComponentTest : public CPPUNIT_NS :: TestFixture {
|
||||
CPPUNIT_TEST_SUITE(ComponentTest);
|
||||
CPPUNIT_TEST(presence);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp (void) {
|
||||
std::istringstream ifs("service.server_mode = 1\n");
|
||||
cfg = new Config();
|
||||
cfg->load(ifs);
|
||||
|
||||
factory = new TestingFactory();
|
||||
|
||||
loop = new Swift::DummyEventLoop();
|
||||
factories = new Swift::DummyNetworkFactories(loop);
|
||||
|
||||
userRegistry = new UserRegistry(cfg, factories);
|
||||
|
||||
component = new Component(loop, factories, cfg, factory, userRegistry);
|
||||
component->start();
|
||||
|
||||
loop->processEvents();
|
||||
}
|
||||
|
||||
void tearDown (void) {
|
||||
delete component;
|
||||
delete userRegistry;
|
||||
delete factories;
|
||||
delete factory;
|
||||
delete loop;
|
||||
delete cfg;
|
||||
received.clear();
|
||||
}
|
||||
|
||||
void presence() {
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
UserRegistry *userRegistry;
|
||||
Config *cfg;
|
||||
Swift::Server *server;
|
||||
Swift::DummyNetworkFactories *factories;
|
||||
Swift::DummyEventLoop *loop;
|
||||
TestingFactory *factory;
|
||||
Component *component;
|
||||
std::vector<std::string> received;
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (ComponentTest);
|
|
@ -89,10 +89,21 @@ class UserRegistryTest : public CPPUNIT_NS :: TestFixture {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string(""), userRegistry->getUserPassword("unknown@localhost"));
|
||||
}
|
||||
|
||||
void bindSession(boost::shared_ptr<Swift::Connection> conn) {
|
||||
std::vector<std::string> &received = conn == client1 ? received1 : received2;
|
||||
|
||||
send(conn, "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
|
||||
CPPUNIT_ASSERT(received[0].find("<?xml version=\"1.0\"?>") == 0);
|
||||
CPPUNIT_ASSERT(received[1].find("urn:ietf:params:xml:ns:xmpp-bind") != std::string::npos);
|
||||
CPPUNIT_ASSERT(received[1].find("urn:ietf:params:xml:ns:xmpp-session") != std::string::npos);
|
||||
|
||||
}
|
||||
|
||||
void handleDataReceived(const Swift::SafeByteArray &data, boost::shared_ptr<Swift::Connection> conn) {
|
||||
if (conn == client1) {
|
||||
received1.push_back(safeByteArrayToString(data));
|
||||
// std::cout << received1.back() << "\n";
|
||||
std::cout << received1.back() << "\n";
|
||||
}
|
||||
else {
|
||||
received2.push_back(safeByteArrayToString(data));
|
||||
|
@ -116,9 +127,10 @@ class UserRegistryTest : public CPPUNIT_NS :: TestFixture {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string(""), userRegistry->getUserPassword("username@localhost"));
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received1.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"></success>"), received1[0]);
|
||||
received1.clear();
|
||||
|
||||
bindSession(client1);
|
||||
|
||||
// TODO: resource binding
|
||||
// AHVzZXJuYW1lMgB0ZXN0 username2:test
|
||||
}
|
||||
|
||||
void loginInvalidPassword() {
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Transport {
|
|||
static LoggerPtr logger = Logger::getLogger("Component");
|
||||
static LoggerPtr logger_xml = Logger::getLogger("Component.XML");
|
||||
|
||||
Component::Component(Swift::EventLoop *loop, Swift::BoostNetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry) {
|
||||
Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry) {
|
||||
m_component = NULL;
|
||||
m_userRegistry = NULL;
|
||||
m_server = NULL;
|
||||
|
@ -61,14 +61,6 @@ Component::Component(Swift::EventLoop *loop, Swift::BoostNetworkFactories *facto
|
|||
m_loop = loop;
|
||||
m_userRegistry = userRegistry;
|
||||
|
||||
if (CONFIG_STRING(m_config, "logging.config").empty()) {
|
||||
LoggerPtr root = Logger::getRootLogger();
|
||||
root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
|
||||
}
|
||||
else {
|
||||
log4cxx::PropertyConfigurator::configure(CONFIG_STRING(m_config, "logging.config"));
|
||||
}
|
||||
|
||||
m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
|
||||
|
||||
m_factories = factories;
|
||||
|
|
Loading…
Add table
Reference in a new issue