blob: 0e14b0fd746d9369e379718ffa15624a2c7e47ea [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);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080050 data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070051
Junxiao Shi1fbdb542017-02-03 00:05:53 +000052 if (modifyData != nullptr) {
53 modifyData(*data);
54 }
55
56 data->wireEncode();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080057 m_cs.insert(*data);
Junxiao Shia9388182014-12-13 23:16:09 -070058
59 return data->getFullName();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080060 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070061
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080062 Interest&
63 startInterest(const Name& name)
64 {
65 m_interest = make_shared<Interest>(name);
66 return *m_interest;
67 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070068
mzhang4eab72492015-02-25 11:16:09 -060069 void
70 find(const std::function<void(uint32_t)>& check)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080071 {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000072 bool hasResult = false;
mzhang4eab72492015-02-25 11:16:09 -060073 m_cs.find(*m_interest,
74 [&] (const Interest& interest, const Data& data) {
Junxiao Shi1fbdb542017-02-03 00:05:53 +000075 hasResult = true;
76 const Block& content = data.getContent();
77 uint32_t found = *reinterpret_cast<const uint32_t*>(content.value());
78 check(found);
79 },
80 bind([&] {
81 hasResult = true;
82 check(0);
83 }));
84
85 // current Cs::find implementation performs lookup synchronously
86 BOOST_CHECK(hasResult);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080087 }
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070088
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080089protected:
90 Cs m_cs;
91 shared_ptr<Interest> m_interest;
92};
93
94BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
95
96BOOST_AUTO_TEST_CASE(EmptyDataName)
97{
Junxiao Shi1fbdb542017-02-03 00:05:53 +000098 insert(1, "/");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070099
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000100 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600101 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800102}
103
104BOOST_AUTO_TEST_CASE(EmptyInterestName)
105{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000106 insert(1, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700107
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000108 startInterest("/");
mzhang4eab72492015-02-25 11:16:09 -0600109 CHECK_CS_FIND(1);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800110}
111
Junxiao Shia9388182014-12-13 23:16:09 -0700112BOOST_AUTO_TEST_CASE(ExactName)
113{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000114 insert(1, "/");
115 insert(2, "/A");
116 insert(3, "/A/B");
117 insert(4, "/A/C");
118 insert(5, "/D");
Junxiao Shia9388182014-12-13 23:16:09 -0700119
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000120 startInterest("/A");
mzhang4eab72492015-02-25 11:16:09 -0600121 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700122}
123
124BOOST_AUTO_TEST_CASE(FullName)
125{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000126 Name n1 = insert(1, "/A");
127 Name n2 = insert(2, "/A");
Junxiao Shia9388182014-12-13 23:16:09 -0700128
129 startInterest(n1);
mzhang4eab72492015-02-25 11:16:09 -0600130 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700131
132 startInterest(n2);
mzhang4eab72492015-02-25 11:16:09 -0600133 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700134}
135
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800136BOOST_AUTO_TEST_CASE(Leftmost)
137{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000138 insert(1, "/A");
139 insert(2, "/B/p/1");
140 insert(3, "/B/p/2");
141 insert(4, "/B/q/1");
142 insert(5, "/B/q/2");
143 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700144
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000145 startInterest("/B");
mzhang4eab72492015-02-25 11:16:09 -0600146 CHECK_CS_FIND(2);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800147}
148
149BOOST_AUTO_TEST_CASE(Rightmost)
150{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000151 insert(1, "/A");
152 insert(2, "/B/p/1");
153 insert(3, "/B/p/2");
154 insert(4, "/B/q/1");
155 insert(5, "/B/q/2");
156 insert(6, "/C");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700157
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000158 startInterest("/B")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800159 .setChildSelector(1);
mzhang4eab72492015-02-25 11:16:09 -0600160 CHECK_CS_FIND(4);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800161}
162
Junxiao Shia9388182014-12-13 23:16:09 -0700163BOOST_AUTO_TEST_CASE(MinSuffixComponents)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800164{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000165 insert(1, "/");
166 insert(2, "/A");
167 insert(3, "/B/1");
168 insert(4, "/C/1/2");
169 insert(5, "/D/1/2/3");
170 insert(6, "/E/1/2/3/4");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700171
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000172 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800173 .setMinSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600174 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700175
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000176 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700177 .setMinSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600178 CHECK_CS_FIND(1);
Junxiao Shia9388182014-12-13 23:16:09 -0700179
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000180 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700181 .setMinSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600182 CHECK_CS_FIND(2);
Junxiao Shia9388182014-12-13 23:16:09 -0700183
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000184 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700185 .setMinSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600186 CHECK_CS_FIND(3);
Junxiao Shia9388182014-12-13 23:16:09 -0700187
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000188 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700189 .setMinSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600190 CHECK_CS_FIND(4);
Junxiao Shia9388182014-12-13 23:16:09 -0700191
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000192 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700193 .setMinSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600194 CHECK_CS_FIND(5);
Junxiao Shia9388182014-12-13 23:16:09 -0700195
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000196 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700197 .setMinSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600198 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700199
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000200 startInterest("/")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800201 .setMinSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600202 CHECK_CS_FIND(0);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800203}
204
205BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
206{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000207 insert(1, "/");
208 insert(2, "/A");
209 insert(3, "/B/2");
210 insert(4, "/C/2/3");
211 insert(5, "/D/2/3/4");
212 insert(6, "/E/2/3/4/5");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700213
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000214 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700215 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800216 .setMaxSuffixComponents(0);
mzhang4eab72492015-02-25 11:16:09 -0600217 CHECK_CS_FIND(0);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700218
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000219 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700220 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800221 .setMaxSuffixComponents(1);
mzhang4eab72492015-02-25 11:16:09 -0600222 CHECK_CS_FIND(1);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700223
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000224 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700225 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800226 .setMaxSuffixComponents(2);
mzhang4eab72492015-02-25 11:16:09 -0600227 CHECK_CS_FIND(2);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700228
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000229 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700230 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800231 .setMaxSuffixComponents(3);
mzhang4eab72492015-02-25 11:16:09 -0600232 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700233
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000234 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700235 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800236 .setMaxSuffixComponents(4);
mzhang4eab72492015-02-25 11:16:09 -0600237 CHECK_CS_FIND(4);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700238
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000239 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700240 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800241 .setMaxSuffixComponents(5);
mzhang4eab72492015-02-25 11:16:09 -0600242 CHECK_CS_FIND(5);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700243
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000244 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700245 .setChildSelector(1)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800246 .setMaxSuffixComponents(6);
mzhang4eab72492015-02-25 11:16:09 -0600247 CHECK_CS_FIND(6);
Junxiao Shia9388182014-12-13 23:16:09 -0700248
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000249 startInterest("/")
Junxiao Shia9388182014-12-13 23:16:09 -0700250 .setChildSelector(1)
251 .setMaxSuffixComponents(7);
mzhang4eab72492015-02-25 11:16:09 -0600252 CHECK_CS_FIND(6);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800253}
254
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000255BOOST_AUTO_TEST_CASE(MustBeFresh)
256{
Eric Newberryf4056d02017-05-26 17:31:53 +0000257 insert(1, "/A/1"); // omitted FreshnessPeriod means FreshnessPeriod = 0 ms
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000258 insert(2, "/A/2", [] (Data& data) { data.setFreshnessPeriod(time::seconds(0)); });
259 insert(3, "/A/3", [] (Data& data) { data.setFreshnessPeriod(time::seconds(1)); });
260 insert(4, "/A/4", [] (Data& data) { data.setFreshnessPeriod(time::seconds(3600)); });
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000261
262 // lookup at exact same moment as insertion is not tested because this won't happen in reality
263
264 this->advanceClocks(time::milliseconds(500)); // @500ms
265 startInterest("/A")
266 .setMustBeFresh(true);
267 CHECK_CS_FIND(3);
268
269 this->advanceClocks(time::milliseconds(1500)); // @2s
270 startInterest("/A")
271 .setMustBeFresh(true);
272 CHECK_CS_FIND(4);
273
274 this->advanceClocks(time::seconds(3500)); // @3502s
275 startInterest("/A")
276 .setMustBeFresh(true);
277 CHECK_CS_FIND(4);
278
279 this->advanceClocks(time::seconds(3500)); // @7002s
280 startInterest("/A")
281 .setMustBeFresh(true);
Eric Newberryf4056d02017-05-26 17:31:53 +0000282 CHECK_CS_FIND(0);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000283}
284
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800285BOOST_AUTO_TEST_CASE(DigestOrder)
286{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000287 Name n1 = insert(1, "/A");
288 Name n2 = insert(2, "/A");
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700289
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000290 uint32_t expectedLeftmost = 0, expectedRightmost = 0;
291 if (n1 < n2) {
292 expectedLeftmost = 1;
293 expectedRightmost = 2;
294 }
295 else {
296 BOOST_CHECK_MESSAGE(n1 != n2, "implicit digest collision detected");
297 expectedLeftmost = 2;
298 expectedRightmost = 1;
299 }
300
301 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800302 .setChildSelector(0);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000303 CHECK_CS_FIND(expectedLeftmost);
304 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800305 .setChildSelector(1);
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000306 CHECK_CS_FIND(expectedRightmost);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800307}
308
309BOOST_AUTO_TEST_CASE(DigestExclude)
310{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000311 insert(1, "/A");
312 Name n2 = insert(2, "/A");
313 insert(3, "/A/B");
Junxiao Shia9388182014-12-13 23:16:09 -0700314
315 uint8_t digest00[ndn::crypto::SHA256_DIGEST_SIZE];
316 std::fill_n(digest00, sizeof(digest00), 0x00);
317 uint8_t digestFF[ndn::crypto::SHA256_DIGEST_SIZE];
318 std::fill_n(digestFF, sizeof(digestFF), 0xFF);
319
320 Exclude excludeDigest;
321 excludeDigest.excludeRange(
322 name::Component::fromImplicitSha256Digest(digest00, sizeof(digest00)),
323 name::Component::fromImplicitSha256Digest(digestFF, sizeof(digestFF)));
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700324
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000325 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700326 .setChildSelector(0)
327 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600328 CHECK_CS_FIND(3);
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -0700329
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000330 startInterest("/A")
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800331 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700332 .setExclude(excludeDigest);
mzhang4eab72492015-02-25 11:16:09 -0600333 CHECK_CS_FIND(3);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400334
Junxiao Shia9388182014-12-13 23:16:09 -0700335 Exclude excludeGeneric;
336 excludeGeneric.excludeAfter(name::Component(static_cast<uint8_t*>(nullptr), 0));
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400337
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000338 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700339 .setChildSelector(0)
340 .setExclude(excludeGeneric);
mzhang4eab72492015-02-25 11:16:09 -0600341 find([] (uint32_t found) { BOOST_CHECK(found == 1 || found == 2); });
Junxiao Shia9388182014-12-13 23:16:09 -0700342
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000343 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400344 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700345 .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
348 Exclude exclude2 = excludeGeneric;
349 exclude2.excludeOne(n2.get(-1));
350
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000351 startInterest("/A")
Junxiao Shia9388182014-12-13 23:16:09 -0700352 .setChildSelector(0)
353 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600354 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400355
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000356 startInterest("/A")
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400357 .setChildSelector(1)
Junxiao Shia9388182014-12-13 23:16:09 -0700358 .setExclude(exclude2);
mzhang4eab72492015-02-25 11:16:09 -0600359 CHECK_CS_FIND(1);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400360}
361
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700362BOOST_AUTO_TEST_SUITE_END() // Find
363
364// When the capacity limit is set to zero, Data cannot be inserted;
365// this test case covers this situation.
366// The behavior of non-zero capacity limit depends on the eviction policy,
367// and is tested in policy test suites.
368BOOST_FIXTURE_TEST_CASE(ZeroCapacity, FindFixture)
369{
370 m_cs.setLimit(0);
371
372 BOOST_CHECK_EQUAL(m_cs.getLimit(), 0);
373 BOOST_CHECK_EQUAL(m_cs.size(), 0);
374 BOOST_CHECK(m_cs.begin() == m_cs.end());
375
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000376 insert(1, "/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700377 BOOST_CHECK_EQUAL(m_cs.size(), 0);
378
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000379 startInterest("/A");
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700380 CHECK_CS_FIND(0);
381}
Junxiao Shia9388182014-12-13 23:16:09 -0700382
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000383BOOST_FIXTURE_TEST_CASE(CachePolicyNoCache, FindFixture)
Junxiao Shi35b16b12015-02-16 22:14:57 -0700384{
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000385 insert(1, "/A", [] (Data& data) {
386 data.setTag(make_shared<lp::CachePolicyTag>(
387 lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)));
388 });
Junxiao Shi35b16b12015-02-16 22:14:57 -0700389
Junxiao Shi1fbdb542017-02-03 00:05:53 +0000390 startInterest("/A");
391 CHECK_CS_FIND(0);
Junxiao Shi35b16b12015-02-16 22:14:57 -0700392}
393
Junxiao Shifc206962015-01-16 11:12:22 -0700394BOOST_AUTO_TEST_CASE(Enumeration)
395{
396 Cs cs;
397
398 Name nameA("/A");
399 Name nameAB("/A/B");
400 Name nameABC("/A/B/C");
401 Name nameD("/D");
402
403 BOOST_CHECK_EQUAL(cs.size(), 0);
404 BOOST_CHECK(cs.begin() == cs.end());
405
406 cs.insert(*makeData(nameABC));
407 BOOST_CHECK_EQUAL(cs.size(), 1);
408 BOOST_CHECK(cs.begin() != cs.end());
409 BOOST_CHECK(cs.begin()->getName() == nameABC);
410 BOOST_CHECK((*cs.begin()).getName() == nameABC);
411
412 auto i = cs.begin();
413 auto j = cs.begin();
414 BOOST_CHECK(++i == cs.end());
415 BOOST_CHECK(j++ == cs.begin());
416 BOOST_CHECK(j == cs.end());
417
418 cs.insert(*makeData(nameA));
419 cs.insert(*makeData(nameAB));
420 cs.insert(*makeData(nameD));
421
422 std::set<Name> expected = {nameA, nameAB, nameABC, nameD};
423 std::set<Name> actual;
424 for (const auto& csEntry : cs) {
425 actual.insert(csEntry.getName());
426 }
427 BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
428}
429
Minsheng Zhangffe8bbb2016-03-10 13:40:37 -0700430BOOST_AUTO_TEST_SUITE_END() // TestCs
431BOOST_AUTO_TEST_SUITE_END() // Table
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800432
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700433} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800434} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800435} // namespace nfd