Make use of logger provided by ndn-cxx
This commit also introduces a basic implmentation of DummyForwarder to
remove dependency on (and uncertainty of) the running instance of NFD.
Change-Id: Iba9fcbf3d3ebb1a5ae47018ad3be5d7d2b9c7462
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
index 77a0e6d..c7f69bc 100755
--- a/.jenkins.d/00-deps.sh
+++ b/.jenkins.d/00-deps.sh
@@ -9,7 +9,7 @@
if has OSX $NODE_LABELS; then
brew update
brew upgrade
- brew install boost pkg-config cryptopp openssl log4cxx protobuf tinyxml qt5
+ brew install boost pkg-config cryptopp openssl protobuf tinyxml qt5
brew cleanup
fi
@@ -18,5 +18,5 @@
sudo apt-get -qq install build-essential pkg-config libboost-all-dev \
libcrypto++-dev libsqlite3-dev libssl-dev \
libpcap-dev \
- liblog4cxx10-dev protobuf-compiler libprotobuf-dev libtinyxml-dev qt5-default
+ protobuf-compiler libprotobuf-dev libtinyxml-dev qt5-default
fi
diff --git a/.jenkins.d/02-nfd.sh b/.jenkins.d/02-nfd.sh
index a109057..4307cef 100755
--- a/.jenkins.d/02-nfd.sh
+++ b/.jenkins.d/02-nfd.sh
@@ -34,12 +34,11 @@
git submodule sync
git submodule update
-## Cleanup
-sudo ./waf -j1 --color=yes distclean
-
./waf -j1 --color=yes configure
./waf -j1 --color=yes build
sudo ./waf -j1 --color=yes install
+
+# Install default config
sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf
popd >/dev/null
diff --git a/cmd/csd.cpp b/cmd/csd.cpp
index 7363ef7..00cd434 100644
--- a/cmd/csd.cpp
+++ b/cmd/csd.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -34,8 +34,6 @@
int
main(int argc, char* argv[])
{
- INIT_LOGGERS();
-
QCoreApplication app(argc, argv);
if (argc != 4) {
diff --git a/cmd/dump-db.cpp b/cmd/dump-db.cpp
index e6245ea..3333507 100644
--- a/cmd/dump-db.cpp
+++ b/cmd/dump-db.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -30,7 +30,7 @@
using namespace std;
using namespace Ndnx;
-INIT_LOGGER("DumpDb");
+_LOG_INIT(DumpDb);
class StateLogDumper : public DbHelper
{
@@ -297,8 +297,6 @@
int
main(int argc, char* argv[])
{
- INIT_LOGGERS();
-
if (argc != 3 && !(argc == 5 && string(argv[1]) == "action")) {
cerr << "Usage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
cerr << " or: ./dump-db action <path-to-shared-folder> <device-name> <seq-no>" << endl;
diff --git a/core/logging.cpp b/core/logging.cpp
deleted file mode 100644
index 08030c9..0000000
--- a/core/logging.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016, Regents of the University of California.
- *
- * This file is part of ChronoShare, a decentralized file sharing application over NDN.
- *
- * ChronoShare 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.
- *
- * ChronoShare 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 copies of the GNU General Public License along with
- * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ChronoShare authors and contributors.
- */
-
-#include "logging.hpp"
-
-#include <log4cxx/basicconfigurator.h>
-#include <log4cxx/consoleappender.h>
-#include <log4cxx/defaultconfigurator.h>
-#include <log4cxx/helpers/exception.h>
-#include <log4cxx/level.h>
-#include <log4cxx/logger.h>
-#include <log4cxx/patternlayout.h>
-#include <log4cxx/propertyconfigurator.h>
-
-#include <unistd.h>
-
-namespace ndn {
-namespace chronoshare {
-
-using namespace log4cxx;
-using namespace log4cxx::helpers;
-
-void
-INIT_LOGGERS()
-{
- static bool configured = false;
-
- if (configured)
- return;
-
- if (access("log4cxx.properties", R_OK) == 0)
- PropertyConfigurator::configureAndWatch("log4cxx.properties");
- else {
- PatternLayoutPtr layout(new PatternLayout("%d{HH:mm:ss} %p %c{1} - %m%n"));
- ConsoleAppenderPtr appender(new ConsoleAppender(layout));
-
- BasicConfigurator::configure(appender);
- Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
- }
-
- configured = true;
-}
-
-} // chronoshare
-} // ndn
diff --git a/core/logging.hpp b/core/logging.hpp
index 86e1bf0..b7c3f34 100644
--- a/core/logging.hpp
+++ b/core/logging.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -21,43 +21,32 @@
#ifndef CHRONOSHARE_CORE_LOGGING_HPP
#define CHRONOSHARE_CORE_LOGGING_HPP
-#include "core/chronoshare-config.hpp"
-
-#include <log4cxx/logger.h>
+#include <ndn-cxx/util/logger.hpp>
namespace ndn {
namespace chronoshare {
-#define MEMBER_LOGGER static log4cxx::LoggerPtr staticModuleLogger;
+#define _LOG_INIT(name) NDN_LOG_INIT(chronoshare.name)
-#define INIT_MEMBER_LOGGER(className, name) \
- log4cxx::LoggerPtr className::staticModuleLogger = log4cxx::Logger::getLogger(name);
+#define _LOG_DEBUG(x) NDN_LOG_DEBUG(x)
-#define INIT_LOGGER(name) \
- static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name);
+#define _LOG_TRACE(x) NDN_LOG_TRACE(x)
-#define _LOG_DEBUG(x) LOG4CXX_DEBUG(staticModuleLogger, x);
-
-#define _LOG_TRACE(x) LOG4CXX_TRACE(staticModuleLogger, x);
-
-#define _LOG_FUNCTION(x) LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "(" << x << ")");
-
-#define _LOG_FUNCTION_NOARGS LOG4CXX_TRACE(staticModuleLogger, __FUNCTION__ << "()");
-
-#define _LOG_ERROR(x) LOG4CXX_ERROR(staticModuleLogger, x);
+#define _LOG_ERROR(x) NDN_LOG_ERROR(x)
#define _LOG_ERROR_COND(cond, x) \
- if (cond) { \
- _LOG_ERROR(x) \
- }
+ do { \
+ if (cond) { \
+ _LOG_ERROR(x); \
+ } \
+ } while (false)
#define _LOG_DEBUG_COND(cond, x) \
- if (cond) { \
- _LOG_DEBUG(x) \
- }
-
-void
-INIT_LOGGERS();
+ do { \
+ if (cond) { \
+ _LOG_DEBUG(x); \
+ } \
+ } while (false)
} // chronoshare
} // ndn
diff --git a/fs-watcher/fs-watcher.cpp b/fs-watcher/fs-watcher.cpp
index 9513b1c..65305a4 100644
--- a/fs-watcher/fs-watcher.cpp
+++ b/fs-watcher/fs-watcher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -30,7 +30,7 @@
using namespace std;
using namespace boost;
-INIT_LOGGER("FsWatcher");
+_LOG_INIT(FsWatcher);
FsWatcher::FsWatcher(QString dirPath, LocalFile_Change_Callback onChange,
LocalFile_Change_Callback onDelete, QObject* parent)
diff --git a/gui/chronosharegui.cpp b/gui/chronosharegui.cpp
index 781127e..1464cae 100644
--- a/gui/chronosharegui.cpp
+++ b/gui/chronosharegui.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -43,7 +43,7 @@
static const QString ICON_BIG_FILE(":/images/chronoshare-big.png");
static const QString ICON_TRAY_FILE(":/images/" TRAY_ICON);
-INIT_LOGGER("Gui");
+_LOG_INIT(Gui);
ChronoShareGui::ChronoShareGui(QWidget* parent)
: QDialog(parent)
diff --git a/gui/main.cpp b/gui/main.cpp
index 29246e5..ddebf16 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -25,8 +25,6 @@
int
main(int argc, char* argv[])
{
- INIT_LOGGERS();
-
QApplication app(argc, argv);
// do not quit when last window closes
diff --git a/osx/auto-update/sparkle-auto-update.mm b/osx/auto-update/sparkle-auto-update.mm
index 388dce7..d64079b 100644
--- a/osx/auto-update/sparkle-auto-update.mm
+++ b/osx/auto-update/sparkle-auto-update.mm
@@ -25,7 +25,7 @@
#include "logging.hpp"
-INIT_LOGGER("SparkeAutoUpdate");
+_LOG_INIT(SparkeAutoUpdate);
class SparkleAutoUpdate::Private
{
diff --git a/server/request_handler.cpp b/server/request_handler.cpp
index 1a959a1..c7b8898 100644
--- a/server/request_handler.cpp
+++ b/server/request_handler.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -47,7 +47,7 @@
namespace http {
namespace server {
-INIT_LOGGER("HttpServer")
+_LOG_INIT(HttpServer);
request_handler::request_handler(const std::string& doc_root)
: doc_root_(doc_root.c_str())
diff --git a/server/server.cpp b/server/server.cpp
index 46c983a..f52b448 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -37,7 +37,7 @@
using namespace ndn::chronoshare;
-INIT_LOGGER("HttpServer")
+_LOG_INIT(HttpServer);
server::server(const std::string& address, const std::string& port, const std::string& doc_root)
: io_service_()
diff --git a/src/action-log.cpp b/src/action-log.cpp
index f6663ae..179be79 100644
--- a/src/action-log.cpp
+++ b/src/action-log.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -27,7 +27,7 @@
using namespace std;
using namespace Ndnx;
-INIT_LOGGER("ActionLog");
+_LOG_INIT(ActionLog);
const std::string INIT_DATABASE = "\
CREATE TABLE ActionLog ( \n\
diff --git a/src/content-server.cpp b/src/content-server.cpp
index bbd9235..b795afe 100644
--- a/src/content-server.cpp
+++ b/src/content-server.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -27,7 +27,7 @@
#include <boost/make_shared.hpp>
#include <utility>
-INIT_LOGGER("ContentServer");
+_LOG_INIT(ContentServer);
using namespace Ndnx;
using namespace std;
diff --git a/src/db-helper.cpp b/src/db-helper.cpp
index 0597c12..2096138 100644
--- a/src/db-helper.cpp
+++ b/src/db-helper.cpp
@@ -26,7 +26,7 @@
namespace ndn {
namespace chronoshare {
-INIT_LOGGER("DbHelper")
+_LOG_INIT(DbHelper);
namespace fs = boost::filesystem;
diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp
index 4a07b14..be7d3c4 100644
--- a/src/dispatcher.cpp
+++ b/src/dispatcher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -30,7 +30,7 @@
using namespace std;
using namespace boost;
-INIT_LOGGER("Dispatcher");
+_LOG_INIT(Dispatcher);
static const string CHRONOSHARE_APP = "chronoshare";
static const string BROADCAST_DOMAIN = "/ndn/broadcast";
diff --git a/src/fetch-manager.cpp b/src/fetch-manager.cpp
index 27f8d6d..15ecb32 100644
--- a/src/fetch-manager.cpp
+++ b/src/fetch-manager.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -27,7 +27,7 @@
#include "logging.hpp"
#include "simple-interval-generator.hpp"
-INIT_LOGGER("FetchManager");
+_LOG_INIT(FetchManager);
using namespace boost;
using namespace std;
diff --git a/src/fetcher.cpp b/src/fetcher.cpp
index e2ee6d0..83f8491 100644
--- a/src/fetcher.cpp
+++ b/src/fetcher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -28,7 +28,7 @@
#include <boost/ref.hpp>
#include <boost/throw_exception.hpp>
-INIT_LOGGER("Fetcher");
+_LOG_INIT(Fetcher);
using namespace boost;
using namespace std;
diff --git a/src/file-state.cpp b/src/file-state.cpp
index 42e40de..33a4384 100644
--- a/src/file-state.cpp
+++ b/src/file-state.cpp
@@ -22,7 +22,7 @@
#include "logging.h"
#include <boost/bind.hpp>
-INIT_LOGGER("FileState")
+_LOG_INIT(FileState);
using namespace boost;
using namespace std;
diff --git a/src/object-db.cpp b/src/object-db.cpp
index fd4223e..e522b51 100644
--- a/src/object-db.cpp
+++ b/src/object-db.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -25,7 +25,7 @@
#include <iostream>
#include <sys/stat.h>
-INIT_LOGGER("Object.Db");
+_LOG_INIT(Object.Db);
using namespace std;
using namespace Ndnx;
diff --git a/src/object-manager.cpp b/src/object-manager.cpp
index ba3e5f2..d900098 100644
--- a/src/object-manager.cpp
+++ b/src/object-manager.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -32,7 +32,7 @@
#include <boost/throw_exception.hpp>
#include <fstream>
-INIT_LOGGER("Object.Manager");
+_LOG_INIT(Object.Manager);
using namespace Ndnx;
using namespace boost;
diff --git a/src/state-server.cpp b/src/state-server.cpp
index a013534..f84cdea 100644
--- a/src/state-server.cpp
+++ b/src/state-server.cpp
@@ -28,7 +28,7 @@
#include <boost/make_shared.hpp>
#include <utility>
-INIT_LOGGER("StateServer")
+_LOG_INIT(StateServer);
using namespace Ndnx;
using namespace std;
diff --git a/src/sync-core.cpp b/src/sync-core.cpp
index c4f9a26..f894746 100644
--- a/src/sync-core.cpp
+++ b/src/sync-core.cpp
@@ -29,7 +29,7 @@
namespace ndn {
namespace chronoshare {
-INIT_LOGGER("Sync.Core")
+_LOG_INIT(Sync.Core);
const int SyncCore::FRESHNESS = 2;
const std::string SyncCore::RECOVER = "RECOVER";
diff --git a/src/sync-log.cpp b/src/sync-log.cpp
index 4e5403d..6dde05c 100644
--- a/src/sync-log.cpp
+++ b/src/sync-log.cpp
@@ -29,7 +29,7 @@
using util::Sqlite3Statement;
-INIT_LOGGER("Sync.Log")
+_LOG_INIT(Sync.Log);
// static void
// xTrace(void*, const char* q)
@@ -101,7 +101,7 @@
, m_localName(localName)
{
sqlite3_exec(m_db, INIT_DATABASE.c_str(), NULL, NULL, NULL);
- _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, "DB Constructer: " << sqlite3_errmsg(m_db));
+ _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, "DB Constructor: " << sqlite3_errmsg(m_db));
UpdateDeviceSeqNo(localName, 0);
diff --git a/tests/logger-config-global-fixture.cpp b/tests/logger-config-global-fixture.cpp
index fab5a29..659edf9 100644
--- a/tests/logger-config-global-fixture.cpp
+++ b/tests/logger-config-global-fixture.cpp
@@ -34,8 +34,6 @@
public:
GlobalConfigurationFixture()
{
- INIT_LOGGERS();
-
if (getenv("HOME") != nullptr) {
m_home = getenv("HOME");
}
diff --git a/tests/unit-tests/action-log.t.cpp b/tests/unit-tests/action-log.t.cpp
index f598276..2281026 100644
--- a/tests/unit-tests/action-log.t.cpp
+++ b/tests/unit-tests/action-log.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -38,8 +38,6 @@
BOOST_AUTO_TEST_CASE(ActionLogTest)
{
- INIT_LOGGERS();
-
Name localName("/alex");
fs::path tmpdir = fs::unique_path(fs::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%");
diff --git a/tests/unit-tests/dispatcher.t.cpp b/tests/unit-tests/dispatcher.t.cpp
index 572db31..5270102 100644
--- a/tests/unit-tests/dispatcher.t.cpp
+++ b/tests/unit-tests/dispatcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -32,11 +32,10 @@
using namespace boost;
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.Dispatcher");
+_LOG_INIT(Test.Dispatcher);
BOOST_AUTO_TEST_SUITE(TestDispatcher)
-
void
cleanDir(fs::path dir)
{
@@ -53,8 +52,6 @@
BOOST_AUTO_TEST_CASE(DispatcherTest)
{
- INIT_LOGGERS();
-
fs::path dir1("./TestDispatcher/test-white-house");
fs::path dir2("./TestDispatcher/test-black-house");
diff --git a/tests/unit-tests/dummy-forwarder.cpp b/tests/unit-tests/dummy-forwarder.cpp
new file mode 100644
index 0000000..6ee9990
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.cpp
@@ -0,0 +1,70 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#include "dummy-forwarder.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace chronoshare {
+
+DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
+ : m_io(io)
+ , m_keyChain(keyChain)
+{
+}
+
+Face&
+DummyForwarder::addFace()
+{
+ auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain, util::
+ DummyClientFace::Options{true, true});
+ face->onSendInterest.connect([this, face] (const Interest& interest) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(interest);
+ }
+ });
+ face->onSendData.connect([this, face] (const Data& data) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(data);
+ }
+ });
+
+ face->onSendNack.connect([this, face] (const lp::Nack& nack) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(nack);
+ }
+ });
+
+ m_faces.push_back(face);
+ return *face;
+}
+
+} // namespace chronoshare
+} // namespace ndn
diff --git a/tests/unit-tests/dummy-forwarder.hpp b/tests/unit-tests/dummy-forwarder.hpp
new file mode 100644
index 0000000..ea5a736
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.hpp
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/lp/nack.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#ifndef NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
+#define NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
+
+namespace ndn {
+namespace chronoshare {
+
+/**
+ * @brief Very basic implementation of the dummy forwarder
+ *
+ * Interests expressed by any added face, will be forwarded to all other faces.
+ * Similarly, any pushed data, will be pushed to all other faces.
+ */
+class DummyForwarder
+{
+public:
+ DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain);
+
+ Face&
+ addFace();
+
+ Face&
+ getFace(size_t nFace)
+ {
+ return *m_faces.at(nFace);
+ }
+
+private:
+ boost::asio::io_service& m_io;
+ KeyChain& m_keyChain;
+ std::vector<shared_ptr<util::DummyClientFace>> m_faces;
+};
+
+} // namespace chronoshare
+} // namespace ndn
+
+#endif // NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
diff --git a/tests/unit-tests/fetch-manager.t.cpp b/tests/unit-tests/fetch-manager.t.cpp
index 24ec688..9ce544f 100644
--- a/tests/unit-tests/fetch-manager.t.cpp
+++ b/tests/unit-tests/fetch-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -25,7 +25,7 @@
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
-INIT_LOGGER("Test.FetchManager");
+_LOG_INIT(Test.FetchManager);
using namespace Ndnx;
using namespace std;
@@ -113,8 +113,6 @@
BOOST_AUTO_TEST_CASE(TestFetcher)
{
- INIT_LOGGERS();
-
CcnxWrapperPtr ccnx = make_shared<CcnxWrapper>();
Name baseName("/base");
@@ -206,8 +204,6 @@
BOOST_AUTO_TEST_CASE (TestFetcher2)
{
- INIT_LOGGERS ();
-
NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> ();
Name baseName ("/base");
diff --git a/tests/unit-tests/fetch-task-db.t.cpp b/tests/unit-tests/fetch-task-db.t.cpp
index 03c5de8..3fd940e 100644
--- a/tests/unit-tests/fetch-task-db.t.cpp
+++ b/tests/unit-tests/fetch-task-db.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -34,7 +34,7 @@
#include <unistd.h>
#include <utility>
-INIT_LOGGER("Test.FetchTaskDb");
+_LOG_INIT(Test.FetchTaskDb);
using namespace Ndnx;
using namespace std;
@@ -104,7 +104,6 @@
BOOST_AUTO_TEST_CASE(FetchTaskDbTest)
{
- INIT_LOGGERS();
fs::path folder("TaskDbTest");
fs::create_directories(folder / ".chronoshare");
diff --git a/tests/unit-tests/object-manager.t.cpp b/tests/unit-tests/object-manager.t.cpp
index c19cd75..7b721c1 100644
--- a/tests/unit-tests/object-manager.t.cpp
+++ b/tests/unit-tests/object-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -30,7 +30,7 @@
#include <iterator>
#include <unistd.h>
-INIT_LOGGER("Test.ObjectManager");
+_LOG_INIT(Test.ObjectManager);
using namespace Ndnx;
using namespace std;
@@ -41,8 +41,6 @@
BOOST_AUTO_TEST_CASE(ObjectManagerTest)
{
- INIT_LOGGERS();
-
fs::path tmpdir = fs::unique_path(fs::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%");
_LOG_DEBUG("tmpdir: " << tmpdir);
Name deviceName("/device");
diff --git a/tests/unit-tests/serve-and-fetch.t.cpp b/tests/unit-tests/serve-and-fetch.t.cpp
index d9aa6c7..da6aa1a 100644
--- a/tests/unit-tests/serve-and-fetch.t.cpp
+++ b/tests/unit-tests/serve-and-fetch.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -37,7 +37,7 @@
#include "logging.hpp"
-INIT_LOGGER("Test.ServerAndFetch");
+_LOG_INIT(Test.ServerAndFetch);
using namespace Ndnx;
using namespace std;
@@ -114,8 +114,6 @@
BOOST_AUTO_TEST_CASE(TestServeAndFetch)
{
- INIT_LOGGERS();
-
_LOG_DEBUG("Setting up test environment ...");
setup();
diff --git a/tests/unit-tests/sync-core.t.cpp b/tests/unit-tests/sync-core.t.cpp
index 5fdd5fa..d0c47f5 100644
--- a/tests/unit-tests/sync-core.t.cpp
+++ b/tests/unit-tests/sync-core.t.cpp
@@ -21,6 +21,7 @@
#include "sync-core.hpp"
#include "test-common.hpp"
+#include "dummy-forwarder.hpp"
namespace ndn {
namespace chronoshare {
@@ -28,19 +29,18 @@
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.SyncCore")
+_LOG_INIT(Test.SyncCore);
class TestSyncCoreFixture : public IdentityManagementTimeFixture
{
public:
- void
- advanceClocks()
+ TestSyncCoreFixture()
+ : forwarder(m_io, m_keyChain)
{
- for (int i = 0; i < 100; ++i) {
- usleep(10000);
- IdentityManagementTimeFixture::advanceClocks(time::milliseconds(10), 1);
- }
}
+
+public:
+ DummyForwarder forwarder;
};
BOOST_FIXTURE_TEST_SUITE(TestSyncCore, TestSyncCoreFixture)
@@ -77,47 +77,42 @@
Name loc2("/locator2");
Name syncPrefix("/broadcast/arslan");
- shared_ptr<Face> c1 = make_shared<Face>(this->m_io);
+ Face& c1 = forwarder.addFace();
auto log1 = make_shared<SyncLog>(dir1, user1);
- auto core1 = make_shared<SyncCore>(*c1, log1, user1, loc1, syncPrefix, bind(&callback, _1));
+ auto core1 = make_shared<SyncCore>(c1, log1, user1, loc1, syncPrefix, bind(&callback, _1));
- shared_ptr<Face> c2 = make_shared<Face>(this->m_io);
+ Face& c2 = forwarder.addFace();
auto log2 = make_shared<SyncLog>(dir2, user2);
- auto core2 = make_shared<SyncCore>(*c2, log2, user2, loc2, syncPrefix, bind(&callback, _1));
+ auto core2 = make_shared<SyncCore>(c2, log2, user2, loc2, syncPrefix, bind(&callback, _1));
- // @TODO: Implement test using the dummy forwarder and disable dependency on real time
-
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
- // _LOG_TRACE("\n\n\n\n\n\n----------\n");
-
core1->updateLocalState(1);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core2->seq(user1), 1);
BOOST_CHECK_EQUAL(log2->LookupLocator(user1), loc1);
core1->updateLocalState(5);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core2->seq(user1), 5);
BOOST_CHECK_EQUAL(log2->LookupLocator(user1), loc1);
core2->updateLocalState(10);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core1->seq(user2), 10);
BOOST_CHECK_EQUAL(log1->LookupLocator(user2), loc2);
// simple simultaneous data generation
- _LOG_TRACE("\n\n\n\n\n\n----------Simultaneous\n");
core1->updateLocalState(11);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
core2->updateLocalState(15);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core1->seq(user2), 15);
BOOST_CHECK_EQUAL(core2->seq(user1), 11);
diff --git a/tests/unit-tests/sync-log.t.cpp b/tests/unit-tests/sync-log.t.cpp
index bf5801e..7d4eeeb 100644
--- a/tests/unit-tests/sync-log.t.cpp
+++ b/tests/unit-tests/sync-log.t.cpp
@@ -28,8 +28,6 @@
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.SyncLog")
-
BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture)
BOOST_AUTO_TEST_CASE(BasicDatabaseTest)
diff --git a/tests/unit-tests/sync-state.pb.t.cpp b/tests/unit-tests/sync-state.pb.t.cpp
index b0ce112..d1910db 100644
--- a/tests/unit-tests/sync-state.pb.t.cpp
+++ b/tests/unit-tests/sync-state.pb.t.cpp
@@ -31,8 +31,6 @@
namespace chronoshare {
namespace tests {
-INIT_LOGGER("Test.protobuf")
-
BOOST_AUTO_TEST_SUITE(TestSyncStatePb)
BOOST_AUTO_TEST_CASE(Serialize)
diff --git a/tests/wscript b/tests/wscript
index b47447b..0b08cc0 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -22,6 +22,7 @@
target='../unit-tests',
features='cxx cxxprogram',
source=bld.path.ant_glob(['*.cpp',
+ 'unit-tests/dummy-forwarder.cpp',
'unit-tests/sync-*.t.cpp',
],
excl=['main.cpp']),
diff --git a/wscript b/wscript
index 0d03237..2148c4a 100644
--- a/wscript
+++ b/wscript
@@ -55,17 +55,15 @@
if Utils.unversioned_sys_platform() == "linux":
conf.define("TRAY_ICON", "chronoshare-ubuntu.png")
- conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
-
USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
- 'regex', 'program_options', 'thread']
+ 'regex', 'program_options', 'thread', 'log', 'log_setup']
conf.env['WITH_TESTS'] = conf.options.with_tests
if conf.env['WITH_TESTS']:
USED_BOOST_LIBS += ['unit_test_framework']
conf.define('HAVE_TESTS', 1)
- conf.check_boost(lib=USED_BOOST_LIBS)
+ conf.check_boost(lib=USED_BOOST_LIBS, mt=True)
if conf.env.BOOST_VERSION_NUMBER < 105400:
Logs.error("Minimum required boost version is 1.54.0")
Logs.error("Please upgrade your distribution or install custom boost libraries" +
@@ -86,7 +84,7 @@
target='core-objects',
features=['cxx'],
source=bld.path.ant_glob('core/**/*.cpp'),
- use='NDN_CXX LOG4CXX BOOST',
+ use='NDN_CXX BOOST',
includes='.',
export_includes='.')
@@ -108,7 +106,7 @@
'src/db-helper.cpp',
'src/sync-*.cpp',
]),
- use='core-objects adhoc BOOST LOG4CXX NDN_CXX TINYXML SQLITE3',
+ use='core-objects adhoc BOOST NDN_CXX TINYXML SQLITE3',
includes="src",
export_includes="src",
)