blob: 43c65afc2ddd4acb4b18fe6c32712398edabec28 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifc206962015-01-16 11:12:22 -07003 * Copyright (c) 2014-2015, 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.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080010 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070011 * 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 Shia9388182014-12-13 23:16:09 -070024 */
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070025
26#include "table/cs.hpp"
Junxiao Shia9388182014-12-13 23:16:09 -070027#include <ndn-cxx/util/crypto.hpp>
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080032namespace cs {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070034
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035using namespace nfd::tests;
Junxiao Shi35b16b12015-02-16 22:14:57 -070036using ndn::nfd::LocalControlHeader;
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture)
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070039
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080040class FindFixture : protected BaseFixture
41{
42protected:
Junxiao Shia9388182014-12-13 23:16:09 -070043 Name
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080044 insert(uint32_t id, const Name& name)
45 {
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040046 shared_ptr<Data> data = makeData(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070047 data->setFreshnessPeriod(time::milliseconds(99999));
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048 data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
Junxiao Shia9388182014-12-13 23:16:09 -070049 data->wireEncode();
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070050
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080051 m_cs.insert(*data);
Junxiao Shia9388182014-12-13 23:16:09 -070052
53 return data->getFullName();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080054 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070055
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080056 Interest&
57 startInterest(const Name& name)
58 {
59 m_interest = make_shared<Interest>(name);
60 return *m_interest;
61 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070062
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080063 uint32_t
64 find()
65 {
Junxiao Shia9388182014-12-13 23:16:09 -070066 // m_cs.dump();
67
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080068 const Data* found = m_cs.find(*m_interest);
Junxiao Shia9388182014-12-13 23:16:09 -070069 if (found == nullptr) {
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080070 return 0;
71 }
72 const Block& content = found->getContent();
73 if (content.value_size() != sizeof(uint32_t)) {
74 return 0;
75 }
76 return *reinterpret_cast<const uint32_t*>(content.value());
77 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070078
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080079protected:
80 Cs m_cs;
81 shared_ptr<Interest> m_interest;
82};
83
84BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
85
86BOOST_AUTO_TEST_CASE(EmptyDataName)
87{
88 insert(1, "ndn:/");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070089
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080090 startInterest("ndn:/");
91 BOOST_CHECK_EQUAL(find(), 1);
92}
93
94BOOST_AUTO_TEST_CASE(EmptyInterestName)
95{
96 insert(1, "ndn:/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070097
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080098 startInterest("ndn:/");
99 BOOST_CHECK_EQUAL(find(), 1);
100}
101
Junxiao Shia9388182014-12-13 23:16:09 -0700102BOOST_AUTO_TEST_CASE(ExactName)
103{
104 insert(1, "ndn:/");
105 insert(2, "ndn:/A");
106 insert(3, "ndn:/A/B");
107 insert(4, "ndn:/A/C");
108 insert(5, "ndn:/D");
109
110 startInterest("ndn:/A");
111 BOOST_CHECK_EQUAL(find(), 2);
112}
113
114BOOST_AUTO_TEST_CASE(FullName)
115{
116 Name n1 = insert(1, "ndn:/A");
117 Name n2 = insert(2, "ndn:/A");
118
119 startInterest(n1);
120 BOOST_CHECK_EQUAL(find(), 1);
121
122 startInterest(n2);
123 BOOST_CHECK_EQUAL(find(), 2);
124}
125
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800126BOOST_AUTO_TEST_CASE(Leftmost)
127{
128 insert(1, "ndn:/A");
129 insert(2, "ndn:/B/p/1");
130 insert(3, "ndn:/B/p/2");
131 insert(4, "ndn:/B/q/1");
132 insert(5, "ndn:/B/q/2");
133 insert(6, "ndn:/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700134
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800135 startInterest("ndn:/B");
136 BOOST_CHECK_EQUAL(find(), 2);
137}
138
139BOOST_AUTO_TEST_CASE(Rightmost)
140{
141 insert(1, "ndn:/A");
142 insert(2, "ndn:/B/p/1");
143 insert(3, "ndn:/B/p/2");
144 insert(4, "ndn:/B/q/1");
145 insert(5, "ndn:/B/q/2");
146 insert(6, "ndn:/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700147
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800148 startInterest("ndn:/B")
149 .setChildSelector(1);
150 BOOST_CHECK_EQUAL(find(), 4);
151}
152
Junxiao Shia9388182014-12-13 23:16:09 -0700153BOOST_AUTO_TEST_CASE(MinSuffixComponents)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800154{
155 insert(1, "ndn:/");
156 insert(2, "ndn:/A");
Junxiao Shia9388182014-12-13 23:16:09 -0700157 insert(3, "ndn:/B/1");
158 insert(4, "ndn:/C/1/2");
159 insert(5, "ndn:/D/1/2/3");
160 insert(6, "ndn:/E/1/2/3/4");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700161
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800162 startInterest("ndn:/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800163 .setMinSuffixComponents(0);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800164 BOOST_CHECK_EQUAL(find(), 1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700165
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800166 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700167 .setMinSuffixComponents(1);
168 BOOST_CHECK_EQUAL(find(), 1);
169
170 startInterest("ndn:/")
171 .setMinSuffixComponents(2);
172 BOOST_CHECK_EQUAL(find(), 2);
173
174 startInterest("ndn:/")
175 .setMinSuffixComponents(3);
176 BOOST_CHECK_EQUAL(find(), 3);
177
178 startInterest("ndn:/")
179 .setMinSuffixComponents(4);
180 BOOST_CHECK_EQUAL(find(), 4);
181
182 startInterest("ndn:/")
183 .setMinSuffixComponents(5);
184 BOOST_CHECK_EQUAL(find(), 5);
185
186 startInterest("ndn:/")
187 .setMinSuffixComponents(6);
188 BOOST_CHECK_EQUAL(find(), 6);
189
190 startInterest("ndn:/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800191 .setMinSuffixComponents(7);
192 BOOST_CHECK_EQUAL(find(), 0);
193}
194
195BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
196{
197 insert(1, "ndn:/");
198 insert(2, "ndn:/A");
Junxiao Shia9388182014-12-13 23:16:09 -0700199 insert(3, "ndn:/B/2");
200 insert(4, "ndn:/C/2/3");
201 insert(5, "ndn:/D/2/3/4");
202 insert(6, "ndn:/E/2/3/4/5");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700203
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800204 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700205 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800206 .setMaxSuffixComponents(0);
207 BOOST_CHECK_EQUAL(find(), 0);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700208
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800209 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700210 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800211 .setMaxSuffixComponents(1);
212 BOOST_CHECK_EQUAL(find(), 1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700213
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800214 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700215 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800216 .setMaxSuffixComponents(2);
217 BOOST_CHECK_EQUAL(find(), 2);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700218
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800219 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700220 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800221 .setMaxSuffixComponents(3);
222 BOOST_CHECK_EQUAL(find(), 3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700223
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800224 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700225 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800226 .setMaxSuffixComponents(4);
227 BOOST_CHECK_EQUAL(find(), 4);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700228
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800229 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700230 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800231 .setMaxSuffixComponents(5);
232 BOOST_CHECK_EQUAL(find(), 5);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700233
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800234 startInterest("ndn:/")
Junxiao Shia9388182014-12-13 23:16:09 -0700235 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800236 .setMaxSuffixComponents(6);
237 BOOST_CHECK_EQUAL(find(), 6);
Junxiao Shia9388182014-12-13 23:16:09 -0700238
239 startInterest("ndn:/")
240 .setChildSelector(1)
241 .setMaxSuffixComponents(7);
242 BOOST_CHECK_EQUAL(find(), 6);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800243}
244
245BOOST_AUTO_TEST_CASE(DigestOrder)
246{
247 insert(1, "ndn:/A");
248 insert(2, "ndn:/A");
249 // We don't know which comes first, but there must be some order
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700250
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800251 startInterest("ndn:/A")
252 .setChildSelector(0);
253 uint32_t leftmost = find();
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700254
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800255 startInterest("ndn:/A")
256 .setChildSelector(1);
257 uint32_t rightmost = find();
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700258
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800259 BOOST_CHECK_NE(leftmost, rightmost);
260}
261
262BOOST_AUTO_TEST_CASE(DigestExclude)
263{
Junxiao Shia9388182014-12-13 23:16:09 -0700264 insert(1, "ndn:/A");
265 Name n2 = insert(2, "ndn:/A");
266 insert(3, "ndn:/A/B");
267
268 uint8_t digest00[ndn::crypto::SHA256_DIGEST_SIZE];
269 std::fill_n(digest00, sizeof(digest00), 0x00);
270 uint8_t digestFF[ndn::crypto::SHA256_DIGEST_SIZE];
271 std::fill_n(digestFF, sizeof(digestFF), 0xFF);
272
273 Exclude excludeDigest;
274 excludeDigest.excludeRange(
275 name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
276 name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700277
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800278 startInterest("ndn:/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700279 .setChildSelector(0)
280 .setExclude(excludeDigest);
281 BOOST_CHECK_EQUAL(find(), 3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700282
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800283 startInterest("ndn:/A")
284 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700285 .setExclude(excludeDigest);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400286 BOOST_CHECK_EQUAL(find(), 3);
287
Junxiao Shia9388182014-12-13 23:16:09 -0700288 Exclude excludeGeneric;
289 excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400290
Junxiao Shia9388182014-12-13 23:16:09 -0700291 startInterest("ndn:/A")
292 .setChildSelector(0)
293 .setExclude(excludeGeneric);
294 int found1 = find();
295 BOOST_CHECK(found1 == 1 || found1 == 2);
296
297 startInterest("ndn:/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400298 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700299 .setExclude(excludeGeneric);
300 int found2 = find();
301 BOOST_CHECK(found2 == 1 || found2 == 2);
302
303 Exclude exclude2 = excludeGeneric;
304 exclude2.excludeOne(n2.get(-1));
305
306 startInterest("ndn:/A")
307 .setChildSelector(0)
308 .setExclude(exclude2);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400309 BOOST_CHECK_EQUAL(find(), 1);
310
Junxiao Shia9388182014-12-13 23:16:09 -0700311 startInterest("ndn:/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400312 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700313 .setExclude(exclude2);
314 BOOST_CHECK_EQUAL(find(), 1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400315}
316
Junxiao Shia9388182014-12-13 23:16:09 -0700317BOOST_AUTO_TEST_SUITE_END()
318
Junxiao Shi35b16b12015-02-16 22:14:57 -0700319BOOST_AUTO_TEST_CASE(CachingPolicyNoCache)
320{
321 Cs cs(3);
322
323 shared_ptr<Data> dataA = makeData("ndn:/A");
324 dataA->getLocalControlHeader().setCachingPolicy(LocalControlHeader::CachingPolicy::NO_CACHE);
325 dataA->wireEncode();
326 BOOST_CHECK_EQUAL(cs.insert(*dataA), false);
327
328 BOOST_CHECK(cs.find(Interest("ndn:/A")) == nullptr);
329}
330
Junxiao Shia9388182014-12-13 23:16:09 -0700331BOOST_FIXTURE_TEST_CASE(Evict, UnitTestTimeFixture)
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400332{
Junxiao Shia9388182014-12-13 23:16:09 -0700333 Cs cs(3);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400334
Junxiao Shia9388182014-12-13 23:16:09 -0700335 shared_ptr<Data> dataA = makeData("ndn:/A");
336 dataA->setFreshnessPeriod(time::milliseconds(99999));
337 dataA->wireEncode();
338 cs.insert(*dataA);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400339
Junxiao Shia9388182014-12-13 23:16:09 -0700340 shared_ptr<Data> dataB = makeData("ndn:/B");
341 dataB->setFreshnessPeriod(time::milliseconds(10));
342 dataB->wireEncode();
343 cs.insert(*dataB);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400344
Junxiao Shia9388182014-12-13 23:16:09 -0700345 shared_ptr<Data> dataC = makeData("ndn:/C");
346 dataC->setFreshnessPeriod(time::milliseconds(99999));
347 dataC->wireEncode();
348 cs.insert(*dataC, true);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400349
Junxiao Shia9388182014-12-13 23:16:09 -0700350 this->advanceClocks(time::milliseconds(11));
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400351
Junxiao Shia9388182014-12-13 23:16:09 -0700352 // evict unsolicited
353 shared_ptr<Data> dataD = makeData("ndn:/D");
354 dataD->setFreshnessPeriod(time::milliseconds(99999));
355 dataD->wireEncode();
356 cs.insert(*dataD);
357 BOOST_CHECK_EQUAL(cs.size(), 3);
358 BOOST_CHECK(cs.find(Interest("ndn:/C")) == nullptr);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400359
Junxiao Shia9388182014-12-13 23:16:09 -0700360 // evict stale
361 shared_ptr<Data> dataE = makeData("ndn:/E");
362 dataE->setFreshnessPeriod(time::milliseconds(99999));
363 dataE->wireEncode();
364 cs.insert(*dataE);
365 BOOST_CHECK_EQUAL(cs.size(), 3);
366 BOOST_CHECK(cs.find(Interest("ndn:/B")) == nullptr);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400367
Junxiao Shia9388182014-12-13 23:16:09 -0700368 // evict fifo
369 shared_ptr<Data> dataF = makeData("ndn:/F");
370 dataF->setFreshnessPeriod(time::milliseconds(99999));
371 dataF->wireEncode();
372 cs.insert(*dataF);
373 BOOST_CHECK_EQUAL(cs.size(), 3);
374 BOOST_CHECK(cs.find(Interest("ndn:/A")) == nullptr);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400375}
376
Junxiao Shia9388182014-12-13 23:16:09 -0700377BOOST_FIXTURE_TEST_CASE(Refresh, UnitTestTimeFixture)
378{
379 Cs cs(3);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400380
Junxiao Shia9388182014-12-13 23:16:09 -0700381 shared_ptr<Data> dataA = makeData("ndn:/A");
382 dataA->setFreshnessPeriod(time::milliseconds(99999));
383 dataA->wireEncode();
384 cs.insert(*dataA);
385
386 shared_ptr<Data> dataB = makeData("ndn:/B");
387 dataB->setFreshnessPeriod(time::milliseconds(10));
388 dataB->wireEncode();
389 cs.insert(*dataB);
390
391 shared_ptr<Data> dataC = makeData("ndn:/C");
392 dataC->setFreshnessPeriod(time::milliseconds(10));
393 dataC->wireEncode();
394 cs.insert(*dataC);
395
396 this->advanceClocks(time::milliseconds(11));
397
398 // refresh dataB
399 shared_ptr<Data> dataB2 = make_shared<Data>(*dataB);
400 dataB2->wireEncode();
401 cs.insert(*dataB2);
402 BOOST_CHECK_EQUAL(cs.size(), 3);
403 BOOST_CHECK(cs.find(Interest("ndn:/A")) != nullptr);
404 BOOST_CHECK(cs.find(Interest("ndn:/B")) != nullptr);
405 BOOST_CHECK(cs.find(Interest("ndn:/C")) != nullptr);
406
407 // evict dataC stale
408 shared_ptr<Data> dataD = makeData("ndn:/D");
409 dataD->setFreshnessPeriod(time::milliseconds(99999));
410 dataD->wireEncode();
411 cs.insert(*dataD);
412 BOOST_CHECK_EQUAL(cs.size(), 3);
413 BOOST_CHECK(cs.find(Interest("ndn:/C")) == nullptr);
414}
415
Junxiao Shifc206962015-01-16 11:12:22 -0700416BOOST_AUTO_TEST_CASE(Enumeration)
417{
418 Cs cs;
419
420 Name nameA("/A");
421 Name nameAB("/A/B");
422 Name nameABC("/A/B/C");
423 Name nameD("/D");
424
425 BOOST_CHECK_EQUAL(cs.size(), 0);
426 BOOST_CHECK(cs.begin() == cs.end());
427
428 cs.insert(*makeData(nameABC));
429 BOOST_CHECK_EQUAL(cs.size(), 1);
430 BOOST_CHECK(cs.begin() != cs.end());
431 BOOST_CHECK(cs.begin()->getName() == nameABC);
432 BOOST_CHECK((*cs.begin()).getName() == nameABC);
433
434 auto i = cs.begin();
435 auto j = cs.begin();
436 BOOST_CHECK(++i == cs.end());
437 BOOST_CHECK(j++ == cs.begin());
438 BOOST_CHECK(j == cs.end());
439
440 cs.insert(*makeData(nameA));
441 cs.insert(*makeData(nameAB));
442 cs.insert(*makeData(nameD));
443
444 std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
445 std::set<Name> actual;
446 for (const auto& csEntry : cs) {
447 actual.insert(csEntry.getName());
448 }
449 BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
450}
451
Junxiao Shia9388182014-12-13 23:16:09 -0700452BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800453
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700454} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800455} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800456} // namespace nfd