build: switch to C++17
Change-Id: Ia147b22fbdee68d87f0289851683ffbbb4466caa
diff --git a/tests/unit/clients/response.t.cpp b/tests/unit/clients/response.t.cpp
index 97a6fe0..a24505e 100644
--- a/tests/unit/clients/response.t.cpp
+++ b/tests/unit/clients/response.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.
@@ -33,7 +33,6 @@
Name zone("/net");
name::Component qType = ndns::label::NDNS_ITERATIVE_QUERY;
-
ndns::Response r(zone, qType);
r.setRrLabel(Name("/ndnsim/www"));
r.setRrType(label::CERT_RR_TYPE);
@@ -47,7 +46,7 @@
BOOST_CHECK_EQUAL(r.getQueryType(), qType);
const std::string DATA1("some fake content");
- r.setAppContent(makeBinaryBlock(ndn::tlv::Content, DATA1.c_str(), DATA1.size()));
+ r.setAppContent(makeStringBlock(ndn::tlv::Content, DATA1));
//const Block& block = r.wireEncode();
shared_ptr<Data> data = r.toData();
@@ -63,10 +62,9 @@
r4.setContentType(NDNS_RESP);
std::string str = "Just try it";
- Block s = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size());
+ Block s = makeStringBlock(ndns::tlv::RrData, str);
r4.addRr(s);
str = "Go to Hell";
- // Block s2 = makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size());
r4.addRr(str);
BOOST_CHECK_NE(r2, r4);
@@ -78,7 +76,7 @@
BOOST_CHECK_EQUAL(r5.fromData(zone, *data), true);
BOOST_CHECK_EQUAL(r4, r5);
- }
+}
BOOST_AUTO_TEST_SUITE_END()
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);
}
diff --git a/tests/unit/database-test-data.cpp b/tests/unit/database-test-data.cpp
index 9188eff..f77c5be 100644
--- a/tests/unit/database-test-data.cpp
+++ b/tests/unit/database-test-data.cpp
@@ -30,8 +30,6 @@
namespace ndns {
namespace tests {
-NDNS_LOG_INIT(TestFakeData);
-
const fs::path DbTestData::TEST_DATABASE = fs::path(UNIT_TESTS_TMPDIR) / "test-ndns.db";
const Name DbTestData::TEST_IDENTITY_NAME("/test19");
const fs::path DbTestData::TEST_CERT = fs::path(UNIT_TESTS_TMPDIR) / "anchors" / "root.cert";
@@ -44,13 +42,11 @@
}
DbTestData::DbTestData()
- : m_session(TEST_DATABASE.string()),
- m_testName("/test19"),
- m_netName("/test19/net"),
- m_ndnsimName("/test19/net/ndnsim")
+ : m_session(TEST_DATABASE.string())
+ , m_testName("/test19")
+ , m_netName("/test19/net")
+ , m_ndnsimName("/test19/net/ndnsim")
{
- NDNS_LOG_TRACE("start creating test data");
-
NdnsValidatorBuilder::VALIDATOR_CONF_FILE = (fs::path(UNIT_TESTS_TMPDIR) / "validator.conf").string();
ManagementTool tool(TEST_DATABASE.string(), m_keyChain);
@@ -81,18 +77,15 @@
m_identity = CertHelper::getIdentity(m_keyChain, identityName);
m_certName = CertHelper::getDefaultCertificateNameOfIdentity(m_keyChain, identityName);
m_cert = CertHelper::getCertificate(m_keyChain, identityName, m_certName);
+ BOOST_ASSERT(!m_certName.empty());
io::save(m_cert, TEST_CERT.string());
- NDNS_LOG_INFO("save test root cert " << m_certName << " to: " << TEST_CERT.string());
-
- BOOST_ASSERT(!m_certName.empty());
- NDNS_LOG_TRACE("test certName: " << m_certName);
int certificateIndex = 0;
auto addQueryRrset = [this, &certificateIndex] (const Name& label, Zone& zone,
const name::Component& type) {
const time::seconds ttl(3000 + 100 * certificateIndex);
- const name::Component version = name::Component::fromVersion(100 + 1000 * certificateIndex);
+ const auto version = name::Component::fromVersion(100 + 1000 * certificateIndex);
name::Component qType(label::NDNS_ITERATIVE_QUERY);
NdnsContentType contentType = NDNS_RESP;
if (type == label::APPCERT_RR_TYPE) {
@@ -122,8 +115,6 @@
// last link is the same as former one
BOOST_ASSERT(!m_links.empty());
m_links.push_back(m_links.back());
-
- NDNS_LOG_INFO("insert testing data: OK");
}
void
diff --git a/tests/unit/mgmt/management-tool.t.cpp b/tests/unit/mgmt/management-tool.t.cpp
index 97282d1..d4f6234 100644
--- a/tests/unit/mgmt/management-tool.t.cpp
+++ b/tests/unit/mgmt/management-tool.t.cpp
@@ -447,8 +447,7 @@
// Check certificate freshnessPeriod and validity
Certificate cert = CertHelper::getCertificate(m_keyChain, zoneIdentityName, dsk);
- time::system_clock::TimePoint beg,end;
- std::tie(beg, end) = cert.getValidityPeriod().getPeriod();
+ auto [beg, end] = cert.getValidityPeriod().getPeriod();
BOOST_REQUIRE_NO_THROW(cert = findCertFromDb(zone, dsk));
BOOST_CHECK_EQUAL(cert.getFreshnessPeriod(), time::seconds(4200));