Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 9 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * \author Ilya Moiseenko <iliamo@ucla.edu> |
| 25 | **/ |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 26 | |
| 27 | #include "table/cs.hpp" |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 28 | #include "table/cs-entry.hpp" |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 29 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 30 | #include "tests/test-common.hpp" |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 34 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 35 | class CsAccessor : public Cs |
| 36 | { |
| 37 | public: |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 38 | bool |
| 39 | evictItem_accessor() |
| 40 | { |
| 41 | return evictItem(); |
| 42 | } |
| 43 | }; |
| 44 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 45 | BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture) |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 46 | |
Alexander Afanasyev | 281b916 | 2014-06-08 10:15:20 +0300 | [diff] [blame] | 47 | BOOST_AUTO_TEST_CASE(SetLimit) |
| 48 | { |
| 49 | Cs cs(1); |
| 50 | |
| 51 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/1")), true); |
| 52 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/2")), true); |
| 53 | BOOST_CHECK_EQUAL(cs.size(), 1); |
| 54 | |
| 55 | cs.setLimit(3); |
| 56 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/3")), true); |
| 57 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/4")), true); |
| 58 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/5")), true); |
| 59 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 60 | |
| 61 | cs.setLimit(2); |
| 62 | BOOST_CHECK_EQUAL(cs.size(), 2); |
| 63 | } |
| 64 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(Insertion) |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 66 | { |
| 67 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 68 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(cs.insert(*makeData("/insertion")), true); |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 72 | BOOST_AUTO_TEST_CASE(Insertion2) |
| 73 | { |
| 74 | Cs cs; |
| 75 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 76 | cs.insert(*makeData("/a")); |
| 77 | cs.insert(*makeData("/b")); |
| 78 | cs.insert(*makeData("/c")); |
| 79 | cs.insert(*makeData("/d")); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 80 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(cs.size(), 4); |
| 82 | } |
| 83 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(DuplicateInsertion) |
| 85 | { |
| 86 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 87 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 88 | shared_ptr<Data> data0 = makeData("/insert/smth"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(cs.insert(*data0), true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 90 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 91 | shared_ptr<Data> data = makeData("/insert/duplicate"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(cs.insert(*data), true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 93 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 94 | cs.insert(*data); |
| 95 | BOOST_CHECK_EQUAL(cs.size(), 2); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(DuplicateInsertion2) |
| 100 | { |
| 101 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 102 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 103 | shared_ptr<Data> data = makeData("/insert/duplicate"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(cs.insert(*data), true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 105 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 106 | cs.insert(*data); |
| 107 | BOOST_CHECK_EQUAL(cs.size(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 108 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 109 | shared_ptr<Data> data2 = makeData("/insert/original"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL(cs.insert(*data2), true); |
| 111 | BOOST_CHECK_EQUAL(cs.size(), 2); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(InsertAndFind) |
| 115 | { |
| 116 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 117 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 118 | Name name("/insert/and/find"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 119 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 120 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(cs.insert(*data), true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 122 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 123 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 124 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 125 | const Data* found = cs.find(*interest); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 126 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 127 | BOOST_REQUIRE(found != 0); |
| 128 | BOOST_CHECK_EQUAL(data->getName(), found->getName()); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_CASE(InsertAndNotFind) |
| 132 | { |
| 133 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 134 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 135 | Name name("/insert/and/find"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 136 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(cs.insert(*data), true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 138 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 139 | Name name2("/not/find"); |
| 140 | shared_ptr<Interest> interest = make_shared<Interest>(name2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 141 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 142 | const Data* found = cs.find(*interest); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 143 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 144 | BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0)); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(InsertAndErase) |
| 149 | { |
| 150 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 151 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 152 | shared_ptr<Data> data = makeData("/insertandelete"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 153 | cs.insert(*data); |
| 154 | BOOST_CHECK_EQUAL(cs.size(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 155 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 156 | cs.evictItem_accessor(); |
| 157 | BOOST_CHECK_EQUAL(cs.size(), 0); |
| 158 | } |
| 159 | |
| 160 | BOOST_AUTO_TEST_CASE(StalenessQueue) |
| 161 | { |
| 162 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 163 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 164 | Name name2("/insert/fresh"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 165 | shared_ptr<Data> data2 = makeData(name2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 166 | data2->setFreshnessPeriod(time::milliseconds(5000)); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 167 | signData(data2); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 168 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 169 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 170 | Name name("/insert/expire"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 171 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 172 | data->setFreshnessPeriod(time::milliseconds(500)); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 173 | signData(data); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 174 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 175 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 176 | BOOST_CHECK_EQUAL(cs.size(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 177 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 178 | sleep(3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 179 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 180 | cs.evictItem_accessor(); |
| 181 | BOOST_CHECK_EQUAL(cs.size(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 182 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 183 | shared_ptr<Interest> interest = make_shared<Interest>(name2); |
| 184 | const Data* found = cs.find(*interest); |
| 185 | BOOST_REQUIRE(found != 0); |
| 186 | BOOST_CHECK_EQUAL(found->getName(), name2); |
| 187 | } |
| 188 | |
Alexander Afanasyev | 4cf4170 | 2014-10-19 23:46:10 -0400 | [diff] [blame] | 189 | BOOST_AUTO_TEST_CASE(Bug2043) // eviction order of unsolicited packets |
| 190 | { |
| 191 | Cs cs(3); |
| 192 | |
| 193 | cs.insert(*makeData("/a"), true); |
| 194 | cs.insert(*makeData("/b"), true); |
| 195 | cs.insert(*makeData("/c"), true); |
| 196 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 197 | |
| 198 | cs.insert(*makeData("/d"), true); |
| 199 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 200 | |
| 201 | const Data* oldestData = cs.find(Interest("/a")); |
| 202 | const Data* newestData = cs.find(Interest("/c")); |
| 203 | BOOST_CHECK(oldestData == 0); |
| 204 | BOOST_CHECK(newestData != 0); |
| 205 | } |
| 206 | |
| 207 | BOOST_AUTO_TEST_CASE(UnsolicitedWithSolicitedEvictionOrder) |
| 208 | { |
| 209 | Cs cs(3); |
| 210 | |
| 211 | cs.insert(*makeData("/a"), true); |
| 212 | cs.insert(*makeData("/b"), false); |
| 213 | cs.insert(*makeData("/c"), true); |
| 214 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 215 | |
| 216 | cs.insert(*makeData("/d"), true); |
| 217 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 218 | |
| 219 | const Data* oldestData = cs.find(Interest("/a")); |
| 220 | const Data* newestData = cs.find(Interest("/c")); |
| 221 | BOOST_CHECK(oldestData == 0); |
| 222 | BOOST_CHECK(newestData != 0); |
| 223 | } |
| 224 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 225 | //even max size |
| 226 | BOOST_AUTO_TEST_CASE(ReplacementEvenSize) |
| 227 | { |
| 228 | Cs cs(4); |
| 229 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 230 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 231 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 232 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 233 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 234 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 235 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 236 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 237 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 238 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 239 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 240 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 241 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 242 | shared_ptr<Data> data5 = makeData("/e"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 243 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 244 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(cs.size(), 4); |
| 246 | } |
| 247 | |
| 248 | //odd max size |
| 249 | BOOST_AUTO_TEST_CASE(Replacement2) |
| 250 | { |
| 251 | Cs cs(3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 252 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 253 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 254 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 255 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 256 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 257 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 258 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 259 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 260 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 261 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 262 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 263 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 264 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 266 | } |
| 267 | |
| 268 | BOOST_AUTO_TEST_CASE(InsertAndEraseByName) |
| 269 | { |
| 270 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 271 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 272 | Name name("/insertandremovebyname"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 273 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 274 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 275 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 276 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 277 | data->wireEncode().size()); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 278 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 279 | shared_ptr<Data> data2 = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 280 | cs.insert(*data2); |
| 281 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 282 | shared_ptr<Data> data3 = makeData("/z"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 283 | cs.insert(*data3); |
| 284 | |
| 285 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 286 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 287 | name.append(digest1->buf(), digest1->size()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 288 | cs.erase(name); |
| 289 | BOOST_CHECK_EQUAL(cs.size(), 2); |
| 290 | } |
| 291 | |
| 292 | BOOST_AUTO_TEST_CASE(DigestCalculation) |
| 293 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 294 | shared_ptr<Data> data = makeData("/digest/compute"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 295 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 296 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 297 | data->wireEncode().size()); |
| 298 | BOOST_CHECK_EQUAL(digest1->size(), 32); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 299 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 300 | cs::Entry* entry = new cs::Entry(); |
| 301 | entry->setData(*data, false); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 302 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 303 | BOOST_CHECK_EQUAL_COLLECTIONS(digest1->begin(), digest1->end(), |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 304 | entry->getFullName()[-1].value_begin(), |
| 305 | entry->getFullName()[-1].value_end()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | BOOST_AUTO_TEST_CASE(InsertCanonical) |
| 309 | { |
| 310 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 311 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 312 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 313 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 314 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 315 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 316 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 317 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 318 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 319 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 320 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 321 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 322 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 323 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 324 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 325 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 326 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 327 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 328 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 329 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 330 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 331 | cs.insert(*data7); |
| 332 | } |
| 333 | |
| 334 | BOOST_AUTO_TEST_CASE(EraseCanonical) |
| 335 | { |
| 336 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 337 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 338 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 339 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 340 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 341 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 342 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 343 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 344 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 345 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 346 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 347 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 348 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 349 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 350 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 351 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 352 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 353 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 354 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 355 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 356 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 357 | cs.insert(*data7); |
| 358 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 359 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 360 | data->wireEncode().size()); |
| 361 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 362 | Name name("/a"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 363 | name.append(digest1->buf(), digest1->size()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 364 | cs.erase(name); |
| 365 | BOOST_CHECK_EQUAL(cs.size(), 6); |
| 366 | } |
| 367 | |
| 368 | BOOST_AUTO_TEST_CASE(ImplicitDigestSelector) |
| 369 | { |
| 370 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 371 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 372 | Name name("/digest/works"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 373 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 374 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 375 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 376 | shared_ptr<Data> data2 = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 377 | cs.insert(*data2); |
| 378 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 379 | shared_ptr<Data> data3 = makeData("/z/z/z"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 380 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 381 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 382 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 383 | data->wireEncode().size()); |
| 384 | uint8_t digest2[32] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 385 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 386 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 387 | shared_ptr<Interest> interest = make_shared<Interest>(); |
| 388 | interest->setName(Name(name).append(digest1->buf(), digest1->size())); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 389 | interest->setMinSuffixComponents(0); |
| 390 | interest->setMaxSuffixComponents(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 391 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 392 | const Data* found = cs.find(*interest); |
| 393 | BOOST_CHECK_NE(found, static_cast<const Data*>(0)); |
| 394 | BOOST_CHECK_EQUAL(found->getName(), name); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 395 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 396 | shared_ptr<Interest> interest2 = make_shared<Interest>(); |
| 397 | interest2->setName(Name(name).append(digest2, 32)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 398 | interest2->setMinSuffixComponents(0); |
| 399 | interest2->setMaxSuffixComponents(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 400 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 401 | const Data* notfound = cs.find(*interest2); |
| 402 | BOOST_CHECK_EQUAL(notfound, static_cast<const Data*>(0)); |
| 403 | } |
| 404 | |
| 405 | BOOST_AUTO_TEST_CASE(ChildSelector) |
| 406 | { |
| 407 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 408 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 409 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 410 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 411 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 412 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 413 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 414 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 415 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 416 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 417 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 418 | shared_ptr<Data> data5 = makeData("/c/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 419 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 420 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 421 | shared_ptr<Data> data6 = makeData("/c/f"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 422 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 423 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 424 | shared_ptr<Data> data7 = makeData("/c/n"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 425 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 426 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 427 | shared_ptr<Interest> interest = make_shared<Interest>("/c"); |
| 428 | interest->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 429 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 430 | const Data* found = cs.find(*interest); |
| 431 | BOOST_CHECK_EQUAL(found->getName(), "/c/n"); |
| 432 | |
| 433 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c"); |
| 434 | interest2->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 435 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 436 | const Data* found2 = cs.find(*interest2); |
| 437 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
| 438 | } |
| 439 | |
| 440 | BOOST_AUTO_TEST_CASE(ChildSelector2) |
| 441 | { |
| 442 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 443 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 444 | shared_ptr<Data> data = makeData("/a/b/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 445 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 446 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 447 | shared_ptr<Data> data2 = makeData("/a/b/2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 448 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 449 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 450 | shared_ptr<Data> data3 = makeData("/a/z/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 451 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 452 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 453 | shared_ptr<Data> data4 = makeData("/a/z/2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 454 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 455 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 456 | shared_ptr<Interest> interest = make_shared<Interest>("/a"); |
| 457 | interest->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 458 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 459 | const Data* found = cs.find(*interest); |
| 460 | BOOST_CHECK_EQUAL(found->getName(), "/a/z/1"); |
| 461 | } |
| 462 | |
| 463 | BOOST_AUTO_TEST_CASE(MustBeFreshSelector) |
| 464 | { |
| 465 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 466 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 467 | Name name("/insert/nonfresh"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 468 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 469 | data->setFreshnessPeriod(time::milliseconds(500)); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 470 | signData(data); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 471 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 472 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 473 | sleep(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 474 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 475 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 476 | interest->setMustBeFresh(true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 477 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 478 | const Data* found = cs.find(*interest); |
| 479 | BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0)); |
| 480 | } |
| 481 | |
Ilya Moiseenko | 9c9231b | 2014-04-10 11:05:12 -0400 | [diff] [blame] | 482 | BOOST_AUTO_TEST_CASE(PublisherKeySelector) |
| 483 | { |
| 484 | Cs cs; |
| 485 | |
| 486 | Name name("/insert/withkey"); |
| 487 | shared_ptr<Data> data = makeData(name); |
| 488 | cs.insert(*data); |
| 489 | |
| 490 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 491 | Name keyName("/somewhere/key"); |
| 492 | |
| 493 | ndn::KeyLocator locator(keyName); |
| 494 | interest->setPublisherPublicKeyLocator(locator); |
| 495 | |
| 496 | const Data* found = cs.find(*interest); |
| 497 | BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0)); |
| 498 | } |
| 499 | |
| 500 | BOOST_AUTO_TEST_CASE(PublisherKeySelector2) |
| 501 | { |
| 502 | Cs cs; |
| 503 | Name name("/insert/withkey"); |
| 504 | shared_ptr<Data> data = makeData(name); |
| 505 | cs.insert(*data); |
| 506 | |
| 507 | Name name2("/insert/withkey2"); |
| 508 | shared_ptr<Data> data2 = make_shared<Data>(name2); |
| 509 | |
| 510 | Name keyName("/somewhere/key"); |
| 511 | const ndn::KeyLocator locator(keyName); |
| 512 | |
| 513 | ndn::SignatureSha256WithRsa fakeSignature; |
| 514 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 515 | reinterpret_cast<const uint8_t*>(0), 0)); |
| 516 | |
| 517 | fakeSignature.setKeyLocator(locator); |
| 518 | data2->setSignature(fakeSignature); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 519 | data2->wireEncode(); |
Ilya Moiseenko | 9c9231b | 2014-04-10 11:05:12 -0400 | [diff] [blame] | 520 | |
| 521 | cs.insert(*data2); |
| 522 | |
| 523 | shared_ptr<Interest> interest = make_shared<Interest>(name2); |
| 524 | interest->setPublisherPublicKeyLocator(locator); |
| 525 | |
| 526 | const Data* found = cs.find(*interest); |
| 527 | BOOST_CHECK_NE(found, static_cast<const Data*>(0)); |
| 528 | BOOST_CHECK_EQUAL(found->getName(), data2->getName()); |
| 529 | } |
| 530 | |
| 531 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 532 | BOOST_AUTO_TEST_CASE(MinMaxComponentsSelector) |
| 533 | { |
| 534 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 535 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 536 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 537 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 538 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 539 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 540 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 541 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 542 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 543 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 544 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 545 | shared_ptr<Data> data5 = makeData("/c/c/1/2/3/4/5/6"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 546 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 547 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 548 | shared_ptr<Data> data6 = makeData("/c/c/6/7/8/9"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 549 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 550 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 551 | shared_ptr<Data> data7 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 552 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 553 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 554 | shared_ptr<Data> data8 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 555 | cs.insert(*data8); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 556 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 557 | shared_ptr<Interest> interest = make_shared<Interest>("/c/c"); |
| 558 | interest->setMinSuffixComponents(3); |
| 559 | interest->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 560 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 561 | const Data* found = cs.find(*interest); |
| 562 | BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3/4/5/6"); |
| 563 | |
| 564 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c/c"); |
| 565 | interest2->setMinSuffixComponents(4); |
| 566 | interest2->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 567 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 568 | const Data* found2 = cs.find(*interest2); |
| 569 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 570 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 571 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c/c"); |
| 572 | interest3->setMaxSuffixComponents(2); |
| 573 | interest3->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 574 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 575 | const Data* found3 = cs.find(*interest3); |
| 576 | BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1"); |
| 577 | } |
| 578 | |
| 579 | BOOST_AUTO_TEST_CASE(ExcludeSelector) |
| 580 | { |
| 581 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 582 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 583 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 584 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 585 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 586 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 587 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 588 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 589 | shared_ptr<Data> data3 = makeData("/c/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 590 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 591 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 592 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 593 | cs.insert(*data4); |
| 594 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 595 | shared_ptr<Data> data5 = makeData("/c/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 596 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 597 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 598 | shared_ptr<Data> data6 = makeData("/c/f"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 599 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 600 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 601 | shared_ptr<Data> data7 = makeData("/c/n"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 602 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 603 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 604 | shared_ptr<Interest> interest = make_shared<Interest>("/c"); |
| 605 | interest->setChildSelector(1); |
| 606 | Exclude e; |
| 607 | e.excludeOne (Name::Component("n")); |
| 608 | interest->setExclude(e); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 609 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 610 | const Data* found = cs.find(*interest); |
| 611 | BOOST_CHECK_EQUAL(found->getName(), "/c/f"); |
| 612 | |
| 613 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c"); |
| 614 | interest2->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 615 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 616 | Exclude e2; |
| 617 | e2.excludeOne (Name::Component("a")); |
| 618 | interest2->setExclude(e2); |
| 619 | |
| 620 | const Data* found2 = cs.find(*interest2); |
| 621 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 622 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 623 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c"); |
| 624 | interest3->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 625 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 626 | Exclude e3; |
| 627 | e3.excludeOne (Name::Component("c")); |
| 628 | interest3->setExclude(e3); |
| 629 | |
| 630 | const Data* found3 = cs.find(*interest3); |
| 631 | BOOST_CHECK_EQUAL(found3->getName(), "/c/a"); |
| 632 | } |
| 633 | |
| 634 | // |
| 635 | |
| 636 | class FindFixture : protected BaseFixture |
| 637 | { |
| 638 | protected: |
| 639 | void |
| 640 | insert(uint32_t id, const Name& name) |
| 641 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 642 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 643 | data->setFreshnessPeriod(time::milliseconds(99999)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 644 | data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id)); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 645 | signData(data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 646 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 647 | m_cs.insert(*data); |
| 648 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 649 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 650 | Interest& |
| 651 | startInterest(const Name& name) |
| 652 | { |
| 653 | m_interest = make_shared<Interest>(name); |
| 654 | return *m_interest; |
| 655 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 656 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 657 | uint32_t |
| 658 | find() |
| 659 | { |
| 660 | const Data* found = m_cs.find(*m_interest); |
| 661 | if (found == 0) { |
| 662 | return 0; |
| 663 | } |
| 664 | const Block& content = found->getContent(); |
| 665 | if (content.value_size() != sizeof(uint32_t)) { |
| 666 | return 0; |
| 667 | } |
| 668 | return *reinterpret_cast<const uint32_t*>(content.value()); |
| 669 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 670 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 671 | protected: |
| 672 | Cs m_cs; |
| 673 | shared_ptr<Interest> m_interest; |
| 674 | }; |
| 675 | |
| 676 | BOOST_FIXTURE_TEST_SUITE(Find, FindFixture) |
| 677 | |
| 678 | BOOST_AUTO_TEST_CASE(EmptyDataName) |
| 679 | { |
| 680 | insert(1, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 681 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 682 | startInterest("ndn:/"); |
| 683 | BOOST_CHECK_EQUAL(find(), 1); |
| 684 | } |
| 685 | |
| 686 | BOOST_AUTO_TEST_CASE(EmptyInterestName) |
| 687 | { |
| 688 | insert(1, "ndn:/A"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 689 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 690 | startInterest("ndn:/"); |
| 691 | BOOST_CHECK_EQUAL(find(), 1); |
| 692 | } |
| 693 | |
| 694 | BOOST_AUTO_TEST_CASE(Leftmost) |
| 695 | { |
| 696 | insert(1, "ndn:/A"); |
| 697 | insert(2, "ndn:/B/p/1"); |
| 698 | insert(3, "ndn:/B/p/2"); |
| 699 | insert(4, "ndn:/B/q/1"); |
| 700 | insert(5, "ndn:/B/q/2"); |
| 701 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 702 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 703 | startInterest("ndn:/B"); |
| 704 | BOOST_CHECK_EQUAL(find(), 2); |
| 705 | } |
| 706 | |
| 707 | BOOST_AUTO_TEST_CASE(Rightmost) |
| 708 | { |
| 709 | insert(1, "ndn:/A"); |
| 710 | insert(2, "ndn:/B/p/1"); |
| 711 | insert(3, "ndn:/B/p/2"); |
| 712 | insert(4, "ndn:/B/q/1"); |
| 713 | insert(5, "ndn:/B/q/2"); |
| 714 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 715 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 716 | startInterest("ndn:/B") |
| 717 | .setChildSelector(1); |
| 718 | BOOST_CHECK_EQUAL(find(), 4); |
| 719 | } |
| 720 | |
| 721 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName1) |
| 722 | { |
| 723 | insert(1, "ndn:/"); |
| 724 | insert(2, "ndn:/A/B"); |
| 725 | insert(3, "ndn:/A/C"); |
| 726 | insert(4, "ndn:/A"); |
| 727 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 728 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 729 | // Intuitively you would think Data 4 should be between Data 1 and 2, |
| 730 | // but Data 4 has full Name ndn:/A/<32-octet hash>. |
| 731 | startInterest("ndn:/A"); |
| 732 | BOOST_CHECK_EQUAL(find(), 2); |
| 733 | } |
| 734 | |
| 735 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName33) |
| 736 | { |
| 737 | insert(1, "ndn:/"); |
| 738 | insert(2, "ndn:/A"); |
| 739 | insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's |
| 740 | insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
| 741 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 742 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 743 | // Data 2 is returned, because <32-octet hash> is less than Data 3. |
| 744 | startInterest("ndn:/A"); |
| 745 | BOOST_CHECK_EQUAL(find(), 2); |
| 746 | } |
| 747 | |
| 748 | BOOST_AUTO_TEST_CASE(MinSuffixComponents) |
| 749 | { |
| 750 | insert(1, "ndn:/A/1/2/3/4"); |
| 751 | insert(2, "ndn:/B/1/2/3"); |
| 752 | insert(3, "ndn:/C/1/2"); |
| 753 | insert(4, "ndn:/D/1"); |
| 754 | insert(5, "ndn:/E"); |
| 755 | insert(6, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 756 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 757 | startInterest("ndn:/") |
| 758 | .setChildSelector(1) |
| 759 | .setMinSuffixComponents(0); |
| 760 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 761 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 762 | startInterest("ndn:/") |
| 763 | .setChildSelector(1) |
| 764 | .setMinSuffixComponents(1); |
| 765 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 766 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 767 | startInterest("ndn:/") |
| 768 | .setChildSelector(1) |
| 769 | .setMinSuffixComponents(2); |
| 770 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 771 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 772 | startInterest("ndn:/") |
| 773 | .setChildSelector(1) |
| 774 | .setMinSuffixComponents(3); |
| 775 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 776 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 777 | startInterest("ndn:/") |
| 778 | .setChildSelector(1) |
| 779 | .setMinSuffixComponents(4); |
| 780 | BOOST_CHECK_EQUAL(find(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 781 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 782 | startInterest("ndn:/") |
| 783 | .setChildSelector(1) |
| 784 | .setMinSuffixComponents(5); |
| 785 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 786 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 787 | startInterest("ndn:/") |
| 788 | .setChildSelector(1) |
| 789 | .setMinSuffixComponents(6); |
| 790 | BOOST_CHECK_EQUAL(find(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 791 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 792 | startInterest("ndn:/") |
| 793 | .setChildSelector(1) |
| 794 | .setMinSuffixComponents(7); |
| 795 | BOOST_CHECK_EQUAL(find(), 0); |
| 796 | } |
| 797 | |
| 798 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents) |
| 799 | { |
| 800 | insert(1, "ndn:/"); |
| 801 | insert(2, "ndn:/A"); |
| 802 | insert(3, "ndn:/A/B"); |
| 803 | insert(4, "ndn:/A/B/C"); |
| 804 | insert(5, "ndn:/A/B/C/D"); |
| 805 | insert(6, "ndn:/A/B/C/D/E"); |
| 806 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 807 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 808 | startInterest("ndn:/") |
| 809 | .setMaxSuffixComponents(0); |
| 810 | BOOST_CHECK_EQUAL(find(), 0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 811 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 812 | startInterest("ndn:/") |
| 813 | .setMaxSuffixComponents(1); |
| 814 | BOOST_CHECK_EQUAL(find(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 815 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 816 | startInterest("ndn:/") |
| 817 | .setMaxSuffixComponents(2); |
| 818 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 819 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 820 | startInterest("ndn:/") |
| 821 | .setMaxSuffixComponents(3); |
| 822 | BOOST_CHECK_EQUAL(find(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 823 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 824 | startInterest("ndn:/") |
| 825 | .setMaxSuffixComponents(4); |
| 826 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 827 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 828 | startInterest("ndn:/") |
| 829 | .setMaxSuffixComponents(5); |
| 830 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 831 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 832 | startInterest("ndn:/") |
| 833 | .setMaxSuffixComponents(6); |
| 834 | BOOST_CHECK_EQUAL(find(), 6); |
| 835 | } |
| 836 | |
| 837 | BOOST_AUTO_TEST_CASE(DigestOrder) |
| 838 | { |
| 839 | insert(1, "ndn:/A"); |
| 840 | insert(2, "ndn:/A"); |
| 841 | // We don't know which comes first, but there must be some order |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 842 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 843 | startInterest("ndn:/A") |
| 844 | .setChildSelector(0); |
| 845 | uint32_t leftmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 846 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 847 | startInterest("ndn:/A") |
| 848 | .setChildSelector(1); |
| 849 | uint32_t rightmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 850 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 851 | BOOST_CHECK_NE(leftmost, rightmost); |
| 852 | } |
| 853 | |
| 854 | BOOST_AUTO_TEST_CASE(DigestExclude) |
| 855 | { |
| 856 | insert(1, "ndn:/A/B"); |
| 857 | insert(2, "ndn:/A"); |
| 858 | insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 859 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 860 | startInterest("ndn:/A") |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 861 | .setExclude(Exclude().excludeBefore(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 862 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" |
| 863 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's |
| 864 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 865 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 866 | startInterest("ndn:/A") |
| 867 | .setChildSelector(1) |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 868 | .setExclude(Exclude().excludeAfter(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 869 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 870 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 871 | "\x00"), 33))); // 33 0x00's |
| 872 | BOOST_CHECK_EQUAL(find(), 2); |
| 873 | } |
| 874 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 875 | BOOST_AUTO_TEST_CASE(ExactName32) |
| 876 | { |
| 877 | insert(1, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 32 'B's |
| 878 | insert(2, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 32 'C's |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 879 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 880 | startInterest("ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); |
| 881 | BOOST_CHECK_EQUAL(find(), 1); |
| 882 | } |
| 883 | |
| 884 | BOOST_AUTO_TEST_CASE(MinSuffixComponents32) |
| 885 | { |
| 886 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/1/2/3/4"); // 32 'x's |
| 887 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/B/1/2/3"); |
| 888 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/C/1/2"); |
| 889 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/D/1"); |
| 890 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/E"); |
| 891 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); |
| 892 | |
| 893 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 894 | .setChildSelector(1) |
| 895 | .setMinSuffixComponents(0); |
| 896 | BOOST_CHECK_EQUAL(find(), 6); |
| 897 | |
| 898 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 899 | .setChildSelector(1) |
| 900 | .setMinSuffixComponents(1); |
| 901 | BOOST_CHECK_EQUAL(find(), 6); |
| 902 | |
| 903 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 904 | .setChildSelector(1) |
| 905 | .setMinSuffixComponents(2); |
| 906 | BOOST_CHECK_EQUAL(find(), 5); |
| 907 | |
| 908 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 909 | .setChildSelector(1) |
| 910 | .setMinSuffixComponents(3); |
| 911 | BOOST_CHECK_EQUAL(find(), 4); |
| 912 | |
| 913 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 914 | .setChildSelector(1) |
| 915 | .setMinSuffixComponents(4); |
| 916 | BOOST_CHECK_EQUAL(find(), 3); |
| 917 | |
| 918 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 919 | .setChildSelector(1) |
| 920 | .setMinSuffixComponents(5); |
| 921 | BOOST_CHECK_EQUAL(find(), 2); |
| 922 | |
| 923 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 924 | .setChildSelector(1) |
| 925 | .setMinSuffixComponents(6); |
| 926 | BOOST_CHECK_EQUAL(find(), 1); |
| 927 | |
| 928 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 929 | .setChildSelector(1) |
| 930 | .setMinSuffixComponents(7); |
| 931 | BOOST_CHECK_EQUAL(find(), 0); |
| 932 | } |
| 933 | |
| 934 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents32) |
| 935 | { |
| 936 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); // 32 'x's |
| 937 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A"); |
| 938 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B"); |
| 939 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C"); |
| 940 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D"); |
| 941 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D/E"); |
| 942 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
| 943 | |
| 944 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 945 | .setMaxSuffixComponents(0); |
| 946 | BOOST_CHECK_EQUAL(find(), 0); |
| 947 | |
| 948 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 949 | .setMaxSuffixComponents(1); |
| 950 | BOOST_CHECK_EQUAL(find(), 1); |
| 951 | |
| 952 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 953 | .setMaxSuffixComponents(2); |
| 954 | BOOST_CHECK_EQUAL(find(), 2); |
| 955 | |
| 956 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 957 | .setMaxSuffixComponents(3); |
| 958 | BOOST_CHECK_EQUAL(find(), 3); |
| 959 | |
| 960 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 961 | .setMaxSuffixComponents(4); |
| 962 | BOOST_CHECK_EQUAL(find(), 4); |
| 963 | |
| 964 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 965 | .setMaxSuffixComponents(5); |
| 966 | BOOST_CHECK_EQUAL(find(), 5); |
| 967 | |
| 968 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 969 | .setMaxSuffixComponents(6); |
| 970 | BOOST_CHECK_EQUAL(find(), 6); |
| 971 | } |
| 972 | |
| 973 | BOOST_AUTO_TEST_SUITE_END() // Find |
| 974 | |
| 975 | BOOST_AUTO_TEST_SUITE_END() // TableCs |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 976 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 977 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 978 | } // namespace nfd |