summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-04-07 19:20:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-04-07 19:20:54 (GMT)
commit2086abd85c97ee4e03f6d7b266076c6607012243 (patch)
treef9baa8c2a9ca9c83aa64029142396f561d7f2cb0 /Swiften/Network/UnitTest
parent8fc68f601b92dc4d0fa378c1d9fa2114e379f7ce (diff)
downloadswift-contrib-2086abd85c97ee4e03f6d7b266076c6607012243.zip
swift-contrib-2086abd85c97ee4e03f6d7b266076c6607012243.tar.bz2
Support fallback multiple host addresses when connecting.
Resolves: #305
Diffstat (limited to 'Swiften/Network/UnitTest')
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 663011c..2a2ab41 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.cpp
@@ -18,6 +18,7 @@ using namespace Swift;
class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ConnectorTest);
CPPUNIT_TEST(testConnect);
+ CPPUNIT_TEST(testConnect_FirstAddressHostFails);
CPPUNIT_TEST(testConnect_NoSRVHost);
CPPUNIT_TEST(testConnect_NoHosts);
CPPUNIT_TEST(testConnect_FirstSRVHostFails);
@@ -73,6 +74,24 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
}
+ void testConnect_FirstAddressHostFails() {
+ std::auto_ptr<Connector> testling(createConnector());
+
+ HostAddress address1("1.1.1.1");
+ HostAddress address2("2.2.2.2");
+ resolver->addXMPPClientService("foo.com", "host-foo.com", 1234);
+ resolver->addAddress("host-foo.com", address1);
+ resolver->addAddress("host-foo.com", address2);
+ connectionFactory->failingPorts.push_back(HostAddressPort(address1, 1234));
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(connections[0]);
+ CPPUNIT_ASSERT(HostAddressPort(address2, 1234) == *(connections[0]->hostAddressPort));
+ }
+
void testConnect_NoHosts() {
std::auto_ptr<Connector> testling(createConnector());
@@ -207,7 +226,8 @@ class ConnectorTest : public CppUnit::TestFixture {
void connect(const HostAddressPort& address) {
hostAddressPort = address;
if (isResponsive) {
- MainEventLoop::postEvent(boost::bind(boost::ref(onConnectFinished), std::find(failingPorts.begin(), failingPorts.end(), address) != failingPorts.end()));
+ bool fail = std::find(failingPorts.begin(), failingPorts.end(), address) != failingPorts.end();
+ MainEventLoop::postEvent(boost::bind(boost::ref(onConnectFinished), fail));
}
}