blob: 083d44867da84252b7db9ec02c879da358f16686 [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/*
Davide Pesavento288141a2024-02-13 17:30:35 -05003 * Copyright (c) 2014-2024, 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
Davide Pesavento288141a2024-02-13 17:30:35 -050026namespace nlsr::tests {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027
Nick Gordone9733ed2017-04-26 10:48:39 -050028BOOST_AUTO_TEST_SUITE(TestAdjacent)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029
Nick Gordone9733ed2017-04-26 10:48:39 -050030BOOST_AUTO_TEST_CASE(OperatorEquals)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050031{
Nick Gordone9733ed2017-04-26 10:48:39 -050032 const ndn::Name ADJ_NAME_1 = "name1";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050033 const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000");
Nick Gordone9733ed2017-04-26 10:48:39 -050034 const double ADJ_LINK_COST_1 = 1;
35 Adjacent adjacent1(ADJ_NAME_1);
36 Adjacent adjacent2(ADJ_NAME_1);
37 adjacent1.setFaceUri(ADJ_URI_1);
38 adjacent2.setFaceUri(ADJ_URI_1);
39 adjacent1.setLinkCost(ADJ_LINK_COST_1);
40 adjacent2.setLinkCost(ADJ_LINK_COST_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050041
Nick Gordone9733ed2017-04-26 10:48:39 -050042 BOOST_CHECK(adjacent1 == adjacent2);
43}
44
Nick Gordon2a1ac612017-10-06 15:36:49 -050045BOOST_AUTO_TEST_CASE(OperatorLessThan)
46{
47 const ndn::Name ADJ_NAME_1 = "name1";
48 const double ADJ_LINK_COST_1 = 1;
49 const ndn::Name ADJ_NAME_2 = "name2";
50 const double ADJ_LINK_COST_2 = 2;
51 Adjacent adjacent1(ADJ_NAME_1);
52 Adjacent adjacent2(ADJ_NAME_1);
53 adjacent1.setLinkCost(ADJ_LINK_COST_1);
54 adjacent2.setLinkCost(ADJ_LINK_COST_2);
55
56 BOOST_CHECK(adjacent1 < adjacent2);
57
58 Adjacent adjacent3(ADJ_NAME_2);
59 adjacent3.setLinkCost(ADJ_LINK_COST_1);
60
61 BOOST_CHECK(adjacent1 < adjacent3);
62}
63
Nick Gordone9733ed2017-04-26 10:48:39 -050064BOOST_AUTO_TEST_CASE(Accessors)
65{
66 const ndn::Name ADJ_NAME_1 = "name1";
67 Adjacent adjacent1(ADJ_NAME_1);
68
69 // Link cost should always be rounded up to the nearest integer.
70 // The library only acceps integral values for prefix registration.
71 adjacent1.setLinkCost(10.1);
72
73 BOOST_CHECK_EQUAL(adjacent1.getName(), "name1");
74 BOOST_CHECK_EQUAL(adjacent1.getLinkCost(), 11);
75}
76
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040077BOOST_AUTO_TEST_CASE(CompareFaceUri)
Nick Gordone9733ed2017-04-26 10:48:39 -050078{
79 const ndn::Name ADJ_NAME_1 = "name1";
80 const ndn::Name ADJ_NAME_2 = "name2";
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050081 const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050082 Adjacent adjacent1(ADJ_NAME_1);
83 Adjacent adjacent2(ADJ_NAME_2);
Nick Gordone9733ed2017-04-26 10:48:39 -050084 adjacent1.setFaceUri(ADJ_URI_1);
85 adjacent2.setFaceUri(ADJ_URI_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050086
Nick Gordone9733ed2017-04-26 10:48:39 -050087 BOOST_CHECK(adjacent1.compareFaceUri(adjacent2.getFaceUri()));
88}
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050089
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040090BOOST_AUTO_TEST_CASE(CompareFaceId)
Nick Gordone9733ed2017-04-26 10:48:39 -050091{
92 const ndn::Name ADJ_NAME_1 = "name1";
93 const ndn::Name ADJ_NAME_2 = "name2";
94 const uint64_t ADJ_FACEID_1 = 1;
95 Adjacent adjacent1(ADJ_NAME_1);
96 Adjacent adjacent2(ADJ_NAME_2);
97 adjacent1.setFaceId(ADJ_FACEID_1);
98 adjacent2.setFaceId(ADJ_FACEID_1);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050099
Nick Gordone9733ed2017-04-26 10:48:39 -0500100 BOOST_CHECK(adjacent1.compareFaceId(adjacent2.getFaceId()));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500101}
102
103BOOST_AUTO_TEST_SUITE_END()
104
Davide Pesavento288141a2024-02-13 17:30:35 -0500105} // namespace nlsr::tests