Fix compilation with latest ndn-cxx
Change-Id: Iaf468a75466134d18ecbb1fef66e4cb401d781a4
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);
}