blob: 94c30e80f790e1230cc8b671d566a9c189208d62 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -05003 * Copyright (c) 2013-2022 Regents of the University of California.
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040020 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/mgmt/nfd/strategy-choice.hpp"
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050025
Junxiao Shibc6beb12017-01-11 23:20:39 +000026#include <boost/lexical_cast.hpp>
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040027
28namespace ndn {
29namespace nfd {
30namespace tests {
31
Junxiao Shi7357ef22016-09-07 02:39:37 +000032BOOST_AUTO_TEST_SUITE(Mgmt)
33BOOST_AUTO_TEST_SUITE(Nfd)
34BOOST_AUTO_TEST_SUITE(TestStrategyChoice)
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040035
36BOOST_AUTO_TEST_CASE(Encode)
37{
Junxiao Shibc6beb12017-01-11 23:20:39 +000038 StrategyChoice sc1;
39 sc1.setName("/hello/world")
40 .setStrategy("/some/non/existing/strategy/name");
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050041 Block wire = sc1.wireEncode();
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040042
43 // These octets are obtained by the snippet below.
44 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050045 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050046 // printf("0x%02x, ", *it);
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040047 // }
48 static const uint8_t expected[] = {
49 0x80, 0x39, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x08, 0x05, 0x77,
50 0x6f, 0x72, 0x6c, 0x64, 0x6b, 0x27, 0x07, 0x25, 0x08, 0x04, 0x73, 0x6f, 0x6d, 0x65,
51 0x08, 0x03, 0x6e, 0x6f, 0x6e, 0x08, 0x08, 0x65, 0x78, 0x69, 0x73, 0x74, 0x69, 0x6e,
52 0x67, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x08, 0x04, 0x6e,
53 0x61, 0x6d, 0x65
54 };
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050055 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
56 wire.begin(), wire.end());
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040057
Junxiao Shibc6beb12017-01-11 23:20:39 +000058 StrategyChoice sc2(wire);
59 BOOST_CHECK_EQUAL(sc1, sc2);
60}
61
62BOOST_AUTO_TEST_CASE(Equality)
63{
64 StrategyChoice sc1, sc2;
65
66 sc1.setName("/A")
67 .setStrategy("/strategyP");
68 sc2 = sc1;
69 BOOST_CHECK_EQUAL(sc1, sc2);
70
71 sc2.setName("/B");
72 BOOST_CHECK_NE(sc1, sc2);
73
74 sc2 = sc1;
75 sc2.setStrategy("/strategyQ");
76 BOOST_CHECK_NE(sc1, sc2);
77}
78
79BOOST_AUTO_TEST_CASE(Print)
80{
81 StrategyChoice sc;
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050082 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),
83 "StrategyChoice(Name: /, Strategy: /)");
84
Junxiao Shibc6beb12017-01-11 23:20:39 +000085 sc.setName("/A")
86 .setStrategy("/strategyP");
87 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc),
88 "StrategyChoice(Name: /A, Strategy: /strategyP)");
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040089}
90
Junxiao Shi7357ef22016-09-07 02:39:37 +000091BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
92BOOST_AUTO_TEST_SUITE_END() // Nfd
93BOOST_AUTO_TEST_SUITE_END() // Mgmt
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040094
95} // namespace tests
96} // namespace nfd
97} // namespace ndn