blob: 8036d0d1ac4aa6752452e909425aee65fdf6cc54 [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 Pesavento152ef442023-04-22 02:02:29 -04003 * Copyright (c) 2013-2023 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/channel-status.hpp"
Davide Pesavento152ef442023-04-22 02:02:29 -040023#include "ndn-cxx/util/concepts.hpp"
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "tests/boost-test.hpp"
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050026
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050027#include <boost/lexical_cast.hpp>
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040028
29namespace ndn {
30namespace nfd {
31namespace tests {
32
Davide Pesavento152ef442023-04-22 02:02:29 -040033BOOST_CONCEPT_ASSERT((StatusDatasetItem<ChannelStatus>));
34
Junxiao Shi7357ef22016-09-07 02:39:37 +000035BOOST_AUTO_TEST_SUITE(Mgmt)
36BOOST_AUTO_TEST_SUITE(Nfd)
37BOOST_AUTO_TEST_SUITE(TestChannelStatus)
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040038
39BOOST_AUTO_TEST_CASE(Encode)
40{
41 ChannelStatus status1;
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050042 status1.setLocalUri("udp4://192.168.2.1");
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050043 Block wire = status1.wireEncode();
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040044
45 // These octets are obtained by the snippet below.
46 // This check is intended to detect unexpected encoding change in the future.
Davide Pesaventodf8fd8a2022-02-21 20:04:21 -050047 // for (auto it = wire.begin(); it != wire.end(); ++it) {
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050048 // printf("0x%02x, ", *it);
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040049 // }
50 static const uint8_t expected[] = {
51 0x82, 0x14, 0x81, 0x12, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
52 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x32, 0x2e, 0x31
53 };
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050054 BOOST_CHECK_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
55 wire.begin(), wire.end());
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040056
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040057 ChannelStatus status2(wire);
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050058 BOOST_CHECK_EQUAL(status1, status2);
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040059}
60
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050061BOOST_AUTO_TEST_CASE(Equality)
62{
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050063 ChannelStatus status1, status2;
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050064
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050065 status1.setLocalUri("udp4://127.0.0.1:6363");
66 status2 = status1;
67 BOOST_CHECK_EQUAL(status1, status2);
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050068
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050069 status2.setLocalUri("dev://eth0");
70 BOOST_CHECK_NE(status1, status2);
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050071}
72
73BOOST_AUTO_TEST_CASE(Print)
74{
Davide Pesavento25e3d8c2017-02-08 22:17:46 -050075 ChannelStatus status;
76 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
77 "Channel(LocalUri: )");
78
79 status.setLocalUri("udp4://127.0.0.1:6363");
80 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(status),
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050081 "Channel(LocalUri: udp4://127.0.0.1:6363)");
82}
83
Junxiao Shi7357ef22016-09-07 02:39:37 +000084BOOST_AUTO_TEST_SUITE_END() // TestChannelStatus
85BOOST_AUTO_TEST_SUITE_END() // Nfd
86BOOST_AUTO_TEST_SUITE_END() // Mgmt
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040087
88} // namespace tests
89} // namespace nfd
90} // namespace ndn