tests: sync common testing infrastructure with ndn-cxx
Change-Id: I1e5cdcda8f6d3d9f9addc7a9f17359aedef9db7e
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index 2a1e607..5c95a0c 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -19,34 +19,35 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NLSR_TEST_COMMON_HPP
-#define NLSR_TEST_COMMON_HPP
+#ifndef NLSR_TESTS_TEST_COMMON_HPP
+#define NLSR_TESTS_TEST_COMMON_HPP
-#include "common.hpp"
#include "conf-parameter.hpp"
-#include "route/fib.hpp"
-#include "boost-test.hpp"
-#include "identity-management-fixture.hpp"
+#include "tests/boost-test.hpp"
-#include <boost/asio.hpp>
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/data.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-#include <ndn-cxx/util/time-unit-test-clock.hpp>
namespace nlsr {
namespace test {
+/**
+ * \brief Create a Data with a null (i.e., empty) signature
+ *
+ * If a "real" signature is desired, use KeyChainFixture and sign again with `m_keyChain`.
+ */
+std::shared_ptr<ndn::Data>
+makeData(const ndn::Name& name);
+
+/**
+ * \brief Add a null signature to \p data
+ */
ndn::Data&
signData(ndn::Data& data);
-void
-checkPrefixRegistered(const ndn::util::DummyClientFace& face, const ndn::Name& prefix);
-
-/** \brief add a fake signature to Data
+/**
+ * \brief Add a null signature to \p data
*/
inline std::shared_ptr<ndn::Data>
signData(std::shared_ptr<ndn::Data> data)
@@ -55,132 +56,18 @@
return data;
}
-class BaseFixture : public tests::IdentityManagementFixture
-{
-public:
- BaseFixture()
- : m_scheduler(m_ioService)
- {
- }
-
-protected:
- boost::asio::io_service m_ioService;
- ndn::Scheduler m_scheduler;
-};
-
-class UnitTestTimeFixture : public BaseFixture
-{
-protected:
- UnitTestTimeFixture()
- : steadyClock(std::make_shared<ndn::time::UnitTestSteadyClock>())
- , systemClock(std::make_shared<ndn::time::UnitTestSystemClock>())
- {
- ndn::time::setCustomClocks(steadyClock, systemClock);
- }
-
- ~UnitTestTimeFixture()
- {
- ndn::time::setCustomClocks(nullptr, nullptr);
- }
-
- void
- advanceClocks(const ndn::time::nanoseconds& tick, size_t nTicks = 1);
-
-protected:
- std::shared_ptr<ndn::time::UnitTestSteadyClock> steadyClock;
- std::shared_ptr<ndn::time::UnitTestSystemClock> systemClock;
-};
-
-class MockNfdMgmtFixture : public UnitTestTimeFixture
-{
-public:
- MockNfdMgmtFixture();
-
- virtual
- ~MockNfdMgmtFixture() = default;
-
- /** \brief send one WireEncodable in reply to StatusDataset request
- * \param prefix dataset prefix without version and segment
- * \param payload payload block
- * \note payload must fit in one Data
- * \pre Interest for dataset has been expressed, sendDataset has not been invoked
- */
- template<typename T>
- void
- sendDataset(const ndn::Name& prefix, const T& payload)
- {
- BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T>));
-
- this->sendDatasetReply(prefix, payload.wireEncode());
- }
-
- /** \brief send two WireEncodables in reply to StatusDataset request
- * \param prefix dataset prefix without version and segment
- * \param payload1 first vector item
- * \param payload2 second vector item
- * \note all payloads must fit in one Data
- * \pre Interest for dataset has been expressed, sendDataset has not been invoked
- */
- template<typename T1, typename T2>
- void
- sendDataset(const ndn::Name& prefix, const T1& payload1, const T2& payload2)
- {
- BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T1>));
- BOOST_CONCEPT_ASSERT((ndn::WireEncodable<T2>));
-
- ndn::encoding::EncodingBuffer buffer;
- payload2.wireEncode(buffer);
- payload1.wireEncode(buffer);
-
- this->sendDatasetReply(prefix, buffer);
- }
-
- /** \brief send a payload in reply to StatusDataset request
- * \param name dataset prefix without version and segment
- * \param contentArgs passed to Data::setContent
- */
- template<typename ...ContentArgs>
- void
- sendDatasetReply(ndn::Name name, ContentArgs&&... contentArgs)
- {
- name.appendVersion().appendSegment(0);
-
- // These warnings assist in debugging when nfdc does not receive StatusDataset.
- // They usually indicate a misspelled prefix or incorrect timing in the test case.
- if (m_face.sentInterests.empty()) {
- BOOST_WARN_MESSAGE(false, "no Interest expressed");
- }
- else {
- BOOST_WARN_MESSAGE(m_face.sentInterests.back().getName().isPrefixOf(name),
- "last Interest " << m_face.sentInterests.back().getName() <<
- " cannot be satisfied by this Data " << name);
- }
-
- auto data = std::make_shared<ndn::Data>(name);
- data->setFreshnessPeriod(1_s);
- data->setFinalBlock(name[-1]);
- data->setContent(std::forward<ContentArgs>(contentArgs)...);
- this->signDatasetReply(*data);
- m_face.receive(*data);
- }
-
- virtual void
- signDatasetReply(ndn::Data& data);
-
-public:
- ndn::util::DummyClientFace m_face;
-};
+void
+checkPrefixRegistered(const ndn::util::DummyClientFace& face, const ndn::Name& prefix);
class DummyConfFileProcessor
{
- typedef std::function<void(ConfParameter&)> AfterConfProcessing;
-
public:
DummyConfFileProcessor(ConfParameter& conf,
SyncProtocol protocol = SYNC_PROTOCOL_PSYNC,
- int32_t hyperbolicState = HYPERBOLIC_STATE_OFF,
- ndn::Name networkName = "/ndn", ndn::Name siteName = "/site",
- ndn::Name routerName = "/%C1.Router/this-router")
+ HyperbolicState hyperbolicState = HYPERBOLIC_STATE_OFF,
+ const ndn::Name& networkName = "/ndn",
+ const ndn::Name& siteName = "/site",
+ const ndn::Name& routerName = "/%C1.Router/this-router")
{
conf.setNetwork(networkName);
conf.setSiteName(siteName);
@@ -194,4 +81,4 @@
} // namespace test
} // namespace nlsr
-#endif // NLSR_TEST_COMMON_HPP
+#endif // NLSR_TESTS_TEST_COMMON_HPP