build: switch to C++17
Change-Id: Ia147b22fbdee68d87f0289851683ffbbb4466caa
diff --git a/tests/unit/daemon/db-mgr.t.cpp b/tests/unit/daemon/db-mgr.t.cpp
index 0b69330..a30f2dc 100644
--- a/tests/unit/daemon/db-mgr.t.cpp
+++ b/tests/unit/daemon/db-mgr.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 NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -18,7 +18,6 @@
*/
#include "daemon/db-mgr.hpp"
-#include "logger.hpp"
#include "boost-test.hpp"
@@ -29,8 +28,6 @@
namespace ndns {
namespace tests {
-NDNS_LOG_INIT(DbMgrTest);
-
BOOST_AUTO_TEST_SUITE(DbMgr)
const auto TEST_DATABASE2 = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-ndns.db";
@@ -46,7 +43,6 @@
~DbMgrFixture()
{
session.close();
- NDNS_LOG_INFO("remove database " << TEST_DATABASE2);
boost::filesystem::remove(TEST_DATABASE2);
}
@@ -113,7 +109,7 @@
rrset1.setTtl(time::seconds(4600));
static const std::string DATA1 = "SOME DATA";
- rrset1.setData(makeBinaryBlock(ndn::tlv::Content, DATA1.c_str(), DATA1.size()));
+ rrset1.setData(makeStringBlock(ndn::tlv::Content, DATA1));
BOOST_CHECK_EQUAL(rrset1.getId(), 0);
BOOST_CHECK_NO_THROW(session.insert(rrset1));
@@ -141,7 +137,7 @@
rrset1.setVersion(name::Component::fromVersion(890));
static const std::string DATA2 = "ANOTHER DATA";
- rrset1.setData(makeBinaryBlock(ndn::tlv::Content, DATA2.c_str(), DATA2.size()));
+ rrset1.setData(makeStringBlock(ndn::tlv::Content, DATA2));
BOOST_CHECK_NO_THROW(session.update(rrset1));
@@ -190,7 +186,7 @@
rrset1.setId(1);
BOOST_CHECK_NO_THROW(session.remove(rrset1));
- rrset1.setZone(0);
+ rrset1.setZone(nullptr);
rrset1.setId(1);
BOOST_CHECK_NO_THROW(session.remove(rrset1));
}
@@ -233,7 +229,7 @@
rrset1.setTtl(time::seconds(4600));
static const std::string DATA1 = "SOME DATA";
- rrset1.setData(makeBinaryBlock(ndn::tlv::Content, DATA1.data(), DATA1.size()));
+ rrset1.setData(makeStringBlock(ndn::tlv::Content, DATA1));
session.insert(rrset1);
Rrset rrset2(&zone);
@@ -242,14 +238,13 @@
rrset2.setVersion(name::Component::fromVersion(232));
rrset2.setTtl(time::seconds(2100));
std::string data2 = "host1.net";
- rrset2.setData(makeBinaryBlock(ndn::tlv::Content, data2.c_str(), data2.size()));
+ rrset2.setData(makeStringBlock(ndn::tlv::Content, data2));
session.insert(rrset2);
std::vector<Rrset> vec = session.findRrsets(zone);
BOOST_CHECK_EQUAL(vec.size(), 2);
- std::sort(vec.begin(),
- vec.end(),
+ std::sort(vec.begin(), vec.end(),
[] (const Rrset& n1, const Rrset& n2) {
return n1.getLabel().size() < n2.getLabel().size();
});
diff --git a/tests/unit/daemon/name-server.t.cpp b/tests/unit/daemon/name-server.t.cpp
index a0ec0f5..35555dd 100644
--- a/tests/unit/daemon/name-server.t.cpp
+++ b/tests/unit/daemon/name-server.t.cpp
@@ -22,7 +22,6 @@
#include "clients/query.hpp"
#include "clients/response.hpp"
#include "daemon/db-mgr.hpp"
-#include "logger.hpp"
#include "boost-test.hpp"
#include "unit/database-test-data.hpp"
@@ -34,8 +33,6 @@
namespace ndns {
namespace tests {
-NDNS_LOG_INIT(NameServerTest);
-
class NameServerFixture : public DbTestData
{
public:
@@ -76,7 +73,6 @@
face.onSendData.connectSingleShot([&] (const Data& data) {
hasDataBack = true;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
@@ -101,7 +97,6 @@
// will ask for non-existing record
face.onSendData.connectSingleShot([&] (const Data& data) {
++nDataBack;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
@@ -115,7 +110,6 @@
// will ask for the existing record (will have type NDNS_KEY, as it is certificate)
face.onSendData.connectSingleShot([&] (const Data& data) {
++nDataBack;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
@@ -173,9 +167,9 @@
re.setContentType(NDNS_RESP);
std::string str = "ns1.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
str = "ns2.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
auto data = re.toData();
m_keyChain.sign(*data, security::signingByCertificate(m_cert));
@@ -191,18 +185,17 @@
face.onSendData.connectSingleShot([&] (const Data& data) {
hasDataBack = true;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
BOOST_CHECK_NO_THROW(resp.fromData(zone, data));
BOOST_CHECK_EQUAL(resp.getContentType(), NDNS_RESP); // by default NDNS_BLOB is enough
- BOOST_CHECK_GT(resp.getRrs().size(), 0);
+ BOOST_TEST_REQUIRE(resp.getRrs().size() > 0);
Block block = resp.getRrs()[0];
block.parse();
int ret = -1;
BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
- Block::element_const_iterator val = block.elements_begin();
+ auto val = block.elements_begin();
BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
ret = readNonNegativeInteger(*val);
BOOST_CHECK_EQUAL(ret, 0);
@@ -223,9 +216,9 @@
re.setContentType(NDNS_RESP);
std::string str = "ns1.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
str = "ns2.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
auto data = re.toData();
m_keyChain.sign(*data, security::signingByCertificate(m_cert));
@@ -241,18 +234,17 @@
face.onSendData.connectSingleShot([&] (const Data& data) {
hasDataBack = true;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
BOOST_CHECK_NO_THROW(resp.fromData(zone, data));
BOOST_CHECK_EQUAL(resp.getContentType(), NDNS_RESP); // by default NDNS_BLOB is enough
- BOOST_CHECK_GT(resp.getRrs().size(), 0);
+ BOOST_TEST_REQUIRE(resp.getRrs().size() > 0);
Block block = resp.getRrs()[0];
block.parse();
int ret = -1;
BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
- Block::element_const_iterator val = block.elements_begin();
+ auto val = block.elements_begin();
BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
ret = readNonNegativeInteger(*val);
BOOST_CHECK_EQUAL(ret, 0);
@@ -284,9 +276,8 @@
m_keyChain.sign(dskCert, security::signingByCertificate(m_cert));
m_keyChain.setDefaultCertificate(dsk, dskCert);
-
- NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert.getName() << ". KeyLocator: "
- << dskCert.getKeyLocator()->getName());
+ BOOST_TEST_MESSAGE("Added Certificate=" << dskCert.getName()
+ << " KeyLocator=" << dskCert.getKeyLocator()->getName());
Rrset rrset(&m_test);
Name label = dskCert.getName().getPrefix(-2).getSubName(m_test.getName().size() + 1);
@@ -296,8 +287,7 @@
rrset.setTtl(m_test.getTtl());
rrset.setData(dskCert.wireEncode());
m_session.insert(rrset);
- NDNS_LOG_TRACE("DB: zone " << m_test << " add a CERT RR with name="
- << dskCert.getName() << " rrLabel=" << label);
+ BOOST_TEST_MESSAGE(m_test << " added CERT RR with name=" << dskCert.getName() << " label=" << label);
Response re;
re.setZone(zone);
@@ -307,9 +297,9 @@
re.setContentType(NDNS_RESP);
std::string str = "ns1.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
str = "ns2.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
auto data = re.toData();
m_keyChain.sign(*data, security::signingByCertificate(dskCert));
@@ -326,7 +316,7 @@
// no data back, since the Update cannot pass verification
face.onSendData.connectSingleShot([&] (const Data&) {
hasDataBack = true;
- BOOST_FAIL("UNEXPECTED");
+ BOOST_ERROR("unexpected onSendData");
});
face.receive(q.toInterest());
@@ -349,9 +339,8 @@
run();
validatorFace.onSendInterest.connect([this] (const Interest& interest) {
- NDNS_LOG_TRACE("validatorFace get Interest: " << interest.getName());
- auto i = interest.shared_from_this();
- io.post([i, this] { face.receive(*i); });
+ BOOST_TEST_MESSAGE("Interest on validatorFace: " << interest);
+ io.post([this, i = interest.shared_from_this()] { face.receive(*i); });
});
}
@@ -381,9 +370,9 @@
re.setContentType(NDNS_RESP);
std::string str = "ns1.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
str = "ns2.ndnsim.net";
- re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
+ re.addRr(makeStringBlock(ndns::tlv::RrData, str));
auto data = re.toData();
m_keyChain.sign(*data, security::signingByCertificate(m_cert));
@@ -396,25 +385,23 @@
q.setRrType(label::NDNS_UPDATE_LABEL);
bool hasDataBack = false;
+ auto regex = make_shared<Regex>("(<>*)<NDNS><KEY>(<>+)<CERT><>");
- shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<NDNS><KEY>(<>+)<CERT><>");
face.onSendData.connect([&] (const Data& data) {
if (regex->match(data.getName())) {
- shared_ptr<const Data> d = data.shared_from_this();
- io.post([d, this] {
- validatorFace.receive(*d); // It's data requested by validator
- });
+ io.post([this, d = data.shared_from_this()] {
+ validatorFace.receive(*d); // It's data requested by validator
+ });
}
else {
// cert is requested by validator
hasDataBack = true;
- NDNS_LOG_TRACE("get Data back");
BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
Response resp;
BOOST_CHECK_NO_THROW(resp.fromData(zone, data));
BOOST_CHECK_EQUAL(resp.getContentType(), NDNS_RESP); // by default NDNS_BLOB is enough
- BOOST_CHECK_GT(resp.getRrs().size(), 0);
+ BOOST_TEST_REQUIRE(resp.getRrs().size() > 0);
Block block = resp.getRrs()[0];
block.parse();
int ret = -1;
diff --git a/tests/unit/daemon/rrset-factory.t.cpp b/tests/unit/daemon/rrset-factory.t.cpp
index 5314dad..66c65dd 100644
--- a/tests/unit/daemon/rrset-factory.t.cpp
+++ b/tests/unit/daemon/rrset-factory.t.cpp
@@ -31,8 +31,6 @@
namespace ndns {
namespace tests {
-NDNS_LOG_INIT(RrsetFactoryTest);
-
const auto TEST_DATABASE2 = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-ndns.db";
const auto TEST_CERT = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "anchors" / "root.cert";
@@ -47,24 +45,18 @@
Zone zone1;
zone1.setName(m_zoneName);
zone1.setTtl(time::seconds(4600));
- BOOST_CHECK_NO_THROW(m_session.insert(zone1));
+ m_session.insert(zone1);
Name identityName = Name(TEST_IDENTITY_NAME).append("NDNS");
-
m_identity = m_keyChain.createIdentity(identityName);
m_cert = m_identity.getDefaultKey().getDefaultCertificate();
m_certName = m_cert.getName();
saveIdentityCert(m_identity, TEST_CERT.string());
-
- NDNS_LOG_INFO("save test root cert " << m_certName << " to: " << TEST_CERT);
- BOOST_CHECK_GT(m_certName.size(), 0);
- NDNS_LOG_TRACE("test certName: " << m_certName);
}
~RrsetFactoryFixture()
{
m_session.close();
- NDNS_LOG_INFO("remove database " << TEST_DATABASE2);
boost::filesystem::remove(TEST_DATABASE2);
boost::filesystem::remove(TEST_CERT);
}