tests: sync common testing infrastructure with ndn-cxx
Change-Id: I1e5cdcda8f6d3d9f9addc7a9f17359aedef9db7e
diff --git a/tests/publisher/publisher-fixture.hpp b/tests/publisher/publisher-fixture.hpp
index 3dcf103..ffc7016 100644
--- a/tests/publisher/publisher-fixture.hpp
+++ b/tests/publisher/publisher-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, The University of Memphis,
+ * Copyright (c) 2014-2022, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -19,40 +19,31 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NLSR_PUBLISHER_FIXTURE_HPP
-#define NLSR_PUBLISHER_FIXTURE_HPP
+#ifndef NLSR_TESTS_PUBLISHER_FIXTURE_HPP
+#define NLSR_TESTS_PUBLISHER_FIXTURE_HPP
#include "publisher/dataset-interest-handler.hpp"
#include "nlsr.hpp"
+#include "tests/io-key-chain-fixture.hpp"
#include "tests/test-common.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/security/pib/identity.hpp>
-
-#include <ndn-cxx/util/io.hpp>
-
-#include <boost/filesystem.hpp>
-
-using namespace ndn;
-
namespace nlsr {
namespace test {
-class PublisherFixture : public BaseFixture
+class PublisherFixture : public IoKeyChainFixture
{
public:
PublisherFixture()
- : face(m_ioService, m_keyChain, {true, true})
+ : face(m_io, m_keyChain, {true, true})
, conf(face, m_keyChain)
, confProcessor(conf)
, nlsr(face, m_keyChain, conf)
, lsdb(nlsr.m_lsdb)
, rt1(nlsr.m_routingTable)
{
- routerId = addIdentity(conf.getRouterPrefix());
- face.processEvents(ndn::time::milliseconds(100));
+ routerId = m_keyChain.createIdentity(conf.getRouterPrefix());
+ advanceClocks(100_ms);
}
void
@@ -65,16 +56,28 @@
NextHop
createNextHop(const std::string& faceUri, double cost)
{
- NextHop nexthop(faceUri, cost);
- return nexthop;
+ return {faceUri, cost};
}
CoordinateLsa
createCoordinateLsa(const std::string& origin, double radius, std::vector<double> angle)
{
- CoordinateLsa lsa(origin, 1, ndn::time::system_clock::now(),
- radius, angle);
- return lsa;
+ return {origin, 1, ndn::time::system_clock::now(), radius, angle};
+ }
+
+ void
+ processDatasetInterest(std::function<bool(const ndn::Block&)> isSameType)
+ {
+ advanceClocks(30_ms);
+
+ BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
+ ndn::Block parser(face.sentData[0].getContent());
+ parser.parse();
+ face.sentData.clear();
+
+ auto it = parser.elements_begin();
+ BOOST_CHECK(isSameType(*it++));
+ BOOST_CHECK(it == parser.elements_end());
}
public:
@@ -91,4 +94,4 @@
} // namespace test
} // namespace nlsr
-#endif // NLSR_PUBLISHER_FIXTURE_HPP
+#endif // NLSR_TESTS_PUBLISHER_FIXTURE_HPP
diff --git a/tests/publisher/test-dataset-interest-handler.cpp b/tests/publisher/test-dataset-interest-handler.cpp
index b8a44d3..2e71585 100644
--- a/tests/publisher/test-dataset-interest-handler.cpp
+++ b/tests/publisher/test-dataset-interest-handler.cpp
@@ -22,30 +22,11 @@
#include "publisher/dataset-interest-handler.hpp"
#include "tlv-nlsr.hpp"
-#include "tests/test-common.hpp"
-#include "publisher-fixture.hpp"
+#include "tests/publisher/publisher-fixture.hpp"
namespace nlsr {
namespace test {
-static void
-processDatasetInterest(ndn::util::DummyClientFace& face,
- std::function<bool(const ndn::Block&)> isSameType)
-{
- face.processEvents(30_ms);
-
- BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
-
- ndn::Block parser(face.sentData[0].getContent());
- parser.parse();
-
- auto it = parser.elements_begin();
- BOOST_CHECK_EQUAL(isSameType(*it++), true);
- BOOST_CHECK(it == parser.elements_end());
-
- face.sentData.clear();
-}
-
BOOST_FIXTURE_TEST_SUITE(TestDatasetInterestHandler, PublisherFixture)
BOOST_AUTO_TEST_CASE(Localhost)
@@ -70,29 +51,23 @@
const ndn::Name& DEST_ROUTER = rte1.getDestination();
NextHop nh = createNextHop("udp://face-test1", 10);
-
rt1.addNextHop(DEST_ROUTER, nh);
// Request adjacency LSAs
face.receive(ndn::Interest("/localhost/nlsr/lsdb/adjacencies").setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
+ processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
// Request coordinate LSAs
face.receive(ndn::Interest("/localhost/nlsr/lsdb/coordinates").setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
+ processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
// Request Name LSAs
face.receive(ndn::Interest("/localhost/nlsr/lsdb/names").setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
+ processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
// Request Routing Table
face.receive(ndn::Interest("/localhost/nlsr/routing-table").setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const ndn::Block& block) {
- return block.type() == ndn::tlv::nlsr::RoutingTable; });
+ processDatasetInterest([] (const ndn::Block& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
}
BOOST_AUTO_TEST_CASE(RouterName)
@@ -126,23 +101,19 @@
// Request adjacency LSAs
face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("adjacencies")).setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const auto& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
+ processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::AdjacencyLsa; });
// Request coordinate LSAs
face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("coordinates")).setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const auto& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
+ processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::CoordinateLsa; });
// Request Name LSAs
face.receive(ndn::Interest(ndn::Name(routerName).append("lsdb").append("names")).setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const auto& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
+ processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::NameLsa; });
// Request Routing Table
face.receive(ndn::Interest(ndn::Name(routerName).append("routing-table")).setCanBePrefix(true));
- processDatasetInterest(face,
- [] (const auto& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
+ processDatasetInterest([] (const auto& block) { return block.type() == ndn::tlv::nlsr::RoutingTable; });
}
BOOST_AUTO_TEST_SUITE_END()