summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/UnitTest/ConnectorTest.cpp')
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 05c6e28..af1ad4e 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.cpp
@@ -17,13 +17,16 @@ using namespace Swift;
class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ConnectorTest);
CPPUNIT_TEST(testConnect);
+ CPPUNIT_TEST(testConnect_NoSRVHost);
CPPUNIT_TEST(testConnect_NoHosts);
- CPPUNIT_TEST(testConnect_FirstHostFails);
- CPPUNIT_TEST(testConnect_AllHostsFail);
+ CPPUNIT_TEST(testConnect_FirstSRVHostFails);
+ CPPUNIT_TEST(testConnect_AllSRVHostsFailWithoutFallbackHost);
+ CPPUNIT_TEST(testConnect_AllSRVHostsFailWithFallbackHost);
+ CPPUNIT_TEST(testConnect_SRVAndFallbackHostsFail);
CPPUNIT_TEST_SUITE_END();
public:
- ConnectorTest() : host1(HostAddress("1.1.1.1"), 1234), host2(HostAddress("2.2.2.2"), 2345) {
+ ConnectorTest() : host1(HostAddress("1.1.1.1"), 1234), host2(HostAddress("2.2.2.2"), 2345), host3(HostAddress("3.3.3.3"), 5222) {
}
void setUp() {
@@ -42,6 +45,7 @@ class ConnectorTest : public CppUnit::TestFixture {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
+ resolver->addAddress("foo.com", host3.getAddress());
testling->start();
eventLoop->processEvents();
@@ -51,6 +55,18 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(host1 == *(connections[0]->hostAddressPort));
}
+ void testConnect_NoSRVHost() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addAddress("foo.com", host3.getAddress());
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(connections[0]);
+ CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
+ }
+
void testConnect_NoHosts() {
std::auto_ptr<Connector> testling(createConnector());
@@ -61,7 +77,7 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!connections[0]);
}
- void testConnect_FirstHostFails() {
+ void testConnect_FirstSRVHostFails() {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
@@ -74,7 +90,7 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(host2 == *(connections[0]->hostAddressPort));
}
- void testConnect_AllHostsFail() {
+ void testConnect_AllSRVHostsFailWithoutFallbackHost() {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
@@ -88,6 +104,36 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!connections[0]);
}
+ void testConnect_AllSRVHostsFailWithFallbackHost() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addXMPPClientService("foo.com", host2);
+ resolver->addAddress("foo.com", host3.getAddress());
+ 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]);
+ CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
+ }
+
+ void testConnect_SRVAndFallbackHostsFail() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addAddress("foo.com", host3.getAddress());
+ connectionFactory->failingPorts.push_back(host1);
+ connectionFactory->failingPorts.push_back(host3);
+
+ 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);
@@ -131,6 +177,7 @@ class ConnectorTest : public CppUnit::TestFixture {
private:
HostAddressPort host1;
HostAddressPort host2;
+ HostAddressPort host3;
DummyEventLoop* eventLoop;
StaticDomainNameResolver* resolver;
MockConnectionFactory* connectionFactory;