encoding: provide FormattedOutputFunction for Block

refs #2225

Change-Id: Ie38539ff93293b3919789043b01e09b573fb619a
diff --git a/tests/unit-tests/data.t.cpp b/tests/unit-tests/data.t.cpp
index ccf4e5b..b7d49c3 100644
--- a/tests/unit-tests/data.t.cpp
+++ b/tests/unit-tests/data.t.cpp
@@ -273,9 +273,9 @@
 
   // modify then re-encode as v0.2 format
   d.setName("/E");
-  BOOST_CHECK(d.wireEncode() ==
-              "0630 0703080145 1400 1500 16031B0100 "
-              "1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76"_block);
+  BOOST_CHECK_EQUAL(d.wireEncode(),
+    "0630 0703080145 1400 1500 16031B0100 "
+    "1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76"_block);
 }
 
 BOOST_AUTO_TEST_CASE(Full)
@@ -293,9 +293,9 @@
 
   // modify then re-encode as v0.2 format
   d.setName("/E");
-  BOOST_CHECK(d.wireEncode() ==
-              "0630 0703080145 1400 1500 16031B0100 "
-              "1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76"_block);
+  BOOST_CHECK_EQUAL(d.wireEncode(),
+    "0630 0703080145 1400 1500 16031B0100 "
+    "1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76"_block);
 }
 
 BOOST_AUTO_TEST_CASE(CriticalElementOutOfOrder)
diff --git a/tests/unit-tests/delegation-list.t.cpp b/tests/unit-tests/delegation-list.t.cpp
index 7ae92ed..e2aada8 100644
--- a/tests/unit-tests/delegation-list.t.cpp
+++ b/tests/unit-tests/delegation-list.t.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).
  *
@@ -178,7 +178,7 @@
 
   EncodingBuffer encoder;
   dl.wireEncode(encoder);
-  BOOST_CHECK(encoder.block() == makeDelegationListBlock(tlv::ForwardingHint, {DEL1B, DEL2A}));
+  BOOST_CHECK_EQUAL(encoder.block(), makeDelegationListBlock(tlv::ForwardingHint, {DEL1B, DEL2A}));
 }
 
 BOOST_AUTO_TEST_CASE(InsertReplace)
@@ -191,7 +191,7 @@
 
   EncodingBuffer encoder;
   dl.wireEncode(encoder);
-  BOOST_CHECK(encoder.block() == makeDelegationListBlock(tlv::ForwardingHint, {DEL1A}));
+  BOOST_CHECK_EQUAL(encoder.block(), makeDelegationListBlock(tlv::ForwardingHint, {DEL1A}));
 }
 
 BOOST_AUTO_TEST_CASE(InsertAppend)
@@ -204,7 +204,7 @@
 
   EncodingBuffer encoder;
   dl.wireEncode(encoder);
-  BOOST_CHECK(encoder.block() == makeDelegationListBlock(tlv::ForwardingHint, {DEL1A, DEL2A}));
+  BOOST_CHECK_EQUAL(encoder.block(), makeDelegationListBlock(tlv::ForwardingHint, {DEL1A, DEL2A}));
 }
 
 BOOST_AUTO_TEST_CASE(InsertSkip)
@@ -216,7 +216,7 @@
 
   EncodingBuffer encoder;
   dl.wireEncode(encoder);
-  BOOST_CHECK(encoder.block() == makeDelegationListBlock(tlv::ForwardingHint, {DEL2A}));
+  BOOST_CHECK_EQUAL(encoder.block(), makeDelegationListBlock(tlv::ForwardingHint, {DEL2A}));
 }
 
 BOOST_AUTO_TEST_CASE(Unsorted)
@@ -231,7 +231,7 @@
 
   EncodingBuffer encoder;
   dl.wireEncode(encoder, tlv::Content);
-  BOOST_CHECK(encoder.block() == makeDelegationListBlock(tlv::Content, {DEL2A, DEL1B}));
+  BOOST_CHECK_EQUAL(encoder.block(), makeDelegationListBlock(tlv::Content, {DEL2A, DEL1B}));
 }
 
 BOOST_AUTO_TEST_CASE(EncodeBadType)
diff --git a/tests/unit-tests/encoding/block-helpers.t.cpp b/tests/unit-tests/encoding/block-helpers.t.cpp
index 47226b3..9247e0a 100644
--- a/tests/unit-tests/encoding/block-helpers.t.cpp
+++ b/tests/unit-tests/encoding/block-helpers.t.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).
  *
@@ -95,8 +95,8 @@
   Block b3 = makeBinaryBlock(100, buf1.begin(), buf1.end()); // fast encoding (random access iterator)
   Block b4 = makeBinaryBlock(100, buf3.begin(), buf3.end()); // slow encoding (general iterator)
 
-  BOOST_CHECK(b1 == b2);
-  BOOST_CHECK(b1 == b3);
+  BOOST_CHECK_EQUAL(b1, b2);
+  BOOST_CHECK_EQUAL(b1, b3);
   BOOST_CHECK_EQUAL(b1.type(), 100);
   BOOST_CHECK_EQUAL(b1.value_size(), buf1.size());
   BOOST_CHECK_EQUAL_COLLECTIONS(b1.value_begin(), b1.value_end(),
@@ -112,7 +112,7 @@
   b1.parse();
   BOOST_CHECK_EQUAL(b1.elements().size(), 1);
   BOOST_CHECK_EQUAL(b1.elements().begin()->type(), name.wireEncode().type());
-  BOOST_CHECK(*b1.elements().begin() == name.wireEncode());
+  BOOST_CHECK_EQUAL(*b1.elements().begin(), name.wireEncode());
 }
 
 BOOST_AUTO_TEST_SUITE_END() // TestBlockHelpers
diff --git a/tests/unit-tests/encoding/block.t.cpp b/tests/unit-tests/encoding/block.t.cpp
index 967a285..70174aa 100644
--- a/tests/unit-tests/encoding/block.t.cpp
+++ b/tests/unit-tests/encoding/block.t.cpp
@@ -22,7 +22,9 @@
 #include "encoding/block.hpp"
 #include "encoding/block-helpers.hpp"
 
+#include "block-literal.hpp"
 #include "boost-test.hpp"
+#include <boost/lexical_cast.hpp>
 #include <cstring>
 #include <sstream>
 
@@ -492,6 +494,42 @@
   BOOST_CHECK_EQUAL(e != f, true);
 }
 
+BOOST_AUTO_TEST_CASE(Print)
+{
+  // default constructed
+  Block b;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b), "[invalid]");
+
+  // zero length
+  b = "0700"_block;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b), "7[empty]");
+
+  // unparsed
+  b = "0E10FF7E4E6B3B21C902660F16ED589FCCCC"_block;
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b),
+                    "14[16]=FF7E4E6B3B21C902660F16ED589FCCCC");
+  // set and restore format flags
+  {
+    std::ostringstream oss;
+    oss << std::showbase << std::hex << 0xd23c4 << b << 0x4981e;
+    BOOST_CHECK_EQUAL(oss.str(), "0xd23c414[16]=FF7E4E6B3B21C902660F16ED589FCCCC0x4981e");
+  }
+
+  // parsed
+  b = "FD010808 0502CADD 59024E42"_block;
+  b.parse();
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b),
+                    "264[8]={5[2]=CADD,89[2]=4E42}");
+
+  // parsed then modified: print modified sub-elements
+  b = "FD010808 0502CADD 59024E42"_block;
+  b.parse();
+  b.erase(b.elements_begin());
+  b.push_back("10022386"_block);
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b),
+                    "264[8]={89[2]=4E42,16[2]=2386}");
+}
+
 BOOST_AUTO_TEST_SUITE_END() // TestBlock
 BOOST_AUTO_TEST_SUITE_END() // Encoding
 
diff --git a/tests/unit-tests/interest.t.cpp b/tests/unit-tests/interest.t.cpp
index 2860551..f1e79dc 100644
--- a/tests/unit-tests/interest.t.cpp
+++ b/tests/unit-tests/interest.t.cpp
@@ -147,7 +147,7 @@
 
   // modify then re-encode as v0.2 format
   i.setNonce(0x54657c95);
-  BOOST_CHECK(i.wireEncode() == "0510 0703080149 09030E0101 0A04957C6554"_block);
+  BOOST_CHECK_EQUAL(i.wireEncode(), "0510 0703080149 09030E0101 0A04957C6554"_block);
 }
 
 BOOST_AUTO_TEST_CASE(Full)
@@ -170,9 +170,8 @@
 
   // modify then re-encode as v0.2 format
   i.setName("/J");
-  BOOST_CHECK(i.wireEncode() ==
-              "0520 070308014A 09021200 0A044ACB1E4C 0C0276A1 "
-              "1E0B(1F09 1E023E15 0703080148)"_block);
+  BOOST_CHECK_EQUAL(i.wireEncode(),
+    "0520 070308014A 09021200 0A044ACB1E4C 0C0276A1 1E0B(1F09 1E023E15 0703080148)"_block);
 }
 
 BOOST_AUTO_TEST_CASE(CriticalElementOutOfOrder)
diff --git a/tests/unit-tests/key-locator.t.cpp b/tests/unit-tests/key-locator.t.cpp
index 05dc94a..ce3c6ae 100644
--- a/tests/unit-tests/key-locator.t.cpp
+++ b/tests/unit-tests/key-locator.t.cpp
@@ -52,7 +52,7 @@
                                 wire.begin(), wire.end());
 
   KeyLocator b(wire);
-  BOOST_CHECK(a == b);
+  BOOST_CHECK_EQUAL(a, b);
   BOOST_CHECK_EQUAL(b.getType(), KeyLocator::KeyLocator_None);
   BOOST_CHECK_THROW(b.getName(), KeyLocator::Error);
   BOOST_CHECK_THROW(b.getKeyDigest(), KeyLocator::Error);
@@ -83,7 +83,7 @@
                                 wire.begin(), wire.end());
 
   KeyLocator b(wire);
-  BOOST_CHECK(a == b);
+  BOOST_CHECK_EQUAL(a, b);
   BOOST_CHECK_EQUAL(b.getType(), KeyLocator::KeyLocator_Name);
   BOOST_CHECK_EQUAL(b.getName(), Name("/N"));
   BOOST_CHECK_THROW(b.getKeyDigest(), KeyLocator::Error);
@@ -100,7 +100,7 @@
   KeyLocator a;
   a.setKeyDigest(digestBuffer);
   BOOST_CHECK_EQUAL(a.getType(), KeyLocator::KeyLocator_KeyDigest);
-  BOOST_CHECK(a.getKeyDigest() == expectedDigestBlock);
+  BOOST_CHECK_EQUAL(a.getKeyDigest(), expectedDigestBlock);
   BOOST_CHECK_THROW(a.getName(), KeyLocator::Error);
 
   Block wire;
@@ -118,9 +118,9 @@
                                 wire.begin(), wire.end());
 
   KeyLocator b(wire);
-  BOOST_CHECK(a == b);
+  BOOST_CHECK_EQUAL(a, b);
   BOOST_CHECK_EQUAL(b.getType(), KeyLocator::KeyLocator_KeyDigest);
-  BOOST_CHECK(b.getKeyDigest() == expectedDigestBlock);
+  BOOST_CHECK_EQUAL(b.getKeyDigest(), expectedDigestBlock);
   BOOST_CHECK_THROW(b.getName(), KeyLocator::Error);
 
   BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(b), "KeyDigest=123456789A...");
diff --git a/tests/unit-tests/meta-info.t.cpp b/tests/unit-tests/meta-info.t.cpp
index 9e04b78..aee3b69 100644
--- a/tests/unit-tests/meta-info.t.cpp
+++ b/tests/unit-tests/meta-info.t.cpp
@@ -46,7 +46,7 @@
   b.setType(a.getType());
   b.setFreshnessPeriod(a.getFreshnessPeriod());
   b.setFinalBlock(a.getFinalBlock());
-  BOOST_CHECK(b.wireEncode() == "1400"_block);
+  BOOST_CHECK_EQUAL(b.wireEncode(), "1400"_block);
   BOOST_CHECK_EQUAL(a, b); // expected failure #4569
 
   // non-default values
@@ -61,7 +61,7 @@
   b.setType(a.getType());
   b.setFreshnessPeriod(a.getFreshnessPeriod());
   b.setFinalBlockId(a.getFinalBlockId());
-  BOOST_CHECK(b.wireEncode() == wire2);
+  BOOST_CHECK_EQUAL(b.wireEncode(), wire2);
   BOOST_CHECK_EQUAL(a, b);
 
   // FinalBlockId is typed name component
@@ -75,7 +75,7 @@
   b.setType(a.getType());
   b.setFreshnessPeriod(a.getFreshnessPeriod());
   b.setFinalBlockId(a.getFinalBlockId());
-  BOOST_CHECK(b.wireEncode() == wire3);
+  BOOST_CHECK_EQUAL(b.wireEncode(), wire3);
   BOOST_CHECK_EQUAL(a, b);
 }
 
@@ -97,19 +97,19 @@
     info1.addAppMetaInfo(makeStringBlock(type, ss[i]));
   }
 
-  BOOST_CHECK(info1.findAppMetaInfo(252) == 0);
+  BOOST_CHECK(info1.findAppMetaInfo(252) == nullptr);
 
   info1.addAppMetaInfo(makeNonNegativeIntegerBlock(252, 1000));
-  BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
+  BOOST_CHECK(info1.findAppMetaInfo(252) != nullptr);
 
   info1.addAppMetaInfo(makeNonNegativeIntegerBlock(252, 1000));
-  BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
+  BOOST_CHECK(info1.findAppMetaInfo(252) != nullptr);
 
   info1.removeAppMetaInfo(252);
-  BOOST_CHECK(info1.findAppMetaInfo(252) != 0);
+  BOOST_CHECK(info1.findAppMetaInfo(252) != nullptr);
 
   info1.removeAppMetaInfo(252);
-  BOOST_CHECK(info1.findAppMetaInfo(252) == 0);
+  BOOST_CHECK(info1.findAppMetaInfo(252) == nullptr);
 
   // // These octets are obtained by the snippet below.
   // // This check is intended to detect unexpected encoding change in the future.
diff --git a/tests/unit-tests/mgmt/dispatcher.t.cpp b/tests/unit-tests/mgmt/dispatcher.t.cpp
index 9f8d34d..69f389d 100644
--- a/tests/unit-tests/mgmt/dispatcher.t.cpp
+++ b/tests/unit-tests/mgmt/dispatcher.t.cpp
@@ -226,9 +226,9 @@
   BOOST_CHECK_EQUAL(nCallbackCalled, 0);
   BOOST_CHECK_EQUAL(face.sentData.size(), 2);
 
-  BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(face.sentData[0].getContentType(), tlv::ContentType_Blob);
   BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
-  BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(face.sentData[1].getContentType(), tlv::ContentType_Blob);
   BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
 
   face.receive(*makeInterest("/root/test/%80%00/valid"));
@@ -354,9 +354,9 @@
   advanceClocks(1_ms, 20);
   BOOST_CHECK_EQUAL(face.sentData.size(), 2);
 
-  BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(face.sentData[0].getContentType(), tlv::ContentType_Blob);
   BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
-  BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
+  BOOST_CHECK_EQUAL(face.sentData[1].getContentType(), tlv::ContentType_Blob);
   BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);
 
   face.sentData.clear();
@@ -371,7 +371,7 @@
 
   auto fetchedData = storage.find(interestSmall);
   BOOST_REQUIRE(fetchedData != nullptr);
-  BOOST_CHECK(face.sentData[0].wireEncode() == fetchedData->wireEncode());
+  BOOST_CHECK_EQUAL(face.sentData[0].wireEncode(), fetchedData->wireEncode());
 
   face.receive(*makeInterest(Name("/root/test/small/valid").appendVersion(10))); // should be ignored
   face.receive(*makeInterest(Name("/root/test/small/valid").appendSegment(20))); // should be ignored
@@ -382,10 +382,10 @@
   Block content = face.sentData[0].getContent();
   BOOST_CHECK_NO_THROW(content.parse());
 
-  BOOST_CHECK_EQUAL(content.elements().size(), 3);
-  BOOST_CHECK(content.elements()[0] == smallBlock);
-  BOOST_CHECK(content.elements()[1] == smallBlock);
-  BOOST_CHECK(content.elements()[2] == smallBlock);
+  BOOST_REQUIRE_EQUAL(content.elements().size(), 3);
+  BOOST_CHECK_EQUAL(content.elements()[0], smallBlock);
+  BOOST_CHECK_EQUAL(content.elements()[1], smallBlock);
+  BOOST_CHECK_EQUAL(content.elements()[2], smallBlock);
 
   storage.erase("/", true); // clear the storage
   face.sentData.clear();
@@ -407,7 +407,7 @@
 
   // the Data sent through the face should be the same as the first Data in the storage
   BOOST_CHECK_EQUAL(face.sentData[0].getName(), dataInStorage[0].getName());
-  BOOST_CHECK(face.sentData[0].getContent() == dataInStorage[0].getContent());
+  BOOST_CHECK_EQUAL(face.sentData[0].getContent(), dataInStorage[0].getContent());
 
   content = [&dataInStorage] () -> Block {
     EncodingBuffer encoder;
@@ -421,17 +421,17 @@
   }();
 
   BOOST_CHECK_NO_THROW(content.parse());
-  BOOST_CHECK_EQUAL(content.elements().size(), 3);
-  BOOST_CHECK(content.elements()[0] == largeBlock);
-  BOOST_CHECK(content.elements()[1] == largeBlock);
-  BOOST_CHECK(content.elements()[2] == largeBlock);
+  BOOST_REQUIRE_EQUAL(content.elements().size(), 3);
+  BOOST_CHECK_EQUAL(content.elements()[0], largeBlock);
+  BOOST_CHECK_EQUAL(content.elements()[1], largeBlock);
+  BOOST_CHECK_EQUAL(content.elements()[2], largeBlock);
 
   storage.erase("/", true);// clear the storage
   face.sentData.clear();
   face.receive(*makeInterest("/root/test/reject/%80%00/valid")); // returns nack
   advanceClocks(1_ms);
   BOOST_CHECK_EQUAL(face.sentData.size(), 1);
-  BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Nack);
+  BOOST_CHECK_EQUAL(face.sentData[0].getContentType(), tlv::ContentType_Nack);
   BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 400);
   BOOST_CHECK_EQUAL(storage.size(), 0); // the nack packet will not be inserted into the in-memory storage
 }
@@ -460,30 +460,30 @@
   post(block);
   advanceClocks(1_ms, 10);
 
-  BOOST_CHECK_EQUAL(face.sentData.size(), 4);
+  BOOST_REQUIRE_EQUAL(face.sentData.size(), 4);
   BOOST_CHECK_EQUAL(face.sentData[0].getName(), "/root/test/%FE%00");
   BOOST_CHECK_EQUAL(face.sentData[1].getName(), "/root/test/%FE%01");
   BOOST_CHECK_EQUAL(face.sentData[2].getName(), "/root/test/%FE%02");
   BOOST_CHECK_EQUAL(face.sentData[3].getName(), "/root/test/%FE%03");
 
-  BOOST_CHECK(face.sentData[0].getContent().blockFromValue() == block);
-  BOOST_CHECK(face.sentData[1].getContent().blockFromValue() == block);
-  BOOST_CHECK(face.sentData[2].getContent().blockFromValue() == block);
-  BOOST_CHECK(face.sentData[3].getContent().blockFromValue() == block);
+  BOOST_CHECK_EQUAL(face.sentData[0].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(face.sentData[1].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(face.sentData[2].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(face.sentData[3].getContent().blockFromValue(), block);
 
   // each version of notification will be sent to both places
   std::vector<Data> dataInStorage;
   std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));
-  BOOST_CHECK_EQUAL(dataInStorage.size(), 4);
+  BOOST_REQUIRE_EQUAL(dataInStorage.size(), 4);
   BOOST_CHECK_EQUAL(dataInStorage[0].getName(), "/root/test/%FE%00");
   BOOST_CHECK_EQUAL(dataInStorage[1].getName(), "/root/test/%FE%01");
   BOOST_CHECK_EQUAL(dataInStorage[2].getName(), "/root/test/%FE%02");
   BOOST_CHECK_EQUAL(dataInStorage[3].getName(), "/root/test/%FE%03");
 
-  BOOST_CHECK(dataInStorage[0].getContent().blockFromValue() == block);
-  BOOST_CHECK(dataInStorage[1].getContent().blockFromValue() == block);
-  BOOST_CHECK(dataInStorage[2].getContent().blockFromValue() == block);
-  BOOST_CHECK(dataInStorage[3].getContent().blockFromValue() == block);
+  BOOST_CHECK_EQUAL(dataInStorage[0].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(dataInStorage[1].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(dataInStorage[2].getContent().blockFromValue(), block);
+  BOOST_CHECK_EQUAL(dataInStorage[3].getContent().blockFromValue(), block);
 }
 
 BOOST_AUTO_TEST_SUITE_END() // TestDispatcher
diff --git a/tests/unit-tests/mgmt/status-dataset-context.t.cpp b/tests/unit-tests/mgmt/status-dataset-context.t.cpp
index c5af199..34e6fc1 100644
--- a/tests/unit-tests/mgmt/status-dataset-context.t.cpp
+++ b/tests/unit-tests/mgmt/status-dataset-context.t.cpp
@@ -97,7 +97,7 @@
 {
   Name dataName = context.getPrefix();
   BOOST_CHECK(dataName[-1].isVersion());
-  BOOST_CHECK(dataName.getPrefix(-1) == interest->getName());
+  BOOST_CHECK_EQUAL(dataName.getPrefix(-1), interest->getName());
 }
 
 BOOST_AUTO_TEST_CASE(SetValid)
@@ -105,7 +105,7 @@
   Name validPrefix = Name(interest->getName()).append("/valid");
   BOOST_CHECK_NO_THROW(context.setPrefix(validPrefix));
   BOOST_CHECK(context.getPrefix()[-1].isVersion());
-  BOOST_CHECK(context.getPrefix().getPrefix(-1) == validPrefix);
+  BOOST_CHECK_EQUAL(context.getPrefix().getPrefix(-1), validPrefix);
 }
 
 BOOST_AUTO_TEST_CASE(SetInvalid)
@@ -161,7 +161,7 @@
   const auto& args = sendDataHistory[0];
 
   BOOST_CHECK_EQUAL(args.dataName, makeSegmentName(0));
-  BOOST_CHECK(args.content.blockFromValue() == contentBlock);
+  BOOST_CHECK_EQUAL(args.content.blockFromValue(), contentBlock);
   BOOST_CHECK_EQUAL(args.imsFresh, defaultImsFresh);
   BOOST_CHECK_EQUAL(args.isFinalBlock, true);
 }
@@ -199,7 +199,7 @@
   auto contentLargeBlock = concatenateDataContent();
   BOOST_CHECK_NO_THROW(contentLargeBlock.parse());
   BOOST_REQUIRE_EQUAL(contentLargeBlock.elements().size(), 1);
-  BOOST_CHECK(contentLargeBlock.elements()[0] == largeBlock);
+  BOOST_CHECK_EQUAL(contentLargeBlock.elements()[0], largeBlock);
 }
 
 BOOST_AUTO_TEST_CASE(MultipleSmall)
@@ -220,7 +220,7 @@
   BOOST_CHECK_NO_THROW(contentMultiBlocks.parse());
   BOOST_CHECK_EQUAL(contentMultiBlocks.elements().size(), nBlocks);
   for (auto&& element : contentMultiBlocks.elements()) {
-    BOOST_CHECK(element == contentBlock);
+    BOOST_CHECK_EQUAL(element, contentBlock);
   }
 }
 
diff --git a/tests/unit-tests/name.t.cpp b/tests/unit-tests/name.t.cpp
index c934be1..af71206 100644
--- a/tests/unit-tests/name.t.cpp
+++ b/tests/unit-tests/name.t.cpp
@@ -48,8 +48,9 @@
   BOOST_CHECK(name[5].isImplicitSha256Digest());
 
   Block wire = name.wireEncode();
-  BOOST_CHECK(wire == "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F "
-              "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block);
+  BOOST_CHECK_EQUAL(wire,
+    "0737 0804456D6964 FD61D2025033 0800 08012E 08021C9F "
+    "01200415E3624A151850AC686C84F155F29808C0DD73819AA4A4C20BE73A4D8A874C"_block);
 
   Name decoded(wire);
   BOOST_CHECK_EQUAL(decoded, name);
@@ -199,37 +200,37 @@
 BOOST_AUTO_TEST_CASE(AppendComponent)
 {
   Name name;
-  BOOST_CHECK(name.wireEncode() == "0700"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
 
   name.append(Component("Emid"));
-  BOOST_CHECK(name.wireEncode() == "0706 0804456D6964"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0706 0804456D6964"_block);
 
   name.append(25042, reinterpret_cast<const uint8_t*>("P3"), 2);
-  BOOST_CHECK(name.wireEncode() == "070C 0804456D6964 FD61D2025033"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "070C 0804456D6964 FD61D2025033"_block);
 
   name.append(reinterpret_cast<const uint8_t*>("."), 1);
-  BOOST_CHECK(name.wireEncode() == "070F 0804456D6964 FD61D2025033 08012E"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "070F 0804456D6964 FD61D2025033 08012E"_block);
 
   std::vector<uint8_t> v1{0x28, 0xF0, 0xA3, 0x6B};
   name.append(16, v1.begin(), v1.end());
-  BOOST_CHECK(name.wireEncode() == "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0715 0804456D6964 FD61D2025033 08012E 100428F0A36B"_block);
 
   BOOST_CHECK(!name.empty());
   name.clear();
   BOOST_CHECK(name.empty());
-  BOOST_CHECK(name.wireEncode() == "0700"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0700"_block);
 
   name.append(v1.begin(), v1.end());
-  BOOST_CHECK(name.wireEncode() == "0706 080428F0A36B"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0706 080428F0A36B"_block);
 
   name.append("xKh");
-  BOOST_CHECK(name.wireEncode() == "070B 080428F0A36B 0803784B68"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "070B 080428F0A36B 0803784B68"_block);
 
   name.append("0100"_block);
-  BOOST_CHECK(name.wireEncode() == "070F 080428F0A36B 0803784B68 08020100"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080428F0A36B 0803784B68 08020100"_block);
 
   name.append("080109"_block);
-  BOOST_CHECK(name.wireEncode() == "0712 080428F0A36B 0803784B68 08020100 080109"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "0712 080428F0A36B 0803784B68 08020100 080109"_block);
 }
 
 BOOST_AUTO_TEST_CASE(AppendPartialName)
@@ -237,7 +238,7 @@
   Name name("/A/B");
   name.append(PartialName("/6=C/D"))
       .append(PartialName("/E"));
-  BOOST_CHECK(name.wireEncode() == "070F 080141 080142 060143 080144 080145"_block);
+  BOOST_CHECK_EQUAL(name.wireEncode(), "070F 080141 080142 060143 080144 080145"_block);
 }
 
 BOOST_AUTO_TEST_CASE(AppendNumber)
diff --git a/tests/unit-tests/security/pib/pib-impl.t.cpp b/tests/unit-tests/security/pib/pib-impl.t.cpp
index 265c111..6094b0e 100644
--- a/tests/unit-tests/security/pib/pib-impl.t.cpp
+++ b/tests/unit-tests/security/pib/pib-impl.t.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).
  *
@@ -224,7 +224,8 @@
   BOOST_CHECK_EQUAL(this->pib.hasCertificate(this->id1Key1Cert1.getName()), true);
   BOOST_CHECK_EQUAL(this->pib.hasIdentity(this->id1), true);
   BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), true);
-  BOOST_CHECK(this->pib.getCertificate(this->id1Key1Cert1.getName()).wireEncode() == this->id1Key1Cert1.wireEncode());
+  BOOST_CHECK_EQUAL(this->pib.getCertificate(this->id1Key1Cert1.getName()).wireEncode(),
+                    this->id1Key1Cert1.wireEncode());
   BOOST_CHECK_NO_THROW(this->pib.getDefaultCertificateOfKey(this->id1Key1Name));
   BOOST_CHECK_EQUAL(this->pib.getDefaultCertificateOfKey(this->id1Key1Name), this->id1Key1Cert1);
 
@@ -323,7 +324,7 @@
   BOOST_CHECK_EQUAL(this->pib.hasCertificate(this->id1Key1Cert1.getName()), true);
 
   auto cert = this->pib.getCertificate(this->id1Key1Cert1.getName());
-  BOOST_CHECK(cert.wireEncode() == this->id1Key1Cert1.wireEncode());
+  BOOST_CHECK_EQUAL(cert.wireEncode(), this->id1Key1Cert1.wireEncode());
 
   // Create a fake cert with the same name
   auto cert2 = this->id1Key2Cert1;
@@ -332,7 +333,7 @@
   this->pib.addCertificate(cert2);
 
   auto cert3 = this->pib.getCertificate(this->id1Key1Cert1.getName());
-  BOOST_CHECK(cert3.wireEncode() == cert2.wireEncode());
+  BOOST_CHECK_EQUAL(cert3.wireEncode(), cert2.wireEncode());
 
   // both key and certificate are overwritten
   Buffer keyBits3 = this->pib.getKeyBits(this->id1Key1Name);
diff --git a/tests/unit-tests/security/safe-bag.t.cpp b/tests/unit-tests/security/safe-bag.t.cpp
index 3c93e58..0423c69 100644
--- a/tests/unit-tests/security/safe-bag.t.cpp
+++ b/tests/unit-tests/security/safe-bag.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 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).
  *
@@ -150,7 +150,7 @@
   Block block(SAFE_BAG, sizeof(SAFE_BAG));
 
   // check safe bag block
-  BOOST_CHECK(wireBlock == block);
+  BOOST_CHECK_EQUAL(wireBlock, block);
 
   // wire decode
   SafeBag safeBag2;
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 658b1c2..a819279 100644
--- a/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
@@ -102,7 +102,7 @@
   sig.setKeyLocator(Name("/test/another/key/locator"));
 
   const Block& encodeSigInfoBlock2 = sig.getInfo();
-  BOOST_CHECK(sigInfoBlock != encodeSigInfoBlock2);
+  BOOST_CHECK_NE(sigInfoBlock, encodeSigInfoBlock2);
 }
 
 BOOST_AUTO_TEST_CASE(DataSignature)
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 4599178..86dbb37 100644
--- a/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
@@ -107,7 +107,7 @@
   sig.setKeyLocator(Name("/test/another/key/locator"));
 
   const Block& encodeSigInfoBlock2 = sig.getInfo();
-  BOOST_CHECK(sigInfoBlock != encodeSigInfoBlock2);
+  BOOST_CHECK_NE(sigInfoBlock, encodeSigInfoBlock2);
 }
 
 BOOST_AUTO_TEST_CASE(DataSignature)
diff --git a/tests/unit-tests/security/signing-info.t.cpp b/tests/unit-tests/security/signing-info.t.cpp
index 9a64a53..fc6f627 100644
--- a/tests/unit-tests/security/signing-info.t.cpp
+++ b/tests/unit-tests/security/signing-info.t.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).
  *
@@ -93,16 +93,16 @@
 BOOST_AUTO_TEST_CASE(CustomSignatureInfo)
 {
   SigningInfo info1;
-  BOOST_CHECK(info1.getSignatureInfo() == SignatureInfo());
+  BOOST_CHECK_EQUAL(info1.getSignatureInfo(), SignatureInfo());
 
   SignatureInfo si;
   si.setKeyLocator(Name("ndn:/test/key/locator"));
   info1.setSignatureInfo(si);
 
-  BOOST_CHECK(info1.getSignatureInfo() == si);
+  BOOST_CHECK_EQUAL(info1.getSignatureInfo(), si);
 
   SigningInfo info2(SigningInfo::SIGNER_TYPE_NULL, SigningInfo::getEmptyName(), si);
-  BOOST_CHECK(info2.getSignatureInfo() == si);
+  BOOST_CHECK_EQUAL(info2.getSignatureInfo(), si);
 }
 
 BOOST_AUTO_TEST_CASE(FromString)
diff --git a/tests/unit-tests/security/v2/additional-description.t.cpp b/tests/unit-tests/security/v2/additional-description.t.cpp
index 98431b6..7ceee8c 100644
--- a/tests/unit-tests/security/v2/additional-description.t.cpp
+++ b/tests/unit-tests/security/v2/additional-description.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 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).
  *
@@ -82,13 +82,13 @@
   BOOST_REQUIRE_NO_THROW(AdditionalDescription(Block(description, sizeof(description))));
   AdditionalDescription aDescription2(Block(description, sizeof(description)));
 
-  BOOST_CHECK(aDescription2 == aDescription);
+  BOOST_CHECK_EQUAL(aDescription2, aDescription);
 
   AdditionalDescription aDescription3;
   aDescription3.set("key3", "val3");
   aDescription3.set("key2", "val2");
 
-  BOOST_CHECK(aDescription2 != aDescription3);
+  BOOST_CHECK_NE(aDescription2, aDescription3);
 
   std::ostringstream os;
   os << aDescription;
diff --git a/tests/unit-tests/security/v2/key-chain.t.cpp b/tests/unit-tests/security/v2/key-chain.t.cpp
index d03f572..a4cc2f7 100644
--- a/tests/unit-tests/security/v2/key-chain.t.cpp
+++ b/tests/unit-tests/security/v2/key-chain.t.cpp
@@ -216,9 +216,9 @@
 
   // Create the third key
   Key key3 = m_keyChain.createKey(id);
-  BOOST_CHECK(key3.getName() != key2.getName());
+  BOOST_CHECK_NE(key3.getName(), key2.getName());
   // The added key will not be the default key, because the default key already exists
-  BOOST_CHECK(id.getDefaultKey().getName() == key2.getName());
+  BOOST_CHECK_EQUAL(id.getDefaultKey().getName(), key2.getName());
   BOOST_CHECK_EQUAL(id.getKeys().size(), 2);
   BOOST_REQUIRE_NO_THROW(key3.getDefaultCertificate());
 
diff --git a/tests/unit-tests/signature-info.t.cpp b/tests/unit-tests/signature-info.t.cpp
index 836c114..f5cf102 100644
--- a/tests/unit-tests/signature-info.t.cpp
+++ b/tests/unit-tests/signature-info.t.cpp
@@ -195,7 +195,7 @@
   info.setKeyLocator(KeyLocator("/test/key/locator"));
   info.setValidityPeriod(vp1);
 
-  BOOST_CHECK(info.getValidityPeriod() == vp1);
+  BOOST_CHECK_EQUAL(info.getValidityPeriod(), vp1);
 
   const Block& encoded = info.wireEncode();
 
@@ -206,7 +206,7 @@
   Block block(sigInfo, sizeof(sigInfo));
   SignatureInfo info2;
   info2.wireDecode(block);
-  BOOST_CHECK(info2.getValidityPeriod() == vp1);
+  BOOST_CHECK_EQUAL(info2.getValidityPeriod(), vp1);
 
   const security::ValidityPeriod& validityPeriod = info2.getValidityPeriod();
   BOOST_CHECK(validityPeriod.getPeriod() == std::make_pair(notBefore, notAfter));
diff --git a/tests/unit-tests/util/sqlite3-statement.t.cpp b/tests/unit-tests/util/sqlite3-statement.t.cpp
index 78e8664..13171c5 100644
--- a/tests/unit-tests/util/sqlite3-statement.t.cpp
+++ b/tests/unit-tests/util/sqlite3-statement.t.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).
  *
@@ -135,10 +135,9 @@
     BOOST_CHECK_EQUAL(stmt.step(), SQLITE_ROW);
     BOOST_CHECK_EQUAL(stmt.getInt(0), 4);
 
-    Block newBlock;
-    BOOST_CHECK_NO_THROW(newBlock = stmt.getBlock(1));
+    Block newBlock = stmt.getBlock(1);
     BOOST_CHECK_EQUAL(newBlock.type(), 100);
-    BOOST_CHECK(newBlock == block);
+    BOOST_CHECK_EQUAL(newBlock, block);
 
     BOOST_CHECK_EQUAL(stmt.step(), SQLITE_ROW);
     BOOST_CHECK_EQUAL(stmt.getInt(0), 5);