blob: 204c5a3645263621446e2374929eea31d434c1e5 [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi4370fde2016-02-24 12:20:46 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shiee5a4442014-07-27 17:13:43 -070024 */
Junxiao Shic1e12362014-01-24 20:03:26 -070025
26#include "table/fib.hpp"
Junxiao Shi4370fde2016-02-24 12:20:46 -070027#include "table/pit.hpp"
28#include "table/measurements.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070029#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070030
Junxiao Shid9ee45c2014-02-27 15:38:11 -070031#include "tests/test-common.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070032
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Junxiao Shia6de4292016-07-12 02:08:10 +000034namespace fib {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035namespace tests {
Junxiao Shic1e12362014-01-24 20:03:26 -070036
Junxiao Shia6de4292016-07-12 02:08:10 +000037using namespace nfd::tests;
38
Junxiao Shi4370fde2016-02-24 12:20:46 -070039BOOST_AUTO_TEST_SUITE(Table)
40BOOST_FIXTURE_TEST_SUITE(TestFib, BaseFixture)
Junxiao Shic1e12362014-01-24 20:03:26 -070041
Junxiao Shia6de4292016-07-12 02:08:10 +000042BOOST_AUTO_TEST_CASE(FibEntry)
Junxiao Shic1e12362014-01-24 20:03:26 -070043{
44 Name prefix("ndn:/pxWhfFza");
Junxiao Shi8c8d2182014-01-30 22:33:00 -070045 shared_ptr<Face> face1 = make_shared<DummyFace>();
46 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shiefceadc2014-03-09 18:52:57 -070047
Junxiao Shia6de4292016-07-12 02:08:10 +000048 Entry entry(prefix);
Junxiao Shiefceadc2014-03-09 18:52:57 -070049 BOOST_CHECK_EQUAL(entry.getPrefix(), prefix);
50
Junxiao Shic1e12362014-01-24 20:03:26 -070051 // []
Junxiao Shia6de4292016-07-12 02:08:10 +000052 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -070053
Junxiao Shia6de4292016-07-12 02:08:10 +000054 entry.addNextHop(*face1, 20);
Junxiao Shic1e12362014-01-24 20:03:26 -070055 // [(face1,20)]
Junxiao Shia6de4292016-07-12 02:08:10 +000056 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
57 BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
58 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
Junxiao Shiefceadc2014-03-09 18:52:57 -070059
Junxiao Shia6de4292016-07-12 02:08:10 +000060 entry.addNextHop(*face1, 30);
Junxiao Shic1e12362014-01-24 20:03:26 -070061 // [(face1,30)]
Junxiao Shia6de4292016-07-12 02:08:10 +000062 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
63 BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
64 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 30);
Junxiao Shic1e12362014-01-24 20:03:26 -070065
Junxiao Shia6de4292016-07-12 02:08:10 +000066 entry.addNextHop(*face2, 40);
Junxiao Shic1e12362014-01-24 20:03:26 -070067 // [(face1,30), (face2,40)]
Junxiao Shia6de4292016-07-12 02:08:10 +000068 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
69 {
70 NextHopList::const_iterator it = entry.getNextHops().begin();
71 BOOST_REQUIRE(it != entry.getNextHops().end());
72 BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
73 BOOST_CHECK_EQUAL(it->getCost(), 30);
74
75 ++it;
76 BOOST_REQUIRE(it != entry.getNextHops().end());
77 BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
78 BOOST_CHECK_EQUAL(it->getCost(), 40);
79
80 ++it;
81 BOOST_CHECK(it == entry.getNextHops().end());
Junxiao Shic1e12362014-01-24 20:03:26 -070082 }
83
Junxiao Shia6de4292016-07-12 02:08:10 +000084 entry.addNextHop(*face2, 10);
Junxiao Shic1e12362014-01-24 20:03:26 -070085 // [(face2,10), (face1,30)]
Junxiao Shia6de4292016-07-12 02:08:10 +000086 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
87 {
88 NextHopList::const_iterator it = entry.getNextHops().begin();
89 BOOST_REQUIRE(it != entry.getNextHops().end());
90 BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
91 BOOST_CHECK_EQUAL(it->getCost(), 10);
92
93 ++it;
94 BOOST_REQUIRE(it != entry.getNextHops().end());
95 BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
96 BOOST_CHECK_EQUAL(it->getCost(), 30);
97
98 ++it;
99 BOOST_CHECK(it == entry.getNextHops().end());
Junxiao Shic1e12362014-01-24 20:03:26 -0700100 }
Junxiao Shiefceadc2014-03-09 18:52:57 -0700101
Junxiao Shia6de4292016-07-12 02:08:10 +0000102 entry.removeNextHop(*face1);
Junxiao Shic1e12362014-01-24 20:03:26 -0700103 // [(face2,10)]
Junxiao Shia6de4292016-07-12 02:08:10 +0000104 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
105 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
106 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700107
Junxiao Shia6de4292016-07-12 02:08:10 +0000108 entry.removeNextHop(*face1);
Junxiao Shic1e12362014-01-24 20:03:26 -0700109 // [(face2,10)]
Junxiao Shia6de4292016-07-12 02:08:10 +0000110 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
111 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
112 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700113
Junxiao Shia6de4292016-07-12 02:08:10 +0000114 entry.removeNextHop(*face2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700115 // []
Junxiao Shia6de4292016-07-12 02:08:10 +0000116 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700117
Junxiao Shia6de4292016-07-12 02:08:10 +0000118 entry.removeNextHop(*face2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700119 // []
Junxiao Shia6de4292016-07-12 02:08:10 +0000120 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shic1e12362014-01-24 20:03:26 -0700121}
122
123BOOST_AUTO_TEST_CASE(Insert_LongestPrefixMatch)
124{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500125 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800126 Fib fib(nameTree);
Junxiao Shia6de4292016-07-12 02:08:10 +0000127
Junxiao Shi40631842014-03-01 13:52:37 -0700128 // []
Junxiao Shiefceadc2014-03-09 18:52:57 -0700129 BOOST_CHECK_EQUAL(fib.size(), 0);
Junxiao Shia6de4292016-07-12 02:08:10 +0000130 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/"); // the empty entry
Junxiao Shi40631842014-03-01 13:52:37 -0700131
Junxiao Shia6de4292016-07-12 02:08:10 +0000132 std::pair<Entry*, bool> insertRes = fib.insert("/");
Junxiao Shi40631842014-03-01 13:52:37 -0700133 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000134 BOOST_REQUIRE(insertRes.first != nullptr);
135 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/");
Junxiao Shic1e12362014-01-24 20:03:26 -0700136 // ['/']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700137 BOOST_CHECK_EQUAL(fib.size(), 1);
138
Junxiao Shia6de4292016-07-12 02:08:10 +0000139 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700140
Junxiao Shia6de4292016-07-12 02:08:10 +0000141 insertRes = fib.insert("/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700142 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000143 BOOST_REQUIRE(insertRes.first != nullptr);
144 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700145 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700146 BOOST_CHECK_EQUAL(fib.size(), 2);
147
Junxiao Shia6de4292016-07-12 02:08:10 +0000148 insertRes = fib.insert("/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700149 BOOST_CHECK_EQUAL(insertRes.second, false);
Junxiao Shia6de4292016-07-12 02:08:10 +0000150 BOOST_REQUIRE(insertRes.first != nullptr);
151 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700152 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700153 BOOST_CHECK_EQUAL(fib.size(), 2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700154
Junxiao Shia6de4292016-07-12 02:08:10 +0000155 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700156
Junxiao Shia6de4292016-07-12 02:08:10 +0000157 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700158
Junxiao Shia6de4292016-07-12 02:08:10 +0000159 insertRes = fib.insert("/A/B/C");
Junxiao Shic1e12362014-01-24 20:03:26 -0700160 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000161 BOOST_REQUIRE(insertRes.first != nullptr);
162 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A/B/C");
Junxiao Shic1e12362014-01-24 20:03:26 -0700163 // ['/', '/A', '/A/B/C']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700164 BOOST_CHECK_EQUAL(fib.size(), 3);
Junxiao Shic1e12362014-01-24 20:03:26 -0700165
Junxiao Shia6de4292016-07-12 02:08:10 +0000166 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
167 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B").getPrefix(), "/A");
168 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A/B/C");
169 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/E").getPrefix(), "/");
Junxiao Shic1e12362014-01-24 20:03:26 -0700170}
171
Junxiao Shi4370fde2016-02-24 12:20:46 -0700172BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithPitEntry)
173{
174 NameTree nameTree;
175 Fib fib(nameTree);
176
177 shared_ptr<Data> dataABC = makeData("/A/B/C");
178 Name fullNameABC = dataABC->getFullName();
179 shared_ptr<Data> dataADE = makeData("/A/D/E");
180 Name fullNameADE = dataADE->getFullName();
181 fib.insert("/A");
182 fib.insert(fullNameABC);
183
184 Pit pit(nameTree);
185 shared_ptr<Interest> interestAB = makeInterest("/A/B");
186 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
187 shared_ptr<Interest> interestABC = makeInterest(fullNameABC);
188 shared_ptr<pit::Entry> pitABC = pit.insert(*interestABC).first;
189 shared_ptr<Interest> interestADE = makeInterest(fullNameADE);
190 shared_ptr<pit::Entry> pitADE = pit.insert(*interestADE).first;
191
Junxiao Shia6de4292016-07-12 02:08:10 +0000192 size_t nNameTreeEntriesBefore = nameTree.size();
Junxiao Shi4370fde2016-02-24 12:20:46 -0700193
Junxiao Shia6de4292016-07-12 02:08:10 +0000194 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitAB).getPrefix(), "/A");
195 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitABC).getPrefix(), fullNameABC);
196 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitADE).getPrefix(), "/A");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700197
Junxiao Shia6de4292016-07-12 02:08:10 +0000198 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700199}
200
201BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithMeasurementsEntry)
202{
203 NameTree nameTree;
204 Fib fib(nameTree);
205
206 fib.insert("/A");
207 fib.insert("/A/B/C");
208
209 Measurements measurements(nameTree);
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000210 measurements::Entry& mAB = measurements.get("/A/B");
211 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700212
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000213 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mAB).getPrefix(), "/A");
214 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mABCD).getPrefix(), "/A/B/C");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700215}
216
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700217void
Junxiao Shia6de4292016-07-12 02:08:10 +0000218validateFindExactMatch(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700219{
Junxiao Shia6de4292016-07-12 02:08:10 +0000220 const Entry* entry = fib.findExactMatch(target);
221 BOOST_REQUIRE_MESSAGE(entry != nullptr, "No entry found for " << target);
222 BOOST_CHECK_EQUAL(entry->getPrefix(), target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700223}
224
225void
Junxiao Shia6de4292016-07-12 02:08:10 +0000226validateNoExactMatch(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700227{
Junxiao Shia6de4292016-07-12 02:08:10 +0000228 const Entry* entry = fib.findExactMatch(target);
229 BOOST_CHECK_MESSAGE(entry == nullptr,
230 "Found unexpected entry for " << target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700231}
232
Junxiao Shia6de4292016-07-12 02:08:10 +0000233BOOST_AUTO_TEST_CASE(ExactMatch)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700234{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500235 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800236 Fib fib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700237 fib.insert("/A");
238 fib.insert("/A/B");
239 fib.insert("/A/B/C");
240
241 validateFindExactMatch(fib, "/A");
242 validateFindExactMatch(fib, "/A/B");
243 validateFindExactMatch(fib, "/A/B/C");
Junxiao Shia6de4292016-07-12 02:08:10 +0000244
Junxiao Shi40631842014-03-01 13:52:37 -0700245 validateNoExactMatch(fib, "/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700246 validateNoExactMatch(fib, "/does/not/exist");
Junxiao Shia6de4292016-07-12 02:08:10 +0000247}
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700248
Junxiao Shia6de4292016-07-12 02:08:10 +0000249BOOST_AUTO_TEST_CASE(ExactMatchGap)
250{
251 NameTree nameTree;
252 Fib fib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700253 fib.insert("/X");
254 fib.insert("/X/Y/Z");
255
Junxiao Shia6de4292016-07-12 02:08:10 +0000256 validateNoExactMatch(fib, "/X/Y");
257}
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700258
Junxiao Shia6de4292016-07-12 02:08:10 +0000259BOOST_AUTO_TEST_CASE(ExactMatchEmpty)
260{
261 NameTree nameTree;
262 Fib fib(nameTree);
263 validateNoExactMatch(fib, "/");
264 validateNoExactMatch(fib, "/nothing/here");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700265}
266
267void
Junxiao Shiee5a4442014-07-27 17:13:43 -0700268validateErase(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700269{
HangZhangad4afd12014-03-01 11:03:08 +0800270 fib.erase(target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700271
Junxiao Shia6de4292016-07-12 02:08:10 +0000272 const Entry* entry = fib.findExactMatch(target);
273 BOOST_CHECK_MESSAGE(entry == nullptr, "Found \"removed\" entry for " << target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700274}
275
Junxiao Shiee5a4442014-07-27 17:13:43 -0700276BOOST_AUTO_TEST_CASE(Erase)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700277{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500278 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800279 Fib fib(nameTree);
Junxiao Shi40631842014-03-01 13:52:37 -0700280 fib.insert("/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700281 fib.insert("/A");
282 fib.insert("/A/B");
283 fib.insert("/A/B/C");
284
285 // check if we remove the right thing and leave
286 // everything else alone
287
Junxiao Shiee5a4442014-07-27 17:13:43 -0700288 validateErase(fib, "/A/B");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700289 validateFindExactMatch(fib, "/A");
290 validateFindExactMatch(fib, "/A/B/C");
291 validateFindExactMatch(fib, "/");
292
Junxiao Shiee5a4442014-07-27 17:13:43 -0700293 validateErase(fib, "/A/B/C");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700294 validateFindExactMatch(fib, "/A");
295 validateFindExactMatch(fib, "/");
296
Junxiao Shiee5a4442014-07-27 17:13:43 -0700297 validateErase(fib, "/A");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700298 validateFindExactMatch(fib, "/");
299
Junxiao Shiee5a4442014-07-27 17:13:43 -0700300 validateErase(fib, "/");
Junxiao Shi40631842014-03-01 13:52:37 -0700301 validateNoExactMatch(fib, "/");
Junxiao Shia6de4292016-07-12 02:08:10 +0000302}
Junxiao Shi40631842014-03-01 13:52:37 -0700303
Junxiao Shia6de4292016-07-12 02:08:10 +0000304BOOST_AUTO_TEST_CASE(EraseGap)
305{
306 NameTree nameTree;
307 Fib fib(nameTree);
308 fib.insert("/X");
309 fib.insert("/X/Y/Z");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700310
Junxiao Shia6de4292016-07-12 02:08:10 +0000311 fib.erase("/X/Y"); //should do nothing
312 validateFindExactMatch(fib, "/X");
313 validateFindExactMatch(fib, "/X/Y/Z");
314}
315
316BOOST_AUTO_TEST_CASE(EraseEmpty)
317{
318 NameTree nameTree;
319 Fib fib(nameTree);
320
321 BOOST_CHECK_NO_THROW(fib.erase("/does/not/exist"));
322 validateErase(fib, "/");
323 BOOST_CHECK_NO_THROW(fib.erase("/still/does/not/exist"));
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700324}
325
Junxiao Shiee5a4442014-07-27 17:13:43 -0700326BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
327{
328 NameTree nameTree;
329 Fib fib(nameTree);
330 size_t nNameTreeEntriesBefore = nameTree.size();
331
Junxiao Shia6de4292016-07-12 02:08:10 +0000332 fib.insert("/A/B/C");
333 fib.erase("/A/B/C");
Junxiao Shiee5a4442014-07-27 17:13:43 -0700334 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
335}
336
HangZhang5d469422014-03-12 09:26:26 +0800337BOOST_AUTO_TEST_CASE(Iterator)
338{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500339 NameTree nameTree;
HangZhang5d469422014-03-12 09:26:26 +0800340 Fib fib(nameTree);
341 Name nameA("/A");
342 Name nameAB("/A/B");
343 Name nameABC("/A/B/C");
344 Name nameRoot("/");
345
346 fib.insert(nameA);
347 fib.insert(nameAB);
348 fib.insert(nameABC);
349 fib.insert(nameRoot);
350
Junxiao Shia6de4292016-07-12 02:08:10 +0000351 std::set<Name> expected{nameA, nameAB, nameABC, nameRoot};
HangZhang5d469422014-03-12 09:26:26 +0800352
Junxiao Shi4370fde2016-02-24 12:20:46 -0700353 for (Fib::const_iterator it = fib.begin(); it != fib.end(); it++) {
HangZhang5d469422014-03-12 09:26:26 +0800354 bool isInSet = expected.find(it->getPrefix()) != expected.end();
355 BOOST_CHECK(isInSet);
356 expected.erase(it->getPrefix());
357 }
358
359 BOOST_CHECK_EQUAL(expected.size(), 0);
360}
361
Junxiao Shi4370fde2016-02-24 12:20:46 -0700362BOOST_AUTO_TEST_SUITE_END() // TestFib
363BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shic1e12362014-01-24 20:03:26 -0700364
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700365} // namespace tests
Junxiao Shia6de4292016-07-12 02:08:10 +0000366} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800367} // namespace nfd