Fix logic

Change-Id: I7bfb72e8bb245fab3e9a9d575abc7217bbae86d0
diff --git a/tests/unit-tests/test-data-fetch-and-publish.cpp.outdated b/tests/integrated-tests/test-data-fetch-and-publish.cpp.outdated
similarity index 100%
rename from tests/unit-tests/test-data-fetch-and-publish.cpp.outdated
rename to tests/integrated-tests/test-data-fetch-and-publish.cpp.outdated
diff --git a/tests/integrated-tests/test-logic.cpp b/tests/integrated-tests/test-logic.cpp
new file mode 100644
index 0000000..088b8fb
--- /dev/null
+++ b/tests/integrated-tests/test-logic.cpp
@@ -0,0 +1,307 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2014 University of California, Los Angeles
+ *
+ * This file is part of ChronoSync, synchronization library for distributed realtime
+ * applications for NDN.
+ *
+ * ChronoSync 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.
+ *
+ * ChronoSync 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
+ * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "logic.hpp"
+
+#include "boost-test.hpp"
+
+namespace chronosync {
+namespace test {
+
+using std::vector;
+
+class Handler
+{
+public:
+  Handler(ndn::Face& face,
+          const Name& syncPrefix,
+          const Name& userPrefix)
+    : logic(face,
+            syncPrefix,
+            userPrefix,
+            bind(&Handler::onUpdate, this, _1))
+  {
+  }
+
+  void
+  onUpdate(const vector<MissingDataInfo>& v)
+  {
+    for (size_t i = 0; i < v.size(); i++) {
+      update(v[i].session, v[i].high, v[i].low);
+    }
+  }
+
+  void
+  update(const Name& p, const SeqNo& high, const SeqNo& low)
+  {
+    map[p] = high;
+  }
+
+  void
+  updateSeqNo(const SeqNo& seqNo)
+  {
+    logic.updateSeqNo(seqNo);
+  }
+
+  void
+  check(const Name& sessionName, const SeqNo& seqNo)
+  {
+    BOOST_CHECK_EQUAL(map[sessionName], seqNo);
+  }
+
+  Logic logic;
+  std::map<Name, SeqNo> map;
+};
+
+class LogicFixture
+{
+public:
+  LogicFixture()
+    : syncPrefix("/ndn/broadcast/sync")
+    , scheduler(io)
+  {
+    syncPrefix.appendVersion();
+    userPrefix[0] = Name("/user0");
+    userPrefix[1] = Name("/user1");
+    userPrefix[2] = Name("/user2");
+
+    faces[0] = make_shared<ndn::Face>(ref(io));
+    faces[1] = make_shared<ndn::Face>(ref(io));
+    faces[2] = make_shared<ndn::Face>(ref(io));
+  }
+
+  void
+  createHandler(size_t idx)
+  {
+    handler[idx] = make_shared<Handler>(ref(*faces[idx]), syncPrefix, userPrefix[idx]);
+  }
+
+  void
+  updateSeqNo(size_t idx, const SeqNo& seqNo)
+  {
+    handler[idx]->updateSeqNo(seqNo);
+  }
+
+  void
+  checkSeqNo(size_t sIdx, size_t dIdx, const SeqNo& seqNo)
+  {
+    handler[sIdx]->check(handler[dIdx]->logic.getSessionName(), seqNo);
+  }
+
+  void
+  terminate()
+  {
+    io.stop();
+  }
+
+  Name syncPrefix;
+  Name userPrefix[3];
+
+  boost::asio::io_service io;
+  shared_ptr<ndn::Face> faces[3];
+  ndn::Scheduler scheduler;
+  shared_ptr<Handler> handler[3];
+};
+
+BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture)
+
+void
+onUpdate(const vector<MissingDataInfo>& v)
+{
+}
+
+BOOST_AUTO_TEST_CASE(Constructor)
+{
+  Name syncPrefix("/ndn/broadcast/sync");
+  Name userPrefix("/user");
+  ndn::Face face;
+  BOOST_REQUIRE_NO_THROW(Logic(face, syncPrefix, userPrefix,
+                               bind(onUpdate, _1)));
+}
+
+BOOST_AUTO_TEST_CASE(TwoBasic)
+{
+  scheduler.scheduleEvent(ndn::time::milliseconds(100),
+                          bind(&LogicFixture::createHandler, this, 0));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(200),
+                          bind(&LogicFixture::createHandler, this, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(300),
+                          bind(&LogicFixture::updateSeqNo, this, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1000),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1100),
+                          bind(&LogicFixture::updateSeqNo, this, 0, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1800),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1900),
+                          bind(&LogicFixture::updateSeqNo, this, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2600),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2800),
+                          bind(&LogicFixture::terminate, this));
+
+  io.run();
+}
+
+BOOST_AUTO_TEST_CASE(ThreeBasic)
+{
+  scheduler.scheduleEvent(ndn::time::milliseconds(100),
+                          bind(&LogicFixture::createHandler, this, 0));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(200),
+                          bind(&LogicFixture::createHandler, this, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(300),
+                          bind(&LogicFixture::createHandler, this, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(500),
+                          bind(&LogicFixture::updateSeqNo, this, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1400),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1450),
+                          bind(&LogicFixture::checkSeqNo, this, 2, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1500),
+                          bind(&LogicFixture::updateSeqNo, this, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2400),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2450),
+                          bind(&LogicFixture::checkSeqNo, this, 2, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2500),
+                          bind(&LogicFixture::updateSeqNo, this, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4400),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4450),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4500),
+                          bind(&LogicFixture::terminate, this));
+
+  io.run();
+}
+
+BOOST_AUTO_TEST_CASE(ResetRecover)
+{
+  scheduler.scheduleEvent(ndn::time::milliseconds(100),
+                          bind(&LogicFixture::createHandler, this, 0));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(200),
+                          bind(&LogicFixture::createHandler, this, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(500),
+                          bind(&LogicFixture::updateSeqNo, this, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1400),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1500),
+                          bind(&LogicFixture::updateSeqNo, this, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2400),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2500),
+                          bind(&LogicFixture::createHandler, this, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(3000),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(3050),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(3100),
+                          bind(&LogicFixture::updateSeqNo, this, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4000),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4050),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 2, 4));
+
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4500),
+                          bind(&LogicFixture::terminate, this));
+
+  io.run();
+}
+
+BOOST_AUTO_TEST_CASE(RecoverConflict)
+{
+  scheduler.scheduleEvent(ndn::time::milliseconds(0),
+                          bind(&LogicFixture::createHandler, this, 0));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(50),
+                          bind(&LogicFixture::createHandler, this, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(100),
+                          bind(&LogicFixture::createHandler, this, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(500),
+                          bind(&LogicFixture::updateSeqNo, this, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1400),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1400),
+                          bind(&LogicFixture::checkSeqNo, this, 2, 0, 1));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1500),
+                          bind(&LogicFixture::updateSeqNo, this, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(1500),
+                          bind(&LogicFixture::updateSeqNo, this, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2400),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2450),
+                          bind(&LogicFixture::checkSeqNo, this, 0, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2500),
+                          bind(&LogicFixture::checkSeqNo, this, 1, 2, 4));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(2550),
+                          bind(&LogicFixture::checkSeqNo, this, 2, 1, 2));
+
+  scheduler.scheduleEvent(ndn::time::milliseconds(4500),
+                          bind(&LogicFixture::terminate, this));
+
+  io.run();
+}
+
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace test
+} // namespace chronosync
diff --git a/tests/unit-tests/test-socket.cpp.outdated b/tests/integrated-tests/test-socket.cpp.outdated
similarity index 100%
rename from tests/unit-tests/test-socket.cpp.outdated
rename to tests/integrated-tests/test-socket.cpp.outdated
diff --git a/tests/unit-tests/test-scheduler.cc.tmp b/tests/unit-tests/test-scheduler.cc.tmp
deleted file mode 100644
index 2a53a22..0000000
--- a/tests/unit-tests/test-scheduler.cc.tmp
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync 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.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <boost/test/unit_test.hpp>
-#include <boost/test/output_test_stream.hpp>
-#include <map>
-using boost::test_tools::output_test_stream;
-
-#include <boost/make_shared.hpp>
-#include "sync-scheduler.h"
-#include "sync-logic.h"
-
-using namespace Sync;
-using namespace std;
-using namespace boost;
-
-
-
-// void funcUpdate (const std::string &, const SeqNo &newSeq, const SeqNo &oldSeq)
-// {
-//   cout << "funcUpdate\n";
-// }
-
-// void funcRemove (const std::string &)
-// {
-//   cout << "funcRemove\n";
-// }
-
-enum SCHEDULE_LABELS
-  {
-    TEST_LABEL,
-    ANOTHER_LABEL
-  };
-
-struct SchedulerFixture
-{
-  SchedulerFixture ()
-    : counter (0)
-  {}
-
-  int counter;
-
-  Scheduler *scheduler;
-
-  void everySecond ()
-  {
-    // cout << "." << flush;
-    counter ++;
-
-    if (counter < 9)
-    scheduler->schedule (boost::posix_time::milliseconds (100),
-                         boost::bind (&SchedulerFixture::everySecond, this),
-                         TEST_LABEL);
-  }
-
-  void setCounterFive ()
-  {
-    counter = 5;
-  }
-
-  void setCounterThree ()
-  {
-    counter = 3;
-  }
-};
-
-
-#ifdef _DEBUG
-
-BOOST_FIXTURE_TEST_SUITE (SchedulerTestSuite, SchedulerFixture)
-
-BOOST_AUTO_TEST_CASE (BasicTest)
-{
-  BOOST_CHECK_NO_THROW (scheduler = new Scheduler ());
-
-  scheduler->schedule (posix_time::milliseconds (100),
-                       bind (&SchedulerFixture::everySecond, this),
-                       TEST_LABEL);
-
-  sleep (1);
-  // cout << counter << endl;
-  BOOST_CHECK_EQUAL (counter, 9); // generally, should be 9
-
-  scheduler->schedule (posix_time::seconds (2),
-		       bind (&SchedulerFixture::setCounterFive, this),
-                       TEST_LABEL);
-
-  this_thread::sleep (posix_time::milliseconds (400)); // just in case
-
-  scheduler->schedule (posix_time::milliseconds (600),
-		       bind (&SchedulerFixture::setCounterThree, this),
-                       TEST_LABEL);
-
-  this_thread::sleep (posix_time::milliseconds (500));
-  BOOST_CHECK_EQUAL (counter, 9); // still 9
-
-  this_thread::sleep (posix_time::milliseconds (200));
-  BOOST_CHECK_EQUAL (counter, 3);
-
-  this_thread::sleep (posix_time::milliseconds (1000));
-  BOOST_CHECK_EQUAL (counter, 5);
-
-  scheduler->schedule (posix_time::milliseconds (100),
-		       bind (&SchedulerFixture::setCounterThree, this),
-                       ANOTHER_LABEL);
-  this_thread::sleep (posix_time::milliseconds (50));
-  scheduler->cancel (ANOTHER_LABEL);
-  this_thread::sleep (posix_time::milliseconds (150));
-  BOOST_CHECK_EQUAL (counter, 5);
-
-  BOOST_CHECK_NO_THROW (delete scheduler);
-}
-
-BOOST_AUTO_TEST_SUITE_END ()
-
-
-void funcUpdate( const std::string &/*prefix*/, const SeqNo &/*newSeq*/, const SeqNo &/*oldSeq*/ )
-{
-}
-
-void funcPass( const std::vector<MissingDataInfo> &v)
-{
-}
-
-void funcRemove( const std::string &/*prefix*/ )
-{
-}
-
-BOOST_AUTO_TEST_CASE (SyncLogicSchedulerTest)
-{
-  SyncLogic *logic = 0;
-  BOOST_CHECK_NO_THROW (logic = new SyncLogic ("/prefix", funcPass, funcRemove));
-  this_thread::sleep (posix_time::milliseconds (100));
-
-  Scheduler &scheduler = logic->getScheduler ();
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 1);
-
-  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 2);
-
-  this_thread::sleep (posix_time::milliseconds (100)); // max waiting time
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 1);
-
-  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
-  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
-  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
-  BOOST_CHECK_NO_THROW (logic->respondSyncInterest ("/prefix/e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"));
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 5);
-
-  this_thread::sleep (posix_time::milliseconds (19)); // min waiting time is 20
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 5);
-
-  this_thread::sleep (posix_time::milliseconds (100)); // max waiting time
-  BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 1);
-
-  BOOST_CHECK_NO_THROW (delete logic);
-}
-
-#endif
diff --git a/tests/unit-tests/test-sync-logic.cpp.outdated b/tests/unit-tests/test-sync-logic.cpp.outdated
deleted file mode 100644
index e916ad5..0000000
--- a/tests/unit-tests/test-sync-logic.cpp.outdated
+++ /dev/null
@@ -1,181 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync 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.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <boost/test/unit_test.hpp>
-#include <boost/test/output_test_stream.hpp>
-#include <map>
-using boost::test_tools::output_test_stream;
-
-#include <boost/make_shared.hpp>
-
-#include <ndn-cxx/security/validator-null.hpp>
-#include "sync-logic.h"
-#include "sync-seq-no.h"
-
-using namespace std;
-using namespace boost;
-using namespace Sync;
-
-struct Handler
-{
-  string instance;
-
-  Handler (const string &_instance)
-  : instance (_instance)
-  {
-  }
-
-  void wrapper (const vector<MissingDataInfo> &v) {
-    int n = v.size();
-    for (int i = 0; i < n; i++) {
-      onUpdate (v[i].prefix, v[i].high, v[i].low);
-    }
-  }
-
-  void onUpdate (const string &p/*prefix*/, const SeqNo &seq/*newSeq*/, const SeqNo &oldSeq/*oldSeq*/)
-  {
-    m_map[p] = seq.getSeq ();
-
-    // cout << instance << "\t";
-    // if (!oldSeq.isValid ())
-    //   cout << "Inserted: " << p << " (" << seq << ")" << endl;
-    // else
-    //   cout << "Updated: " << p << "  ( " << oldSeq << ".." << seq << ")" << endl;
-  }
-
-  void onRemove (const string &p/*prefix*/)
-  {
-    // cout << instance << "\tRemoved: " << p << endl;
-    m_map.erase (p);
-  }
-
-  map<string, uint32_t> m_map;
-};
-
-class TestCore
-{
-public:
-  TestCore(ndn::shared_ptr<boost::asio::io_service> ioService)
-    : m_ioService(ioService)
-  {
-    m_l[0] = 0;
-    m_l[1] = 0;
-
-    m_validator = ndn::make_shared<ndn::ValidatorNull>();
-  }
-
-  ~TestCore()
-  {
-    if(m_l[0] != 0)
-      delete m_l[0];
-
-    if(m_l[1] != 0)
-      delete m_l[1];
-  }
-
-  void
-  finish(ndn::shared_ptr<boost::asio::io_service> ioService)
-  {
-    ioService->stop();
-  }
-
-  void
-  createSyncLogic(int index,
-                  ndn::shared_ptr<Handler> h)
-  {
-    ndn::Name identity("/tmp-" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-    ndn::shared_ptr<ndn::IdentityCertificate> cert = m_keyChain.getCertificate(m_keyChain.createIdentity(identity));
-    m_faces[index] = ndn::make_shared<ndn::Face>(ndn::ref(*m_ioService));
-    m_l[index] = new SyncLogic(ndn::Name("/bcast"),
-                               *cert,
-                               m_validator, m_faces[index],
-                               bind (&Handler::wrapper, &*h, _1),
-                               bind (&Handler::onRemove, &*h, _1));
-  }
-
-  void
-  getOldDigestForOne()
-  {
-    m_oldDigest = m_l[0]->getRootDigest();
-  }
-
-  void
-  getNewDigestForOne()
-  {
-    m_newDigest = m_l[0]->getRootDigest();
-  }
-
-  void
-  addLocalNamesForOne(ndn::Name name, uint64_t session, uint64_t seq)
-  {
-    m_l[0]->addLocalNames(name, session, seq);
-  }
-
-  void
-  removeForOne(ndn::Name name)
-  {
-    m_l[0]->remove(name);
-  }
-
-  void
-  checkDigest()
-  {
-    BOOST_CHECK(m_oldDigest != m_newDigest);
-  }
-
-
-public:
-  ndn::KeyChain m_keyChain;
-  ndn::shared_ptr<boost::asio::io_service> m_ioService;
-  SyncLogic* m_l[2];
-  ndn::shared_ptr<ndn::Face> m_faces[2];
-  ndn::shared_ptr<ndn::ValidatorNull> m_validator;
-  string m_oldDigest;
-  string m_newDigest;
-};
-
-void
-checkMapSize(ndn::shared_ptr<Handler> h, int size)
-{ BOOST_CHECK_EQUAL (h->m_map.size (), size); }
-
-
-BOOST_AUTO_TEST_CASE (SyncLogicTest)
-{
-  ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
-  ndn::Scheduler scheduler(*ioService);
-  TestCore testCore(ioService);
-
-  ndn::shared_ptr<Handler> h1 = ndn::make_shared<Handler>("1");
-  ndn::shared_ptr<Handler> h2 = ndn::make_shared<Handler>("2");
-
-  scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestCore::createSyncLogic, &testCore, 0, h1));
-  scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestCore::getOldDigestForOne, &testCore));
-  scheduler.scheduleEvent(ndn::time::milliseconds(200), ndn::bind(&TestCore::addLocalNamesForOne, &testCore, "/one", 1, 2));
-  scheduler.scheduleEvent(ndn::time::milliseconds(300), ndn::bind(&checkMapSize, h1, 0));
-  scheduler.scheduleEvent(ndn::time::milliseconds(400), ndn::bind(&TestCore::createSyncLogic, &testCore, 1, h2));
-  scheduler.scheduleEvent(ndn::time::milliseconds(500), ndn::bind(&checkMapSize, h1, 0));
-  scheduler.scheduleEvent(ndn::time::milliseconds(600), ndn::bind(&checkMapSize, h2, 1));
-  scheduler.scheduleEvent(ndn::time::milliseconds(700), ndn::bind(&TestCore::removeForOne, &testCore, "/one"));
-  scheduler.scheduleEvent(ndn::time::milliseconds(800), ndn::bind(&TestCore::getNewDigestForOne, &testCore));
-  scheduler.scheduleEvent(ndn::time::milliseconds(900), ndn::bind(&TestCore::checkDigest, &testCore));
-  scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestCore::finish, &testCore, ioService));
-
-  ioService->run();
-
-}
diff --git a/tests/unit-tests/test-sync-validator.cpp.outdated b/tests/unit-tests/test-sync-validator.cpp.outdated
deleted file mode 100644
index 7c8c300..0000000
--- a/tests/unit-tests/test-sync-validator.cpp.outdated
+++ /dev/null
@@ -1,349 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync 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.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <boost/test/unit_test.hpp>
-#include "sync-validator.h"
-
-#include <boost/lexical_cast.hpp>
-#include <boost/asio.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-
-BOOST_AUTO_TEST_SUITE(TestSyncValidator)
-
-void
-onValidated(const ndn::shared_ptr<const ndn::Data>& data)
-{
-  BOOST_CHECK(true);
-}
-
-void
-onValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
-                   const std::string& failureInfo)
-{
-  BOOST_CHECK(false);
-}
-
-void
-onValidated2(const ndn::shared_ptr<const ndn::Data>& data)
-{
-  BOOST_CHECK(false);
-}
-
-void
-onValidationFailed2(const ndn::shared_ptr<const ndn::Data>& data,
-                    const std::string& failureInfo)
-{
-  BOOST_CHECK(true);
-}
-
-void
-publishData(const uint8_t* buf, size_t len, int freshness)
-{
-}
-
-BOOST_AUTO_TEST_CASE (Graph)
-{
-  using namespace Sync;
-  using namespace ndn;
-
-  Name prefix("/Sync/TestSyncValidator/AddEdge");
-  KeyChain keychain;
-
-  Name identity1("/TestSyncValidator/AddEdge-1/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName1 = keychain.createIdentity(identity1);
-  shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
-
-  Name identity2("/TestSyncValidator/AddEdge-2/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName2 = keychain.createIdentity(identity2);
-  shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
-
-  Name identity3("/TestSyncValidator/AddEdge-3/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName3 = keychain.createIdentity(identity3);
-  shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
-
-  Name identity4("/TestSyncValidator/AddEdge-4/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName4 = keychain.createIdentity(identity4);
-  shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4);
-
-  Name identity5("/TestSyncValidator/AddEdge-5/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName5 = keychain.createIdentity(identity5);
-  shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5);
-
-  shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
-  shared_ptr<Face> face = make_shared<Face>(ref(*ioService));
-  shared_ptr<SecRuleRelative> rule;
-  SyncValidator validator(prefix, *anchor, *face,
-                          bind(&publishData, _1, _2, _3),
-                          rule);
-
-  validator.addParticipant(*introducer);
-  BOOST_CHECK(validator.canTrust(certName2));
-
-  IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1));
-  keychain.sign(introCert, certName2);
-  validator.addParticipant(introCert);
-  BOOST_CHECK(validator.canTrust(certName3));
-
-  IntroCertificate introCert1(prefix, *anchor, certName3.getPrefix(-1));
-  keychain.sign(introCert1, certName3);
-  validator.addParticipant(introCert1);
-  validator.setAnchor(*introducer);
-  BOOST_CHECK(validator.canTrust(certName2));
-  BOOST_CHECK(validator.canTrust(certName3));
-  BOOST_CHECK(validator.canTrust(certName1));
-
-  IntroCertificate introCert2(prefix, *introducee2, certName4.getPrefix(-1));
-  keychain.sign(introCert2, certName4);
-  validator.addParticipant(introCert2);
-  BOOST_CHECK(validator.canTrust(certName5) == false);
-  BOOST_CHECK(validator.canTrust(certName4) == false);
-
-  IntroCertificate introCert3(prefix, *introducee, certName5.getPrefix(-1));
-  keychain.sign(introCert3, certName5);
-  validator.addParticipant(introCert3);
-  BOOST_CHECK(validator.canTrust(certName5) == false);
-  BOOST_CHECK(validator.canTrust(certName4) == false);
-
-  validator.setAnchor(*introducee2);
-  BOOST_CHECK(validator.canTrust(certName1));
-  BOOST_CHECK(validator.canTrust(certName2));
-  BOOST_CHECK(validator.canTrust(certName3));
-  BOOST_CHECK(validator.canTrust(certName4) == false);
-  BOOST_CHECK(validator.canTrust(certName5));
-
-
-  keychain.deleteIdentity(identity1);
-  keychain.deleteIdentity(identity2);
-  keychain.deleteIdentity(identity3);
-  keychain.deleteIdentity(identity4);
-  keychain.deleteIdentity(identity5);
-}
-
-BOOST_AUTO_TEST_CASE (OfflineValidate)
-{
-  using namespace Sync;
-  using namespace ndn;
-
-  Name prefix("/Sync/TestSyncValidator/OfflineValidate");
-  KeyChain keychain;
-
-  Name identity1("/TestSyncValidator/OfflineValidate-1/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName1 = keychain.createIdentity(identity1);
-  shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
-
-  Name identity2("/TestSyncValidator/OfflineValidate-2/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName2 = keychain.createIdentity(identity2);
-  shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
-
-  Name identity3("/TestSyncValidator/OfflineValidate-3/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName3 = keychain.createIdentity(identity3);
-  shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
-
-  Name identity4("/TestSyncValidator/OfflineValidate-4/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName4 = keychain.createIdentity(identity4);
-  shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4);
-
-  Name identity5("/TestSyncValidator/OfflineValidate-5/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName5 = keychain.createIdentity(identity5);
-  shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5);
-
-  shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
-  shared_ptr<Face> face = make_shared<Face>(ref(*ioService));
-  shared_ptr<SecRuleRelative> rule;
-  SyncValidator validator(prefix, *anchor, *face,
-                          bind(&publishData, _1, _2, _3),
-                          rule);
-
-  validator.addParticipant(*introducer);
-  BOOST_CHECK(validator.canTrust(certName2));
-
-  IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1));
-  keychain.sign(introCert, certName2);
-  validator.addParticipant(introCert);
-  BOOST_CHECK(validator.canTrust(certName3));
-
-  IntroCertificate introCert2(prefix, *introducee2, certName4.getPrefix(-1));
-  keychain.sign(introCert2, certName4);
-  validator.addParticipant(introCert2);
-  BOOST_CHECK(validator.canTrust(certName5) == false);
-  BOOST_CHECK(validator.canTrust(certName4) == false);
-
-  validator.setAnchor(*introducer2);
-  BOOST_CHECK(validator.canTrust(certName1) == false);
-  BOOST_CHECK(validator.canTrust(certName2) == false);
-  BOOST_CHECK(validator.canTrust(certName3) == false);
-  BOOST_CHECK(validator.canTrust(certName4));
-  BOOST_CHECK(validator.canTrust(certName5));
-
-  Name dataName1 = prefix;
-  dataName1.append("data-1");
-  shared_ptr<Data> data1 = make_shared<Data>(dataName1);
-  keychain.sign(*data1, certName5);
-
-  validator.validate(*data1,
-		     bind(&onValidated, _1),
-		     bind(&onValidationFailed, _1, _2));
-
-  Name dataName2 = prefix;
-  dataName2.append("data-2");
-  shared_ptr<Data> data2 = make_shared<Data>(dataName2);
-  keychain.sign(*data2, certName1);
-
-  validator.validate(*data2,
-		     bind(&onValidated2, _1),
-		     bind(&onValidationFailed2, _1, _2));
-
-  // ioService->run();
-
-  keychain.deleteIdentity(identity1);
-  keychain.deleteIdentity(identity2);
-  keychain.deleteIdentity(identity3);
-  keychain.deleteIdentity(identity4);
-  keychain.deleteIdentity(identity5);
-}
-
-struct FacesFixture
-{
-  FacesFixture()
-    : regPrefixId(0)
-    , regPrefixId2(0)
-  {}
-
-  void
-  onInterest(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data)
-  {
-    face->put(*data);
-    face->unsetInterestFilter(regPrefixId);
-  }
-
-  void
-  onInterest2(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data)
-  {
-    face->put(*data);
-    face->unsetInterestFilter(regPrefixId2);
-  }
-
-  void
-  onRegFailed()
-  {}
-
-  void
-  validate(ndn::shared_ptr<Sync::SyncValidator> validator, ndn::shared_ptr<ndn::Data> data,
-           const ndn::Name& certName3, const ndn::Name& certName4)
-  {
-    validator->validate(*data,
-                        bind(&onValidated, _1),
-                        bind(&onValidationFailed, _1, _2));
-
-
-    BOOST_CHECK(validator->canTrust(certName3));
-    BOOST_CHECK(validator->canTrust(certName4));
-  }
-
-  void
-  terminate(ndn::shared_ptr<ndn::Face> face)
-  {
-    face->getIoService().stop();
-  }
-
-  const ndn::RegisteredPrefixId* regPrefixId;
-  const ndn::RegisteredPrefixId* regPrefixId2;
-};
-
-BOOST_FIXTURE_TEST_CASE(OnlineValidate, FacesFixture)
-{
-  using namespace Sync;
-  using namespace ndn;
-
-  Name prefix("/Sync/TestSyncValidator/OnlineValidate");
-  KeyChain keychain;
-
-  Name identity1("/TestSyncValidator/OnlineValidate-1/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName1 = keychain.createIdentity(identity1);
-  shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
-
-  Name identity2("/TestSyncValidator/OnlineValidate-2/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName2 = keychain.createIdentity(identity2);
-  shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
-
-  Name identity3("/TestSyncValidator/OnlineValidate-3/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName3 = keychain.createIdentity(identity3);
-  shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
-
-  Name identity4("/TestSyncValidator/OnlineValidate-4/"
-                 + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
-  Name certName4 = keychain.createIdentity(identity4);
-  shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName4);
-
-  shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
-  shared_ptr<Face> face = make_shared<Face>(ref(*ioService));
-  shared_ptr<Face> face2 = make_shared<Face>(ref(*ioService));
-
-  shared_ptr<SecRuleRelative> rule;
-  shared_ptr<SyncValidator> validator = shared_ptr<SyncValidator>
-    (new SyncValidator(prefix, *anchor, *face2, bind(&publishData, _1, _2, _3), rule));
-
-  validator->addParticipant(*introducer);
-  BOOST_CHECK(validator->canTrust(certName2));
-
-  shared_ptr<IntroCertificate> introCert = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee, certName2.getPrefix(-1)));
-  keychain.sign(*introCert, certName2);
-  BOOST_CHECK(validator->canTrust(certName3) == false);
-
-  shared_ptr<IntroCertificate> introCert2 = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee2, certName3.getPrefix(-1)));
-  keychain.sign(*introCert2, certName3);
-  BOOST_CHECK(validator->canTrust(certName4) == false);
-
-  Name dataName1 = prefix;
-  dataName1.append("data-1");
-  shared_ptr<Data> data1 = make_shared<Data>(dataName1);
-  keychain.sign(*data1, certName4);
-
-  ndn::Scheduler scheduler(*ioService);
-
-  scheduler.scheduleEvent(time::seconds(1),
-                          bind(&FacesFixture::terminate, this, face));
-
-  regPrefixId = face->setInterestFilter(introCert->getName().getPrefix(-1),
-                                       bind(&FacesFixture::onInterest, this, face, introCert),
-                                       bind(&FacesFixture::onRegFailed, this));
-
-  regPrefixId2 = face->setInterestFilter(introCert2->getName().getPrefix(-1),
-					bind(&FacesFixture::onInterest2, this, face, introCert2),
-					bind(&FacesFixture::onRegFailed, this));
-
-  scheduler.scheduleEvent(time::milliseconds(200),
-                          bind(&FacesFixture::validate, this,
-			       validator, data1, certName3, certName4));
-
-  keychain.deleteIdentity(identity1);
-  keychain.deleteIdentity(identity2);
-  keychain.deleteIdentity(identity3);
-  keychain.deleteIdentity(identity4);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/wscript b/tests/wscript
index d1a61ba..384dbba 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -4,9 +4,9 @@
 top = '..'
 
 def build(bld):
-    unit_test_main = bld(
-        target='unit-tests-main',
-        name='unit-tests-main',
+    test_main = bld(
+        target='tests-main',
+        name='tests-main',
         features='cxx',
         source=bld.path.ant_glob(['main.cpp']),
         use='ChronoSync',
@@ -16,7 +16,16 @@
         target="../unit-tests",
         source=bld.path.ant_glob(['unit-tests/**/*.cpp']),
         features=['cxx', 'cxxprogram'],
-        use='ChronoSync, unit-tests-main',
+        use='ChronoSync tests-main LOG4CXX',
+        includes=['.'],
+        install_path=None,
+        )
+
+    integrated_test = bld.program(
+        target="../integrated-tests",
+        source=bld.path.ant_glob(['integrated-tests/**/*.cpp']),
+        features=['cxx', 'cxxprogram'],
+        use='ChronoSync tests-main',
         includes=['.'],
         install_path=None,
         )