A few code reorganizations
Change-Id: If4632fecc7085e5448226c2061e08546757eda9b
diff --git a/common.hpp b/common.hpp
index a3cf9fb..40a48ce 100644
--- a/common.hpp
+++ b/common.hpp
@@ -54,7 +54,8 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/scoped_ptr.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
using std::size_t;
@@ -88,6 +89,7 @@
namespace name = ndn::name;
namespace time = ndn::time;
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_COMMON_HPP
diff --git a/core/auditor.cpp b/core/auditor.cpp
index b2db2b7..ce17b04 100644
--- a/core/auditor.cpp
+++ b/core/auditor.cpp
@@ -23,7 +23,8 @@
#include <ndn-cxx/util/digest.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
bool
Auditor::doesExist(const NonNegativeInteger& seqNo,
@@ -74,7 +75,7 @@
size_t childLevel = 0;
ndn::ConstBufferPtr childHash = hash;
- NonNegativeInteger parentSeqMask = (~0) << 1;
+ NonNegativeInteger parentSeqMask = (~0ul) << 1;
NonNegativeInteger parentSeqNo = childSeqNo & parentSeqMask;
size_t parentLevel = 1;
@@ -237,4 +238,5 @@
return true;
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/auditor.hpp b/core/auditor.hpp
index 87e67b5..f47e856 100644
--- a/core/auditor.hpp
+++ b/core/auditor.hpp
@@ -29,7 +29,8 @@
#include <ndn-cxx/encoding/buffer.hpp>
#include <vector>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class Auditor
{
@@ -57,6 +58,7 @@
const Name& loggerName);
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_AUDITOR_HPP
diff --git a/core/conf/checker.cpp b/core/conf/checker.cpp
index d00bb34..30d6d2b 100644
--- a/core/conf/checker.cpp
+++ b/core/conf/checker.cpp
@@ -23,7 +23,8 @@
#include <boost/algorithm/string.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
Checker::~Checker()
@@ -173,4 +174,5 @@
}
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/conf/checker.hpp b/core/conf/checker.hpp
index 17117aa..f618f92 100644
--- a/core/conf/checker.hpp
+++ b/core/conf/checker.hpp
@@ -30,7 +30,8 @@
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
class Checker
@@ -93,6 +94,7 @@
};
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CONF_CHECKER_HPP
diff --git a/core/conf/config-file.cpp b/core/conf/config-file.cpp
index ffb8051..fd1902b 100644
--- a/core/conf/config-file.cpp
+++ b/core/conf/config-file.cpp
@@ -22,7 +22,8 @@
#include "config-file.hpp"
#include <boost/property_tree/info_parser.hpp>
#include <boost/filesystem.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
ConfigFile::ConfigFile(const std::string& filename)
@@ -94,4 +95,5 @@
}
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/conf/config-file.hpp b/core/conf/config-file.hpp
index e86def2..1ed2fab 100644
--- a/core/conf/config-file.hpp
+++ b/core/conf/config-file.hpp
@@ -25,7 +25,8 @@
#include "common.hpp"
#include "config.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
class ConfigFile
{
@@ -74,6 +75,7 @@
};
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CONF_CONFIG_FILE_HPP
diff --git a/core/conf/config.hpp b/core/conf/config.hpp
index 7bffe63..c515d70 100644
--- a/core/conf/config.hpp
+++ b/core/conf/config.hpp
@@ -24,7 +24,8 @@
#include <boost/property_tree/ptree.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
typedef boost::property_tree::ptree ConfigSection;
@@ -40,6 +41,7 @@
};
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CONF_CONFIG_HPP
diff --git a/core/conf/filter.cpp b/core/conf/filter.cpp
index 7f4c945..bb18236 100644
--- a/core/conf/filter.cpp
+++ b/core/conf/filter.cpp
@@ -23,7 +23,8 @@
#include <boost/algorithm/string.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
Filter::~Filter()
@@ -154,4 +155,5 @@
}
} // namespace conf
+} // namespace delorean
} // namespace ndn
diff --git a/core/conf/filter.hpp b/core/conf/filter.hpp
index 65a58ce..7c26720 100644
--- a/core/conf/filter.hpp
+++ b/core/conf/filter.hpp
@@ -26,7 +26,8 @@
#include "config.hpp"
#include <ndn-cxx/util/regex.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
/**
@@ -105,6 +106,7 @@
};
} // namespace conf
+} // namespace delorean
} // namespace ndn
#endif // NDN_DELOREAN_CONF_FILTER_HPP
diff --git a/core/conf/key-locator-checker.cpp b/core/conf/key-locator-checker.cpp
index 8e21677..c2f808d 100644
--- a/core/conf/key-locator-checker.cpp
+++ b/core/conf/key-locator-checker.cpp
@@ -23,7 +23,8 @@
#include <boost/algorithm/string.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
KeyLocatorChecker::~KeyLocatorChecker()
@@ -274,4 +275,5 @@
}
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/conf/key-locator-checker.hpp b/core/conf/key-locator-checker.hpp
index 97f270b..7cc2937 100644
--- a/core/conf/key-locator-checker.hpp
+++ b/core/conf/key-locator-checker.hpp
@@ -26,7 +26,8 @@
#include "config.hpp"
#include <ndn-cxx/util/regex.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
class KeyLocatorCheckerFactory;
@@ -122,6 +123,7 @@
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP
diff --git a/core/conf/rule.cpp b/core/conf/rule.cpp
index 55dc59d..efaac3e 100644
--- a/core/conf/rule.cpp
+++ b/core/conf/rule.cpp
@@ -21,7 +21,8 @@
#include "rule.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
Rule::Rule(const std::string& id)
@@ -78,4 +79,5 @@
}
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/conf/rule.hpp b/core/conf/rule.hpp
index 47a70fd..2133efe 100644
--- a/core/conf/rule.hpp
+++ b/core/conf/rule.hpp
@@ -25,7 +25,8 @@
#include "filter.hpp"
#include "checker.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace conf {
class Rule
@@ -68,6 +69,7 @@
};
} // namespace conf
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CONF_RULE_HPP
diff --git a/core/db.cpp b/core/db.cpp
index 22474df..d87707f 100644
--- a/core/db.cpp
+++ b/core/db.cpp
@@ -25,7 +25,8 @@
#include <string>
#include <boost/filesystem.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
static const std::string INITIALIZATION =
"CREATE TABLE IF NOT EXISTS \n"
@@ -306,4 +307,5 @@
return m_nextLeafSeqNo;
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/db.hpp b/core/db.hpp
index b722efe..071371f 100644
--- a/core/db.hpp
+++ b/core/db.hpp
@@ -29,7 +29,8 @@
struct sqlite3;
-namespace nsl {
+namespace ndn {
+namespace delorean {
class Db : noncopyable
{
@@ -79,6 +80,7 @@
NonNegativeInteger m_nextLeafSeqNo;
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_DB_HPP
diff --git a/core/leaf.cpp b/core/leaf.cpp
index 36dd275..1046b15 100644
--- a/core/leaf.cpp
+++ b/core/leaf.cpp
@@ -25,7 +25,8 @@
#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/util/crypto.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
const Name Leaf::EMPTY_NAME;
const size_t Leaf::N_LOGGER_LEAF_SUFFIX = 4;
@@ -251,4 +252,5 @@
throw Error("No more sub-TLV in LoggerLeaf");
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/leaf.hpp b/core/leaf.hpp
index 4ee11d3..fa07cab 100644
--- a/core/leaf.hpp
+++ b/core/leaf.hpp
@@ -27,7 +27,8 @@
#include "util/timestamp.hpp"
#include <ndn-cxx/encoding/buffer.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class Leaf
{
@@ -138,6 +139,7 @@
Name m_loggerName;
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_LEAF_HPP
diff --git a/core/logger-response.cpp b/core/logger-response.cpp
index c36f932..4b67ed5 100644
--- a/core/logger-response.cpp
+++ b/core/logger-response.cpp
@@ -22,7 +22,8 @@
#include "logger-response.hpp"
#include "tlv.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
LoggerResponse::LoggerResponse()
: m_code(-1)
@@ -128,4 +129,5 @@
throw Error("No more sub-TLV in log response");
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/logger-response.hpp b/core/logger-response.hpp
index d773ab2..2ba5491 100644
--- a/core/logger-response.hpp
+++ b/core/logger-response.hpp
@@ -26,7 +26,8 @@
#include "util/non-negative-integer.hpp"
#include <ndn-cxx/encoding/buffer.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class LoggerResponse
{
@@ -93,6 +94,7 @@
mutable Block m_wire;
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP
diff --git a/core/logger.cpp b/core/logger.cpp
index 983a44d..8349f7b 100644
--- a/core/logger.cpp
+++ b/core/logger.cpp
@@ -23,7 +23,8 @@
#include "tlv.hpp"
#include "conf/config-file.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
const int Logger::N_DATA_FETCHING_RETRIAL = 2;
@@ -302,4 +303,5 @@
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/logger.hpp b/core/logger.hpp
index f685495..08b910e 100644
--- a/core/logger.hpp
+++ b/core/logger.hpp
@@ -28,11 +28,13 @@
#include "policy-checker.hpp"
#include "merkle-tree.hpp"
#include "util/non-negative-integer.hpp"
+
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/validator-config.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class Logger
{
@@ -135,6 +137,7 @@
PolicyChecker m_policyChecker;
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_LOGGER_HPP
diff --git a/core/merkle-tree.cpp b/core/merkle-tree.cpp
index 2219d2f..300456a 100644
--- a/core/merkle-tree.cpp
+++ b/core/merkle-tree.cpp
@@ -21,7 +21,8 @@
#include "merkle-tree.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
MerkleTree::MerkleTree(Db& db)
: m_db(db)
@@ -215,4 +216,5 @@
m_pendingTrees[newSibling->getPeakIndex().level] = newSibling;
}
-}// namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/merkle-tree.hpp b/core/merkle-tree.hpp
index f1baa46..c388fe9 100644
--- a/core/merkle-tree.hpp
+++ b/core/merkle-tree.hpp
@@ -27,7 +27,8 @@
#include "sub-tree-binary.hpp"
#include <vector>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class MerkleTree
{
@@ -103,6 +104,7 @@
std::map<size_t, shared_ptr<SubTreeBinary>> m_pendingTrees;
};
-}// namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_MERKLE_TREE_HPP
diff --git a/core/node.cpp b/core/node.cpp
index d0882e4..74716e6 100644
--- a/core/node.cpp
+++ b/core/node.cpp
@@ -24,7 +24,8 @@
#include <ndn-cxx/util/digest.hpp>
#include <boost/lexical_cast.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
ndn::ConstBufferPtr Node::EMPTY_HASH;
@@ -121,4 +122,5 @@
return EMPTY_HASH;
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/node.hpp b/core/node.hpp
index a9cb487..ef0db61 100644
--- a/core/node.hpp
+++ b/core/node.hpp
@@ -26,7 +26,8 @@
#include "util/non-negative-integer.hpp"
#include <ndn-cxx/encoding/buffer.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class Node
{
@@ -119,6 +120,7 @@
typedef shared_ptr<Node> NodePtr;
typedef shared_ptr<const Node> ConstNodePtr;
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_NODE_HPP
diff --git a/core/policy-checker.cpp b/core/policy-checker.cpp
index 97464a1..34e2582 100644
--- a/core/policy-checker.cpp
+++ b/core/policy-checker.cpp
@@ -24,7 +24,8 @@
#include <ndn-cxx/security/validator.hpp>
#include <boost/algorithm/string.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
using ndn::time::system_clock;
@@ -55,8 +56,6 @@
void
PolicyChecker::onConfigRule(const conf::ConfigSection& section)
{
- using namespace nsl::conf;
-
auto it = section.begin();
// Get rule.id
@@ -82,7 +81,7 @@
throw Error("Unrecognized <rule.for>: " + usage + " in rule: " + ruleId);
// Get rule.filter(s)
- std::vector<shared_ptr<Filter> > filters;
+ std::vector<shared_ptr<conf::Filter> > filters;
for (; it != section.end(); it++) {
if (!boost::iequals(it->first, "filter")) {
if (boost::iequals(it->first, "checker"))
@@ -90,17 +89,17 @@
throw Error("Expect <rule.filter> in rule: " + ruleId);
}
- filters.push_back(FilterFactory::create(it->second));
+ filters.push_back(conf::FilterFactory::create(it->second));
continue;
}
// Get rule.checker(s)
- std::vector<shared_ptr<Checker> > checkers;
+ std::vector<shared_ptr<conf::Checker> > checkers;
for (; it != section.end(); it++) {
if (!boost::iequals(it->first, "checker"))
throw Error("Expect <rule.checker> in rule: " + ruleId);
- checkers.push_back(CheckerFactory::create(it->second));
+ checkers.push_back(conf::CheckerFactory::create(it->second));
continue;
}
@@ -167,4 +166,5 @@
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/policy-checker.hpp b/core/policy-checker.hpp
index 1194316..2f04788 100644
--- a/core/policy-checker.hpp
+++ b/core/policy-checker.hpp
@@ -30,7 +30,8 @@
#include <ndn-cxx/security/identity-certificate.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
class PolicyChecker
{
@@ -71,6 +72,7 @@
DataRuleList m_dataRules;
};
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_POLICY_CHECKER_HPP
diff --git a/core/sub-tree-binary.cpp b/core/sub-tree-binary.cpp
index 26cef84..ad3b7a2 100644
--- a/core/sub-tree-binary.cpp
+++ b/core/sub-tree-binary.cpp
@@ -25,7 +25,8 @@
#include <ndn-cxx/util/crypto.hpp>
#include <ndn-cxx/security/digest-sha256.hpp>
-namespace nsl {
+namespace ndn {
+namespace delorean {
const time::milliseconds SubTreeBinary::INCOMPLETE_FRESHNESS_PERIOD(60000);
const std::string SubTreeBinary::COMPONENT_COMPLETE("complete");
@@ -468,4 +469,5 @@
updateParentNode(parentNode);
}
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
diff --git a/core/sub-tree-binary.hpp b/core/sub-tree-binary.hpp
index ba52e1b..56fd66d 100644
--- a/core/sub-tree-binary.hpp
+++ b/core/sub-tree-binary.hpp
@@ -24,7 +24,8 @@
#include "node.hpp"
-namespace nsl {
+namespace ndn {
+namespace delorean {
typedef std::function<void(const Node::Index&)> CompleteCallback;
typedef std::function<void(const Node::Index&,
@@ -177,6 +178,7 @@
typedef shared_ptr<SubTreeBinary> SubTreeBinaryPtr;
typedef shared_ptr<const SubTreeBinary> ConstSubTreeBinaryPtr;
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_SUB_TREE_HPP
diff --git a/core/tlv.hpp b/core/tlv.hpp
index d36f772..eb66e53 100644
--- a/core/tlv.hpp
+++ b/core/tlv.hpp
@@ -22,7 +22,8 @@
#ifndef NDN_DELOREAN_CORE_TLV_HPP
#define NDN_DELOREAN_CORE_TLV_HPP
-namespace nsl {
+namespace ndn {
+namespace delorean {
namespace tlv {
/**
@@ -47,6 +48,7 @@
};
} // namespace tlv
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_CORE_TLV_HPP
diff --git a/core/util/non-negative-integer.hpp b/core/util/non-negative-integer.hpp
index 08afe34..5b034f7 100644
--- a/core/util/non-negative-integer.hpp
+++ b/core/util/non-negative-integer.hpp
@@ -22,10 +22,12 @@
#ifndef NDN_DELOREAN_UTIL_NON_NEGATIVE_INTEGER_HPP
#define NDN_DELOREAN_UTIL_NON_NEGATIVE_INTEGER_HPP
-namespace nsl {
+namespace ndn {
+namespace delorean {
typedef uint64_t NonNegativeInteger;
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_UTIL_NON_NEGATIVE_INTEGER_HPP
diff --git a/core/util/timestamp.hpp b/core/util/timestamp.hpp
index a35a09d..cecc046 100644
--- a/core/util/timestamp.hpp
+++ b/core/util/timestamp.hpp
@@ -22,10 +22,12 @@
#ifndef NDN_DELOREAN_UTIL_TIMESTAMP_HPP
#define NDN_DELOREAN_UTIL_TIMESTAMP_HPP
-namespace nsl {
+namespace ndn {
+namespace delorean {
typedef uint64_t Timestamp;
-} // namespace nsl
+} // namespace delorean
+} // namespace ndn
#endif // NDN_DELOREAN_UTIL_TIMESTAMP_HPP
diff --git a/daemon/main.cpp b/daemon/main.cpp
index ee8c9fd..57ad8ba 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -19,6 +19,7 @@
* DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "common.hpp"
#include "../core/logger.hpp"
#include <boost/program_options/options_description.hpp>
@@ -26,7 +27,6 @@
#include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp>
-
int
main(int argc, char** argv)
{
@@ -62,11 +62,11 @@
if (vm.count("config") == 0) {
if (!getenv("HOME")) {
- configFile = "/usr/local/etc/ndn/nsl.conf";
+ configFile = NDN_DELOREAN_DEFAULT_CONFIG_FILE;
}
else {
configFile = getenv("HOME");
- configFile += "/.ndn/nsl.conf";
+ configFile += "/.ndn/ndn-delorean.conf";
}
if (!fs::exists(fs::path(configFile))) {
@@ -77,7 +77,7 @@
try {
ndn::Face face;
- nsl::Logger(face, configFile);
+ ndn::delorean::Logger(face, configFile);
face.processEvents();
}
catch (std::runtime_error& e) {
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