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 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 287 | name.appendImplicitSha256Digest(digest1); |
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"); |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 363 | name.appendImplicitSha256Digest(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 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 532 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 533 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MinMaxComponentsSelector, 1) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 534 | BOOST_AUTO_TEST_CASE(MinMaxComponentsSelector) |
| 535 | { |
| 536 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 537 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 538 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 539 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 540 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 541 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 542 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 543 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 544 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 545 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 546 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 547 | 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] | 548 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 549 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 550 | shared_ptr<Data> data6 = makeData("/c/c/6/7/8/9"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 551 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 552 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 553 | shared_ptr<Data> data7 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 554 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 555 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 556 | shared_ptr<Data> data8 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 557 | cs.insert(*data8); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 558 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 559 | shared_ptr<Interest> interest = make_shared<Interest>("/c/c"); |
| 560 | interest->setMinSuffixComponents(3); |
| 561 | interest->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 562 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 563 | const Data* found = cs.find(*interest); |
| 564 | BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3/4/5/6"); |
| 565 | |
| 566 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c/c"); |
| 567 | interest2->setMinSuffixComponents(4); |
| 568 | interest2->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 569 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 570 | const Data* found2 = cs.find(*interest2); |
| 571 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 572 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 573 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c/c"); |
| 574 | interest3->setMaxSuffixComponents(2); |
| 575 | interest3->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 576 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 577 | const Data* found3 = cs.find(*interest3); |
| 578 | BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1"); |
| 579 | } |
| 580 | |
| 581 | BOOST_AUTO_TEST_CASE(ExcludeSelector) |
| 582 | { |
| 583 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 584 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 585 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 586 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 587 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 588 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 589 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 590 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 591 | shared_ptr<Data> data3 = makeData("/c/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 592 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 593 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 594 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 595 | cs.insert(*data4); |
| 596 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 597 | shared_ptr<Data> data5 = makeData("/c/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 598 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 599 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 600 | shared_ptr<Data> data6 = makeData("/c/f"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 601 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 602 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 603 | shared_ptr<Data> data7 = makeData("/c/n"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 604 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 605 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 606 | shared_ptr<Interest> interest = make_shared<Interest>("/c"); |
| 607 | interest->setChildSelector(1); |
| 608 | Exclude e; |
| 609 | e.excludeOne (Name::Component("n")); |
| 610 | interest->setExclude(e); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 611 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 612 | const Data* found = cs.find(*interest); |
| 613 | BOOST_CHECK_EQUAL(found->getName(), "/c/f"); |
| 614 | |
| 615 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c"); |
| 616 | interest2->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 617 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 618 | Exclude e2; |
| 619 | e2.excludeOne (Name::Component("a")); |
| 620 | interest2->setExclude(e2); |
| 621 | |
| 622 | const Data* found2 = cs.find(*interest2); |
| 623 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 624 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 625 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c"); |
| 626 | interest3->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 627 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 628 | Exclude e3; |
| 629 | e3.excludeOne (Name::Component("c")); |
| 630 | interest3->setExclude(e3); |
| 631 | |
| 632 | const Data* found3 = cs.find(*interest3); |
| 633 | BOOST_CHECK_EQUAL(found3->getName(), "/c/a"); |
| 634 | } |
| 635 | |
| 636 | // |
| 637 | |
| 638 | class FindFixture : protected BaseFixture |
| 639 | { |
| 640 | protected: |
| 641 | void |
| 642 | insert(uint32_t id, const Name& name) |
| 643 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 644 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 645 | data->setFreshnessPeriod(time::milliseconds(99999)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 646 | data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id)); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 647 | signData(data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 648 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 649 | m_cs.insert(*data); |
| 650 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 651 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 652 | Interest& |
| 653 | startInterest(const Name& name) |
| 654 | { |
| 655 | m_interest = make_shared<Interest>(name); |
| 656 | return *m_interest; |
| 657 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 658 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 659 | uint32_t |
| 660 | find() |
| 661 | { |
| 662 | const Data* found = m_cs.find(*m_interest); |
| 663 | if (found == 0) { |
| 664 | return 0; |
| 665 | } |
| 666 | const Block& content = found->getContent(); |
| 667 | if (content.value_size() != sizeof(uint32_t)) { |
| 668 | return 0; |
| 669 | } |
| 670 | return *reinterpret_cast<const uint32_t*>(content.value()); |
| 671 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 672 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 673 | protected: |
| 674 | Cs m_cs; |
| 675 | shared_ptr<Interest> m_interest; |
| 676 | }; |
| 677 | |
| 678 | BOOST_FIXTURE_TEST_SUITE(Find, FindFixture) |
| 679 | |
| 680 | BOOST_AUTO_TEST_CASE(EmptyDataName) |
| 681 | { |
| 682 | insert(1, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 683 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 684 | startInterest("ndn:/"); |
| 685 | BOOST_CHECK_EQUAL(find(), 1); |
| 686 | } |
| 687 | |
| 688 | BOOST_AUTO_TEST_CASE(EmptyInterestName) |
| 689 | { |
| 690 | insert(1, "ndn:/A"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 691 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 692 | startInterest("ndn:/"); |
| 693 | BOOST_CHECK_EQUAL(find(), 1); |
| 694 | } |
| 695 | |
| 696 | BOOST_AUTO_TEST_CASE(Leftmost) |
| 697 | { |
| 698 | insert(1, "ndn:/A"); |
| 699 | insert(2, "ndn:/B/p/1"); |
| 700 | insert(3, "ndn:/B/p/2"); |
| 701 | insert(4, "ndn:/B/q/1"); |
| 702 | insert(5, "ndn:/B/q/2"); |
| 703 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 704 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 705 | startInterest("ndn:/B"); |
| 706 | BOOST_CHECK_EQUAL(find(), 2); |
| 707 | } |
| 708 | |
| 709 | BOOST_AUTO_TEST_CASE(Rightmost) |
| 710 | { |
| 711 | insert(1, "ndn:/A"); |
| 712 | insert(2, "ndn:/B/p/1"); |
| 713 | insert(3, "ndn:/B/p/2"); |
| 714 | insert(4, "ndn:/B/q/1"); |
| 715 | insert(5, "ndn:/B/q/2"); |
| 716 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 717 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 718 | startInterest("ndn:/B") |
| 719 | .setChildSelector(1); |
| 720 | BOOST_CHECK_EQUAL(find(), 4); |
| 721 | } |
| 722 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 723 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 724 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(Leftmost_ExactName1, 1) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 725 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName1) |
| 726 | { |
| 727 | insert(1, "ndn:/"); |
| 728 | insert(2, "ndn:/A/B"); |
| 729 | insert(3, "ndn:/A/C"); |
| 730 | insert(4, "ndn:/A"); |
| 731 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 732 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 733 | // Intuitively you would think Data 4 should be between Data 1 and 2, |
| 734 | // but Data 4 has full Name ndn:/A/<32-octet hash>. |
| 735 | startInterest("ndn:/A"); |
| 736 | BOOST_CHECK_EQUAL(find(), 2); |
| 737 | } |
| 738 | |
| 739 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName33) |
| 740 | { |
| 741 | insert(1, "ndn:/"); |
| 742 | insert(2, "ndn:/A"); |
| 743 | insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's |
| 744 | insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
| 745 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 746 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 747 | // Data 2 is returned, because <32-octet hash> is less than Data 3. |
| 748 | startInterest("ndn:/A"); |
| 749 | BOOST_CHECK_EQUAL(find(), 2); |
| 750 | } |
| 751 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 752 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 753 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MinSuffixComponents, 2) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 754 | BOOST_AUTO_TEST_CASE(MinSuffixComponents) |
| 755 | { |
| 756 | insert(1, "ndn:/A/1/2/3/4"); |
| 757 | insert(2, "ndn:/B/1/2/3"); |
| 758 | insert(3, "ndn:/C/1/2"); |
| 759 | insert(4, "ndn:/D/1"); |
| 760 | insert(5, "ndn:/E"); |
| 761 | insert(6, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 762 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 763 | startInterest("ndn:/") |
| 764 | .setChildSelector(1) |
| 765 | .setMinSuffixComponents(0); |
| 766 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 767 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 768 | startInterest("ndn:/") |
| 769 | .setChildSelector(1) |
| 770 | .setMinSuffixComponents(1); |
| 771 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 772 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 773 | startInterest("ndn:/") |
| 774 | .setChildSelector(1) |
| 775 | .setMinSuffixComponents(2); |
| 776 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 777 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 778 | startInterest("ndn:/") |
| 779 | .setChildSelector(1) |
| 780 | .setMinSuffixComponents(3); |
| 781 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 782 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 783 | startInterest("ndn:/") |
| 784 | .setChildSelector(1) |
| 785 | .setMinSuffixComponents(4); |
| 786 | BOOST_CHECK_EQUAL(find(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 787 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 788 | startInterest("ndn:/") |
| 789 | .setChildSelector(1) |
| 790 | .setMinSuffixComponents(5); |
| 791 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 792 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 793 | startInterest("ndn:/") |
| 794 | .setChildSelector(1) |
| 795 | .setMinSuffixComponents(6); |
| 796 | BOOST_CHECK_EQUAL(find(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 797 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 798 | startInterest("ndn:/") |
| 799 | .setChildSelector(1) |
| 800 | .setMinSuffixComponents(7); |
| 801 | BOOST_CHECK_EQUAL(find(), 0); |
| 802 | } |
| 803 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 804 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 805 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MaxSuffixComponents, 5) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 806 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents) |
| 807 | { |
| 808 | insert(1, "ndn:/"); |
| 809 | insert(2, "ndn:/A"); |
| 810 | insert(3, "ndn:/A/B"); |
| 811 | insert(4, "ndn:/A/B/C"); |
| 812 | insert(5, "ndn:/A/B/C/D"); |
| 813 | insert(6, "ndn:/A/B/C/D/E"); |
| 814 | // 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] | 815 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 816 | startInterest("ndn:/") |
| 817 | .setMaxSuffixComponents(0); |
| 818 | BOOST_CHECK_EQUAL(find(), 0); |
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(1); |
| 822 | BOOST_CHECK_EQUAL(find(), 1); |
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(2); |
| 826 | BOOST_CHECK_EQUAL(find(), 2); |
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(3); |
| 830 | BOOST_CHECK_EQUAL(find(), 3); |
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(4); |
| 834 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 835 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 836 | startInterest("ndn:/") |
| 837 | .setMaxSuffixComponents(5); |
| 838 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 839 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 840 | startInterest("ndn:/") |
| 841 | .setMaxSuffixComponents(6); |
| 842 | BOOST_CHECK_EQUAL(find(), 6); |
| 843 | } |
| 844 | |
| 845 | BOOST_AUTO_TEST_CASE(DigestOrder) |
| 846 | { |
| 847 | insert(1, "ndn:/A"); |
| 848 | insert(2, "ndn:/A"); |
| 849 | // 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] | 850 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 851 | startInterest("ndn:/A") |
| 852 | .setChildSelector(0); |
| 853 | uint32_t leftmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 854 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 855 | startInterest("ndn:/A") |
| 856 | .setChildSelector(1); |
| 857 | uint32_t rightmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 858 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 859 | BOOST_CHECK_NE(leftmost, rightmost); |
| 860 | } |
| 861 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 862 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 863 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(DigestExclude, 1) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 864 | BOOST_AUTO_TEST_CASE(DigestExclude) |
| 865 | { |
| 866 | insert(1, "ndn:/A/B"); |
| 867 | insert(2, "ndn:/A"); |
| 868 | insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 869 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 870 | startInterest("ndn:/A") |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 871 | .setExclude(Exclude().excludeBefore(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 872 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" |
| 873 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's |
| 874 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 875 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 876 | startInterest("ndn:/A") |
| 877 | .setChildSelector(1) |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 878 | .setExclude(Exclude().excludeAfter(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 879 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 880 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 881 | "\x00"), 33))); // 33 0x00's |
| 882 | BOOST_CHECK_EQUAL(find(), 2); |
| 883 | } |
| 884 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 885 | BOOST_AUTO_TEST_CASE(ExactName32) |
| 886 | { |
| 887 | insert(1, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 32 'B's |
| 888 | insert(2, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 32 'C's |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 889 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 890 | startInterest("ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); |
| 891 | BOOST_CHECK_EQUAL(find(), 1); |
| 892 | } |
| 893 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 894 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 895 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MinSuffixComponents32, 2) |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 896 | BOOST_AUTO_TEST_CASE(MinSuffixComponents32) |
| 897 | { |
| 898 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/1/2/3/4"); // 32 'x's |
| 899 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/B/1/2/3"); |
| 900 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/C/1/2"); |
| 901 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/D/1"); |
| 902 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/E"); |
| 903 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); |
| 904 | |
| 905 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 906 | .setChildSelector(1) |
| 907 | .setMinSuffixComponents(0); |
| 908 | BOOST_CHECK_EQUAL(find(), 6); |
| 909 | |
| 910 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 911 | .setChildSelector(1) |
| 912 | .setMinSuffixComponents(1); |
| 913 | BOOST_CHECK_EQUAL(find(), 6); |
| 914 | |
| 915 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 916 | .setChildSelector(1) |
| 917 | .setMinSuffixComponents(2); |
| 918 | BOOST_CHECK_EQUAL(find(), 5); |
| 919 | |
| 920 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 921 | .setChildSelector(1) |
| 922 | .setMinSuffixComponents(3); |
| 923 | BOOST_CHECK_EQUAL(find(), 4); |
| 924 | |
| 925 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 926 | .setChildSelector(1) |
| 927 | .setMinSuffixComponents(4); |
| 928 | BOOST_CHECK_EQUAL(find(), 3); |
| 929 | |
| 930 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 931 | .setChildSelector(1) |
| 932 | .setMinSuffixComponents(5); |
| 933 | BOOST_CHECK_EQUAL(find(), 2); |
| 934 | |
| 935 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 936 | .setChildSelector(1) |
| 937 | .setMinSuffixComponents(6); |
| 938 | BOOST_CHECK_EQUAL(find(), 1); |
| 939 | |
| 940 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 941 | .setChildSelector(1) |
| 942 | .setMinSuffixComponents(7); |
| 943 | BOOST_CHECK_EQUAL(find(), 0); |
| 944 | } |
| 945 | |
Alexander Afanasyev | 3651fd7 | 2014-11-10 10:41:47 -0800 | [diff] [blame] | 946 | /// @todo Expected failures, needs to be fixed as part of Issue #2118 |
| 947 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MaxSuffixComponents32, 5) |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 948 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents32) |
| 949 | { |
| 950 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); // 32 'x's |
| 951 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A"); |
| 952 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B"); |
| 953 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C"); |
| 954 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D"); |
| 955 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D/E"); |
| 956 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
| 957 | |
| 958 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 959 | .setMaxSuffixComponents(0); |
| 960 | BOOST_CHECK_EQUAL(find(), 0); |
| 961 | |
| 962 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 963 | .setMaxSuffixComponents(1); |
| 964 | BOOST_CHECK_EQUAL(find(), 1); |
| 965 | |
| 966 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 967 | .setMaxSuffixComponents(2); |
| 968 | BOOST_CHECK_EQUAL(find(), 2); |
| 969 | |
| 970 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 971 | .setMaxSuffixComponents(3); |
| 972 | BOOST_CHECK_EQUAL(find(), 3); |
| 973 | |
| 974 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 975 | .setMaxSuffixComponents(4); |
| 976 | BOOST_CHECK_EQUAL(find(), 4); |
| 977 | |
| 978 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 979 | .setMaxSuffixComponents(5); |
| 980 | BOOST_CHECK_EQUAL(find(), 5); |
| 981 | |
| 982 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 983 | .setMaxSuffixComponents(6); |
| 984 | BOOST_CHECK_EQUAL(find(), 6); |
| 985 | } |
| 986 | |
| 987 | BOOST_AUTO_TEST_SUITE_END() // Find |
| 988 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 989 | BOOST_AUTO_TEST_CASE(Iterator) |
| 990 | { |
| 991 | Cs cs; |
| 992 | |
| 993 | Name nameA("/A"); |
| 994 | Name nameAB("/A/B"); |
| 995 | Name nameABC("/A/B/C"); |
| 996 | Name nameD("/D"); |
| 997 | |
| 998 | BOOST_CHECK_EQUAL(cs.size(), 0); |
| 999 | BOOST_CHECK(cs.begin() == cs.end()); |
| 1000 | |
| 1001 | cs.insert(*makeData(nameABC)); |
| 1002 | BOOST_CHECK_EQUAL(cs.size(), 1); |
| 1003 | BOOST_CHECK(cs.begin() != cs.end()); |
| 1004 | BOOST_CHECK(cs.begin()->getName() == nameABC); |
| 1005 | BOOST_CHECK((*cs.begin()).getName() == nameABC); |
| 1006 | |
| 1007 | auto i = cs.begin(); |
| 1008 | auto j = cs.begin(); |
| 1009 | BOOST_CHECK(++i == cs.end()); |
| 1010 | BOOST_CHECK(j++ == cs.begin()); |
| 1011 | BOOST_CHECK(j == cs.end()); |
| 1012 | |
| 1013 | cs.insert(*makeData(nameA)); |
| 1014 | cs.insert(*makeData(nameAB)); |
| 1015 | cs.insert(*makeData(nameD)); |
| 1016 | |
| 1017 | std::set<Name> expected = {nameA, nameAB, nameABC, nameD}; |
| 1018 | std::set<Name> actual; |
| 1019 | for (const auto& csEntry : cs) { |
| 1020 | actual.insert(csEntry.getName()); |
| 1021 | } |
| 1022 | BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end()); |
| 1023 | } |
| 1024 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 1025 | BOOST_AUTO_TEST_SUITE_END() // TableCs |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 1026 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 1027 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 1028 | } // namespace nfd |