tests: sync common testing infrastructure with ndn-cxx
Also upgrade waf to version 2.0.21
Change-Id: Ibfd3386772d48df287b6be73e6d778d3661abe86
diff --git a/tests/clock-fixture.cpp b/tests/clock-fixture.cpp
new file mode 100644
index 0000000..0b4e04a
--- /dev/null
+++ b/tests/clock-fixture.cpp
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California
+ * The University of Memphis
+ *
+ * This file is part of PSync.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * PSync 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tests/clock-fixture.hpp"
+
+namespace ndn {
+namespace tests {
+
+ClockFixture::ClockFixture()
+ : m_steadyClock(make_shared<time::UnitTestSteadyClock>())
+ , m_systemClock(make_shared<time::UnitTestSystemClock>())
+{
+ time::setCustomClocks(m_steadyClock, m_systemClock);
+}
+
+ClockFixture::~ClockFixture()
+{
+ time::setCustomClocks(nullptr, nullptr);
+}
+
+void
+ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total)
+{
+ BOOST_ASSERT(tick > time::nanoseconds::zero());
+ BOOST_ASSERT(total >= time::nanoseconds::zero());
+
+ while (total > time::nanoseconds::zero()) {
+ auto t = std::min(tick, total);
+ m_steadyClock->advance(t);
+ m_systemClock->advance(t);
+ total -= t;
+
+ afterTick();
+ }
+}
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/clock-fixture.hpp b/tests/clock-fixture.hpp
new file mode 100644
index 0000000..c340526
--- /dev/null
+++ b/tests/clock-fixture.hpp
@@ -0,0 +1,83 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California
+ * The University of Memphis
+ *
+ * This file is part of PSync.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * PSync 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PSYNC_TESTS_CLOCK_FIXTURE_HPP
+#define PSYNC_TESTS_CLOCK_FIXTURE_HPP
+
+#include <ndn-cxx/util/time-unit-test-clock.hpp>
+
+namespace ndn {
+namespace tests {
+
+/** \brief A test fixture that overrides steady clock and system clock.
+ */
+class ClockFixture
+{
+public:
+ virtual
+ ~ClockFixture();
+
+ /** \brief Advance steady and system clocks.
+ *
+ * Clocks are advanced in increments of \p tick for \p nTicks ticks.
+ * afterTick() is called after each tick.
+ *
+ * Exceptions thrown during I/O events are propagated to the caller.
+ * Clock advancement will stop in the event of an exception.
+ */
+ void
+ advanceClocks(time::nanoseconds tick, size_t nTicks = 1)
+ {
+ advanceClocks(tick, tick * nTicks);
+ }
+
+ /** \brief Advance steady and system clocks.
+ *
+ * Clocks are advanced in increments of \p tick for \p total time.
+ * The last increment might be shorter than \p tick.
+ * afterTick() is called after each tick.
+ *
+ * Exceptions thrown during I/O events are propagated to the caller.
+ * Clock advancement will stop in the event of an exception.
+ */
+ void
+ advanceClocks(time::nanoseconds tick, time::nanoseconds total);
+
+protected:
+ ClockFixture();
+
+private:
+ /** \brief Called by advanceClocks() after each clock advancement (tick).
+ *
+ * The base class implementation is a no-op.
+ */
+ virtual void
+ afterTick()
+ {
+ }
+
+protected:
+ shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
+ shared_ptr<time::UnitTestSystemClock> m_systemClock;
+};
+
+} // namespace tests
+} // namespace ndn
+
+#endif // PSYNC_TESTS_CLOCK_FIXTURE_HPP
diff --git a/tests/io-fixture.hpp b/tests/io-fixture.hpp
new file mode 100644
index 0000000..d15a8ed
--- /dev/null
+++ b/tests/io-fixture.hpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California
+ * The University of Memphis
+ *
+ * This file is part of PSync.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * PSync 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PSYNC_TESTS_IO_FIXTURE_HPP
+#define PSYNC_TESTS_IO_FIXTURE_HPP
+
+#include "tests/clock-fixture.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace tests {
+
+class IoFixture : public ClockFixture
+{
+private:
+ void
+ afterTick() final
+ {
+ if (m_io.stopped()) {
+#if BOOST_VERSION >= 106600
+ m_io.restart();
+#else
+ m_io.reset();
+#endif
+ }
+ m_io.poll();
+ }
+
+protected:
+ boost::asio::io_service m_io;
+};
+
+} // namespace tests
+} // namespace ndn
+
+#endif // PSYNC_TESTS_IO_FIXTURE_HPP
diff --git a/tests/test-consumer.cpp b/tests/test-consumer.cpp
index 269124d..373a8ca 100644
--- a/tests/test-consumer.cpp
+++ b/tests/test-consumer.cpp
@@ -20,7 +20,7 @@
#include "PSync/consumer.hpp"
#include "tests/boost-test.hpp"
-#include "tests/unit-test-time-fixture.hpp"
+#include "tests/io-fixture.hpp"
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -55,15 +55,13 @@
BOOST_CHECK(!consumer.addSubscription(subscription, 0));
}
-BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture)
+BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
{
- util::DummyClientFace face(io, {true, true});
+ util::DummyClientFace face(m_io, {true, true});
Consumer consumer(Name("/psync"), face,
[] (const auto&) {},
[] (const auto&) {},
- 40, 0.001,
- ndn::time::milliseconds(4000),
- ndn::time::milliseconds(4000));
+ 40, 0.001, 4_s, 4_s);
consumer.sendHelloInterest();
advanceClocks(4_s);
@@ -71,7 +69,7 @@
face.sentInterests.clear();
consumer.stop();
- consumer.m_iblt = ndn::Name("test");
+ consumer.m_iblt = Name("test");
consumer.sendSyncInterest();
advanceClocks(3999_ms);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp
index 33b5014..2693421 100644
--- a/tests/test-full-producer.cpp
+++ b/tests/test-full-producer.cpp
@@ -20,7 +20,7 @@
#include "PSync/full-producer.hpp"
#include "tests/boost-test.hpp"
-#include "tests/unit-test-time-fixture.hpp"
+#include "tests/io-fixture.hpp"
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
@@ -35,7 +35,7 @@
BOOST_AUTO_TEST_CASE(Constructor)
{
util::DummyClientFace face({true, true});
- BOOST_REQUIRE_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr));
+ BOOST_CHECK_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr));
}
BOOST_AUTO_TEST_CASE(OnInterest)
@@ -51,17 +51,17 @@
BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
}
-BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture)
+BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
{
Name syncPrefix("/psync"), userNode("/testUser");
- util::DummyClientFace face(io, {true, true});
+ util::DummyClientFace face(m_io, {true, true});
- FullProducer node(40, face, syncPrefix, userNode, nullptr, ndn::time::milliseconds(8000));
- advanceClocks(ndn::time::milliseconds(10));
+ FullProducer node(40, face, syncPrefix, userNode, nullptr, 8_s);
+ advanceClocks(10_ms);
face.sentInterests.clear();
// full sync sends the next one in interest lifetime / 2 +- jitter
- advanceClocks(ndn::time::milliseconds(6000));
+ advanceClocks(6_s);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
}
@@ -72,17 +72,16 @@
FullProducer node(40, face, syncPrefix, userNode, nullptr);
- ndn::Name syncInterestName(syncPrefix);
+ Name syncInterestName(syncPrefix);
node.m_iblt.appendToName(syncInterestName);
- ndn::Interest syncInterest(syncInterestName);
+ Interest syncInterest(syncInterestName);
- auto badCompress = std::make_shared<const ndn::Buffer>(5);
-
- BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, badCompress));
+ auto badCompress = std::make_shared<const Buffer>(5);
+ BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
const uint8_t test[] = {'t', 'e', 's', 't'};
auto goodCompressBadBlock = compress(node.m_contentCompression, &test[0], sizeof(test));
- BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
+ BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index 38e7bf2..0d2b0ee 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -22,7 +22,7 @@
#include "PSync/detail/state.hpp"
#include "tests/boost-test.hpp"
-#include "tests/unit-test-time-fixture.hpp"
+#include "tests/io-fixture.hpp"
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -31,14 +31,15 @@
using namespace ndn;
-class FullSyncFixture : public tests::UnitTestTimeFixture
+class FullSyncFixture : public tests::IoFixture
{
protected:
void
addNode(int id)
{
BOOST_ASSERT(id >= 0 && id <= 3);
- faces[id] = std::make_shared<util::DummyClientFace>(io, util::DummyClientFace::Options{true, true});
+
+ faces[id] = std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true});
userPrefixes[id] = Name("userPrefix" + to_string(id));
nodes[id] = make_shared<FullProducer>(40, *faces[id], syncPrefix, userPrefixes[id],
[] (const auto&) {});
diff --git a/tests/test-partial-producer.cpp b/tests/test-partial-producer.cpp
index ffddac8..3f5de4c 100644
--- a/tests/test-partial-producer.cpp
+++ b/tests/test-partial-producer.cpp
@@ -34,7 +34,7 @@
BOOST_AUTO_TEST_CASE(Constructor)
{
util::DummyClientFace face({true, true});
- BOOST_REQUIRE_NO_THROW(PartialProducer(40, face, Name("/psync"), Name("/testUser")));
+ BOOST_CHECK_NO_THROW(PartialProducer(40, face, Name("/psync"), Name("/testUser")));
}
BOOST_AUTO_TEST_CASE(RegisterPrefix)
@@ -43,7 +43,7 @@
util::DummyClientFace face({true, true});
PartialProducer producer(40, face, syncPrefix, userNode);
- face.processEvents(time::milliseconds(-1));
+ face.processEvents(-1_ms);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
auto interest = face.sentInterests.front();
@@ -88,24 +88,24 @@
producer.m_iblt.appendToName(syncInterestName);
Interest syncInterest(syncInterestName);
- syncInterest.setInterestLifetime(time::milliseconds(1000));
+ syncInterest.setInterestLifetime(1_s);
syncInterest.setNonce(1);
- BOOST_REQUIRE_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
- face.processEvents(time::milliseconds(10));
+ BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
+ face.processEvents(10_ms);
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
- face.processEvents(time::milliseconds(500));
+ face.processEvents(500_ms);
// Same interest again - size of pending interest should remain same, but expirationEvent should change
syncInterest.setNonce(2);
- BOOST_REQUIRE_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
- face.processEvents(time::milliseconds(10));
+ BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
+ face.processEvents(10_ms);
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
- face.processEvents(time::milliseconds(500));
+ face.processEvents(500_ms);
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
- face.processEvents(time::milliseconds(500));
+ face.processEvents(500_ms);
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 0);
}
@@ -119,7 +119,7 @@
Name syncInterestName(syncPrefix);
syncInterestName.append("sync");
producer.m_iblt.appendToName(syncInterestName);
- BOOST_REQUIRE_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
+ BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
// Sync interest with malicious bloom filter
syncInterestName = syncPrefix;
@@ -128,7 +128,7 @@
syncInterestName.appendNumber(1); // false positive probability * 1000 of bloom filter
syncInterestName.append("fake-name");
producer.m_iblt.appendToName(syncInterestName);
- BOOST_REQUIRE_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
+ BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
// Sync interest with malicious IBF
syncInterestName = syncPrefix;
@@ -136,7 +136,7 @@
BloomFilter bf(20, 0.001);
bf.appendToName(syncInterestName);
syncInterestName.append("fake-name");
- BOOST_REQUIRE_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
+ BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestName, Interest(syncInterestName)));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-partial-sync.cpp b/tests/test-partial-sync.cpp
index 2c648e9..6235310 100644
--- a/tests/test-partial-sync.cpp
+++ b/tests/test-partial-sync.cpp
@@ -21,7 +21,7 @@
#include "PSync/consumer.hpp"
#include "tests/boost-test.hpp"
-#include "tests/unit-test-time-fixture.hpp"
+#include "tests/io-fixture.hpp"
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -30,23 +30,18 @@
using namespace ndn;
-class PartialSyncFixture : public tests::UnitTestTimeFixture
+class PartialSyncFixture : public tests::IoFixture
{
public:
PartialSyncFixture()
- : face(io, {true, true})
- , syncPrefix("psync")
- , userPrefix("testUser-0")
- , numHelloDataRcvd(0)
- , numSyncDataRcvd(0)
{
producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix);
addUserNodes("testUser", 10);
}
- ~PartialSyncFixture()
+ ~PartialSyncFixture() override
{
- for (auto consumer : consumers) {
+ for (const auto& consumer : consumers) {
if (consumer) {
consumer->stop();
}
@@ -56,15 +51,15 @@
void
addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true)
{
- consumerFaces[id] = std::make_shared<util::DummyClientFace>(io, util::DummyClientFace::Options{true, true});
+ consumerFaces[id] =
+ std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true});
if (linkToProducer) {
face.linkTo(*consumerFaces[id]);
}
consumers[id] = std::make_shared<Consumer>(syncPrefix, *consumerFaces[id],
- [&, id] (const auto& availableSubs)
- {
+ [&, id] (const auto& availableSubs) {
numHelloDataRcvd++;
BOOST_CHECK(checkSubList(availableSubs));
@@ -136,17 +131,17 @@
producer->updateSeqNo(prefix, seq);
}
- util::DummyClientFace face;
- Name syncPrefix;
- Name userPrefix;
+ util::DummyClientFace face{m_io, {true, true}};
+ Name syncPrefix{"psync"};
+ Name userPrefix{"testUser-0"};
shared_ptr<PartialProducer> producer;
- std::map <ndn::Name, uint64_t> oldSeqMap;
+ std::map<Name, uint64_t> oldSeqMap;
shared_ptr<Consumer> consumers[3];
shared_ptr<util::DummyClientFace> consumerFaces[3];
- int numHelloDataRcvd;
- int numSyncDataRcvd;
+ int numHelloDataRcvd = 0;
+ int numSyncDataRcvd = 0;
};
BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture)
@@ -293,7 +288,7 @@
// Link to first producer goes down
face.unlink();
- util::DummyClientFace face2(io, {true, true});
+ util::DummyClientFace face2(m_io, {true, true});
PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix);
for (int i = 1; i < 10; i++) {
replicatedProducer.addUserNode("testUser-" + to_string(i));
@@ -331,7 +326,7 @@
oldSeqMap = producer->m_prefixes;
for (int i = 0; i < 50; i++) {
- ndn::Name prefix("testUser-" + to_string(i));
+ Name prefix("testUser-" + to_string(i));
producer->updateSeqNo(prefix, producer->getSeqNo(prefix).value() + 1);
}
// Next sync interest should trigger the nack
@@ -343,7 +338,7 @@
bool nackRcvd = false;
for (const auto& data : face.sentData) {
- if (data.getContentType() == ndn::tlv::ContentType_Nack) {
+ if (data.getContentType() == tlv::ContentType_Nack) {
nackRcvd = true;
break;
}
@@ -384,7 +379,7 @@
BOOST_AUTO_TEST_CASE(SegmentedSync)
{
- ndn::Name longNameToExceedDataSize;
+ Name longNameToExceedDataSize;
for (int i = 0; i < 100; i++) {
longNameToExceedDataSize.append("test-" + std::to_string(i));
}
@@ -401,7 +396,7 @@
BOOST_CHECK_EQUAL(numHelloDataRcvd, 1);
// To be used later to simulate sending delayed segmented interest
- ndn::Name syncInterestName(consumers[0]->m_syncInterestPrefix);
+ Name syncInterestName(consumers[0]->m_syncInterestPrefix);
consumers[0]->m_bloomFilter.appendToName(syncInterestName);
syncInterestName.append(consumers[0]->m_iblt);
syncInterestName.appendVersion();
diff --git a/tests/test-producer-base.cpp b/tests/test-producer-base.cpp
index e3a813c..4320e83 100644
--- a/tests/test-producer-base.cpp
+++ b/tests/test-producer-base.cpp
@@ -56,7 +56,7 @@
BOOST_CHECK_EQUAL(prefix.getPrefix(-1), userNode);
producerBase.removeUserNode(userNode);
- BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()) == ndn::nullopt);
+ BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()) == nullopt);
BOOST_CHECK(producerBase.m_biMap.right.find(prefixWithSeq) == producerBase.m_biMap.right.end());
BOOST_CHECK(producerBase.m_biMap.left.find(hash) == producerBase.m_biMap.left.end());
@@ -72,12 +72,12 @@
ProducerBase producerBase(40, face, Name("/psync"), Name("/testUser"));
BOOST_CHECK_EQUAL(face.sentData.size(), 0);
- producerBase.m_syncReplyFreshness = time::milliseconds(1000);
+ producerBase.m_syncReplyFreshness = 1_s;
producerBase.sendApplicationNack(Name("test"));
- face.processEvents(time::milliseconds(10));
+ face.processEvents(10_ms);
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
- BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), ndn::tlv::ContentType_Nack);
+ BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), tlv::ContentType_Nack);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-segment-publisher.cpp b/tests/test-segment-publisher.cpp
index 7b7bfc7..bf437b9 100644
--- a/tests/test-segment-publisher.cpp
+++ b/tests/test-segment-publisher.cpp
@@ -21,7 +21,7 @@
#include "PSync/detail/state.hpp"
#include "tests/boost-test.hpp"
-#include "tests/unit-test-time-fixture.hpp"
+#include "tests/io-fixture.hpp"
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/interest.hpp>
@@ -33,29 +33,24 @@
using namespace ndn;
-class SegmentPublisherFixture : public tests::UnitTestTimeFixture
+class SegmentPublisherFixture : public tests::IoFixture
{
public:
SegmentPublisherFixture()
- : face(io, util::DummyClientFace::Options{true, true})
+ : face(m_io, util::DummyClientFace::Options{true, true})
, publisher(face, keyChain)
- , freshness(1000)
- , numComplete(0)
- , numRepliesFromStore(0)
{
face.setInterestFilter(InterestFilter("/hello/world"),
bind(&SegmentPublisherFixture::onInterest, this, _1, _2),
- [] (const ndn::Name& prefix, const std::string& msg) {
- BOOST_CHECK(false);
- });
- advanceClocks(ndn::time::milliseconds(10));
+ [] (auto&&...) { BOOST_CHECK(false); });
+ advanceClocks(10_ms);
for (int i = 0; i < 1000; ++i) {
state.addContent(Name("/test").appendNumber(i));
}
}
- ~SegmentPublisherFixture()
+ ~SegmentPublisherFixture() override
{
fetcher->stop();
}
@@ -63,11 +58,11 @@
void
expressInterest(const Interest& interest)
{
- fetcher = util::SegmentFetcher::start(face, interest, ndn::security::getAcceptAllValidator());
+ fetcher = util::SegmentFetcher::start(face, interest, security::getAcceptAllValidator());
fetcher->onComplete.connect([this] (auto&&...) { numComplete++; });
fetcher->onError.connect([] (auto&&...) { BOOST_CHECK(false); });
- advanceClocks(ndn::time::milliseconds(10));
+ advanceClocks(10_ms);
}
void
@@ -92,11 +87,11 @@
SegmentPublisher publisher;
shared_ptr<util::SegmentFetcher> fetcher;
Name dataName;
- time::milliseconds freshness;
+ time::milliseconds freshness = 1_s;
State state;
- int numComplete;
- int numRepliesFromStore;
+ int numComplete = 0;
+ int numRepliesFromStore = 0;
};
BOOST_FIXTURE_TEST_SUITE(TestSegmentPublisher, SegmentPublisherFixture)
@@ -116,7 +111,7 @@
BOOST_CHECK_EQUAL(numComplete, 2);
BOOST_CHECK_EQUAL(numRepliesFromStore, 3);
- advanceClocks(ndn::time::milliseconds(freshness));
+ advanceClocks(time::milliseconds(freshness));
BOOST_CHECK_EQUAL(publisher.m_ims.size(), 0);
numRepliesFromStore = 0;
@@ -126,16 +121,10 @@
numRepliesFromStore = 0;
face.expressInterest(Interest("/hello/world/").setCanBePrefix(true),
- [this] (const Interest& interest, const Data& data) {
- numComplete++;
- },
- [] (const Interest& interest, const lp::Nack& nack) {
- BOOST_CHECK(false);
- },
- [] (const Interest& interest) {
- BOOST_CHECK(false);
- });
- advanceClocks(ndn::time::milliseconds(10));
+ [this] (auto&&...) { this->numComplete++; },
+ [] (auto&&...) { BOOST_CHECK(false); },
+ [] (auto&&...) { BOOST_CHECK(false); });
+ advanceClocks(10_ms);
BOOST_CHECK_EQUAL(numComplete, 4);
BOOST_CHECK_EQUAL(numRepliesFromStore, 1);
}
@@ -152,7 +141,7 @@
BOOST_CHECK_EQUAL(numRepliesFromStore, 2);
BOOST_CHECK_EQUAL(publisher.m_ims.size(), 3);
- advanceClocks(ndn::time::milliseconds(freshness));
+ advanceClocks(time::milliseconds(freshness));
BOOST_CHECK_EQUAL(publisher.m_ims.size(), 0);
}
diff --git a/tests/unit-test-time-fixture.hpp b/tests/unit-test-time-fixture.hpp
deleted file mode 100644
index ea653f0..0000000
--- a/tests/unit-test-time-fixture.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2020 University of California, Los Angeles
- * The University of Memphis
- *
- * This file is part of PSync.
- *
- * PSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU Lesser General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * PSync 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
-#define NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP
-
-#include <ndn-cxx/util/time-unit-test-clock.hpp>
-
-#include <boost/asio.hpp>
-
-namespace ndn {
-namespace tests {
-
-class UnitTestTimeFixture
-{
-public:
- UnitTestTimeFixture()
- : steadyClock(make_shared<time::UnitTestSteadyClock>())
- , systemClock(make_shared<time::UnitTestSystemClock>())
- {
- time::setCustomClocks(steadyClock, systemClock);
- }
-
- ~UnitTestTimeFixture()
- {
- time::setCustomClocks(nullptr, nullptr);
- }
-
- void
- advanceClocks(const time::nanoseconds& tick, size_t nTicks = 1)
- {
- for (size_t i = 0; i < nTicks; ++i) {
- steadyClock->advance(tick);
- systemClock->advance(tick);
-
- if (io.stopped())
- io.reset();
- io.poll();
- }
- }
-
-public:
- shared_ptr<time::UnitTestSteadyClock> steadyClock;
- shared_ptr<time::UnitTestSystemClock> systemClock;
- boost::asio::io_service io;
-};
-
-} // namespace tests
-} // namespace ndn
-
-#endif // NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP