blob: e1bc11165a4a6173f70fc64dc166493c596518f1 [file] [log] [blame]
Junxiao Shi95fdebe2014-11-08 23:45:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa84f4642017-08-23 16:14:51 -04002/*
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -05003 * Copyright (c) 2013-2020 Regents of the University of California.
Junxiao Shi95fdebe2014-11-08 23:45:03 -07004 *
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 Pesaventoeee3e822016-11-26 19:19:34 +010021
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/encoding/nfd-constants.hpp"
Junxiao Shi95fdebe2014-11-08 23:45:03 -070023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesaventoa84f4642017-08-23 16:14:51 -040025
Junxiao Shi18ef4de2015-10-17 16:58:23 +000026#include <boost/lexical_cast.hpp>
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -050027#include <iomanip>
Davide Pesaventoa84f4642017-08-23 16:14:51 -040028#include <sstream>
Junxiao Shi18ef4de2015-10-17 16:58:23 +000029
30namespace ndn {
31namespace nfd {
32namespace tests {
33
34BOOST_AUTO_TEST_SUITE(Encoding)
35BOOST_AUTO_TEST_SUITE(TestNfdConstants)
36
Davide Pesaventoe55589c2017-02-20 03:02:51 -050037BOOST_AUTO_TEST_CASE(PrintFaceScope)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000038{
39 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NONE), "none");
40 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NON_LOCAL), "non-local");
41 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_LOCAL), "local");
42 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceScope>(126)), "126");
43}
44
Davide Pesaventoe55589c2017-02-20 03:02:51 -050045BOOST_AUTO_TEST_CASE(PrintFacePersistency)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000046{
47 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_NONE), "none");
48 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_ON_DEMAND), "on-demand");
49 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERSISTENT), "persistent");
50 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERMANENT), "permanent");
51 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FacePersistency>(110)), "110");
52}
53
Davide Pesaventoe55589c2017-02-20 03:02:51 -050054BOOST_AUTO_TEST_CASE(PrintLinkType)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000055{
56 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_NONE), "none");
57 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_POINT_TO_POINT), "point-to-point");
58 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_MULTI_ACCESS), "multi-access");
Teng Liangb4ecadc2017-03-25 10:55:40 -050059 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_AD_HOC), "adhoc");
Junxiao Shi18ef4de2015-10-17 16:58:23 +000060 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<LinkType>(104)), "104");
61}
62
Davide Pesaventoe55589c2017-02-20 03:02:51 -050063BOOST_AUTO_TEST_CASE(PrintFaceEventKind)
64{
65 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_NONE), "none");
66 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_CREATED), "created");
67 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DESTROYED), "destroyed");
68 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_UP), "up");
69 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DOWN), "down");
70 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceEventKind>(175)), "175");
71}
72
Junxiao Shi6336c5f2017-04-04 22:16:03 +000073BOOST_AUTO_TEST_CASE(ParseRouteOrigin)
74{
75 auto expectSuccess = [] (const std::string& input, RouteOrigin expected) {
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -050076 BOOST_TEST_CONTEXT("input = " << std::quoted(input)) {
77 std::istringstream is(input);
78 RouteOrigin routeOrigin;
79 is >> routeOrigin;
Junxiao Shi6336c5f2017-04-04 22:16:03 +000080
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -050081 BOOST_CHECK(!is.fail());
82 BOOST_CHECK_EQUAL(routeOrigin, expected);
83 }
Junxiao Shi6336c5f2017-04-04 22:16:03 +000084 };
85
86 auto expectFail = [] (const std::string& input) {
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -050087 BOOST_TEST_CONTEXT("input = " << std::quoted(input)) {
88 std::istringstream is(input);
89 RouteOrigin routeOrigin;
90 is >> routeOrigin;
Junxiao Shi6336c5f2017-04-04 22:16:03 +000091
Davide Pesavento1a4a7bf2020-12-04 22:30:46 -050092 BOOST_CHECK(is.fail());
93 BOOST_CHECK_EQUAL(routeOrigin, ROUTE_ORIGIN_NONE);
94 }
Junxiao Shi6336c5f2017-04-04 22:16:03 +000095 };
96
97 expectSuccess("none", ROUTE_ORIGIN_NONE);
98 expectSuccess("App", ROUTE_ORIGIN_APP);
99 expectSuccess("AutoReg", ROUTE_ORIGIN_AUTOREG);
100 expectSuccess("Client", ROUTE_ORIGIN_CLIENT);
101 expectSuccess("AutoConf", ROUTE_ORIGIN_AUTOCONF);
102 expectSuccess("NLSR", ROUTE_ORIGIN_NLSR);
Teng Liang502b4792018-08-29 10:29:38 -0700103 expectSuccess("PrefixAnn", ROUTE_ORIGIN_PREFIXANN);
Junxiao Shi6336c5f2017-04-04 22:16:03 +0000104 expectSuccess("static", ROUTE_ORIGIN_STATIC);
105 expectSuccess("27", static_cast<RouteOrigin>(27));
106
107 expectSuccess(" app", ROUTE_ORIGIN_APP);
108 expectSuccess("app ", ROUTE_ORIGIN_APP);
109 expectSuccess(" app ", ROUTE_ORIGIN_APP);
110
111 expectFail("unrecognized");
112 expectFail("-1");
113 expectFail("0.1");
114 expectFail("65537");
115 expectFail("");
116}
117
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500118BOOST_AUTO_TEST_CASE(PrintRouteOrigin)
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000119{
120 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NONE), "none");
121 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_APP), "app");
122 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOREG), "autoreg");
123 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_CLIENT), "client");
124 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOCONF), "autoconf");
125 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NLSR), "nlsr");
Teng Liang502b4792018-08-29 10:29:38 -0700126 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_PREFIXANN), "prefixann");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000127 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_STATIC), "static");
128 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteOrigin>(27)), "27");
129}
130
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500131BOOST_AUTO_TEST_CASE(PrintRouteFlags)
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000132{
133 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAGS_NONE), "none");
134 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CHILD_INHERIT), "child-inherit");
135 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CAPTURE), "capture");
136 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500137 ROUTE_FLAG_CHILD_INHERIT | ROUTE_FLAG_CAPTURE)), "child-inherit|capture");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000138 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500139 ROUTE_FLAG_CAPTURE | 0x9c)), "capture|0x9c");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000140}
141
142BOOST_AUTO_TEST_SUITE_END() // TestNfdConstants
143BOOST_AUTO_TEST_SUITE_END() // Encoding
144
145} // namespace tests
146} // namespace nfd
147} // namespace ndn