blob: 0ffe2de71559544f7ca6f3f868684ac1d5b0a3e4 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev4671bf72014-05-19 09:01:37 -04002/**
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -05003 * Copyright (c) 2013-2017 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
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#include "mgmt/nfd/channel-status.hpp"
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040023
24#include "boost-test.hpp"
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050025#include <boost/lexical_cast.hpp>
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040026
27namespace ndn {
28namespace nfd {
29namespace tests {
30
Junxiao Shi7357ef22016-09-07 02:39:37 +000031BOOST_AUTO_TEST_SUITE(Mgmt)
32BOOST_AUTO_TEST_SUITE(Nfd)
33BOOST_AUTO_TEST_SUITE(TestChannelStatus)
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040034
35BOOST_AUTO_TEST_CASE(Encode)
36{
37 ChannelStatus status1;
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050038 status1.setLocalUri("udp4://192.168.2.1");
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040039
40 Block wire;
41 BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
42
43 // These octets are obtained by the snippet below.
44 // This check is intended to detect unexpected encoding change in the future.
45 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
46 // printf("0x%02x, ", *it);
47 // }
48 static const uint8_t expected[] = {
49 0x82, 0x14, 0x81, 0x12, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
50 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x32, 0x2e, 0x31
51 };
52 BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
53 wire.begin(), wire.end());
54
55 BOOST_REQUIRE_NO_THROW(ChannelStatus(wire));
56 ChannelStatus status2(wire);
57 BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
58}
59
Davide Pesavento9f9bd8a2017-02-06 00:33:32 -050060BOOST_AUTO_TEST_CASE(Equality)
61{
62 ChannelStatus cs1, cs2;
63
64 cs1.setLocalUri("udp4://127.0.0.1:6363");
65 cs2 = cs1;
66 BOOST_CHECK_EQUAL(cs1, cs2);
67
68 cs2.setLocalUri("dev://eth0");
69 BOOST_CHECK_NE(cs1, cs2);
70}
71
72BOOST_AUTO_TEST_CASE(Print)
73{
74 ChannelStatus cs;
75 cs.setLocalUri("udp4://127.0.0.1:6363");
76 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(cs),
77 "Channel(LocalUri: udp4://127.0.0.1:6363)");
78}
79
Junxiao Shi7357ef22016-09-07 02:39:37 +000080BOOST_AUTO_TEST_SUITE_END() // TestChannelStatus
81BOOST_AUTO_TEST_SUITE_END() // Nfd
82BOOST_AUTO_TEST_SUITE_END() // Mgmt
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040083
84} // namespace tests
85} // namespace nfd
86} // namespace ndn