mgmt: ChannelStatus equality operators and formatted output

Change-Id: I17745976af96d4dda3d6717eefd760fd52ebfb71
Refs: #3903
diff --git a/src/mgmt/nfd/channel-status.cpp b/src/mgmt/nfd/channel-status.cpp
index bbbfdf4..c2a9b63 100644
--- a/src/mgmt/nfd/channel-status.cpp
+++ b/src/mgmt/nfd/channel-status.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-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -20,22 +20,16 @@
  */
 
 #include "channel-status.hpp"
+#include "encoding/encoding-buffer.hpp"
 #include "encoding/tlv-nfd.hpp"
-#include "encoding/block-helpers.hpp"
 #include "util/concepts.hpp"
 
 namespace ndn {
 namespace nfd {
 
-//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ChannelStatus>));
-BOOST_CONCEPT_ASSERT((WireEncodable<ChannelStatus>));
-BOOST_CONCEPT_ASSERT((WireDecodable<ChannelStatus>));
-static_assert(std::is_base_of<tlv::Error, ChannelStatus::Error>::value,
-              "ChannelStatus::Error must inherit from tlv::Error");
+BOOST_CONCEPT_ASSERT((StatusDatasetItem<ChannelStatus>));
 
-ChannelStatus::ChannelStatus()
-{
-}
+ChannelStatus::ChannelStatus() = default;
 
 ChannelStatus::ChannelStatus(const Block& payload)
 {
@@ -49,7 +43,7 @@
   size_t totalLength = 0;
 
   totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri,
-                 reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
+                 reinterpret_cast<const uint8_t*>(m_localUri.data()), m_localUri.size());
 
   totalLength += encoder.prependVarNumber(totalLength);
   totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus);
@@ -105,5 +99,17 @@
   return *this;
 }
 
+bool
+operator==(const ChannelStatus& a, const ChannelStatus& b)
+{
+  return a.getLocalUri() == b.getLocalUri();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const ChannelStatus& cs)
+{
+  return os << "Channel(" << "LocalUri: " << cs.getLocalUri() << ")";
+}
+
 } // namespace nfd
 } // namespace ndn
diff --git a/src/mgmt/nfd/channel-status.hpp b/src/mgmt/nfd/channel-status.hpp
index 5a2aae8..16eb419 100644
--- a/src/mgmt/nfd/channel-status.hpp
+++ b/src/mgmt/nfd/channel-status.hpp
@@ -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-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -76,6 +76,18 @@
   mutable Block m_wire;
 };
 
+bool
+operator==(const ChannelStatus& a, const ChannelStatus& b);
+
+inline bool
+operator!=(const ChannelStatus& a, const ChannelStatus& b)
+{
+  return !(a == b);
+}
+
+std::ostream&
+operator<<(std::ostream& os, const ChannelStatus& cs);
+
 } // namespace nfd
 } // namespace ndn
 
diff --git a/tests/unit-tests/mgmt/nfd/channel-status.t.cpp b/tests/unit-tests/mgmt/nfd/channel-status.t.cpp
index c682f59..0ffe2de 100644
--- a/tests/unit-tests/mgmt/nfd/channel-status.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/channel-status.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-2017 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 "mgmt/nfd/channel-status.hpp"
 
 #include "boost-test.hpp"
+#include <boost/lexical_cast.hpp>
 
 namespace ndn {
 namespace nfd {
@@ -34,9 +35,7 @@
 BOOST_AUTO_TEST_CASE(Encode)
 {
   ChannelStatus status1;
-  status1
-    .setLocalUri("udp4://192.168.2.1")
-    ;
+  status1.setLocalUri("udp4://192.168.2.1");
 
   Block wire;
   BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
@@ -58,6 +57,26 @@
   BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
 }
 
+BOOST_AUTO_TEST_CASE(Equality)
+{
+  ChannelStatus cs1, cs2;
+
+  cs1.setLocalUri("udp4://127.0.0.1:6363");
+  cs2 = cs1;
+  BOOST_CHECK_EQUAL(cs1, cs2);
+
+  cs2.setLocalUri("dev://eth0");
+  BOOST_CHECK_NE(cs1, cs2);
+}
+
+BOOST_AUTO_TEST_CASE(Print)
+{
+  ChannelStatus cs;
+  cs.setLocalUri("udp4://127.0.0.1:6363");
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(cs),
+                    "Channel(LocalUri: udp4://127.0.0.1:6363)");
+}
+
 BOOST_AUTO_TEST_SUITE_END() // TestChannelStatus
 BOOST_AUTO_TEST_SUITE_END() // Nfd
 BOOST_AUTO_TEST_SUITE_END() // Mgmt