blob: 3aa6de4ad921d8a100505d0565267f2ee1c6f8fa [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibb6146e2017-07-26 23:07:52 +00002/*
Junxiao Shi1fbdb542017-02-03 00:05:53 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shifc206962015-01-16 11:12:22 -07004 * 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"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080027
Junxiao Shid9ee45c2014-02-27 15:38:11 -070028#include "tests/test-common.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080029
Junxiao Shi4e1b6ee2017-08-03 02:20:50 +000030#include <cstring>
31#include <ndn-cxx/lp/tags.hpp>
32#include <ndn-cxx/util/sha256.hpp>
33
mzhang4eab72492015-02-25 11:16:09 -060034#define CHECK_CS_FIND(expected) find([&] (uint32_t found) { BOOST_CHECK_EQUAL(expected, found); });
35
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080036namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037namespace cs {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038namespace tests {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070039
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080040using namespace nfd::tests;
41
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -070042BOOST_AUTO_TEST_SUITE(Table)
43BOOST_FIXTURE_TEST_SUITE(TestCs, BaseFixture)
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070044
Junxiao Shi1fbdb542017-02-03 00:05:53 +000045class FindFixture : public UnitTestTimeFixture
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080046{
47protected:
Junxiao Shia9388182014-12-13 23:16:09 -070048 Name
Junxiao Shi1fbdb542017-02-03 00:05:53 +000049 insert(uint32_t id, const Name& name, const std::function<void(Data&)>& modifyData = nullptr)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080050 {
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040051 shared_ptr<Data> data = makeData(name);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080052 data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070053
Junxiao Shi1fbdb542017-02-03 00:05:53 +000054 if (modifyData != nullptr) {
55 modifyData(*data);
56 }
57
58 data->wireEncode();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080059 m_cs.insert(*data);
Junxiao Shia9388182014-12-13 23:16:09 -070060
61 return data->getFullName();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080062 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070063
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080064 Interest&
65 startInterest(const Name& name)
66 {
67 m_interest = make_shared<Interest>(name);
68 return *m_interest;
69 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070070
mzhang4eab72492015-02-25 11:16:09 -060071 void
72 find(const std::function<void(uint32_t)>& check)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080073 {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000074 bool hasResult = false;
mzhang4eab72492015-02-25 11:16:09 -060075 m_cs.find(*m_interest,
76 [&] (const Interest& interest, const Data& data) {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000077 hasResult = true;
78 const Block& content = data.getContent();
Junxiao Shi4e1b6ee2017-08-03 02:20:50 +000079 uint32_t found = 0;
80 std::memcpy(&found, content.value(), sizeof(found));
Junxiao Shi1fbdb542017-02-03 00:05:53 +000081 check(found);
82 },
83 bind([&] {
84 hasResult = true;
85 check(0);
86 }));
87
88 // current Cs::find implementation performs lookup synchronously
89 BOOST_CHECK(hasResult);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080090 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070091
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080092protected:
93 Cs m_cs;
94 shared_ptr<Interest> m_interest;
95};
96
97BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
98
99BOOST_AUTO_TEST_CASE(EmptyDataName)
100{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000101 insert(1, "/");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700102
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000103 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600104 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800105}
106
107BOOST_AUTO_TEST_CASE(EmptyInterestName)
108{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000109 insert(1, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700110
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000111 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600112 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800113}
114
Junxiao Shia9388182014-12-13 23:16:09 -0700115BOOST_AUTO_TEST_CASE(ExactName)
116{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000117 insert(1, "/");
118 insert(2, "/A");
119 insert(3, "/A/B");
120 insert(4, "/A/C");
121 insert(5, "/D");
Junxiao Shia9388182014-12-13 23:16:09 -0700122
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000123 startInterest("/A");
mzhang4eab72492015-02-25 11:16:09 -0600124 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700125}
126
127BOOST_AUTO_TEST_CASE(FullName)
128{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000129 Name n1 = insert(1, "/A");
130 Name n2 = insert(2, "/A");
Junxiao Shia9388182014-12-13 23:16:09 -0700131
132 startInterest(n1);
mzhang4eab72492015-02-25 11:16:09 -0600133 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700134
135 startInterest(n2);
mzhang4eab72492015-02-25 11:16:09 -0600136 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700137}
138
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800139BOOST_AUTO_TEST_CASE(Leftmost)
140{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000141 insert(1, "/A");
142 insert(2, "/B/p/1");
143 insert(3, "/B/p/2");
144 insert(4, "/B/q/1");
145 insert(5, "/B/q/2");
146 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700147
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000148 startInterest("/B");
mzhang4eab72492015-02-25 11:16:09 -0600149 CHECK_CS_FIND(2);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800150}
151
152BOOST_AUTO_TEST_CASE(Rightmost)
153{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000154 insert(1, "/A");
155 insert(2, "/B/p/1");
156 insert(3, "/B/p/2");
157 insert(4, "/B/q/1");
158 insert(5, "/B/q/2");
159 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700160
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000161 startInterest("/B")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800162 .setChildSelector(1);
mzhang4eab72492015-02-25 11:16:09 -0600163 CHECK_CS_FIND(4);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800164}
165
Junxiao Shia9388182014-12-13 23:16:09 -0700166BOOST_AUTO_TEST_CASE(MinSuffixComponents)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800167{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000168 insert(1, "/");
169 insert(2, "/A");
170 insert(3, "/B/1");
171 insert(4, "/C/1/2");
172 insert(5, "/D/1/2/3");
173 insert(6, "/E/1/2/3/4");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700174
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000175 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800176 .setMinSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600177 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700178
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000179 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700180 .setMinSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600181 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700182
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000183 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700184 .setMinSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600185 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700186
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000187 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700188 .setMinSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600189 CHECK_CS_FIND(3);
Junxiao Shia9388182014-12-13 23:16:09 -0700190
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000191 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700192 .setMinSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600193 CHECK_CS_FIND(4);
Junxiao Shia9388182014-12-13 23:16:09 -0700194
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000195 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700196 .setMinSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600197 CHECK_CS_FIND(5);
Junxiao Shia9388182014-12-13 23:16:09 -0700198
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000199 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700200 .setMinSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600201 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700202
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000203 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800204 .setMinSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600205 CHECK_CS_FIND(0);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800206}
207
208BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
209{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000210 insert(1, "/");
211 insert(2, "/A");
212 insert(3, "/B/2");
213 insert(4, "/C/2/3");
214 insert(5, "/D/2/3/4");
215 insert(6, "/E/2/3/4/5");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700216
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000217 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700218 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800219 .setMaxSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600220 CHECK_CS_FIND(0);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700221
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000222 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700223 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800224 .setMaxSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600225 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700226
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000227 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700228 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800229 .setMaxSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600230 CHECK_CS_FIND(2);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700231
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000232 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700233 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800234 .setMaxSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600235 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700236
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000237 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700238 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800239 .setMaxSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600240 CHECK_CS_FIND(4);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700241
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000242 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700243 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800244 .setMaxSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600245 CHECK_CS_FIND(5);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700246
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000247 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700248 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800249 .setMaxSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600250 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700251
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000252 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700253 .setChildSelector(1)
254 .setMaxSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600255 CHECK_CS_FIND(6);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800256}
257
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000258BOOST_AUTO_TEST_CASE(MustBeFresh)
259{
Eric Newberryf4056d02017-05-26 17:31:53 +0000260 insert(1, "/A/1"); // omitted FreshnessPeriod means FreshnessPeriod = 0 ms
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000261 insert(2, "/A/2", [] (Data& data) { data.setFreshnessPeriod(time::seconds(0)); });
262 insert(3, "/A/3", [] (Data& data) { data.setFreshnessPeriod(time::seconds(1)); });
263 insert(4, "/A/4", [] (Data& data) { data.setFreshnessPeriod(time::seconds(3600)); });
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000264
265 // lookup at exact same moment as insertion is not tested because this won't happen in reality
266
267 this->advanceClocks(time::milliseconds(500)); // @500ms
268 startInterest("/A")
269 .setMustBeFresh(true);
270 CHECK_CS_FIND(3);
271
272 this->advanceClocks(time::milliseconds(1500)); // @2s
273 startInterest("/A")
274 .setMustBeFresh(true);
275 CHECK_CS_FIND(4);
276
277 this->advanceClocks(time::seconds(3500)); // @3502s
278 startInterest("/A")
279 .setMustBeFresh(true);
280 CHECK_CS_FIND(4);
281
282 this->advanceClocks(time::seconds(3500)); // @7002s
283 startInterest("/A")
284 .setMustBeFresh(true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000285 CHECK_CS_FIND(0);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000286}
287
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800288BOOST_AUTO_TEST_CASE(DigestOrder)
289{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000290 Name n1 = insert(1, "/A");
291 Name n2 = insert(2, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700292
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000293 uint32_t expectedLeftmost = 0, expectedRightmost = 0;
294 if (n1 < n2) {
295 expectedLeftmost = 1;
296 expectedRightmost = 2;
297 }
298 else {
299 BOOST_CHECK_MESSAGE(n1 != n2, "implicit digest collision detected");
300 expectedLeftmost = 2;
301 expectedRightmost = 1;
302 }
303
304 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800305 .setChildSelector(0);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000306 CHECK_CS_FIND(expectedLeftmost);
307 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800308 .setChildSelector(1);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000309 CHECK_CS_FIND(expectedRightmost);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800310}
311
312BOOST_AUTO_TEST_CASE(DigestExclude)
313{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000314 insert(1, "/A");
315 Name n2 = insert(2, "/A");
316 insert(3, "/A/B");
Junxiao Shia9388182014-12-13 23:16:09 -0700317
Junxiao Shibb6146e2017-07-26 23:07:52 +0000318 uint8_t digest00[ndn::util::Sha256::DIGEST_SIZE];
Junxiao Shia9388182014-12-13 23:16:09 -0700319 std::fill_n(digest00, sizeof(digest00), 0x00);
Junxiao Shibb6146e2017-07-26 23:07:52 +0000320 uint8_t digestFF[ndn::util::Sha256::DIGEST_SIZE];
Junxiao Shia9388182014-12-13 23:16:09 -0700321 std::fill_n(digestFF, sizeof(digestFF), 0xFF);
322
323 Exclude excludeDigest;
324 excludeDigest.excludeRange(
325 name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
326 name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700327
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000328 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700329 .setChildSelector(0)
330 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600331 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700332
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000333 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800334 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700335 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600336 CHECK_CS_FIND(3);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400337
Junxiao Shia9388182014-12-13 23:16:09 -0700338 Exclude excludeGeneric;
339 excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400340
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000341 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700342 .setChildSelector(0)
343 .setExclude(excludeGeneric);
mzhang4eab72492015-02-25 11:16:09 -0600344 find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
Junxiao Shia9388182014-12-13 23:16:09 -0700345
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000346 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400347 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700348 .setExclude(excludeGeneric);
mzhang4eab72492015-02-25 11:16:09 -0600349 find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
Junxiao Shia9388182014-12-13 23:16:09 -0700350
351 Exclude exclude2 = excludeGeneric;
352 exclude2.excludeOne(n2.get(-1));
353
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000354 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700355 .setChildSelector(0)
356 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600357 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400358
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000359 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400360 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700361 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600362 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400363}
364
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700365BOOST_AUTO_TEST_SUITE_END() // Find
366
367// When the capacity limit is set to zero, Data cannot be inserted;
368// this test case covers this situation.
369// The behavior of non-zero capacity limit depends on the eviction policy,
370// and is tested in policy test suites.
371BOOST_FIXTURE_TEST_CASE(ZeroCapacity, FindFixture)
372{
373 m_cs.setLimit(0);
374
375 BOOST_CHECK_EQUAL(m_cs.getLimit(), 0);
376 BOOST_CHECK_EQUAL(m_cs.size(), 0);
377 BOOST_CHECK(m_cs.begin() == m_cs.end());
378
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000379 insert(1, "/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700380 BOOST_CHECK_EQUAL(m_cs.size(), 0);
381
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000382 startInterest("/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700383 CHECK_CS_FIND(0);
384}
Junxiao Shia9388182014-12-13 23:16:09 -0700385
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000386BOOST_FIXTURE_TEST_CASE(CachePolicyNoCache, FindFixture)
Junxiao Shi35b16b12015-02-16 22:14:57 -0700387{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000388 insert(1, "/A", [] (Data& data) {
389 data.setTag(make_shared<lp::CachePolicyTag>(
390 lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)));
391 });
Junxiao Shi35b16b12015-02-16 22:14:57 -0700392
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000393 startInterest("/A");
394 CHECK_CS_FIND(0);
Junxiao Shi35b16b12015-02-16 22:14:57 -0700395}
396
Junxiao Shifc206962015-01-16 11:12:22 -0700397BOOST_AUTO_TEST_CASE(Enumeration)
398{
399 Cs cs;
400
401 Name nameA("/A");
402 Name nameAB("/A/B");
403 Name nameABC("/A/B/C");
404 Name nameD("/D");
405
406 BOOST_CHECK_EQUAL(cs.size(), 0);
407 BOOST_CHECK(cs.begin() == cs.end());
408
409 cs.insert(*makeData(nameABC));
410 BOOST_CHECK_EQUAL(cs.size(), 1);
411 BOOST_CHECK(cs.begin() != cs.end());
412 BOOST_CHECK(cs.begin()->getName() == nameABC);
413 BOOST_CHECK((*cs.begin()).getName() == nameABC);
414
415 auto i = cs.begin();
416 auto j = cs.begin();
417 BOOST_CHECK(++i == cs.end());
418 BOOST_CHECK(j++ == cs.begin());
419 BOOST_CHECK(j == cs.end());
420
421 cs.insert(*makeData(nameA));
422 cs.insert(*makeData(nameAB));
423 cs.insert(*makeData(nameD));
424
425 std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
426 std::set<Name> actual;
427 for (const auto& csEntry : cs) {
428 actual.insert(csEntry.getName());
429 }
430 BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
431}
432
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700433BOOST_AUTO_TEST_SUITE_END() // TestCs
434BOOST_AUTO_TEST_SUITE_END() // Table
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800435
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700436} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800437} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800438} // namespace nfd