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