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/Network/UnitTest/ChainedConnectorTest.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/Network/UnitTest/ChainedConnectorTest.cpp')
-rw-r--r-- | Swiften/Network/UnitTest/ChainedConnectorTest.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Swiften/Network/UnitTest/ChainedConnectorTest.cpp b/Swiften/Network/UnitTest/ChainedConnectorTest.cpp index 3fad433..2d78cd7 100644 --- a/Swiften/Network/UnitTest/ChainedConnectorTest.cpp +++ b/Swiften/Network/UnitTest/ChainedConnectorTest.cpp @@ -7,61 +7,61 @@ #include <memory> #include <boost/bind.hpp> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/Network/ChainedConnector.h> #include <Swiften/Network/Connection.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/DomainNameResolveError.h> #include <Swiften/Network/DummyTimerFactory.h> #include <Swiften/Network/HostAddressPort.h> #include <Swiften/Network/StaticDomainNameResolver.h> using namespace Swift; class ChainedConnectorTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ChainedConnectorTest); CPPUNIT_TEST(testConnect_FirstConnectorSucceeds); CPPUNIT_TEST(testConnect_SecondConnectorSucceeds); CPPUNIT_TEST(testConnect_NoConnectorSucceeds); CPPUNIT_TEST(testConnect_NoDNS); CPPUNIT_TEST(testStop); CPPUNIT_TEST_SUITE_END(); public: void setUp() { error.reset(); - host = HostAddressPort(HostAddress("1.1.1.1"), 1234); + host = HostAddressPort(HostAddress::fromString("1.1.1.1").get(), 1234); eventLoop = new DummyEventLoop(); resolver = new StaticDomainNameResolver(eventLoop); resolver->addXMPPClientService("foo.com", host); connectionFactory1 = new MockConnectionFactory(eventLoop, 1); connectionFactory2 = new MockConnectionFactory(eventLoop, 2); timerFactory = new DummyTimerFactory(); } void tearDown() { delete timerFactory; delete connectionFactory2; delete connectionFactory1; delete resolver; delete eventLoop; } void testConnect_FirstConnectorSucceeds() { std::shared_ptr<ChainedConnector> testling(createConnector()); connectionFactory1->connects = true; connectionFactory2->connects = false; testling->start(); eventLoop->processEvents(); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size())); CPPUNIT_ASSERT(connections[0]); CPPUNIT_ASSERT_EQUAL(1, std::dynamic_pointer_cast<MockConnection>(connections[0])->id); CPPUNIT_ASSERT(!std::dynamic_pointer_cast<DomainNameResolveError>(error)); } |