Junxiao Shi | 95fdebe | 2014-11-08 23:45:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Teng Liang | b4ecadc | 2017-03-25 10:55:40 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Junxiao Shi | 95fdebe | 2014-11-08 23:45:03 -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 | */ |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 21 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 22 | #include "encoding/nfd-constants.hpp" |
Junxiao Shi | 95fdebe | 2014-11-08 23:45:03 -0700 | [diff] [blame] | 23 | |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 24 | #include "boost-test.hpp" |
| 25 | #include <boost/lexical_cast.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(Encoding) |
| 32 | BOOST_AUTO_TEST_SUITE(TestNfdConstants) |
| 33 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 34 | BOOST_AUTO_TEST_CASE(PrintFaceScope) |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 35 | { |
| 36 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NONE), "none"); |
| 37 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NON_LOCAL), "non-local"); |
| 38 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_LOCAL), "local"); |
| 39 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceScope>(126)), "126"); |
| 40 | } |
| 41 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 42 | BOOST_AUTO_TEST_CASE(PrintFacePersistency) |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 43 | { |
| 44 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_NONE), "none"); |
| 45 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_ON_DEMAND), "on-demand"); |
| 46 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERSISTENT), "persistent"); |
| 47 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERMANENT), "permanent"); |
| 48 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FacePersistency>(110)), "110"); |
| 49 | } |
| 50 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(PrintLinkType) |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 52 | { |
| 53 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_NONE), "none"); |
| 54 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_POINT_TO_POINT), "point-to-point"); |
| 55 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_MULTI_ACCESS), "multi-access"); |
Teng Liang | b4ecadc | 2017-03-25 10:55:40 -0500 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_AD_HOC), "adhoc"); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<LinkType>(104)), "104"); |
| 58 | } |
| 59 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 60 | BOOST_AUTO_TEST_CASE(PrintFaceEventKind) |
| 61 | { |
| 62 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_NONE), "none"); |
| 63 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_CREATED), "created"); |
| 64 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DESTROYED), "destroyed"); |
| 65 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_UP), "up"); |
| 66 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DOWN), "down"); |
| 67 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceEventKind>(175)), "175"); |
| 68 | } |
| 69 | |
Junxiao Shi | 6336c5f | 2017-04-04 22:16:03 +0000 | [diff] [blame] | 70 | BOOST_AUTO_TEST_CASE(ParseRouteOrigin) |
| 71 | { |
| 72 | auto expectSuccess = [] (const std::string& input, RouteOrigin expected) { |
| 73 | std::istringstream is(input); |
| 74 | RouteOrigin routeOrigin; |
| 75 | is >> routeOrigin; |
| 76 | |
| 77 | BOOST_TEST_MESSAGE("parsing " << input); |
| 78 | BOOST_CHECK_EQUAL(routeOrigin, expected); |
| 79 | }; |
| 80 | |
| 81 | auto expectFail = [] (const std::string& input) { |
| 82 | std::istringstream is(input); |
| 83 | RouteOrigin routeOrigin; |
| 84 | is >> routeOrigin; |
| 85 | |
| 86 | BOOST_TEST_MESSAGE("parsing " << input); |
| 87 | BOOST_CHECK(is.fail()); |
| 88 | BOOST_CHECK_EQUAL(routeOrigin, ROUTE_ORIGIN_NONE); |
| 89 | }; |
| 90 | |
| 91 | expectSuccess("none", ROUTE_ORIGIN_NONE); |
| 92 | expectSuccess("App", ROUTE_ORIGIN_APP); |
| 93 | expectSuccess("AutoReg", ROUTE_ORIGIN_AUTOREG); |
| 94 | expectSuccess("Client", ROUTE_ORIGIN_CLIENT); |
| 95 | expectSuccess("AutoConf", ROUTE_ORIGIN_AUTOCONF); |
| 96 | expectSuccess("NLSR", ROUTE_ORIGIN_NLSR); |
| 97 | expectSuccess("static", ROUTE_ORIGIN_STATIC); |
| 98 | expectSuccess("27", static_cast<RouteOrigin>(27)); |
| 99 | |
| 100 | expectSuccess(" app", ROUTE_ORIGIN_APP); |
| 101 | expectSuccess("app ", ROUTE_ORIGIN_APP); |
| 102 | expectSuccess(" app ", ROUTE_ORIGIN_APP); |
| 103 | |
| 104 | expectFail("unrecognized"); |
| 105 | expectFail("-1"); |
| 106 | expectFail("0.1"); |
| 107 | expectFail("65537"); |
| 108 | expectFail(""); |
| 109 | } |
| 110 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(PrintRouteOrigin) |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 112 | { |
| 113 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NONE), "none"); |
| 114 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_APP), "app"); |
| 115 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOREG), "autoreg"); |
| 116 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_CLIENT), "client"); |
| 117 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOCONF), "autoconf"); |
| 118 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NLSR), "nlsr"); |
| 119 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_STATIC), "static"); |
| 120 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteOrigin>(27)), "27"); |
| 121 | } |
| 122 | |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 123 | BOOST_AUTO_TEST_CASE(PrintRouteFlags) |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 124 | { |
| 125 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAGS_NONE), "none"); |
| 126 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CHILD_INHERIT), "child-inherit"); |
| 127 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CAPTURE), "capture"); |
| 128 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>( |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 129 | ROUTE_FLAG_CHILD_INHERIT | ROUTE_FLAG_CAPTURE)), "child-inherit|capture"); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>( |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 131 | ROUTE_FLAG_CAPTURE | 0x9c)), "capture|0x9c"); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | BOOST_AUTO_TEST_SUITE_END() // TestNfdConstants |
| 135 | BOOST_AUTO_TEST_SUITE_END() // Encoding |
| 136 | |
| 137 | } // namespace tests |
| 138 | } // namespace nfd |
| 139 | } // namespace ndn |