blob: 5406096c4b748f9f9a2442e4c2b326a609aacccc [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -04002/*
3 * Copyright (c) 2014-2022, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author Ashlesh Gawande <agawande@memphis.edu>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040021 */
Davide Pesaventocb065f12019-12-27 01:03:34 -050022
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050023#include "adjacent.hpp"
Davide Pesaventocb065f12019-12-27 01:03:34 -050024#include "tests/boost-test.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025
26namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027namespace test {
28
Nick Gordone9733ed2017-04-26 10:48:39 -050029BOOST_AUTO_TEST_SUITE(TestAdjacent)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050030
Nick Gordone9733ed2017-04-26 10:48:39 -050031BOOST_AUTO_TEST_CASE(OperatorEquals)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032{
Nick Gordone9733ed2017-04-26 10:48:39 -050033 const ndn::Name ADJ_NAME_1 = "name1";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050034 const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000");
Nick Gordone9733ed2017-04-26 10:48:39 -050035 const double ADJ_LINK_COST_1 = 1;
36 Adjacent adjacent1(ADJ_NAME_1);
37 Adjacent adjacent2(ADJ_NAME_1);
38 adjacent1.setFaceUri(ADJ_URI_1);
39 adjacent2.setFaceUri(ADJ_URI_1);
40 adjacent1.setLinkCost(ADJ_LINK_COST_1);
41 adjacent2.setLinkCost(ADJ_LINK_COST_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050042
Nick Gordone9733ed2017-04-26 10:48:39 -050043 BOOST_CHECK(adjacent1 == adjacent2);
44}
45
Nick Gordon2a1ac612017-10-06 15:36:49 -050046BOOST_AUTO_TEST_CASE(OperatorLessThan)
47{
48 const ndn::Name ADJ_NAME_1 = "name1";
49 const double ADJ_LINK_COST_1 = 1;
50 const ndn::Name ADJ_NAME_2 = "name2";
51 const double ADJ_LINK_COST_2 = 2;
52 Adjacent adjacent1(ADJ_NAME_1);
53 Adjacent adjacent2(ADJ_NAME_1);
54 adjacent1.setLinkCost(ADJ_LINK_COST_1);
55 adjacent2.setLinkCost(ADJ_LINK_COST_2);
56
57 BOOST_CHECK(adjacent1 < adjacent2);
58
59 Adjacent adjacent3(ADJ_NAME_2);
60 adjacent3.setLinkCost(ADJ_LINK_COST_1);
61
62 BOOST_CHECK(adjacent1 < adjacent3);
63}
64
Nick Gordone9733ed2017-04-26 10:48:39 -050065BOOST_AUTO_TEST_CASE(Accessors)
66{
67 const ndn::Name ADJ_NAME_1 = "name1";
68 Adjacent adjacent1(ADJ_NAME_1);
69
70 // Link cost should always be rounded up to the nearest integer.
71 // The library only acceps integral values for prefix registration.
72 adjacent1.setLinkCost(10.1);
73
74 BOOST_CHECK_EQUAL(adjacent1.getName(), "name1");
75 BOOST_CHECK_EQUAL(adjacent1.getLinkCost(), 11);
76}
77
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040078BOOST_AUTO_TEST_CASE(CompareFaceUri)
Nick Gordone9733ed2017-04-26 10:48:39 -050079{
80 const ndn::Name ADJ_NAME_1 = "name1";
81 const ndn::Name ADJ_NAME_2 = "name2";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050082 const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050083 Adjacent adjacent1(ADJ_NAME_1);
84 Adjacent adjacent2(ADJ_NAME_2);
Nick Gordone9733ed2017-04-26 10:48:39 -050085 adjacent1.setFaceUri(ADJ_URI_1);
86 adjacent2.setFaceUri(ADJ_URI_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050087
Nick Gordone9733ed2017-04-26 10:48:39 -050088 BOOST_CHECK(adjacent1.compareFaceUri(adjacent2.getFaceUri()));
89}
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050090
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040091BOOST_AUTO_TEST_CASE(CompareFaceId)
Nick Gordone9733ed2017-04-26 10:48:39 -050092{
93 const ndn::Name ADJ_NAME_1 = "name1";
94 const ndn::Name ADJ_NAME_2 = "name2";
95 const uint64_t ADJ_FACEID_1 = 1;
96 Adjacent adjacent1(ADJ_NAME_1);
97 Adjacent adjacent2(ADJ_NAME_2);
98 adjacent1.setFaceId(ADJ_FACEID_1);
99 adjacent2.setFaceId(ADJ_FACEID_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500100
Nick Gordone9733ed2017-04-26 10:48:39 -0500101 BOOST_CHECK(adjacent1.compareFaceId(adjacent2.getFaceId()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500102}
103
104BOOST_AUTO_TEST_SUITE_END()
105
Nick Gordonfad8e252016-08-11 14:21:38 -0500106} // namespace test
107} // namespace nlsr