akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 5 | * |
| 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 Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 21 | */ |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 22 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 23 | #include "adjacent.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 26 | namespace nlsr::tests { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 28 | BOOST_AUTO_TEST_SUITE(TestAdjacent) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE(OperatorEquals) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 32 | const ndn::Name ADJ_NAME_1 = "name1"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 33 | const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 34 | 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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 41 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 42 | BOOST_CHECK(adjacent1 == adjacent2); |
| 43 | } |
| 44 | |
Nick Gordon | 2a1ac61 | 2017-10-06 15:36:49 -0500 | [diff] [blame] | 45 | BOOST_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 Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 64 | BOOST_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 Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 77 | BOOST_AUTO_TEST_CASE(CompareFaceUri) |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 78 | { |
| 79 | const ndn::Name ADJ_NAME_1 = "name1"; |
| 80 | const ndn::Name ADJ_NAME_2 = "name2"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 81 | const ndn::FaceUri ADJ_URI_1 = ndn::FaceUri("udp4://10.0.0.1:8000"); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 82 | Adjacent adjacent1(ADJ_NAME_1); |
| 83 | Adjacent adjacent2(ADJ_NAME_2); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 84 | adjacent1.setFaceUri(ADJ_URI_1); |
| 85 | adjacent2.setFaceUri(ADJ_URI_1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 86 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 87 | BOOST_CHECK(adjacent1.compareFaceUri(adjacent2.getFaceUri())); |
| 88 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 89 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 90 | BOOST_AUTO_TEST_CASE(CompareFaceId) |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 91 | { |
| 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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 99 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 100 | BOOST_CHECK(adjacent1.compareFaceId(adjacent2.getFaceId())); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | BOOST_AUTO_TEST_SUITE_END() |
| 104 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 105 | } // namespace nlsr::tests |