diff --git a/tests/daemon/mgmt/cs-manager.t.cpp b/tests/daemon/mgmt/cs-manager.t.cpp index d56b3d62..b4fe0512 100644 --- a/tests/daemon/mgmt/cs-manager.t.cpp +++ b/tests/daemon/mgmt/cs-manager.t.cpp @@ -71,8 +71,7 @@ BOOST_AUTO_TEST_CASE(Config) body.setCapacity(22129); body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, false, false); body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, true, false); - BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // send filled cs/config command @@ -87,8 +86,7 @@ BOOST_AUTO_TEST_CASE(Config) body.setCapacity(18609); body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_ADMIT, true, false); body.setFlagBit(CsFlagBit::BIT_CS_ENABLE_SERVE, false, false); - BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // CS shall have updated config @@ -119,28 +117,24 @@ BOOST_AUTO_TEST_CASE(Erase) const Name cmdPrefix = Name("/localhost/nfd").append(ndn::nfd::CsEraseCommand::getName()); // requested Name matches no Data - auto req = makeControlCommandRequest(cmdPrefix, - ControlParameters().setName("/A").setCount(1)); + auto req = makeControlCommandRequest(cmdPrefix, ControlParameters().setName("/A").setCount(1)); receiveInterest(req); // response should include zero as actual Count ControlParameters body; body.setName("/A"); body.setCount(0); - BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // requested Count is less than erase limit - req = makeControlCommandRequest(cmdPrefix, - ControlParameters().setName("/B").setCount(3)); + req = makeControlCommandRequest(cmdPrefix, ControlParameters().setName("/B").setCount(3)); receiveInterest(req); // response should include actual Count and omit Capacity body.setName("/B"); body.setCount(3); - BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(1, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // requested Count equals erase limit @@ -151,8 +145,7 @@ BOOST_AUTO_TEST_CASE(Erase) // response should include actual Count and omit Capacity body.setName("/E"); body.setCount(CsManager::ERASE_LIMIT - 1); - BOOST_CHECK_EQUAL(checkResponse(2, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(2, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // requested Count exceeds erase limit, but there are no more Data @@ -163,8 +156,7 @@ BOOST_AUTO_TEST_CASE(Erase) // response should include actual Count and omit Capacity body.setName("/F"); body.setCount(CsManager::ERASE_LIMIT); - BOOST_CHECK_EQUAL(checkResponse(3, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(3, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // requested Count exceeds erase limit, and there are more Data @@ -176,21 +168,18 @@ BOOST_AUTO_TEST_CASE(Erase) body.setName("/G"); body.setCount(CsManager::ERASE_LIMIT); body.setCapacity(CsManager::ERASE_LIMIT); - BOOST_CHECK_EQUAL(checkResponse(4, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(4, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // request omit Count, which implies "no limit" aka exceeds erase limit - req = makeControlCommandRequest(cmdPrefix, - ControlParameters().setName("/H")); + req = makeControlCommandRequest(cmdPrefix, ControlParameters().setName("/H")); receiveInterest(req); // response should include both actual Count and Capacity since there are more Data body.setName("/H"); body.setCount(CsManager::ERASE_LIMIT); body.setCapacity(CsManager::ERASE_LIMIT); - BOOST_CHECK_EQUAL(checkResponse(5, req.getName(), - ControlResponse(200, "OK").setBody(body.wireEncode())), + BOOST_CHECK_EQUAL(checkResponse(5, req.getName(), makeResponse(200, "OK", body)), CheckResponseResult::OK); // one Data each under /A, /G, /H remain, all other Data are erased diff --git a/tests/daemon/mgmt/face-manager-create-face.t.cpp b/tests/daemon/mgmt/face-manager-create-face.t.cpp index 31c4bf15..45e70d26 100644 --- a/tests/daemon/mgmt/face-manager-create-face.t.cpp +++ b/tests/daemon/mgmt/face-manager-create-face.t.cpp @@ -117,7 +117,6 @@ class LocalTcpFaceLocalFieldsEnabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); } }; @@ -130,7 +129,6 @@ class LocalTcpFaceLocalFieldsDisabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); } }; @@ -143,7 +141,6 @@ class NonLocalUdpFaceLocalFieldsEnabled // won't work because non-local scope { return ControlParameters() .setUri("udp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); } }; @@ -156,7 +153,6 @@ class NonLocalUdpFaceLocalFieldsDisabled { return ControlParameters() .setUri("udp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); } }; @@ -169,7 +165,6 @@ class TcpFaceLpReliabilityEnabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); } }; @@ -182,7 +177,6 @@ class TcpFaceLpReliabilityDisabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); } }; @@ -195,7 +189,6 @@ class UdpFaceLpReliabilityEnabled { return ControlParameters() .setUri("udp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); } }; @@ -208,7 +201,6 @@ class UdpFaceLpReliabilityDisabled { return ControlParameters() .setUri("udp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); } }; @@ -221,7 +213,6 @@ class TcpFaceCongestionMarkingEnabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setBaseCongestionMarkingInterval(50_ms) .setDefaultCongestionThreshold(1000) .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); @@ -236,7 +227,34 @@ class TcpFaceCongestionMarkingDisabled { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) + .setBaseCongestionMarkingInterval(50_ms) + .setDefaultCongestionThreshold(1000) + .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); + } +}; + +class UdpFaceCongestionMarkingEnabled +{ +public: + static ControlParameters + getParameters() + { + return ControlParameters() + .setUri("udp4://127.0.0.1:26363") + .setBaseCongestionMarkingInterval(50_ms) + .setDefaultCongestionThreshold(1000) + .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); + } +}; + +class UdpFaceCongestionMarkingDisabled +{ +public: + static ControlParameters + getParameters() + { + return ControlParameters() + .setUri("udp4://127.0.0.1:26363") .setBaseCongestionMarkingInterval(50_ms) .setDefaultCongestionThreshold(1000) .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); @@ -251,7 +269,6 @@ class TcpFaceMtuOverride { return ControlParameters() .setUri("tcp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setMtu(1000); } }; @@ -264,12 +281,11 @@ class UdpFaceMtuOverride { return ControlParameters() .setUri("udp4://127.0.0.1:26363") - .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) .setMtu(1000); } }; -class FaceUriMalformed +class RemoteUriMalformed { public: static ControlParameters @@ -280,7 +296,7 @@ class FaceUriMalformed } }; -class FaceUriNonCanonical +class RemoteUriNonCanonical { public: static ControlParameters @@ -291,7 +307,43 @@ class FaceUriNonCanonical } }; -class FaceUriUnsupportedScheme +class LocalUriMalformed +{ +public: + static ControlParameters + getParameters() + { + return ControlParameters() + .setUri("udp4://127.0.0.1:26363") + .setLocalUri("udp4://127.0.0.1:not-a-port"); + } +}; + +class LocalUriNonCanonical +{ +public: + static ControlParameters + getParameters() + { + return ControlParameters() + .setUri("udp4://127.0.0.1:26363") + .setLocalUri("udp://localhost"); + } +}; + +class LocalUriUnsupported +{ +public: + static ControlParameters + getParameters() + { + return ControlParameters() + .setUri("udp4://127.0.0.1:26363") + .setLocalUri("udp4://127.0.0.1:36363"); + } +}; + +class UnsupportedProtocol { public: static ControlParameters @@ -302,7 +354,7 @@ class FaceUriUnsupportedScheme } }; -// Pairs of CreateCommand and success/failure status +// Pairs of FaceCreateCommand request and success/failure response using TestCases = boost::mp11::mp_list< boost::mp11::mp_list>, boost::mp11::mp_list, @@ -320,19 +372,24 @@ using TestCases = boost::mp11::mp_list< boost::mp11::mp_list, boost::mp11::mp_list, boost::mp11::mp_list, + boost::mp11::mp_list, + boost::mp11::mp_list, boost::mp11::mp_list>, boost::mp11::mp_list, - boost::mp11::mp_list>, - boost::mp11::mp_list>, - boost::mp11::mp_list> + boost::mp11::mp_list>, + boost::mp11::mp_list>, + boost::mp11::mp_list>, + boost::mp11::mp_list>, + boost::mp11::mp_list>, + boost::mp11::mp_list> >; BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixture) { - using FaceType = boost::mp11::mp_first; + using CreateRequest = boost::mp11::mp_first; using CreateResult = boost::mp11::mp_second; - Interest req = makeControlCommandRequest(this->CREATE_REQUEST, FaceType::getParameters()); + Interest req = makeControlCommandRequest(this->CREATE_REQUEST, CreateRequest::getParameters()); bool hasCallbackFired = false; this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) { @@ -342,15 +399,18 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur ControlResponse actual(response.getContent().blockFromValue()); ControlResponse expected(CreateResult::getExpected()); - BOOST_TEST_MESSAGE(actual.getText()); - BOOST_CHECK_EQUAL(expected.getCode(), actual.getCode()); + BOOST_TEST(expected.getCode() == actual.getCode(), actual.getText()); if (actual.getBody().hasWire()) { - ControlParameters expectedParams(FaceType::getParameters()); + ControlParameters expectedParams(CreateRequest::getParameters()); + ndn::nfd::FaceCreateCommand::applyDefaultsToRequest(expectedParams); ControlParameters actualParams(actual.getBody()); - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK_EQUAL(expectedParams.getFacePersistency(), actualParams.getFacePersistency()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(expectedParams.getUri() == actualParams.getUri()); + BOOST_TEST(actualParams.hasLocalUri()); + BOOST_TEST(actualParams.hasFlags()); + BOOST_TEST(expectedParams.getFacePersistency() == actualParams.getFacePersistency()); if (actual.getCode() == 200) { if (expectedParams.hasFlags()) { @@ -363,15 +423,16 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); } else { - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); + // congestion marking is enabled by default + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); } } else { - // local fields and LpReliability are disabled by default, congestion marking is enabled - // by default on TCP, UDP, and Unix stream - BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); - BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); + // local fields and reliability are disabled by default + // congestion marking is enabled by default on TCP, UDP, and Unix stream + BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); + BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); } if (expectedParams.hasBaseCongestionMarkingInterval()) { @@ -394,14 +455,11 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur BOOST_CHECK_EQUAL(expectedParams.getMtu(), actualParams.getMtu()); } } - else { - BOOST_CHECK_EQUAL(expectedParams.getUri(), actualParams.getUri()); - } } if (actual.getCode() != 200) { FaceUri uri; - if (uri.parse(FaceType::getParameters().getUri())) { + if (uri.parse(CreateRequest::getParameters().getUri())) { // ensure face not created const auto& faceTable = this->node1.faceTable; BOOST_CHECK(std::none_of(faceTable.begin(), faceTable.end(), [uri] (Face& face) { @@ -419,7 +477,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur this->node1.face.receive(req); this->advanceClocks(1_ms, 10); - BOOST_CHECK(hasCallbackFired); + BOOST_TEST(hasCallbackFired); } BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture) @@ -435,7 +493,7 @@ BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture) // find the created face auto foundFace = this->node1.findFaceByUri(FaceType::getParameters().getUri()); - BOOST_REQUIRE(foundFace != nullptr); + BOOST_TEST_REQUIRE(foundFace != nullptr); { // re-create face @@ -467,7 +525,7 @@ BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture) this->node1.face.receive(req); this->advanceClocks(1_ms, 10); - BOOST_CHECK(hasCallbackFired); + BOOST_TEST(hasCallbackFired); } } diff --git a/tests/daemon/mgmt/face-manager-update-face.t.cpp b/tests/daemon/mgmt/face-manager-update-face.t.cpp index 7ccc9f27..202e360f 100644 --- a/tests/daemon/mgmt/face-manager-update-face.t.cpp +++ b/tests/daemon/mgmt/face-manager-update-face.t.cpp @@ -88,28 +88,25 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1; bool hasCallbackFired = false; - signal::ScopedConnection connection = target.face.onSendData.connect( - [&, req, isForOnDemandFace, this] (const Data& response) { - if (!req.getName().isPrefixOf(response.getName())) { - return; - } - - ControlResponse create(response.getContent().blockFromValue()); - BOOST_REQUIRE_EQUAL(create.getCode(), 200); - BOOST_REQUIRE(create.getBody().hasWire()); - - ControlParameters faceParams(create.getBody()); - BOOST_REQUIRE(faceParams.hasFaceId()); - this->faceId = faceParams.getFaceId(); - - hasCallbackFired = true; - - if (isForOnDemandFace) { - auto face = target.faceTable.get(static_cast(this->faceId)); - // to force creation of on-demand face - face->sendInterest(*makeInterest("/hello/world")); - } - }); + signal::ScopedConnection conn = target.face.onSendData.connect([&] (const Data& response) { + if (!req.getName().isPrefixOf(response.getName())) { + return; + } + + ControlResponse create(response.getContent().blockFromValue()); + BOOST_TEST_REQUIRE(create.getCode() == 200); + ControlParameters faceParams(create.getBody()); + BOOST_TEST_REQUIRE(faceParams.hasFaceId()); + this->faceId = faceParams.getFaceId(); + + hasCallbackFired = true; + + if (isForOnDemandFace) { + auto face = target.faceTable.get(this->faceId); + // to force creation of on-demand face + face->sendInterest(*makeInterest("/hello/world")); + } + }); target.face.receive(req); advanceClocks(1_ms, 10); @@ -119,12 +116,11 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture advanceClocks(1_ms, 10); // let node1 accept Interest and create on-demand face } - BOOST_REQUIRE(hasCallbackFired); + BOOST_TEST_REQUIRE(hasCallbackFired); } void - updateFace(const ControlParameters& requestParams, - bool isSelfUpdating, + updateFace(const ControlParameters& requestParams, bool isSelfUpdating, const std::function& checkResp) { Interest req = makeControlCommandRequest(UPDATE_REQUEST, requestParams); @@ -134,21 +130,20 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture } bool hasCallbackFired = false; - signal::ScopedConnection connection = this->node1.face.onSendData.connect( - [req, &hasCallbackFired, &checkResp] (const Data& response) { - if (!req.getName().isPrefixOf(response.getName())) { - return; - } + signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) { + if (!req.getName().isPrefixOf(response.getName())) { + return; + } - ControlResponse actual(response.getContent().blockFromValue()); - checkResp(actual); + ControlResponse actual(response.getContent().blockFromValue()); + checkResp(actual); - hasCallbackFired = true; - }); + hasCallbackFired = true; + }); this->node1.face.receive(req); advanceClocks(1_ms, 10); - BOOST_REQUIRE(hasCallbackFired); + BOOST_TEST_REQUIRE(hasCallbackFired); } private: @@ -164,22 +159,21 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture Interest req = makeControlCommandRequest(DESTROY_REQUEST, params); bool hasCallbackFired = false; - signal::ScopedConnection connection = this->node1.face.onSendData.connect( - [this, req, &hasCallbackFired] (const Data& response) { - if (!req.getName().isPrefixOf(response.getName())) { - return; - } + signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) { + if (!req.getName().isPrefixOf(response.getName())) { + return; + } - ControlResponse destroy(response.getContent().blockFromValue()); - BOOST_CHECK_EQUAL(destroy.getCode(), 200); + ControlResponse destroy(response.getContent().blockFromValue()); + BOOST_CHECK_EQUAL(destroy.getCode(), 200); - faceId = 0; - hasCallbackFired = true; - }); + faceId = 0; + hasCallbackFired = true; + }); this->node1.face.receive(req); advanceClocks(1_ms, 10); - BOOST_REQUIRE(hasCallbackFired); + BOOST_TEST_REQUIRE(hasCallbackFired); } protected: @@ -194,9 +188,8 @@ BOOST_AUTO_TEST_CASE(FaceDoesNotExist) requestParams.setFaceId(65535); updateFace(requestParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(404, "Specified face does not exist"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); + BOOST_TEST(actual.getCode() == 404); + BOOST_TEST(actual.getText() == "Specified face does not exist"); }); } @@ -219,15 +212,11 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, F .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); updateFace(parameters, false, [] (const ControlResponse& actual) { - BOOST_TEST_MESSAGE(actual.getText()); - BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode()); - - // the response for either 200 or 409 will have a content body - BOOST_REQUIRE(actual.getBody().hasWire()); + BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText()); - ControlParameters resp; - resp.wireDecode(actual.getBody()); - BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); + // the response for either 200 or 409 will have a content body + ControlParameters resp(actual.getBody()); + BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); }); } @@ -244,37 +233,24 @@ BOOST_AUTO_TEST_CASE(UpdateMtu) mtuTooLow.setMtu(63); updateFace(validParams, false, [] (const ControlResponse& actual) { - BOOST_CHECK_EQUAL(actual.getCode(), 200); - BOOST_TEST_MESSAGE(actual.getText()); + BOOST_TEST(actual.getCode() == 200, actual.getText()); - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_REQUIRE(actualParams.hasMtu()); - // Check for changed MTU - BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); - } - else { - BOOST_ERROR("Valid: Response does not contain ControlParameters"); - } + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST_REQUIRE(actualParams.hasMtu()); + // Check for changed MTU + BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); }); updateFace(mtuTooLow, false, [] (const ControlResponse& actual) { - BOOST_CHECK_EQUAL(actual.getCode(), 409); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(!actualParams.hasFaceId()); - BOOST_REQUIRE(actualParams.hasMtu()); - // Check for returned invalid parameter - BOOST_CHECK_EQUAL(actualParams.getMtu(), 63); - } - else { - BOOST_ERROR("Too low: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 409); + BOOST_TEST(actual.getText() == "Invalid properties specified"); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(!actualParams.hasFaceId()); + BOOST_TEST_REQUIRE(actualParams.hasMtu()); + // Check for returned invalid parameter + BOOST_CHECK_EQUAL(actualParams.getMtu(), 63); }); } @@ -287,231 +263,62 @@ BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace) updateParams.setMtu(4000); updateFace(updateParams, false, [] (const ControlResponse& actual) { - BOOST_CHECK_EQUAL(actual.getCode(), 409); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(!actualParams.hasFaceId()); - BOOST_REQUIRE(actualParams.hasMtu()); - // Check for returned invalid parameter - BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); - } - else { - BOOST_ERROR("Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 409); + BOOST_TEST(actual.getText() == "Invalid properties specified"); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(!actualParams.hasFaceId()); + BOOST_TEST_REQUIRE(actualParams.hasMtu()); + // Check for returned invalid parameter + BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000); }); } -class TcpLocalFieldsEnable +template +struct TcpLocalFields { -public: - static std::string - getUri() - { - return "tcp4://127.0.0.1:26363"; - } - - static constexpr ndn::nfd::FacePersistency - getPersistency() - { - return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - } - - static constexpr bool - getInitLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabled() - { - return true; - } - - static constexpr bool - getLocalFieldsEnabledMask() - { - return true; - } - - static constexpr bool - shouldHaveWire() - { - return false; - } + static inline const std::string uri = "tcp4://127.0.0.1:26363"; + static constexpr bool localFieldsInit = !EnableLocalFields; + static constexpr bool localFieldsEnabled = EnableLocalFields; + static constexpr bool mask = true; + static constexpr bool shouldHaveBody = false; }; -class TcpLocalFieldsDisable +// UDP faces are non-local by definition. +struct UdpLocalFieldsEnable { -public: - static std::string - getUri() - { - return "tcp4://127.0.0.1:26363"; - } - - static constexpr ndn::nfd::FacePersistency - getPersistency() - { - return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - } - - static constexpr bool - getInitLocalFieldsEnabled() - { - return true; - } - - static constexpr bool - getLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabledMask() - { - return true; - } - - static constexpr bool - shouldHaveWire() - { - return false; - } + static inline const std::string uri = "udp4://127.0.0.1:26363"; + static constexpr bool localFieldsInit = false; + static constexpr bool localFieldsEnabled = true; + static constexpr bool mask = true; + static constexpr bool shouldHaveBody = true; }; -// UDP faces are non-local by definition -class UdpLocalFieldsEnable +// UDP faces are non-local by definition. +// In this test case, attempt to disable local fields on face with local fields already disabled. +struct UdpLocalFieldsDisable { -public: - static std::string - getUri() - { - return "udp4://127.0.0.1:26363"; - } - - static constexpr ndn::nfd::FacePersistency - getPersistency() - { - return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - } - - static constexpr bool - getInitLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabled() - { - return true; - } - - static constexpr bool - getLocalFieldsEnabledMask() - { - return true; - } - - static constexpr bool - shouldHaveWire() - { - return true; - } -}; - -// UDP faces are non-local by definition -// In this test case, attempt to disable local fields on face with local fields already disabled -class UdpLocalFieldsDisable -{ -public: - static std::string - getUri() - { - return "udp4://127.0.0.1:26363"; - } - - static constexpr ndn::nfd::FacePersistency - getPersistency() - { - return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - } - - static constexpr bool - getInitLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabledMask() - { - return true; - } - - static constexpr bool - shouldHaveWire() - { - return false; - } + static inline const std::string uri = "udp4://127.0.0.1:26363"; + static constexpr bool localFieldsInit = false; + static constexpr bool localFieldsEnabled = false; + static constexpr bool mask = true; + static constexpr bool shouldHaveBody = false; }; // In this test case, set Flags to enable local fields on non-local face, but exclude local fields // from Mask. This test case will pass as no action is taken due to the missing Mask bit. -class UdpLocalFieldsEnableNoMaskBit +struct UdpLocalFieldsEnableNoMaskBit { -public: - static std::string - getUri() - { - return "udp4://127.0.0.1:26363"; - } - - static constexpr ndn::nfd::FacePersistency - getPersistency() - { - return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - } - - static constexpr bool - getInitLocalFieldsEnabled() - { - return false; - } - - static constexpr bool - getLocalFieldsEnabled() - { - return true; - } - - static constexpr bool - getLocalFieldsEnabledMask() - { - return false; - } - - static constexpr bool - shouldHaveWire() - { - return false; - } + static inline const std::string uri = "udp4://127.0.0.1:26363"; + static constexpr bool localFieldsInit = false; + static constexpr bool localFieldsEnabled = true; + static constexpr bool mask = false; + static constexpr bool shouldHaveBody = false; }; using LocalFieldFaces = boost::mp11::mp_list< - boost::mp11::mp_list, - boost::mp11::mp_list, + boost::mp11::mp_list, CommandSuccess>, + boost::mp11::mp_list, CommandSuccess>, boost::mp11::mp_list>, boost::mp11::mp_list, boost::mp11::mp_list @@ -522,28 +329,24 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces) using TestType = boost::mp11::mp_first; using ResultType = boost::mp11::mp_second; - createFace(TestType::getUri(), TestType::getPersistency(), {}, {}, - TestType::getInitLocalFieldsEnabled()); + createFace(TestType::uri, ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, TestType::localFieldsInit); ControlParameters requestParams; requestParams.setFaceId(faceId); - requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled()); - if (!TestType::getLocalFieldsEnabledMask()) { + requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::localFieldsEnabled); + if constexpr (!TestType::mask) { requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED); } updateFace(requestParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(ResultType::getExpected()); - BOOST_TEST_MESSAGE(actual.getText()); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); + BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText()); - if (TestType::shouldHaveWire() && actual.getBody().hasWire()) { + if constexpr (TestType::shouldHaveBody) { ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(!actualParams.hasFacePersistency()); - BOOST_CHECK(actualParams.hasFlags()); - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); - BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); + BOOST_TEST(!actualParams.hasFacePersistency()); + BOOST_TEST(actualParams.hasFlags()); + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); + BOOST_TEST(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); } }); } @@ -561,41 +364,25 @@ BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable) disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); updateFace(enableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate local fields enabled - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); - } - else { - BOOST_ERROR("Enable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate local fields enabled + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); }); updateFace(disableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate local fields disabled - BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); - } - else { - BOOST_ERROR("Disable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate local fields disabled + BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); }); } @@ -612,41 +399,25 @@ BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable) disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); updateFace(enableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate reliability enabled - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); - } - else { - BOOST_ERROR("Enable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate reliability enabled + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); }); updateFace(disableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate reliability disabled - BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); - } - else { - BOOST_ERROR("Disable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate reliability disabled + BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); }); } @@ -667,51 +438,35 @@ BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable) disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); updateFace(enableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - // Check that congestion marking parameters changed - BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); - BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms); - BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); - BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate congestion marking enabled - BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); - } - else { - BOOST_ERROR("Enable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + // Check that congestion marking parameters changed + BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); + BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms); + BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); + BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate congestion marking enabled + BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); }); updateFace(disableParams, false, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); - - if (actual.getBody().hasWire()) { - ControlParameters actualParams(actual.getBody()); - - BOOST_CHECK(actualParams.hasFaceId()); - BOOST_CHECK(actualParams.hasFacePersistency()); - // Check that congestion marking parameters changed, even though feature disabled - BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); - BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms); - BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); - BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000); - BOOST_REQUIRE(actualParams.hasFlags()); - // Check if flags indicate marking disabled - BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); - } - else { - BOOST_ERROR("Disable: Response does not contain ControlParameters"); - } + BOOST_TEST(actual.getCode() == 200, actual.getText()); + + ControlParameters actualParams(actual.getBody()); + BOOST_TEST(actualParams.hasFaceId()); + BOOST_TEST(actualParams.hasFacePersistency()); + // Check that congestion marking parameters changed, even though feature disabled + BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval()); + BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms); + BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold()); + BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000); + BOOST_TEST_REQUIRE(actualParams.hasFlags()); + // Check if flags indicate marking disabled + BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); }); } @@ -719,13 +474,18 @@ BOOST_AUTO_TEST_CASE(SelfUpdating) { createFace(); - // Send a command that does nothing (will return 200) and does not contain a FaceId + // Send a command that does nothing and does not contain a FaceId ControlParameters sentParams; + // Success case: FaceId is obtained automatically from IncomingFaceIdTag updateFace(sentParams, true, [] (const ControlResponse& actual) { - ControlResponse expected(200, "OK"); - BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode()); - BOOST_TEST_MESSAGE(actual.getText()); + BOOST_TEST(actual.getCode() == 200, actual.getText()); + }); + + // Error case: IncomingFaceIdTag is missing + updateFace(sentParams, false, [] (const ControlResponse& actual) { + BOOST_TEST(actual.getCode() == 404); + BOOST_TEST(actual.getText() == "No FaceId specified and IncomingFaceId not available"); }); } diff --git a/tests/daemon/mgmt/face-manager.t.cpp b/tests/daemon/mgmt/face-manager.t.cpp index b0ad678c..6d25143e 100644 --- a/tests/daemon/mgmt/face-manager.t.cpp +++ b/tests/daemon/mgmt/face-manager.t.cpp @@ -43,7 +43,7 @@ namespace nfd::tests { class FaceManagerFixture : public ManagerFixtureWithAuthenticator { -public: +protected: FaceManagerFixture() : m_faceSystem(m_faceTable, make_shared(0)) , m_manager(m_faceSystem, m_dispatcher, *m_authenticator) @@ -52,32 +52,20 @@ class FaceManagerFixture : public ManagerFixtureWithAuthenticator setPrivilege("faces"); } -public: enum AddFaceFlags { REMOVE_LAST_NOTIFICATION = 1 << 0, - SET_SCOPE_LOCAL = 1 << 1, - SET_URI_TEST = 1 << 2, - RANDOMIZE_COUNTERS = 1 << 3, + RANDOMIZE_COUNTERS = 1 << 1, }; /** * \brief Adds a face to the FaceTable. * \param flags bitwise OR'ed AddFaceFlags */ + template shared_ptr - addFace(unsigned int flags = 0) + addFace(unsigned int flags = 0, Args&&... args) { - std::string uri = "dummy://"; - ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL; - - if (flags & SET_SCOPE_LOCAL) { - scope = ndn::nfd::FACE_SCOPE_LOCAL; - } - if (flags & SET_URI_TEST) { - uri = "test://"; - } - - auto face = make_shared(uri, uri, scope); + auto face = make_shared(std::forward(args)...); m_faceTable.add(face); if (flags & RANDOMIZE_COUNTERS) { @@ -96,7 +84,7 @@ class FaceManagerFixture : public ManagerFixtureWithAuthenticator advanceClocks(1_ms, 10); // wait for notification posted if (flags & REMOVE_LAST_NOTIFICATION) { - BOOST_REQUIRE(!m_responses.empty()); + BOOST_TEST_REQUIRE(!m_responses.empty()); m_responses.pop_back(); } @@ -124,7 +112,7 @@ BOOST_AUTO_TEST_SUITE(DestroyFace) BOOST_AUTO_TEST_CASE(Existing) { - auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation + auto addedFace = addFace(REMOVE_LAST_NOTIFICATION); // clear notification for creation auto parameters = ControlParameters().setFaceId(addedFace->getId()); auto req = makeControlCommandRequest(FaceManagerCommandFixture::DESTROY_REQUEST, parameters); @@ -158,7 +146,7 @@ BOOST_AUTO_TEST_CASE(FaceDataset) { const size_t nEntries = 32; for (size_t i = 0; i < nEntries; ++i) { - addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST | RANDOMIZE_COUNTERS); + addFace(REMOVE_LAST_NOTIFICATION | RANDOMIZE_COUNTERS, "test://", "test://"); } receiveInterest(Interest("/localhost/nfd/faces/list").setCanBePrefix(true)); @@ -167,9 +155,9 @@ BOOST_AUTO_TEST_CASE(FaceDataset) content.parse(); BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); - std::set faceIds; - for (size_t idx = 0; idx < nEntries; ++idx) { - ndn::nfd::FaceStatus decodedStatus(content.elements()[idx]); + std::unordered_set faceIds; + for (const auto& el : content.elements()) { + ndn::nfd::FaceStatus decodedStatus(el); BOOST_TEST_INFO_SCOPE(decodedStatus); BOOST_CHECK(m_faceTable.get(decodedStatus.getFaceId()) != nullptr); faceIds.insert(decodedStatus.getFaceId()); @@ -178,16 +166,15 @@ BOOST_AUTO_TEST_CASE(FaceDataset) ndn::nfd::FaceStatus status(content.elements().front()); const Face* face = m_faceTable.get(status.getFaceId()); - BOOST_REQUIRE(face != nullptr); + BOOST_TEST_REQUIRE(face != nullptr); // check face properties BOOST_CHECK_EQUAL(status.getRemoteUri(), face->getRemoteUri().toString()); BOOST_CHECK_EQUAL(status.getLocalUri(), face->getLocalUri().toString()); - BOOST_CHECK_EQUAL(status.hasExpirationPeriod(), - face->getExpirationTime() != time::steady_clock::time_point::max()); - BOOST_CHECK_EQUAL(status.getFaceScope(), face->getScope()); - BOOST_CHECK_EQUAL(status.getFacePersistency(), face->getPersistency()); - BOOST_CHECK_EQUAL(status.getLinkType(), face->getLinkType()); + BOOST_TEST(!status.hasExpirationPeriod()); + BOOST_CHECK_EQUAL(status.getFaceScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); + BOOST_CHECK_EQUAL(status.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); + BOOST_CHECK_EQUAL(status.getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT); // check link service properties BOOST_CHECK_EQUAL(status.hasBaseCongestionMarkingInterval(), false); @@ -195,7 +182,7 @@ BOOST_AUTO_TEST_CASE(FaceDataset) BOOST_CHECK_EQUAL(status.getFlags(), 0); // check transport properties - BOOST_CHECK_EQUAL(status.hasMtu(), true); + BOOST_TEST_REQUIRE(status.hasMtu()); BOOST_CHECK_EQUAL(status.getMtu(), ndn::MAX_NDN_PACKET_SIZE); // check counters @@ -213,56 +200,82 @@ BOOST_AUTO_TEST_CASE(FaceQuery) { using ndn::nfd::FaceQueryFilter; - auto face1 = addFace(REMOVE_LAST_NOTIFICATION); // dummy:// - auto face2 = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // dummy://, local - auto face3 = addFace(REMOVE_LAST_NOTIFICATION | SET_URI_TEST); // test:// + auto face1 = addFace(REMOVE_LAST_NOTIFICATION, "dummy://one", "dummy://one", + ndn::nfd::FACE_SCOPE_NON_LOCAL, + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + ndn::nfd::LINK_TYPE_POINT_TO_POINT); + auto face2 = addFace(REMOVE_LAST_NOTIFICATION, "dummy://two", "remote://foo", + ndn::nfd::FACE_SCOPE_LOCAL, + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + ndn::nfd::LINK_TYPE_POINT_TO_POINT); + auto face3 = addFace(REMOVE_LAST_NOTIFICATION, "local://bar", "remote://foo", + ndn::nfd::FACE_SCOPE_NON_LOCAL, + ndn::nfd::FACE_PERSISTENCY_PERMANENT, + ndn::nfd::LINK_TYPE_POINT_TO_POINT); + auto face4 = addFace(REMOVE_LAST_NOTIFICATION, "local://bar", "dummy://four", + ndn::nfd::FACE_SCOPE_NON_LOCAL, + ndn::nfd::FACE_PERSISTENCY_PERSISTENT, + ndn::nfd::LINK_TYPE_AD_HOC); auto generateQuery = [] (const auto& filter) { return Interest(Name("/localhost/nfd/faces/query").append(filter.wireEncode())) .setCanBePrefix(true); }; - auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy")); + auto allQuery = generateQuery(FaceQueryFilter()); + auto noneQuery = generateQuery(FaceQueryFilter().setUriScheme("nomatch")); auto idQuery = generateQuery(FaceQueryFilter().setFaceId(face1->getId())); - auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)); + auto schemeQuery = generateQuery(FaceQueryFilter().setUriScheme("dummy")); + auto remoteQuery = generateQuery(FaceQueryFilter().setRemoteUri("remote://foo")); + auto localQuery = generateQuery(FaceQueryFilter().setLocalUri("local://bar")); + auto scopeQuery = generateQuery(FaceQueryFilter().setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)); + auto persistencyQuery = generateQuery(FaceQueryFilter().setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)); + auto linkQuery = generateQuery(FaceQueryFilter().setLinkType(ndn::nfd::LINK_TYPE_AD_HOC)); auto invalidQueryName = Name("/localhost/nfd/faces/query") .append(ndn::makeStringBlock(tlv::Content, "invalid")); auto invalidQuery = Interest(invalidQueryName).setCanBePrefix(true); - receiveInterest(schemeQuery); // face1 and face2 expected + receiveInterest(allQuery); // all 4 faces expected + receiveInterest(noneQuery); // no faces expected receiveInterest(idQuery); // face1 expected - receiveInterest(scopeQuery); // face1 and face3 expected + receiveInterest(schemeQuery); // face1, face2, face4 expected + receiveInterest(remoteQuery); // face2 and face3 expected + receiveInterest(localQuery); // face3 and face4 expected + receiveInterest(scopeQuery); // face2 expected + receiveInterest(persistencyQuery); // face3 expected + receiveInterest(linkQuery); // face4 expected receiveInterest(invalidQuery); // nack expected - BOOST_REQUIRE_EQUAL(m_responses.size(), 4); - - Block content; - ndn::nfd::FaceStatus status; - - content = m_responses[0].getContent(); - content.parse(); - BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face2 - status.wireDecode(content.elements()[0]); - BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); - status.wireDecode(content.elements()[1]); - BOOST_CHECK_EQUAL(face2->getId(), status.getFaceId()); - - content = m_responses[1].getContent(); - content.parse(); - BOOST_CHECK_EQUAL(content.elements().size(), 1); // face1 - status.wireDecode(content.elements()[0]); - BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); + BOOST_REQUIRE_EQUAL(m_responses.size(), 10); + + auto checkQueryResponse = [this] (size_t idx, const std::unordered_set& expected) { + BOOST_TEST_INFO("Response index = " << idx); + const Block& content = m_responses.at(idx).getContent(); + content.parse(); + std::unordered_set actual; + std::string actualStr; + for (const auto& el : content.elements()) { + ndn::nfd::FaceStatus status(el); + actual.insert(status.getFaceId()); + actualStr += std::to_string(status.getFaceId()) + " "; + } + BOOST_TEST_INFO("Content = { " << actualStr << "}"); + BOOST_TEST(actual == expected); + }; - content = m_responses[2].getContent(); - content.parse(); - BOOST_CHECK_EQUAL(content.elements().size(), 2); // face1 and face3 - status.wireDecode(content.elements()[0]); - BOOST_CHECK_EQUAL(face1->getId(), status.getFaceId()); - status.wireDecode(content.elements()[1]); - BOOST_CHECK_EQUAL(face3->getId(), status.getFaceId()); - - ControlResponse expectedResponse(400, "Malformed filter"); // nack, 400, malformed filter - BOOST_CHECK_EQUAL(checkResponse(3, invalidQueryName, expectedResponse, tlv::ContentType_Nack), + checkQueryResponse(0, {face1->getId(), face2->getId(), face3->getId(), face4->getId()}); + checkQueryResponse(1, {}); + checkQueryResponse(2, {face1->getId()}); + checkQueryResponse(3, {face1->getId(), face2->getId(), face4->getId()}); + checkQueryResponse(4, {face2->getId(), face3->getId()}); + checkQueryResponse(5, {face3->getId(), face4->getId()}); + checkQueryResponse(6, {face2->getId()}); + checkQueryResponse(7, {face3->getId()}); + checkQueryResponse(8, {face4->getId()}); + + // nack, 400, malformed filter + ControlResponse expectedResponse(400, "Malformed filter"); + BOOST_CHECK_EQUAL(checkResponse(9, invalidQueryName, expectedResponse, tlv::ContentType_Nack), CheckResponseResult::OK); } @@ -330,10 +343,10 @@ BOOST_AUTO_TEST_CASE(ChannelDataset) content.parse(); BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); - for (size_t idx = 0; idx < nEntries; ++idx) { - ndn::nfd::ChannelStatus decodedStatus(content.elements()[idx]); + for (const auto& el : content.elements()) { + ndn::nfd::ChannelStatus decodedStatus(el); BOOST_TEST_INFO_SCOPE(decodedStatus); - BOOST_CHECK(addedChannels.find(decodedStatus.getLocalUri()) != addedChannels.end()); + BOOST_TEST(addedChannels.count(decodedStatus.getLocalUri()) == 1); } } diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp index af03ae1e..9cab78f0 100644 --- a/tests/daemon/mgmt/fib-manager.t.cpp +++ b/tests/daemon/mgmt/fib-manager.t.cpp @@ -147,7 +147,7 @@ operator<<(std::ostream& os, FibManagerFixture::CheckNextHopResult result) case FibManagerFixture::CheckNextHopResult::WRONG_COST: return os << "WRONG_COST"; } - return os << static_cast(result); + return os << ndn::to_underlying(result); } BOOST_AUTO_TEST_SUITE(Mgmt) @@ -422,14 +422,14 @@ BOOST_AUTO_TEST_CASE(FibDataset) BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); std::vector receivedRecords, expectedRecords; - for (size_t idx = 0; idx < nEntries; ++idx) { - ndn::nfd::FibEntry decodedEntry(content.elements()[idx]); + for (const auto& el : content.elements()) { + ndn::nfd::FibEntry decodedEntry(el); BOOST_TEST_INFO_SCOPE(decodedEntry); receivedRecords.push_back(decodedEntry); actualPrefixes.erase(decodedEntry.getPrefix()); auto matchedEntry = m_fib.findExactMatch(decodedEntry.getPrefix()); - BOOST_REQUIRE(matchedEntry != nullptr); + BOOST_TEST_REQUIRE(matchedEntry != nullptr); expectedRecords.emplace_back(); expectedRecords.back().setPrefix(matchedEntry->getPrefix()); diff --git a/tests/daemon/mgmt/forwarder-status-manager.t.cpp b/tests/daemon/mgmt/forwarder-status-manager.t.cpp index 56db14a8..039a1019 100644 --- a/tests/daemon/mgmt/forwarder-status-manager.t.cpp +++ b/tests/daemon/mgmt/forwarder-status-manager.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -85,9 +85,8 @@ BOOST_AUTO_TEST_CASE(GeneralStatusDataset) auto afterRequest = time::system_clock::now(); // verify - Block response = this->concatenateResponses(0, m_responses.size()); - ndn::nfd::ForwarderStatus status; - BOOST_REQUIRE_NO_THROW(status.wireDecode(response)); + Block content = concatenateResponses(); + ndn::nfd::ForwarderStatus status(content); BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION_BUILD_STRING); BOOST_CHECK_EQUAL(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(m_startTime)); diff --git a/tests/daemon/mgmt/manager-common-fixture.cpp b/tests/daemon/mgmt/manager-common-fixture.cpp index e918cdb3..4a759837 100644 --- a/tests/daemon/mgmt/manager-common-fixture.cpp +++ b/tests/daemon/mgmt/manager-common-fixture.cpp @@ -29,7 +29,8 @@ namespace nfd::tests { InterestSignerFixture::InterestSignerFixture() { - BOOST_REQUIRE(m_keyChain.createIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY)); + auto id = m_keyChain.createIdentity(DEFAULT_COMMAND_SIGNER_IDENTITY); + BOOST_VERIFY(id); } Interest @@ -80,18 +81,11 @@ ManagerCommonFixture::receiveInterest(const Interest& interest) advanceClocks(1_ms); } -ControlResponse -ManagerCommonFixture::makeResponse(uint32_t code, const std::string& text, - const ControlParameters& parameters) -{ - return ControlResponse(code, text).setBody(parameters.wireEncode()); -} - ManagerCommonFixture::CheckResponseResult ManagerCommonFixture::checkResponse(size_t idx, const Name& expectedName, const ControlResponse& expectedResponse, - int expectedContentType /*= -1*/) + int expectedContentType) { Data data; try { @@ -103,7 +97,7 @@ ManagerCommonFixture::checkResponse(size_t idx, } if (data.getName() != expectedName) { - BOOST_TEST_MESSAGE("response[" << idx << "] has wrong name " << data.getName()); + BOOST_TEST_MESSAGE("response[" << idx << "] has wrong name " << std::quoted(data.getName().toUri())); return CheckResponseResult::WRONG_NAME; } @@ -117,8 +111,8 @@ ManagerCommonFixture::checkResponse(size_t idx, try { response.wireDecode(data.getContent().blockFromValue()); } - catch (const tlv::Error&) { - BOOST_TEST_MESSAGE("response[" << idx << "] cannot be decoded"); + catch (const tlv::Error& e) { + BOOST_TEST_MESSAGE("response[" << idx << "] cannot be decoded: " << e.what()); return CheckResponseResult::INVALID_RESPONSE; } @@ -128,7 +122,7 @@ ManagerCommonFixture::checkResponse(size_t idx, } if (response.getText() != expectedResponse.getText()) { - BOOST_TEST_MESSAGE("response[" << idx << "] has wrong StatusText " << response.getText()); + BOOST_TEST_MESSAGE("response[" << idx << "] has wrong StatusText " << std::quoted(response.getText())); return CheckResponseResult::WRONG_TEXT; } @@ -138,7 +132,8 @@ ManagerCommonFixture::checkResponse(size_t idx, BOOST_TEST_MESSAGE("response[" << idx << "] has wrong body size " << body.value_size()); return CheckResponseResult::WRONG_BODY_SIZE; } - if (body.value_size() > 0 && memcmp(body.value(), expectedBody.value(), body.value_size()) != 0) { + + if (!std::equal(body.value_begin(), body.value_end(), expectedBody.value_begin())) { BOOST_TEST_MESSAGE("response[" << idx << "] has wrong body value"); return CheckResponseResult::WRONG_BODY_VALUE; } @@ -176,26 +171,26 @@ std::ostream& operator<<(std::ostream& os, ManagerCommonFixture::CheckResponseResult result) { switch (result) { - case ManagerCommonFixture::CheckResponseResult::OK: - return os << "OK"; - case ManagerCommonFixture::CheckResponseResult::OUT_OF_BOUNDARY: - return os << "OUT_OF_BOUNDARY"; - case ManagerCommonFixture::CheckResponseResult::WRONG_NAME: - return os << "WRONG_NAME"; - case ManagerCommonFixture::CheckResponseResult::WRONG_CONTENT_TYPE: - return os << "WRONG_CONTENT_TYPE"; - case ManagerCommonFixture::CheckResponseResult::INVALID_RESPONSE: - return os << "INVALID_RESPONSE"; - case ManagerCommonFixture::CheckResponseResult::WRONG_CODE: - return os << "WRONG_CODE"; - case ManagerCommonFixture::CheckResponseResult::WRONG_TEXT: - return os << "WRONG_TEXT"; - case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_SIZE: - return os << "WRONG_BODY_SIZE"; - case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_VALUE: - return os << "WRONG_BODY_VALUE"; + case ManagerCommonFixture::CheckResponseResult::OK: + return os << "OK"; + case ManagerCommonFixture::CheckResponseResult::OUT_OF_BOUNDARY: + return os << "OUT_OF_BOUNDARY"; + case ManagerCommonFixture::CheckResponseResult::WRONG_NAME: + return os << "WRONG_NAME"; + case ManagerCommonFixture::CheckResponseResult::WRONG_CONTENT_TYPE: + return os << "WRONG_CONTENT_TYPE"; + case ManagerCommonFixture::CheckResponseResult::INVALID_RESPONSE: + return os << "INVALID_RESPONSE"; + case ManagerCommonFixture::CheckResponseResult::WRONG_CODE: + return os << "WRONG_CODE"; + case ManagerCommonFixture::CheckResponseResult::WRONG_TEXT: + return os << "WRONG_TEXT"; + case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_SIZE: + return os << "WRONG_BODY_SIZE"; + case ManagerCommonFixture::CheckResponseResult::WRONG_BODY_VALUE: + return os << "WRONG_BODY_VALUE"; } - return os << static_cast(result); + return os << ndn::to_underlying(result); } void diff --git a/tests/daemon/mgmt/manager-common-fixture.hpp b/tests/daemon/mgmt/manager-common-fixture.hpp index 22d9120d..a28611a5 100644 --- a/tests/daemon/mgmt/manager-common-fixture.hpp +++ b/tests/daemon/mgmt/manager-common-fixture.hpp @@ -84,7 +84,7 @@ class InterestSignerFixture : public GlobalIoTimeFixture, public KeyChainFixture */ class ManagerCommonFixture : public InterestSignerFixture { -public: // initialize +public: /** * @brief Add `/localhost/nfd` as a top prefix to the dispatcher. * @@ -93,21 +93,20 @@ class ManagerCommonFixture : public InterestSignerFixture void setTopPrefix(); -public: // test /** * @brief Cause management to receive an Interest. * - * call DummyClientFace::receive to receive Interest and then call advanceClocks to ensure - * the Interest dispatched - * - * @param interest the Interest to receive + * Calls DummyClientFace::receive() to receive the Interest and then calls advanceClocks() + * to ensure the Interest is dispatched. */ void receiveInterest(const Interest& interest); -public: // verify static ControlResponse - makeResponse(uint32_t code, const std::string& text, const ControlParameters& parameters); + makeResponse(uint32_t code, const std::string& text, const ControlParameters& parameters) + { + return ControlResponse(code, text).setBody(parameters.wireEncode()); + } enum class CheckResponseResult { OK, @@ -118,7 +117,7 @@ class ManagerCommonFixture : public InterestSignerFixture WRONG_CODE, WRONG_TEXT, WRONG_BODY_SIZE, - WRONG_BODY_VALUE + WRONG_BODY_VALUE, }; /** diff --git a/tests/daemon/mgmt/rib-manager.t.cpp b/tests/daemon/mgmt/rib-manager.t.cpp index 2e876d5e..6da89d30 100644 --- a/tests/daemon/mgmt/rib-manager.t.cpp +++ b/tests/daemon/mgmt/rib-manager.t.cpp @@ -186,11 +186,8 @@ class RibManagerFixture : public ManagerCommonFixture auto replyFibAddCommand = [this] (const Interest& interest) { ControlParameters params(interest.getName().at(4).blockFromValue()); BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); - params.setFaceId(1) - .setCost(0); - ControlResponse resp; - resp.setCode(200) - .setBody(params.wireEncode()); + params.setFaceId(1).setCost(0); + ControlResponse resp = makeResponse(200, "OK", params); auto data = make_shared(interest.getName()); data->setContent(resp.wireEncode()); @@ -603,8 +600,8 @@ BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); std::vector receivedRecords, expectedRecords; - for (size_t idx = 0; idx < nEntries; ++idx) { - ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); + for (const auto& el : content.elements()) { + ndn::nfd::RibEntry decodedEntry(el); BOOST_TEST_INFO_SCOPE(decodedEntry); receivedRecords.push_back(decodedEntry); actualPrefixes.erase(decodedEntry.getName()); @@ -613,7 +610,7 @@ BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) BOOST_REQUIRE(matchedEntryIt != m_rib.end()); auto matchedEntry = matchedEntryIt->second; - BOOST_REQUIRE(matchedEntry != nullptr); + BOOST_TEST_REQUIRE(matchedEntry != nullptr); expectedRecords.emplace_back(); expectedRecords.back().setName(matchedEntry->getName()); @@ -664,8 +661,8 @@ BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) auto it2 = m_rib.find("/test-remove-invalid-faces-2"); BOOST_CHECK(it2 == m_rib.end()); BOOST_REQUIRE(it1 != m_rib.end()); - BOOST_CHECK(it1->second->hasFaceId(1)); - BOOST_CHECK(!it1->second->hasFaceId(2)); + BOOST_TEST(it1->second->hasFaceId(1)); + BOOST_TEST(!it1->second->hasFaceId(2)); } BOOST_AUTO_TEST_CASE(OnNotification) diff --git a/tests/daemon/mgmt/strategy-choice-manager.t.cpp b/tests/daemon/mgmt/strategy-choice-manager.t.cpp index 6cd2e70c..aff0beec 100644 --- a/tests/daemon/mgmt/strategy-choice-manager.t.cpp +++ b/tests/daemon/mgmt/strategy-choice-manager.t.cpp @@ -91,10 +91,7 @@ BOOST_AUTO_TEST_CASE(SetSuccess) ControlParameters expectedParams; expectedParams.setName("/A") .setStrategy(strategyNameP); // response should have versioned strategy name - ControlResponse expectedResp; - expectedResp.setCode(200) - .setText("OK") - .setBody(expectedParams.wireEncode()); + ControlResponse expectedResp = makeResponse(200, "OK", expectedParams); BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), expectedResp), CheckResponseResult::OK); @@ -146,7 +143,7 @@ BOOST_AUTO_TEST_CASE(SetNameTooLong) BOOST_AUTO_TEST_CASE(UnsetSuccess) { auto insertRes = sc.insert("/A", strategyNameP); - BOOST_REQUIRE(insertRes); + BOOST_TEST_REQUIRE(insertRes); ControlParameters reqParams; reqParams.setName("/A"); @@ -154,10 +151,7 @@ BOOST_AUTO_TEST_CASE(UnsetSuccess) receiveInterest(req); ControlParameters expectedParams(reqParams); - ControlResponse expectedResp; - expectedResp.setCode(200) - .setText("OK") - .setBody(expectedParams.wireEncode()); + ControlResponse expectedResp = makeResponse(200, "OK", expectedParams); BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), expectedResp), CheckResponseResult::OK); @@ -172,10 +166,7 @@ BOOST_AUTO_TEST_CASE(UnsetNoop) receiveInterest(req); ControlParameters expectedParams(reqParams); - ControlResponse expectedResp; - expectedResp.setCode(200) - .setText("OK") - .setBody(expectedParams.wireEncode()); + ControlResponse expectedResp = makeResponse(200, "OK", expectedParams); BOOST_CHECK_EQUAL(checkResponse(0, req.getName(), expectedResp), CheckResponseResult::OK); @@ -201,7 +192,7 @@ BOOST_AUTO_TEST_CASE(UnsetRootForbidden) BOOST_AUTO_TEST_CASE(StrategyChoiceDataset) { std::map expected; // namespace => strategy instance name - for (const strategy_choice::Entry& entry : sc) { + for (const auto& entry : sc) { expected[entry.getPrefix()] = entry.getStrategyInstanceName(); } @@ -211,7 +202,7 @@ BOOST_AUTO_TEST_CASE(StrategyChoiceDataset) Name strategy = DummyStrategy::getStrategyName(i); auto insertRes = sc.insert(name, strategy); - BOOST_CHECK(insertRes); + BOOST_TEST(insertRes); expected[name] = strategy; } @@ -221,8 +212,8 @@ BOOST_AUTO_TEST_CASE(StrategyChoiceDataset) dataset.parse(); BOOST_CHECK_EQUAL(dataset.elements_size(), expected.size()); - for (auto i = dataset.elements_begin(); i != dataset.elements_end(); ++i) { - ndn::nfd::StrategyChoice record(*i); + for (const auto& el : dataset.elements()) { + ndn::nfd::StrategyChoice record(el); BOOST_TEST_INFO_SCOPE(record); auto found = expected.find(record.getName()); if (found == expected.end()) { diff --git a/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp index 2f1e27a5..e6d9988b 100644 --- a/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp +++ b/tests/daemon/rib/readvertise/nfd-rib-readvertise-destination.t.cpp @@ -41,47 +41,33 @@ using namespace nfd::rib; class NfdRibReadvertiseDestinationFixture : public GlobalIoTimeFixture, public KeyChainFixture { -protected: - NfdRibReadvertiseDestinationFixture() - : nSuccessCallbacks(0) - , nFailureCallbacks(0) - , face(g_io, m_keyChain, {true, false}) - , controller(face, m_keyChain) - , dest(controller, rib, ndn::nfd::CommandOptions().setPrefix("/localhost/nlsr")) - , successCallback([this] { nSuccessCallbacks++; }) - , failureCallback([this] (const std::string&) { nFailureCallbacks++; }) - { - } - -public: - uint32_t nSuccessCallbacks; - uint32_t nFailureCallbacks; - protected: static inline const Name RIB_REGISTER_COMMAND_PREFIX = Name("/localhost/nlsr") .append(ndn::nfd::RibRegisterCommand::getName()); static inline const Name RIB_UNREGISTER_COMMAND_PREFIX = Name("/localhost/nlsr") .append(ndn::nfd::RibUnregisterCommand::getName()); - ndn::DummyClientFace face; - ndn::nfd::Controller controller; + ndn::DummyClientFace face{g_io, m_keyChain, {true, false}}; + ndn::nfd::Controller controller{face, m_keyChain}; Rib rib; - NfdRibReadvertiseDestination dest; - std::function successCallback; - std::function failureCallback; + NfdRibReadvertiseDestination dest{controller, rib, ndn::nfd::CommandOptions().setPrefix("/localhost/nlsr")}; + + std::function successCallback = [this] { nSuccessCallbacks++; }; + std::function failureCallback = [this] (auto&&) { nFailureCallbacks++; }; + + int nSuccessCallbacks = 0; + int nFailureCallbacks = 0; }; BOOST_AUTO_TEST_SUITE(Rib) BOOST_FIXTURE_TEST_SUITE(TestNfdRibReadvertiseDestination, NfdRibReadvertiseDestinationFixture) -class AdvertiseSuccessScenario +struct AdvertiseSuccessScenario { -public: - ndn::nfd::ControlResponse + static ndn::nfd::ControlResponse makeResponse(const ControlParameters& sentCp) { ControlParameters response; - response.setFaceId(1) .setName(sentCp.getName()) .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT) @@ -92,40 +78,30 @@ class AdvertiseSuccessScenario responsePayload.setCode(200) .setText("Successfully registered.") .setBody(response.wireEncode()); + return responsePayload; } - void - checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture) - { - BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 1); - BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 0); - } + static constexpr int nExpectedSuccessCalls = 1; + static constexpr int nExpectedFailureCalls = 0; }; -class AdvertiseFailureScenario +struct AdvertiseFailureScenario { -public: - ndn::nfd::ControlResponse - makeResponse(ControlParameters sentCp) + static ndn::nfd::ControlResponse + makeResponse(const ControlParameters& sentCp) { - ndn::nfd::ControlResponse responsePayload(403, "Not Authenticated"); - return responsePayload; + return ndn::nfd::ControlResponse(403, "Not Authenticated"); } - void - checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture) - { - BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 1); - BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 0); - } + static constexpr int nExpectedSuccessCalls = 0; + static constexpr int nExpectedFailureCalls = 1; }; using AdvertiseScenarios = boost::mp11::mp_list; BOOST_AUTO_TEST_CASE_TEMPLATE(Advertise, Scenario, AdvertiseScenarios) { - Scenario scenario; Name prefix("/ndn/memphis/test"); ReadvertisedRoute rr(prefix); @@ -139,27 +115,27 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Advertise, Scenario, AdvertiseScenarios) // Parse the sent command Interest to check correctness. ControlParameters sentCp; - BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_REGISTER_COMMAND_PREFIX.size()).blockFromValue())); + BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_REGISTER_COMMAND_PREFIX.size()) + .blockFromValue())); BOOST_CHECK_EQUAL(sentCp.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT); BOOST_CHECK_EQUAL(sentCp.getName(), prefix); - ndn::nfd::ControlResponse responsePayload = scenario.makeResponse(sentCp); + ndn::nfd::ControlResponse responsePayload = Scenario::makeResponse(sentCp); auto responseData = makeData(sentInterest.getName()); responseData->setContent(responsePayload.wireEncode()); face.receive(*responseData); this->advanceClocks(10_ms); - scenario.checkCommandOutcome(this); + BOOST_TEST(nSuccessCallbacks == Scenario::nExpectedSuccessCalls); + BOOST_TEST(nFailureCallbacks == Scenario::nExpectedFailureCalls); } -class WithdrawSuccessScenario +struct WithdrawSuccessScenario { -public: - ndn::nfd::ControlResponse + static ndn::nfd::ControlResponse makeResponse(const ControlParameters& sentCp) { ControlParameters response; - response.setFaceId(1) .setName(sentCp.getName()) .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT); @@ -172,37 +148,26 @@ class WithdrawSuccessScenario return responsePayload; } - void - checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture) - { - BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 1); - BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 0); - } + static constexpr int nExpectedSuccessCalls = 1; + static constexpr int nExpectedFailureCalls = 0; }; -class WithdrawFailureScenario +struct WithdrawFailureScenario { -public: - ndn::nfd::ControlResponse - makeResponse(ControlParameters sentCp) + static ndn::nfd::ControlResponse + makeResponse(const ControlParameters& sentCp) { - ndn::nfd::ControlResponse responsePayload(403, "Not authenticated"); - return responsePayload; + return ndn::nfd::ControlResponse(403, "Not authenticated"); } - void - checkCommandOutcome(NfdRibReadvertiseDestinationFixture* fixture) - { - BOOST_CHECK_EQUAL(fixture->nFailureCallbacks, 1); - BOOST_CHECK_EQUAL(fixture->nSuccessCallbacks, 0); - } + static constexpr int nExpectedSuccessCalls = 0; + static constexpr int nExpectedFailureCalls = 1; }; using WithdrawScenarios = boost::mp11::mp_list; BOOST_AUTO_TEST_CASE_TEMPLATE(Withdraw, Scenario, WithdrawScenarios) { - Scenario scenario; Name prefix("/ndn/memphis/test"); ReadvertisedRoute rr(prefix); @@ -215,18 +180,20 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Withdraw, Scenario, WithdrawScenarios) BOOST_CHECK(RIB_UNREGISTER_COMMAND_PREFIX.isPrefixOf(sentInterest.getName())); ControlParameters sentCp; - BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_UNREGISTER_COMMAND_PREFIX.size()).blockFromValue())); + BOOST_CHECK_NO_THROW(sentCp.wireDecode(sentInterest.getName().get(RIB_UNREGISTER_COMMAND_PREFIX.size()) + .blockFromValue())); BOOST_CHECK_EQUAL(sentCp.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT); BOOST_CHECK_EQUAL(sentCp.getName(), prefix); - ndn::nfd::ControlResponse responsePayload = scenario.makeResponse(sentCp); + ndn::nfd::ControlResponse responsePayload = Scenario::makeResponse(sentCp); auto responseData = makeData(sentInterest.getName()); responseData->setContent(responsePayload.wireEncode()); face.receive(*responseData); this->advanceClocks(1_ms); - scenario.checkCommandOutcome(this); + BOOST_TEST(nSuccessCallbacks == Scenario::nExpectedSuccessCalls); + BOOST_TEST(nFailureCallbacks == Scenario::nExpectedFailureCalls); } BOOST_AUTO_TEST_CASE(DestinationAvailability) @@ -235,8 +202,7 @@ BOOST_AUTO_TEST_CASE(DestinationAvailability) Name commandPrefix("/localhost/nlsr"); Route route; - dest.afterAvailabilityChange.connect( - std::bind(&std::vector::push_back, &availabilityChangeHistory, _1)); + dest.afterAvailabilityChange.connect([&] (bool val) { availabilityChangeHistory.push_back(val); }); BOOST_CHECK_EQUAL(dest.isAvailable(), false); rib.insert(commandPrefix, route);