face: API to remove all pending Interests

Change-Id: Iac341689270698b66ec6228c27e23ea6cf3e5e59
Refs: #3300
diff --git a/src/detail/face-impl.hpp b/src/detail/face-impl.hpp
index 98fda53..808355f 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -167,6 +167,12 @@
   }
 
   void
+  asyncRemoveAllPendingInterests()
+  {
+    m_pendingInterestTable.clear();
+  }
+
+  void
   asyncPutData(const shared_ptr<const Data>& data)
   {
     this->ensureConnected(true);
diff --git a/src/face.cpp b/src/face.cpp
index 336e85e..9d6b0dd 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -218,6 +218,12 @@
   m_ioService.post([=] { m_impl->asyncRemovePendingInterest(pendingInterestId); });
 }
 
+void
+Face::removeAllPendingInterests()
+{
+  m_ioService.post([=] { m_impl->asyncRemoveAllPendingInterests(); });
+}
+
 size_t
 Face::getNPendingInterests() const
 {
diff --git a/src/face.hpp b/src/face.hpp
index a07e293..e07f541 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -273,6 +273,12 @@
   removePendingInterest(const PendingInterestId* pendingInterestId);
 
   /**
+   * @brief Cancel all previously expressed Interests
+   */
+  void
+  removeAllPendingInterests();
+
+  /**
    * @brief Get number of pending Interests
    */
   size_t
diff --git a/tests/unit-tests/face.t.cpp b/tests/unit-tests/face.t.cpp
index 4127655..438dde5 100644
--- a/tests/unit-tests/face.t.cpp
+++ b/tests/unit-tests/face.t.cpp
@@ -243,6 +243,31 @@
   advanceClocks(time::milliseconds(10), 100);
 }
 
+BOOST_AUTO_TEST_CASE(removeAllPendingInterests)
+{
+  face->expressInterest(Interest("/Hello/World/0", time::milliseconds(50)),
+                        bind([] { BOOST_FAIL("Unexpected data"); }),
+                        bind([] { BOOST_FAIL("Unexpected nack"); }),
+                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
+
+  face->expressInterest(Interest("/Hello/World/1", time::milliseconds(50)),
+                        bind([] { BOOST_FAIL("Unexpected data"); }),
+                        bind([] { BOOST_FAIL("Unexpected nack"); }),
+                        bind([] { BOOST_FAIL("Unexpected timeout"); }));
+
+  advanceClocks(time::milliseconds(10));
+
+  face->removeAllPendingInterests();
+  advanceClocks(time::milliseconds(10));
+
+  BOOST_CHECK_EQUAL(face->getNPendingInterests(), 0);
+
+  face->receive(*util::makeData("/Hello/World/0"));
+  face->receive(*util::makeData("/Hello/World/1"));
+  advanceClocks(time::milliseconds(10), 100);
+}
+
+
 BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter)
 {
   size_t nInterests = 0;