build: Making build system consistent with other NDN projects and adding unit-test framework
This commit aims only at correcting building system and adding unit-test framework.
Existing test cases (ChronoSync) are disabled temporarily and will be fixed later.
Minimum changes are made, so that the code can be built successfully.
Compiling warnings will be resolved in a later commit.
Refs: #1495
Change-Id: Ibf7119bbd77b6307cb58bbee47b61d7a7312df98
diff --git a/tests-integrated/boost-test.hpp b/tests-integrated/boost-test.hpp
new file mode 100644
index 0000000..f3b8bc0
--- /dev/null
+++ b/tests-integrated/boost-test.hpp
@@ -0,0 +1,34 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014 University of Memphis
+ * Regents of the University of California,
+ *
+ * This file is part of NLSR (Named-data Link State Routing).
+ * See AUTHORS.md for complete list of NLSR authors and contributors.
+ *
+ * NLSR 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.
+ *
+ * NLSR 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
+ * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+
+#ifndef NLSR_TESTS_INTEGRATED_BOOST_TEST_HPP
+#define NLSR_TESTS_INTEGRATED_BOOST_TEST_HPP
+
+// suppress warnings from Boost.Test
+#pragma GCC system_header
+#pragma clang system_header
+
+#include <boost/test/unit_test.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/test/output_test_stream.hpp>
+
+#endif // NLSR_TESTS_INTEGRATED_BOOST_TEST_HPP
diff --git a/tests-integrated/main.cpp b/tests-integrated/main.cpp
new file mode 100644
index 0000000..9930f26
--- /dev/null
+++ b/tests-integrated/main.cpp
@@ -0,0 +1,24 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014 University of Memphis,
+ * Regents of the University of California
+ *
+ * This file is part of NLSR (Named-data Link State Routing).
+ * See AUTHORS.md for complete list of NLSR authors and contributors.
+ *
+ * NLSR 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.
+ *
+ * NLSR 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
+ * NLSR, 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
+
+#include "boost-test.hpp"
diff --git a/tests-integrated/nsync/test-socket.cc.tmp b/tests-integrated/nsync/test-socket.cc.tmp
new file mode 100644
index 0000000..60a87f3
--- /dev/null
+++ b/tests-integrated/nsync/test-socket.cc.tmp
@@ -0,0 +1,399 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ * Chaoyi Bian <bcy@pku.edu.cn>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/output_test_stream.hpp>
+using boost::test_tools::output_test_stream;
+
+#include <boost/make_shared.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "sync-logging.h"
+#include "sync-socket.h"
+#include <ndn-cpp-dev/security/validator-null.hpp>
+
+extern "C" {
+#include <unistd.h>
+}
+
+using namespace Sync;
+using namespace std;
+using namespace boost;
+
+INIT_LOGGER ("Test.AppSocket");
+
+#define PRINT
+//std::cout << "Line: " << __LINE__ << std::endl;
+
+class TestSocketApp {
+public:
+ TestSocketApp()
+ : sum(0)
+ {}
+
+ map<ndn::Name, string> data;
+ void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
+ // _LOG_FUNCTION (this << ", " << str1);
+ ndn::Name dataName(dataPacket->getName());
+ string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()), dataPacket->getContent().value_size());
+ data.insert(make_pair(dataName, str2));
+ // cout << str1 << ", " << str2 << endl;
+ }
+
+ void set(ndn::Name name, const char * buf, int len) {
+ string str2(buf, len);
+ data.insert(make_pair(name, str2));
+ }
+
+ void setNum(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
+ int n = dataPacket->getContent().value_size() / 4;
+ uint32_t *numbers = new uint32_t [n];
+ memcpy(numbers, dataPacket->getContent().value(), dataPacket->getContent().value_size());
+ for (int i = 0; i < n; i++) {
+ sum += numbers[i];
+ }
+ delete numbers;
+
+ }
+
+ void setNum(ndn::Name name, const char * buf, int len) {
+ int n = len / 4;
+ int *numbers = new int [n];
+ memcpy(numbers, buf, len);
+ for (int i = 0; i < n; i++) {
+ sum += numbers[i];
+ }
+ delete numbers;
+ }
+
+ uint32_t sum;
+
+ void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
+ int n = v.size();
+
+ PRINT
+
+ for (int i = 0; i < n; i++) {
+ for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
+ //PRINT
+ socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1));
+ }
+ }
+ }
+
+ void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) {
+ int n = v.size();
+
+ PRINT
+
+ // std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
+ for (int i = 0; i < n; i++) {
+ // std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
+ for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
+ PRINT
+ socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
+ }
+ }
+ }
+
+ void pass(const string &prefix) {
+ }
+
+ string toString(){
+ map<ndn::Name, string>::iterator it = data.begin();
+ string str = "\n";
+ for (; it != data.end(); ++it){
+ str += "<";
+ str += it->first.toUri();
+ str += "|";
+ str += it->second;
+ str += ">";
+ str += "\n";
+ }
+
+ return str;
+ }
+
+};
+
+class TestSet1{
+public:
+ TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService)
+ : m_validator(new ndn::ValidatorNull())
+ , m_face1(new ndn::Face(ioService))
+ , m_face2(new ndn::Face(ioService))
+ , m_face3(new ndn::Face(ioService))
+ , m_p1("/irl.cs.ucla.edu")
+ , m_p2("/yakshi.org")
+ , m_p3("/google.com")
+ , m_syncPrefix("/let/us/sync")
+ {}
+
+ void
+ createSyncSocket1()
+ {
+ _LOG_DEBUG ("s1");
+ m_s1 = make_shared<SyncSocket>(m_syncPrefix, m_validator, m_face1,
+ bind(&TestSocketApp::fetchAll, &m_a1, _1, _2),
+ bind(&TestSocketApp::pass, &m_a1, _1));
+ }
+
+ void
+ createSyncSocket2()
+ {
+ _LOG_DEBUG ("s2");
+ m_s2 = make_shared<SyncSocket>(m_syncPrefix, m_validator, m_face2,
+ bind(&TestSocketApp::fetchAll, &m_a2, _1, _2),
+ bind(&TestSocketApp::pass, &m_a2, _1));
+ }
+
+ void
+ createSyncSocket3()
+ {
+ _LOG_DEBUG ("s3");
+ m_s3 = make_shared<SyncSocket>(m_syncPrefix, m_validator, m_face3,
+ bind(&TestSocketApp::fetchAll, &m_a3, _1, _2),
+ bind(&TestSocketApp::pass, &m_a3, _1));
+ }
+
+ void
+ publishSocket1(uint32_t session, string data)
+ {
+ _LOG_DEBUG ("s1 publish");
+ m_s1->publishData (m_p1, session, data.c_str(), data.size(), 1000);
+ }
+
+ void
+ publishSocket2(uint32_t session, string data)
+ {
+ _LOG_DEBUG ("s2 publish");
+ m_s2->publishData (m_p2, session, data.c_str(), data.size(), 1000);
+ }
+
+ void
+ publishSocket3(uint32_t session, string data)
+ {
+ _LOG_DEBUG ("s3 publish");
+ m_s3->publishData (m_p3, session, data.c_str(), data.size(), 1000);
+ }
+
+ void
+ setSocket1(string suffix, string data)
+ {
+ _LOG_DEBUG ("a1 set");
+ ndn::Name name = m_p1;
+ name.append(suffix);
+ m_a1.set (name, data.c_str(), data.size());
+ }
+
+ void
+ setSocket2(string suffix, string data)
+ {
+ _LOG_DEBUG ("a2 set");
+ ndn::Name name = m_p2;
+ name.append(suffix);
+ m_a2.set (name, data.c_str(), data.size());
+ }
+
+ void
+ setSocket3(string suffix, string data)
+ {
+ _LOG_DEBUG ("a3 set");
+ ndn::Name name = m_p3;
+ name.append(suffix);
+ m_a3.set (name, data.c_str(), data.size());
+ }
+
+ void
+ check(int round)
+ {
+ BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString());
+ BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString());
+ }
+
+ void
+ done()
+ {
+ m_s1.reset();
+ m_s2.reset();
+ m_s3.reset();
+ }
+
+
+ TestSocketApp m_a1, m_a2, m_a3;
+ ndn::shared_ptr<ndn::ValidatorNull> m_validator;
+ ndn::shared_ptr<ndn::Face> m_face1, m_face2, m_face3;
+ ndn::Name m_p1, m_p2, m_p3;
+ ndn::shared_ptr<SyncSocket> m_s1, m_s2, m_s3;
+ ndn::Name m_syncPrefix;
+};
+
+class TestSet2{
+public:
+ TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
+ : m_validator(new ndn::ValidatorNull())
+ , m_face1(new ndn::Face(ioService))
+ , m_face2(new ndn::Face(ioService))
+ , m_p1("/xiaonei.com")
+ , m_p2("/mitbbs.com")
+ , m_syncPrefix("/this/is/the/prefix")
+ {}
+
+ void
+ createSyncSocket1()
+ {
+ _LOG_DEBUG ("s1");
+ m_s1 = make_shared<SyncSocket>(m_syncPrefix, m_validator, m_face1,
+ bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
+ bind(&TestSocketApp::pass, &m_a1, _1));
+ }
+
+ void
+ createSyncSocket2()
+ {
+ _LOG_DEBUG ("s2");
+ m_s2 = make_shared<SyncSocket>(m_syncPrefix, m_validator, m_face2,
+ bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
+ bind(&TestSocketApp::pass, &m_a2, _1));
+ }
+
+ void
+ publishSocket1(uint32_t session, string data)
+ {
+ _LOG_DEBUG ("s1 publish");
+ m_s1->publishData (m_p1, session, data.c_str(), data.size(), 1000);
+ }
+
+ void
+ publishSocket2(uint32_t session, string data)
+ {
+ _LOG_DEBUG ("s2 publish");
+ m_s2->publishData (m_p2, session, data.c_str(), data.size(), 1000);
+ }
+
+ void
+ setSocket1(const char* ptr, size_t size)
+ {
+ _LOG_DEBUG ("a1 setNum");
+ m_a1.setNum (m_p1, ptr, size);
+ }
+
+ void
+ setSocket2(const char* ptr, size_t size)
+ {
+ _LOG_DEBUG ("a2 setNum");
+ m_a2.setNum (m_p2, ptr, size);
+ }
+
+ void
+ check(int num)
+ {
+ _LOG_DEBUG ("codnum " << num);
+ _LOG_DEBUG ("a1 sum " << m_a1.sum);
+ _LOG_DEBUG ("a2 sum " << m_a2.sum);
+
+ BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
+ }
+
+ void
+ done()
+ {
+ m_s1.reset();
+ m_s2.reset();
+ }
+
+ TestSocketApp m_a1, m_a2;
+ ndn::shared_ptr<ndn::ValidatorNull> m_validator;
+ ndn::shared_ptr<ndn::Face> m_face1, m_face2;
+ ndn::Name m_p1, m_p2;
+ ndn::shared_ptr<SyncSocket> m_s1, m_s2;
+ ndn::Name m_syncPrefix;
+};
+
+BOOST_AUTO_TEST_CASE (AppSocketTest1)
+{
+ INIT_LOGGERS ();
+
+ ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
+ ndn::Scheduler scheduler(*ioService);
+ TestSet1 testSet1(ioService);
+
+ scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
+ scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
+ scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
+ string data0 = "Very funny Scotty, now beam down my clothes";
+ scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data0));
+ scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/0", data0));
+ scheduler.scheduleEvent(ndn::time::seconds(1.16), ndn::bind(&TestSet1::check, &testSet1, 1));
+ string data1 = "Yes, give me that ketchup";
+ string data2 = "Don't look conspicuous, it draws fire";
+ scheduler.scheduleEvent(ndn::time::seconds(1.17), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data1));
+ scheduler.scheduleEvent(ndn::time::seconds(1.18), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data2));
+ scheduler.scheduleEvent(ndn::time::seconds(2.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data1));
+ scheduler.scheduleEvent(ndn::time::seconds(2.16), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data2));
+ scheduler.scheduleEvent(ndn::time::seconds(2.17), ndn::bind(&TestSet1::check, &testSet1, 2));
+ string data3 = "You surf the Internet, I surf the real world";
+ string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
+ string data5 = "Real men wear pink. Why? Because their wives make them";
+ scheduler.scheduleEvent(ndn::time::seconds(3.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, 0, data3));
+ scheduler.scheduleEvent(ndn::time::seconds(3.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data4));
+ scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data5));
+ scheduler.scheduleEvent(ndn::time::seconds(4.21), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/0", data3));
+ scheduler.scheduleEvent(ndn::time::seconds(4.22), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/0", data4));
+ scheduler.scheduleEvent(ndn::time::seconds(4.23), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/1", data5));
+ scheduler.scheduleEvent(ndn::time::seconds(4.30), ndn::bind(&TestSet1::check, &testSet1, 3));
+ // not sure weither this is simultanous data generation from multiple sources
+ _LOG_DEBUG ("Simultaneous publishing");
+ string data6 = "Shakespeare says: 'Prose before hos.'";
+ string data7 = "Pick good people, talent never wears out";
+ scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket1, &testSet1, 0, data6));
+ scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket2, &testSet1, 0, data7));
+ scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data6));
+ scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data7));
+ scheduler.scheduleEvent(ndn::time::seconds(6.90), ndn::bind(&TestSet1::check, &testSet1, 4));
+ scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet1::done, &testSet1));
+
+ ioService->run();
+}
+
+BOOST_AUTO_TEST_CASE (AppSocketTest2)
+{
+ ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
+ ndn::Scheduler scheduler(*ioService);
+ TestSet2 testSet2(ioService);
+
+ scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
+ scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
+ uint32_t num[5] = {0, 1, 2, 3, 4};
+ string data0((const char *) num, sizeof(num));
+ scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet2::publishSocket1, &testSet2, 0, data0));
+ scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
+ scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet2::check, &testSet2, 10));
+ uint32_t newNum[5] = {9, 7, 2, 1, 1};
+ string data1((const char *) newNum, sizeof(newNum));
+ scheduler.scheduleEvent(ndn::time::seconds(1.10), ndn::bind(&TestSet2::publishSocket2, &testSet2, 0, data1));
+ scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
+ scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet2::check, &testSet2, 30));
+ scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet2::done, &testSet2));
+
+ ioService->run();
+}
diff --git a/tests-integrated/nsync/test-sync-logic.cc.tmp b/tests-integrated/nsync/test-sync-logic.cc.tmp
new file mode 100644
index 0000000..d2444e7
--- /dev/null
+++ b/tests-integrated/nsync/test-sync-logic.cc.tmp
@@ -0,0 +1,179 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ * Chaoyi Bian <bcy@pku.edu.cn>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#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-cpp-dev/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()
+ {
+ }
+
+ void
+ createSyncLogic(int index,
+ ndn::shared_ptr<Handler> h)
+ {
+ m_faces[index] = ndn::make_shared<ndn::Face>(m_ioService);
+ m_l[index] = new SyncLogic(ndn::Name("/bcast"),
+ 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::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::seconds(0), ndn::bind(&TestCore::createSyncLogic, &testCore, 0, h1));
+ scheduler.scheduleEvent(ndn::time::seconds(0.1), ndn::bind(&TestCore::getOldDigestForOne, &testCore));
+ scheduler.scheduleEvent(ndn::time::seconds(0.2), ndn::bind(&TestCore::addLocalNamesForOne, &testCore, "/one", 1, 2));
+ scheduler.scheduleEvent(ndn::time::seconds(0.3), ndn::bind(&checkMapSize, h1, 0));
+ scheduler.scheduleEvent(ndn::time::seconds(0.4), ndn::bind(&TestCore::createSyncLogic, &testCore, 1, h2));
+ scheduler.scheduleEvent(ndn::time::seconds(0.5), ndn::bind(&checkMapSize, h1, 0));
+ scheduler.scheduleEvent(ndn::time::seconds(0.6), ndn::bind(&checkMapSize, h2, 1));
+ scheduler.scheduleEvent(ndn::time::seconds(0.7), ndn::bind(&TestCore::removeForOne, &testCore, "/one"));
+ scheduler.scheduleEvent(ndn::time::seconds(0.8), ndn::bind(&TestCore::getNewDigestForOne, &testCore));
+ scheduler.scheduleEvent(ndn::time::seconds(0.9), ndn::bind(&TestCore::checkDigest, &testCore));
+ scheduler.scheduleEvent(ndn::time::seconds(1.0), ndn::bind(&TestCore::finish, &testCore));
+
+ ioService->run();
+
+}
diff --git a/tests-integrated/wscript b/tests-integrated/wscript
new file mode 100644
index 0000000..13ed609
--- /dev/null
+++ b/tests-integrated/wscript
@@ -0,0 +1,50 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+"""
+Copyright (c) 2014 University of Memphis
+ Regents of the University of California,
+
+This file is part of NLSR (Named-data Link State Routing).
+See AUTHORS.md for complete list of NLSR authors and contributors.
+
+NLSR 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.
+
+NLSR 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
+NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+top = '..'
+
+def build(bld):
+ if bld.env['WITH_TESTS']:
+ integrated_test_main = bld(
+ target='integrated-tests-main',
+ name='integrated-tests-main',
+ features='cxx',
+ source=bld.path.ant_glob(['*.cpp']),
+ use='nlsr-objects',
+ )
+
+ integrated_test_nsync = bld.program (
+ target="../integrated-tests-nsync",
+ features="cxx cxxprogram",
+ source=bld.path.ant_glob(['nsync/**/*.cc']),
+ use='nsync-objects integrated-tests-main',
+ includes='.',
+ install_path=None,
+ )
+
+ integrated_test_nlsr = bld.program (
+ target="../integrated-tests-nlsr",
+ features="cxx cxxprogram",
+ source=bld.path.ant_glob(['nlsr/**/*.cpp']),
+ use='nlsr-objects integrated-tests-main',
+ includes='.',
+ install_path=None,
+ )