tests: use DummyClientFace::linkTo() instead of DummyForwarder
Change-Id: Ied69eeb1b98fd2bdf3672db21bbea7a4a559382b
diff --git a/tests/dummy-forwarder.cpp b/tests/dummy-forwarder.cpp
deleted file mode 100644
index 61526cb..0000000
--- a/tests/dummy-forwarder.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- 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,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NDNS (Named Data Networking Domain Name Service) and is
- * based on the code written as part of NFD (Named Data Networking Daemon).
- * See AUTHORS.md for complete list of NDNS authors and contributors.
- *
- * NDNS is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "dummy-forwarder.hpp"
-
-#include <boost/asio/io_service.hpp>
-
-namespace ndn {
-namespace ndns {
-namespace tests {
-
-DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
- : m_io(io)
- , m_keyChain(keyChain)
-{
-}
-
-Face&
-DummyForwarder::addFace()
-{
- auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain, util::
- DummyClientFace::Options{true, true});
- face->onSendInterest.connect([this, face] (const Interest& interest) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(interest);
- }
- });
-
- face->onSendData.connect([this, face] (const Data& data) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(data);
- }
- });
-
- face->onSendNack.connect([this, face] (const lp::Nack& nack) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(nack);
- }
- });
-
- m_faces.push_back(face);
- return *face;
-}
-
-} // namespace tests
-} // namespace ndns
-} // namespace ndn
diff --git a/tests/dummy-forwarder.hpp b/tests/dummy-forwarder.hpp
deleted file mode 100644
index 481d257..0000000
--- a/tests/dummy-forwarder.hpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- 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,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NDNS (Named Data Networking Domain Name Service) and is
- * based on the code written as part of NFD (Named Data Networking Daemon).
- * See AUTHORS.md for complete list of NDNS authors and contributors.
- *
- * NDNS is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/lp/nack.hpp>
-#include <ndn-cxx/util/dummy-client-face.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-
-#ifndef NDNS_TESTS_TEST_DUMMY_FORWARDER_HPP
-#define NDNS_TESTS_TEST_DUMMY_FORWARDER_HPP
-
-namespace ndn {
-namespace ndns {
-namespace tests {
-
-/**
- * @brief Very basic implementation of the dummy forwarder
- *
- * Interests expressed by any added face, will be forwarded to all other faces.
- * Similarly, any pushed data, will be pushed to all other faces.
- */
-class DummyForwarder
-{
-public:
- DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain);
-
- Face&
- addFace();
-
- Face&
- getFace(size_t nFace)
- {
- return *m_faces.at(nFace);
- }
-
-private:
- boost::asio::io_service& m_io;
- KeyChain& m_keyChain;
- std::vector<shared_ptr<util::DummyClientFace>> m_faces;
-};
-
-} // namespace tests
-} // namespace ndns
-} // namespace ndn
-
-#endif // NDNS_TESTS_TEST_DUMMY_FORWARDER_HPP
diff --git a/tests/unit/validator/certificate-fetcher-ndns-app-cert.cpp b/tests/unit/validator/certificate-fetcher-ndns-app-cert.cpp
index 3f236aa..e062702 100644
--- a/tests/unit/validator/certificate-fetcher-ndns-app-cert.cpp
+++ b/tests/unit/validator/certificate-fetcher-ndns-app-cert.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -26,10 +26,8 @@
#include "mgmt/management-tool.hpp"
#include "test-common.hpp"
-#include "dummy-forwarder.hpp"
#include "unit/database-test-data.hpp"
-#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/security/v2/validation-policy-simple-hierarchy.hpp>
namespace ndn {
@@ -38,8 +36,8 @@
BOOST_AUTO_TEST_SUITE(AppCertFetcher)
-unique_ptr<security::v2::Validator>
-CreateValidatorAppCert(Face& face)
+static unique_ptr<security::v2::Validator>
+makeValidatorAppCert(Face& face)
{
return make_unique<security::v2::Validator>(make_unique<::ndn::security::v2::ValidationPolicySimpleHierarchy>(),
make_unique<CertificateFetcherAppCert>(face));
@@ -49,25 +47,28 @@
{
public:
AppCertFetcherFixture()
- : m_forwarder(m_io, m_keyChain)
- , m_face(m_forwarder.addFace())
- , m_validator(CreateValidatorAppCert(m_face))
+ : m_validatorFace(m_io, m_keyChain, {true, true})
+ , m_validator(makeValidatorAppCert(m_validatorFace))
{
// build the data and certificate for this test
buildAppCertAndData();
- auto validatorOnlyForConstructServer = NdnsValidatorBuilder::create(m_face, 10, 0, TEST_CONFIG_PATH "/" "validator.conf");
- // initlize all servers
- auto addServer = [&] (const Name& zoneName) {
- Face& face = m_forwarder.addFace();
+ auto serverValidator = NdnsValidatorBuilder::create(m_validatorFace, 10, 0,
+ TEST_CONFIG_PATH "/validator.conf");
+ // initialize all servers
+ auto addServer = [this, &serverValidator] (const Name& zoneName) {
+ m_serverFaces.push_back(make_unique<util::DummyClientFace>(m_io, m_keyChain,
+ util::DummyClientFace::Options{true, true}));
+ m_serverFaces.back()->linkTo(m_validatorFace);
+
// validator is used only for check update signature
// no updates tested here, so validator will not be used
// passing m_validator is only for construct server
Name certName = CertHelper::getDefaultCertificateNameOfIdentity(m_keyChain,
- Name(zoneName).append("NDNS"));
- auto server = make_shared<NameServer>(zoneName, certName, face,
- m_session, m_keyChain, *validatorOnlyForConstructServer);
- m_servers.push_back(server);
+ Name(zoneName).append("NDNS"));
+ auto server = make_shared<NameServer>(zoneName, certName, *m_serverFaces.back(),
+ m_session, m_keyChain, *serverValidator);
+ m_servers.push_back(std::move(server));
};
addServer(m_testName);
addServer(m_netName);
@@ -75,12 +76,6 @@
advanceClocks(time::milliseconds(10), 1);
}
- ~AppCertFetcherFixture()
- {
- m_face.getIoService().stop();
- m_face.shutdown();
- }
-
private:
void
buildAppCertAndData()
@@ -109,14 +104,13 @@
}
public:
- DummyForwarder m_forwarder;
- ndn::Face& m_face;
+ util::DummyClientFace m_validatorFace;
unique_ptr<security::v2::Validator> m_validator;
+ std::vector<unique_ptr<util::DummyClientFace>> m_serverFaces;
std::vector<shared_ptr<ndns::NameServer>> m_servers;
Data m_appCertSignedData;
};
-
BOOST_FIXTURE_TEST_CASE(Basic, AppCertFetcherFixture)
{
bool hasValidated = false;
diff --git a/tests/unit/validator/validator.cpp b/tests/unit/validator/validator.cpp
index 21f6d27..c9ac644 100644
--- a/tests/unit/validator/validator.cpp
+++ b/tests/unit/validator/validator.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -23,11 +23,8 @@
#include "daemon/name-server.hpp"
#include "test-common.hpp"
-#include "dummy-forwarder.hpp"
#include "unit/database-test-data.hpp"
-#include <ndn-cxx/util/io.hpp>
-
namespace ndn {
namespace ndns {
namespace tests {
@@ -38,50 +35,47 @@
{
public:
ValidatorTestFixture()
- : m_forwarder(m_io, m_keyChain)
- , m_face(m_forwarder.addFace())
- , m_validator(NdnsValidatorBuilder::create(m_face, 500, 0, TEST_CONFIG_PATH "/" "validator.conf"))
+ : m_validatorFace(m_io, m_keyChain, {true, true})
+ , m_validator(NdnsValidatorBuilder::create(m_validatorFace, 500, 0,
+ TEST_CONFIG_PATH "/validator.conf"))
{
// generate a random cert
// check how does name-server test do
- // initlize all servers
- auto addServer = [&] (const Name& zoneName) {
- Face& face = m_forwarder.addFace();
+ // initialize all servers
+ auto addServer = [this] (const Name& zoneName) {
+ m_serverFaces.push_back(make_unique<util::DummyClientFace>(m_io, m_keyChain,
+ util::DummyClientFace::Options{true, true}));
+ m_serverFaces.back()->linkTo(m_validatorFace);
+
// validator is used only for check update signature
// no updates tested here, so validator will not be used
// passing m_validator is only for construct server
Name certName = CertHelper::getDefaultCertificateNameOfIdentity(m_keyChain,
Name(zoneName).append("NDNS"));
- auto server = make_shared<NameServer>(zoneName, certName, face,
+ auto server = make_shared<NameServer>(zoneName, certName, *m_serverFaces.back(),
m_session, m_keyChain, *m_validator);
- m_servers.push_back(server);
+ m_servers.push_back(std::move(server));
};
addServer(m_testName);
addServer(m_netName);
addServer(m_ndnsimName);
+
m_ndnsimCert = CertHelper::getDefaultCertificateNameOfIdentity(m_keyChain,
- Name(m_ndnsimName).append("NDNS"));
+ Name(m_ndnsimName).append("NDNS"));
m_randomCert = m_keyChain.createIdentity("/random/identity").getDefaultKey()
- .getDefaultCertificate().getName();
+ .getDefaultCertificate().getName();
advanceClocks(time::milliseconds(10), 1);
}
- ~ValidatorTestFixture()
- {
- m_face.getIoService().stop();
- m_face.shutdown();
- }
-
public:
- DummyForwarder m_forwarder;
- ndn::Face& m_face;
+ util::DummyClientFace m_validatorFace;
unique_ptr<security::v2::Validator> m_validator;
+ std::vector<unique_ptr<util::DummyClientFace>> m_serverFaces;
std::vector<shared_ptr<ndns::NameServer>> m_servers;
Name m_ndnsimCert;
Name m_randomCert;
};
-
BOOST_FIXTURE_TEST_CASE(Basic, ValidatorTestFixture)
{
SignatureInfo info;