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