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 | /* |
| 3 | * Copyright (c) 2014-2022, 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 | |
| 26 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | namespace test { |
| 28 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 29 | BOOST_AUTO_TEST_SUITE(TestAdjacent) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 30 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 31 | BOOST_AUTO_TEST_CASE(OperatorEquals) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 33 | const ndn::Name ADJ_NAME_1 = "name1"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 34 | 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] | 35 | 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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 42 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 43 | BOOST_CHECK(adjacent1 == adjacent2); |
| 44 | } |
| 45 | |
Nick Gordon | 2a1ac61 | 2017-10-06 15:36:49 -0500 | [diff] [blame] | 46 | BOOST_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 Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 65 | BOOST_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 Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(CompareFaceUri) |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 79 | { |
| 80 | const ndn::Name ADJ_NAME_1 = "name1"; |
| 81 | const ndn::Name ADJ_NAME_2 = "name2"; |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 82 | 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] | 83 | Adjacent adjacent1(ADJ_NAME_1); |
| 84 | Adjacent adjacent2(ADJ_NAME_2); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 85 | adjacent1.setFaceUri(ADJ_URI_1); |
| 86 | adjacent2.setFaceUri(ADJ_URI_1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 87 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 88 | BOOST_CHECK(adjacent1.compareFaceUri(adjacent2.getFaceUri())); |
| 89 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 90 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 91 | BOOST_AUTO_TEST_CASE(CompareFaceId) |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 92 | { |
| 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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 100 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 101 | BOOST_CHECK(adjacent1.compareFaceId(adjacent2.getFaceId())); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_SUITE_END() |
| 105 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 106 | } // namespace test |
| 107 | } // namespace nlsr |