blob: b271a6254bc0797f386e2c63352875a565a96f25 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Tianxing Ma9ea36392018-10-05 14:32:55 -05003 * Copyright (c) 2014-2019, The University of Memphis,
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08004 * 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/adjacency.hpp"
23
24#include "../boost-test.hpp"
25
26namespace nlsr {
Tianxing Ma9ea36392018-10-05 14:32:55 -050027namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080028namespace test {
29
30BOOST_AUTO_TEST_SUITE(TlvTestAdjacency)
31
32const uint8_t AdjacencyData[] =
33{
34 // Header
35 0x84, 0x30,
36 // Name
37 0x07, 0x16, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x09, 0x61, 0x64, 0x6a, 0x61,
38 0x63, 0x65, 0x6e, 0x63, 0x79, 0x08, 0x03, 0x74, 0x6c, 0x76,
39 // Uri
40 0x8d, 0x13, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x61, 0x64, 0x6a, 0x61, 0x63, 0x65,
41 0x6e, 0x63, 0x79, 0x2f, 0x74, 0x6c, 0x76,
42 // Cost
43 0x8c, 0x01, 0x80
44};
45
46BOOST_AUTO_TEST_CASE(AdjacencyEncode)
47{
48 Adjacency adjacency;
49 adjacency.setName("/test/adjacency/tlv");
50 adjacency.setUri("/test/adjacency/tlv");
51 adjacency.setCost(128);
52
53 const ndn::Block& wire = adjacency.wireEncode();
54
55 BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyData,
56 AdjacencyData + sizeof(AdjacencyData),
57 wire.begin(), wire.end());
58}
59
60BOOST_AUTO_TEST_CASE(AdjacencyDecode)
61{
62 Adjacency adjacency;
63
64 adjacency.wireDecode(ndn::Block(AdjacencyData, sizeof(AdjacencyData)));
65
66 ndn::Name name("/test/adjacency/tlv");
67 BOOST_REQUIRE_EQUAL(adjacency.getName(), name);
68 BOOST_REQUIRE_EQUAL(adjacency.getUri(), "/test/adjacency/tlv");
69 BOOST_REQUIRE_EQUAL(adjacency.getCost(), 128);
70}
71
72BOOST_AUTO_TEST_CASE(AdjacencyOutputStream)
73{
74 Adjacency adjacency;
75 adjacency.setName("/test/adjacency/tlv");
76 adjacency.setUri("/test/adjacency/tlv");
77 adjacency.setCost(128);
78
79 std::ostringstream os;
80 os << adjacency;
81
82 BOOST_CHECK_EQUAL(os.str(), "Adjacency(Name: /test/adjacency/tlv, "
83 "Uri: /test/adjacency/tlv, "
84 "Cost: 128)");
85}
86
87BOOST_AUTO_TEST_SUITE_END()
88
89} // namespace test
90} // namespace tlv
91} // namespace nlsr