Fix compilation with latest ndn-cxx
Change-Id: Iaf468a75466134d18ecbb1fef66e4cb401d781a4
diff --git a/tests/unit-tests/dummy-forwarder.cpp b/tests/unit-tests/dummy-forwarder.cpp
new file mode 100644
index 0000000..224dcd3
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.cpp
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2017 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 "dummy-forwarder.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace chronosync {
+
+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) {
+ Interest i(interest);
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ m_io.post([=] { otherFace->receive(i); });
+ }
+ });
+ face->onSendData.connect([this, face] (const Data& data) {
+ Data d(data);
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ m_io.post([=] { otherFace->receive(d); });
+ }
+ });
+
+ face->onSendNack.connect([this, face] (const lp::Nack& nack) {
+ lp::Nack n(nack);
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ m_io.post([=] { otherFace->receive(n); });
+ }
+ });
+
+ m_faces.push_back(face);
+ return *face;
+}
+
+} // namespace chronosync
+} // namespace ndn
diff --git a/tests/unit-tests/dummy-forwarder.hpp b/tests/unit-tests/dummy-forwarder.hpp
new file mode 100644
index 0000000..3e7d9b3
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.hpp
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2017 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 <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_CHRONOSYNC_UNIT_TESTS_DUMMY_FORWARDER_HPP
+#define NDN_CHRONOSYNC_UNIT_TESTS_DUMMY_FORWARDER_HPP
+
+namespace ndn {
+namespace chronosync {
+
+/**
+ * @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 chronosync
+} // namespace ndn
+
+#endif // NDN_CHRONOSYNC_UNIT_TESTS_DUMMY_FORWARDER_HPP
diff --git a/tests/unit-tests/test-interest-table.cpp b/tests/unit-tests/test-interest-table.cpp
index 0f0c95d..be0f289 100644
--- a/tests/unit-tests/test-interest-table.cpp
+++ b/tests/unit-tests/test-interest-table.cpp
@@ -37,37 +37,36 @@
Name interestName1;
digest1 = ndn::util::Sha256::computeDigest(origin, 1);
interestName1.append(prefix).append(name::Component(digest1));
- interest1 = make_shared<Interest>(interestName1);
- interest1->setInterestLifetime(time::milliseconds(100));
+
+ interest1 = Interest(interestName1);
+ interest1.setInterestLifetime(time::milliseconds(100));
Name interestName2;
digest2 = ndn::util::Sha256::computeDigest(origin, 2);
interestName2.append(prefix).append(name::Component(digest2));
- interest2 = make_shared<Interest>(interestName2);
- interest2->setInterestLifetime(time::milliseconds(100));
+ interest2 = Interest(interestName2);
+ interest2.setInterestLifetime(time::milliseconds(100));
Name interestName3;
digest3 = ndn::util::Sha256::computeDigest(origin, 3);
interestName3.append(prefix).append(name::Component(digest3));
- interest3 = make_shared<Interest>(interestName3);
- interest3->setInterestLifetime(time::milliseconds(100));
+ interest3 = Interest(interestName3);
+ interest3.setInterestLifetime(time::milliseconds(100));
}
void
- insert(InterestTable& table,
- shared_ptr<Interest> interest,
- ndn::ConstBufferPtr digest)
+ insert(InterestTable& table, const Interest& interest, ndn::ConstBufferPtr digest)
{
table.insert(interest, digest);
}
- shared_ptr<Interest> interest1;
+ Interest interest1;
ndn::ConstBufferPtr digest1;
- shared_ptr<Interest> interest2;
+ Interest interest2;
ndn::ConstBufferPtr digest2;
- shared_ptr<Interest> interest3;
+ Interest interest3;
ndn::ConstBufferPtr digest3;
};
diff --git a/tests/unit-tests/test-logic.cpp b/tests/unit-tests/test-logic.cpp
index 342af4c..a243bb0 100644
--- a/tests/unit-tests/test-logic.cpp
+++ b/tests/unit-tests/test-logic.cpp
@@ -18,20 +18,22 @@
*/
#include "logic.hpp"
-#include "../unit-test-time-fixture.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
+
#include "boost-test.hpp"
+#include "../identity-management-fixture.hpp"
+
+#include "dummy-forwarder.hpp"
namespace chronosync {
namespace test {
using std::vector;
-using ndn::util::DummyClientFace;
+using ndn::chronosync::DummyForwarder;
class Handler
{
public:
- Handler(DummyClientFace& face,
+ Handler(ndn::Face& face,
const Name& syncPrefix,
const Name& userPrefix)
: logic(face,
@@ -66,64 +68,30 @@
std::map<Name, SeqNo> map;
};
-class LogicFixture : public ndn::tests::UnitTestTimeFixture
+class LogicFixture : public ndn::tests::IdentityManagementTimeFixture
{
public:
LogicFixture()
: syncPrefix("/ndn/broadcast/sync")
+ , fw(io, m_keyChain)
{
syncPrefix.appendVersion();
userPrefix[0] = Name("/user0");
userPrefix[1] = Name("/user1");
userPrefix[2] = Name("/user2");
userPrefix[3] = Name("/user3");
-
- faces[0].reset(new DummyClientFace(io, {true, true}));
- faces[1].reset(new DummyClientFace(io, {true, true}));
- faces[2].reset(new DummyClientFace(io, {true, true}));
- faces[3].reset(new DummyClientFace(io, {true, true}));
-
- for (int i = 0; i < 4; i++) {
- readInterestOffset[i] = 0;
- readDataOffset[i] = 0;
- }
- }
-
- void
- passPacket()
- {
- for (int i = 0; i < 4; i++)
- checkFace(i);
- }
-
- void
- checkFace(int sender)
- {
- while (faces[sender]->sentInterests.size() > readInterestOffset[sender]) {
- for (int i = 0; i < 4; i++) {
- if (sender != i)
- faces[i]->receive(faces[sender]->sentInterests[readInterestOffset[sender]]);
- }
- readInterestOffset[sender]++;
- }
- while (faces[sender]->sentData.size() > readDataOffset[sender]) {
- for (int i = 0; i < 4; i++) {
- if (sender != i)
- faces[i]->receive(faces[sender]->sentData[readDataOffset[sender]]);
- }
- readDataOffset[sender]++;
- }
}
public:
Name syncPrefix;
Name userPrefix[4];
- std::unique_ptr<DummyClientFace> faces[4];
+ DummyForwarder fw;
+ // std::unique_ptr<DummyClientFace> faces[4];
shared_ptr<Handler> handler[4];
- size_t readInterestOffset[4];
- size_t readDataOffset[4];
+ // size_t readInterestOffset[4];
+ // size_t readDataOffset[4];
};
BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture)
@@ -137,156 +105,120 @@
{
Name syncPrefix("/ndn/broadcast/sync");
Name userPrefix("/user");
- DummyClientFace face(io, {true, true});
- BOOST_REQUIRE_NO_THROW(Logic(face, syncPrefix, userPrefix,
- bind(onUpdate, _1)));
+ ndn::util::DummyClientFace face(io, {true, true});
+ BOOST_REQUIRE_NO_THROW(Logic(face, syncPrefix, userPrefix, bind(onUpdate, _1)));
}
BOOST_AUTO_TEST_CASE(TwoBasic)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
+
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(2);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 2);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[1]->updateSeqNo(2);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2);
}
BOOST_AUTO_TEST_CASE(ThreeBasic)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]);
- advanceClocks(ndn::time::milliseconds(10), 20);
+ handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 70; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1);
handler[1]->updateSeqNo(2);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2);
BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2);
handler[2]->updateSeqNo(4);
- for (int i = 0; i < 100; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4);
BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4);
}
BOOST_AUTO_TEST_CASE(ResetRecover)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]);
- advanceClocks(ndn::time::milliseconds(10), 30);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
handler[1]->updateSeqNo(2);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2);
- advanceClocks(ndn::time::milliseconds(10), 10);
- handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
+ handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1);
BOOST_CHECK_EQUAL(handler[2]->map[handler[1]->logic.getSessionName()], 2);
handler[2]->updateSeqNo(4);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4);
BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4);
}
BOOST_AUTO_TEST_CASE(RecoverConflict)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]);
- advanceClocks(ndn::time::milliseconds(10), 30);
+ handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1);
handler[1]->updateSeqNo(2);
handler[2]->updateSeqNo(4);
- for (int i = 0; i < 75; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 2);
BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 4);
BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 4);
@@ -295,34 +227,28 @@
BOOST_AUTO_TEST_CASE(PartitionRecover)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[1]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[1]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[2] = make_shared<Handler>(ref(*faces[2]), syncPrefix, userPrefix[2]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[2] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[3] = make_shared<Handler>(ref(*faces[3]), syncPrefix, userPrefix[3]);
- advanceClocks(ndn::time::milliseconds(10), 30);
+ handler[3] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[3]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 1);
BOOST_CHECK_EQUAL(handler[3]->map[handler[0]->logic.getSessionName()], 1);
handler[2]->updateSeqNo(2);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 2);
BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 2);
BOOST_CHECK_EQUAL(handler[3]->map[handler[2]->logic.getSessionName()], 2);
@@ -331,20 +257,14 @@
handler[1]->updateSeqNo(3);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 3);
handler[2]->map[handler[1]->logic.getSessionName()] = 0;
handler[3]->map[handler[1]->logic.getSessionName()] = 0;
handler[3]->updateSeqNo(4);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[2]->map[handler[3]->logic.getSessionName()], 4);
handler[0]->map[handler[3]->logic.getSessionName()] = 0;
handler[1]->map[handler[3]->logic.getSessionName()] = 0;
@@ -353,20 +273,14 @@
handler[0]->updateSeqNo(5);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 5);
BOOST_CHECK_EQUAL(handler[2]->map[handler[0]->logic.getSessionName()], 5);
BOOST_CHECK_EQUAL(handler[3]->map[handler[0]->logic.getSessionName()], 5);
handler[2]->updateSeqNo(6);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[2]->logic.getSessionName()], 6);
BOOST_CHECK_EQUAL(handler[1]->map[handler[2]->logic.getSessionName()], 6);
BOOST_CHECK_EQUAL(handler[3]->map[handler[2]->logic.getSessionName()], 6);
@@ -374,49 +288,34 @@
BOOST_AUTO_TEST_CASE(MultipleUserUnderOneLogic)
{
- handler[0] = make_shared<Handler>(ref(*faces[0]), syncPrefix, userPrefix[0]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[0] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[0]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
- handler[1] = make_shared<Handler>(ref(*faces[1]), syncPrefix, userPrefix[2]);
- advanceClocks(ndn::time::milliseconds(10), 10);
+ handler[1] = make_shared<Handler>(ref(fw.addFace()), syncPrefix, userPrefix[2]);
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->logic.addUserNode(userPrefix[1]);
- for (int i = 0; i < 20; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
handler[0]->updateSeqNo(1);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName()], 1);
handler[0]->logic.updateSeqNo(2, userPrefix[1]);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[1]->map[handler[0]->logic.getSessionName(userPrefix[1])], 2);
handler[1]->updateSeqNo(4);
- for (int i = 0; i < 50; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(handler[0]->map[handler[1]->logic.getSessionName()], 4);
handler[0]->logic.removeUserNode(userPrefix[0]);
- for (int i = 0; i < 100; i++) {
- advanceClocks(ndn::time::milliseconds(2), 10);
- passPacket();
- }
+ advanceClocks(ndn::time::milliseconds(50), 100);
BOOST_CHECK_EQUAL(handler[1]->logic.getSessionNames().size(), 2);
}
diff --git a/tests/unit-tests/test-socket.cpp b/tests/unit-tests/test-socket.cpp
index 0c478ec..3fd0d26 100644
--- a/tests/unit-tests/test-socket.cpp
+++ b/tests/unit-tests/test-socket.cpp
@@ -18,9 +18,11 @@
*/
#include "socket.hpp"
-#include "../unit-test-time-fixture.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
+
#include "boost-test.hpp"
+#include "../unit-test-time-fixture.hpp"
+
+#include <ndn-cxx/util/dummy-client-face.hpp>
namespace chronosync {
namespace test {
@@ -30,7 +32,6 @@
using std::map;
using ndn::util::DummyClientFace;
-
/**
* @brief Emulate an app that use the Socket class
*
@@ -54,12 +55,12 @@
}
void
- set(const shared_ptr<const Data>& dataPacket)
+ set(const Data& dataPacket)
{
// std::cerr << "set Data" << std::endl;
- Name dataName(dataPacket->getName());
- string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()),
- dataPacket->getContent().value_size());
+ Name dataName(dataPacket.getName());
+ string str2(reinterpret_cast<const char*>(dataPacket.getContent().value()),
+ dataPacket.getContent().value_size());
data.insert(make_pair(dataName, str2));
}
@@ -71,11 +72,11 @@
}
void
- setNum(const shared_ptr<const Data>& dataPacket)
+ setNum(const Data& dataPacket)
{
// std::cerr << "setNum Data" << std::endl;
- size_t n = dataPacket->getContent().value_size() / 4;
- const uint32_t* numbers = reinterpret_cast<const uint32_t*>(dataPacket->getContent().value());
+ size_t n = dataPacket.getContent().value_size() / 4;
+ const uint32_t* numbers = reinterpret_cast<const uint32_t*>(dataPacket.getContent().value());
for (size_t i = 0; i < n; i++) {
sum += numbers[i];
}
@@ -99,7 +100,7 @@
// std::cerr << "fetchAll" << std::endl;
for (size_t i = 0; i < v.size(); i++) {
for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
- socket.fetchData(v[i].session, s, [this] (const shared_ptr<const Data>& dataPacket) {
+ socket.fetchData(v[i].session, s, [this] (const Data& dataPacket) {
this->set(dataPacket);
});
}
@@ -112,7 +113,7 @@
// std::cerr << "fetchNumbers" << std::endl;
for (size_t i = 0; i < v.size(); i++) {
for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
- socket.fetchData(v[i].session, s, [this] (const shared_ptr<const Data>& dataPacket) {
+ socket.fetchData(v[i].session, s, [this] (const Data& dataPacket) {
this->setNum(dataPacket);
});
}
diff --git a/tests/unit-tests/test-state.cpp b/tests/unit-tests/test-state.cpp
index ed88373..9e7ce58 100644
--- a/tests/unit-tests/test-state.cpp
+++ b/tests/unit-tests/test-state.cpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -18,12 +18,13 @@
*/
#include "state.hpp"
+
#include "boost-test.hpp"
namespace chronosync {
namespace test {
-using boost::tuple;
+using std::tuple;
BOOST_AUTO_TEST_SUITE(StateTests)
@@ -43,21 +44,21 @@
tuple<bool, bool, SeqNo> result;
result = state.update(info, 12);
- BOOST_CHECK_EQUAL(result.get<0>(), true);
- BOOST_CHECK_EQUAL(result.get<1>(), false);
- BOOST_CHECK_EQUAL(result.get<2>(), 0);
+ BOOST_CHECK_EQUAL(std::get<0>(result), true);
+ BOOST_CHECK_EQUAL(std::get<1>(result), false);
+ BOOST_CHECK_EQUAL(std::get<2>(result), 0);
BOOST_CHECK_NO_THROW(state.update(info, 12));
result = state.update(info, 12);
- BOOST_CHECK_EQUAL(result.get<0>(), false);
- BOOST_CHECK_EQUAL(result.get<1>(), false);
- BOOST_CHECK_EQUAL(result.get<2>(), 0);
+ BOOST_CHECK_EQUAL(std::get<0>(result), false);
+ BOOST_CHECK_EQUAL(std::get<1>(result), false);
+ BOOST_CHECK_EQUAL(std::get<2>(result), 0);
BOOST_CHECK_NO_THROW(state.update(info, 11));
result = state.update(info, 11);
- BOOST_CHECK_EQUAL(result.get<0>(), false);
- BOOST_CHECK_EQUAL(result.get<1>(), false);
- BOOST_CHECK_EQUAL(result.get<2>(), 0);
+ BOOST_CHECK_EQUAL(std::get<0>(result), false);
+ BOOST_CHECK_EQUAL(std::get<1>(result), false);
+ BOOST_CHECK_EQUAL(std::get<2>(result), 0);
BOOST_CHECK_EQUAL(state.getLeaves().size(), 1);
BOOST_CHECK_EQUAL((*state.getLeaves().begin())->getSeq(), 12);
@@ -67,9 +68,9 @@
BOOST_CHECK_EQUAL((*state.getLeaves().begin())->getSeq(), 13);
result = state.update(info, 14);
- BOOST_CHECK_EQUAL(result.get<0>(), false);
- BOOST_CHECK_EQUAL(result.get<1>(), true);
- BOOST_CHECK_EQUAL(result.get<2>(), 13);
+ BOOST_CHECK_EQUAL(std::get<0>(result), false);
+ BOOST_CHECK_EQUAL(std::get<1>(result), true);
+ BOOST_CHECK_EQUAL(std::get<2>(result), 13);
BOOST_CHECK_EQUAL(state.getLeaves().size(), 1);
BOOST_CHECK_EQUAL((*state.getLeaves().begin())->getSeq(), 14);