face: pass addFace and NetworkMonitor to ProtocolFactory constructor
refs #4021
Change-Id: I842515eb044bb1c655b347e6069e63c55c4e2d54
diff --git a/tests/daemon/face/ethernet-factory.t.cpp b/tests/daemon/face/ethernet-factory.t.cpp
index 856a942..e48c38f 100644
--- a/tests/daemon/face/ethernet-factory.t.cpp
+++ b/tests/daemon/face/ethernet-factory.t.cpp
@@ -36,15 +36,10 @@
namespace face {
namespace tests {
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, EthernetFixture)
-
-using face::Face;
-
-class EthernetConfigFixture : public EthernetFixture
- , public FaceSystemFixture
+class EthernetFactoryFixture : public EthernetFixture
+ , public FaceSystemFactoryFixture<EthernetFactory>
{
-public:
+protected:
std::vector<const Face*>
listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
{
@@ -58,7 +53,12 @@
}
};
-BOOST_FIXTURE_TEST_SUITE(ProcessConfig, EthernetConfigFixture)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, EthernetFactoryFixture)
+
+using nfd::Face;
+
+BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(Normal)
{
@@ -313,16 +313,12 @@
BOOST_AUTO_TEST_CASE(GetChannels)
{
- EthernetFactory factory;
-
auto channels = factory.getChannels();
BOOST_CHECK_EQUAL(channels.empty(), true);
}
BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
- EthernetFactory factory;
-
createFace(factory,
FaceUri("ether://[00:00:5e:00:53:5e]"),
{},
diff --git a/tests/daemon/face/face-system-fixture.hpp b/tests/daemon/face/face-system-fixture.hpp
index f1ea72c..b6143d4 100644
--- a/tests/daemon/face/face-system-fixture.hpp
+++ b/tests/daemon/face/face-system-fixture.hpp
@@ -113,6 +113,21 @@
FaceSystem faceSystem;
};
+/** \brief FaceSystemFixture with a ProtocolFactory reference
+ */
+template<typename FactoryType>
+class FaceSystemFactoryFixture : public FaceSystemFixture
+{
+protected:
+ FaceSystemFactoryFixture()
+ : factory(getFactoryById<FactoryType>(FactoryType::getId()))
+ {
+ }
+
+protected:
+ FactoryType& factory;
+};
+
} // namespace tests
} // namespace face
} // namespace nfd
diff --git a/tests/daemon/face/face-system.t.cpp b/tests/daemon/face/face-system.t.cpp
index 590c063..1e46240 100644
--- a/tests/daemon/face/face-system.t.cpp
+++ b/tests/daemon/face/face-system.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
@@ -40,6 +40,11 @@
class DummyProtocolFactory : public ProtocolFactory
{
public:
+ DummyProtocolFactory(const CtorParams& params)
+ : ProtocolFactory(params)
+ {
+ }
+
void
processConfig(OptionalConfigSection configSection,
FaceSystem::ConfigContext& context) override
@@ -81,8 +86,8 @@
BOOST_AUTO_TEST_CASE(Normal)
{
- faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>();
- faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>();
+ faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
+ faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2"));
@@ -119,8 +124,8 @@
BOOST_AUTO_TEST_CASE(OmittedSection)
{
- faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>();
- faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>();
+ faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
+ faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2"));
@@ -165,7 +170,7 @@
BOOST_AUTO_TEST_CASE(ChangeProvidedSchemes)
{
- faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>();
+ faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
const std::string CONFIG = R"CONFIG(
diff --git a/tests/daemon/face/tcp-factory.t.cpp b/tests/daemon/face/tcp-factory.t.cpp
index a66e46a..d994fa2 100644
--- a/tests/daemon/face/tcp-factory.t.cpp
+++ b/tests/daemon/face/tcp-factory.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
@@ -33,12 +33,14 @@
namespace face {
namespace tests {
+using TcpFactoryFixture = FaceSystemFactoryFixture<TcpFactory>;
+
BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, BaseFixture)
+BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, TcpFactoryFixture)
using nfd::Face;
-BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceSystemFixture)
+BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(Normal)
{
@@ -58,7 +60,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<TcpFactory>("tcp");
BOOST_CHECK_EQUAL(factory.getChannels().size(), 2);
}
@@ -73,7 +74,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<TcpFactory>("tcp");
BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
}
@@ -131,8 +131,6 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- TcpFactory factory;
-
shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
BOOST_CHECK_EQUAL(channel1, channel1a);
@@ -148,7 +146,6 @@
BOOST_AUTO_TEST_CASE(GetChannels)
{
- TcpFactory factory;
BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
std::vector<shared_ptr<const Channel>> expectedChannels;
@@ -166,8 +163,6 @@
BOOST_AUTO_TEST_CASE(FaceCreate)
{
- TcpFactory factory;
-
createFace(factory,
FaceUri("tcp4://127.0.0.1:6363"),
{},
@@ -201,7 +196,6 @@
BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
- TcpFactory factory;
factory.createChannel("127.0.0.1", "20071");
createFace(factory,
@@ -237,7 +231,7 @@
"Local fields can only be enabled on faces with local scope"});
}
-class FaceCreateTimeoutFixture : public BaseFixture
+class FaceCreateTimeoutFixture : public TcpFactoryFixture
{
public:
void
@@ -264,7 +258,6 @@
BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture)
{
- TcpFactory factory;
factory.createChannel("0.0.0.0", "20070");
factory.createFace(FaceUri("tcp4://192.0.2.1:20070"),
@@ -278,7 +271,7 @@
BOOST_CHECK(face == nullptr);
}
-class FakeNetworkInterfaceFixture : public BaseFixture
+class FakeNetworkInterfaceFixture : public TcpFactoryFixture
{
public:
FakeNetworkInterfaceFixture()
@@ -322,7 +315,6 @@
{
using namespace boost::asio::ip;
- TcpFactory factory;
factory.prohibitEndpoint(tcp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
BOOST_CHECK((factory.m_prohibitedEndpoints ==
diff --git a/tests/daemon/face/udp-factory.t.cpp b/tests/daemon/face/udp-factory.t.cpp
index b5ddb8a..0ad5612 100644
--- a/tests/daemon/face/udp-factory.t.cpp
+++ b/tests/daemon/face/udp-factory.t.cpp
@@ -36,12 +36,14 @@
namespace face {
namespace tests {
+using UdpFactoryFixture = FaceSystemFactoryFixture<UdpFactory>;
+
BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, BaseFixture)
+BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture)
using nfd::Face;
-BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceSystemFixture)
+BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(Channels)
{
@@ -62,7 +64,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<UdpFactory>("udp");
checkChannelListEqual(factory, {"udp4://0.0.0.0:7001", "udp6://[::]:7001"});
}
@@ -84,7 +85,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<UdpFactory>("udp");
checkChannelListEqual(factory, {"udp4://0.0.0.0:7001"});
}
@@ -106,11 +106,10 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<UdpFactory>("udp");
checkChannelListEqual(factory, {"udp6://[::]:7001"});
}
-class UdpMcastConfigFixture : public FaceSystemFixture
+class UdpMcastConfigFixture : public UdpFactoryFixture
{
protected:
UdpMcastConfigFixture()
@@ -369,7 +368,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<UdpFactory>("udp");
BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
}
@@ -492,7 +490,6 @@
BOOST_AUTO_TEST_CASE(GetChannels)
{
- UdpFactory factory;
BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
std::vector<shared_ptr<const Channel>> expectedChannels;
@@ -511,8 +508,6 @@
BOOST_AUTO_TEST_CASE(CreateChannel)
{
- UdpFactory factory;
-
auto channel1 = factory.createChannel("127.0.0.1", "20070");
auto channel1a = factory.createChannel("127.0.0.1", "20070");
BOOST_CHECK_EQUAL(channel1, channel1a);
@@ -545,8 +540,6 @@
BOOST_AUTO_TEST_CASE(CreateMulticastFace)
{
- UdpFactory factory;
-
auto multicastFace1 = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20070");
auto multicastFace1a = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20070");
BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
@@ -599,8 +592,6 @@
BOOST_AUTO_TEST_CASE(FaceCreate)
{
- UdpFactory factory;
-
createFace(factory,
FaceUri("udp4://127.0.0.1:6363"),
{},
@@ -634,7 +625,6 @@
BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
- UdpFactory factory;
factory.createChannel("127.0.0.1", "20071");
createFace(factory,
@@ -678,7 +668,7 @@
"Local fields can only be enabled on faces with local scope"});
}
-class FakeNetworkInterfaceFixture : public BaseFixture
+class FakeNetworkInterfaceFixture : public UdpFactoryFixture
{
public:
FakeNetworkInterfaceFixture()
@@ -722,7 +712,6 @@
{
using namespace boost::asio::ip;
- UdpFactory factory;
factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
BOOST_CHECK((factory.m_prohibitedEndpoints ==
diff --git a/tests/daemon/face/unix-stream-factory.t.cpp b/tests/daemon/face/unix-stream-factory.t.cpp
index dc5b5ac..5bd0506 100644
--- a/tests/daemon/face/unix-stream-factory.t.cpp
+++ b/tests/daemon/face/unix-stream-factory.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
@@ -36,12 +36,14 @@
#define CHANNEL_PATH1 "unix-stream-test.1.sock"
#define CHANNEL_PATH2 "unix-stream-test.2.sock"
+using UnixStreamFactoryFixture = FaceSystemFactoryFixture<UnixStreamFactory>;
+
BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, BaseFixture)
+BOOST_FIXTURE_TEST_SUITE(TestUnixStreamFactory, UnixStreamFactoryFixture)
using nfd::Face;
-BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceSystemFixture)
+BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(Normal)
{
@@ -97,8 +99,6 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- UnixStreamFactory factory;
-
shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
BOOST_CHECK_EQUAL(channel1, channel1a);
@@ -113,7 +113,6 @@
BOOST_AUTO_TEST_CASE(GetChannels)
{
- UnixStreamFactory factory;
BOOST_CHECK(factory.getChannels().empty());
std::vector<shared_ptr<const Channel>> expectedChannels;
@@ -131,8 +130,6 @@
BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
- UnixStreamFactory factory;
-
createFace(factory,
FaceUri("unix:///var/run/nfd.sock"),
{},
diff --git a/tests/daemon/face/websocket-factory.t.cpp b/tests/daemon/face/websocket-factory.t.cpp
index 5243c97..c17e620 100644
--- a/tests/daemon/face/websocket-factory.t.cpp
+++ b/tests/daemon/face/websocket-factory.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
@@ -35,10 +35,12 @@
namespace ip = boost::asio::ip;
-BOOST_AUTO_TEST_SUITE(Face)
-BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, BaseFixture)
+using WebSocketFactoryFixture = FaceSystemFactoryFixture<WebSocketFactory>;
-BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceSystemFixture)
+BOOST_AUTO_TEST_SUITE(Face)
+BOOST_FIXTURE_TEST_SUITE(TestWebSocketFactory, WebSocketFactoryFixture)
+
+BOOST_AUTO_TEST_SUITE(ProcessConfig)
BOOST_AUTO_TEST_CASE(Normal)
{
@@ -58,7 +60,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<WebSocketFactory>("websocket");
checkChannelListEqual(factory, {"ws://[::]:9696"});
}
@@ -80,7 +81,6 @@
parseConfig(CONFIG, true);
parseConfig(CONFIG, false);
- auto& factory = this->getFactoryById<WebSocketFactory>("websocket");
checkChannelListEqual(factory, {"ws://0.0.0.0:9696"});
}
@@ -137,7 +137,6 @@
}
)CONFIG";
- auto& factory = this->getFactoryById<WebSocketFactory>("websocket");
BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
}
@@ -154,7 +153,6 @@
)CONFIG";
parseConfig(CONFIG1, false);
- auto& factory = this->getFactoryById<WebSocketFactory>("websocket");
checkChannelListEqual(factory, {"ws://[::]:9001"});
const std::string CONFIG2 = R"CONFIG(
@@ -175,7 +173,6 @@
BOOST_AUTO_TEST_CASE(GetChannels)
{
- WebSocketFactory factory;
BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
std::vector<shared_ptr<const Channel>> expectedChannels;
@@ -194,8 +191,6 @@
BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
{
- WebSocketFactory factory;
-
createFace(factory,
FaceUri("ws://127.0.0.1:20070"),
{},