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