diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-08 14:29:17 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-18 08:49:39 (GMT) |
commit | 43479ef719ea8fc6abbf654730b47c4583140508 (patch) | |
tree | c0a05a837b8988c0875fedb6161c08f3dcb2ffb0 /Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp | |
parent | c82f95fd431e702137d5f2e3dda4cf0ae424e837 (diff) | |
download | swift-43479ef719ea8fc6abbf654730b47c4583140508.zip swift-43479ef719ea8fc6abbf654730b47c4583140508.tar.bz2 |
Improve string to HostAddress conversion API
Previously HostAddress had a constructor which allowed
initialisation via a std::string. This initialisation can
fail and this is heavily used for checking whether a string
is a valid IP address.
This constructor is removed in this commit and replaced by
a static method HostAddress::fromString, taking a string and
returning an optional HostAddress. This clearly communicates
that the conversion can fail.
Test-Information:
./scons test=all passes on macOS 10.12.1.
Change-Id: Idaafee6f84010ce541c55f267ac77ad6ac8f02b4
Diffstat (limited to 'Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp')
-rw-r--r-- | Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp index 11b0eb5..6982c0c 100644 --- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp +++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp @@ -76,13 +76,13 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { } void testIPv4Server() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("127.0.0.1"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("127.0.0.1").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -95,13 +95,13 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { } void testIPv6Server() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::1"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::1").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -114,14 +114,14 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { } void testIPv4IPv6DualStackServer() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); // Test IPv4. BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -136,7 +136,7 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { // Test IPv6. clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -149,14 +149,14 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { } void testIPv6DualStackServerPeerAddress() { - BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress("::"), 9999, boostIOServiceThread_->getIOService(), eventLoop_); + BoostConnectionServer::ref testling = BoostConnectionServer::create(HostAddress::fromString("::").get(), 9999, boostIOServiceThread_->getIOService(), eventLoop_); testling->onNewConnection.connect(boost::bind(&BoostConnectionServerTest::handleNewConnection, this, _1)); testling->start(); // Test IPv4. BoostConnection::ref clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("127.0.0.1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("127.0.0.1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -165,7 +165,7 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); // The IPv4 localhost mapped to a IPv6 address is expected here. - CPPUNIT_ASSERT(HostAddress("::ffff:127.0.0.1") == remoteAddress_.get().getAddress()); + CPPUNIT_ASSERT(HostAddress::fromString("::ffff:127.0.0.1").get() == remoteAddress_.get().getAddress()); receivedNewConnection_ = false; connectFinished_ = false; @@ -174,7 +174,7 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { // Test IPv6. clientTestling = BoostConnection::create(boostIOServiceThread_->getIOService(), eventLoop_); clientTestling->onConnectFinished.connect(boost::bind(&BoostConnectionServerTest::handleConnectFinished, this, _1)); - clientTestling->connect(HostAddressPort(HostAddress("::1"), 9999)); + clientTestling->connect(HostAddressPort(HostAddress::fromString("::1").get(), 9999)); while (!connectFinished_) { Swift::sleep(10); @@ -183,7 +183,7 @@ class BoostConnectionServerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(true, receivedNewConnection_); // The IPv6 local host is expected here. - CPPUNIT_ASSERT(HostAddress("::1") == remoteAddress_.get().getAddress()); + CPPUNIT_ASSERT(HostAddress::fromString("::1").get() == remoteAddress_.get().getAddress()); testling->stop(); } |