mgmt: StrategyChoice equality operators and formatted output

refs #3903

Change-Id: I458e80959b5a3ecdc1d0e55ec2ac361772a60e70
diff --git a/src/mgmt/nfd/strategy-choice.cpp b/src/mgmt/nfd/strategy-choice.cpp
index 2e294d7..3643be6 100644
--- a/src/mgmt/nfd/strategy-choice.cpp
+++ b/src/mgmt/nfd/strategy-choice.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).
  *
@@ -27,15 +27,14 @@
 namespace ndn {
 namespace nfd {
 
-//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<StrategyChoice>));
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<StrategyChoice>));
 BOOST_CONCEPT_ASSERT((WireEncodable<StrategyChoice>));
+BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<StrategyChoice>));
 BOOST_CONCEPT_ASSERT((WireDecodable<StrategyChoice>));
 static_assert(std::is_base_of<tlv::Error, StrategyChoice::Error>::value,
               "StrategyChoice::Error must inherit from tlv::Error");
 
-StrategyChoice::StrategyChoice()
-{
-}
+StrategyChoice::StrategyChoice() = default;
 
 StrategyChoice::StrategyChoice(const Block& payload)
 {
@@ -127,5 +126,20 @@
   return *this;
 }
 
+bool
+operator==(const StrategyChoice& a, const StrategyChoice& b)
+{
+  return a.getName() == b.getName() && a.getStrategy() == b.getStrategy();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const StrategyChoice& sc)
+{
+  return os << "StrategyChoice("
+            << "Name: " << sc.getName() << ", "
+            << "Strategy: " << sc.getStrategy()
+            << ")";
+}
+
 } // namespace nfd
 } // namespace ndn
diff --git a/src/mgmt/nfd/strategy-choice.hpp b/src/mgmt/nfd/strategy-choice.hpp
index 8cdaa59..ec46348 100644
--- a/src/mgmt/nfd/strategy-choice.hpp
+++ b/src/mgmt/nfd/strategy-choice.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).
  *
@@ -87,6 +87,18 @@
   mutable Block m_wire;
 };
 
+bool
+operator==(const StrategyChoice& a, const StrategyChoice& b);
+
+inline bool
+operator!=(const StrategyChoice& a, const StrategyChoice& b)
+{
+  return !(a == b);
+}
+
+std::ostream&
+operator<<(std::ostream& os, const StrategyChoice& sc);
+
 } // namespace nfd
 } // namespace ndn
 
diff --git a/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp b/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp
index 4fca737..b02be0c 100644
--- a/tests/unit-tests/mgmt/nfd/strategy-choice.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/strategy-choice.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/strategy-choice.hpp"
 
 #include "boost-test.hpp"
+#include <boost/lexical_cast.hpp>
 
 namespace ndn {
 namespace nfd {
@@ -33,14 +34,12 @@
 
 BOOST_AUTO_TEST_CASE(Encode)
 {
-  StrategyChoice strategyChoice1;
-  strategyChoice1
-    .setName("/hello/world")
-    .setStrategy("/some/non/existing/strategy/name")
-    ;
+  StrategyChoice sc1;
+  sc1.setName("/hello/world")
+     .setStrategy("/some/non/existing/strategy/name");
 
   Block wire;
-  BOOST_REQUIRE_NO_THROW(wire = strategyChoice1.wireEncode());
+  BOOST_REQUIRE_NO_THROW(wire = sc1.wireEncode());
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
@@ -58,9 +57,34 @@
                                   wire.begin(), wire.end());
 
   BOOST_REQUIRE_NO_THROW(StrategyChoice(wire));
-  StrategyChoice strategyChoice2(wire);
-  BOOST_CHECK_EQUAL(strategyChoice1.getName(), strategyChoice2.getName());
-  BOOST_CHECK_EQUAL(strategyChoice1.getStrategy(), strategyChoice2.getStrategy());
+  StrategyChoice sc2(wire);
+  BOOST_CHECK_EQUAL(sc1, sc2);
+}
+
+BOOST_AUTO_TEST_CASE(Equality)
+{
+  StrategyChoice sc1, sc2;
+
+  sc1.setName("/A")
+     .setStrategy("/strategyP");
+  sc2 = sc1;
+  BOOST_CHECK_EQUAL(sc1, sc2);
+
+  sc2.setName("/B");
+  BOOST_CHECK_NE(sc1, sc2);
+
+  sc2 = sc1;
+  sc2.setStrategy("/strategyQ");
+  BOOST_CHECK_NE(sc1, sc2);
+}
+
+BOOST_AUTO_TEST_CASE(Print)
+{
+  StrategyChoice sc;
+  sc.setName("/A")
+    .setStrategy("/strategyP");
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),
+                    "StrategyChoice(Name: /A, Strategy: /strategyP)");
 }
 
 BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice