detail: improve ScopedCancelHandle
This also removes deprecated implicit conversion operators
from 'FooHandle' types to 'const FooId*'
Change-Id: I5b412bf833bb106b8f5aa483dbe09b6c58736e19
diff --git a/tests/unit/detail/cancel-handle.t.cpp b/tests/unit/detail/cancel-handle.t.cpp
index b87f9cd..2e951dd 100644
--- a/tests/unit/detail/cancel-handle.t.cpp
+++ b/tests/unit/detail/cancel-handle.t.cpp
@@ -55,11 +55,13 @@
BOOST_AUTO_TEST_SUITE(ScopedHandle)
+using ScopedTestHandle = ScopedCancelHandle<CancelHandle>;
+
BOOST_AUTO_TEST_CASE(ManualCancel)
{
int nCancels = 0;
{
- ScopedCancelHandle hdl = makeDummyCancelHandle(nCancels);
+ ScopedTestHandle hdl = makeDummyCancelHandle(nCancels);
BOOST_CHECK_EQUAL(nCancels, 0);
hdl.cancel();
@@ -72,7 +74,7 @@
{
int nCancels = 0;
{
- ScopedCancelHandle hdl = makeDummyCancelHandle(nCancels);
+ ScopedTestHandle hdl = makeDummyCancelHandle(nCancels);
BOOST_CHECK_EQUAL(nCancels, 0);
} // hdl goes out of scope
BOOST_CHECK_EQUAL(nCancels, 1);
@@ -82,7 +84,7 @@
{
int nCancels1 = 0, nCancels2 = 0;
{
- ScopedCancelHandle hdl = makeDummyCancelHandle(nCancels1);
+ ScopedTestHandle hdl = makeDummyCancelHandle(nCancels1);
hdl = makeDummyCancelHandle(nCancels2);
BOOST_CHECK_EQUAL(nCancels1, 1);
BOOST_CHECK_EQUAL(nCancels2, 0);
@@ -94,7 +96,7 @@
{
int nCancels = 0;
{
- ScopedCancelHandle hdl = makeDummyCancelHandle(nCancels);
+ ScopedTestHandle hdl = makeDummyCancelHandle(nCancels);
hdl.release();
hdl.cancel(); // no effect
} // hdl goes out of scope
@@ -104,10 +106,10 @@
BOOST_AUTO_TEST_CASE(MoveConstruct)
{
int nCancels = 0;
- unique_ptr<ScopedCancelHandle> hdl1;
+ unique_ptr<ScopedTestHandle> hdl1;
{
- ScopedCancelHandle hdl2 = makeDummyCancelHandle(nCancels);
- hdl1 = make_unique<ScopedCancelHandle>(std::move(hdl2));
+ ScopedTestHandle hdl2 = makeDummyCancelHandle(nCancels);
+ hdl1 = make_unique<ScopedTestHandle>(std::move(hdl2));
} // hdl2 goes out of scope
BOOST_CHECK_EQUAL(nCancels, 0);
hdl1.reset();
@@ -118,9 +120,9 @@
{
int nCancels = 0;
{
- ScopedCancelHandle hdl1;
+ ScopedTestHandle hdl1;
{
- ScopedCancelHandle hdl2 = makeDummyCancelHandle(nCancels);
+ ScopedTestHandle hdl2 = makeDummyCancelHandle(nCancels);
hdl1 = std::move(hdl2);
} // hdl2 goes out of scope
BOOST_CHECK_EQUAL(nCancels, 0);
diff --git a/tests/unit/face.t.cpp b/tests/unit/face.t.cpp
index 43b4db5..eb01f8f 100644
--- a/tests/unit/face.t.cpp
+++ b/tests/unit/face.t.cpp
@@ -267,25 +267,6 @@
} while (false));
}
-BOOST_AUTO_TEST_CASE(RemovePendingInterestId)
-{
- const PendingInterestId* interestId =
- face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
- bind([] { BOOST_FAIL("Unexpected data"); }),
- bind([] { BOOST_FAIL("Unexpected nack"); }),
- bind([] { BOOST_FAIL("Unexpected timeout"); }));
- advanceClocks(10_ms);
-
- face.removePendingInterest(interestId);
- advanceClocks(10_ms);
-
- face.receive(*makeData("/Hello/World/%21"));
- advanceClocks(200_ms, 5);
-
- // avoid "test case [...] did not check any assertions" message from Boost.Test
- BOOST_CHECK(true);
-}
-
BOOST_AUTO_TEST_CASE(CancelPendingInterestHandle)
{
auto hdl = face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
@@ -391,7 +372,7 @@
bool hasInterest1 = false, hasData = false;
// first InterestFilter allows loopback and should receive Interest
- face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) {
+ face.setInterestFilter("/", [&] (const InterestFilter&, const Interest&) {
hasInterest1 = true;
// do not respond with Data right away, so Face must send Interest to forwarder
});
@@ -534,11 +515,10 @@
{
size_t nInterests = 0;
size_t nRegs = 0;
- const RegisteredPrefixId* regPrefixId =
- face.setInterestFilter("/Hello/World",
- bind([&nInterests] { ++nInterests; }),
- bind([&nRegs] { ++nRegs; }),
- bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); }));
+ auto hdl = face.setInterestFilter("/Hello/World",
+ bind([&nInterests] { ++nInterests; }),
+ bind([&nRegs] { ++nRegs; }),
+ bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); }));
advanceClocks(25_ms, 4);
BOOST_CHECK_EQUAL(nRegs, 1);
BOOST_CHECK_EQUAL(nInterests, 0);
@@ -558,7 +538,7 @@
BOOST_CHECK_EQUAL(nInterests, 2);
// removing filter
- face.unsetInterestFilter(regPrefixId);
+ hdl.cancel();
advanceClocks(25_ms, 4);
face.receive(*makeInterest("/Hello/World/%21/3"));
@@ -585,10 +565,9 @@
BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback)
{
size_t nInterests = 0;
- const RegisteredPrefixId* regPrefixId =
- face.setInterestFilter("/Hello/World",
- bind([&nInterests] { ++nInterests; }),
- bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); }));
+ auto hdl = face.setInterestFilter("/Hello/World",
+ bind([&nInterests] { ++nInterests; }),
+ bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); }));
advanceClocks(25_ms, 4);
BOOST_CHECK_EQUAL(nInterests, 0);
@@ -606,7 +585,7 @@
BOOST_CHECK_EQUAL(nInterests, 2);
// removing filter
- face.unsetInterestFilter(regPrefixId);
+ hdl.cancel();
advanceClocks(25_ms, 4);
face.receive(*makeInterest("/Hello/World/%21/3"));
@@ -650,18 +629,6 @@
BOOST_CHECK_EQUAL(nRegFailed, 1);
}
-BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefixFunc)
-{
- const RegisteredPrefixId* regPrefixId = nullptr;
- BOOST_CHECK(runPrefixReg([&] (const auto& success, const auto& failure) {
- regPrefixId = face.registerPrefix("/Hello/World", success, failure);
- }));
-
- BOOST_CHECK(runPrefixUnreg([&] (const auto& success, const auto& failure) {
- face.unregisterPrefix(regPrefixId, success, failure);
- }));
-}
-
BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FaceFixture<NoPrefixRegReply>)
{
BOOST_CHECK(!runPrefixReg([&] (const auto& success, const auto& failure) {
diff --git a/tests/unit/util/scheduler.t.cpp b/tests/unit/util/scheduler.t.cpp
index d403a7c..021c1f0 100644
--- a/tests/unit/util/scheduler.t.cpp
+++ b/tests/unit/util/scheduler.t.cpp
@@ -249,7 +249,7 @@
BOOST_CHECK(eid == EventId{});
}
-BOOST_AUTO_TEST_CASE(Valid)
+BOOST_AUTO_TEST_CASE(OperatorBool)
{
EventId eid;
BOOST_CHECK_EQUAL(static_cast<bool>(eid), false);
@@ -366,6 +366,26 @@
BOOST_CHECK_EQUAL(hit, 2);
}
+BOOST_AUTO_TEST_CASE(OperatorBool)
+{
+ ScopedEventId se;
+ BOOST_CHECK_EQUAL(static_cast<bool>(se), false);
+ BOOST_CHECK_EQUAL(!se, true);
+
+ se = scheduler.schedule(10_ms, []{});
+ BOOST_CHECK_EQUAL(static_cast<bool>(se), true);
+ BOOST_CHECK_EQUAL(!se, false);
+
+ se.cancel();
+ BOOST_CHECK(!se);
+
+ se = scheduler.schedule(10_ms, []{});
+ BOOST_CHECK(se);
+
+ se.release();
+ BOOST_CHECK(!se);
+}
+
BOOST_AUTO_TEST_SUITE_END() // ScopedEventId
BOOST_AUTO_TEST_SUITE_END() // TestScheduler