interest: declare default CanBePrefix setting

refs #4581

Change-Id: I82de3b13c3010242fa7999a2564d4a5442dfd14b
diff --git a/src/interest.cpp b/src/interest.cpp
index f08eeb2..8fc04a3 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -23,7 +23,10 @@
 #include "util/random.hpp"
 #include "data.hpp"
 
+#include <boost/scope_exit.hpp>
+
 #include <cstring>
+#include <iostream>
 #include <sstream>
 
 namespace ndn {
@@ -35,16 +38,27 @@
 static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
               "Interest::Error must inherit from tlv::Error");
 
+#ifdef NDN_CXX_HAVE_TESTS
+bool Interest::s_errorIfCanBePrefixUnset = true;
+#endif // NDN_CXX_HAVE_TESTS
+boost::logic::tribool Interest::s_defaultCanBePrefix = boost::logic::indeterminate;
+
 Interest::Interest(const Name& name, time::milliseconds lifetime)
   : m_name(name)
+  , m_isCanBePrefixSet(false)
   , m_interestLifetime(lifetime)
 {
   if (lifetime < time::milliseconds::zero()) {
     BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0"));
   }
+
+  if (!boost::logic::indeterminate(s_defaultCanBePrefix)) {
+    setCanBePrefix(static_cast<bool>(s_defaultCanBePrefix));
+  }
 }
 
 Interest::Interest(const Block& wire)
+  : m_isCanBePrefixSet(true)
 {
   wireDecode(wire);
 }
@@ -55,6 +69,20 @@
 size_t
 Interest::wireEncode(EncodingImpl<TAG>& encoder) const
 {
+  static bool hasDefaultCanBePrefixWarning = false;
+  if (!m_isCanBePrefixSet) {
+    if (!hasDefaultCanBePrefixWarning) {
+      std::cerr << "WARNING: Interest.CanBePrefix will be set to 0 in the near future. "
+                << "Please declare a preferred setting via Interest::setDefaultCanBePrefix.";
+      hasDefaultCanBePrefixWarning = true;
+    }
+#ifdef NDN_CXX_HAVE_TESTS
+     if (s_errorIfCanBePrefixUnset) {
+       BOOST_THROW_EXCEPTION(std::logic_error("Interest.CanBePrefix is unset"));
+     }
+#endif // NDN_CXX_HAVE_TESTS
+  }
+
   size_t totalLength = 0;
 
   // Interest ::= INTEREST-TYPE TLV-LENGTH
@@ -131,6 +159,8 @@
       setNonce(getNonce());
     }
   }
+
+  m_isCanBePrefixSet = true; // don't trigger warning from decoded packet
 }
 
 bool
@@ -493,6 +523,21 @@
 
 // ---- operators ----
 
+bool
+operator==(const Interest& lhs, const Interest& rhs)
+{
+  bool wasCanBePrefixSetOnLhs = lhs.m_isCanBePrefixSet;
+  bool wasCanBePrefixSetOnRhs = rhs.m_isCanBePrefixSet;
+  lhs.m_isCanBePrefixSet = true;
+  rhs.m_isCanBePrefixSet = true;
+  BOOST_SCOPE_EXIT_ALL(&) {
+    lhs.m_isCanBePrefixSet = wasCanBePrefixSetOnLhs;
+    rhs.m_isCanBePrefixSet = wasCanBePrefixSetOnRhs;
+  };
+
+  return lhs.wireEncode() == rhs.wireEncode();
+}
+
 std::ostream&
 operator<<(std::ostream& os, const Interest& interest)
 {
diff --git a/src/interest.hpp b/src/interest.hpp
index 7d0705e..1357352 100644
--- a/src/interest.hpp
+++ b/src/interest.hpp
@@ -27,6 +27,7 @@
 #include "packet-base.hpp"
 #include "selectors.hpp"
 #include "util/time.hpp"
+#include <boost/logic/tribool.hpp>
 
 namespace ndn {
 
@@ -147,6 +148,26 @@
     return *this;
   }
 
+  /** @brief Declare the default CanBePrefix setting of the application.
+   *
+   *  As part of transitioning to NDN Packet Format v0.3, the default setting for CanBePrefix
+   *  will be changed from "true" to "false". Application developers are advised to review all
+   *  Interests expressed by their application and decide what CanBePrefix setting is appropriate
+   *  for each Interest, to avoid breaking changes when the transition occurs. Application may
+   *  either set CanBePrefix on a per-Interest basis, or declare a default CanBePrefix setting for
+   *  all Interests expressed by the application using this function. If an application neither
+   *  declares a default nor sets CanBePrefix on every Interest, Interest::wireEncode will print a
+   *  one-time warning message.
+   *
+   *  @note This function should not be used in libraries or in ndn-cxx unit tests.
+   *  @sa https://redmine.named-data.net/projects/nfd/wiki/Packet03Transition
+   */
+  static void
+  setDefaultCanBePrefix(bool canBePrefix)
+  {
+    s_defaultCanBePrefix = canBePrefix;
+  }
+
   /** @brief Check whether the CanBePrefix element is present.
    *
    *  This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3.
@@ -171,6 +192,7 @@
   {
     m_selectors.setMaxSuffixComponents(canBePrefix ? -1 : 1);
     m_wire.reset();
+    m_isCanBePrefixSet = true;
     return *this;
   }
 
@@ -390,14 +412,26 @@
   void
   decode03();
 
+#ifdef NDN_CXX_HAVE_TESTS
+public:
+  /** @brief If true, not setting CanBePrefix results in an error in wireEncode().
+   */
+  static bool s_errorIfCanBePrefixUnset;
+#endif // NDN_CXX_HAVE_TESTS
+
 private:
+  static boost::logic::tribool s_defaultCanBePrefix;
+
   Name m_name;
   Selectors m_selectors;
+  mutable bool m_isCanBePrefixSet;
   mutable optional<uint32_t> m_nonce;
   time::milliseconds m_interestLifetime;
   DelegationList m_forwardingHint;
 
   mutable Block m_wire;
+
+  friend bool operator==(const Interest& lhs, const Interest& rhs);
 };
 
 NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest);
@@ -405,11 +439,8 @@
 std::ostream&
 operator<<(std::ostream& os, const Interest& interest);
 
-inline bool
-operator==(const Interest& lhs, const Interest& rhs)
-{
-  return lhs.wireEncode() == rhs.wireEncode();
-}
+bool
+operator==(const Interest& lhs, const Interest& rhs);
 
 inline bool
 operator!=(const Interest& lhs, const Interest& rhs)
diff --git a/src/security/command-interest-signer.cpp b/src/security/command-interest-signer.cpp
index 70e80a1..d4cb33a 100644
--- a/src/security/command-interest-signer.cpp
+++ b/src/security/command-interest-signer.cpp
@@ -56,6 +56,7 @@
 CommandInterestSigner::makeCommandInterest(const Name& name, const SigningInfo& params)
 {
   Interest commandInterest(prepareCommandInterestName(name));
+  commandInterest.setCanBePrefix(false);
   m_keyChain.sign(commandInterest, params);
   return commandInterest;
 }
diff --git a/src/security/v2/certificate-bundle-fetcher.cpp b/src/security/v2/certificate-bundle-fetcher.cpp
index 45a0c38..227a434 100644
--- a/src/security/v2/certificate-bundle-fetcher.cpp
+++ b/src/security/v2/certificate-bundle-fetcher.cpp
@@ -95,9 +95,10 @@
                                                   const ValidationContinuation& continueValidation)
 {
   Interest bundleInterest = Interest(bundleNamePrefix);
-  bundleInterest.setInterestLifetime(m_bundleInterestLifetime);
+  bundleInterest.setCanBePrefix(true);
   bundleInterest.setMustBeFresh(true);
   bundleInterest.setChildSelector(1);
+  bundleInterest.setInterestLifetime(m_bundleInterestLifetime);
 
   m_face.expressInterest(bundleInterest,
                          [=] (const Interest& interest, const Data& data) {
@@ -123,8 +124,9 @@
   }
 
   Interest bundleInterest(fullBundleName.getPrefix(-1).append(segmentNo));
-  bundleInterest.setInterestLifetime(m_bundleInterestLifetime);
+  bundleInterest.setCanBePrefix(false);
   bundleInterest.setMustBeFresh(false);
+  bundleInterest.setInterestLifetime(m_bundleInterestLifetime);
 
   m_face.expressInterest(bundleInterest,
                          [=] (const Interest& interest, const Data& data) {
diff --git a/src/security/v2/certificate-request.hpp b/src/security/v2/certificate-request.hpp
index c1d88dc..9bcb93b 100644
--- a/src/security/v2/certificate-request.hpp
+++ b/src/security/v2/certificate-request.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -46,6 +46,12 @@
   {
   }
 
+  explicit
+  CertificateRequest(const Name& name)
+    : CertificateRequest(Interest(name).setCanBePrefix(true))
+  {
+  }
+
 public:
   /// @brief the name for the requested data/certificate.
   Interest m_interest;
diff --git a/src/security/v2/validation-policy-config.cpp b/src/security/v2/validation-policy-config.cpp
index 2d82079..ff3f7bf 100644
--- a/src/security/v2/validation-policy-config.cpp
+++ b/src/security/v2/validation-policy-config.cpp
@@ -255,7 +255,7 @@
   for (const auto& rule : m_dataRules) {
     if (rule->match(tlv::Data, data.getName())) {
       if (rule->check(tlv::Data, data.getName(), klName, state)) {
-        return continueValidation(make_shared<CertificateRequest>(Interest(klName)), state);
+        return continueValidation(make_shared<CertificateRequest>(klName), state);
       }
       // rule->check calls state->fail(...) if the check fails
       return;
@@ -284,7 +284,7 @@
   for (const auto& rule : m_interestRules) {
     if (rule->match(tlv::Interest, interest.getName())) {
       if (rule->check(tlv::Interest, interest.getName(), klName, state)) {
-        return continueValidation(make_shared<CertificateRequest>(Interest(klName)), state);
+        return continueValidation(make_shared<CertificateRequest>(klName), state);
       }
       // rule->check calls state->fail(...) if the check fails
       return;
diff --git a/src/security/v2/validation-policy-simple-hierarchy.cpp b/src/security/v2/validation-policy-simple-hierarchy.cpp
index 0ad6128..e83c9bc 100644
--- a/src/security/v2/validation-policy-simple-hierarchy.cpp
+++ b/src/security/v2/validation-policy-simple-hierarchy.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -35,7 +35,7 @@
   }
 
   if (klName.getPrefix(-2).isPrefixOf(data.getName())) {
-    continueValidation(make_shared<CertificateRequest>(Interest(klName)), state);
+    continueValidation(make_shared<CertificateRequest>(klName), state);
   }
   else {
     state->fail({ValidationError::Code::INVALID_KEY_LOCATOR, "Data signing policy violation for " +
@@ -53,7 +53,7 @@
   }
 
   if (klName.getPrefix(-2).isPrefixOf(interest.getName())) {
-    continueValidation(make_shared<CertificateRequest>(Interest(klName)), state);
+    continueValidation(make_shared<CertificateRequest>(klName), state);
   }
   else {
     state->fail({ValidationError::Code::INVALID_KEY_LOCATOR, "Interest signing policy violation for " +
diff --git a/src/util/notification-subscriber.cpp b/src/util/notification-subscriber.cpp
index e69800a..f72aa58 100644
--- a/src/util/notification-subscriber.cpp
+++ b/src/util/notification-subscriber.cpp
@@ -79,6 +79,7 @@
     return;
 
   auto interest = make_shared<Interest>(m_prefix);
+  interest->setCanBePrefix(true);
   interest->setMustBeFresh(true);
   interest->setChildSelector(1);
   interest->setInterestLifetime(getInterestLifetime());
@@ -101,6 +102,7 @@
   nextName.appendSequenceNumber(m_lastSequenceNo + 1);
 
   auto interest = make_shared<Interest>(nextName);
+  interest->setCanBePrefix(false);
   interest->setInterestLifetime(getInterestLifetime());
 
   m_lastInterestId = m_face.expressInterest(*interest,
diff --git a/tests/integrated/default-can-be-prefix-0.cpp b/tests/integrated/default-can-be-prefix-0.cpp
new file mode 100644
index 0000000..8be2c4f
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-0.cpp
@@ -0,0 +1,46 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=0)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefix0)
+{
+  Interest::setDefaultCanBePrefix(false);
+  Interest interest1;
+  Interest interest2(interest1.wireEncode());
+  BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), false);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix-1.cpp b/tests/integrated/default-can-be-prefix-1.cpp
new file mode 100644
index 0000000..e2071e1
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-1.cpp
@@ -0,0 +1,46 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=1)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefix1)
+{
+  Interest::setDefaultCanBePrefix(true);
+  Interest interest1;
+  Interest interest2(interest1.wireEncode());
+  BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), true);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix-unset.cpp b/tests/integrated/default-can-be-prefix-unset.cpp
new file mode 100644
index 0000000..88375da
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-unset.cpp
@@ -0,0 +1,47 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=unset)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefixUnset)
+{
+  Interest interest1;
+  BOOST_CHECK_THROW(interest1.wireEncode(), std::logic_error);
+  Interest::s_errorIfCanBePrefixUnset = false;
+  Interest interest2(interest1.wireEncode());
+  BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), true);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix.README.md b/tests/integrated/default-can-be-prefix.README.md
new file mode 100644
index 0000000..23b01ae
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix.README.md
@@ -0,0 +1,10 @@
+# DefaultCanBePrefix test
+
+`default-can-be-prefix-*.cpp` verifies the effect of `Interest::setDefaultCanBePrefix`.
+They are written as integration tests because ndn-cxx unit tests are prohibited from calling `Interest::setDefaultCanBePrefix`.
+
+Manual verification steps:
+
+1. `default-can-be-prefix-unset` program should print a "CanBePrefix unset" warning to stderr.
+2. `default-can-be-prefix-0` and `default-can-be-prefix-1` test cases should not print that warning.
+
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 2884ec6..adbe314 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -128,7 +128,7 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExpressInterestData, TransportType, Transports, FaceFixture<TransportType>)
 {
   int nData = 0;
-  this->face.expressInterest(Interest("/"),
+  this->face.expressInterest(*makeInterest("/", true),
     [&] (const Interest&, const Data&) { ++nData; },
     [] (const Interest&, const lp::Nack&) { BOOST_ERROR("unexpected Nack"); },
     [] (const Interest&) { BOOST_ERROR("unexpected timeout"); });
@@ -140,7 +140,7 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExpressInterestNack, TransportType, Transports, FaceFixture<TransportType>)
 {
   int nNacks = 0;
-  this->face.expressInterest(Interest("/localhost/non-existent-should-nack"),
+  this->face.expressInterest(*makeInterest("/localhost/non-existent-should-nack"),
     [] (const Interest&, const Data&) { BOOST_ERROR("unexpected Data"); },
     [&] (const Interest&, const lp::Nack&) { ++nNacks; },
     [] (const Interest&) { BOOST_ERROR("unexpected timeout"); });
@@ -156,7 +156,7 @@
   std::this_thread::sleep_for(std::chrono::milliseconds(200)); // wait for FIB update to take effect
 
   int nTimeouts = 0;
-  this->face.expressInterest(Interest("/localhost/non-existent-should-timeout", 1_s),
+  this->face.expressInterest(*makeInterest("/localhost/non-existent-should-timeout", false, 1_s),
     [] (const Interest&, const Data&) { BOOST_ERROR("unexpected Data"); },
     [] (const Interest&, const lp::Nack&) { BOOST_ERROR("unexpected Nack"); },
     [&] (const Interest&) { ++nTimeouts; });
@@ -168,7 +168,7 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(OversizedInterest, TransportType, Transports, FaceFixture<TransportType>)
 {
   BOOST_CHECK_THROW(do {
-    this->face.expressInterest(Interest(makeVeryLongName()), nullptr, nullptr, nullptr);
+    this->face.expressInterest(*makeInterest(makeVeryLongName()), nullptr, nullptr, nullptr);
     this->face.processEvents();
   } while (false), Face::OversizedPacketError);
 }
@@ -229,7 +229,7 @@
   });
 
   char interestOutcome;
-  this->sendInterest(1_s, Interest("/Hello/World/regular", 50_ms), interestOutcome);
+  this->sendInterest(1_s, *makeInterest("/Hello/World/regular", false, 50_ms), interestOutcome);
 
   this->face.processEvents();
   BOOST_CHECK_EQUAL(interestOutcome, 'T');
@@ -254,10 +254,10 @@
     BOOST_CHECK(!output.empty());
   });
 
-  this->sendInterest(200_ms, Interest("/Hello/World/a", 50_ms));
-  this->sendInterest(300_ms, Interest("/Hello/World/a/b", 50_ms));
-  this->sendInterest(400_ms, Interest("/Hello/World/a/b/c", 50_ms));
-  this->sendInterest(500_ms, Interest("/Hello/World/a/b/d", 50_ms));
+  this->sendInterest(200_ms, *makeInterest("/Hello/World/a", false, 50_ms));
+  this->sendInterest(300_ms, *makeInterest("/Hello/World/a/b", false, 50_ms));
+  this->sendInterest(400_ms, *makeInterest("/Hello/World/a/b/c", false, 50_ms));
+  this->sendInterest(500_ms, *makeInterest("/Hello/World/a/b/d", false, 50_ms));
 
   this->face.processEvents();
   BOOST_CHECK_EQUAL(nRegSuccess, 1);
@@ -280,10 +280,10 @@
     BOOST_CHECK(output.empty());
   });
 
-  this->sendInterest(200_ms, Interest("/Hello/World/a", 50_ms));
-  this->sendInterest(300_ms, Interest("/Hello/World/a/b", 50_ms));
-  this->sendInterest(400_ms, Interest("/Hello/World/a/b/c", 50_ms));
-  this->sendInterest(500_ms, Interest("/Hello/World/a/b/d", 50_ms));
+  this->sendInterest(200_ms, *makeInterest("/Hello/World/a", false, 50_ms));
+  this->sendInterest(300_ms, *makeInterest("/Hello/World/a/b", false, 50_ms));
+  this->sendInterest(400_ms, *makeInterest("/Hello/World/a/b/c", false, 50_ms));
+  this->sendInterest(500_ms, *makeInterest("/Hello/World/a/b/d", false, 50_ms));
 
   this->face.processEvents();
 }
@@ -305,8 +305,8 @@
     [] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
   char outcome1, outcome2;
-  this->sendInterest(700_ms, Interest("/Hello/World/data", 50_ms), outcome1);
-  this->sendInterest(800_ms, Interest("/Hello/World/nack", 50_ms), outcome2);
+  this->sendInterest(700_ms, *makeInterest("/Hello/World/data", false, 50_ms), outcome1);
+  this->sendInterest(800_ms, *makeInterest("/Hello/World/nack", false, 50_ms), outcome2);
 
   this->face.processEvents();
   BOOST_CHECK_EQUAL(outcome1, 'D');
@@ -324,7 +324,7 @@
     nullptr,
     [] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
-  this->sendInterest(1_s, Interest("/Hello/World/oversized", 50_ms));
+  this->sendInterest(1_s, *makeInterest("/Hello/World/oversized", true, 50_ms));
 
   BOOST_CHECK_THROW(this->face.processEvents(), Face::OversizedPacketError);
 }
@@ -335,12 +335,12 @@
 
 BOOST_AUTO_TEST_CASE(ShutdownWhileSendInProgress) // Bug #3136
 {
-  this->face.expressInterest(Interest("/Hello/World"), nullptr, nullptr, nullptr);
+  this->face.expressInterest(*makeInterest("/Hello/World"), nullptr, nullptr, nullptr);
   this->face.processEvents(1_s);
 
-  this->face.expressInterest(Interest("/Bye/World/1"), nullptr, nullptr, nullptr);
-  this->face.expressInterest(Interest("/Bye/World/2"), nullptr, nullptr, nullptr);
-  this->face.expressInterest(Interest("/Bye/World/3"), nullptr, nullptr, nullptr);
+  this->face.expressInterest(*makeInterest("/Bye/World/1"), nullptr, nullptr, nullptr);
+  this->face.expressInterest(*makeInterest("/Bye/World/2"), nullptr, nullptr, nullptr);
+  this->face.expressInterest(*makeInterest("/Bye/World/3"), nullptr, nullptr, nullptr);
   this->face.shutdown();
 
   this->face.processEvents(1_s); // should not segfault
diff --git a/tests/make-interest-data.cpp b/tests/make-interest-data.cpp
index a497da2..4f66268 100644
--- a/tests/make-interest-data.cpp
+++ b/tests/make-interest-data.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -26,9 +26,10 @@
 namespace tests {
 
 shared_ptr<Interest>
-makeInterest(const Name& name, uint32_t nonce)
+makeInterest(const Name& name, bool canBePrefix, time::milliseconds lifetime, uint32_t nonce)
 {
-  auto interest = make_shared<Interest>(name);
+  auto interest = make_shared<Interest>(name, lifetime);
+  interest->setCanBePrefix(canBePrefix);
   if (nonce != 0) {
     interest->setNonce(nonce);
   }
diff --git a/tests/make-interest-data.hpp b/tests/make-interest-data.hpp
index 8fc5545..a703263 100644
--- a/tests/make-interest-data.hpp
+++ b/tests/make-interest-data.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -32,11 +32,13 @@
 
 /** \brief create an Interest
  *  \param name Interest name
- *  \param nonce if non-zero, set Nonce to this value
- *               (useful for creating Nack with same Nonce)
+ *  \param canBePrefix CanBePrefix setting
+ *  \param lifetime InterestLifetime
+ *  \param nonce if non-zero, set Nonce to this value (useful for creating Nack with same Nonce)
  */
 shared_ptr<Interest>
-makeInterest(const Name& name, uint32_t nonce = 0);
+makeInterest(const Name& name, bool canBePrefix = false,
+             time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME, uint32_t nonce = 0);
 
 /** \brief create a Data with fake signature
  *  \note Data may be modified afterwards without losing the fake signature.
@@ -66,14 +68,6 @@
 lp::Nack
 makeNack(const Interest& interest, lp::NackReason reason);
 
-/** \brief create a Nack
- *  \param name Interest name
- *  \param nonce Interest nonce
- *  \param reason Nack reason
- */
-lp::Nack
-makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
-
 /** \brief replace a name component
  *  \param[inout] name name
  *  \param index name component index
diff --git a/tests/unit-tests/face.t.cpp b/tests/unit-tests/face.t.cpp
index 2412c66..3f2b82a 100644
--- a/tests/unit-tests/face.t.cpp
+++ b/tests/unit-tests/face.t.cpp
@@ -27,9 +27,9 @@
 #include "util/scheduler.hpp"
 
 #include "boost-test.hpp"
+#include "make-interest-data.hpp"
 #include "identity-management-time-fixture.hpp"
 #include "test-home-fixture.hpp"
-#include "make-interest-data.hpp"
 
 namespace ndn {
 namespace tests {
@@ -65,7 +65,7 @@
 BOOST_AUTO_TEST_CASE(ExpressInterestData)
 {
   size_t nData = 0;
-  face.expressInterest(Interest("/Hello/World", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
                        [&] (const Interest& i, const Data& d) {
                          BOOST_CHECK(i.getName().isPrefixOf(d.getName()));
                          BOOST_CHECK_EQUAL(i.getName(), "/Hello/World");
@@ -86,7 +86,7 @@
   BOOST_CHECK_EQUAL(face.sentData.size(), 0);
 
   size_t nTimeouts = 0;
-  face.expressInterest(Interest("/Hello/World/a/2", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World/a/2", false, 50_ms),
                        bind([]{}),
                        bind([]{}),
                        bind([&nTimeouts] { ++nTimeouts; }));
@@ -98,14 +98,14 @@
 {
   size_t nData = 0;
 
-  face.expressInterest(Interest("/Hello/World", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
                        [&] (const Interest& i, const Data& d) {
                          ++nData;
                        },
                        bind([] { BOOST_FAIL("Unexpected Nack"); }),
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
 
-  face.expressInterest(Interest("/Hello/World/a", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World/a", true, 50_ms),
                        [&] (const Interest& i, const Data& d) {
                          ++nData;
                        },
@@ -125,7 +125,7 @@
 
 BOOST_AUTO_TEST_CASE(ExpressInterestEmptyDataCallback)
 {
-  face.expressInterest(Interest("/Hello/World"),
+  face.expressInterest(*makeInterest("/Hello/World", true),
                        nullptr,
                        bind([] { BOOST_FAIL("Unexpected Nack"); }),
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
@@ -140,7 +140,7 @@
 BOOST_AUTO_TEST_CASE(ExpressInterestTimeout)
 {
   size_t nTimeouts = 0;
-  face.expressInterest(Interest("/Hello/World", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        bind([] { BOOST_FAIL("Unexpected Nack"); }),
                        [&nTimeouts] (const Interest& i) {
@@ -158,7 +158,7 @@
 
 BOOST_AUTO_TEST_CASE(ExpressInterestEmptyTimeoutCallback)
 {
-  face.expressInterest(Interest("/Hello/World", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        bind([] { BOOST_FAIL("Unexpected Nack"); }),
                        nullptr);
@@ -173,9 +173,9 @@
 {
   size_t nNacks = 0;
 
-  Interest interest("/Hello/World", 50_ms);
+  auto interest = makeInterest("/Hello/World", false, 50_ms);
 
-  face.expressInterest(interest,
+  face.expressInterest(*interest,
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        [&] (const Interest& i, const lp::Nack& n) {
                          BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName()));
@@ -199,18 +199,16 @@
 {
   size_t nNacks = 0;
 
-  Interest interest("/Hello/World", 50_ms);
-  interest.setNonce(1);
-
-  face.expressInterest(interest,
+  auto interest = makeInterest("/Hello/World", false, 50_ms, 1);
+  face.expressInterest(*interest,
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        [&] (const Interest& i, const lp::Nack& n) {
                          ++nNacks;
                        },
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
 
-  interest.setNonce(2);
-  face.expressInterest(interest,
+  interest->setNonce(2);
+  face.expressInterest(*interest,
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        [&] (const Interest& i, const lp::Nack& n) {
                          ++nNacks;
@@ -229,7 +227,7 @@
 
 BOOST_AUTO_TEST_CASE(ExpressInterestEmptyNackCallback)
 {
-  face.expressInterest(Interest("/Hello/World"),
+  face.expressInterest(*makeInterest("/Hello/World"),
                        bind([] { BOOST_FAIL("Unexpected Data"); }),
                        nullptr,
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
@@ -244,7 +242,7 @@
 BOOST_AUTO_TEST_CASE(RemovePendingInterest)
 {
   const PendingInterestId* interestId =
-    face.expressInterest(Interest("/Hello/World", 50_ms),
+    face.expressInterest(*makeInterest("/Hello/World", true, 50_ms),
                          bind([] { BOOST_FAIL("Unexpected data"); }),
                          bind([] { BOOST_FAIL("Unexpected nack"); }),
                          bind([] { BOOST_FAIL("Unexpected timeout"); }));
@@ -262,12 +260,12 @@
 
 BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests)
 {
-  face.expressInterest(Interest("/Hello/World/0", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World/0", false, 50_ms),
                        bind([] { BOOST_FAIL("Unexpected data"); }),
                        bind([] { BOOST_FAIL("Unexpected nack"); }),
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
 
-  face.expressInterest(Interest("/Hello/World/1", 50_ms),
+  face.expressInterest(*makeInterest("/Hello/World/1", false, 50_ms),
                        bind([] { BOOST_FAIL("Unexpected data"); }),
                        bind([] { BOOST_FAIL("Unexpected nack"); }),
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
@@ -288,7 +286,7 @@
 {
   {
     DummyClientFace face2(io, m_keyChain);
-    face2.expressInterest(Interest("/Hello/World", 50_ms),
+    face2.expressInterest(*makeInterest("/Hello/World", false, 50_ms),
                           nullptr, nullptr, nullptr);
     advanceClocks(50_ms, 2);
   }
@@ -301,14 +299,14 @@
 
 BOOST_AUTO_TEST_CASE(DataCallbackPutData) // Bug 4596
 {
-  face.expressInterest(Interest("/localhost/notification/1"),
+  face.expressInterest(*makeInterest("/localhost/notification/1"),
                        [&] (const Interest& i, const Data& d) {
                          face.put(*makeData("/chronosync/sampleDigest/1"));
                        }, nullptr, nullptr);
   advanceClocks(10_ms);
   BOOST_CHECK_EQUAL(face.sentInterests.back().getName(), "/localhost/notification/1");
 
-  face.receive(Interest("/chronosync/sampleDigest"));
+  face.receive(*makeInterest("/chronosync/sampleDigest", true));
   advanceClocks(10_ms);
 
   face.put(*makeData("/localhost/notification/1"));
@@ -355,7 +353,7 @@
   face.setInterestFilter(InterestFilter("/").allowLoopback(false),
     bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); }));
 
-  face.expressInterest(Interest("/A"),
+  face.expressInterest(*makeInterest("/A", true),
                        bind([&] { hasData = true; }),
                        bind([] { BOOST_FAIL("Unexpected nack"); }),
                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
@@ -382,7 +380,7 @@
   face.setInterestFilter("/", bind([]{}));
   advanceClocks(10_ms);
 
-  face.receive(*makeInterest("/A"));
+  face.receive(*makeInterest("/A", true));
   advanceClocks(10_ms);
   BOOST_CHECK(hasInterest1);
   BOOST_CHECK_EQUAL(face.sentData.size(), 1);
@@ -399,21 +397,24 @@
 
   BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
 
-  face.put(makeNack("/unsolicited", 18645250, lp::NackReason::NO_ROUTE));
+  face.put(makeNack(*makeInterest("/unsolicited", false, DEFAULT_INTEREST_LIFETIME, 18645250),
+                    lp::NackReason::NO_ROUTE));
   advanceClocks(10_ms);
   BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent
 
-  face.receive(*makeInterest("/Hello/World", 14247162));
-  face.receive(*makeInterest("/another/prefix", 92203002));
+  auto interest1 = makeInterest("/Hello/World", false, DEFAULT_INTEREST_LIFETIME, 14247162);
+  face.receive(*interest1);
+  auto interest2 = makeInterest("/another/prefix", false, DEFAULT_INTEREST_LIFETIME, 92203002);
+  face.receive(*interest2);
   advanceClocks(10_ms);
 
-  face.put(makeNack("/Hello/World", 14247162, lp::NackReason::DUPLICATE));
+  face.put(makeNack(*interest1, lp::NackReason::DUPLICATE));
   advanceClocks(10_ms);
   BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 1);
   BOOST_CHECK_EQUAL(face.sentNacks[0].getReason(), lp::NackReason::DUPLICATE);
   BOOST_CHECK(face.sentNacks[0].getTag<lp::CongestionMarkTag>() == nullptr);
 
-  auto nack = makeNack("/another/prefix", 92203002, lp::NackReason::NO_ROUTE);
+  auto nack = makeNack(*interest2, lp::NackReason::NO_ROUTE);
   nack.setTag(make_shared<lp::CongestionMarkTag>(1));
   face.put(nack);
   advanceClocks(10_ms);
@@ -434,7 +435,8 @@
   face.setInterestFilter("/", bind([&] { hasInterest2 = true; }));
   advanceClocks(10_ms);
 
-  face.receive(*makeInterest("/A", 14333271));
+  auto interest = makeInterest("/A", false, DEFAULT_INTEREST_LIFETIME, 14333271);
+  face.receive(*interest);
   advanceClocks(10_ms);
   BOOST_CHECK(hasInterest1);
   BOOST_CHECK(hasInterest2);
@@ -442,12 +444,12 @@
   // Nack from first destination is received, should wait for a response from the other destination
   BOOST_CHECK_EQUAL(face.sentNacks.size(), 0);
 
-  face.put(makeNack("/A", 14333271, lp::NackReason::NO_ROUTE)); // Nack from second destination
+  face.put(makeNack(*interest, lp::NackReason::NO_ROUTE)); // Nack from second destination
   advanceClocks(10_ms);
   BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked
   BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason
 
-  face.put(makeNack("/A", 14333271, lp::NackReason::DUPLICATE));
+  face.put(makeNack(*interest, lp::NackReason::DUPLICATE));
   BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored
 }
 
@@ -464,7 +466,8 @@
   face.setInterestFilter(InterestFilter("/").allowLoopback(false),
     bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); }));
 
-  face.expressInterest(*makeInterest("/A", 28395852),
+  auto interest = makeInterest("/A", false, DEFAULT_INTEREST_LIFETIME, 28395852);
+  face.expressInterest(*interest,
                        bind([] { BOOST_FAIL("Unexpected data"); }),
                        [&] (const Interest&, const lp::Nack& nack) {
                          hasNack = true;
@@ -476,7 +479,7 @@
   BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder
   BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder
 
-  face.receive(makeNack("/A", 28395852, lp::NackReason::NO_ROUTE));
+  face.receive(makeNack(*interest, lp::NackReason::NO_ROUTE));
   advanceClocks(1_ms);
   BOOST_CHECK_EQUAL(hasNack, true);
 }
@@ -494,17 +497,17 @@
   BOOST_CHECK_EQUAL(nRegs, 1);
   BOOST_CHECK_EQUAL(nInterests, 0);
 
-  face.receive(Interest("/Hello/World/%21"));
+  face.receive(*makeInterest("/Hello/World/%21"));
   advanceClocks(25_ms, 4);
 
   BOOST_CHECK_EQUAL(nRegs, 1);
   BOOST_CHECK_EQUAL(nInterests, 1);
 
-  face.receive(Interest("/Bye/World/%21"));
+  face.receive(*makeInterest("/Bye/World/%21"));
   advanceClocks(10000_ms, 10);
   BOOST_CHECK_EQUAL(nInterests, 1);
 
-  face.receive(Interest("/Hello/World/%21/2"));
+  face.receive(*makeInterest("/Hello/World/%21/2"));
   advanceClocks(25_ms, 4);
   BOOST_CHECK_EQUAL(nInterests, 2);
 
@@ -512,7 +515,7 @@
   face.unsetInterestFilter(regPrefixId);
   advanceClocks(25_ms, 4);
 
-  face.receive(Interest("/Hello/World/%21/3"));
+  face.receive(*makeInterest("/Hello/World/%21/3"));
   BOOST_CHECK_EQUAL(nInterests, 2);
 
   face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr));
@@ -543,16 +546,16 @@
   advanceClocks(25_ms, 4);
   BOOST_CHECK_EQUAL(nInterests, 0);
 
-  face.receive(Interest("/Hello/World/%21"));
+  face.receive(*makeInterest("/Hello/World/%21"));
   advanceClocks(25_ms, 4);
 
   BOOST_CHECK_EQUAL(nInterests, 1);
 
-  face.receive(Interest("/Bye/World/%21"));
+  face.receive(*makeInterest("/Bye/World/%21"));
   advanceClocks(10000_ms, 10);
   BOOST_CHECK_EQUAL(nInterests, 1);
 
-  face.receive(Interest("/Hello/World/%21/2"));
+  face.receive(*makeInterest("/Hello/World/%21/2"));
   advanceClocks(25_ms, 4);
   BOOST_CHECK_EQUAL(nInterests, 2);
 
@@ -560,7 +563,7 @@
   face.unsetInterestFilter(regPrefixId);
   advanceClocks(25_ms, 4);
 
-  face.receive(Interest("/Hello/World/%21/3"));
+  face.receive(*makeInterest("/Hello/World/%21/3"));
   BOOST_CHECK_EQUAL(nInterests, 2);
 
   face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr));
@@ -655,7 +658,7 @@
 
   advanceClocks(25_ms, 4);
 
-  face.receive(Interest("/Hello/World/%21"));
+  face.receive(*makeInterest("/Hello/World/%21"));
   advanceClocks(25_ms, 4);
 
   BOOST_CHECK_EQUAL(nInInterests1, 1);
@@ -674,7 +677,7 @@
 
   advanceClocks(25_ms, 4);
 
-  BOOST_REQUIRE_THROW(face.receive(Interest("/Hello/World/XXX/b/c")), InterestFilter::Error);
+  BOOST_REQUIRE_THROW(face.receive(*makeInterest("/Hello/World/XXX/b/c")), InterestFilter::Error);
 }
 
 BOOST_AUTO_TEST_CASE(SetRegexFilter)
@@ -687,16 +690,16 @@
 
   advanceClocks(25_ms, 4);
 
-  face.receive(Interest("/Hello/World/a"));     // shouldn't match
+  face.receive(*makeInterest("/Hello/World/a"));     // shouldn't match
   BOOST_CHECK_EQUAL(nInInterests, 0);
 
-  face.receive(Interest("/Hello/World/a/b"));   // should match
+  face.receive(*makeInterest("/Hello/World/a/b"));   // should match
   BOOST_CHECK_EQUAL(nInInterests, 1);
 
-  face.receive(Interest("/Hello/World/a/b/c")); // should match
+  face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
   BOOST_CHECK_EQUAL(nInInterests, 2);
 
-  face.receive(Interest("/Hello/World/a/b/d")); // should not match
+  face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
   BOOST_CHECK_EQUAL(nInInterests, 2);
 }
 
@@ -714,16 +717,16 @@
   advanceClocks(25_ms, 4);
   BOOST_CHECK_EQUAL(nRegSuccesses, 1);
 
-  face.receive(Interest("/Hello/World/a")); // shouldn't match
+  face.receive(*makeInterest("/Hello/World/a")); // shouldn't match
   BOOST_CHECK_EQUAL(nInInterests, 0);
 
-  face.receive(Interest("/Hello/World/a/b")); // should match
+  face.receive(*makeInterest("/Hello/World/a/b")); // should match
   BOOST_CHECK_EQUAL(nInInterests, 1);
 
-  face.receive(Interest("/Hello/World/a/b/c")); // should match
+  face.receive(*makeInterest("/Hello/World/a/b/c")); // should match
   BOOST_CHECK_EQUAL(nInInterests, 2);
 
-  face.receive(Interest("/Hello/World/a/b/d")); // should not match
+  face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match
   BOOST_CHECK_EQUAL(nInInterests, 2);
 }
 
@@ -736,8 +739,7 @@
   face.setInterestFilter(Name("/"), bind([&hit] { ++hit; }));
   face.processEvents(time::milliseconds(-1));
 
-  auto interest = make_shared<Interest>("/A");
-  face.receive(*interest);
+  face.receive(*makeInterest("/A"));
   face.processEvents(time::milliseconds(-1));
 
   BOOST_CHECK_EQUAL(hit, 1);
diff --git a/tests/unit-tests/ims/in-memory-storage.t.cpp b/tests/unit-tests/ims/in-memory-storage.t.cpp
index 0cec78a..2304889 100644
--- a/tests/unit-tests/ims/in-memory-storage.t.cpp
+++ b/tests/unit-tests/ims/in-memory-storage.t.cpp
@@ -436,16 +436,18 @@
   shared_ptr<Data> data7 = makeData("/c/n");
   ims.insert(*data7);
 
-  shared_ptr<Interest> interest = makeInterest("/c");
+  shared_ptr<Interest> interest = makeInterest("/c", true);
   interest->setChildSelector(1);
 
   shared_ptr<const Data> found = ims.find(*interest);
+  BOOST_REQUIRE(found != nullptr);
   BOOST_CHECK_EQUAL(found->getName(), "/c/n");
 
-  shared_ptr<Interest> interest2 = makeInterest("/c");
+  shared_ptr<Interest> interest2 = makeInterest("/c", true);
   interest2->setChildSelector(0);
 
   shared_ptr<const Data> found2 = ims.find(*interest2);
+  BOOST_REQUIRE(found2 != nullptr);
   BOOST_CHECK_EQUAL(found2->getName(), "/c/c");
 }
 
@@ -465,10 +467,11 @@
   shared_ptr<Data> data4 = makeData("/a/z/2");
   ims.insert(*data4);
 
-  shared_ptr<Interest> interest = makeInterest("/a");
+  shared_ptr<Interest> interest = makeInterest("/a", true);
   interest->setChildSelector(1);
 
   shared_ptr<const Data> found = ims.find(*interest);
+  BOOST_REQUIRE(found != nullptr);
   BOOST_CHECK_EQUAL(found->getName(), "/a/z/1");
 }
 
@@ -544,18 +547,20 @@
   shared_ptr<Data> data8 = makeData("/c/c/1");
   ims.insert(*data8);
 
-  shared_ptr<Interest> interest = makeInterest("/c/c");
+  shared_ptr<Interest> interest = makeInterest("/c/c", true);
   interest->setMinSuffixComponents(3);
   interest->setChildSelector(0);
 
   shared_ptr<const Data> found = ims.find(*interest);
+  BOOST_REQUIRE(found != nullptr);
   BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3");
 
-  shared_ptr<Interest> interest2 = makeInterest("/c/c");
+  shared_ptr<Interest> interest2 = makeInterest("/c/c", true);
   interest2->setMinSuffixComponents(4);
   interest2->setChildSelector(1);
 
   shared_ptr<const Data> found2 = ims.find(*interest2);
+  BOOST_REQUIRE(found2 != nullptr);
   BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9");
 
   shared_ptr<Interest> interest3 = makeInterest("/c/c");
@@ -563,6 +568,7 @@
   interest3->setChildSelector(1);
 
   shared_ptr<const Data> found3 = ims.find(*interest3);
+  BOOST_REQUIRE(found3 != nullptr);
   BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1");
 }
 
@@ -591,33 +597,34 @@
   shared_ptr<Data> data7 = makeData("/c/n");
   ims.insert(*data7);
 
-  shared_ptr<Interest> interest = makeInterest("/c");
+  shared_ptr<Interest> interest = makeInterest("/c", true);
   interest->setChildSelector(1);
   Exclude e;
-  e.excludeOne (Name::Component("n"));
+  e.excludeOne(Name::Component("n"));
   interest->setExclude(e);
 
   shared_ptr<const Data> found = ims.find(*interest);
+  BOOST_REQUIRE(found != nullptr);
   BOOST_CHECK_EQUAL(found->getName(), "/c/f");
 
-  shared_ptr<Interest> interest2 = makeInterest("/c");
+  shared_ptr<Interest> interest2 = makeInterest("/c", true);
   interest2->setChildSelector(0);
-
   Exclude e2;
-  e2.excludeOne (Name::Component("a"));
+  e2.excludeOne(Name::Component("a"));
   interest2->setExclude(e2);
 
   shared_ptr<const Data> found2 = ims.find(*interest2);
+  BOOST_REQUIRE(found2 != nullptr);
   BOOST_CHECK_EQUAL(found2->getName(), "/c/c");
 
-  shared_ptr<Interest> interest3 = makeInterest("/c");
+  shared_ptr<Interest> interest3 = makeInterest("/c", true);
   interest3->setChildSelector(0);
-
   Exclude e3;
-  e3.excludeOne (Name::Component("c"));
+  e3.excludeOne(Name::Component("c"));
   interest3->setExclude(e3);
 
   shared_ptr<const Data> found3 = ims.find(*interest3);
+  BOOST_REQUIRE(found3 != nullptr);
   BOOST_CHECK_EQUAL(found3->getName(), "/c/a");
 }
 
@@ -642,11 +649,9 @@
 BOOST_AUTO_TEST_CASE_TEMPLATE(GetLimit, T, InMemoryStoragesLimited)
 {
   T ims(10000);
-
   BOOST_CHECK_EQUAL(ims.getLimit(), 10000);
 
   T ims2(4);
-
   BOOST_CHECK_EQUAL(ims2.getLimit(), 4);
 }
 
@@ -665,7 +670,6 @@
   }
 
   BOOST_CHECK_EQUAL(ims.size(), 11);
-
   BOOST_CHECK_EQUAL(ims.getCapacity(), 20);
 }
 
@@ -718,7 +722,7 @@
   Interest&
   startInterest(const Name& name)
   {
-    m_interest = makeInterest(name);
+    m_interest = makeInterest(name, true);
     return *m_interest;
   }
 
diff --git a/tests/unit-tests/interest-filter.t.cpp b/tests/unit-tests/interest-filter.t.cpp
index 157fa05..96f4ae9 100644
--- a/tests/unit-tests/interest-filter.t.cpp
+++ b/tests/unit-tests/interest-filter.t.cpp
@@ -27,6 +27,7 @@
 #include "util/dummy-client-face.hpp"
 
 #include "boost-test.hpp"
+#include "make-interest-data.hpp"
 
 namespace ndn {
 namespace tests {
@@ -58,7 +59,7 @@
   face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
     [] (const Name&, const Interest&) { BOOST_ERROR("unexpected Interest"); });
   face.processEvents(1_ms);
-  BOOST_CHECK_THROW(face.receive(Interest("/Hello/World/a/b/c")), InterestFilter::Error);
+  BOOST_CHECK_THROW(face.receive(*makeInterest("/Hello/World/a/b/c")), InterestFilter::Error);
 }
 
 BOOST_AUTO_TEST_CASE(AllowLoopback)
diff --git a/tests/unit-tests/interest.t.cpp b/tests/unit-tests/interest.t.cpp
index f1e79dc..bf2389f 100644
--- a/tests/unit-tests/interest.t.cpp
+++ b/tests/unit-tests/interest.t.cpp
@@ -61,6 +61,7 @@
   };
 
   Interest i1("/local/ndn/prefix");
+  i1.setCanBePrefix(true);
   i1.setNonce(1);
   Block wire1 = i1.wireEncode();
   BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
@@ -96,6 +97,7 @@
 
   Interest i1;
   i1.setName("/local/ndn/prefix");
+  i1.setCanBePrefix(true);
   i1.setMinSuffixComponents(1);
   i1.setNonce(1);
   i1.setInterestLifetime(1000_ms);
@@ -395,6 +397,7 @@
 BOOST_AUTO_TEST_CASE(ModifyForwardingHint)
 {
   Interest i;
+  i.setCanBePrefix(false);
   i.setForwardingHint({{1, "/A"}});
   i.wireEncode();
   BOOST_CHECK(i.hasWire());
@@ -431,6 +434,7 @@
 BOOST_AUTO_TEST_CASE(SetNonce)
 {
   Interest i1("/A");
+  i1.setCanBePrefix(false);
   i1.setNonce(1);
   i1.wireEncode();
   BOOST_CHECK_EQUAL(i1.getNonce(), 1);
diff --git a/tests/unit-tests/mgmt/dispatcher.t.cpp b/tests/unit-tests/mgmt/dispatcher.t.cpp
index 69f389d..c75af4d 100644
--- a/tests/unit-tests/mgmt/dispatcher.t.cpp
+++ b/tests/unit-tests/mgmt/dispatcher.t.cpp
@@ -361,7 +361,7 @@
 
   face.sentData.clear();
 
-  auto interestSmall = *makeInterest("/root/test/small/valid");
+  auto interestSmall = *makeInterest("/root/test/small/valid", true);
   face.receive(interestSmall);
   advanceClocks(1_ms, 10);
 
diff --git a/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp b/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
index a819279..2f90302 100644
--- a/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
@@ -25,6 +25,7 @@
 
 #include "boost-test.hpp"
 #include "../identity-management-time-fixture.hpp"
+#include "make-interest-data.hpp"
 
 namespace ndn {
 namespace security {
@@ -124,21 +125,21 @@
 {
   Identity identity = addIdentity("/SecurityTestSignatureSha256WithEcdsa/InterestSignature", EcKeyParams());
 
-  Interest interest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
-  Interest interest11("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
+  auto interest = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
+  auto interest11 = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
 
   scheduler.scheduleEvent(100_ms, [&] {
-      BOOST_CHECK_NO_THROW(m_keyChain.sign(interest, security::SigningInfo(identity)));
+      m_keyChain.sign(*interest, security::SigningInfo(identity));
     });
 
   advanceClocks(100_ms);
   scheduler.scheduleEvent(100_ms, [&] {
-      BOOST_CHECK_NO_THROW(m_keyChain.sign(interest11, security::SigningInfo(identity)));
+      m_keyChain.sign(*interest11, security::SigningInfo(identity));
     });
 
   advanceClocks(100_ms);
 
-  Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size());
+  Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
 
   Interest interest2;
   interest2.wireDecode(interestBlock);
diff --git a/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp b/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
index 86dbb37..7de3774 100644
--- a/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
@@ -25,6 +25,7 @@
 
 #include "boost-test.hpp"
 #include "../identity-management-time-fixture.hpp"
+#include "make-interest-data.hpp"
 
 namespace ndn {
 namespace security {
@@ -129,21 +130,21 @@
 {
   Identity identity = addIdentity("/SecurityTestSignatureSha256WithRsa/InterestSignature", RsaKeyParams());
 
-  Interest interest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
-  Interest interest11("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
+  auto interest = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
+  auto interest11 = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
 
   scheduler.scheduleEvent(100_ms, [&] {
-      BOOST_CHECK_NO_THROW(m_keyChain.sign(interest, security::SigningInfo(identity)));
+      m_keyChain.sign(*interest, security::SigningInfo(identity));
     });
 
   advanceClocks(100_ms);
   scheduler.scheduleEvent(100_ms, [&] {
-      BOOST_CHECK_NO_THROW(m_keyChain.sign(interest11, security::SigningInfo(identity)));
+      m_keyChain.sign(*interest11, security::SigningInfo(identity));
     });
 
   advanceClocks(100_ms);
 
-  Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size());
+  Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
 
   Interest interest2;
   interest2.wireDecode(interestBlock);
diff --git a/tests/unit-tests/util/dummy-client-face.t.cpp b/tests/unit-tests/util/dummy-client-face.t.cpp
index 5308e28..aed8cd6 100644
--- a/tests/unit-tests/util/dummy-client-face.t.cpp
+++ b/tests/unit-tests/util/dummy-client-face.t.cpp
@@ -29,6 +29,8 @@
 namespace util {
 namespace tests {
 
+using namespace ndn::tests;
+
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_FIXTURE_TEST_SUITE(TestDummyClientFace, ndn::tests::IdentityManagementTimeFixture)
 
@@ -71,12 +73,12 @@
 
   int nFace1Data = 0;
   int nFace2Nack = 0;
-  face1.expressInterest(Interest("/face2/data"),
+  face1.expressInterest(*makeInterest("/face2/data"),
                         [&] (const Interest& i, const Data& d) {
                           BOOST_CHECK_EQUAL(d.getName().toUri(), "/face2/data");
                           nFace1Data++;
                         }, nullptr, nullptr);
-  face2.expressInterest(Interest("/face1/data"),
+  face2.expressInterest(*makeInterest("/face1/data"),
                         [&] (const Interest& i, const Data& d) {
                           BOOST_CHECK(false);
                         },