blob: ecbbf38b71b9273e918eaa4ec5bed82768e94d2b [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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"
Junxiao Shicbc8e942016-09-06 03:17:45 +000027#include <ndn-cxx/lp/tags.hpp>
Junxiao Shia9388182014-12-13 23:16:09 -070028#include <ndn-cxx/util/crypto.hpp>
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080029
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030#include "tests/test-common.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080031
mzhang4eab72492015-02-25 11:16:09 -060032#define CHECK_CS_FIND(expected) find([&] (uint32_t found) { BOOST_CHECK_EQUAL(expected, found); });
33
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035namespace cs {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036namespace tests {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070037
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080038using namespace nfd::tests;
39
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -070040BOOST_AUTO_TEST_SUITE(Table)
41BOOST_FIXTURE_TEST_SUITE(TestCs, BaseFixture)
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070042
Junxiao Shi1fbdb542017-02-03 00:05:53 +000043class FindFixture : public UnitTestTimeFixture
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080044{
45protected:
Junxiao Shia9388182014-12-13 23:16:09 -070046 Name
Junxiao Shi1fbdb542017-02-03 00:05:53 +000047 insert(uint32_t id, const Name& name, const std::function<void(Data&)>& modifyData = nullptr)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048 {
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040049 shared_ptr<Data> data = makeData(name);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070050 data->setFreshnessPeriod(time::milliseconds(99999));
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080051 data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070052
Junxiao Shi1fbdb542017-02-03 00:05:53 +000053 if (modifyData != nullptr) {
54 modifyData(*data);
55 }
56
57 data->wireEncode();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080058 m_cs.insert(*data);
Junxiao Shia9388182014-12-13 23:16:09 -070059
60 return data->getFullName();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080061 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070062
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080063 Interest&
64 startInterest(const Name& name)
65 {
66 m_interest = make_shared<Interest>(name);
67 return *m_interest;
68 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070069
mzhang4eab72492015-02-25 11:16:09 -060070 void
71 find(const std::function<void(uint32_t)>& check)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080072 {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000073 bool hasResult = false;
mzhang4eab72492015-02-25 11:16:09 -060074 m_cs.find(*m_interest,
75 [&] (const Interest& interest, const Data& data) {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000076 hasResult = true;
77 const Block& content = data.getContent();
78 uint32_t found = *reinterpret_cast<const uint32_t*>(content.value());
79 check(found);
80 },
81 bind([&] {
82 hasResult = true;
83 check(0);
84 }));
85
86 // current Cs::find implementation performs lookup synchronously
87 BOOST_CHECK(hasResult);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080088 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070089
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080090protected:
91 Cs m_cs;
92 shared_ptr<Interest> m_interest;
93};
94
95BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
96
97BOOST_AUTO_TEST_CASE(EmptyDataName)
98{
Junxiao Shi1fbdb542017-02-03 00:05:53 +000099 insert(1, "/");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700100
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000101 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600102 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800103}
104
105BOOST_AUTO_TEST_CASE(EmptyInterestName)
106{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000107 insert(1, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700108
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000109 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600110 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800111}
112
Junxiao Shia9388182014-12-13 23:16:09 -0700113BOOST_AUTO_TEST_CASE(ExactName)
114{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000115 insert(1, "/");
116 insert(2, "/A");
117 insert(3, "/A/B");
118 insert(4, "/A/C");
119 insert(5, "/D");
Junxiao Shia9388182014-12-13 23:16:09 -0700120
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000121 startInterest("/A");
mzhang4eab72492015-02-25 11:16:09 -0600122 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700123}
124
125BOOST_AUTO_TEST_CASE(FullName)
126{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000127 Name n1 = insert(1, "/A");
128 Name n2 = insert(2, "/A");
Junxiao Shia9388182014-12-13 23:16:09 -0700129
130 startInterest(n1);
mzhang4eab72492015-02-25 11:16:09 -0600131 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700132
133 startInterest(n2);
mzhang4eab72492015-02-25 11:16:09 -0600134 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700135}
136
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800137BOOST_AUTO_TEST_CASE(Leftmost)
138{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000139 insert(1, "/A");
140 insert(2, "/B/p/1");
141 insert(3, "/B/p/2");
142 insert(4, "/B/q/1");
143 insert(5, "/B/q/2");
144 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700145
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000146 startInterest("/B");
mzhang4eab72492015-02-25 11:16:09 -0600147 CHECK_CS_FIND(2);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800148}
149
150BOOST_AUTO_TEST_CASE(Rightmost)
151{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000152 insert(1, "/A");
153 insert(2, "/B/p/1");
154 insert(3, "/B/p/2");
155 insert(4, "/B/q/1");
156 insert(5, "/B/q/2");
157 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700158
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000159 startInterest("/B")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800160 .setChildSelector(1);
mzhang4eab72492015-02-25 11:16:09 -0600161 CHECK_CS_FIND(4);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800162}
163
Junxiao Shia9388182014-12-13 23:16:09 -0700164BOOST_AUTO_TEST_CASE(MinSuffixComponents)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800165{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000166 insert(1, "/");
167 insert(2, "/A");
168 insert(3, "/B/1");
169 insert(4, "/C/1/2");
170 insert(5, "/D/1/2/3");
171 insert(6, "/E/1/2/3/4");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700172
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000173 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800174 .setMinSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600175 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700176
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000177 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700178 .setMinSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600179 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700180
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000181 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700182 .setMinSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600183 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700184
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000185 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700186 .setMinSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600187 CHECK_CS_FIND(3);
Junxiao Shia9388182014-12-13 23:16:09 -0700188
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000189 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700190 .setMinSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600191 CHECK_CS_FIND(4);
Junxiao Shia9388182014-12-13 23:16:09 -0700192
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000193 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700194 .setMinSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600195 CHECK_CS_FIND(5);
Junxiao Shia9388182014-12-13 23:16:09 -0700196
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000197 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700198 .setMinSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600199 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700200
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000201 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800202 .setMinSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600203 CHECK_CS_FIND(0);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800204}
205
206BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
207{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000208 insert(1, "/");
209 insert(2, "/A");
210 insert(3, "/B/2");
211 insert(4, "/C/2/3");
212 insert(5, "/D/2/3/4");
213 insert(6, "/E/2/3/4/5");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700214
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000215 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700216 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800217 .setMaxSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600218 CHECK_CS_FIND(0);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700219
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000220 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700221 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800222 .setMaxSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600223 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700224
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000225 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700226 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800227 .setMaxSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600228 CHECK_CS_FIND(2);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700229
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000230 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700231 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800232 .setMaxSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600233 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700234
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000235 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700236 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800237 .setMaxSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600238 CHECK_CS_FIND(4);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700239
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000240 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700241 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800242 .setMaxSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600243 CHECK_CS_FIND(5);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700244
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000245 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700246 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800247 .setMaxSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600248 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700249
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000250 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700251 .setChildSelector(1)
252 .setMaxSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600253 CHECK_CS_FIND(6);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800254}
255
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000256BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MustBeFresh, 1)
257BOOST_AUTO_TEST_CASE(MustBeFresh)
258{
259 ///\todo #3944 add /A/1 without FreshnessPeriod, which is same as FreshnessPeriod=0ms
260 insert(2, "/A/2", [] (Data& data) { data.setFreshnessPeriod(time::seconds(0)); });
261 insert(3, "/A/3", [] (Data& data) { data.setFreshnessPeriod(time::seconds(1)); });
262 insert(4, "/A/4", [] (Data& data) { data.setFreshnessPeriod(time::seconds(3600)); });
263 insert(5, "/A/5"); // omitted FreshnessPeriod means infinite
264 ///\todo #3944 delete /A/5
265
266 // lookup at exact same moment as insertion is not tested because this won't happen in reality
267
268 this->advanceClocks(time::milliseconds(500)); // @500ms
269 startInterest("/A")
270 .setMustBeFresh(true);
271 CHECK_CS_FIND(3);
272
273 this->advanceClocks(time::milliseconds(1500)); // @2s
274 startInterest("/A")
275 .setMustBeFresh(true);
276 CHECK_CS_FIND(4);
277
278 this->advanceClocks(time::seconds(3500)); // @3502s
279 startInterest("/A")
280 .setMustBeFresh(true);
281 CHECK_CS_FIND(4);
282
283 this->advanceClocks(time::seconds(3500)); // @7002s
284 startInterest("/A")
285 .setMustBeFresh(true);
286 CHECK_CS_FIND(5); // expected failure https://redmine.named-data.net/issues/3944#note-2
287 ///\todo #3944 this should not find any Data
288}
289
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800290BOOST_AUTO_TEST_CASE(DigestOrder)
291{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000292 Name n1 = insert(1, "/A");
293 Name n2 = insert(2, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700294
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000295 uint32_t expectedLeftmost = 0, expectedRightmost = 0;
296 if (n1 < n2) {
297 expectedLeftmost = 1;
298 expectedRightmost = 2;
299 }
300 else {
301 BOOST_CHECK_MESSAGE(n1 != n2, "implicit digest collision detected");
302 expectedLeftmost = 2;
303 expectedRightmost = 1;
304 }
305
306 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800307 .setChildSelector(0);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000308 CHECK_CS_FIND(expectedLeftmost);
309 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800310 .setChildSelector(1);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000311 CHECK_CS_FIND(expectedRightmost);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800312}
313
314BOOST_AUTO_TEST_CASE(DigestExclude)
315{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000316 insert(1, "/A");
317 Name n2 = insert(2, "/A");
318 insert(3, "/A/B");
Junxiao Shia9388182014-12-13 23:16:09 -0700319
320 uint8_t digest00[ndn::crypto::SHA256_DIGEST_SIZE];
321 std::fill_n(digest00, sizeof(digest00), 0x00);
322 uint8_t digestFF[ndn::crypto::SHA256_DIGEST_SIZE];
323 std::fill_n(digestFF, sizeof(digestFF), 0xFF);
324
325 Exclude excludeDigest;
326 excludeDigest.excludeRange(
327 name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
328 name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700329
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000330 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700331 .setChildSelector(0)
332 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600333 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700334
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000335 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800336 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700337 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600338 CHECK_CS_FIND(3);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400339
Junxiao Shia9388182014-12-13 23:16:09 -0700340 Exclude excludeGeneric;
341 excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400342
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000343 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700344 .setChildSelector(0)
345 .setExclude(excludeGeneric);
mzhang4eab72492015-02-25 11:16:09 -0600346 find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
Junxiao Shia9388182014-12-13 23:16:09 -0700347
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000348 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400349 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700350 .setExclude(excludeGeneric);
mzhang4eab72492015-02-25 11:16:09 -0600351 find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
Junxiao Shia9388182014-12-13 23:16:09 -0700352
353 Exclude exclude2 = excludeGeneric;
354 exclude2.excludeOne(n2.get(-1));
355
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000356 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700357 .setChildSelector(0)
358 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600359 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400360
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000361 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400362 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700363 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600364 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400365}
366
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700367BOOST_AUTO_TEST_SUITE_END() // Find
368
369// When the capacity limit is set to zero, Data cannot be inserted;
370// this test case covers this situation.
371// The behavior of non-zero capacity limit depends on the eviction policy,
372// and is tested in policy test suites.
373BOOST_FIXTURE_TEST_CASE(ZeroCapacity, FindFixture)
374{
375 m_cs.setLimit(0);
376
377 BOOST_CHECK_EQUAL(m_cs.getLimit(), 0);
378 BOOST_CHECK_EQUAL(m_cs.size(), 0);
379 BOOST_CHECK(m_cs.begin() == m_cs.end());
380
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000381 insert(1, "/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700382 BOOST_CHECK_EQUAL(m_cs.size(), 0);
383
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000384 startInterest("/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700385 CHECK_CS_FIND(0);
386}
Junxiao Shia9388182014-12-13 23:16:09 -0700387
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000388BOOST_FIXTURE_TEST_CASE(CachePolicyNoCache, FindFixture)
Junxiao Shi35b16b12015-02-16 22:14:57 -0700389{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000390 insert(1, "/A", [] (Data& data) {
391 data.setTag(make_shared<lp::CachePolicyTag>(
392 lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)));
393 });
Junxiao Shi35b16b12015-02-16 22:14:57 -0700394
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000395 startInterest("/A");
396 CHECK_CS_FIND(0);
Junxiao Shi35b16b12015-02-16 22:14:57 -0700397}
398
Junxiao Shifc206962015-01-16 11:12:22 -0700399BOOST_AUTO_TEST_CASE(Enumeration)
400{
401 Cs cs;
402
403 Name nameA("/A");
404 Name nameAB("/A/B");
405 Name nameABC("/A/B/C");
406 Name nameD("/D");
407
408 BOOST_CHECK_EQUAL(cs.size(), 0);
409 BOOST_CHECK(cs.begin() == cs.end());
410
411 cs.insert(*makeData(nameABC));
412 BOOST_CHECK_EQUAL(cs.size(), 1);
413 BOOST_CHECK(cs.begin() != cs.end());
414 BOOST_CHECK(cs.begin()->getName() == nameABC);
415 BOOST_CHECK((*cs.begin()).getName() == nameABC);
416
417 auto i = cs.begin();
418 auto j = cs.begin();
419 BOOST_CHECK(++i == cs.end());
420 BOOST_CHECK(j++ == cs.begin());
421 BOOST_CHECK(j == cs.end());
422
423 cs.insert(*makeData(nameA));
424 cs.insert(*makeData(nameAB));
425 cs.insert(*makeData(nameD));
426
427 std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
428 std::set<Name> actual;
429 for (const auto& csEntry : cs) {
430 actual.insert(csEntry.getName());
431 }
432 BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
433}
434
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700435BOOST_AUTO_TEST_SUITE_END() // TestCs
436BOOST_AUTO_TEST_SUITE_END() // Table
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800437
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700438} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800439} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800440} // namespace nfd