interest: improve code readability

And add more tests for decoding of malformed ForwardingHint

Change-Id: Ie7b043911769a0952300aa412fe7dbb893a464aa
diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp
index fe65955..4dfde5c 100644
--- a/ndn-cxx/interest.cpp
+++ b/ndn-cxx/interest.cpp
@@ -319,28 +319,26 @@
 bool
 Interest::matchesData(const Data& data) const
 {
-  size_t interestNameLength = m_name.size();
   const Name& dataName = data.getName();
   size_t fullNameLength = dataName.size() + 1;
 
   // check Name and CanBePrefix
-  if (interestNameLength == fullNameLength) {
+  if (m_name.size() == fullNameLength) {
     if (m_name.get(-1).isImplicitSha256Digest()) {
-      if (m_name != data.getFullName()) {
-        return false;
-      }
+      return m_name == data.getFullName();
     }
     else {
-      // Interest Name is same length as Data full Name, but last component isn't digest
-      // so there's no possibility of matching
+      // the Interest name has the same length as the Data full name, but the last
+      // component is not a digest, so there is no possibility of matching
       return false;
     }
   }
-  else if (getCanBePrefix() ? !m_name.isPrefixOf(dataName) : (m_name != dataName)) {
-    return false;
+  else if (m_canBePrefix) {
+    return m_name.isPrefixOf(dataName);
   }
-
-  return true;
+  else {
+    return m_name == dataName;
+  }
 }
 
 bool
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 055be68..bd6e302 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -502,6 +502,9 @@
 
 BOOST_AUTO_TEST_CASE(CriticalElementOutOfOrder)
 {
+  BOOST_CHECK_EXCEPTION(i.wireDecode("0507 FC00 0703080149"_block),
+    tlv::Error,
+    [] (const auto& e) { return e.what() == "Name element is missing or out of order"sv; });
   BOOST_CHECK_EXCEPTION(i.wireDecode(
     "0529 2100 0703080149 1200 1E0B(1F09 1E023E15 0703080148) "
     "0A044ACB1E4C 0C0276A1 2201D6 2404C0C1C2C3"_block),
@@ -578,13 +581,23 @@
 BOOST_AUTO_TEST_CASE(BadCanBePrefix)
 {
   BOOST_CHECK_EXCEPTION(i.wireDecode("0508 0703080149 210102"_block), tlv::Error,
-                        [] (const auto& e) { return e.what() == "CanBePrefix element has non-zero TLV-LENGTH"sv; });
+    [] (const auto& e) { return e.what() == "CanBePrefix element has non-zero TLV-LENGTH"sv; });
 }
 
 BOOST_AUTO_TEST_CASE(BadMustBeFresh)
 {
   BOOST_CHECK_EXCEPTION(i.wireDecode("0508 0703080149 120102"_block), tlv::Error,
-                        [] (const auto& e) { return e.what() == "MustBeFresh element has non-zero TLV-LENGTH"sv; });
+    [] (const auto& e) { return e.what() == "MustBeFresh element has non-zero TLV-LENGTH"sv; });
+}
+
+BOOST_AUTO_TEST_CASE(BadForwardingHint)
+{
+  BOOST_CHECK_EXCEPTION(i.wireDecode("050C 0703080149 1E05(0703080248)"_block), tlv::Error,
+    [] (const auto& e) { return e.what() == "Invalid Name in ForwardingHint"sv; });
+  BOOST_CHECK_EXCEPTION(i.wireDecode("050E 0703080149 1E07(1F05(0703080248))"_block), tlv::Error,
+    [] (const auto& e) { return e.what() == "Invalid Name in ForwardingHint.Delegation"sv; });
+  BOOST_CHECK_EXCEPTION(i.wireDecode("0509 0703080149 1E02(2100)"_block), tlv::Error,
+    [] (const auto& e) { return e.what() == "Unexpected TLV-TYPE 33 while decoding ForwardingHint"sv; });
 }
 
 BOOST_AUTO_TEST_CASE(BadNonce)
@@ -628,12 +641,6 @@
   BOOST_CHECK_EQUAL(i.isParametersDigestValid(), false);
 }
 
-BOOST_AUTO_TEST_CASE(UnrecognizedNonCriticalElementBeforeName)
-{
-  BOOST_CHECK_EXCEPTION(i.wireDecode("0507 FC00 0703080149"_block), tlv::Error,
-                        [] (const auto& e) { return e.what() == "Name element is missing or out of order"sv; });
-}
-
 BOOST_AUTO_TEST_CASE(UnrecognizedCriticalElement)
 {
   BOOST_CHECK_EXCEPTION(i.wireDecode("0507 0703080149 FB00"_block), tlv::Error,
@@ -677,8 +684,8 @@
   BOOST_CHECK_EQUAL(interest->matchesData(*data), false); // violates implicit digest
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MatchesInterest, 1)
-BOOST_AUTO_TEST_CASE(MatchesInterest)
+BOOST_AUTO_TEST_CASE(MatchesInterest,
+  * boost::unit_test::expected_failures(1))
 {
   Interest interest;
   interest.setName("/A")
diff --git a/tests/unit/net/face-uri.t.cpp b/tests/unit/net/face-uri.t.cpp
index fe34b01..050b1cc 100644
--- a/tests/unit/net/face-uri.t.cpp
+++ b/tests/unit/net/face-uri.t.cpp
@@ -215,8 +215,8 @@
   }
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CanonizeUdpV4, 1)
-BOOST_FIXTURE_TEST_CASE(CanonizeUdpV4, CanonizeFixture)
+BOOST_FIXTURE_TEST_CASE(CanonizeUdpV4, CanonizeFixture,
+  * boost::unit_test::expected_failures(1))
 {
   SKIP_IF_IPV4_UNAVAILABLE();
 
@@ -243,8 +243,8 @@
   runTest("udp4://[2001:db8::1]:6363", false);
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CanonizeUdpV6, 1)
-BOOST_FIXTURE_TEST_CASE(CanonizeUdpV6, CanonizeFixture)
+BOOST_FIXTURE_TEST_CASE(CanonizeUdpV6, CanonizeFixture,
+  * boost::unit_test::expected_failures(1))
 {
   SKIP_IF_IPV6_UNAVAILABLE();
 
@@ -345,8 +345,8 @@
   }
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CanonizeTcpV4, 1)
-BOOST_FIXTURE_TEST_CASE(CanonizeTcpV4, CanonizeFixture)
+BOOST_FIXTURE_TEST_CASE(CanonizeTcpV4, CanonizeFixture,
+  * boost::unit_test::expected_failures(1))
 {
   SKIP_IF_IPV4_UNAVAILABLE();
 
@@ -384,8 +384,8 @@
   }
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CanonizeTcpV6, 1)
-BOOST_FIXTURE_TEST_CASE(CanonizeTcpV6, CanonizeFixture)
+BOOST_FIXTURE_TEST_CASE(CanonizeTcpV6, CanonizeFixture,
+  * boost::unit_test::expected_failures(1))
 {
   SKIP_IF_IPV6_UNAVAILABLE();
 
@@ -408,8 +408,8 @@
   runTest("tcp6://192.0.2.1:6363", false);
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(ParseUnix, 1)
-BOOST_AUTO_TEST_CASE(ParseUnix)
+BOOST_AUTO_TEST_CASE(ParseUnix,
+  * boost::unit_test::expected_failures(1))
 {
   FaceUri uri;
 
@@ -477,8 +477,8 @@
   runTest("ether://[33:33:01:01:01:01]", true, "ether://[33:33:01:01:01:01]");
 }
 
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(ParseDev, 1)
-BOOST_AUTO_TEST_CASE(ParseDev)
+BOOST_AUTO_TEST_CASE(ParseDev,
+  * boost::unit_test::expected_failures(1))
 {
   FaceUri uri;