management: nfd::ForwarderStatus

nfd::Status is renamed to ForwarderStatus.
Fields are swapped according to new Management protocol.

ForwarderStatus::wireEncode uses Content as outermost element.

refs #1422

Change-Id: I388d5eb56eed2a9958a27e51e010c696e9608ca9
diff --git a/tests/management/nfd-forwarder-status.cpp b/tests/management/nfd-forwarder-status.cpp
new file mode 100644
index 0000000..123459e
--- /dev/null
+++ b/tests/management/nfd-forwarder-status.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "management/nfd-forwarder-status.hpp"
+// Having a separate compilation unit is necessary to ensure .hpp can compile on its own.
+#include "data.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace ndn {
+namespace nfd {
+
+BOOST_AUTO_TEST_SUITE(NfdForwarderStatus)
+
+BOOST_AUTO_TEST_CASE(Encode)
+{
+  ForwarderStatus status1;
+  status1.setNfdVersion(1014210635);
+  status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325)));
+  status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272)));
+  status1.setNNameTreeEntries(1849943160);
+  status1.setNFibEntries(621739748);
+  status1.setNPitEntries(482129741);
+  status1.setNMeasurementsEntries(1771725298);
+  status1.setNCsEntries(1264968688);
+  status1.setNInInterests(612811615);
+  status1.setNInDatas(1843576050);
+  status1.setNOutInterests(952144445);
+  status1.setNOutDatas(138198826);
+
+  EncodingBuffer buffer;
+  status1.wireEncode(buffer);
+  Block wire = buffer.block();
+
+  // These octets are obtained by the snippet below.
+  // This check is intended to detect unexpected encoding change in the future.
+  //for (Buffer::iterator it = buffer.begin(); it != buffer.end(); ++it) {
+  //  printf("0x%02x, ", *it);
+  //}
+  static const uint8_t expected[] = {
+    0x15, 0x50, 0x80, 0x04, 0x3c, 0x73, 0xa0, 0x4b, 0x81, 0x08, 0x00, 0x00,
+    0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00, 0xce,
+    0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84, 0x04,
+    0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86, 0x04,
+    0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, 0x04,
+    0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x92, 0x04,
+    0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, 0x3c, 0xbf, 0x2a
+  };
+  BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+                                  wire.begin(), wire.end());
+
+  Data data;
+  data.setContent(wire);
+
+  ForwarderStatus status2(data.getContent());
+  BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
+  BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
+  BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp());
+  BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries());
+  BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries());
+  BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries());
+  BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries());
+  BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
+  BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
+  BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
+  BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
+  BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace nfd
+} // namespace ndn
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index de9a1bb..6e3de4d 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -9,8 +9,6 @@
 #include "management/nfd-face-management-options.hpp"
 #include "management/nfd-face-event-notification.hpp"
 #include "management/nfd-face-status.hpp"
-#include "management/nfd-status.hpp"
-#include "data.hpp"
 
 #include <boost/test/unit_test.hpp>
 #include <boost/test/output_test_stream.hpp>
@@ -228,43 +226,6 @@
   }
 }
 
-BOOST_AUTO_TEST_CASE(NfdStatusEncode)
-{
-  Status status1;
-  status1.setNfdVersion(1014210635);
-  status1.setStartTimestamp(time::fromUnixTimestamp(time::seconds(375193249)));
-  status1.setCurrentTimestamp(time::fromUnixTimestamp(time::seconds(1886109034)));
-  status1.setNNameTreeEntries(1849943160);
-  status1.setNFibEntries(621739748);
-  status1.setNPitEntries(482129741);
-  status1.setNMeasurementsEntries(1771725298);
-  status1.setNCsEntries(1264968688);
-  status1.setNInInterests(612811615);
-  status1.setNOutInterests(952144445);
-  status1.setNInDatas(1843576050);
-  status1.setNOutDatas(138198826);
-
-  EncodingBuffer buffer;
-  status1.wireEncode(buffer);
-
-  Data data;
-  data.setContent(buffer.buf(), buffer.size());
-
-  Status status2(data.getContent());
-  BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
-  BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
-  BOOST_CHECK_EQUAL(status1.getCurrentTimestamp(), status2.getCurrentTimestamp());
-  BOOST_CHECK_EQUAL(status1.getNNameTreeEntries(), status2.getNNameTreeEntries());
-  BOOST_CHECK_EQUAL(status1.getNFibEntries(), status2.getNFibEntries());
-  BOOST_CHECK_EQUAL(status1.getNPitEntries(), status2.getNPitEntries());
-  BOOST_CHECK_EQUAL(status1.getNMeasurementsEntries(), status2.getNMeasurementsEntries());
-  BOOST_CHECK_EQUAL(status1.getNCsEntries(), status2.getNCsEntries());
-  BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
-  BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
-  BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
-  BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
-}
-
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace nfd
diff --git a/tests/security/identity-fixture.cpp b/tests/security/identity-fixture.cpp
index 2cc7e4f..1c286e2 100644
--- a/tests/security/identity-fixture.cpp
+++ b/tests/security/identity-fixture.cpp
@@ -19,7 +19,13 @@
   IdentityFixture()
   {
     // save the old default identity
-    m_oldDefaultIdentity = m_keyChain.getDefaultIdentity();
+    try {
+      m_oldDefaultIdentity = m_keyChain.getDefaultIdentity();
+      m_hasOldDefaultIdentity = true;
+    }
+    catch (SecPublicInfo::Error& e) {
+      m_hasOldDefaultIdentity = false;
+    }
 
     m_newIdentity.set("/ndn-cpp-dev-test-identity");
     m_newIdentity.appendVersion();
@@ -35,14 +41,19 @@
   ~IdentityFixture()
   {
     // recover the old default setting
-    m_keyChain.setDefaultIdentity(m_oldDefaultIdentity);
+    if (m_hasOldDefaultIdentity) {
+      m_keyChain.setDefaultIdentity(m_oldDefaultIdentity);
+    }
 
     // remove the temporarily created identity and certificates
+    // XXX This has no effect if oldDefaultIdentity doesn't exist.
+    //     newIdentity would be kept as default.
     m_keyChain.deleteIdentity(m_newIdentity);
   }
 
 private:
   KeyChain m_keyChain;
+  bool m_hasOldDefaultIdentity;
   Name m_oldDefaultIdentity;
   Name m_newIdentity;
 };