Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "rib/route.hpp" |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame^] | 27 | |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace rib { |
| 32 | namespace tests { |
| 33 | |
| 34 | using namespace nfd::tests; |
| 35 | |
| 36 | BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture) |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(Equality) |
| 39 | { |
| 40 | Route a; |
| 41 | Route b; |
| 42 | BOOST_CHECK_EQUAL(a, b); |
| 43 | |
| 44 | a.faceId = b.faceId = 15404; |
| 45 | a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR; |
| 46 | a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
| 47 | a.cost = b.cost = 28826; |
| 48 | a.expires = b.expires = time::steady_clock::now() + time::milliseconds(26782232); |
| 49 | BOOST_CHECK_EQUAL(a, b); |
| 50 | |
| 51 | b.faceId = 18559; |
| 52 | BOOST_CHECK_NE(a, b); |
| 53 | a.faceId = 18559; |
| 54 | |
| 55 | b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT; |
| 56 | BOOST_CHECK_NE(a, b); |
| 57 | a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT; |
| 58 | |
| 59 | b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE; |
| 60 | BOOST_CHECK_NE(a, b); |
| 61 | a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE; |
| 62 | |
| 63 | b.cost = 103; |
| 64 | BOOST_CHECK_NE(a, b); |
| 65 | a.cost = 103; |
| 66 | |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame^] | 67 | b.expires = nullopt; |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 68 | BOOST_CHECK_NE(a, b); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame^] | 69 | a.expires = nullopt; |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 70 | |
| 71 | BOOST_CHECK_EQUAL(a, b); |
| 72 | } |
| 73 | |
| 74 | BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture) |
| 75 | { |
| 76 | Route r; |
| 77 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r), |
| 78 | "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)"); |
| 79 | |
| 80 | r.faceId = 4980; |
| 81 | r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC; |
| 82 | r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
| 83 | r.cost = 2312; |
| 84 | r.expires = time::steady_clock::now() + time::milliseconds(791214234); |
| 85 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r), |
| 86 | "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: 791214234 milliseconds)"); |
| 87 | |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame^] | 88 | r.expires = nullopt; |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r), |
| 90 | "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)"); |
| 91 | } |
| 92 | |
| 93 | BOOST_AUTO_TEST_SUITE_END() // TestRoute |
| 94 | |
| 95 | } // namespace tests |
| 96 | } // namespace rib |
| 97 | } // namespace nfd |