summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-12 18:12:47 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-12 18:12:47 (GMT)
commitfdd8755e2363e8d706a3d0bdc2e71f234abdf829 (patch)
tree470401f6f80873c4e1ce5af5cd30ab6837854d04 /Swiften/QA/NetworkTest
parent6a20be61e229255f93d55f13be3346525698237a (diff)
downloadswift-contrib-fdd8755e2363e8d706a3d0bdc2e71f234abdf829.zip
swift-contrib-fdd8755e2363e8d706a3d0bdc2e71f234abdf829.tar.bz2
Refactored DNS handling.
Connections now fallback on other DNS entries upon failure, taking into account SRV priorities.
Diffstat (limited to 'Swiften/QA/NetworkTest')
-rw-r--r--Swiften/QA/NetworkTest/DomainNameResolverTest.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
index 8968efd..cb812a1 100644
--- a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
+++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
@@ -2,7 +2,7 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "Swiften/Base/String.h"
-#include "Swiften/Network/DomainNameResolver.h"
+#include "Swiften/Network/PlatformDomainNameResolver.h"
#include "Swiften/Network/DomainNameResolveException.h"
using namespace Swift;
@@ -14,13 +14,14 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testResolve_Invalid);
//CPPUNIT_TEST(testResolve_IPv6);
CPPUNIT_TEST(testResolve_International);
+ CPPUNIT_TEST(testResolve_Localhost);
CPPUNIT_TEST_SUITE_END();
public:
DomainNameResolverTest() {}
void setUp() {
- resolver_ = new DomainNameResolver();
+ resolver_ = new PlatformDomainNameResolver();
}
void tearDown() {
@@ -28,17 +29,22 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
}
void testResolve_NoSRV() {
- HostAddressPort result = resolver_->resolve("xmpp.test.swift.im");
+ HostAddressPort result = resolver_->resolve("xmpp.test.swift.im")[0];
CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.0"), result.getAddress().toString());
CPPUNIT_ASSERT_EQUAL(5222, result.getPort());
}
void testResolve_SRV() {
- HostAddressPort result = resolver_->resolve("xmpp-srv.test.swift.im");
+ std::vector<HostAddressPort> result = resolver_->resolve("xmpp-srv.test.swift.im");
- CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.1"), result.getAddress().toString());
- CPPUNIT_ASSERT_EQUAL(5000, result.getPort());
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(result.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.1"), result[0].getAddress().toString());
+ CPPUNIT_ASSERT_EQUAL(5000, result[0].getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.3"), result[1].getAddress().toString());
+ CPPUNIT_ASSERT_EQUAL(5000, result[1].getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.2"), result[2].getAddress().toString());
+ CPPUNIT_ASSERT_EQUAL(5000, result[2].getPort());
}
void testResolve_Invalid() {
@@ -46,19 +52,25 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
}
void testResolve_IPv6() {
- HostAddressPort result = resolver_->resolve("xmpp-ipv6.test.swift.im");
+ HostAddressPort result = resolver_->resolve("xmpp-ipv6.test.swift.im")[0];
CPPUNIT_ASSERT_EQUAL(std::string("0000:0000:0000:0000:0000:ffff:0a00:0104"), result.getAddress().toString());
CPPUNIT_ASSERT_EQUAL(5222, result.getPort());
}
void testResolve_International() {
- HostAddressPort result = resolver_->resolve("tron\xc3\xa7on.test.swift.im");
+ HostAddressPort result = resolver_->resolve("tron\xc3\xa7on.test.swift.im")[0];
CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.3"), result.getAddress().toString());
CPPUNIT_ASSERT_EQUAL(5222, result.getPort());
}
+ void testResolve_Localhost() {
+ HostAddressPort result = resolver_->resolve("localhost")[0];
+ CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), result.getAddress().toString());
+ CPPUNIT_ASSERT_EQUAL(5222, result.getPort());
+ }
+
private:
- DomainNameResolver* resolver_;
+ PlatformDomainNameResolver* resolver_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(DomainNameResolverTest);