blob: a8a0110a27a42cb01ff42cd74c70bf50ea0327e1 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- 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
30namespace nfd {
31namespace rib {
32namespace tests {
33
34BOOST_FIXTURE_TEST_SUITE(Rib, nfd::tests::BaseFixture)
35
36BOOST_AUTO_TEST_CASE(Basic)
37{
38 rib::Rib rib;
39
Alexander Afanasyev20d31442014-04-19 17:00:53 -070040 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 Afanasyev3ecec502014-04-16 13:42:44 -070047
Alexander Afanasyev20d31442014-04-19 17:00:53 -070048 rib.insert(entry1);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070049 BOOST_CHECK_EQUAL(rib.size(), 1);
50
Alexander Afanasyev20d31442014-04-19 17:00:53 -070051 rib.insert(entry1);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070052 BOOST_CHECK_EQUAL(rib.size(), 1);
53
Alexander Afanasyev20d31442014-04-19 17:00:53 -070054 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 Afanasyev3ecec502014-04-16 13:42:44 -070067 BOOST_CHECK_EQUAL(rib.size(), 2);
68
Alexander Afanasyev20d31442014-04-19 17:00:53 -070069 entry2.name = "/foo/bar";
70 rib.insert(entry2);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070071 BOOST_CHECK_EQUAL(rib.size(), 3);
72
Alexander Afanasyev20d31442014-04-19 17:00:53 -070073 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 Afanasyev3ecec502014-04-16 13:42:44 -070086 BOOST_CHECK_EQUAL(rib.size(), 2);
87
Alexander Afanasyev20d31442014-04-19 17:00:53 -070088 BOOST_CHECK(rib.find(entry2) == rib.end());
89 BOOST_CHECK(rib.find(entry1) != rib.end());
90
91 rib.erase(entry1);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070092 BOOST_CHECK_EQUAL(rib.size(), 1);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070093}
94
95BOOST_AUTO_TEST_SUITE_END()
96
97} // namespace tests
98} // namespace rib
99} // namespace nfd