meta-info: allow typed name component in FinalBlockId

refs #4526

Change-Id: I3b6667928fa47c631e45ff5f0ca2c5030c5cc2ad
diff --git a/src/data.cpp b/src/data.cpp
index 9a59089..6b50dca 100644
--- a/src/data.cpp
+++ b/src/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).
  *
@@ -246,7 +246,7 @@
 }
 
 Data&
-Data::setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
+Data::setFreshnessPeriod(time::milliseconds freshnessPeriod)
 {
   resetWire();
   m_metaInfo.setFreshnessPeriod(freshnessPeriod);
@@ -254,6 +254,20 @@
 }
 
 Data&
+Data::setFinalBlock(optional<name::Component> finalBlockId)
+{
+  resetWire();
+  m_metaInfo.setFinalBlock(std::move(finalBlockId));
+  return *this;
+}
+
+name::Component
+Data::getFinalBlockId() const
+{
+  return m_metaInfo.getFinalBlockId();
+}
+
+Data&
 Data::setFinalBlockId(const name::Component& finalBlockId)
 {
   resetWire();
diff --git a/src/data.hpp b/src/data.hpp
index e0a8466..8eb1b3d 100644
--- a/src/data.hpp
+++ b/src/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).
  *
@@ -206,22 +206,36 @@
   Data&
   setContentType(uint32_t type);
 
-  const time::milliseconds&
+  time::milliseconds
   getFreshnessPeriod() const
   {
     return m_metaInfo.getFreshnessPeriod();
   }
 
   Data&
-  setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
+  setFreshnessPeriod(time::milliseconds freshnessPeriod);
 
-  const name::Component&
-  getFinalBlockId() const
+  const optional<name::Component>&
+  getFinalBlock() const
   {
-    return m_metaInfo.getFinalBlockId();
+    return m_metaInfo.getFinalBlock();
   }
 
   Data&
+  setFinalBlock(optional<name::Component> finalBlockId);
+
+  /** @deprecated Use @c getFinalBlock
+   *  @sa MetaInfo::getFinalBlockId
+   */
+  NDN_CXX_DEPRECATED
+  name::Component
+  getFinalBlockId() const;
+
+  /** @deprecated Use @c setFinalBlock
+   *  @sa MetaInfo::setFinalBlockId
+   */
+  NDN_CXX_DEPRECATED
+  Data&
   setFinalBlockId(const name::Component& finalBlockId);
 
 protected:
diff --git a/src/meta-info.cpp b/src/meta-info.cpp
index e19c11d..c6a43a4 100644
--- a/src/meta-info.cpp
+++ b/src/meta-info.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).
  *
@@ -63,13 +63,22 @@
 }
 
 MetaInfo&
-MetaInfo::setFinalBlockId(const name::Component& finalBlockId)
+MetaInfo::setFinalBlock(optional<name::Component> finalBlockId)
 {
   m_wire.reset();
-  m_finalBlockId = finalBlockId;
+  m_finalBlockId = std::move(finalBlockId);
   return *this;
 }
 
+MetaInfo&
+MetaInfo::setFinalBlockId(const name::Component& finalBlockId)
+{
+  if (finalBlockId.isGeneric() && finalBlockId.empty()) {
+    return setFinalBlock(nullopt);
+  }
+  return setFinalBlock(finalBlockId);
+}
+
 const std::list<Block>&
 MetaInfo::getAppMetaInfo() const
 {
@@ -146,8 +155,8 @@
   }
 
   // FinalBlockId
-  if (!m_finalBlockId.empty()) {
-    totalLength += prependNestedBlock(encoder, tlv::FinalBlockId, m_finalBlockId);
+  if (m_finalBlockId) {
+    totalLength += prependNestedBlock(encoder, tlv::FinalBlockId, *m_finalBlockId);
   }
 
   // FreshnessPeriod
@@ -218,16 +227,11 @@
 
   // FinalBlockId
   if (val != m_wire.elements_end() && val->type() == tlv::FinalBlockId) {
-    m_finalBlockId = val->blockFromValue();
-    if (m_finalBlockId.type() != tlv::NameComponent)
-      {
-        /// @todo May or may not throw exception later...
-        m_finalBlockId = name::Component();
-      }
+    m_finalBlockId.emplace(val->blockFromValue());
     ++val;
   }
   else {
-    m_finalBlockId = name::Component();
+    m_finalBlockId = nullopt;
   }
 
   // AppMetaInfo (if any)
@@ -248,9 +252,9 @@
   }
 
   // FinalBlockId
-  if (!info.getFinalBlockId().empty()) {
+  if (info.getFinalBlock()) {
     os << ", FinalBlockId: ";
-    info.getFinalBlockId().toUri(os);
+    info.getFinalBlock()->toUri(os);
   }
 
   // App-defined MetaInfo items
diff --git a/src/meta-info.hpp b/src/meta-info.hpp
index e8e8a00..911b1a3 100644
--- a/src/meta-info.hpp
+++ b/src/meta-info.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).
  *
@@ -87,27 +87,71 @@
   wireDecode(const Block& wire);
 
 public: // getter/setter
+  /** @brief return ContentType
+   *
+   *  If ContentType element is omitted, returns \c tlv::ContentType_Blob.
+   */
   uint32_t
-  getType() const;
+  getType() const
+  {
+    return m_type;
+  }
 
   /** @brief set ContentType
-   *  @param type a code defined in tlv::ContentTypeValue
+   *  @param type a number defined in \c tlv::ContentTypeValue
    */
   MetaInfo&
   setType(uint32_t type);
 
-  const time::milliseconds&
-  getFreshnessPeriod() const;
+  /** @brief return FreshnessPeriod
+   *
+   *  If FreshnessPeriod element is omitted, returns \c DEFAULT_FRESHNESS_PERIOD.
+   */
+  time::milliseconds
+  getFreshnessPeriod() const
+  {
+    return m_freshnessPeriod;
+  }
 
   /** @brief set FreshnessPeriod
-   *  @throw std::invalid_argument specified FreshnessPeriod is < 0
+   *  @throw std::invalid_argument specified FreshnessPeriod is negative
    */
   MetaInfo&
   setFreshnessPeriod(time::milliseconds freshnessPeriod);
 
-  const name::Component&
-  getFinalBlockId() const;
+  /** @brief return FinalBlockId
+   */
+  const optional<name::Component>&
+  getFinalBlock() const
+  {
+    return m_finalBlockId;
+  }
 
+  /** @brief set FinalBlockId
+   */
+  MetaInfo&
+  setFinalBlock(optional<name::Component> finalBlockId);
+
+  /** @brief return FinalBlockId
+   *  @deprecated use @c getFinalBlock
+   *
+   *  If FinalBlockId element is omitted, returns a default-constructed @c name::Component.
+   *  This is indistinguishable from having an empty GenericNameComponent as FinalBlockId.
+   */
+  NDN_CXX_DEPRECATED
+  name::Component
+  getFinalBlockId() const
+  {
+    return getFinalBlock().value_or(name::Component());
+  }
+
+  /** @brief set FinalBlockId
+   *  @deprecated use @c setFinalBlock
+   *
+   *  Passing a default-constructed @c name::Component removes FinalBlockId element.
+   *  This API does not support adding an empty GenericNameComponent as FinalBlockId.
+   */
+  NDN_CXX_DEPRECATED
   MetaInfo&
   setFinalBlockId(const name::Component& finalBlockId);
 
@@ -117,7 +161,7 @@
    *
    * @note Warning: Experimental API, which may change or disappear in the future
    *
-   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
+   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock
    *       is called before *AppMetaInfo, all app-defined blocks will be lost
    */
   const std::list<Block>&
@@ -133,7 +177,7 @@
    *
    * @note Warning: Experimental API, which may change or disappear in the future
    *
-   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
+   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock
    *       is called before *AppMetaInfo, all app-defined blocks will be lost
    */
   MetaInfo&
@@ -147,7 +191,7 @@
    *
    * @note Warning: Experimental API, which may change or disappear in the future
    *
-   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
+   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock
    *       is called before *AppMetaInfo, all app-defined blocks will be lost
    */
   MetaInfo&
@@ -160,7 +204,7 @@
    *
    * @note Warning: Experimental API, which may change or disappear in the future
    *
-   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
+   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock
    *       is called before *AppMetaInfo, all app-defined blocks will be lost
    */
   bool
@@ -176,7 +220,7 @@
    *
    * @note Warning: Experimental API, which may change or disappear in the future
    *
-   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlockId
+   * @note If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock
    *       is called before *AppMetaInfo, all app-defined blocks will be lost
    */
   const Block*
@@ -192,7 +236,7 @@
 private:
   uint32_t m_type;
   time::milliseconds m_freshnessPeriod;
-  name::Component m_finalBlockId;
+  optional<name::Component> m_finalBlockId;
   std::list<Block> m_appMetaInfo;
 
   mutable Block m_wire;
@@ -203,24 +247,6 @@
 std::ostream&
 operator<<(std::ostream& os, const MetaInfo& info);
 
-inline uint32_t
-MetaInfo::getType() const
-{
-  return m_type;
-}
-
-inline const time::milliseconds&
-MetaInfo::getFreshnessPeriod() const
-{
-  return m_freshnessPeriod;
-}
-
-inline const name::Component&
-MetaInfo::getFinalBlockId() const
-{
-  return m_finalBlockId;
-}
-
 inline bool
 MetaInfo::operator==(const MetaInfo& other) const
 {
diff --git a/src/mgmt/dispatcher.cpp b/src/mgmt/dispatcher.cpp
index df27aca..2a14a91 100644
--- a/src/mgmt/dispatcher.cpp
+++ b/src/mgmt/dispatcher.cpp
@@ -313,7 +313,7 @@
 
   MetaInfo metaInfo;
   if (isFinalBlock) {
-    metaInfo.setFinalBlockId(dataName[-1]);
+    metaInfo.setFinalBlock(dataName[-1]);
   }
 
   sendData(dataName, content, metaInfo, destination, imsFresh);
diff --git a/src/security/v2/certificate-bundle-fetcher.cpp b/src/security/v2/certificate-bundle-fetcher.cpp
index e2fdab9..45a0c38 100644
--- a/src/security/v2/certificate-bundle-fetcher.cpp
+++ b/src/security/v2/certificate-bundle-fetcher.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).
  *
@@ -160,9 +160,9 @@
   else {
     state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
 
-    const name::Component& finalBlockId = bundleData.getMetaInfo().getFinalBlockId();
-    if (!finalBlockId.empty()) {
-      state->setTag(make_shared<FinalBlockIdTag>(finalBlockId));
+    const auto& finalBlockId = bundleData.getFinalBlock();
+    if (!finalBlockId) {
+      state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
     }
 
     Block bundleContent = bundleData.getContent();
diff --git a/src/util/segment-fetcher.cpp b/src/util/segment-fetcher.cpp
index b23b991..90cddaf 100644
--- a/src/util/segment-fetcher.cpp
+++ b/src/util/segment-fetcher.cpp
@@ -131,8 +131,8 @@
       m_buffer->write(reinterpret_cast<const char*>(data.getContent().value()),
                       data.getContent().value_size());
       afterSegmentValidated(data);
-      const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
-      if (finalBlockId.empty() || (finalBlockId > currentSegment)) {
+      const auto& finalBlockId = data.getFinalBlock();
+      if (!finalBlockId || (*finalBlockId > currentSegment)) {
         fetchNextSegment(origInterest, data.getName(), currentSegment.toSegment() + 1, self);
       }
       else {
diff --git a/tests/unit-tests/meta-info.t.cpp b/tests/unit-tests/meta-info.t.cpp
index 43935e3..9e04b78 100644
--- a/tests/unit-tests/meta-info.t.cpp
+++ b/tests/unit-tests/meta-info.t.cpp
@@ -22,6 +22,7 @@
 #include "meta-info.hpp"
 #include "data.hpp"
 
+#include "block-literal.hpp"
 #include "boost-test.hpp"
 
 namespace ndn {
@@ -29,79 +30,53 @@
 
 BOOST_AUTO_TEST_SUITE(TestMetaInfo)
 
-const uint8_t MetaInfo1[] = {0x14, 0x04, 0x19, 0x02, 0x27, 0x10};
-const uint8_t MetaInfo2[] = {0x14, 0x14, 0x19, 0x02, 0x27, 0x10, 0x1a, 0x0e, 0x08, 0x0c,
-                             0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77, 0x6f, 0x72, 0x6c,
-                             0x64, 0x21};
-const uint8_t MetaInfo3[] = {0x14, 0x17, 0x18, 0x01, 0x01, 0x19, 0x02, 0x27, 0x10, 0x1a,
-                             0x0e, 0x08, 0x0c, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x77,
-                             0x6f, 0x72, 0x6c, 0x64, 0x21};
-
-BOOST_AUTO_TEST_CASE(Encode)
+BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(EncodeDecodeEquality, 1)
+BOOST_AUTO_TEST_CASE(EncodeDecodeEquality)
 {
-  MetaInfo meta;
-  meta.setType(tlv::ContentType_Blob);
-  meta.setFreshnessPeriod(10_s);
+  // default values
+  MetaInfo a("1406 type=180100 freshness=190100"_block);
+  BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 0_ms);
+  BOOST_CHECK(!a.getFinalBlock());
+  BOOST_CHECK_EQUAL(a.getFinalBlockId(), name::Component());
+  BOOST_CHECK_EQUAL(a, a);
 
-  BOOST_REQUIRE_NO_THROW(meta.wireEncode());
-  BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo1, MetaInfo1+sizeof(MetaInfo1),
-                                  meta.wireEncode().begin(), meta.wireEncode().end());
-
-  meta.setFinalBlockId(name::Component("hello,world!"));
-  BOOST_REQUIRE_NO_THROW(meta.wireEncode());
-  BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo2, MetaInfo2+sizeof(MetaInfo2),
-                                  meta.wireEncode().begin(), meta.wireEncode().end());
-
-  meta.setType(tlv::ContentType_Link);
-  BOOST_REQUIRE_NO_THROW(meta.wireEncode());
-  BOOST_REQUIRE_EQUAL_COLLECTIONS(MetaInfo3, MetaInfo3+sizeof(MetaInfo3),
-                                  meta.wireEncode().begin(), meta.wireEncode().end());
-}
-
-BOOST_AUTO_TEST_CASE(Decode)
-{
-  MetaInfo meta(Block(MetaInfo1, sizeof(MetaInfo1)));
-  BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(tlv::ContentType_Blob));
-  BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), 10_s);
-  BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component());
-
-  meta.wireDecode(Block(MetaInfo2, sizeof(MetaInfo2)));
-  BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(tlv::ContentType_Blob));
-  BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), 10_s);
-  BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
-
-  meta.wireDecode(Block(MetaInfo3, sizeof(MetaInfo3)));
-  BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(tlv::ContentType_Link));
-  BOOST_CHECK_EQUAL(meta.getFreshnessPeriod(), 10_s);
-  BOOST_CHECK_EQUAL(meta.getFinalBlockId(), name::Component("hello,world!"));
-}
-
-BOOST_AUTO_TEST_CASE(EqualityChecks)
-{
-  MetaInfo a;
   MetaInfo b;
-  BOOST_CHECK_EQUAL(a == b, true);
-  BOOST_CHECK_EQUAL(a != b, false);
+  BOOST_CHECK_NE(a, b);
+  b.setType(a.getType());
+  b.setFreshnessPeriod(a.getFreshnessPeriod());
+  b.setFinalBlock(a.getFinalBlock());
+  BOOST_CHECK(b.wireEncode() == "1400"_block);
+  BOOST_CHECK_EQUAL(a, b); // expected failure #4569
 
-  a.setFreshnessPeriod(10_s);
-  BOOST_CHECK_EQUAL(a == b, false);
-  BOOST_CHECK_EQUAL(a != b, true);
+  // non-default values
+  Block wire2 = "140C type=180101 freshness=190266B2 finalblock=1A03080141"_block;
+  a.wireDecode(wire2);
+  BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Link);
+  BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 26290_ms);
+  BOOST_CHECK_EQUAL(*a.getFinalBlock(), name::Component("A"));
+  BOOST_CHECK_EQUAL(a.getFinalBlockId(), name::Component("A"));
+  BOOST_CHECK_NE(a, b);
 
-  b.setFreshnessPeriod(90_s);
-  BOOST_CHECK_EQUAL(a == b, false);
-  BOOST_CHECK_EQUAL(a != b, true);
+  b.setType(a.getType());
+  b.setFreshnessPeriod(a.getFreshnessPeriod());
+  b.setFinalBlockId(a.getFinalBlockId());
+  BOOST_CHECK(b.wireEncode() == wire2);
+  BOOST_CHECK_EQUAL(a, b);
 
-  b.setFreshnessPeriod(10_s);
-  BOOST_CHECK_EQUAL(a == b, true);
-  BOOST_CHECK_EQUAL(a != b, false);
+  // FinalBlockId is typed name component
+  Block wire3 = "1405 finalblock=1A03DD0141"_block;
+  a.wireDecode(wire3);
+  BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 0_ms);
+  BOOST_CHECK_EQUAL(*a.getFinalBlock(), name::Component::fromEscapedString("221=A"));
+  BOOST_CHECK_NE(a, b);
 
-  a.setType(10);
-  BOOST_CHECK_EQUAL(a == b, false);
-  BOOST_CHECK_EQUAL(a != b, true);
-
-  b.setType(10);
-  BOOST_CHECK_EQUAL(a == b, true);
-  BOOST_CHECK_EQUAL(a != b, false);
+  b.setType(a.getType());
+  b.setFreshnessPeriod(a.getFreshnessPeriod());
+  b.setFinalBlockId(a.getFinalBlockId());
+  BOOST_CHECK(b.wireEncode() == wire3);
+  BOOST_CHECK_EQUAL(a, b);
 }
 
 BOOST_AUTO_TEST_CASE(AppMetaInfo)
@@ -109,7 +84,7 @@
   MetaInfo info1;
   info1.setType(196);
   info1.setFreshnessPeriod(3600_ms);
-  info1.setFinalBlockId(name::Component("/att/final"));
+  info1.setFinalBlock(name::Component("/att/final"));
 
   uint32_t ints[5] = {128, 129, 130, 131, 132};
   std::string ss[5] = {"h", "hello", "hello, world", "hello, world, alex",
@@ -188,56 +163,6 @@
   BOOST_CHECK_THROW(info.addAppMetaInfo(makeNonNegativeIntegerBlock(253, 1000)), MetaInfo::Error);
 }
 
-BOOST_AUTO_TEST_CASE(EncodeDecodeFreshnessPeriod)
-{
-  const uint8_t expectedDefault[] = {
-    0x14, 0x00, // MetaInfo
-  };
-
-  const uint8_t expected1000ms[] = {
-    0x14, 0x04, // MetaInfo
-          0x19, 0x02, // FreshnessPeriod
-                0x03, 0xe8 // 1000ms
-  };
-
-  MetaInfo info;
-  BOOST_CHECK_EQUAL_COLLECTIONS(info.wireEncode().begin(), info.wireEncode().end(),
-                                expectedDefault, expectedDefault + sizeof(expectedDefault));
-
-  info.setFreshnessPeriod(time::milliseconds::zero());
-  BOOST_CHECK_EQUAL_COLLECTIONS(info.wireEncode().begin(), info.wireEncode().end(),
-                                expectedDefault, expectedDefault + sizeof(expectedDefault));
-
-  info.setFreshnessPeriod(1000_ms);
-  BOOST_CHECK_EQUAL_COLLECTIONS(info.wireEncode().begin(), info.wireEncode().end(),
-                                expected1000ms, expected1000ms + sizeof(expected1000ms));
-
-  const uint8_t inputDefault[] = {
-    0x14, 0x03, // MetaInfo
-          0x19, 0x01, // FreshnessPeriod
-                0x00  // 0ms
-  };
-
-  const uint8_t input2000ms[] = {
-    0x14, 0x04, // MetaInfo
-          0x19, 0x02, // FreshnessPeriod
-                0x07, 0xd0 // 2000ms
-  };
-
-  Block inputDefaultBlock(inputDefault, sizeof(inputDefault));
-  BOOST_CHECK_NO_THROW(info.wireDecode(inputDefaultBlock));
-  BOOST_CHECK_EQUAL(info.getFreshnessPeriod(), time::milliseconds::zero());
-
-  Block input2000msBlock(input2000ms, sizeof(input2000ms));
-  BOOST_CHECK_NO_THROW(info.wireDecode(input2000msBlock));
-  BOOST_CHECK_EQUAL(info.getFreshnessPeriod(), 2000_ms);
-
-  BOOST_CHECK_NO_THROW(info.setFreshnessPeriod(10000_ms));
-  BOOST_CHECK_EQUAL(info.getFreshnessPeriod(), 10000_ms);
-  BOOST_CHECK_THROW(info.setFreshnessPeriod(time::milliseconds(-1)), std::invalid_argument);
-  BOOST_CHECK_EQUAL(info.getFreshnessPeriod(), 10000_ms);
-}
-
 BOOST_AUTO_TEST_SUITE_END() // TestMetaInfo
 
 } // namespace tests
diff --git a/tests/unit-tests/mgmt/nfd/status-dataset.t.cpp b/tests/unit-tests/mgmt/nfd/status-dataset.t.cpp
index 2abbdaa..12a7fa1 100644
--- a/tests/unit-tests/mgmt/nfd/status-dataset.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/status-dataset.t.cpp
@@ -98,7 +98,7 @@
     }
 
     auto data = make_shared<Data>(name);
-    data->setFinalBlockId(data->getName()[-1]);
+    data->setFinalBlock(name[-1]);
     return data;
   }
 };
diff --git a/tests/unit-tests/security/v2/certificate-bundle-fetcher.t.cpp b/tests/unit-tests/security/v2/certificate-bundle-fetcher.t.cpp
index f9bc22c..d2e0565 100644
--- a/tests/unit-tests/security/v2/certificate-bundle-fetcher.t.cpp
+++ b/tests/unit-tests/security/v2/certificate-bundle-fetcher.t.cpp
@@ -128,7 +128,7 @@
   certBundle->setName(bundleName);
   certBundle->setFreshnessPeriod(100_s);
   certBundle->setContent(certList);
-  certBundle->setFinalBlockId(name::Component::fromSegment(1));
+  certBundle->setFinalBlock(name::Component::fromSegment(1));
 
   m_keyChain.sign(*certBundle, signingWithSha256());
 
diff --git a/tests/unit-tests/util/segment-fetcher.t.cpp b/tests/unit-tests/util/segment-fetcher.t.cpp
index edcb9ca..c4d6bb8 100644
--- a/tests/unit-tests/util/segment-fetcher.t.cpp
+++ b/tests/unit-tests/util/segment-fetcher.t.cpp
@@ -55,7 +55,7 @@
     auto data = make_shared<Data>(Name(baseName).appendSegment(segment));
     data->setContent(buffer, sizeof(buffer));
     if (isFinal) {
-      data->setFinalBlockId(data->getName()[-1]);
+      data->setFinalBlock(data->getName()[-1]);
     }
 
     return signData(data);