encoding: Block::remove now removes all subelements of type

refs #3070

Change-Id: Ife9cb9fe9ba7e0a79d5f759c9990cbe04b0b87c3
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 693bc17..77be4f2 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -406,7 +406,7 @@
   resetWire();
 
   auto it = std::remove_if(m_subBlocks.begin(), m_subBlocks.end(),
-                           [type] (const Block& subBlock) { return subBlock.type() != type; });
+                           [type] (const Block& subBlock) { return subBlock.type() == type; });
   m_subBlocks.resize(it - m_subBlocks.begin());
 }
 
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index 9407ccf..0552755 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -249,6 +249,11 @@
   element_const_iterator
   find(uint32_t type) const;
 
+  /**
+   * @brief remove all subelements of \p type
+   * @param type TLV-TYPE of subelements to remove
+   * @pre parse() has been invoked
+   */
   void
   remove(uint32_t type);
 
diff --git a/tests/unit-tests/encoding/block.t.cpp b/tests/unit-tests/encoding/block.t.cpp
index 38fc2f2..cc90ede 100644
--- a/tests/unit-tests/encoding/block.t.cpp
+++ b/tests/unit-tests/encoding/block.t.cpp
@@ -477,6 +477,27 @@
   BOOST_CHECK_EQUAL(*(newIt - 1) == firstBlock, true);
 }
 
+BOOST_AUTO_TEST_CASE(Remove)
+{
+  Block block(tlv::Data);
+  block.push_back(makeNonNegativeIntegerBlock(tlv::ContentType, 0));
+  block.push_back(makeNonNegativeIntegerBlock(tlv::FreshnessPeriod, 123));
+  block.push_back(makeStringBlock(tlv::Name, "ndn:/test-prefix"));
+  block.push_back(makeNonNegativeIntegerBlock(tlv::ContentType, 2));
+  block.push_back(makeNonNegativeIntegerBlock(tlv::ContentType, 1));
+
+  BOOST_CHECK_EQUAL(5, block.elements_size());
+  BOOST_REQUIRE_NO_THROW(block.remove(tlv::ContentType));
+  BOOST_CHECK_EQUAL(2, block.elements_size());
+
+  Block::element_container elements = block.elements();
+
+  BOOST_CHECK_EQUAL(tlv::FreshnessPeriod, elements[0].type());
+  BOOST_CHECK_EQUAL(123, readNonNegativeInteger(elements[0]));
+  BOOST_CHECK_EQUAL(tlv::Name, elements[1].type());
+  BOOST_CHECK(readString(elements[1]).compare("ndn:/test-prefix") == 0);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace tests