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 | |
| 84 | |
| 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)); |
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)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 173 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 174 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(cs.size(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 176 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 177 | sleep(3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 178 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 179 | cs.evictItem_accessor(); |
| 180 | BOOST_CHECK_EQUAL(cs.size(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 181 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 182 | shared_ptr<Interest> interest = make_shared<Interest>(name2); |
| 183 | const Data* found = cs.find(*interest); |
| 184 | BOOST_REQUIRE(found != 0); |
| 185 | BOOST_CHECK_EQUAL(found->getName(), name2); |
| 186 | } |
| 187 | |
| 188 | //even max size |
| 189 | BOOST_AUTO_TEST_CASE(ReplacementEvenSize) |
| 190 | { |
| 191 | Cs cs(4); |
| 192 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 193 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 194 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 195 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 196 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 197 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 198 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 199 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 200 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 201 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 202 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 203 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 204 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 205 | shared_ptr<Data> data5 = makeData("/e"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 206 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 207 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(cs.size(), 4); |
| 209 | } |
| 210 | |
| 211 | //odd max size |
| 212 | BOOST_AUTO_TEST_CASE(Replacement2) |
| 213 | { |
| 214 | Cs cs(3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 215 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 216 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 217 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 218 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 219 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 220 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 221 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 222 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 223 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 224 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 225 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 226 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 227 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 229 | } |
| 230 | |
| 231 | BOOST_AUTO_TEST_CASE(InsertAndEraseByName) |
| 232 | { |
| 233 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 234 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 235 | Name name("/insertandremovebyname"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 236 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 237 | cs.insert(*data); |
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 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 240 | data->wireEncode().size()); |
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> data2 = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 243 | cs.insert(*data2); |
| 244 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 245 | shared_ptr<Data> data3 = makeData("/z"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 246 | cs.insert(*data3); |
| 247 | |
| 248 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 249 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 250 | name.append(digest1->buf(), digest1->size()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 251 | cs.erase(name); |
| 252 | BOOST_CHECK_EQUAL(cs.size(), 2); |
| 253 | } |
| 254 | |
| 255 | BOOST_AUTO_TEST_CASE(DigestCalculation) |
| 256 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 257 | shared_ptr<Data> data = makeData("/digest/compute"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 258 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 259 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 260 | data->wireEncode().size()); |
| 261 | BOOST_CHECK_EQUAL(digest1->size(), 32); |
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 | cs::Entry* entry = new cs::Entry(); |
| 264 | entry->setData(*data, false); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 265 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL_COLLECTIONS(digest1->begin(), digest1->end(), |
| 267 | entry->getDigest()->begin(), entry->getDigest()->end()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | BOOST_AUTO_TEST_CASE(InsertCanonical) |
| 271 | { |
| 272 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 273 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 274 | shared_ptr<Data> data = makeData("/a"); |
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 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 278 | cs.insert(*data2); |
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> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 281 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 282 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 283 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 284 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 285 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 286 | 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] | 287 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 288 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 289 | shared_ptr<Data> data6 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 290 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 291 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 292 | shared_ptr<Data> data7 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 293 | cs.insert(*data7); |
| 294 | } |
| 295 | |
| 296 | BOOST_AUTO_TEST_CASE(EraseCanonical) |
| 297 | { |
| 298 | Cs cs; |
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 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 301 | cs.insert(*data); |
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 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 304 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 305 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 306 | shared_ptr<Data> data3 = makeData("/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 307 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 308 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 309 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 310 | cs.insert(*data4); |
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> data5 = makeData("/c/c/1/2/3/4/5/6"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 313 | cs.insert(*data5); |
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> data6 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 316 | cs.insert(*data6); |
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> data7 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 319 | cs.insert(*data7); |
| 320 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 321 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 322 | data->wireEncode().size()); |
| 323 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 324 | Name name("/a"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 325 | name.append(digest1->buf(), digest1->size()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 326 | cs.erase(name); |
| 327 | BOOST_CHECK_EQUAL(cs.size(), 6); |
| 328 | } |
| 329 | |
| 330 | BOOST_AUTO_TEST_CASE(ImplicitDigestSelector) |
| 331 | { |
| 332 | CsAccessor cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 333 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 334 | Name name("/digest/works"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 335 | shared_ptr<Data> data = makeData(name); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 336 | cs.insert(*data); |
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> data2 = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 339 | cs.insert(*data2); |
| 340 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 341 | shared_ptr<Data> data3 = makeData("/z/z/z"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 342 | cs.insert(*data3); |
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 | ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(), |
| 345 | data->wireEncode().size()); |
| 346 | uint8_t digest2[32] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 347 | 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] | 348 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 349 | shared_ptr<Interest> interest = make_shared<Interest>(); |
| 350 | interest->setName(Name(name).append(digest1->buf(), digest1->size())); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 351 | interest->setMinSuffixComponents(0); |
| 352 | interest->setMaxSuffixComponents(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 353 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 354 | const Data* found = cs.find(*interest); |
| 355 | BOOST_CHECK_NE(found, static_cast<const Data*>(0)); |
| 356 | BOOST_CHECK_EQUAL(found->getName(), name); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 357 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 358 | shared_ptr<Interest> interest2 = make_shared<Interest>(); |
| 359 | interest2->setName(Name(name).append(digest2, 32)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 360 | interest2->setMinSuffixComponents(0); |
| 361 | interest2->setMaxSuffixComponents(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 362 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 363 | const Data* notfound = cs.find(*interest2); |
| 364 | BOOST_CHECK_EQUAL(notfound, static_cast<const Data*>(0)); |
| 365 | } |
| 366 | |
| 367 | BOOST_AUTO_TEST_CASE(ChildSelector) |
| 368 | { |
| 369 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 370 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 371 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 372 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 373 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 374 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 375 | cs.insert(*data2); |
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> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 378 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 379 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 380 | shared_ptr<Data> data5 = makeData("/c/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 381 | cs.insert(*data5); |
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 | shared_ptr<Data> data6 = makeData("/c/f"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 384 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 385 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 386 | shared_ptr<Data> data7 = makeData("/c/n"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 387 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 388 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 389 | shared_ptr<Interest> interest = make_shared<Interest>("/c"); |
| 390 | interest->setChildSelector(1); |
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_EQUAL(found->getName(), "/c/n"); |
| 394 | |
| 395 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c"); |
| 396 | interest2->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 397 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 398 | const Data* found2 = cs.find(*interest2); |
| 399 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
| 400 | } |
| 401 | |
| 402 | BOOST_AUTO_TEST_CASE(ChildSelector2) |
| 403 | { |
| 404 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 405 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 406 | shared_ptr<Data> data = makeData("/a/b/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 407 | cs.insert(*data); |
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> data2 = makeData("/a/b/2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 410 | cs.insert(*data2); |
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> data3 = makeData("/a/z/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 413 | cs.insert(*data3); |
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("/a/z/2"); |
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 | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 418 | shared_ptr<Interest> interest = make_shared<Interest>("/a"); |
| 419 | interest->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 420 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 421 | const Data* found = cs.find(*interest); |
| 422 | BOOST_CHECK_EQUAL(found->getName(), "/a/z/1"); |
| 423 | } |
| 424 | |
| 425 | BOOST_AUTO_TEST_CASE(MustBeFreshSelector) |
| 426 | { |
| 427 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 428 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 429 | Name name("/insert/nonfresh"); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 430 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 431 | data->setFreshnessPeriod(time::milliseconds(500)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 432 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 433 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 434 | sleep(1); |
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 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 437 | interest->setMustBeFresh(true); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 438 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 439 | const Data* found = cs.find(*interest); |
| 440 | BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0)); |
| 441 | } |
| 442 | |
Ilya Moiseenko | 9c9231b | 2014-04-10 11:05:12 -0400 | [diff] [blame] | 443 | BOOST_AUTO_TEST_CASE(PublisherKeySelector) |
| 444 | { |
| 445 | Cs cs; |
| 446 | |
| 447 | Name name("/insert/withkey"); |
| 448 | shared_ptr<Data> data = makeData(name); |
| 449 | cs.insert(*data); |
| 450 | |
| 451 | shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 452 | Name keyName("/somewhere/key"); |
| 453 | |
| 454 | ndn::KeyLocator locator(keyName); |
| 455 | interest->setPublisherPublicKeyLocator(locator); |
| 456 | |
| 457 | const Data* found = cs.find(*interest); |
| 458 | BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0)); |
| 459 | } |
| 460 | |
| 461 | BOOST_AUTO_TEST_CASE(PublisherKeySelector2) |
| 462 | { |
| 463 | Cs cs; |
| 464 | Name name("/insert/withkey"); |
| 465 | shared_ptr<Data> data = makeData(name); |
| 466 | cs.insert(*data); |
| 467 | |
| 468 | Name name2("/insert/withkey2"); |
| 469 | shared_ptr<Data> data2 = make_shared<Data>(name2); |
| 470 | |
| 471 | Name keyName("/somewhere/key"); |
| 472 | const ndn::KeyLocator locator(keyName); |
| 473 | |
| 474 | ndn::SignatureSha256WithRsa fakeSignature; |
| 475 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 476 | reinterpret_cast<const uint8_t*>(0), 0)); |
| 477 | |
| 478 | fakeSignature.setKeyLocator(locator); |
| 479 | data2->setSignature(fakeSignature); |
| 480 | |
| 481 | cs.insert(*data2); |
| 482 | |
| 483 | shared_ptr<Interest> interest = make_shared<Interest>(name2); |
| 484 | interest->setPublisherPublicKeyLocator(locator); |
| 485 | |
| 486 | const Data* found = cs.find(*interest); |
| 487 | BOOST_CHECK_NE(found, static_cast<const Data*>(0)); |
| 488 | BOOST_CHECK_EQUAL(found->getName(), data2->getName()); |
| 489 | } |
| 490 | |
| 491 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 492 | BOOST_AUTO_TEST_CASE(MinMaxComponentsSelector) |
| 493 | { |
| 494 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 495 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 496 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 497 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 498 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 499 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 500 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 501 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 502 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 503 | cs.insert(*data4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 504 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 505 | 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] | 506 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 507 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 508 | shared_ptr<Data> data6 = makeData("/c/c/6/7/8/9"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 509 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 510 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 511 | shared_ptr<Data> data7 = makeData("/c/c/1/2/3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 512 | cs.insert(*data7); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 513 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 514 | shared_ptr<Data> data8 = makeData("/c/c/1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 515 | cs.insert(*data8); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 516 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 517 | shared_ptr<Interest> interest = make_shared<Interest>("/c/c"); |
| 518 | interest->setMinSuffixComponents(3); |
| 519 | interest->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 520 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 521 | const Data* found = cs.find(*interest); |
| 522 | BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3/4/5/6"); |
| 523 | |
| 524 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c/c"); |
| 525 | interest2->setMinSuffixComponents(4); |
| 526 | interest2->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 527 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 528 | const Data* found2 = cs.find(*interest2); |
| 529 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 530 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 531 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c/c"); |
| 532 | interest3->setMaxSuffixComponents(2); |
| 533 | interest3->setChildSelector(1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 534 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 535 | const Data* found3 = cs.find(*interest3); |
| 536 | BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1"); |
| 537 | } |
| 538 | |
| 539 | BOOST_AUTO_TEST_CASE(ExcludeSelector) |
| 540 | { |
| 541 | Cs cs; |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 542 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 543 | shared_ptr<Data> data = makeData("/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 544 | cs.insert(*data); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 545 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 546 | shared_ptr<Data> data2 = makeData("/b"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 547 | cs.insert(*data2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 548 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 549 | shared_ptr<Data> data3 = makeData("/c/a"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 550 | cs.insert(*data3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 551 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 552 | shared_ptr<Data> data4 = makeData("/d"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 553 | cs.insert(*data4); |
| 554 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 555 | shared_ptr<Data> data5 = makeData("/c/c"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 556 | cs.insert(*data5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 557 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 558 | shared_ptr<Data> data6 = makeData("/c/f"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 559 | cs.insert(*data6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 560 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 561 | shared_ptr<Data> data7 = makeData("/c/n"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 562 | cs.insert(*data7); |
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 | shared_ptr<Interest> interest = make_shared<Interest>("/c"); |
| 565 | interest->setChildSelector(1); |
| 566 | Exclude e; |
| 567 | e.excludeOne (Name::Component("n")); |
| 568 | interest->setExclude(e); |
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* found = cs.find(*interest); |
| 571 | BOOST_CHECK_EQUAL(found->getName(), "/c/f"); |
| 572 | |
| 573 | shared_ptr<Interest> interest2 = make_shared<Interest>("/c"); |
| 574 | interest2->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 575 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 576 | Exclude e2; |
| 577 | e2.excludeOne (Name::Component("a")); |
| 578 | interest2->setExclude(e2); |
| 579 | |
| 580 | const Data* found2 = cs.find(*interest2); |
| 581 | BOOST_CHECK_EQUAL(found2->getName(), "/c/c"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 582 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 583 | shared_ptr<Interest> interest3 = make_shared<Interest>("/c"); |
| 584 | interest3->setChildSelector(0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 585 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 586 | Exclude e3; |
| 587 | e3.excludeOne (Name::Component("c")); |
| 588 | interest3->setExclude(e3); |
| 589 | |
| 590 | const Data* found3 = cs.find(*interest3); |
| 591 | BOOST_CHECK_EQUAL(found3->getName(), "/c/a"); |
| 592 | } |
| 593 | |
| 594 | // |
| 595 | |
| 596 | class FindFixture : protected BaseFixture |
| 597 | { |
| 598 | protected: |
| 599 | void |
| 600 | insert(uint32_t id, const Name& name) |
| 601 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 602 | shared_ptr<Data> data = makeData(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 603 | data->setFreshnessPeriod(time::milliseconds(99999)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 604 | data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id)); |
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 | m_cs.insert(*data); |
| 607 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 608 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 609 | Interest& |
| 610 | startInterest(const Name& name) |
| 611 | { |
| 612 | m_interest = make_shared<Interest>(name); |
| 613 | return *m_interest; |
| 614 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 615 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 616 | uint32_t |
| 617 | find() |
| 618 | { |
| 619 | const Data* found = m_cs.find(*m_interest); |
| 620 | if (found == 0) { |
| 621 | return 0; |
| 622 | } |
| 623 | const Block& content = found->getContent(); |
| 624 | if (content.value_size() != sizeof(uint32_t)) { |
| 625 | return 0; |
| 626 | } |
| 627 | return *reinterpret_cast<const uint32_t*>(content.value()); |
| 628 | } |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 629 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 630 | protected: |
| 631 | Cs m_cs; |
| 632 | shared_ptr<Interest> m_interest; |
| 633 | }; |
| 634 | |
| 635 | BOOST_FIXTURE_TEST_SUITE(Find, FindFixture) |
| 636 | |
| 637 | BOOST_AUTO_TEST_CASE(EmptyDataName) |
| 638 | { |
| 639 | insert(1, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 640 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 641 | startInterest("ndn:/"); |
| 642 | BOOST_CHECK_EQUAL(find(), 1); |
| 643 | } |
| 644 | |
| 645 | BOOST_AUTO_TEST_CASE(EmptyInterestName) |
| 646 | { |
| 647 | insert(1, "ndn:/A"); |
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 | startInterest("ndn:/"); |
| 650 | BOOST_CHECK_EQUAL(find(), 1); |
| 651 | } |
| 652 | |
| 653 | BOOST_AUTO_TEST_CASE(Leftmost) |
| 654 | { |
| 655 | insert(1, "ndn:/A"); |
| 656 | insert(2, "ndn:/B/p/1"); |
| 657 | insert(3, "ndn:/B/p/2"); |
| 658 | insert(4, "ndn:/B/q/1"); |
| 659 | insert(5, "ndn:/B/q/2"); |
| 660 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 661 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 662 | startInterest("ndn:/B"); |
| 663 | BOOST_CHECK_EQUAL(find(), 2); |
| 664 | } |
| 665 | |
| 666 | BOOST_AUTO_TEST_CASE(Rightmost) |
| 667 | { |
| 668 | insert(1, "ndn:/A"); |
| 669 | insert(2, "ndn:/B/p/1"); |
| 670 | insert(3, "ndn:/B/p/2"); |
| 671 | insert(4, "ndn:/B/q/1"); |
| 672 | insert(5, "ndn:/B/q/2"); |
| 673 | insert(6, "ndn:/C"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 674 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 675 | startInterest("ndn:/B") |
| 676 | .setChildSelector(1); |
| 677 | BOOST_CHECK_EQUAL(find(), 4); |
| 678 | } |
| 679 | |
| 680 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName1) |
| 681 | { |
| 682 | insert(1, "ndn:/"); |
| 683 | insert(2, "ndn:/A/B"); |
| 684 | insert(3, "ndn:/A/C"); |
| 685 | insert(4, "ndn:/A"); |
| 686 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 687 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 688 | // Intuitively you would think Data 4 should be between Data 1 and 2, |
| 689 | // but Data 4 has full Name ndn:/A/<32-octet hash>. |
| 690 | startInterest("ndn:/A"); |
| 691 | BOOST_CHECK_EQUAL(find(), 2); |
| 692 | } |
| 693 | |
| 694 | BOOST_AUTO_TEST_CASE(Leftmost_ExactName33) |
| 695 | { |
| 696 | insert(1, "ndn:/"); |
| 697 | insert(2, "ndn:/A"); |
| 698 | insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's |
| 699 | insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
| 700 | insert(5, "ndn:/D"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 701 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 702 | // Data 2 is returned, because <32-octet hash> is less than Data 3. |
| 703 | startInterest("ndn:/A"); |
| 704 | BOOST_CHECK_EQUAL(find(), 2); |
| 705 | } |
| 706 | |
| 707 | BOOST_AUTO_TEST_CASE(MinSuffixComponents) |
| 708 | { |
| 709 | insert(1, "ndn:/A/1/2/3/4"); |
| 710 | insert(2, "ndn:/B/1/2/3"); |
| 711 | insert(3, "ndn:/C/1/2"); |
| 712 | insert(4, "ndn:/D/1"); |
| 713 | insert(5, "ndn:/E"); |
| 714 | insert(6, "ndn:/"); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 715 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 716 | startInterest("ndn:/") |
| 717 | .setChildSelector(1) |
| 718 | .setMinSuffixComponents(0); |
| 719 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 720 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 721 | startInterest("ndn:/") |
| 722 | .setChildSelector(1) |
| 723 | .setMinSuffixComponents(1); |
| 724 | BOOST_CHECK_EQUAL(find(), 6); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 725 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 726 | startInterest("ndn:/") |
| 727 | .setChildSelector(1) |
| 728 | .setMinSuffixComponents(2); |
| 729 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 730 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 731 | startInterest("ndn:/") |
| 732 | .setChildSelector(1) |
| 733 | .setMinSuffixComponents(3); |
| 734 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 735 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 736 | startInterest("ndn:/") |
| 737 | .setChildSelector(1) |
| 738 | .setMinSuffixComponents(4); |
| 739 | BOOST_CHECK_EQUAL(find(), 3); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 740 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 741 | startInterest("ndn:/") |
| 742 | .setChildSelector(1) |
| 743 | .setMinSuffixComponents(5); |
| 744 | BOOST_CHECK_EQUAL(find(), 2); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 745 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 746 | startInterest("ndn:/") |
| 747 | .setChildSelector(1) |
| 748 | .setMinSuffixComponents(6); |
| 749 | BOOST_CHECK_EQUAL(find(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 750 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 751 | startInterest("ndn:/") |
| 752 | .setChildSelector(1) |
| 753 | .setMinSuffixComponents(7); |
| 754 | BOOST_CHECK_EQUAL(find(), 0); |
| 755 | } |
| 756 | |
| 757 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents) |
| 758 | { |
| 759 | insert(1, "ndn:/"); |
| 760 | insert(2, "ndn:/A"); |
| 761 | insert(3, "ndn:/A/B"); |
| 762 | insert(4, "ndn:/A/B/C"); |
| 763 | insert(5, "ndn:/A/B/C/D"); |
| 764 | insert(6, "ndn:/A/B/C/D/E"); |
| 765 | // 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] | 766 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 767 | startInterest("ndn:/") |
| 768 | .setMaxSuffixComponents(0); |
| 769 | BOOST_CHECK_EQUAL(find(), 0); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 770 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 771 | startInterest("ndn:/") |
| 772 | .setMaxSuffixComponents(1); |
| 773 | BOOST_CHECK_EQUAL(find(), 1); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 774 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 775 | startInterest("ndn:/") |
| 776 | .setMaxSuffixComponents(2); |
| 777 | BOOST_CHECK_EQUAL(find(), 2); |
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 | .setMaxSuffixComponents(3); |
| 781 | BOOST_CHECK_EQUAL(find(), 3); |
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 | .setMaxSuffixComponents(4); |
| 785 | BOOST_CHECK_EQUAL(find(), 4); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 786 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 787 | startInterest("ndn:/") |
| 788 | .setMaxSuffixComponents(5); |
| 789 | BOOST_CHECK_EQUAL(find(), 5); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 790 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 791 | startInterest("ndn:/") |
| 792 | .setMaxSuffixComponents(6); |
| 793 | BOOST_CHECK_EQUAL(find(), 6); |
| 794 | } |
| 795 | |
| 796 | BOOST_AUTO_TEST_CASE(DigestOrder) |
| 797 | { |
| 798 | insert(1, "ndn:/A"); |
| 799 | insert(2, "ndn:/A"); |
| 800 | // 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] | 801 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 802 | startInterest("ndn:/A") |
| 803 | .setChildSelector(0); |
| 804 | uint32_t leftmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 805 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 806 | startInterest("ndn:/A") |
| 807 | .setChildSelector(1); |
| 808 | uint32_t rightmost = find(); |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 809 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 810 | BOOST_CHECK_NE(leftmost, rightmost); |
| 811 | } |
| 812 | |
| 813 | BOOST_AUTO_TEST_CASE(DigestExclude) |
| 814 | { |
| 815 | insert(1, "ndn:/A/B"); |
| 816 | insert(2, "ndn:/A"); |
| 817 | insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 818 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 819 | startInterest("ndn:/A") |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 820 | .setExclude(Exclude().excludeBefore(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 821 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" |
| 822 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's |
| 823 | BOOST_CHECK_EQUAL(find(), 2); |
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:/A") |
| 826 | .setChildSelector(1) |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 827 | .setExclude(Exclude().excludeAfter(name::Component(reinterpret_cast<const uint8_t*>( |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 828 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 829 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 830 | "\x00"), 33))); // 33 0x00's |
| 831 | BOOST_CHECK_EQUAL(find(), 2); |
| 832 | } |
| 833 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 834 | BOOST_AUTO_TEST_CASE(ExactName32) |
| 835 | { |
| 836 | insert(1, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 32 'B's |
| 837 | insert(2, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 32 'C's |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 838 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 839 | startInterest("ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); |
| 840 | BOOST_CHECK_EQUAL(find(), 1); |
| 841 | } |
| 842 | |
| 843 | BOOST_AUTO_TEST_CASE(MinSuffixComponents32) |
| 844 | { |
| 845 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/1/2/3/4"); // 32 'x's |
| 846 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/B/1/2/3"); |
| 847 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/C/1/2"); |
| 848 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/D/1"); |
| 849 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/E"); |
| 850 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); |
| 851 | |
| 852 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 853 | .setChildSelector(1) |
| 854 | .setMinSuffixComponents(0); |
| 855 | BOOST_CHECK_EQUAL(find(), 6); |
| 856 | |
| 857 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 858 | .setChildSelector(1) |
| 859 | .setMinSuffixComponents(1); |
| 860 | BOOST_CHECK_EQUAL(find(), 6); |
| 861 | |
| 862 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 863 | .setChildSelector(1) |
| 864 | .setMinSuffixComponents(2); |
| 865 | BOOST_CHECK_EQUAL(find(), 5); |
| 866 | |
| 867 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 868 | .setChildSelector(1) |
| 869 | .setMinSuffixComponents(3); |
| 870 | BOOST_CHECK_EQUAL(find(), 4); |
| 871 | |
| 872 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 873 | .setChildSelector(1) |
| 874 | .setMinSuffixComponents(4); |
| 875 | BOOST_CHECK_EQUAL(find(), 3); |
| 876 | |
| 877 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 878 | .setChildSelector(1) |
| 879 | .setMinSuffixComponents(5); |
| 880 | BOOST_CHECK_EQUAL(find(), 2); |
| 881 | |
| 882 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 883 | .setChildSelector(1) |
| 884 | .setMinSuffixComponents(6); |
| 885 | BOOST_CHECK_EQUAL(find(), 1); |
| 886 | |
| 887 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 888 | .setChildSelector(1) |
| 889 | .setMinSuffixComponents(7); |
| 890 | BOOST_CHECK_EQUAL(find(), 0); |
| 891 | } |
| 892 | |
| 893 | BOOST_AUTO_TEST_CASE(MaxSuffixComponents32) |
| 894 | { |
| 895 | insert(1, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"); // 32 'x's |
| 896 | insert(2, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A"); |
| 897 | insert(3, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B"); |
| 898 | insert(4, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C"); |
| 899 | insert(5, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D"); |
| 900 | insert(6, "ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/A/B/C/D/E"); |
| 901 | // Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component. |
| 902 | |
| 903 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 904 | .setMaxSuffixComponents(0); |
| 905 | BOOST_CHECK_EQUAL(find(), 0); |
| 906 | |
| 907 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 908 | .setMaxSuffixComponents(1); |
| 909 | BOOST_CHECK_EQUAL(find(), 1); |
| 910 | |
| 911 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 912 | .setMaxSuffixComponents(2); |
| 913 | BOOST_CHECK_EQUAL(find(), 2); |
| 914 | |
| 915 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 916 | .setMaxSuffixComponents(3); |
| 917 | BOOST_CHECK_EQUAL(find(), 3); |
| 918 | |
| 919 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 920 | .setMaxSuffixComponents(4); |
| 921 | BOOST_CHECK_EQUAL(find(), 4); |
| 922 | |
| 923 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 924 | .setMaxSuffixComponents(5); |
| 925 | BOOST_CHECK_EQUAL(find(), 5); |
| 926 | |
| 927 | startInterest("ndn:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 928 | .setMaxSuffixComponents(6); |
| 929 | BOOST_CHECK_EQUAL(find(), 6); |
| 930 | } |
| 931 | |
| 932 | BOOST_AUTO_TEST_SUITE_END() // Find |
| 933 | |
| 934 | BOOST_AUTO_TEST_SUITE_END() // TableCs |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 935 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 936 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 937 | } // namespace nfd |