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