A few code reorganizations
Change-Id: If4632fecc7085e5448226c2061e08546757eda9b
diff --git a/tests/boost-multi-log-formatter.hpp b/tests/boost-multi-log-formatter.hpp
new file mode 100644
index 0000000..ae37416
--- /dev/null
+++ b/tests/boost-multi-log-formatter.hpp
@@ -0,0 +1,214 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2015 Regents of the University of California.
+ *
+ * Based on work by Martin Ba (http://stackoverflow.com/a/26718189)
+ *
+ * This file is distributed under the Boost Software License, Version 1.0.
+ * (See http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef NDN_TESTS_BOOST_MULTI_LOG_FORMATTER_HPP
+#define NDN_TESTS_BOOST_MULTI_LOG_FORMATTER_HPP
+
+#include <boost/version.hpp>
+
+#if BOOST_VERSION >= 105900
+#include <boost/test/unit_test_parameters.hpp>
+#else
+#include <boost/test/detail/unit_test_parameters.hpp>
+#endif // BOOST_VERSION >= 105900
+
+#include <boost/test/unit_test_log_formatter.hpp>
+#include <boost/test/output/compiler_log_formatter.hpp>
+#include <boost/test/output/xml_log_formatter.hpp>
+
+namespace boost {
+namespace unit_test {
+namespace output {
+
+/**
+ * @brief Log formatter for Boost.Test that outputs the logging to multiple formatters
+ *
+ * The log formatter is designed to output to one or multiple formatters at the same time. For
+ * example, one HRF formatter can output to the standard output, while XML formatter output to
+ * the file.
+ *
+ * Usage:
+ *
+ * // Call in init_unit_test_suite: (this will override the --log_format parameter)
+ * auto formatter = new boost::unit_test::output::multi_log_formatter; // same as already configured logger
+ *
+ * // Prepare and add additional logger(s)
+ * formatter.add(std::make_shared<boost::unit_test::output::xml_log_formatter>(),
+ * std::make_shared<std::ofstream>("out.xml"));
+ *
+ * boost::unit_test::unit_test_log.set_formatter(formatter);
+ *
+ * @note Calling `boost::unit_test::unit_test_log.set_stream(...)` will change the stream for
+ * the original logger.
+ */
+class multi_log_formatter : public unit_test_log_formatter
+{
+public:
+ /**
+ * @brief Create instance of the logger, based on the configured logger instance
+ */
+ multi_log_formatter()
+ {
+ auto format =
+#if BOOST_VERSION > 105900
+ runtime_config::get<output_format>(runtime_config::LOG_FORMAT);
+#else
+ runtime_config::log_format();
+#endif // BOOST_VERSION > 105900
+
+ switch (format) {
+ default:
+#if BOOST_VERSION >= 105900
+ case OF_CLF:
+#else
+ case CLF:
+#endif // BOOST_VERSION >= 105900
+ m_loggers.push_back({std::make_shared<compiler_log_formatter>(), nullptr});
+ break;
+#if BOOST_VERSION >= 105900
+ case OF_XML:
+#else
+ case XML:
+#endif // BOOST_VERSION >= 105900
+ m_loggers.push_back({std::make_shared<xml_log_formatter>(), nullptr});
+ break;
+ }
+ }
+
+ void
+ add(std::shared_ptr<unit_test_log_formatter> formatter, std::shared_ptr<std::ostream> os)
+ {
+ m_loggers.push_back({formatter, os});
+ }
+
+ // Formatter interface
+ void
+ log_start(std::ostream& os, counter_t test_cases_amount)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_start(l.os == nullptr ? os : *l.os, test_cases_amount);
+ }
+
+ void
+ log_finish(std::ostream& os)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_finish(l.os == nullptr ? os : *l.os);
+ }
+
+ void
+ log_build_info(std::ostream& os)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_build_info(l.os == nullptr ? os : *l.os);
+ }
+
+ void
+ test_unit_start(std::ostream& os, const test_unit& tu)
+ {
+ for (auto& l : m_loggers)
+ l.logger->test_unit_start(l.os == nullptr ? os : *l.os, tu);
+ }
+
+ void
+ test_unit_finish(std::ostream& os, const test_unit& tu, unsigned long elapsed)
+ {
+ for (auto& l : m_loggers)
+ l.logger->test_unit_finish(l.os == nullptr ? os : *l.os, tu, elapsed);
+ }
+
+ void
+ test_unit_skipped(std::ostream& os, const test_unit& tu)
+ {
+ for (auto& l : m_loggers)
+ l.logger->test_unit_skipped(l.os == nullptr ? os : *l.os, tu);
+ }
+
+#if BOOST_VERSION >= 105900
+ void
+ log_exception_start(std::ostream& os, const log_checkpoint_data& lcd, const execution_exception& ex)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_exception_start(l.os == nullptr ? os : *l.os, lcd, ex);
+ }
+
+ void
+ log_exception_finish(std::ostream& os)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_exception_finish(l.os == nullptr ? os : *l.os);
+ }
+#else
+ void
+ log_exception(std::ostream& os, const log_checkpoint_data& lcd, const execution_exception& ex)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_exception(l.os == nullptr ? os : *l.os, lcd, ex);
+ }
+#endif // BOOST_VERSION >= 105900
+
+ void
+ log_entry_start(std::ostream& os, const log_entry_data& entry_data, log_entry_types let)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_entry_start(l.os == nullptr ? os : *l.os, entry_data, let);
+ }
+
+ void
+ log_entry_value(std::ostream& os, const_string value)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_entry_value(l.os == nullptr ? os : *l.os, value);
+ }
+
+ void
+ log_entry_finish(std::ostream& os)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_entry_finish(l.os == nullptr ? os : *l.os);
+ }
+
+#if BOOST_VERSION >= 105900
+ void
+ entry_context_start(std::ostream& os, log_level level)
+ {
+ for (auto& l : m_loggers)
+ l.logger->entry_context_start(l.os == nullptr ? os : *l.os, level);
+ }
+
+ void
+ log_entry_context(std::ostream& os, const_string value)
+ {
+ for (auto& l : m_loggers)
+ l.logger->log_entry_context(l.os == nullptr ? os : *l.os, value);
+ }
+
+ void
+ entry_context_finish(std::ostream& os)
+ {
+ for (auto& l : m_loggers)
+ l.logger->entry_context_finish(l.os == nullptr ? os : *l.os);
+ }
+#endif // BOOST_VERSION >= 105900
+
+private:
+ struct LoggerInfo
+ {
+ std::shared_ptr<unit_test_log_formatter> logger;
+ std::shared_ptr<std::ostream> os;
+ };
+ std::vector<LoggerInfo> m_loggers;
+};
+
+} // namespace output
+} // namespace unit_test
+} // namespace boost
+
+#endif // NDN_TESTS_BOOST_MULTI_LOG_FORMATTER_HPP
diff --git a/tests/core/auditor.t.cpp b/tests/core/auditor.t.cpp
index cf3eb02..aefb822 100644
--- a/tests/core/auditor.t.cpp
+++ b/tests/core/auditor.t.cpp
@@ -26,7 +26,8 @@
#include <boost/mpl/list.hpp>
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestAuditor)
@@ -210,4 +211,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/config.t.cpp b/tests/core/config.t.cpp
index 2cf27cc..12cca26 100644
--- a/tests/core/config.t.cpp
+++ b/tests/core/config.t.cpp
@@ -26,7 +26,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestConfig)
@@ -109,4 +110,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/db-fixture.hpp b/tests/core/db-fixture.hpp
index 7ecd215..d91bf3b 100644
--- a/tests/core/db-fixture.hpp
+++ b/tests/core/db-fixture.hpp
@@ -25,7 +25,8 @@
#include "db.hpp"
#include <boost/filesystem.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class DbFixture
@@ -50,6 +51,7 @@
};
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_TESTS_DB_FIXTURE_HPP
diff --git a/tests/core/db.t.cpp b/tests/core/db.t.cpp
index 207e565..28921b3 100644
--- a/tests/core/db.t.cpp
+++ b/tests/core/db.t.cpp
@@ -26,7 +26,8 @@
#include <ndn-cxx/encoding/buffer-stream.hpp>
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestDb, DbFixture)
@@ -164,4 +165,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/identity-fixture.hpp b/tests/core/identity-fixture.hpp
index bb3dc7b..2edb693 100644
--- a/tests/core/identity-fixture.hpp
+++ b/tests/core/identity-fixture.hpp
@@ -28,7 +28,8 @@
#include <boost/filesystem.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class IdentityFixture : public UnitTestTimeFixture
@@ -71,6 +72,7 @@
};
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_TESTS_IDENTITY_FIXTURE_HPP
diff --git a/tests/core/leaf.t.cpp b/tests/core/leaf.t.cpp
index ea20985..29221a4 100644
--- a/tests/core/leaf.t.cpp
+++ b/tests/core/leaf.t.cpp
@@ -24,7 +24,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestLeaf)
@@ -155,4 +156,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/logger-response.t.cpp b/tests/core/logger-response.t.cpp
index 9a6f0c0..e352c57 100644
--- a/tests/core/logger-response.t.cpp
+++ b/tests/core/logger-response.t.cpp
@@ -24,7 +24,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestLoggerResponse)
@@ -100,4 +101,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/logger.t.cpp b/tests/core/logger.t.cpp
index 498d05a..cba3d2c 100644
--- a/tests/core/logger.t.cpp
+++ b/tests/core/logger.t.cpp
@@ -27,7 +27,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class LoggerFixture : public IdentityFixture
@@ -35,8 +36,8 @@
{
public:
LoggerFixture()
- : face1(ndn::util::makeDummyClientFace(io, {true, true}))
- , face2(ndn::util::makeDummyClientFace(io, {true, true}))
+ : face1(io, {true, true})
+ , face2(io, {true, true})
, readInterestOffset1(0)
, readDataOffset1(0)
, readInterestOffset2(0)
@@ -53,10 +54,10 @@
{
bool hasPassed = false;
- checkFace(face1->sentInterests, readInterestOffset1, *face2, hasPassed);
- checkFace(face1->sentDatas, readDataOffset1, *face2, hasPassed);
- checkFace(face2->sentInterests, readInterestOffset2, *face1, hasPassed);
- checkFace(face2->sentDatas, readDataOffset2, *face1, hasPassed);
+ checkFace(face1.sentInterests, readInterestOffset1, face2, hasPassed);
+ checkFace(face1.sentData, readDataOffset1, face2, hasPassed);
+ checkFace(face2.sentInterests, readInterestOffset2, face1, hasPassed);
+ checkFace(face2.sentData, readDataOffset2, face1, hasPassed);
return hasPassed;
}
@@ -78,10 +79,10 @@
void
clear()
{
- face1->sentDatas.clear();
- face1->sentInterests.clear();
- face2->sentDatas.clear();
- face2->sentInterests.clear();
+ face1.sentData.clear();
+ face1.sentInterests.clear();
+ face2.sentData.clear();
+ face2.sentInterests.clear();
readInterestOffset1 = 0;
readDataOffset1 = 0;
@@ -90,8 +91,8 @@
}
public:
- shared_ptr<ndn::util::DummyClientFace> face1;
- shared_ptr<ndn::util::DummyClientFace> face2;
+ ndn::util::DummyClientFace face1;
+ ndn::util::DummyClientFace face2;
size_t readInterestOffset1;
size_t readDataOffset1;
@@ -197,7 +198,7 @@
fs::path certPath = fs::path(TEST_LOGGER_PATH) / "trust-anchor.cert";
ndn::io::save(*rootCert, certPath.string());
- Logger logger(*face1, configPath.string());
+ Logger logger(face1, configPath.string());
BOOST_CHECK_EQUAL(logger.getLoggerName(), Name("/test/logger"));
BOOST_CHECK_EQUAL(logger.getTreePrefix(), Name("/test/logger/tree"));
@@ -214,26 +215,26 @@
leafInterestName.appendNumber(0);
auto leafInterest = make_shared<Interest>(leafInterestName);
- face1->receive(*leafInterest);
+ face1.receive(*leafInterest);
advanceClocks(time::milliseconds(2), 100);
- BOOST_CHECK_EQUAL(face1->sentDatas.size(), 1);
- BOOST_CHECK(leafInterestName.isPrefixOf(face1->sentDatas[0].getName()));
+ BOOST_CHECK_EQUAL(face1.sentData.size(), 1);
+ BOOST_CHECK(leafInterestName.isPrefixOf(face1.sentData[0].getName()));
- face1->sentDatas.clear();
+ face1.sentData.clear();
Name treeInterestName("/test/logger/tree");
treeInterestName.appendNumber(0);
treeInterestName.appendNumber(0);
auto treeInterest = make_shared<Interest>(treeInterestName);
- face1->receive(*treeInterest);
+ face1.receive(*treeInterest);
advanceClocks(time::milliseconds(2), 100);
- BOOST_CHECK_EQUAL(face1->sentDatas.size(), 1);
- BOOST_CHECK(treeInterestName.isPrefixOf(face1->sentDatas[0].getName()));
+ BOOST_CHECK_EQUAL(face1.sentData.size(), 1);
+ BOOST_CHECK(treeInterestName.isPrefixOf(face1.sentData[0].getName()));
- face1->sentDatas.clear();
+ face1.sentData.clear();
Name tld("/ndn/tld");
Name tldKeyName = m_keyChain.generateRsaKeyPair(tld);
@@ -246,8 +247,8 @@
m_keyChain.signByIdentity(*tldCert, root);
m_keyChain.addCertificate(*tldCert);
- face2->setInterestFilter(tldCert->getName().getPrefix(-1),
- [&] (const ndn::InterestFilter&, const Interest&) { face2->put(*tldCert); },
+ face2.setInterestFilter(tldCert->getName().getPrefix(-1),
+ [&] (const ndn::InterestFilter&, const Interest&) { face2.put(*tldCert); },
ndn::RegisterPrefixSuccessCallback(),
[] (const Name&, const std::string&) {});
advanceClocks(time::milliseconds(2), 100);
@@ -259,7 +260,7 @@
auto logInterest = make_shared<Interest>(logInterestName);
m_keyChain.sign(*logInterest, tldCert->getName());
- face1->receive(*logInterest);
+ face1.receive(*logInterest);
do {
advanceClocks(time::milliseconds(2), 100);
} while (passPacket());
@@ -276,11 +277,11 @@
leafInterestName2.appendNumber(1);
auto leafInterest2 = make_shared<Interest>(leafInterestName2);
- face1->receive(*leafInterest2);
+ face1.receive(*leafInterest2);
advanceClocks(time::milliseconds(2), 100);
- BOOST_CHECK_EQUAL(face1->sentDatas.size(), 1);
- BOOST_CHECK(leafInterestName2.isPrefixOf(face1->sentDatas[0].getName()));
+ BOOST_CHECK_EQUAL(face1.sentData.size(), 1);
+ BOOST_CHECK(leafInterestName2.isPrefixOf(face1.sentData[0].getName()));
clear();
@@ -290,19 +291,19 @@
treeInterestName2.appendNumber(0);
auto treeInterest2 = make_shared<Interest>(treeInterestName2);
- face1->receive(*treeInterest2);
+ face1.receive(*treeInterest2);
advanceClocks(time::milliseconds(2), 100);
- BOOST_CHECK_EQUAL(face1->sentDatas.size(), 1);
- BOOST_CHECK(treeInterestName2.isPrefixOf(face1->sentDatas[0].getName()));
+ BOOST_CHECK_EQUAL(face1.sentData.size(), 1);
+ BOOST_CHECK(treeInterestName2.isPrefixOf(face1.sentData[0].getName()));
clear();
auto data = make_shared<Data>(Name("/ndn/tld/data"));
m_keyChain.sign(*data, tldCert->getName());
- face2->setInterestFilter(data->getName(),
- [&] (const ndn::InterestFilter&, const Interest&) { face2->put(*data); },
+ face2.setInterestFilter(data->getName(),
+ [&] (const ndn::InterestFilter&, const Interest&) { face2.put(*data); },
ndn::RegisterPrefixSuccessCallback(),
[] (const Name&, const std::string&) {});
advanceClocks(time::milliseconds(2), 100);
@@ -314,7 +315,7 @@
auto logInterest2 = make_shared<Interest>(logInterestName2);
m_keyChain.sign(*logInterest2, tldCert->getName());
- face1->receive(*logInterest2);
+ face1.receive(*logInterest2);
do {
advanceClocks(time::milliseconds(2), 100);
} while (passPacket());
@@ -332,4 +333,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/merkle-tree.t.cpp b/tests/core/merkle-tree.t.cpp
index 6c076dd..7893df0 100644
--- a/tests/core/merkle-tree.t.cpp
+++ b/tests/core/merkle-tree.t.cpp
@@ -26,7 +26,8 @@
#include <boost/mpl/list.hpp>
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestMerkleTree, DbFixture)
@@ -246,4 +247,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/node.t.cpp b/tests/core/node.t.cpp
index 6bd6d31..23542b2 100644
--- a/tests/core/node.t.cpp
+++ b/tests/core/node.t.cpp
@@ -25,7 +25,8 @@
#include <ndn-cxx/encoding/buffer-stream.hpp>
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestNode)
@@ -124,4 +125,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/policy-checker.t.cpp b/tests/core/policy-checker.t.cpp
index 120311b..ed861aa 100644
--- a/tests/core/policy-checker.t.cpp
+++ b/tests/core/policy-checker.t.cpp
@@ -25,7 +25,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestPolicyChecker, IdentityFixture)
@@ -190,4 +191,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/sub-tree-binary.t.cpp b/tests/core/sub-tree-binary.t.cpp
index 757668f..c29f834 100644
--- a/tests/core/sub-tree-binary.t.cpp
+++ b/tests/core/sub-tree-binary.t.cpp
@@ -25,7 +25,8 @@
#include <ndn-cxx/util/digest.hpp>
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class SubTreeBinaryTestFixture
@@ -689,4 +690,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/tree-generation-fixture.t.cpp b/tests/core/tree-generation-fixture.t.cpp
index eaf94e6..c7fa664 100644
--- a/tests/core/tree-generation-fixture.t.cpp
+++ b/tests/core/tree-generation-fixture.t.cpp
@@ -23,7 +23,8 @@
#include "boost-test.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestTreeGenerator)
@@ -109,4 +110,5 @@
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/core/unit-test-time-fixture.hpp b/tests/core/unit-test-time-fixture.hpp
index 9442c2a..253e997 100644
--- a/tests/core/unit-test-time-fixture.hpp
+++ b/tests/core/unit-test-time-fixture.hpp
@@ -26,7 +26,8 @@
#include <boost/asio.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class UnitTestTimeFixture
@@ -64,6 +65,7 @@
};
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
diff --git a/tests/global-configuration-fixture.cpp b/tests/global-configuration-fixture.cpp
new file mode 100644
index 0000000..2601b17
--- /dev/null
+++ b/tests/global-configuration-fixture.cpp
@@ -0,0 +1,78 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2017, Regents of the University of California
+ *
+ * This file is part of NDN DeLorean, An Authentication System for Data Archives in
+ * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
+ * and contributors.
+ *
+ * NDN DeLorean is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NDN
+ * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test-common.hpp"
+
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+class GlobalConfigurationFixture : boost::noncopyable
+{
+public:
+ GlobalConfigurationFixture()
+ {
+ if (getenv("HOME") != nullptr) {
+ m_home = getenv("HOME");
+ }
+ if (getenv("NDN_CLIENT_PIB") != nullptr) {
+ m_pib = getenv("NDN_CLIENT_PIB");
+ }
+ if (getenv("NDN_CLIENT_TPM") != nullptr) {
+ m_tpm = getenv("NDN_CLIENT_TPM");
+ }
+
+ boost::filesystem::path dir(TEST_HOME_PATH);
+ dir /= "test-home";
+ setenv("HOME", dir.generic_string().c_str(), 1);
+
+ setenv("NDN_CLIENT_PIB", "pib-sqlite3", 1);
+ setenv("NDN_CLIENT_TPM", "tpm-file", 1);
+ boost::filesystem::create_directories(dir);
+ }
+
+ ~GlobalConfigurationFixture()
+ {
+ if (!m_home.empty()) {
+ setenv("HOME", m_home.c_str(), 1);
+ }
+ if (!m_pib.empty()) {
+ setenv("NDN_CLIENT_PIB", m_home.c_str(), 1);
+ }
+ if (!m_tpm.empty()) {
+ setenv("NDN_CLIENT_TPM", m_home.c_str(), 1);
+ }
+ }
+
+private:
+ std::string m_home;
+ std::string m_pib;
+ std::string m_tpm;
+};
+
+BOOST_GLOBAL_FIXTURE(GlobalConfigurationFixture)
+#if (BOOST_VERSION >= 105900)
+;
+#endif // BOOST_VERSION >= 105900
+
+} // namespace tests
+} // namespace ndns
+} // namespace ndn
diff --git a/tests/home-env-fixture.cpp b/tests/home-env-fixture.cpp
deleted file mode 100644
index fcfda06..0000000
--- a/tests/home-env-fixture.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California
- *
- * This file is part of NDN DeLorean, An Authentication System for Data Archives in
- * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
- * and contributors.
- *
- * NDN DeLorean is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with NDN
- * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "common.hpp"
-#include <boost/filesystem.hpp>
-
-#include "boost-test.hpp"
-
-namespace nsl {
-namespace tests {
-
-class HomeEnvFixture
-{
-public:
- HomeEnvFixture()
- {
- // initialize KeyChain from test specific HOME: TEST_HOME_PATH
- if (std::getenv("HOME"))
- m_HOME = std::getenv("HOME");
-
- setenv("HOME", "tests/test-home", 1);
- }
-
- ~HomeEnvFixture()
- {
- boost::filesystem::remove_all(boost::filesystem::path("/tmp/test/nsl"));
-
- if (!m_HOME.empty())
- setenv("HOME", m_HOME.c_str(), 1);
- else
- unsetenv("HOME");
- }
-
-private:
- std::string m_HOME;
-
- Name m_newIdentity;
-};
-
-BOOST_GLOBAL_FIXTURE(HomeEnvFixture)
-
-} // namespace tests
-} // namespace nsl
diff --git a/tests/main.cpp b/tests/main.cpp
index 989aa93..3c980ed 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -19,7 +19,95 @@
* DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#define BOOST_TEST_MAIN 1
-#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_ALTERNATIVE_INIT_API
+#define BOOST_TEST_MODULE NDN DeLorean Unit Tests
+
+#include <boost/version.hpp>
+
+#if BOOST_VERSION >= 106200
+// Boost.Test v3.3 (Boost 1.62) natively supports multi-logger output
#include "boost-test.hpp"
+#else
+#define BOOST_TEST_NO_MAIN
+#include "boost-test.hpp"
+
+#include "boost-multi-log-formatter.hpp"
+
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options/parsers.hpp>
+
+#include <fstream>
+#include <iostream>
+
+static bool
+init_tests()
+{
+ init_unit_test();
+
+ namespace po = boost::program_options;
+ namespace ut = boost::unit_test;
+
+ po::options_description extraOptions;
+ std::string logger;
+ std::string outputFile = "-";
+ extraOptions.add_options()
+ ("log_format2", po::value<std::string>(&logger), "Type of second log formatter: HRF or XML")
+ ("log_sink2", po::value<std::string>(&outputFile)->default_value(outputFile), "Second log sink, - for stdout")
+ ;
+ po::variables_map vm;
+ try {
+ po::store(po::command_line_parser(ut::framework::master_test_suite().argc,
+ ut::framework::master_test_suite().argv)
+ .options(extraOptions)
+ .run(),
+ vm);
+ po::notify(vm);
+ }
+ catch (const std::exception& e) {
+ std::cerr << "ERROR: " << e.what() << "\n"
+ << extraOptions << std::endl;
+ return false;
+ }
+
+ if (vm.count("log_format2") == 0) {
+ // second logger is not configured
+ return true;
+ }
+
+ std::shared_ptr<ut::unit_test_log_formatter> formatter;
+ if (logger == "XML") {
+ formatter = std::make_shared<ut::output::xml_log_formatter>();
+ }
+ else if (logger == "HRF") {
+ formatter = std::make_shared<ut::output::compiler_log_formatter>();
+ }
+ else {
+ std::cerr << "ERROR: only HRF or XML log formatter can be specified" << std::endl;
+ return false;
+ }
+
+ std::shared_ptr<std::ostream> output;
+ if (outputFile == "-") {
+ output = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
+ }
+ else {
+ output = std::make_shared<std::ofstream>(outputFile.c_str());
+ }
+
+ auto multiFormatter = new ut::output::multi_log_formatter;
+ multiFormatter->add(formatter, output);
+ ut::unit_test_log.set_formatter(multiFormatter);
+
+ return true;
+}
+
+int
+main(int argc, char* argv[])
+{
+ return ::boost::unit_test::unit_test_main(&init_tests, argc, argv);
+}
+
+#endif // BOOST_VERSION >= 106200
diff --git a/tests/test-common.cpp b/tests/test-common.cpp
new file mode 100644
index 0000000..13c05d3
--- /dev/null
+++ b/tests/test-common.cpp
@@ -0,0 +1,78 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2017, Regents of the University of California
+ *
+ * This file is part of NDN DeLorean, An Authentication System for Data Archives in
+ * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
+ * and contributors.
+ *
+ * NDN DeLorean is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NDN
+ * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "test-common.hpp"
+
+#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
+
+namespace ndn {
+namespace delorean {
+namespace tests {
+
+shared_ptr<Interest>
+makeInterest(const Name& name, uint32_t nonce)
+{
+ auto interest = make_shared<Interest>(name);
+ if (nonce != 0) {
+ interest->setNonce(nonce);
+ }
+ return interest;
+}
+
+shared_ptr<Data>
+makeData(const Name& name)
+{
+ auto data = make_shared<Data>(name);
+ return signData(data);
+}
+
+Data&
+signData(Data& data)
+{
+ ndn::SignatureSha256WithRsa fakeSignature;
+ fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
+ data.setSignature(fakeSignature);
+ data.wireEncode();
+
+ return data;
+}
+
+shared_ptr<Link>
+makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations)
+{
+ auto link = make_shared<Link>(name, delegations);
+ signData(link);
+ return link;
+}
+
+lp::Nack
+makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
+{
+ Interest interest(name);
+ interest.setNonce(nonce);
+ lp::Nack nack(std::move(interest));
+ nack.setReason(reason);
+ return nack;
+}
+
+} // namespace tests
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
new file mode 100644
index 0000000..73fda1d
--- /dev/null
+++ b/tests/test-common.hpp
@@ -0,0 +1,122 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2017, Regents of the University of California
+ *
+ * This file is part of NDN DeLorean, An Authentication System for Data Archives in
+ * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
+ * and contributors.
+ *
+ * NDN DeLorean is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NDN
+ * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef NDN_DELOREAN_TESTS_TEST_COMMON_HPP
+#define NDN_DELOREAN_TESTS_TEST_COMMON_HPP
+
+#include "logger.hpp"
+
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/link.hpp>
+#include <ndn-cxx/lp/nack.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#include <boost/version.hpp>
+#include <boost/asio.hpp>
+#include <boost/filesystem.hpp>
+
+#include <fstream>
+
+#include "boost-test.hpp"
+// #include "unit-test-common-fixtures.hpp"
+// #include "identity-management-fixture.hpp"
+
+namespace ndn {
+namespace delorean {
+namespace tests {
+
+/** \brief create an Interest
+ * \param name Interest name
+ * \param nonce if non-zero, set Nonce to this value
+ * (useful for creating Nack with same Nonce)
+ */
+shared_ptr<Interest>
+makeInterest(const Name& name, uint32_t nonce = 0);
+
+/** \brief create a Data with fake signature
+ * \note Data may be modified afterwards without losing the fake signature.
+ * If a real signature is desired, sign again with KeyChain.
+ */
+shared_ptr<Data>
+makeData(const Name& name);
+
+/** \brief add a fake signature to Data
+ */
+Data&
+signData(Data& data);
+
+/** \brief add a fake signature to Data
+ */
+inline shared_ptr<Data>
+signData(shared_ptr<Data> data)
+{
+ signData(*data);
+ return data;
+}
+
+/** \brief create a Link object with fake signature
+ * \note Link may be modified afterwards without losing the fake signature.
+ * If a real signature is desired, sign again with KeyChain.
+ */
+shared_ptr<Link>
+makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations);
+
+/** \brief create a Nack
+ * \param name Interest name
+ * \param nonce Interest nonce
+ * \param reason Nack reason
+ */
+lp::Nack
+makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
+
+/** \brief replace a name component
+ * \param[inout] name name
+ * \param index name component index
+ * \param a arguments to name::Component constructor
+ */
+template<typename...A>
+void
+setNameComponent(Name& name, ssize_t index, const A& ...a)
+{
+ Name name2 = name.getPrefix(index);
+ name2.append(name::Component(a...));
+ name2.append(name.getSubName(name2.size()));
+ name = name2;
+}
+
+template<typename Packet, typename...A>
+void
+setNameComponent(Packet& packet, ssize_t index, const A& ...a)
+{
+ Name name = packet.getName();
+ setNameComponent(name, index, a...);
+ packet.setName(name);
+}
+
+} // namespace tests
+} // namespace delorean
+} // namespace ndn
+
+#endif // NDN_DELOREAN_TESTS_TEST_COMMON_HPP
diff --git a/tests/tree-generator.cpp b/tests/tree-generator.cpp
index 2689340..cc6dfda 100644
--- a/tests/tree-generator.cpp
+++ b/tests/tree-generator.cpp
@@ -22,7 +22,8 @@
#include "tree-generator.hpp"
#include <ndn-cxx/util/digest.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
const Name TreeGenerator::LOGGER_NAME("/logger/name");
@@ -113,4 +114,5 @@
}
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/tests/tree-generator.hpp b/tests/tree-generator.hpp
index 4c35084..d39d0f1 100644
--- a/tests/tree-generator.hpp
+++ b/tests/tree-generator.hpp
@@ -24,7 +24,8 @@
#include "sub-tree-binary.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tests {
class TreeGenerator
@@ -51,6 +52,7 @@
};
} // namespace tests
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_TESTS_TREE_GENERATOR_HPP