Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "management/nfd-command-options.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
| 28 | namespace tests { |
| 29 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(ManagementNfdCommandOptions) |
Junxiao Shi | 0eba1aa | 2014-10-25 09:54:08 -0700 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_CASE(Timeout) |
| 33 | { |
| 34 | CommandOptions co; |
| 35 | BOOST_CHECK_EQUAL(co.getTimeout(), CommandOptions::DEFAULT_TIMEOUT); |
| 36 | |
| 37 | co.setTimeout(time::milliseconds(7414)); |
| 38 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414)); |
| 39 | |
| 40 | BOOST_CHECK_THROW(co.setTimeout(time::milliseconds::zero()), std::out_of_range); |
| 41 | BOOST_CHECK_THROW(co.setTimeout(time::milliseconds(-1)), std::out_of_range); |
| 42 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(7414)); // unchanged after throw |
| 43 | |
| 44 | co.setTimeout(time::milliseconds(1)); |
| 45 | BOOST_CHECK_EQUAL(co.getTimeout(), time::milliseconds(1)); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(Prefix) |
| 49 | { |
| 50 | CommandOptions co; |
| 51 | BOOST_CHECK_EQUAL(co.getPrefix(), CommandOptions::DEFAULT_PREFIX); |
| 52 | |
| 53 | co.setPrefix(Name()); // empty Name is okay |
| 54 | BOOST_CHECK_EQUAL(co.getPrefix(), Name()); |
| 55 | |
| 56 | co.setPrefix("ndn:/localhop/net/example/nfd"); |
| 57 | BOOST_CHECK_EQUAL(co.getPrefix(), Name("ndn:/localhop/net/example/nfd")); |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_CASE(SigningParams) |
| 61 | { |
| 62 | CommandOptions co; |
| 63 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 64 | |
| 65 | co.setSigningIdentity("ndn:/tmp/identity"); |
| 66 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY); |
| 67 | BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name("ndn:/tmp/identity")); |
| 68 | |
| 69 | co.setSigningDefault(); // reset |
| 70 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 71 | |
| 72 | co.setSigningIdentity(Name()); // empty Name is valid identity Name |
| 73 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_IDENTITY); |
| 74 | BOOST_CHECK_EQUAL(co.getSigningIdentity(), Name()); |
| 75 | |
| 76 | co.setSigningDefault(); // reset |
| 77 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 78 | |
| 79 | co.setSigningCertificate("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01"); |
| 80 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE); |
| 81 | BOOST_CHECK_EQUAL(co.getSigningCertificate(), |
| 82 | Name("ndn:/tmp/KEY/identity/dsk-1/ID-CERT/%FD%01")); |
| 83 | |
| 84 | co.setSigningDefault(); // reset |
| 85 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 86 | |
| 87 | co.setSigningCertificate("ndn:/KEY/dsk-1/ID-CERT/%FD%01"); // minimal certificateName |
| 88 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_CERTIFICATE); |
| 89 | BOOST_CHECK_EQUAL(co.getSigningCertificate(), Name("ndn:/KEY/dsk-1/ID-CERT/%FD%01")); |
| 90 | |
| 91 | co.setSigningDefault(); // reset |
| 92 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), CommandOptions::SIGNING_PARAMS_DEFAULT); |
| 93 | |
| 94 | BOOST_CHECK_THROW(co.setSigningCertificate(IdentityCertificate()), // invalid certificate |
| 95 | std::invalid_argument); |
| 96 | BOOST_CHECK_EQUAL(co.getSigningParamsKind(), |
| 97 | CommandOptions::SIGNING_PARAMS_DEFAULT); // unchanged after throw |
| 98 | } |
| 99 | |
| 100 | BOOST_AUTO_TEST_SUITE_END() |
| 101 | |
| 102 | } // namespace tests |
| 103 | } // namespace nfd |
| 104 | } // namespace ndn |