blob: c2149a1d668648a2bb433191ccb2857598d51fb7 [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/*
Teng Liangc93c2ce2018-04-29 14:19:27 -07003 * Copyright (c) 2013-2018 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
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080022#include "encoding/nfd-constants.hpp"
Junxiao Shi95fdebe2014-11-08 23:45:03 -070023
Junxiao Shi18ef4de2015-10-17 16:58:23 +000024#include "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 Pesaventoa84f4642017-08-23 16:14:51 -040027#include <sstream>
Junxiao Shi18ef4de2015-10-17 16:58:23 +000028
29namespace ndn {
30namespace nfd {
31namespace tests {
32
33BOOST_AUTO_TEST_SUITE(Encoding)
34BOOST_AUTO_TEST_SUITE(TestNfdConstants)
35
Davide Pesaventoe55589c2017-02-20 03:02:51 -050036BOOST_AUTO_TEST_CASE(PrintFaceScope)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000037{
38 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NONE), "none");
39 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_NON_LOCAL), "non-local");
40 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_SCOPE_LOCAL), "local");
41 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceScope>(126)), "126");
42}
43
Davide Pesaventoe55589c2017-02-20 03:02:51 -050044BOOST_AUTO_TEST_CASE(PrintFacePersistency)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000045{
46 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_NONE), "none");
47 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_ON_DEMAND), "on-demand");
48 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERSISTENT), "persistent");
49 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_PERSISTENCY_PERMANENT), "permanent");
50 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FacePersistency>(110)), "110");
51}
52
Davide Pesaventoe55589c2017-02-20 03:02:51 -050053BOOST_AUTO_TEST_CASE(PrintLinkType)
Junxiao Shi18ef4de2015-10-17 16:58:23 +000054{
55 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_NONE), "none");
56 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_POINT_TO_POINT), "point-to-point");
57 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_MULTI_ACCESS), "multi-access");
Teng Liangb4ecadc2017-03-25 10:55:40 -050058 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(LINK_TYPE_AD_HOC), "adhoc");
Junxiao Shi18ef4de2015-10-17 16:58:23 +000059 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<LinkType>(104)), "104");
60}
61
Davide Pesaventoe55589c2017-02-20 03:02:51 -050062BOOST_AUTO_TEST_CASE(PrintFaceEventKind)
63{
64 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_NONE), "none");
65 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_CREATED), "created");
66 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DESTROYED), "destroyed");
67 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_UP), "up");
68 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(FACE_EVENT_DOWN), "down");
69 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<FaceEventKind>(175)), "175");
70}
71
Junxiao Shi6336c5f2017-04-04 22:16:03 +000072BOOST_AUTO_TEST_CASE(ParseRouteOrigin)
73{
74 auto expectSuccess = [] (const std::string& input, RouteOrigin expected) {
75 std::istringstream is(input);
76 RouteOrigin routeOrigin;
77 is >> routeOrigin;
78
79 BOOST_TEST_MESSAGE("parsing " << input);
80 BOOST_CHECK_EQUAL(routeOrigin, expected);
81 };
82
83 auto expectFail = [] (const std::string& input) {
84 std::istringstream is(input);
85 RouteOrigin routeOrigin;
86 is >> routeOrigin;
87
88 BOOST_TEST_MESSAGE("parsing " << input);
89 BOOST_CHECK(is.fail());
90 BOOST_CHECK_EQUAL(routeOrigin, ROUTE_ORIGIN_NONE);
91 };
92
93 expectSuccess("none", ROUTE_ORIGIN_NONE);
94 expectSuccess("App", ROUTE_ORIGIN_APP);
95 expectSuccess("AutoReg", ROUTE_ORIGIN_AUTOREG);
96 expectSuccess("Client", ROUTE_ORIGIN_CLIENT);
97 expectSuccess("AutoConf", ROUTE_ORIGIN_AUTOCONF);
98 expectSuccess("NLSR", ROUTE_ORIGIN_NLSR);
Teng Liangc93c2ce2018-04-29 14:19:27 -070099 expectSuccess("SelfLearning", ROUTE_ORIGIN_SELFLEARNING);
Junxiao Shi6336c5f2017-04-04 22:16:03 +0000100 expectSuccess("static", ROUTE_ORIGIN_STATIC);
101 expectSuccess("27", static_cast<RouteOrigin>(27));
102
103 expectSuccess(" app", ROUTE_ORIGIN_APP);
104 expectSuccess("app ", ROUTE_ORIGIN_APP);
105 expectSuccess(" app ", ROUTE_ORIGIN_APP);
106
107 expectFail("unrecognized");
108 expectFail("-1");
109 expectFail("0.1");
110 expectFail("65537");
111 expectFail("");
112}
113
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500114BOOST_AUTO_TEST_CASE(PrintRouteOrigin)
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000115{
116 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NONE), "none");
117 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_APP), "app");
118 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOREG), "autoreg");
119 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_CLIENT), "client");
120 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_AUTOCONF), "autoconf");
121 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_NLSR), "nlsr");
Teng Liangc93c2ce2018-04-29 14:19:27 -0700122 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_SELFLEARNING), "selflearning");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000123 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_ORIGIN_STATIC), "static");
124 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteOrigin>(27)), "27");
125}
126
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500127BOOST_AUTO_TEST_CASE(PrintRouteFlags)
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000128{
129 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAGS_NONE), "none");
130 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CHILD_INHERIT), "child-inherit");
131 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(ROUTE_FLAG_CAPTURE), "capture");
132 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500133 ROUTE_FLAG_CHILD_INHERIT | ROUTE_FLAG_CAPTURE)), "child-inherit|capture");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000134 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<RouteFlags>(
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500135 ROUTE_FLAG_CAPTURE | 0x9c)), "capture|0x9c");
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000136}
137
138BOOST_AUTO_TEST_SUITE_END() // TestNfdConstants
139BOOST_AUTO_TEST_SUITE_END() // Encoding
140
141} // namespace tests
142} // namespace nfd
143} // namespace ndn