diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-12-17 15:25:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-12-17 16:11:19 (GMT) |
commit | bdb8ace202917809c5492aa37921e0ffd0354730 (patch) | |
tree | 52e93ebf3a555c690086b1bce0b2e01c1bf943b6 /Swiften/Network/UnitTest | |
parent | e32059da8bffc67806862bf78f762d67fb3e4848 (diff) | |
download | swift-bdb8ace202917809c5492aa37921e0ffd0354730.zip swift-bdb8ace202917809c5492aa37921e0ffd0354730.tar.bz2 |
Added eclipse project file.
Diffstat (limited to 'Swiften/Network/UnitTest')
-rw-r--r-- | Swiften/Network/UnitTest/ConnectorTest.cpp | 57 |
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; |