Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/mgmt/nfd/strategy-choice.hpp" |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 23 | #include "ndn-cxx/util/concepts.hpp" |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "tests/boost-test.hpp" |
Davide Pesavento | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 26 | |
Junxiao Shi | bc6beb1 | 2017-01-11 23:20:39 +0000 | [diff] [blame] | 27 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 28 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 29 | namespace ndn::tests { |
| 30 | |
| 31 | using namespace ndn::nfd; |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 32 | |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 33 | BOOST_CONCEPT_ASSERT((StatusDatasetItem<StrategyChoice>)); |
| 34 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 36 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 37 | BOOST_AUTO_TEST_SUITE(TestStrategyChoice) |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 38 | |
| 39 | BOOST_AUTO_TEST_CASE(Encode) |
| 40 | { |
Junxiao Shi | bc6beb1 | 2017-01-11 23:20:39 +0000 | [diff] [blame] | 41 | StrategyChoice sc1; |
| 42 | sc1.setName("/hello/world") |
| 43 | .setStrategy("/some/non/existing/strategy/name"); |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 44 | Block wire = sc1.wireEncode(); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 45 | |
| 46 | // These octets are obtained by the snippet below. |
| 47 | // This check is intended to detect unexpected encoding change in the future. |
Davide Pesavento | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 48 | // for (auto it = wire.begin(); it != wire.end(); ++it) { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 49 | // printf("0x%02x, ", *it); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 50 | // } |
| 51 | static const uint8_t expected[] = { |
| 52 | 0x80, 0x39, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x08, 0x05, 0x77, |
| 53 | 0x6f, 0x72, 0x6c, 0x64, 0x6b, 0x27, 0x07, 0x25, 0x08, 0x04, 0x73, 0x6f, 0x6d, 0x65, |
| 54 | 0x08, 0x03, 0x6e, 0x6f, 0x6e, 0x08, 0x08, 0x65, 0x78, 0x69, 0x73, 0x74, 0x69, 0x6e, |
| 55 | 0x67, 0x08, 0x08, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x08, 0x04, 0x6e, |
| 56 | 0x61, 0x6d, 0x65 |
| 57 | }; |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 59 | wire.begin(), wire.end()); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 60 | |
Junxiao Shi | bc6beb1 | 2017-01-11 23:20:39 +0000 | [diff] [blame] | 61 | StrategyChoice sc2(wire); |
| 62 | BOOST_CHECK_EQUAL(sc1, sc2); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(Equality) |
| 66 | { |
| 67 | StrategyChoice sc1, sc2; |
| 68 | |
| 69 | sc1.setName("/A") |
| 70 | .setStrategy("/strategyP"); |
| 71 | sc2 = sc1; |
| 72 | BOOST_CHECK_EQUAL(sc1, sc2); |
| 73 | |
| 74 | sc2.setName("/B"); |
| 75 | BOOST_CHECK_NE(sc1, sc2); |
| 76 | |
| 77 | sc2 = sc1; |
| 78 | sc2.setStrategy("/strategyQ"); |
| 79 | BOOST_CHECK_NE(sc1, sc2); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(Print) |
| 83 | { |
| 84 | StrategyChoice sc; |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 85 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc), |
| 86 | "StrategyChoice(Name: /, Strategy: /)"); |
| 87 | |
Junxiao Shi | bc6beb1 | 2017-01-11 23:20:39 +0000 | [diff] [blame] | 88 | sc.setName("/A") |
| 89 | .setStrategy("/strategyP"); |
| 90 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sc), |
| 91 | "StrategyChoice(Name: /A, Strategy: /strategyP)"); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 94 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice |
| 95 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 96 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 97 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 98 | } // namespace ndn::tests |