blob: f5b4d299a0a665e101b7dabacc5b9fc06ef94707 [file] [log] [blame]
laqinfan35731852017-08-08 06:17:39 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
laqinfan35731852017-08-08 06:17:39 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22#include "tlv/nexthop.hpp"
23
Davide Pesaventocb065f12019-12-27 01:03:34 -050024#include "tests/boost-test.hpp"
laqinfan35731852017-08-08 06:17:39 -050025
26namespace nlsr {
27namespace tlv {
28namespace test {
29
30BOOST_AUTO_TEST_SUITE(TlvTestNexthops)
31
32const uint8_t NexthopData[] =
33{
34 // Header
Tianxing Ma9ea36392018-10-05 14:32:55 -050035 0x8f, 0x1d,
laqinfan35731852017-08-08 06:17:39 -050036 // Uri
Tianxing Ma9ea36392018-10-05 14:32:55 -050037 0x8d, 0x11, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f,
38 0x70, 0x2f, 0x74, 0x6c, 0x76,
laqinfan35731852017-08-08 06:17:39 -050039 // Cost
Tianxing Ma9ea36392018-10-05 14:32:55 -050040 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66
laqinfan35731852017-08-08 06:17:39 -050041};
42
43BOOST_AUTO_TEST_CASE(NexthopEncode)
44{
45 NextHop nexthops1;
46 nexthops1.setUri("/test/nexthop/tlv");
47 nexthops1.setCost(1.65);
48
49 const ndn::Block& wire = nexthops1.wireEncode();
laqinfan35731852017-08-08 06:17:39 -050050 BOOST_REQUIRE_EQUAL_COLLECTIONS(NexthopData,
51 NexthopData + sizeof(NexthopData),
52 wire.begin(), wire.end());
53}
54
55BOOST_AUTO_TEST_CASE(NexthopDecode)
56{
57 NextHop nexthops1;
58
59 nexthops1.wireDecode(ndn::Block(NexthopData, sizeof(NexthopData)));
60
61 BOOST_REQUIRE_EQUAL(nexthops1.getUri(), "/test/nexthop/tlv");
62 BOOST_REQUIRE_EQUAL(nexthops1.getCost(), 1.65);
63}
64
65BOOST_AUTO_TEST_CASE(AdjacencyOutputStream)
66{
67 NextHop nexthops1;
68 nexthops1.setUri("/test/nexthop/tlv");
69 nexthops1.setCost(99);
70
71 std::ostringstream os;
72 os << nexthops1;
73 BOOST_CHECK_EQUAL(os.str(), "NextHop(Uri: /test/nexthop/tlv, Cost: 99)\n");
74}
75
76BOOST_AUTO_TEST_SUITE_END()
77
78} // namespace test
79} // namespace tlv
80} // namespace nlsr