blob: cb05ed4bfac98a7aae5f130558b83a8029167974 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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/coordinate-lsa.hpp"
23
24#include "../boost-test.hpp"
25
26namespace nlsr {
27namespace tlv {
28namespace test {
29
30BOOST_AUTO_TEST_SUITE(TlvTestCoordinateLsa)
31
32const uint8_t CoordinateLsaData[] =
33{
34 // Header
35 0x85, 0x2b,
36 // LsaInfo
37 0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
38 0x80, 0x8b, 0x02, 0x27, 0x10,
39 // HyperbolicRadius
40 0x87, 0x0a, 0x86, 0x08, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xfa, 0x3f,
41 // HyperbolicAngle
42 0x88, 0x0a, 0x86, 0x08, 0x7b, 0x14, 0xae, 0x47, 0xe1, 0x7a, 0xfc, 0x3f
43};
44
45BOOST_AUTO_TEST_CASE(CoordinateLsaEncode)
46{
47 CoordinateLsa coordinateLsa;
48
49 LsaInfo lsaInfo;
50 lsaInfo.setOriginRouter("test");
51 lsaInfo.setSequenceNumber(128);
52 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
53 coordinateLsa.setLsaInfo(lsaInfo);
54
55 coordinateLsa.setHyperbolicRadius(1.65);
56 coordinateLsa.setHyperbolicAngle(1.78);
57
58 const ndn::Block& wire = coordinateLsa.wireEncode();
59
60 BOOST_REQUIRE_EQUAL_COLLECTIONS(CoordinateLsaData,
61 CoordinateLsaData + sizeof(CoordinateLsaData),
62 wire.begin(), wire.end());
63}
64
65BOOST_AUTO_TEST_CASE(CoordinateLsaDecode)
66{
67 CoordinateLsa coordinateLsa;
68
69 coordinateLsa.wireDecode(ndn::Block(CoordinateLsaData, sizeof(CoordinateLsaData)));
70
71 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getOriginRouter(), "test");
72 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getSequenceNumber(), 128);
73 BOOST_REQUIRE_EQUAL(coordinateLsa.getLsaInfo().getExpirationPeriod(),
74 ndn::time::milliseconds(10000));
75 BOOST_REQUIRE_EQUAL(coordinateLsa.getHyperbolicRadius(), 1.65);
76 BOOST_REQUIRE_EQUAL(coordinateLsa.getHyperbolicAngle(), 1.78);
77}
78
79BOOST_AUTO_TEST_CASE(CoordinateLsaOutputStream)
80{
81 CoordinateLsa coordinateLsa;
82
83 LsaInfo lsaInfo;
84 lsaInfo.setOriginRouter("test");
85 lsaInfo.setSequenceNumber(128);
86 lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
87 coordinateLsa.setLsaInfo(lsaInfo);
88
89 coordinateLsa.setHyperbolicRadius(1.65);
90 coordinateLsa.setHyperbolicAngle(1.78);
91
92 std::ostringstream os;
93 os << coordinateLsa;
94
95 BOOST_CHECK_EQUAL(os.str(), "CoordinateLsa("
96 "LsaInfo(OriginRouter: /test, "
97 "SequenceNumber: 128, "
98 "ExpirationPeriod: 10000 milliseconds), "
99 "HyperbolicRadius: 1.65, "
100 "HyperbolicAngle: 1.78)");
101}
102
103BOOST_AUTO_TEST_SUITE_END()
104
105} // namespace test
106} // namespace tlv
107} // namespace nlsr