Migrate to C++17 and misc code cleanups
Change-Id: I6b63385c92361a7ef5803d2bfd00f39c77e88d34
diff --git a/tests/dataset-fixtures.hpp b/tests/dataset-fixtures.hpp
index 0d93347..77866a0 100644
--- a/tests/dataset-fixtures.hpp
+++ b/tests/dataset-fixtures.hpp
@@ -25,8 +25,7 @@
#include <vector>
#include <boost/mpl/vector.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
class DatasetBase : public virtual IdentityManagementFixture
{
@@ -37,82 +36,62 @@
using std::runtime_error::runtime_error;
};
- using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
- DataContainer data;
-
- using InterestContainer = std::list<std::pair<ndn::Interest, std::shared_ptr<ndn::Data>>>;
- InterestContainer interests;
-
- using RemovalsContainer = std::list<std::pair<ndn::Interest, size_t>>;
- RemovalsContainer removals;
+ std::list<std::shared_ptr<Data>> data;
+ std::list<std::pair<Interest, std::shared_ptr<Data>>> interests;
+ std::list<std::pair<Interest, size_t>> removals;
protected:
- std::shared_ptr<ndn::Data>
- createData(const ndn::Name& name)
+ std::shared_ptr<Data>
+ createData(const Name& name)
{
- if (map.count(name) > 0)
- return map[name];
+ auto it = m_map.find(name);
+ if (it != m_map.end())
+ return it->second;
static const std::vector<uint8_t> content(1500, '-');
- auto data = std::make_shared<ndn::Data>(name);
+ auto data = std::make_shared<Data>(name);
data->setContent(content);
m_keyChain.sign(*data);
- map.insert(std::make_pair(name, data));
+ m_map.emplace(name, data);
return data;
}
- std::shared_ptr<ndn::Data>
- getData(const ndn::Name& name)
+ std::shared_ptr<Data>
+ getData(const Name& name) const
{
- if (map.count(name) > 0)
- return map[name];
- else
- NDN_THROW(Error("Data with name " + name.toUri() + " is not found"));
+ auto it = m_map.find(name);
+ if (it != m_map.end())
+ return it->second;
+
+ NDN_THROW(Error("Data with name " + name.toUri() + " not found"));
}
private:
- std::map<Name, std::shared_ptr<Data>> map;
+ std::map<Name, std::shared_ptr<Data>> m_map;
};
-
template<size_t N>
class SamePrefixDataset : public DatasetBase
{
public:
- static const std::string&
- getName()
- {
- static std::string name = "SamePrefixDataset";
- return name;
- }
-
SamePrefixDataset()
{
- ndn::Name baseName("/x/y/z/test/1");
+ const Name baseName("/x/y/z/test/1");
for (size_t i = 0; i < N; i++) {
- ndn::Name name(baseName);
+ Name name(baseName);
name.appendSegment(i);
- std::shared_ptr<Data> data = createData(name);
+ auto data = createData(name);
this->data.push_back(data);
-
- this->interests.push_back(std::make_pair(Interest(name), data));
+ this->interests.emplace_back(Interest(name), data);
}
}
};
-
class BasicDataset : public DatasetBase
{
public:
- static const std::string&
- getName()
- {
- static std::string name = "BasicDataset";
- return name;
- }
-
BasicDataset()
{
this->data.push_back(createData("/a"));
@@ -120,10 +99,10 @@
this->data.push_back(createData("/a/b/c"));
this->data.push_back(createData("/a/b/c/d"));
- this->interests.push_back(std::make_pair(Interest("/a"), getData("/a")));
- this->interests.push_back(std::make_pair(Interest("/a/b"), getData("/a/b")));
- this->interests.push_back(std::make_pair(Interest("/a/b/c"), getData("/a/b/c")));
- this->interests.push_back(std::make_pair(Interest("/a/b/c/d"), getData("/a/b/c/d")));
+ this->interests.emplace_back(Interest("/a"), getData("/a"));
+ this->interests.emplace_back(Interest("/a/b"), getData("/a/b"));
+ this->interests.emplace_back(Interest("/a/b/c"), getData("/a/b/c"));
+ this->interests.emplace_back(Interest("/a/b/c/d"), getData("/a/b/c/d"));
}
};
@@ -131,13 +110,6 @@
class FetchByPrefixDataset : public DatasetBase
{
public:
- static const std::string&
- getName()
- {
- static std::string name = "FetchByPrefixDataset";
- return name;
- }
-
FetchByPrefixDataset()
{
this->data.push_back(createData("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"));
@@ -205,7 +177,6 @@
FetchByPrefixDataset,
SamePrefixDataset<10>,
SamePrefixDataset<100>>;
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
#endif // REPO_TESTS_DATASET_FIXTURES_HPP
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 681e076..ef5ab5c 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.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.
@@ -18,15 +18,16 @@
*/
#include "identity-management-fixture.hpp"
+
#include <ndn-cxx/security/pib/identity.hpp>
#include <ndn-cxx/security/pib/key.hpp>
#include <ndn-cxx/security/pib/pib.hpp>
#include <ndn-cxx/security/certificate.hpp>
#include <ndn-cxx/util/io.hpp>
+
#include <boost/filesystem.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
IdentityManagementFixture::IdentityManagementFixture()
: m_keyChain("pib-memory:", "tpm-memory:")
@@ -78,5 +79,4 @@
}
}
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index 300c53a..57e26f1 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, 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,10 +21,10 @@
#define REPO_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
#include "common.hpp"
+
#include <ndn-cxx/security/key-chain.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
/** \brief a fixture providing an in-memory KeyChain
*/
@@ -60,7 +60,6 @@
std::vector<std::string> m_certFiles;
};
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
#endif // REPO_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
diff --git a/tests/integrated/command-fixture.cpp b/tests/integrated/command-fixture.cpp
index ad7955a..28990e3 100644
--- a/tests/integrated/command-fixture.cpp
+++ b/tests/integrated/command-fixture.cpp
@@ -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.
@@ -19,8 +19,7 @@
#include "command-fixture.hpp"
-namespace repo {
-namespace tests {
+namespace repo::tests {
CommandFixture::CommandFixture()
: scheduler(repoFace.getIoService())
@@ -33,5 +32,4 @@
validator.load("tests/integrated/insert-delete-validator-config.conf");
}
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/integrated/command-fixture.hpp b/tests/integrated/command-fixture.hpp
index 601f0b9..6d4aa44 100644
--- a/tests/integrated/command-fixture.hpp
+++ b/tests/integrated/command-fixture.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,11 +21,11 @@
#define REPO_TESTS_INTEGRATED_COMMAND_FIXTURE_HPP
#include "../identity-management-fixture.hpp"
-#include <ndn-cxx/security/validator-null.hpp>
-#include <ndn-cxx/mgmt/dispatcher.hpp>
-namespace repo {
-namespace tests {
+#include <ndn-cxx/mgmt/dispatcher.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
+
+namespace repo::tests {
class CommandFixture : public virtual IdentityManagementFixture
{
@@ -35,13 +35,12 @@
protected:
Face repoFace;
Scheduler scheduler;
- KeyChain& keyChain;
+ ndn::KeyChain& keyChain;
ndn::mgmt::Dispatcher dispatcher;
/// \todo #4091 switch to ValidatorPolicyConf and load insert-delete-validator-config.conf
- ValidatorConfig validator;
+ ndn::security::ValidatorConfig validator;
};
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
#endif // REPO_TESTS_INTEGRATED_COMMAND_FIXTURE_HPP
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 5ed5b9b..55d6e65 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -35,8 +35,7 @@
#include <boost/mpl/vector.hpp>
#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
using ndn::time::milliseconds;
@@ -288,5 +287,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index ab3da01..ed62466 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -27,10 +27,7 @@
#include <boost/asio/io_service.hpp>
#include <boost/test/unit_test.hpp>
-#include <ndn-cxx/util/time.hpp>
-
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(TestBasicInterestRead)
@@ -127,5 +124,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/repo-storage-fixture.hpp b/tests/repo-storage-fixture.hpp
index 9a82169..f573736 100644
--- a/tests/repo-storage-fixture.hpp
+++ b/tests/repo-storage-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2018, Regents of the University of California.
+/*
+ * Copyright (c) 2018-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,12 +21,11 @@
#define REPO_TESTS_REPO_STORAGE_FIXTURE_HPP
#include "storage/repo-storage.hpp"
+#include "storage/sqlite-storage.hpp"
#include <boost/filesystem.hpp>
-#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
class RepoStorageFixture
{
@@ -42,13 +41,11 @@
boost::filesystem::remove_all(boost::filesystem::path("unittestdb"));
}
-
public:
std::shared_ptr<Storage> store;
std::shared_ptr<RepoStorage> handle;
};
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
#endif // REPO_TESTS_REPO_STORAGE_FIXTURE_HPP
diff --git a/tests/sqlite-fixture.hpp b/tests/sqlite-fixture.hpp
index a2eba12..c478d64 100644
--- a/tests/sqlite-fixture.hpp
+++ b/tests/sqlite-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, 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.
@@ -23,10 +23,8 @@
#include "storage/sqlite-storage.hpp"
#include <boost/filesystem.hpp>
-#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
class SqliteFixture
{
@@ -46,7 +44,6 @@
SqliteStorage* handle;
};
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
#endif // REPO_TESTS_SQLITE_FIXTURE_HPP
diff --git a/tests/unit/read-handle.t.cpp b/tests/unit/read-handle.t.cpp
index 60a2ee2..a6bfed5 100644
--- a/tests/unit/read-handle.t.cpp
+++ b/tests/unit/read-handle.t.cpp
@@ -35,8 +35,7 @@
BOOST_CHECK_EQUAL(didMatch, EXPECTED); \
} while (false)
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(TestReadHandle)
@@ -57,7 +56,7 @@
}
static bool
- containsNameComponent(const Name& name, const ndn::name::Component& component)
+ containsNameComponent(const Name& name, const Name::Component& component)
{
for (const auto& c : name) {
if (c == component)
@@ -91,42 +90,41 @@
keyChain.createIdentity(identity);
keyChain.sign(*data1, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
- identity));
+ identity));
keyChain.sign(*data2, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
- identity));
+ identity));
face.sentInterests.clear();
handle->insertData(*data1);
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"register"}, true);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, true);
face.sentInterests.clear();
handle->deleteData(data1->getFullName());
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, true);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, true);
face.sentInterests.clear();
handle->insertData(*data1);
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"register"}, true);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, true);
face.sentInterests.clear();
handle->insertData(*data2);
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"register"}, false);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"register"}, false);
face.sentInterests.clear();
handle->deleteData(data1->getFullName());
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, false);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, false);
face.sentInterests.clear();
handle->deleteData(data2->getFullName());
face.processEvents(-1_ms);
- CHECK_INTERESTS(interest.getName(), name::Component{"unregister"}, true);
+ CHECK_INTERESTS(interest.getName(), Name::Component{"unregister"}, true);
}
BOOST_AUTO_TEST_SUITE_END() // TestReadHandle
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/unit/repo-command-parameter.cpp b/tests/unit/repo-command-parameter.cpp
index f01832a..94429fe 100644
--- a/tests/unit/repo-command-parameter.cpp
+++ b/tests/unit/repo-command-parameter.cpp
@@ -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.
@@ -18,17 +18,14 @@
*/
#include "repo-command-parameter.hpp"
-
#include "common.hpp"
-#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/encoding/block-helpers.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(RepoCommandParameter)
@@ -58,5 +55,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/unit/repo-command-response.cpp b/tests/unit/repo-command-response.cpp
index 057b180..1fc9f5d 100644
--- a/tests/unit/repo-command-response.cpp
+++ b/tests/unit/repo-command-response.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2018, Regents of the University of California.
+ * Copyright (c) 2018-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.
@@ -23,8 +23,7 @@
#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(RepoCommandResponse)
@@ -59,5 +58,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/unit/repo-storage.cpp b/tests/unit/repo-storage.cpp
index 4f89d6b..9743933 100644
--- a/tests/unit/repo-storage.cpp
+++ b/tests/unit/repo-storage.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.
@@ -18,17 +18,12 @@
*/
#include "storage/repo-storage.hpp"
-#include "storage/sqlite-storage.hpp"
#include "../dataset-fixtures.hpp"
#include "../repo-storage-fixture.hpp"
-#include <boost/mpl/push_back.hpp>
#include <boost/test/unit_test.hpp>
-#include <iostream>
-#include <string.h>
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(RepoStorage)
@@ -37,11 +32,8 @@
{
};
-
BOOST_FIXTURE_TEST_CASE_TEMPLATE(Bulk, T, CommonDatasets, Fixture<T>)
{
- BOOST_TEST_MESSAGE(T::getName());
-
// Insert data into repo
for (auto i = this->data.begin(); i != this->data.end(); ++i) {
BOOST_CHECK_EQUAL(this->handle->insertData(**i), true);
@@ -52,7 +44,7 @@
// Read
for (auto i = this->interests.begin(); i != this->interests.end(); ++i) {
- std::shared_ptr<ndn::Data> dataTest = this->handle->readData(i->first);
+ auto dataTest = this->handle->readData(i->first);
BOOST_CHECK_EQUAL(*dataTest, *i->second);
}
@@ -73,10 +65,8 @@
std::vector<Name> names;
handle->afterDataInsertion.connect([&] (const Name& name) {
- names.push_back(name);
- BOOST_TEST_MESSAGE("Got notification about " << name);
- });
-
+ names.push_back(name);
+ });
handle->notifyAboutExistingData();
BOOST_CHECK_EQUAL(names.size(), this->data.size());
@@ -84,5 +74,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/unit/sqlite-handle.cpp b/tests/unit/sqlite-handle.cpp
index 9cfb0bf..d3ae687 100644
--- a/tests/unit/sqlite-handle.cpp
+++ b/tests/unit/sqlite-handle.cpp
@@ -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.
@@ -25,8 +25,7 @@
#include <boost/test/unit_test.hpp>
#include <random>
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(SqliteStorage)
@@ -39,13 +38,10 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, CommonDatasets, Fixture<T>)
{
- BOOST_TEST_CHECKPOINT(T::getName());
-
std::vector<Name> names;
// Insert
- for (auto i = this->data.begin();
- i != this->data.end(); ++i) {
+ for (auto i = this->data.begin(); i != this->data.end(); ++i) {
Name name = Name();
this->handle->insert(**i);
name = (*i)->getFullName();
@@ -76,5 +72,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index da90117..9b7b796 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -24,8 +24,7 @@
#include <boost/test/unit_test.hpp>
-namespace repo {
-namespace tests {
+namespace repo::tests {
BOOST_AUTO_TEST_SUITE(TcpBulkInsertHandle)
@@ -149,8 +148,6 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(BulkInsertAndRead, T, CommonDatasets, TcpBulkInsertFixture<T>)
{
- BOOST_TEST_MESSAGE(T::getName());
-
// start bulk inserter
this->bulkInserter.listen("localhost", "17376");
@@ -168,5 +165,4 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace repo
+} // namespace repo::tests