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 | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2022 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/channel-status.hpp" |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Davide Pesavento | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 25 | |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 26 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | namespace tests { |
| 31 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 33 | BOOST_AUTO_TEST_SUITE(Nfd) |
| 34 | BOOST_AUTO_TEST_SUITE(TestChannelStatus) |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Encode) |
| 37 | { |
| 38 | ChannelStatus status1; |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 39 | status1.setLocalUri("udp4://192.168.2.1"); |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 40 | Block wire = status1.wireEncode(); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 41 | |
| 42 | // These octets are obtained by the snippet below. |
| 43 | // This check is intended to detect unexpected encoding change in the future. |
Davide Pesavento | df8fd8a | 2022-02-21 20:04:21 -0500 | [diff] [blame] | 44 | // for (auto it = wire.begin(); it != wire.end(); ++it) { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 45 | // printf("0x%02x, ", *it); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 46 | // } |
| 47 | static const uint8_t expected[] = { |
| 48 | 0x82, 0x14, 0x81, 0x12, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, |
| 49 | 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x32, 0x2e, 0x31 |
| 50 | }; |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected), |
| 52 | wire.begin(), wire.end()); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 53 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 54 | ChannelStatus status2(wire); |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(status1, status2); |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 58 | BOOST_AUTO_TEST_CASE(Equality) |
| 59 | { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 60 | ChannelStatus status1, status2; |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 61 | |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 62 | status1.setLocalUri("udp4://127.0.0.1:6363"); |
| 63 | status2 = status1; |
| 64 | BOOST_CHECK_EQUAL(status1, status2); |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 65 | |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 66 | status2.setLocalUri("dev://eth0"); |
| 67 | BOOST_CHECK_NE(status1, status2); |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_CASE(Print) |
| 71 | { |
Davide Pesavento | 25e3d8c | 2017-02-08 22:17:46 -0500 | [diff] [blame] | 72 | ChannelStatus status; |
| 73 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
| 74 | "Channel(LocalUri: )"); |
| 75 | |
| 76 | status.setLocalUri("udp4://127.0.0.1:6363"); |
| 77 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status), |
Davide Pesavento | 9f9bd8a | 2017-02-06 00:33:32 -0500 | [diff] [blame] | 78 | "Channel(LocalUri: udp4://127.0.0.1:6363)"); |
| 79 | } |
| 80 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 81 | BOOST_AUTO_TEST_SUITE_END() // TestChannelStatus |
| 82 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 83 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 84 | |
| 85 | } // namespace tests |
| 86 | } // namespace nfd |
| 87 | } // namespace ndn |