name: convert to span

Change-Id: I805936731948732114762d0d022d1b447622788d
diff --git a/ndn-cxx/data.cpp b/ndn-cxx/data.cpp
index a54458c..35031ac 100644
--- a/ndn-cxx/data.cpp
+++ b/ndn-cxx/data.cpp
@@ -211,7 +211,7 @@
       NDN_THROW(Error("Cannot compute full name because Data has no wire encoding (not signed)"));
     }
     m_fullName = m_name;
-    m_fullName.appendImplicitSha256Digest(util::Sha256::computeDigest(m_wire.wire(), m_wire.size()));
+    m_fullName.appendImplicitSha256Digest(util::Sha256::computeDigest({m_wire.wire(), m_wire.size()}));
   }
 
   return m_fullName;
diff --git a/ndn-cxx/encoding/block.cpp b/ndn-cxx/encoding/block.cpp
index 56a1477..4b2992a 100644
--- a/ndn-cxx/encoding/block.cpp
+++ b/ndn-cxx/encoding/block.cpp
@@ -111,7 +111,7 @@
   }
 }
 
-Block::Block(const Block& block, Buffer::const_iterator begin, Buffer::const_iterator end,
+Block::Block(const Block& block, Block::const_iterator begin, Block::const_iterator end,
              bool verifyLength)
   : Block(block.m_buffer, begin, end, verifyLength)
 {
@@ -274,7 +274,7 @@
   m_begin = m_end = m_valueBegin = m_valueEnd = {};
 }
 
-Buffer::const_iterator
+Block::const_iterator
 Block::begin() const
 {
   if (!hasWire())
@@ -283,7 +283,7 @@
   return m_begin;
 }
 
-Buffer::const_iterator
+Block::const_iterator
 Block::end() const
 {
   if (!hasWire())
@@ -475,6 +475,13 @@
   m_elements.push_back(element);
 }
 
+void
+Block::push_back(Block&& element)
+{
+  resetWire();
+  m_elements.push_back(std::move(element));
+}
+
 Block::element_iterator
 Block::insert(Block::element_const_iterator pos, const Block& element)
 {
@@ -515,7 +522,7 @@
   }
   else if (block.value_size() > 0) {
     os << block.type() << '[' << block.value_size() << "]=";
-    printHex(os, block.value(), block.value_size(), true);
+    printHex(os, {block.value(), block.value_size()}, true);
   }
   else {
     os << block.type() << "[empty]";
diff --git a/ndn-cxx/encoding/block.hpp b/ndn-cxx/encoding/block.hpp
index 9da1946..34b9619 100644
--- a/ndn-cxx/encoding/block.hpp
+++ b/ndn-cxx/encoding/block.hpp
@@ -44,6 +44,8 @@
 class Block
 {
 public:
+  using value_type             = Buffer::value_type;
+  using const_iterator         = Buffer::const_iterator;
   using element_container      = std::vector<Block>;
   using element_iterator       = element_container::iterator;
   using element_const_iterator = element_container::const_iterator;
@@ -121,7 +123,7 @@
    *  @throw std::invalid_argument [@p begin,@p end) range is not within @p block
    *  @throw tlv::Error Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE
    */
-  Block(const Block& block, Buffer::const_iterator begin, Buffer::const_iterator end,
+  Block(const Block& block, Block::const_iterator begin, Block::const_iterator end,
         bool verifyLength = true);
 
   /** @brief Create a Block from a wire Buffer without parsing
@@ -141,7 +143,7 @@
    *  @param bufSize size of the raw buffer; may be greater than the actual size of the TLV element
    *  @throw tlv::Error Type-Length parsing fails, or size of TLV-VALUE exceeds @p bufSize
    *  @note This constructor copies the TLV element octets to an internal buffer.
-   *  @deprecated
+   *  @deprecated Use Block(span<const uint8_t>)
    */
   [[deprecated("use the constructor that takes a span<>")]]
   Block(const uint8_t* buf, size_t bufSize);
@@ -246,13 +248,13 @@
   /** @brief Get begin iterator of encoded wire
    *  @pre `hasWire() == true`
    */
-  Buffer::const_iterator
+  const_iterator
   begin() const;
 
   /** @brief Get end iterator of encoded wire
    *  @pre `hasWire() == true`
    */
-  Buffer::const_iterator
+  const_iterator
   end() const;
 
   /** @brief Return a raw pointer to the beginning of the encoded wire
@@ -303,7 +305,7 @@
   /** @brief Get begin iterator of TLV-VALUE
    *  @pre `hasValue() == true`
    */
-  Buffer::const_iterator
+  const_iterator
   value_begin() const
   {
     return m_valueBegin;
@@ -312,7 +314,7 @@
   /** @brief Get end iterator of TLV-VALUE
    *  @pre `hasValue() == true`
    */
-  Buffer::const_iterator
+  const_iterator
   value_end() const
   {
     return m_valueEnd;
@@ -382,11 +384,18 @@
   element_iterator
   erase(element_const_iterator first, element_const_iterator last);
 
-  /** @brief Append a sub-element
+  /**
+   * @brief Append a sub-element.
    */
   void
   push_back(const Block& element);
 
+  /**
+   * @brief Append a sub-element.
+   */
+  void
+  push_back(Block&& element);
+
   /** @brief Insert a sub-element
    *  @param pos position of the new sub-element
    *  @param element new sub-element to insert
diff --git a/ndn-cxx/impl/name-component-types.hpp b/ndn-cxx/impl/name-component-types.hpp
index 0ca8bdf..81b8b8e 100644
--- a/ndn-cxx/impl/name-component-types.hpp
+++ b/ndn-cxx/impl/name-component-types.hpp
@@ -109,11 +109,12 @@
   }
 
 protected:
-  /** \brief Calculate the successor of \p comp, extending TLV-LENGTH if value overflows.
-   *  \return whether TLV-LENGTH was extended, and the successor
+  /**
+   * \brief Calculate the successor of \p comp, extending TLV-LENGTH if value overflows.
+   * \return whether TLV-LENGTH was extended, and the successor
    */
-  std::tuple<bool, Block>
-  getSuccessorImpl(const Component& comp) const
+  static std::tuple<bool, Block>
+  getSuccessorImpl(const Component& comp)
   {
     EncodingBuffer encoder(comp.size() + 9, 9);
     // leave room for additional byte when TLV-VALUE overflows, and for TLV-LENGTH size increase
@@ -137,10 +138,11 @@
     return {isOverflow, encoder.block()};
   }
 
-  /** \brief Write TLV-VALUE as `<escaped-value>` of NDN URI syntax.
+  /**
+   * \brief Write TLV-VALUE as `<escaped-value>` of NDN URI syntax.
    */
-  void
-  writeUriEscapedValue(std::ostream& os, const Component& comp) const
+  static void
+  writeUriEscapedValue(std::ostream& os, const Component& comp)
   {
     bool isAllPeriods = std::all_of(comp.value_begin(), comp.value_end(),
                                     [] (uint8_t x) { return x == '.'; });
@@ -241,14 +243,14 @@
     catch (const StringHelperError&) {
       NDN_THROW(Error("Cannot convert to " + m_typeName + " (invalid hex encoding)"));
     }
-    return Component(m_type, std::move(value));
+    return {m_type, std::move(value)};
   }
 
   void
   writeUri(std::ostream& os, const Component& comp) const final
   {
     os << m_uriPrefix << '=';
-    printHex(os, comp.value(), comp.value_size(), false);
+    printHex(os, {comp.value(), comp.value_size()}, false);
   }
 
 private:
diff --git a/ndn-cxx/key-locator.cpp b/ndn-cxx/key-locator.cpp
index 0d35dc9..61659b5 100644
--- a/ndn-cxx/key-locator.cpp
+++ b/ndn-cxx/key-locator.cpp
@@ -201,7 +201,7 @@
     },
     [&] (const Block& digest) {
       os << "KeyDigest=";
-      printHex(os, digest.value(), std::min(digest.value_size(), MAX_KEY_DIGEST_OCTETS_TO_SHOW));
+      printHex(os, {digest.value(), std::min(digest.value_size(), MAX_KEY_DIGEST_OCTETS_TO_SHOW)});
       if (digest.value_size() > MAX_KEY_DIGEST_OCTETS_TO_SHOW) {
         os << "...";
       }
diff --git a/ndn-cxx/name-component.cpp b/ndn-cxx/name-component.cpp
index 61c3afe..6fb973d 100644
--- a/ndn-cxx/name-component.cpp
+++ b/ndn-cxx/name-component.cpp
@@ -169,9 +169,9 @@
     if (value.size() < 3) {
       NDN_THROW(Component::Error("Illegal URI (name component cannot be . or ..)"));
     }
-    return Component(type, reinterpret_cast<const uint8_t*>(value.data()), value.size() - 3);
+    return Component(type, {reinterpret_cast<const uint8_t*>(value.data()), value.size() - 3});
   }
-  return Component(type, reinterpret_cast<const uint8_t*>(value.data()), value.size());
+  return Component(type, {reinterpret_cast<const uint8_t*>(value.data()), value.size()});
 }
 
 Component
@@ -513,7 +513,7 @@
 
   uint32_t type = this->type() + 1;
   auto value = detail::getComponentTypeTable().get(type).getMinValue();
-  return Component(type, value.data(), value.size());
+  return {type, value};
 }
 
 template<encoding::Tag TAG>
diff --git a/ndn-cxx/name-component.hpp b/ndn-cxx/name-component.hpp
index dde0ae8..47ad17d 100644
--- a/ndn-cxx/name-component.hpp
+++ b/ndn-cxx/name-component.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -152,12 +152,12 @@
   }
 
   /**
-   * @brief Construct a NameComponent of TLV-TYPE @p type, copying TLV-VALUE from @p buffer.
+   * @brief Construct a NameComponent of TLV-TYPE @p type, copying the TLV-VALUE from @p value.
    */
-  Component(uint32_t type, span<const uint8_t> buffer);
+  Component(uint32_t type, span<const uint8_t> value);
 
   /**
-   * @brief Construct a GenericNameComponent, copying TLV-VALUE from @p buffer.
+   * @brief Construct a GenericNameComponent, copying the TLV-VALUE from @p buffer.
    */
   explicit
   Component(span<const uint8_t> buffer)
@@ -168,7 +168,9 @@
   /**
    * @brief Construct a NameComponent of TLV-TYPE @p type, copying @p count bytes at @p value as
    *        TLV-VALUE.
+   * @deprecated Use Component(uint32_t, span<const uint8_t>)
    */
+  [[deprecated("use the constructor that takes a span<>")]]
   Component(uint32_t type, const uint8_t* value, size_t count)
     : Component(type, {value, count})
   {
@@ -176,7 +178,9 @@
 
   /**
    * @brief Construct a GenericNameComponent, copying @p count bytes at @p value as TLV-VALUE.
+   * @deprecated Use Component(span<const uint8_t>)
    */
+  [[deprecated("use the constructor that takes a span<>")]]
   Component(const uint8_t* value, size_t count)
     : Component(tlv::GenericNameComponent, {value, count})
   {
diff --git a/ndn-cxx/name.cpp b/ndn-cxx/name.cpp
index 43f9725..ec64e14 100644
--- a/ndn-cxx/name.cpp
+++ b/ndn-cxx/name.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -170,15 +170,15 @@
 const name::Component&
 Name::at(ssize_t i) const
 {
+  auto ssize = static_cast<ssize_t>(size());
+  if (i < -ssize || i >= ssize) {
+    NDN_THROW(Error("Component at offset " + to_string(i) + " does not exist (out of bounds)"));
+  }
+
   if (i < 0) {
-    i += static_cast<ssize_t>(size());
+    i += ssize;
   }
-
-  if (i < 0 || static_cast<size_t>(i) >= size()) {
-    NDN_THROW(Error("Requested component does not exist (out of bounds)"));
-  }
-
-  return reinterpret_cast<const Component&>(m_wire.elements()[i]);
+  return static_cast<const Component&>(m_wire.elements()[static_cast<size_t>(i)]);
 }
 
 PartialName
@@ -261,8 +261,7 @@
 Name&
 Name::appendParametersSha256DigestPlaceholder()
 {
-  static const Component placeholder(tlv::ParametersSha256DigestComponent,
-                                     SHA256_OF_EMPTY_STRING, sizeof(SHA256_OF_EMPTY_STRING));
+  static const Component placeholder(tlv::ParametersSha256DigestComponent, SHA256_OF_EMPTY_STRING);
   return append(placeholder);
 }
 
diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp
index 49a86f9..3265f7d 100644
--- a/ndn-cxx/name.hpp
+++ b/ndn-cxx/name.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -168,7 +168,7 @@
     if (i < 0) {
       i += static_cast<ssize_t>(size());
     }
-    return reinterpret_cast<const Component&>(m_wire.elements()[i]);
+    return static_cast<const Component&>(m_wire.elements()[static_cast<size_t>(i)]);
   }
 
   /** @brief Equivalent to `get(i)`.
@@ -292,23 +292,38 @@
     return *this;
   }
 
-  /** @brief Append a NameComponent of TLV-TYPE @p type, copying @p count bytes at @p value as
-   *         TLV-VALUE.
-   *  @return a reference to this name, to allow chaining.
+  /**
+   * @brief Append a NameComponent of TLV-TYPE @p type, copying the TLV-VALUE from @p value.
+   * @return a reference to this name, to allow chaining.
    */
   Name&
+  append(uint32_t type, span<const uint8_t> value)
+  {
+    return append(Component(type, value));
+  }
+
+  /**
+   * @brief Append a NameComponent of TLV-TYPE @p type, copying @p count bytes at @p value as TLV-VALUE.
+   * @return a reference to this name, to allow chaining.
+   * @deprecated Use append(uint32_t, span<const uint8_t>)
+   */
+  [[deprecated("use the overload that takes a span<>")]]
+  Name&
   append(uint32_t type, const uint8_t* value, size_t count)
   {
-    return append(Component(type, value, count));
+    return append(Component(type, make_span(value, count)));
   }
 
-  /** @brief Append a GenericNameComponent, copying @p count bytes at @p value as TLV-VALUE.
-   *  @return a reference to this name, to allow chaining.
+  /**
+   * @brief Append a GenericNameComponent, copying @p count bytes at @p value as TLV-VALUE.
+   * @return a reference to this name, to allow chaining.
+   * @deprecated Use append(uint32_t, span<const uint8_t>) or append(const Component&)
    */
+  [[deprecated]]
   Name&
   append(const uint8_t* value, size_t count)
   {
-    return append(Component(value, count));
+    return append(Component(make_span(value, count)));
   }
 
   /** @brief Append a NameComponent of TLV-TYPE @p type, copying TLV-VALUE from a range.
diff --git a/ndn-cxx/util/sha256.cpp b/ndn-cxx/util/sha256.cpp
index 3de1b85..d24e8d1 100644
--- a/ndn-cxx/util/sha256.cpp
+++ b/ndn-cxx/util/sha256.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -88,40 +88,39 @@
 Sha256&
 Sha256::operator<<(Sha256& src)
 {
-  auto buf = src.computeDigest();
-  update(buf->data(), buf->size());
+  update(*src.computeDigest());
   return *this;
 }
 
 Sha256&
 Sha256::operator<<(const std::string& str)
 {
-  update(reinterpret_cast<const uint8_t*>(str.data()), str.size());
+  update({reinterpret_cast<const uint8_t*>(str.data()), str.size()});
   return *this;
 }
 
 Sha256&
 Sha256::operator<<(const Block& block)
 {
-  update(block.wire(), block.size());
+  update({block.wire(), block.size()});
   return *this;
 }
 
 Sha256&
 Sha256::operator<<(uint64_t value)
 {
-  update(reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t));
+  update({reinterpret_cast<const uint8_t*>(&value), sizeof(uint64_t)});
   return *this;
 }
 
 void
-Sha256::update(const uint8_t* buffer, size_t size)
+Sha256::update(span<const uint8_t> buffer)
 {
   if (m_isFinalized)
     NDN_THROW(Error("Digest has been already finalized"));
 
   BOOST_ASSERT(m_input != nullptr);
-  m_input->write({buffer, size});
+  m_input->write(buffer);
   m_isEmpty = false;
 }
 
@@ -133,10 +132,10 @@
 }
 
 ConstBufferPtr
-Sha256::computeDigest(const uint8_t* buffer, size_t size)
+Sha256::computeDigest(span<const uint8_t> buffer)
 {
   Sha256 sha256;
-  sha256.update(buffer, size);
+  sha256.update(buffer);
   return sha256.computeDigest();
 }
 
diff --git a/ndn-cxx/util/sha256.hpp b/ndn-cxx/util/sha256.hpp
index 5a42add..745e706 100644
--- a/ndn-cxx/util/sha256.hpp
+++ b/ndn-cxx/util/sha256.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -140,13 +140,18 @@
   operator<<(uint64_t value);
 
   /**
-   * @brief Add a raw buffer to the digest calculation.
-   * @param buffer the input buffer
-   * @param size the size of the input buffer
+   * @brief Add a byte buffer to the digest calculation.
    * @throw Error the digest has already been finalized
    */
   void
-  update(const uint8_t* buffer, size_t size);
+  update(span<const uint8_t> buffer);
+
+  [[deprecated("use the overload that takes a span<>")]]
+  void
+  update(const uint8_t* buffer, size_t size)
+  {
+    update({buffer, size});
+  }
 
   /**
    * @brief Convert digest to std::string.
@@ -157,12 +162,17 @@
 
   /**
    * @brief Stateless SHA-256 digest calculation.
-   * @param buffer the input buffer
-   * @param size the size of the input buffer
    * @return SHA-256 digest of the input buffer
    */
   static ConstBufferPtr
-  computeDigest(const uint8_t* buffer, size_t size);
+  computeDigest(span<const uint8_t> buffer);
+
+  [[deprecated("use the overload that takes a span<>")]]
+  static ConstBufferPtr
+  computeDigest(const uint8_t* buffer, size_t size)
+  {
+    return computeDigest({buffer, size});
+  }
 
 private:
   unique_ptr<security::transform::StepSource> m_input;
diff --git a/ndn-cxx/util/string-helper.hpp b/ndn-cxx/util/string-helper.hpp
index 29e7d67..1b08836 100644
--- a/ndn-cxx/util/string-helper.hpp
+++ b/ndn-cxx/util/string-helper.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -51,12 +51,16 @@
  * @param os Output stream
  * @param buffer Range of bytes to print in hexadecimal format
  * @param wantUpperCase if true (the default) print uppercase hex chars
+ *
+ * Each octet of input is always converted to two hex characters (e.g., "00" for octet==0).
+ * The output string is a continuous sequence of hex characters without any whitespace separators.
  */
 void
 printHex(std::ostream& os, span<const uint8_t> buffer, bool wantUpperCase = true);
 
 /**
  * @brief Output the hex representation of the bytes in @p buffer to the output stream @p os
+ * @deprecated
  *
  * @param os Output stream
  * @param buffer Pointer to an array of bytes
@@ -71,9 +75,9 @@
  * @endcode
  *
  * Each octet is always represented as two hex characters ("00" for octet==0).
- *
  * The output string is a continuous sequence of hex characters without any whitespace separators.
  */
+[[deprecated("use the overload that takes a span<>")]]
 inline void
 printHex(std::ostream& os, const uint8_t* buffer, size_t length, bool wantUpperCase = true)
 {
@@ -117,12 +121,16 @@
  *
  * @param buffer Range of bytes to convert to hexadecimal format
  * @param wantUpperCase if true (the default) use uppercase hex chars
+ *
+ * Each octet of input is always converted to two hex characters (e.g., "00" for octet==0).
+ * The output string is a continuous sequence of hex characters without any whitespace separators.
  */
 NDN_CXX_NODISCARD std::string
 toHex(span<const uint8_t> buffer, bool wantUpperCase = true);
 
 /**
  * @brief Return a string containing the hex representation of the bytes in @p buffer
+ * @deprecated
  *
  * @param buffer Pointer to an array of bytes
  * @param length Size of the array
@@ -136,9 +144,9 @@
  * @endcode
  *
  * Each octet is always represented as two hex characters ("00" for octet==0).
- *
  * The output string is a continuous sequence of hex characters without any whitespace separators.
  */
+[[deprecated("use the overload that takes a span<>")]]
 NDN_CXX_NODISCARD inline std::string
 toHex(const uint8_t* buffer, size_t length, bool wantUpperCase = true)
 {
diff --git a/tests/integration/face.cpp b/tests/integration/face.cpp
index 878b0cc..9357094 100644
--- a/tests/integration/face.cpp
+++ b/tests/integration/face.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -241,9 +241,9 @@
   int nRegSuccess = 0;
   std::set<Name> receivedInterests;
   this->face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
-    [&] (const InterestFilter&, const Interest& interest) { receivedInterests.insert(interest.getName()); },
-    [&] (const Name&) { ++nRegSuccess; },
-    [] (const Name&, const auto& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
+    [&] (auto&&, const auto& interest) { receivedInterests.insert(interest.getName()); },
+    [&] (auto&&) { ++nRegSuccess; },
+    [] (auto&&, const auto& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
 
   this->sched.schedule(700_ms, [] {
     std::string output = executeCommand("nfdc route list | grep /Hello/World");
@@ -258,8 +258,7 @@
   this->face.processEvents();
   BOOST_CHECK_EQUAL(nRegSuccess, 1);
   std::set<Name> expectedInterests{"/Hello/World/a/b", "/Hello/World/a/b/c"};
-  BOOST_CHECK_EQUAL_COLLECTIONS(receivedInterests.begin(), receivedInterests.end(),
-                                expectedInterests.begin(), expectedInterests.end());
+  BOOST_TEST(receivedInterests == expectedInterests, boost::test_tools::per_element());
 }
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(RegexFilterNoRegister, TransportType, Transports, FaceFixture<TransportType>)
diff --git a/tests/unit/data.t.cpp b/tests/unit/data.t.cpp
index 153c471..0a4c9b7 100644
--- a/tests/unit/data.t.cpp
+++ b/tests/unit/data.t.cpp
@@ -204,9 +204,7 @@
   }
   d.setSignatureValue(sig.buf());
 
-  Block dataBlock(d.wireEncode());
-  BOOST_CHECK_EQUAL_COLLECTIONS(DATA1, DATA1 + sizeof(DATA1),
-                                dataBlock.begin(), dataBlock.end());
+  BOOST_TEST(d.wireEncode() == DATA1, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_SUITE_END() // Encode
@@ -537,8 +535,12 @@
   BOOST_CHECK_EQUAL(d.hasContent(), true);
   BOOST_CHECK_EQUAL(d.getContent().type(), tlv::Content);
   BOOST_CHECK_EQUAL(d.getContent().value_size(), 0);
+
   // raw buffer overload (deprecated)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   BOOST_CHECK_THROW(d.setContent(nullptr, 1), std::invalid_argument);
+#pragma GCC diagnostic pop
 
   // ConstBufferPtr overload
   d.setContent(std::make_shared<Buffer>(direct, sizeof(direct)));
diff --git a/tests/unit/encoding/block.t.cpp b/tests/unit/encoding/block.t.cpp
index a39df87..e7c8bac 100644
--- a/tests/unit/encoding/block.t.cpp
+++ b/tests/unit/encoding/block.t.cpp
@@ -111,7 +111,6 @@
   };
 
   Block b1(buf);
-
   Block b2(b1, b1.begin(), b1.end());
   auto buf2 = b2.getBuffer();
 
@@ -120,9 +119,8 @@
   b1.encode();
 
   b2.parse();
-
-  BOOST_CHECK_EQUAL_COLLECTIONS(b2.begin(), b2.end(), buf, buf + sizeof(buf));
-  BOOST_CHECK_EQUAL(buf2, b2.getBuffer());
+  BOOST_TEST(b2 == buf, boost::test_tools::per_element());
+  BOOST_TEST(buf2 == b2.getBuffer()); // check pointers
 }
 
 BOOST_AUTO_TEST_CASE(FromBlockCopyOnWriteModifyCopy)
@@ -133,7 +131,6 @@
 
   Block b1(buf);
   auto buf1 = b1.getBuffer();
-
   Block b2(b1, b1.begin(), b1.end());
 
   b2.parse();
@@ -141,8 +138,8 @@
   b2.encode();
 
   b1.parse();
-  BOOST_CHECK_EQUAL_COLLECTIONS(b1.begin(), b1.end(), buf, buf + sizeof(buf));
-  BOOST_CHECK_EQUAL(buf1, b1.getBuffer());
+  BOOST_TEST(b1 == buf, boost::test_tools::per_element());
+  BOOST_TEST(buf1 == b1.getBuffer()); // check pointers
 }
 
 BOOST_AUTO_TEST_CASE(FromType)
diff --git a/tests/unit/ims/in-memory-storage.t.cpp b/tests/unit/ims/in-memory-storage.t.cpp
index 54ceeb0..3d9ff1e 100644
--- a/tests/unit/ims/in-memory-storage.t.cpp
+++ b/tests/unit/ims/in-memory-storage.t.cpp
@@ -270,7 +270,7 @@
 {
   shared_ptr<Data> data = makeData("/digest/compute");
 
-  ConstBufferPtr digest1 = util::Sha256::computeDigest(data->wireEncode().wire(), data->wireEncode().size());
+  auto digest1 = util::Sha256::computeDigest({data->wireEncode().wire(), data->wireEncode().size()});
   BOOST_CHECK_EQUAL(digest1->size(), 32);
 
   InMemoryStorageEntry entry;
@@ -368,7 +368,7 @@
   shared_ptr<Data> data7 = makeData("/c/c/1");
   ims.insert(*data7);
 
-  ConstBufferPtr digest1 = util::Sha256::computeDigest(data->wireEncode().wire(), data->wireEncode().size());
+  auto digest1 = util::Sha256::computeDigest({data->wireEncode().wire(), data->wireEncode().size()});
 
   Name name("/a");
   ims.erase(name);
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 903d9bb..495d036 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -86,7 +86,7 @@
   BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
 
   Block wire1 = i1.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(wire1 == WIRE, boost::test_tools::per_element());
 
   Interest i2(wire1);
   BOOST_CHECK_EQUAL(i2.getName(), "/local/ndn/prefix");
@@ -129,7 +129,7 @@
   BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
 
   Block wire1 = i1.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(wire1 == WIRE, boost::test_tools::per_element());
 
   Interest i2(wire1);
   BOOST_CHECK_EQUAL(i2.getName(),
@@ -186,7 +186,7 @@
   BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
 
   Block wire1 = i1.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(wire1 == WIRE, boost::test_tools::per_element());
 
   Interest i2(wire1);
   BOOST_CHECK_EQUAL(i2.getName(),
@@ -248,8 +248,7 @@
   BOOST_CHECK_EQUAL(i1.getNonce(), 0x4c1ecb4a);
   BOOST_CHECK_EQUAL(i1.getSignatureInfo()->getSignatureType(), tlv::DigestSha256);
   BOOST_CHECK(i1.getSignatureInfo()->getNonce() == nonce);
-  BOOST_CHECK_EQUAL_COLLECTIONS(i1.getSignatureValue().begin(), i1.getSignatureValue().end(),
-                                sv.begin(), sv.end());
+  BOOST_TEST(i1.getSignatureValue() == sv, boost::test_tools::per_element());
   BOOST_CHECK_EQUAL(i1.getApplicationParameters(), "2404C0C1C2C3"_block);
   BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
 
@@ -259,8 +258,7 @@
   i1.setCanBePrefix(false);
   BOOST_CHECK_EQUAL(i1.hasWire(), false);
 
-  Block wire1 = i1.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(i1.wireEncode() == WIRE, boost::test_tools::per_element());
 
   Interest i2("/local/ndn/prefix");
   i2.setMustBeFresh(true);
@@ -270,8 +268,7 @@
   i2.setSignatureValue(make_shared<Buffer>(sv.value(), sv.value_size()));
   BOOST_CHECK_EQUAL(i2.isParametersDigestValid(), true);
 
-  Block wire2 = i2.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire2.begin(), wire2.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(i2.wireEncode() == WIRE, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(SignedApplicationElements)
@@ -325,8 +322,7 @@
   BOOST_CHECK_EQUAL(i1.getNonce(), 0x4c1ecb4a);
   BOOST_CHECK_EQUAL(i1.getSignatureInfo()->getSignatureType(), tlv::DigestSha256);
   BOOST_CHECK(i1.getSignatureInfo()->getNonce() == nonce);
-  BOOST_CHECK_EQUAL_COLLECTIONS(i1.getSignatureValue().begin(), i1.getSignatureValue().end(),
-                                sv.begin(), sv.end());
+  BOOST_TEST(i1.getSignatureValue() == sv, boost::test_tools::per_element());
   BOOST_CHECK_EQUAL(i1.getApplicationParameters(), "2404C0C1C2C3"_block);
   BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
 
@@ -336,8 +332,7 @@
   i1.setCanBePrefix(false);
   BOOST_CHECK_EQUAL(i1.hasWire(), false);
 
-  Block wire1 = i1.wireEncode();
-  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+  BOOST_TEST(i1.wireEncode() == WIRE, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(MissingApplicationParameters)
@@ -888,8 +883,12 @@
   BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2401C1"_block);
   i.setApplicationParameters(span<uint8_t>{});
   BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2400"_block);
+
   // raw buffer+size overload (deprecated)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   BOOST_CHECK_THROW(i.setApplicationParameters(nullptr, 42), std::invalid_argument);
+#pragma GCC diagnostic pop
 
   // ConstBufferPtr overload
   i.setApplicationParameters(make_shared<Buffer>(PARAMETERS2, sizeof(PARAMETERS2)));
diff --git a/tests/unit/meta-info.t.cpp b/tests/unit/meta-info.t.cpp
index 87add29..56ad239 100644
--- a/tests/unit/meta-info.t.cpp
+++ b/tests/unit/meta-info.t.cpp
@@ -109,7 +109,7 @@
   // // These octets are obtained by the snippet below.
   // // This check is intended to detect unexpected encoding change in the future.
   // const Block& wire = info1.wireEncode();
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   const uint8_t METAINFO[] = {0x14, 0x77, 0x18, 0x01, 0xc4, 0x19, 0x02, 0x0e, 0x10, 0x1a, 0x0c,
diff --git a/tests/unit/metadata-object.t.cpp b/tests/unit/metadata-object.t.cpp
index 9606db7..3fd5d09 100644
--- a/tests/unit/metadata-object.t.cpp
+++ b/tests/unit/metadata-object.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -151,7 +151,7 @@
 
   // invalid keyword name component
   name = name.getPrefix(-3)
-         .append(tlv::KeywordNameComponent, reinterpret_cast<const uint8_t*>("foo"), std::strlen("foo"))
+         .append(tlv::KeywordNameComponent, {'f', 'o', 'o'})
          .appendVersion()
          .appendSegment(0);
   BOOST_CHECK_EQUAL(MetadataObject::isValidName(name), false);
diff --git a/tests/unit/mgmt/nfd/channel-status.t.cpp b/tests/unit/mgmt/nfd/channel-status.t.cpp
index 9b1a4fa..dc29def 100644
--- a/tests/unit/mgmt/nfd/channel-status.t.cpp
+++ b/tests/unit/mgmt/nfd/channel-status.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/channel-status.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -40,7 +41,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/mgmt/nfd/face-event-notification.t.cpp b/tests/unit/mgmt/nfd/face-event-notification.t.cpp
index 3354a1b..f1dfc38 100644
--- a/tests/unit/mgmt/nfd/face-event-notification.t.cpp
+++ b/tests/unit/mgmt/nfd/face-event-notification.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/face-event-notification.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -75,7 +76,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
@@ -120,7 +121,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
@@ -165,7 +166,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
@@ -210,7 +211,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/mgmt/nfd/face-query-filter.t.cpp b/tests/unit/mgmt/nfd/face-query-filter.t.cpp
index 3b32ac8..e46d6c1 100644
--- a/tests/unit/mgmt/nfd/face-query-filter.t.cpp
+++ b/tests/unit/mgmt/nfd/face-query-filter.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/face-query-filter.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -55,7 +56,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //  printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/mgmt/nfd/face-status.t.cpp b/tests/unit/mgmt/nfd/face-status.t.cpp
index a4ad4ac..405bf2c 100644
--- a/tests/unit/mgmt/nfd/face-status.t.cpp
+++ b/tests/unit/mgmt/nfd/face-status.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/face-status.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -64,7 +65,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/mgmt/nfd/forwarder-status.t.cpp b/tests/unit/mgmt/nfd/forwarder-status.t.cpp
index f899ce9..b4eb339 100644
--- a/tests/unit/mgmt/nfd/forwarder-status.t.cpp
+++ b/tests/unit/mgmt/nfd/forwarder-status.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/forwarder-status.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -61,7 +62,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/mgmt/nfd/strategy-choice.t.cpp b/tests/unit/mgmt/nfd/strategy-choice.t.cpp
index 1d8329b..94c30e8 100644
--- a/tests/unit/mgmt/nfd/strategy-choice.t.cpp
+++ b/tests/unit/mgmt/nfd/strategy-choice.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,7 @@
 #include "ndn-cxx/mgmt/nfd/strategy-choice.hpp"
 
 #include "tests/boost-test.hpp"
+
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -41,7 +42,7 @@
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  // for (auto it = wire.begin(); it != wire.end(); ++it) {
   //   printf("0x%02x, ", *it);
   // }
   static const uint8_t expected[] = {
diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp
index 4e8d104..165c3fc 100644
--- a/tests/unit/name.t.cpp
+++ b/tests/unit/name.t.cpp
@@ -236,13 +236,13 @@
   name.append(Component("Emid"));
   BOOST_CHECK_EQUAL(name.wireEncode(), "0706 0804456D6964"_block);
 
-  name.append(25042, reinterpret_cast<const uint8_t*>("P3"), 2);
+  name.append(25042, {'P', '3'});
   BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block);
 
-  name.append(reinterpret_cast<const uint8_t*>("."), 1);
+  name.append(Component(make_span<uint8_t>({'.'})));
   BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block);
 
-  std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
+  const std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
   name.append(16, v1.begin(), v1.end());
   BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
 
diff --git a/tests/unit/security/verification-helpers.t.cpp b/tests/unit/security/verification-helpers.t.cpp
index e3ecc86..d15f8f2 100644
--- a/tests/unit/security/verification-helpers.t.cpp
+++ b/tests/unit/security/verification-helpers.t.cpp
@@ -51,7 +51,7 @@
 //   auto print = [] (const std::string& name, const uint8_t* buf, size_t size) {
 //     std::cout << "  const Block " + name + "{{\n    ";
 
-//     std::string hex = toHex(buf, size);
+//     std::string hex = toHex({buf, size});
 
 //     for (size_t i = 0; i < hex.size(); i++) {
 //       if (i > 0 && i % 32 == 0)
diff --git a/tests/unit/util/exception.t.cpp b/tests/unit/util/exception.t.cpp
index 33884dc..49ac2ab 100644
--- a/tests/unit/util/exception.t.cpp
+++ b/tests/unit/util/exception.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -28,7 +28,7 @@
 
 namespace ndn {
 namespace exception {
-namespace test {
+namespace tests {
 
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_AUTO_TEST_SUITE(TestException)
@@ -106,6 +106,6 @@
 BOOST_AUTO_TEST_SUITE_END() // TestException
 BOOST_AUTO_TEST_SUITE_END() // Util
 
-} // namespace test
+} // namespace tests
 } // namespace exception
 } // namespace ndn
diff --git a/tests/unit/util/sha256.t.cpp b/tests/unit/util/sha256.t.cpp
index 3340204..ae4fea3 100644
--- a/tests/unit/util/sha256.t.cpp
+++ b/tests/unit/util/sha256.t.cpp
@@ -29,27 +29,27 @@
 
 namespace ndn {
 namespace util {
-namespace test {
+namespace tests {
 
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_AUTO_TEST_SUITE(TestSha256)
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
-  const uint8_t input[] = {0x01, 0x02, 0x03, 0x04};
+  const uint8_t buf[] = {0x01, 0x02, 0x03, 0x04};
+  auto input = make_span(buf);
   auto expected = fromHex("9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a");
 
   Sha256 statefulSha256;
   BOOST_CHECK_EQUAL(statefulSha256.empty(), true);
 
-  statefulSha256.update(input, 1);
-  statefulSha256.update(input + 1, 1);
-  statefulSha256.update(input + 2, 1);
-  statefulSha256.update(input + 3, 1);
+  statefulSha256.update(input.subspan(0, 1));
+  statefulSha256.update(input.subspan(1, 1));
+  statefulSha256.update(input.subspan(2, 1));
+  statefulSha256.update(input.subspan(3, 1));
   ConstBufferPtr digest = statefulSha256.computeDigest();
   BOOST_CHECK_EQUAL(digest->size(), Sha256::DIGEST_SIZE);
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(ConstructFromStream)
@@ -63,8 +63,7 @@
   BOOST_CHECK_EQUAL(sha.toString(), "315F5BDB76D078C43B8AC0064E4A0164612B1FCE77C869345BFC94C75894EDD3");
 
   ConstBufferPtr digest = sha.computeDigest();
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(Compare)
@@ -72,14 +71,13 @@
   const uint8_t origin[] = {0x01, 0x02, 0x03, 0x04};
 
   Sha256 digest1;
-  digest1.update(origin, sizeof(origin));
+  digest1.update(origin);
   digest1.computeDigest();
 
   Sha256 digest2;
-  digest2.update(origin, 1);
-  digest2.update(origin + 1, 1);
-  digest2.update(origin + 2, 1);
-  digest2.update(origin + 3, 1);
+  auto in = make_span(origin);
+  digest2.update(in.first(2));
+  digest2.update(in.last(2));
   digest2.computeDigest();
 
   BOOST_CHECK_EQUAL(digest1 == digest2, true);
@@ -98,8 +96,7 @@
   ConstBufferPtr digest = statefulSha256.computeDigest();
 
   BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(InsertionOperatorString)
@@ -112,8 +109,7 @@
   ConstBufferPtr digest = statefulSha256.computeDigest();
 
   BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(InsertionOperatorBlock)
@@ -138,8 +134,7 @@
   ConstBufferPtr digest = statefulSha256.computeDigest();
 
   BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(InsertionOperatorUint64t)
@@ -154,8 +149,7 @@
   ConstBufferPtr digest = statefulSha256.computeDigest();
 
   BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(Reset)
@@ -182,12 +176,10 @@
 
 BOOST_AUTO_TEST_CASE(StaticComputeDigest)
 {
-  const uint8_t input[] = {0x01, 0x02, 0x03, 0x04};
   auto expected = fromHex("9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a");
 
-  ConstBufferPtr digest = Sha256::computeDigest(input, sizeof(input));
-  BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
-                                digest->data(), digest->data() + digest->size());
+  ConstBufferPtr digest = Sha256::computeDigest({0x01, 0x02, 0x03, 0x04});
+  BOOST_TEST(*digest == *expected, boost::test_tools::per_element());
 }
 
 BOOST_AUTO_TEST_CASE(Print)
@@ -209,6 +201,6 @@
 BOOST_AUTO_TEST_SUITE_END() // TestSha256
 BOOST_AUTO_TEST_SUITE_END() // Util
 
-} // namespace test
+} // namespace tests
 } // namespace util
 } // namespace ndn
diff --git a/tests/unit/util/string-helper.t.cpp b/tests/unit/util/string-helper.t.cpp
index 8747301..a129c1a 100644
--- a/tests/unit/util/string-helper.t.cpp
+++ b/tests/unit/util/string-helper.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -35,7 +35,7 @@
 
 namespace ndn {
 namespace util {
-namespace test {
+namespace tests {
 
 using boost::test_tools::output_test_stream;
 
@@ -85,12 +85,12 @@
 
 BOOST_AUTO_TEST_CASE(ToHex)
 {
-  std::string test = "Hello, world!";
-  BOOST_CHECK_EQUAL(toHex(reinterpret_cast<const uint8_t*>(test.data()), test.size()),
+  const std::string test = "Hello, world!";
+  BOOST_CHECK_EQUAL(toHex({reinterpret_cast<const uint8_t*>(test.data()), test.size()}),
                     "48656C6C6F2C20776F726C6421");
-  BOOST_CHECK_EQUAL(toHex(reinterpret_cast<const uint8_t*>(test.data()), test.size(), false),
+  BOOST_CHECK_EQUAL(toHex({reinterpret_cast<const uint8_t*>(test.data()), test.size()}, false),
                     "48656c6c6f2c20776f726c6421");
-  BOOST_CHECK_EQUAL(toHex(nullptr, 0), "");
+  BOOST_CHECK_EQUAL(toHex({}), "");
 
   Buffer buffer(test.data(), test.size());
   BOOST_CHECK_EQUAL(toHex(buffer, false),  "48656c6c6f2c20776f726c6421");
@@ -99,13 +99,13 @@
 
 BOOST_AUTO_TEST_CASE(FromHex)
 {
-  BOOST_CHECK(*fromHex("") == Buffer{});
-  BOOST_CHECK(*fromHex("48656c6c6f2c20776f726c6421") ==
-              (std::vector<uint8_t>{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20,
-                                    0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21}));
-  BOOST_CHECK(*fromHex("012a3Bc4defAB5CdEF") ==
-              (std::vector<uint8_t>{0x01, 0x2a, 0x3b, 0xc4, 0xde,
-                                    0xfa, 0xb5, 0xcd, 0xef}));
+  BOOST_TEST(fromHex("")->empty());
+  const uint8_t expected1[] = {
+    0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21
+  };
+  BOOST_TEST(*fromHex("48656c6c6f2c20776f726c6421") == expected1, boost::test_tools::per_element());
+  const uint8_t expected2[] = {0x01, 0x2a, 0x3b, 0xc4, 0xde, 0xfa, 0xb5, 0xcd, 0xef};
+  BOOST_TEST(*fromHex("012a3Bc4defAB5CdEF") == expected2, boost::test_tools::per_element());
 
   BOOST_CHECK_THROW(fromHex("1"), StringHelperError);
   BOOST_CHECK_THROW(fromHex("zz"), StringHelperError);
@@ -209,6 +209,6 @@
 BOOST_AUTO_TEST_SUITE_END() // TestStringHelper
 BOOST_AUTO_TEST_SUITE_END() // Util
 
-} // namespace test
+} // namespace tests
 } // namespace util
 } // namespace ndn