management: CommandOptions

refs #2039

Change-Id: I51111d84c73c25265d03f303fad238f314264a08
diff --git a/tests/unit-tests/management/test-nfd-command-options.cpp b/tests/unit-tests/management/test-nfd-command-options.cpp
new file mode 100644
index 0000000..b1afb35
--- /dev/null
+++ b/tests/unit-tests/management/test-nfd-command-options.cpp
@@ -0,0 +1,104 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "management/nfd-command-options.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace nfd {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(ManagementTestNfdCommandOptions)
+
+BOOST_AUTO_TEST_CASE(Timeout)
+{
+  CommandOptions co;
+  BOOST_CHECK_EQUAL(co.getTimeout(), CommandOptions::DEFAULT_TIMEOUT);
+
+  co.setTimeout(time::milliseconds(7414));
+  BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414));
+
+  BOOST_CHECK_THROW(co.setTimeout(time::milliseconds::zero()), std::out_of_range);
+  BOOST_CHECK_THROW(co.setTimeout(time::milliseconds(-1)), std::out_of_range);
+  BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414)); // unchanged after throw
+
+  co.setTimeout(time::milliseconds(1));
+  BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(1));
+}
+
+BOOST_AUTO_TEST_CASE(Prefix)
+{
+  CommandOptions co;
+  BOOST_CHECK_EQUAL(co.getPrefix(), CommandOptions::DEFAULT_PREFIX);
+
+  co.setPrefix(Name()); // empty Name is okay
+  BOOST_CHECK_EQUAL(co.getPrefix(), Name());
+
+  co.setPrefix("ndn:/localhop/net/example/nfd");
+  BOOST_CHECK_EQUAL(co.getPrefix(), Name("ndn:/localhop/net/example/nfd"));
+}
+
+BOOST_AUTO_TEST_CASE(SigningParams)
+{
+  CommandOptions co;
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT);
+
+  co.setSigningIdentity("ndn:/tmp/identity");
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY);
+  BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name("ndn:/tmp/identity"));
+
+  co.setSigningDefault(); // reset
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT);
+
+  co.setSigningIdentity(Name()); // empty Name is valid identity Name
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY);
+  BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name());
+
+  co.setSigningDefault(); // reset
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT);
+
+  co.setSigningCertificate("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01");
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE);
+  BOOST_CHECK_EQUAL(co.getSigningCertificate(),
+                    Name("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01"));
+
+  co.setSigningDefault(); // reset
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT);
+
+  co.setSigningCertificate("ndn:/KEY/dsk-1/ID-CERT/%FD%01"); // minimal certificateName
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE);
+  BOOST_CHECK_EQUAL(co.getSigningCertificate(), Name("ndn:/KEY/dsk-1/ID-CERT/%FD%01"));
+
+  co.setSigningDefault(); // reset
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT);
+
+  BOOST_CHECK_THROW(co.setSigningCertificate(IdentityCertificate()), // invalid certificate
+                    std::invalid_argument);
+  BOOST_CHECK_EQUAL(co.getSigningParamsKind(),
+                    CommandOptions::SIGNING_PARAMS_DEFAULT); // unchanged after throw
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd
+} // namespace ndn