Avoid deprecated ndn-cxx functions

Change-Id: Ic9fab00b75e9519315ee776dbc464794a9e56f1c
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index 1a4e272..0d93347 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.hpp
@@ -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-2022, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -21,6 +21,7 @@
 #define REPO_TESTS_DATASET_FIXTURES_HPP
 
 #include "identity-management-fixture.hpp"
+
 #include <vector>
 #include <boost/mpl/vector.hpp>
 
@@ -33,11 +34,7 @@
   class Error : public std::runtime_error
   {
   public:
-    explicit
-    Error(const std::string& what)
-      : std::runtime_error(what)
-    {
-    }
+    using std::runtime_error::runtime_error;
   };
 
   using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
@@ -56,11 +53,10 @@
     if (map.count(name) > 0)
       return map[name];
 
-    static std::vector<uint8_t> content(1500, '-');
+    static const std::vector<uint8_t> content(1500, '-');
 
-    std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
-    data->setName(name);
-    data->setContent(&content[0], content.size());
+    auto data = std::make_shared<ndn::Data>(name);
+    data->setContent(content);
     m_keyChain.sign(*data);
 
     map.insert(std::make_pair(name, data));
@@ -73,7 +69,7 @@
     if (map.count(name) > 0)
       return map[name];
     else
-      BOOST_THROW_EXCEPTION(Error("Data with name " + name.toUri() + " is not found"));
+      NDN_THROW(Error("Data with name " + name.toUri() + " is not found"));
   }
 
 private:
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 03e9a54..5ed5b9b 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021, Regents of the University of California.
+ * Copyright (c) 2014-2022, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -32,7 +32,6 @@
 #include <ndn-cxx/util/random.hpp>
 #include <ndn-cxx/util/time.hpp>
 
-#include <boost/asio/io_service.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/test/unit_test.hpp>
 
@@ -44,7 +43,7 @@
 // All the test cases in this test suite should be run at once.
 BOOST_AUTO_TEST_SUITE(TestBasicCommandInsertDelete)
 
-const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
+const uint8_t CONTENT[] = {3, 1, 4, 1, 5, 9, 2, 6};
 
 template<class Dataset>
 class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
@@ -59,7 +58,7 @@
   {
     Name cmdPrefix("/repo/command");
     repoFace.registerPrefix(cmdPrefix, nullptr,
-      [] (const Name& cmdPrefix, const std::string& reason) {
+      [] (const Name&, const std::string& reason) {
         BOOST_FAIL("Command prefix registration error: " << reason);
       });
   }
@@ -113,11 +112,12 @@
   ndn::security::InterestSigner signer;
 };
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::onInsertInterest(const Interest& interest)
 {
   Data data(Name(interest.getName()));
-  data.setContent(content, sizeof(content));
+  data.setContent(CONTENT);
   data.setFreshnessPeriod(0_ms);
   keyChain.sign(data);
   insertFace.put(data);
@@ -126,56 +126,62 @@
     eventIt->second.cancel();
     insertEvents.erase(eventIt);
   }
-  // schedule an event 50ms later to check whether insert is Ok
-  scheduler.schedule(500_ms, std::bind(&Fixture<T>::checkInsertOk, this, interest));
+
+  // schedule an event to check whether insert is ok
+  scheduler.schedule(500_ms, [=] { this->checkInsertOk(interest); });
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::onRegisterFailed(const std::string& reason)
 {
   BOOST_ERROR("ERROR: Failed to register prefix in local hub's daemon" + reason);
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::delayedInterest()
 {
   BOOST_ERROR("Fetching interest does not come. It may be satisfied in CS or something is wrong");
 }
 
-template<class T> void
-Fixture<T>::onInsertData(const Interest& interest, const Data& data)
+template<class T>
+void
+Fixture<T>::onInsertData(const Interest&, const Data& data)
 {
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
-  int statusCode = response.getCode();
-  BOOST_CHECK_EQUAL(statusCode, 100);
+  BOOST_CHECK_EQUAL(response.getCode(), 100);
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::onDeleteData(const Interest& interest, const Data& data)
 {
   RepoCommandResponse response;
   response.wireDecode(data.getContent().blockFromValue());
-  int statusCode = response.getCode();
-  BOOST_CHECK_EQUAL(statusCode, 200);
+  BOOST_CHECK_EQUAL(response.getCode(), 200);
 
-  //schedlute an event to check whether delete is Ok.
-  scheduler.schedule(100_ms, std::bind(&Fixture<T>::checkDeleteOk, this, interest));
+  // schedule an event to check whether delete is ok
+  scheduler.schedule(100_ms, [=] { this->checkDeleteOk(interest); });
 }
 
-template<class T> void
-Fixture<T>::onInsertTimeout(const Interest& interest)
+template<class T>
+void
+Fixture<T>::onInsertTimeout(const Interest&)
 {
   BOOST_ERROR("Insert command timeout");
 }
 
-template<class T> void
-Fixture<T>::onDeleteTimeout(const Interest& interest)
+template<class T>
+void
+Fixture<T>::onDeleteTimeout(const Interest&)
 {
   BOOST_ERROR("Delete command timeout");
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::sendInsertInterest(const Interest& insertInterest)
 {
   insertFace.expressInterest(insertInterest,
@@ -184,7 +190,8 @@
                              std::bind(&Fixture<T>::onInsertTimeout, this, _1));
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::sendDeleteInterest(const Interest& deleteInterest)
 {
   deleteFace.expressInterest(deleteInterest,
@@ -193,41 +200,43 @@
                              std::bind(&Fixture<T>::onDeleteTimeout, this, _1));
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::checkInsertOk(const Interest& interest)
 {
-  BOOST_TEST_MESSAGE(interest);
-  std::shared_ptr<Data> data = handle->readData(interest);
-  if (data) {
-    int rc = memcmp(data->getContent().value(), content, sizeof(content));
-    BOOST_CHECK_EQUAL(rc, 0);
-  }
-  else {
-    BOOST_ERROR("Check Insert Failed");
+  BOOST_TEST_CONTEXT("Interest " << interest) {
+    auto data = handle->readData(interest);
+    if (data) {
+      BOOST_TEST(data->getContent().value_bytes() == CONTENT, boost::test_tools::per_element());
+    }
+    else {
+      BOOST_ERROR("Insert check failed");
+    }
   }
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::checkDeleteOk(const Interest& interest)
 {
-  std::map<Name, Name>::iterator name = deleteNamePairs.find(interest.getName());
-  BOOST_CHECK_MESSAGE(name != deleteNamePairs.end(), "Delete name not found: " << interest.getName());
-  Interest dataInterest(name->second);
-  std::shared_ptr<Data> data = handle->readData(dataInterest);
+  auto nameIt = deleteNamePairs.find(interest.getName());
+  BOOST_CHECK_MESSAGE(nameIt != deleteNamePairs.end(), "Delete name not found: " << interest.getName());
+  Interest dataInterest(nameIt->second);
+  auto data = handle->readData(dataInterest);
   BOOST_CHECK(!data);
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::scheduleInsertEvent()
 {
   int timeCount = 1;
-  for (typename T::DataContainer::iterator i = this->data.begin();
-       i != this->data.end(); ++i) {
+  for (auto i = this->data.begin(); i != this->data.end(); ++i) {
     Name insertCommandName("/repo/command/insert");
     RepoCommandParameter insertParameter;
     insertParameter.setName(Name((*i)->getName())
                             .appendNumber(ndn::random::generateWord64()));
-    insertCommandName.append(insertParameter.wireEncode());
+    insertCommandName.append(tlv::GenericNameComponent, insertParameter.wireEncode());
     Interest insertInterest = signer.makeCommandInterest(insertCommandName);
     // schedule a job to express insertInterest every 50ms
     scheduler.schedule(milliseconds(timeCount * 50 + 1000),
@@ -245,17 +254,17 @@
   }
 }
 
-template<class T> void
+template<class T>
+void
 Fixture<T>::scheduleDeleteEvent()
 {
   int timeCount = 1;
-  for (typename T::DataContainer::iterator i = this->data.begin();
-       i != this->data.end(); ++i) {
+  for (auto i = this->data.begin(); i != this->data.end(); ++i) {
     Name deleteCommandName("/repo/command/delete");
     RepoCommandParameter deleteParameter;
     deleteParameter.setProcessId(ndn::random::generateWord64());
     deleteParameter.setName((*i)->getName());
-    deleteCommandName.append(deleteParameter.wireEncode());
+    deleteCommandName.append(tlv::GenericNameComponent, deleteParameter.wireEncode());
     Interest deleteInterest = signer.makeCommandInterest(deleteCommandName);
     deleteNamePairs[deleteInterest.getName()] = (*i)->getName();
     scheduler.schedule(milliseconds(4000 + timeCount * 50),
@@ -271,8 +280,8 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
 {
   // schedule events
-  this->scheduler.schedule(0_s, std::bind(&Fixture<T>::scheduleInsertEvent, this));
-  this->scheduler.schedule(10_s, std::bind(&Fixture<T>::scheduleDeleteEvent, this));
+  this->scheduler.schedule(0_s,  [this] { this->scheduleInsertEvent(); });
+  this->scheduler.schedule(10_s, [this] { this->scheduleDeleteEvent(); });
 
   this->repoFace.processEvents(30_s);
 }
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index 81ace5b..ab3da01 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019, Regents of the University of California.
+ * Copyright (c) 2014-2022, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -27,17 +27,14 @@
 #include <boost/asio/io_service.hpp>
 #include <boost/test/unit_test.hpp>
 
-#include <ndn-cxx/util/logger.hpp>
 #include <ndn-cxx/util/time.hpp>
 
 namespace repo {
 namespace tests {
 
-NDN_LOG_INIT(repo.tests.read);
+BOOST_AUTO_TEST_SUITE(TestBasicInterestRead)
 
-BOOST_AUTO_TEST_SUITE(TestBasicInerestRead)
-
-const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
+const uint8_t CONTENT[] = {3, 1, 4, 1, 5, 9, 2, 6};
 
 template<class Dataset>
 class BasicInterestReadFixture : public RepoStorageFixture, public Dataset
@@ -65,17 +62,13 @@
   scheduleReadEvent()
   {
     int timeCount = 1;
-    for (typename Dataset::DataContainer::iterator i = this->data.begin();
-         i != this->data.end(); ++i) {
-      //First insert a data into database;
-      (*i)->setContent(content, sizeof(content));
+    for (auto i = this->data.begin(); i != this->data.end(); ++i) {
+      // First insert a data into database
+      (*i)->setContent(CONTENT);
       (*i)->setFreshnessPeriod(36000_ms);
       keyChain.sign(**i);
-      NDN_LOG_DEBUG(**i);
       bool rc = handle->insertData(**i);
-
       BOOST_CHECK_EQUAL(rc, true);
-      NDN_LOG_DEBUG("Inserted Data " << (**i).getName());
 
       Interest readInterest((*i)->getName());
       readInterest.setMustBeFresh(true);
@@ -86,30 +79,26 @@
   }
 
   void
-  onReadData(const ndn::Interest& interest, const ndn::Data& data)
+  onReadData(const ndn::Interest&, const ndn::Data& data) const
   {
-    int rc = memcmp(data.getContent().value(), content, sizeof(content));
-    BOOST_CHECK_EQUAL(rc, 0);
+    BOOST_TEST(data.getContent().value_bytes() == CONTENT, boost::test_tools::per_element());
   }
 
   void
-  onReadTimeout(const ndn::Interest& interest)
+  onReadTimeout(const ndn::Interest& interest) const
   {
-    NDN_LOG_DEBUG("Timed out " << interest.getName());
-    BOOST_ERROR("Insert or read not successfull");
+    BOOST_ERROR("Read timeout " << interest.getName());
   }
 
   void
-  onReadNack(const ndn::Interest& interest, const ndn::lp::Nack& nack)
+  onReadNack(const ndn::Interest& interest, const ndn::lp::Nack& nack) const
   {
-    NDN_LOG_DEBUG("Nacked " << interest.getName() << nack.getReason());
-    BOOST_ERROR("Read nacked");
+    BOOST_ERROR("Read nack " << interest.getName() << " " << nack.getReason());
   }
 
   void
   sendInterest(const ndn::Interest& interest)
   {
-    NDN_LOG_DEBUG("Sending Interest " << interest.getName());
     readFace.expressInterest(interest,
                              std::bind(&BasicInterestReadFixture::onReadData, this, _1, _2),
                              std::bind(&BasicInterestReadFixture::onReadNack, this, _1, _2),
@@ -124,7 +113,6 @@
   ndn::Face readFace;
 };
 
-
 using Datasets = boost::mpl::vector<BasicDataset,
                                     FetchByPrefixDataset,
                                     SamePrefixDataset<10>>;
@@ -132,7 +120,7 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(Read, T, Datasets, BasicInterestReadFixture<T>)
 {
   this->startListen();
-  this->scheduler.schedule(1_s, std::bind(&BasicInterestReadFixture<T>::scheduleReadEvent, this));
+  this->scheduler.schedule(1_s, [this] { this->scheduleReadEvent(); });
 
   this->repoFace.processEvents(20_s);
 }
diff --git a/tests/unit/read-handle.t.cpp b/tests/unit/read-handle.t.cpp
index 1e22b4e..60a2ee2 100644
--- a/tests/unit/read-handle.t.cpp
+++ b/tests/unit/read-handle.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California.
+ * Copyright (c) 2014-2022,  Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -86,8 +86,8 @@
   auto data1 = std::make_shared<Data>(Name{dataPrefix}.appendNumber(1));
   auto data2 = std::make_shared<Data>(Name{dataPrefix}.appendNumber(2));
 
-  data1->setContent(&content[0], content.size());
-  data2->setContent(&content[0], content.size());
+  data1->setContent(content);
+  data2->setContent(content);
 
   keyChain.createIdentity(identity);
   keyChain.sign(*data1, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index 48d1ae3..da90117 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  Regents of the University of California.
+ * Copyright (c) 2014-2022,  Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -101,8 +101,7 @@
     // scatter-gather is limited to at most `min(64,IOV_MAX)` buffers to be transmitted
     // in a single operation
     for (auto i = this->data.begin(); i != this->data.end(); ++i) {
-
-      socket.async_send(boost::asio::buffer((*i)->wireEncode().wire(), (*i)->wireEncode().size()),
+      socket.async_send(boost::asio::buffer((*i)->wireEncode()),
                         std::bind(&TcpBulkInsertFixture::onSendFinished, this, _1, false));
     }
     onSendFinished(error, true);
@@ -148,7 +147,6 @@
   repo::TcpBulkInsertHandle bulkInserter;
 };
 
-
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, CommonDatasets, TcpBulkInsertFixture<T>)
 {
   BOOST_TEST_MESSAGE(T::getName());