summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-12-02 20:42:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-12-03 08:09:01 (GMT)
commit5608da36a3a319070494d5a70ff984e7c172186e (patch)
tree2c44df5a9f0ea0ab180763222e54aece5dc65c93 /Swiften/Network/UnitTest
parent6e50bd41dc3f11815a40dfef500dc0d61ea5d737 (diff)
downloadswift-5608da36a3a319070494d5a70ff984e7c172186e.zip
swift-5608da36a3a319070494d5a70ff984e7c172186e.tar.bz2
DNS querying is now asynchronous.
This means we can now move them to a separate thread.
Diffstat (limited to 'Swiften/Network/UnitTest')
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 32893d8..05c6e28 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.cpp
@@ -1,128 +1,128 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <boost/optional.hpp>
#include <boost/bind.hpp>
#include "Swiften/Network/Connector.h"
#include "Swiften/Network/Connection.h"
#include "Swiften/Network/ConnectionFactory.h"
#include "Swiften/Network/HostAddressPort.h"
#include "Swiften/Network/StaticDomainNameResolver.h"
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/EventLoop/DummyEventLoop.h"
using namespace Swift;
class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ConnectorTest);
CPPUNIT_TEST(testConnect);
CPPUNIT_TEST(testConnect_NoHosts);
CPPUNIT_TEST(testConnect_FirstHostFails);
CPPUNIT_TEST(testConnect_AllHostsFail);
CPPUNIT_TEST_SUITE_END();
public:
ConnectorTest() : host1(HostAddress("1.1.1.1"), 1234), host2(HostAddress("2.2.2.2"), 2345) {
}
void setUp() {
eventLoop = new DummyEventLoop();
resolver = new StaticDomainNameResolver();
connectionFactory = new MockConnectionFactory();
}
void tearDown() {
delete connectionFactory;
delete resolver;
delete eventLoop;
}
void testConnect() {
std::auto_ptr<Connector> testling(createConnector());
- resolver->addDomain("foo.com", host1);
- resolver->addDomain("foo.com", host2);
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addXMPPClientService("foo.com", host2);
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(connections[0]);
CPPUNIT_ASSERT(host1 == *(connections[0]->hostAddressPort));
}
void testConnect_NoHosts() {
std::auto_ptr<Connector> testling(createConnector());
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(!connections[0]);
}
void testConnect_FirstHostFails() {
std::auto_ptr<Connector> testling(createConnector());
- resolver->addDomain("foo.com", host1);
- resolver->addDomain("foo.com", host2);
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addXMPPClientService("foo.com", host2);
connectionFactory->failingPorts.push_back(host1);
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(host2 == *(connections[0]->hostAddressPort));
}
void testConnect_AllHostsFail() {
std::auto_ptr<Connector> testling(createConnector());
- resolver->addDomain("foo.com", host1);
- resolver->addDomain("foo.com", host2);
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addXMPPClientService("foo.com", host2);
connectionFactory->failingPorts.push_back(host1);
connectionFactory->failingPorts.push_back(host2);
testling->start();
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
CPPUNIT_ASSERT(!connections[0]);
}
private:
Connector* createConnector() {
Connector* connector = new Connector("foo.com", resolver, connectionFactory);
connector->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1));
return connector;
}
void handleConnectorFinished(boost::shared_ptr<Connection> connection) {
boost::shared_ptr<MockConnection> c(boost::dynamic_pointer_cast<MockConnection>(connection));
if (connection) {
assert(c);
}
connections.push_back(c);
}
struct MockConnection : public Connection {
public:
MockConnection(const std::vector<HostAddressPort>& failingPorts) : failingPorts(failingPorts) {}
void listen() { assert(false); }
void connect(const HostAddressPort& address) {
hostAddressPort = address;
MainEventLoop::postEvent(boost::bind(boost::ref(onConnectFinished), std::find(failingPorts.begin(), failingPorts.end(), address) != failingPorts.end()));
}
void disconnect() { assert(false); }
void write(const ByteArray&) { assert(false); }
boost::optional<HostAddressPort> hostAddressPort;
std::vector<HostAddressPort> failingPorts;
};
struct MockConnectionFactory : public ConnectionFactory {
boost::shared_ptr<Connection> createConnection() {
return boost::shared_ptr<Connection>(new MockConnection(failingPorts));
}
std::vector<HostAddressPort> failingPorts;