tools: use FindFace in nfdc face show command
This commit also uses FaceQueryFilter operator== in test cases.
refs #3864
Change-Id: I5096ab07ce02535364c5ac8f9e0f0ad27e55b96e
diff --git a/tests/tools/nfdc/face-module.t.cpp b/tests/tools/nfdc/face-module.t.cpp
index 8d465e2..308196d 100644
--- a/tests/tools/nfdc/face-module.t.cpp
+++ b/tests/tools/nfdc/face-module.t.cpp
@@ -52,10 +52,9 @@
BOOST_AUTO_TEST_CASE(Normal)
{
this->processInterest = [this] (const Interest& interest) {
- Name datasetName("/localhost/nfd/faces/query");
- FaceQueryFilter filter;
- filter.setFaceId(256);
- datasetName.append(filter.wireEncode());
+ BOOST_CHECK_EQUAL(interest.getName().size(), 5);
+ FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
+ BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
FaceStatus payload;
payload.setFaceId(256)
@@ -73,7 +72,7 @@
.setNInBytes(13307258)
.setNOutBytes(6231946);
- this->sendDataset(datasetName, payload);
+ this->sendDataset(interest.getName(), payload);
};
this->execute("face show 256");
@@ -91,7 +90,7 @@
this->execute("face show 256");
BOOST_CHECK_EQUAL(exitCode, 3);
BOOST_CHECK(out.is_empty());
- BOOST_CHECK(err.is_equal("Face 256 not found.\n"));
+ BOOST_CHECK(err.is_equal("Face not found\n"));
}
BOOST_AUTO_TEST_CASE(Error)
@@ -101,7 +100,7 @@
this->execute("face show 256");
BOOST_CHECK_EQUAL(exitCode, 1);
BOOST_CHECK(out.is_empty());
- BOOST_CHECK(err.is_equal("Error 10060 when fetching face information: Timeout\n"));
+ BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
}
BOOST_AUTO_TEST_SUITE_END() // ShowCommand
@@ -150,8 +149,7 @@
if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
BOOST_CHECK_EQUAL(interest.getName().size(), 5);
FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
- // BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(10156));
- BOOST_CHECK_EQUAL(filter.getFaceId(), 10156);
+ BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(10156));
FaceStatus faceStatus;
faceStatus.setFaceId(10156)
@@ -184,8 +182,7 @@
if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
BOOST_CHECK_EQUAL(interest.getName().size(), 5);
FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
- // BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363"));
- BOOST_CHECK_EQUAL(filter.getRemoteUri(), "tcp4://32.121.182.82:6363");
+ BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363"));
FaceStatus faceStatus;
faceStatus.setFaceId(2249)
diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp
index 4dc732e..e96de3e 100644
--- a/tools/nfdc/face-module.cpp
+++ b/tools/nfdc/face-module.cpp
@@ -59,22 +59,22 @@
{
uint64_t faceId = ctx.args.get<uint64_t>("id");
- ndn::nfd::FaceQueryFilter filter;
- filter.setFaceId(faceId);
- ctx.controller.fetch<ndn::nfd::FaceQueryDataset>(
- filter,
- [faceId, &ctx] (const std::vector<FaceStatus>& result) {
- if (result.size() != 1) {
- ctx.exitCode = 3;
- ctx.err << "Face " << faceId << " not found.\n";
- return;
- }
- formatItemText(ctx.out, result.front(), true);
- },
- ctx.makeDatasetFailureHandler("face information"),
- ctx.makeCommandOptions());
+ FindFace findFace(ctx);
+ FindFace::Code res = findFace.execute(faceId);
- ctx.face.processEvents();
+ ctx.exitCode = static_cast<int>(res);
+ switch (res) {
+ case FindFace::Code::OK:
+ formatItemText(ctx.out, findFace.getFaceStatus(), true);
+ break;
+ case FindFace::Code::ERROR:
+ case FindFace::Code::NOT_FOUND:
+ ctx.err << findFace.getErrorReason() << '\n';
+ break;
+ default:
+ BOOST_ASSERT_MSG(false, "unexpected FindFace result");
+ break;
+ }
}
void