peek: code modernization and cleanup
Change-Id: I42d706aa02ab03557d708c729f65716c1c2d3494
diff --git a/tests/peek/ndnpeek.t.cpp b/tests/peek/ndnpeek.t.cpp
index 332c2d2..73e6bfe 100644
--- a/tests/peek/ndnpeek.t.cpp
+++ b/tests/peek/ndnpeek.t.cpp
@@ -53,11 +53,6 @@
class NdnPeekFixture : public UnitTestTimeFixture
{
protected:
- NdnPeekFixture()
- : face(io)
- {
- }
-
void
initialize(const PeekOptions& opts)
{
@@ -66,7 +61,7 @@
protected:
boost::asio::io_service io;
- ndn::util::DummyClientFace face;
+ ndn::util::DummyClientFace face{io};
output_test_stream output;
unique_ptr<NdnPeek> peek;
};
@@ -76,7 +71,6 @@
{
PeekOptions opt;
opt.name = "ndn:/peek/test";
- opt.interestLifetime = DEFAULT_INTEREST_LIFETIME;
opt.timeout = 200_ms;
return opt;
}
@@ -145,7 +139,7 @@
initialize(options);
auto data = makeData(options.name);
- std::string payload = "NdnPeekTest";
+ const std::string payload = "NdnPeekTest";
data->setContent(reinterpret_cast<const uint8_t*>(payload.data()), payload.size());
{
@@ -159,8 +153,9 @@
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), false);
BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), false);
- BOOST_CHECK(face.sentInterests.back().getForwardingHint().empty());
+ BOOST_CHECK_EQUAL(face.sentInterests.back().getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
+ BOOST_CHECK_EQUAL(face.sentInterests.back().hasApplicationParameters(), false);
BOOST_CHECK(peek->getResultCode() == ResultCode::DATA);
}
@@ -174,7 +169,7 @@
auto data = makeData(Name(options.name).append("suffix"));
data->setFreshnessPeriod(1_s);
- std::string payload = "NdnPeekTest";
+ const std::string payload = "NdnPeekTest";
data->setContent(reinterpret_cast<const uint8_t*>(payload.data()), payload.size());
{
@@ -188,8 +183,9 @@
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
BOOST_CHECK_EQUAL(face.sentInterests.back().getCanBePrefix(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getMustBeFresh(), true);
- BOOST_CHECK(face.sentInterests.back().getForwardingHint().empty());
+ BOOST_CHECK_EQUAL(face.sentInterests.back().getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(face.sentInterests.back().getInterestLifetime(), 200_ms);
+ BOOST_CHECK_EQUAL(face.sentInterests.back().hasApplicationParameters(), false);
BOOST_CHECK(peek->getResultCode() == ResultCode::DATA);
}
@@ -228,22 +224,27 @@
OutputCheck::checkOutput(output, nack);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
- BOOST_CHECK_EQUAL(face.sentData.size(), 0);
- BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
BOOST_CHECK(peek->getResultCode() == ResultCode::NACK);
}
-BOOST_AUTO_TEST_CASE(TimeoutDefault)
+BOOST_AUTO_TEST_CASE(NoTimeout)
{
auto options = makeDefaultOptions();
+ options.interestLifetime = 1_s;
+ options.timeout = nullopt;
initialize(options);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
peek->start();
- this->advanceClocks(io, 25_ms, 4);
-
+ this->advanceClocks(io, 100_ms, 9);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face.getNPendingInterests(), 1);
+ BOOST_CHECK(peek->getResultCode() == ResultCode::UNKNOWN);
+
+ this->advanceClocks(io, 100_ms, 2);
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
}
@@ -254,12 +255,13 @@
options.timeout = 100_ms;
initialize(options);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
peek->start();
- this->advanceClocks(io, 25_ms, 8);
+ this->advanceClocks(io, 25_ms, 6);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
}
@@ -270,12 +272,13 @@
options.timeout = 200_ms;
initialize(options);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
peek->start();
this->advanceClocks(io, 25_ms, 4);
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0);
BOOST_CHECK(peek->getResultCode() == ResultCode::TIMEOUT);
}