Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014 Regents of the University of California, |
| 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/rib.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace rib { |
| 32 | namespace tests { |
| 33 | |
| 34 | BOOST_FIXTURE_TEST_SUITE(Rib, nfd::tests::BaseFixture) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Basic) |
| 37 | { |
| 38 | rib::Rib rib; |
| 39 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 40 | RibEntry entry1; |
| 41 | entry1.name = "/hello/world"; |
| 42 | entry1.faceId = 1; |
| 43 | entry1.origin = 20; |
| 44 | entry1.cost = 10; |
| 45 | entry1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE; |
| 46 | entry1.expires = time::steady_clock::now() + time::milliseconds(1500); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 48 | rib.insert(entry1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 49 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 50 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 51 | rib.insert(entry1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 53 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 54 | RibEntry entry2; |
| 55 | entry2.name = "/hello/world"; |
| 56 | entry2.faceId = 1; |
| 57 | entry2.origin = 20; |
| 58 | entry2.cost = 100; |
| 59 | entry2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
| 60 | entry2.expires = time::steady_clock::now() + time::seconds(0); |
| 61 | |
| 62 | rib.insert(entry2); |
| 63 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 64 | |
| 65 | entry2.faceId = 2; |
| 66 | rib.insert(entry2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 67 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 68 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 69 | entry2.name = "/foo/bar"; |
| 70 | rib.insert(entry2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 72 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 73 | entry2.origin = 1; |
| 74 | rib.insert(entry2); |
| 75 | BOOST_CHECK_EQUAL(rib.size(), 4); |
| 76 | |
| 77 | rib.erase(entry2); |
| 78 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 79 | |
| 80 | entry2.name = "/hello/world"; |
| 81 | rib.erase(entry2); |
| 82 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 83 | |
| 84 | entry2.origin = 20; |
| 85 | rib.erase(entry2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 87 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame^] | 88 | BOOST_CHECK(rib.find(entry2) == rib.end()); |
| 89 | BOOST_CHECK(rib.find(entry1) != rib.end()); |
| 90 | |
| 91 | rib.erase(entry1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(rib.size(), 1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | BOOST_AUTO_TEST_SUITE_END() |
| 96 | |
| 97 | } // namespace tests |
| 98 | } // namespace rib |
| 99 | } // namespace nfd |