face: move createChannel overloads that take strings to unit tests
They are used only there.
Change-Id: I0c70221bbcad36024223cc6e3c929b9c08b683c0
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 1546d24..66335c5 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -174,38 +174,20 @@
shared_ptr<TcpChannel>
TcpFactory::createChannel(const tcp::Endpoint& endpoint)
{
- auto channel = findChannel(endpoint);
- if (channel)
- return channel;
+ auto it = m_channels.find(endpoint);
+ if (it != m_channels.end())
+ return it->second;
- channel = make_shared<TcpChannel>(endpoint);
+ auto channel = make_shared<TcpChannel>(endpoint);
m_channels[endpoint] = channel;
return channel;
}
-shared_ptr<TcpChannel>
-TcpFactory::createChannel(const std::string& localIp, const std::string& localPort)
-{
- tcp::Endpoint endpoint(ndn::ip::addressFromString(localIp),
- boost::lexical_cast<uint16_t>(localPort));
- return createChannel(endpoint);
-}
-
std::vector<shared_ptr<const Channel>>
TcpFactory::getChannels() const
{
return getChannelsFromMap(m_channels);
}
-shared_ptr<TcpChannel>
-TcpFactory::findChannel(const tcp::Endpoint& localEndpoint) const
-{
- auto i = m_channels.find(localEndpoint);
- if (i != m_channels.end())
- return i->second;
- else
- return nullptr;
-}
-
} // namespace face
} // namespace nfd
diff --git a/daemon/face/tcp-factory.hpp b/daemon/face/tcp-factory.hpp
index fb4735d..f67de85 100644
--- a/daemon/face/tcp-factory.hpp
+++ b/daemon/face/tcp-factory.hpp
@@ -68,32 +68,10 @@
shared_ptr<TcpChannel>
createChannel(const tcp::Endpoint& localEndpoint);
- /**
- * \brief Create TCP-based channel using specified IP address and port number
- *
- * This method is just a helper that converts the string representation of \p localIp
- * and \p localPort to tcp::Endpoint and calls the other createChannel overload.
- *
- * \return always a valid pointer to a UdpChannel object, an exception
- * is thrown if it cannot be created.
- */
- shared_ptr<TcpChannel>
- createChannel(const std::string& localIp, const std::string& localPort);
-
std::vector<shared_ptr<const Channel>>
getChannels() const override;
private:
- /**
- * \brief Look up TcpChannel using specified local endpoint
- *
- * \return shared pointer to the existing TcpChannel object
- * or empty shared pointer when such channel does not exist
- */
- shared_ptr<TcpChannel>
- findChannel(const tcp::Endpoint& localEndpoint) const;
-
-private:
std::map<tcp::Endpoint, shared_ptr<TcpChannel>> m_channels;
};
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 57be339..7477fb0 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -284,15 +284,6 @@
return channel;
}
-shared_ptr<UdpChannel>
-UdpFactory::createChannel(const std::string& localIp, const std::string& localPort,
- time::nanoseconds idleTimeout)
-{
- udp::Endpoint endpoint(ndn::ip::addressFromString(localIp),
- boost::lexical_cast<uint16_t>(localPort));
- return createChannel(endpoint, idleTimeout);
-}
-
std::vector<shared_ptr<const Channel>>
UdpFactory::getChannels() const
{
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index db8d666..55556ab 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -89,24 +89,6 @@
createChannel(const udp::Endpoint& localEndpoint,
time::nanoseconds idleTimeout);
- /**
- * \brief Create UDP-based channel using specified IP address and port number
- *
- * This method is just a helper that converts the string representation of \p localIp
- * and \p localPort to udp::Endpoint and calls the other createChannel overload.
- *
- * If \p localIp is an IPv6 address of a specific device, it must be in the form
- * <tt>[ip address]%[interface name]</tt>, e.g. <tt>"fe80::5e96:9dff:fe7d:9c8d%en1"</tt>.
- * Otherwise, you can use <tt>"::"</tt>.
- *
- * \return always a valid pointer to a UdpChannel object, an exception
- * is thrown if it cannot be created.
- * \throw UdpFactory::Error
- */
- shared_ptr<UdpChannel>
- createChannel(const std::string& localIp, const std::string& localPort,
- time::nanoseconds idleTimeout = time::seconds(600));
-
std::vector<shared_ptr<const Channel>>
getChannels() const override;
diff --git a/daemon/face/websocket-factory.cpp b/daemon/face/websocket-factory.cpp
index 6a87563..e5317a5 100644
--- a/daemon/face/websocket-factory.cpp
+++ b/daemon/face/websocket-factory.cpp
@@ -25,8 +25,6 @@
#include "websocket-factory.hpp"
-#include <ndn-cxx/net/address-converter.hpp>
-
namespace nfd {
namespace face {
@@ -130,39 +128,21 @@
shared_ptr<WebSocketChannel>
WebSocketFactory::createChannel(const websocket::Endpoint& endpoint)
{
- auto channel = findChannel(endpoint);
- if (channel)
- return channel;
+ auto it = m_channels.find(endpoint);
+ if (it != m_channels.end())
+ return it->second;
- channel = make_shared<WebSocketChannel>(endpoint);
+ auto channel = make_shared<WebSocketChannel>(endpoint);
m_channels[endpoint] = channel;
return channel;
}
-shared_ptr<WebSocketChannel>
-WebSocketFactory::createChannel(const std::string& localIp, const std::string& localPort)
-{
- websocket::Endpoint endpoint(ndn::ip::addressFromString(localIp),
- boost::lexical_cast<uint16_t>(localPort));
- return createChannel(endpoint);
-}
-
std::vector<shared_ptr<const Channel>>
WebSocketFactory::getChannels() const
{
return getChannelsFromMap(m_channels);
}
-shared_ptr<WebSocketChannel>
-WebSocketFactory::findChannel(const websocket::Endpoint& endpoint) const
-{
- auto i = m_channels.find(endpoint);
- if (i != m_channels.end())
- return i->second;
- else
- return nullptr;
-}
-
} // namespace face
} // namespace nfd
diff --git a/daemon/face/websocket-factory.hpp b/daemon/face/websocket-factory.hpp
index a8c4600..21eb6fc 100644
--- a/daemon/face/websocket-factory.hpp
+++ b/daemon/face/websocket-factory.hpp
@@ -71,29 +71,10 @@
shared_ptr<WebSocketChannel>
createChannel(const websocket::Endpoint& localEndpoint);
- /**
- * \brief Create WebSocket-based channel using specified IP address and port number
- *
- * This method is just a helper that converts a string representation of localIp and port to
- * websocket::Endpoint and calls the other createChannel overload.
- */
- shared_ptr<WebSocketChannel>
- createChannel(const std::string& localIp, const std::string& localPort);
-
std::vector<shared_ptr<const Channel>>
getChannels() const override;
private:
- /**
- * \brief Look up WebSocketChannel using specified local endpoint
- *
- * \returns shared pointer to the existing WebSocketChannel object
- * or empty shared pointer when such channel does not exist
- */
- shared_ptr<WebSocketChannel>
- findChannel(const websocket::Endpoint& endpoint) const;
-
-private:
std::map<websocket::Endpoint, shared_ptr<WebSocketChannel>> m_channels;
};
diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp
index c6fee2f..39567d6 100644
--- a/tests/daemon/face/tcp-factory.t.cpp
+++ b/tests/daemon/face/tcp-factory.t.cpp
@@ -29,11 +29,23 @@
#include "factory-test-common.hpp"
#include "tests/limited-io.hpp"
+#include <ndn-cxx/net/address-converter.hpp>
+
namespace nfd {
namespace face {
namespace tests {
-using TcpFactoryFixture = FaceSystemFactoryFixture<TcpFactory>;
+class TcpFactoryFixture : public FaceSystemFactoryFixture<TcpFactory>
+{
+protected:
+ shared_ptr<TcpChannel>
+ createChannel(const std::string& localIp, const std::string& localPort)
+ {
+ tcp::Endpoint endpoint(ndn::ip::addressFromString(localIp),
+ boost::lexical_cast<uint16_t>(localPort));
+ return factory.createChannel(endpoint);
+ }
+};
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, TcpFactoryFixture)
@@ -134,23 +146,23 @@
BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
std::set<std::string> expected;
- expected.insert(factory.createChannel("127.0.0.1", "20070")->getUri().toString());
- expected.insert(factory.createChannel("127.0.0.1", "20071")->getUri().toString());
- expected.insert(factory.createChannel("::1", "20071")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString());
+ expected.insert(createChannel("::1", "20071")->getUri().toString());
checkChannelListEqual(factory, expected);
}
BOOST_AUTO_TEST_CASE(CreateChannel)
{
- auto channel1 = factory.createChannel("127.0.0.1", "20070");
- auto channel1a = factory.createChannel("127.0.0.1", "20070");
+ auto channel1 = createChannel("127.0.0.1", "20070");
+ auto channel1a = createChannel("127.0.0.1", "20070");
BOOST_CHECK_EQUAL(channel1, channel1a);
BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070");
- auto channel2 = factory.createChannel("127.0.0.1", "20071");
+ auto channel2 = createChannel("127.0.0.1", "20071");
BOOST_CHECK_NE(channel1, channel2);
- auto channel3 = factory.createChannel("::1", "20071");
+ auto channel3 = createChannel("::1", "20071");
BOOST_CHECK_NE(channel2, channel3);
BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071");
}
@@ -165,7 +177,7 @@
false,
{CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
- factory.createChannel("127.0.0.1", "20071");
+ createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("tcp4://127.0.0.1:6363"),
@@ -202,7 +214,7 @@
BOOST_AUTO_TEST_CASE(UnsupportedCreateFace)
{
- factory.createChannel("127.0.0.1", "20071");
+ createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("tcp4://127.0.0.1:20072"),
@@ -259,7 +271,7 @@
BOOST_FIXTURE_TEST_CASE(CreateFaceTimeout, CreateFaceTimeoutFixture)
{
- factory.createChannel("0.0.0.0", "20070");
+ createChannel("0.0.0.0", "20070");
factory.createFace({FaceUri("tcp4://192.0.2.1:20070"), {},
ndn::nfd::FACE_PERSISTENCY_PERSISTENT, false, false},
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index 2747fa8..ce4d17e 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -31,12 +31,23 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/range/algorithm/count_if.hpp>
+#include <ndn-cxx/net/address-converter.hpp>
namespace nfd {
namespace face {
namespace tests {
-using UdpFactoryFixture = FaceSystemFactoryFixture<UdpFactory>;
+class UdpFactoryFixture : public FaceSystemFactoryFixture<UdpFactory>
+{
+protected:
+ shared_ptr<UdpChannel>
+ createChannel(const std::string& localIp, const std::string& localPort)
+ {
+ udp::Endpoint endpoint(ndn::ip::addressFromString(localIp),
+ boost::lexical_cast<uint16_t>(localPort));
+ return factory.createChannel(endpoint, time::minutes(5));
+ }
+};
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture)
@@ -495,28 +506,28 @@
BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
std::set<std::string> expected;
- expected.insert(factory.createChannel("127.0.0.1", "20070")->getUri().toString());
- expected.insert(factory.createChannel("127.0.0.1", "20071")->getUri().toString());
- expected.insert(factory.createChannel("::1", "20071")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString());
+ expected.insert(createChannel("::1", "20071")->getUri().toString());
checkChannelListEqual(factory, expected);
}
BOOST_AUTO_TEST_CASE(CreateChannel)
{
- auto channel1 = factory.createChannel("127.0.0.1", "20070");
- auto channel1a = factory.createChannel("127.0.0.1", "20070");
+ auto channel1 = createChannel("127.0.0.1", "20070");
+ auto channel1a = createChannel("127.0.0.1", "20070");
BOOST_CHECK_EQUAL(channel1, channel1a);
BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
- auto channel2 = factory.createChannel("127.0.0.1", "20071");
+ auto channel2 = createChannel("127.0.0.1", "20071");
BOOST_CHECK_NE(channel1, channel2);
- auto channel3 = factory.createChannel("::1", "20071");
+ auto channel3 = createChannel("::1", "20071");
BOOST_CHECK_NE(channel2, channel3);
BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071");
// createChannel with multicast address
- BOOST_CHECK_EXCEPTION(factory.createChannel("224.0.0.1", "20070"), UdpFactory::Error,
+ BOOST_CHECK_EXCEPTION(createChannel("224.0.0.1", "20070"), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
"createChannel is only for unicast channels. The provided endpoint "
@@ -525,7 +536,7 @@
// createChannel with a local endpoint that has already been allocated for a UDP multicast face
auto multicastFace = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20072");
- BOOST_CHECK_EXCEPTION(factory.createChannel("127.0.0.1", "20072"), UdpFactory::Error,
+ BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", "20072"), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
"Cannot create the requested UDP unicast channel, local "
@@ -540,7 +551,7 @@
BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
// createMulticastFace with a local endpoint that is already used by a channel
- auto channel = factory.createChannel("127.0.0.1", "20071");
+ auto channel = createChannel("127.0.0.1", "20071");
BOOST_CHECK_EXCEPTION(factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20071"), UdpFactory::Error,
[] (const UdpFactory::Error& e) {
return strcmp(e.what(),
@@ -595,7 +606,7 @@
false,
{CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
- factory.createChannel("127.0.0.1", "20071");
+ createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("udp4://127.0.0.1:6363"),
@@ -633,7 +644,7 @@
BOOST_AUTO_TEST_CASE(UnsupportedCreateFace)
{
- factory.createChannel("127.0.0.1", "20071");
+ createChannel("127.0.0.1", "20071");
createFace(factory,
FaceUri("udp4://127.0.0.1:20072"),
diff --git a/tests/daemon/face/websocket-factory.t.cpp b/tests/daemon/face/websocket-factory.t.cpp
index 380646e..d813931 100644
--- a/tests/daemon/face/websocket-factory.t.cpp
+++ b/tests/daemon/face/websocket-factory.t.cpp
@@ -28,13 +28,23 @@
#include "face-system-fixture.hpp"
#include "factory-test-common.hpp"
+#include <ndn-cxx/net/address-converter.hpp>
+
namespace nfd {
namespace face {
namespace tests {
-namespace ip = boost::asio::ip;
-
-using WebSocketFactoryFixture = FaceSystemFactoryFixture<WebSocketFactory>;
+class WebSocketFactoryFixture : public FaceSystemFactoryFixture<WebSocketFactory>
+{
+protected:
+ shared_ptr<WebSocketChannel>
+ createChannel(const std::string& localIp, const std::string& localPort)
+ {
+ websocket::Endpoint endpoint(ndn::ip::addressFromString(localIp),
+ boost::lexical_cast<uint16_t>(localPort));
+ return factory.createChannel(endpoint);
+ }
+};
BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, WebSocketFactoryFixture)
@@ -175,9 +185,9 @@
BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
std::set<std::string> expected;
- expected.insert(factory.createChannel("127.0.0.1", "20070")->getUri().toString());
- expected.insert(factory.createChannel("127.0.0.1", "20071")->getUri().toString());
- expected.insert(factory.createChannel("::1", "20071")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString());
+ expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString());
+ expected.insert(createChannel("::1", "20071")->getUri().toString());
checkChannelListEqual(factory, expected);
}