Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 25 | |
| 26 | #include "table/strategy-choice.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 27 | |
| 28 | #include "tests/test-common.hpp" |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 29 | #include "../fw/dummy-strategy.hpp" |
| 30 | #include "../fw/install-strategy.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Table) |
| 36 | BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, BaseFixture) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 37 | |
| 38 | using fw::Strategy; |
| 39 | |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE(Get) |
| 41 | { |
| 42 | Forwarder forwarder; |
| 43 | Name nameP("ndn:/strategy/P"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 44 | install<DummyStrategy>(forwarder, nameP); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 45 | |
| 46 | StrategyChoice& table = forwarder.getStrategyChoice(); |
| 47 | |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 48 | BOOST_CHECK(table.insert("ndn:/", nameP)); |
| 49 | // { '/'=>P } |
| 50 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 51 | auto getRoot = table.get("ndn:/"); |
| 52 | BOOST_CHECK_EQUAL(getRoot.first, true); |
| 53 | BOOST_CHECK_EQUAL(getRoot.second, nameP); |
| 54 | |
| 55 | auto getA = table.get("ndn:/A"); |
| 56 | BOOST_CHECK_EQUAL(getA.first, false); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 59 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 60 | { |
| 61 | Forwarder forwarder; |
| 62 | Name nameP("ndn:/strategy/P"); |
| 63 | Name nameQ("ndn:/strategy/Q"); |
| 64 | Name nameZ("ndn:/strategy/Z"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 65 | install<DummyStrategy>(forwarder, nameP); |
| 66 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 67 | |
| 68 | StrategyChoice& table = forwarder.getStrategyChoice(); |
| 69 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 70 | BOOST_CHECK(table.insert("ndn:/", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 71 | // { '/'=>P } |
| 72 | |
| 73 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 74 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 75 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 76 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 77 | BOOST_CHECK(table.insert("ndn:/A/B", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 78 | // { '/'=>P, '/A/B'=>P } |
| 79 | |
| 80 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 81 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 82 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 83 | // same instance |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 84 | BOOST_CHECK_EQUAL(&table.findEffectiveStrategy("ndn:/"), |
| 85 | &table.findEffectiveStrategy("ndn:/A/B")); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 86 | |
| 87 | table.erase("ndn:/A"); // no effect |
| 88 | // { '/'=>P, '/A/B'=>P } |
| 89 | |
| 90 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 91 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 92 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 93 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 94 | BOOST_CHECK(table.insert("ndn:/A", nameQ)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 95 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
| 96 | |
| 97 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 98 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameQ); |
| 99 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 100 | |
| 101 | table.erase("ndn:/A/B"); |
| 102 | // { '/'=>P, '/A'=>Q } |
| 103 | |
| 104 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 105 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameQ); |
| 106 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameQ); |
| 107 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 108 | BOOST_CHECK(!table.insert("ndn:/", nameZ)); // non existent strategy |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 109 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 110 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 111 | BOOST_CHECK(table.insert("ndn:/A", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 112 | // { '/'=>Q, '/A'=>P } |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/") .getName(), nameQ); |
| 115 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 116 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 117 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/D") .getName(), nameQ); |
| 118 | } |
| 119 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 120 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry) |
| 121 | { |
| 122 | Forwarder forwarder; |
| 123 | Name nameP("ndn:/strategy/P"); |
| 124 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 125 | install<DummyStrategy>(forwarder, nameP); |
| 126 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 127 | |
| 128 | shared_ptr<Data> dataABC = makeData("/A/B/C"); |
| 129 | Name fullName = dataABC->getFullName(); |
| 130 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 131 | StrategyChoice& table = forwarder.getStrategyChoice(); |
| 132 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 133 | BOOST_CHECK(table.insert("/A", nameP)); |
| 134 | BOOST_CHECK(table.insert(fullName, nameQ)); |
| 135 | |
| 136 | Pit& pit = forwarder.getPit(); |
| 137 | shared_ptr<Interest> interestAB = makeInterest("/A/B"); |
| 138 | shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first; |
| 139 | shared_ptr<Interest> interestFull = makeInterest(fullName); |
| 140 | shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first; |
| 141 | |
| 142 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*pitAB).getName(), nameP); |
| 143 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*pitFull).getName(), nameQ); |
| 144 | } |
| 145 | |
| 146 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry) |
| 147 | { |
| 148 | Forwarder forwarder; |
| 149 | Name nameP("ndn:/strategy/P"); |
| 150 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 151 | install<DummyStrategy>(forwarder, nameP); |
| 152 | install<DummyStrategy>(forwarder, nameQ); |
| 153 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 154 | StrategyChoice& table = forwarder.getStrategyChoice(); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 155 | |
| 156 | BOOST_CHECK(table.insert("/A", nameP)); |
| 157 | BOOST_CHECK(table.insert("/A/B/C", nameQ)); |
| 158 | |
| 159 | Measurements& measurements = forwarder.getMeasurements(); |
| 160 | shared_ptr<measurements::Entry> mAB = measurements.get("/A/B"); |
| 161 | shared_ptr<measurements::Entry> mABCD = measurements.get("/A/B/C/D"); |
| 162 | |
| 163 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*mAB).getName(), nameP); |
| 164 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy(*mABCD).getName(), nameQ); |
| 165 | } |
| 166 | |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 167 | //XXX BOOST_CONCEPT_ASSERT((ForwardIterator<std::vector<int>::iterator>)) |
| 168 | // is also failing. There might be a problem with ForwardIterator concept checking. |
| 169 | //BOOST_CONCEPT_ASSERT((ForwardIterator<StrategyChoice::const_iterator>)); |
| 170 | |
| 171 | BOOST_AUTO_TEST_CASE(Enumerate) |
| 172 | { |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 173 | Forwarder forwarder; |
| 174 | Name nameP("ndn:/strategy/P"); |
| 175 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 176 | install<DummyStrategy>(forwarder, nameP); |
| 177 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 178 | |
| 179 | StrategyChoice& table = forwarder.getStrategyChoice(); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 180 | |
| 181 | table.insert("ndn:/", nameP); |
| 182 | table.insert("ndn:/A/B", nameQ); |
| 183 | table.insert("ndn:/A/B/C", nameP); |
| 184 | table.insert("ndn:/D", nameP); |
| 185 | table.insert("ndn:/E", nameQ); |
| 186 | |
| 187 | BOOST_CHECK_EQUAL(table.size(), 5); |
| 188 | |
| 189 | std::map<Name, Name> map; // namespace=>strategyName |
| 190 | for (StrategyChoice::const_iterator it = table.begin(); it != table.end(); ++it) { |
| 191 | map[it->getPrefix()] = it->getStrategyName(); |
| 192 | } |
| 193 | BOOST_CHECK_EQUAL(map.size(), 5); |
| 194 | BOOST_CHECK_EQUAL(map["ndn:/"], nameP); |
| 195 | BOOST_CHECK_EQUAL(map["ndn:/A/B"], nameQ); |
| 196 | BOOST_CHECK_EQUAL(map["ndn:/A/B/C"], nameP); |
| 197 | BOOST_CHECK_EQUAL(map["ndn:/D"], nameP); |
| 198 | BOOST_CHECK_EQUAL(map["ndn:/E"], nameQ); |
| 199 | BOOST_CHECK_EQUAL(map.size(), 5); |
| 200 | } |
| 201 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 202 | class PStrategyInfo : public fw::StrategyInfo |
| 203 | { |
Junxiao Shi | 39ef261 | 2014-11-29 20:35:19 -0700 | [diff] [blame] | 204 | public: |
| 205 | static constexpr int |
| 206 | getTypeId() |
| 207 | { |
| 208 | return 10; |
| 209 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | BOOST_AUTO_TEST_CASE(ClearStrategyInfo) |
| 213 | { |
| 214 | Forwarder forwarder; |
| 215 | Name nameP("ndn:/strategy/P"); |
| 216 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 217 | install<DummyStrategy>(forwarder, nameP); |
| 218 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 219 | |
| 220 | StrategyChoice& table = forwarder.getStrategyChoice(); |
| 221 | Measurements& measurements = forwarder.getMeasurements(); |
| 222 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 223 | BOOST_CHECK(table.insert("ndn:/", nameP)); |
| 224 | // { '/'=>P } |
| 225 | measurements.get("ndn:/") ->getOrCreateStrategyInfo<PStrategyInfo>(); |
| 226 | measurements.get("ndn:/A") ->getOrCreateStrategyInfo<PStrategyInfo>(); |
| 227 | measurements.get("ndn:/A/B") ->getOrCreateStrategyInfo<PStrategyInfo>(); |
| 228 | measurements.get("ndn:/A/C") ->getOrCreateStrategyInfo<PStrategyInfo>(); |
| 229 | |
| 230 | BOOST_CHECK(table.insert("ndn:/A/B", nameP)); |
| 231 | // { '/'=>P, '/A/B'=>P } |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 232 | BOOST_CHECK(measurements.get("ndn:/") ->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 233 | BOOST_CHECK(measurements.get("ndn:/A") ->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 234 | BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 235 | BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 236 | |
| 237 | BOOST_CHECK(table.insert("ndn:/A", nameQ)); |
| 238 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 239 | BOOST_CHECK(measurements.get("ndn:/") ->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 240 | BOOST_CHECK(measurements.get("ndn:/A") ->getStrategyInfo<PStrategyInfo>() == nullptr); |
| 241 | BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 242 | BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 243 | |
| 244 | table.erase("ndn:/A/B"); |
| 245 | // { '/'=>P, '/A'=>Q } |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 246 | BOOST_CHECK(measurements.get("ndn:/") ->getStrategyInfo<PStrategyInfo>() != nullptr); |
| 247 | BOOST_CHECK(measurements.get("ndn:/A") ->getStrategyInfo<PStrategyInfo>() == nullptr); |
| 248 | BOOST_CHECK(measurements.get("ndn:/A/B")->getStrategyInfo<PStrategyInfo>() == nullptr); |
| 249 | BOOST_CHECK(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 252 | BOOST_AUTO_TEST_CASE(EraseNameTreeEntry) |
| 253 | { |
| 254 | Forwarder forwarder; |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 255 | Name nameP("ndn:/strategy/P"); |
| 256 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 257 | install<DummyStrategy>(forwarder, nameP); |
| 258 | install<DummyStrategy>(forwarder, nameQ); |
| 259 | |
| 260 | NameTree& nameTree = forwarder.getNameTree(); |
| 261 | StrategyChoice& table = forwarder.getStrategyChoice(); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 262 | |
| 263 | table.insert("ndn:/", nameP); |
| 264 | |
| 265 | size_t nNameTreeEntriesBefore = nameTree.size(); |
| 266 | |
| 267 | table.insert("ndn:/A/B", nameQ); |
| 268 | table.erase("ndn:/A/B"); |
| 269 | BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore); |
| 270 | } |
| 271 | |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 272 | BOOST_AUTO_TEST_CASE(Versioning) |
| 273 | { |
| 274 | Forwarder forwarder; |
| 275 | Name nameP("ndn:/strategy/P"); |
| 276 | Name nameP1("ndn:/strategy/P/%FD%01"); |
| 277 | Name nameP2("ndn:/strategy/P/%FD%02"); |
| 278 | Name name3("ndn:/%FD%03"); |
| 279 | Name name4("ndn:/%FD%04"); |
| 280 | Name nameQ("ndn:/strategy/Q"); |
| 281 | Name nameQ5("ndn:/strategy/Q/%FD%05"); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 282 | |
| 283 | StrategyChoice& table = forwarder.getStrategyChoice(); |
| 284 | |
| 285 | // install |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 286 | auto strategyP1 = make_unique<DummyStrategy>(ref(forwarder), nameP1); |
| 287 | Strategy* instanceP1 = strategyP1.get(); |
| 288 | auto strategyP1b = make_unique<DummyStrategy>(ref(forwarder), nameP1); |
| 289 | auto strategyP2 = make_unique<DummyStrategy>(ref(forwarder), nameP2); |
| 290 | auto strategy3 = make_unique<DummyStrategy>(ref(forwarder), name3); |
| 291 | auto strategy4 = make_unique<DummyStrategy>(ref(forwarder), name4); |
| 292 | auto strategyQ = make_unique<DummyStrategy>(ref(forwarder), nameQ); |
| 293 | auto strategyQ5 = make_unique<DummyStrategy>(ref(forwarder), nameQ5); |
| 294 | |
| 295 | bool isInstalled = false; |
| 296 | Strategy* installed = nullptr; |
| 297 | |
| 298 | std::tie(isInstalled, installed) = table.install(std::move(strategyP1)); |
| 299 | BOOST_CHECK_EQUAL(isInstalled, true); |
| 300 | BOOST_CHECK_EQUAL(installed, instanceP1); |
| 301 | std::tie(isInstalled, installed) = table.install(std::move(strategyP1b)); |
| 302 | BOOST_CHECK_EQUAL(isInstalled, false); |
| 303 | BOOST_CHECK_EQUAL(installed, instanceP1); |
| 304 | |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(table.hasStrategy(nameP, false), true); |
| 306 | BOOST_CHECK_EQUAL(table.hasStrategy(nameP, true), false); |
| 307 | BOOST_CHECK_EQUAL(table.hasStrategy(nameP1, true), true); |
| 308 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame^] | 309 | BOOST_CHECK_EQUAL(table.install(std::move(strategyP2)).first, true); |
| 310 | BOOST_CHECK_EQUAL(table.install(std::move(strategy3)).first, true); |
| 311 | BOOST_CHECK_EQUAL(table.install(std::move(strategy4)).first, true); |
| 312 | BOOST_CHECK_EQUAL(table.install(std::move(strategyQ)).first, true); |
| 313 | BOOST_CHECK_EQUAL(table.install(std::move(strategyQ5)).first, true); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 314 | |
| 315 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 316 | // exact match, { '/'=>Q } |
| 317 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameQ); |
| 318 | |
| 319 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 320 | BOOST_CHECK(table.insert("ndn:/", nameP)); |
| 321 | // { '/'=>P2 } |
| 322 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameP2); |
| 323 | |
| 324 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 325 | BOOST_CHECK(table.insert("ndn:/", nameP1)); |
| 326 | // { '/'=>P1 } |
| 327 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameP1); |
| 328 | |
| 329 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 330 | BOOST_CHECK(table.insert("ndn:/", nameP2)); |
| 331 | // { '/'=>P2 } |
| 332 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameP2); |
| 333 | |
| 334 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 335 | BOOST_CHECK(! table.insert("ndn:/", "ndn:/strategy/A")); |
| 336 | // not installed |
| 337 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameQ); |
| 338 | |
| 339 | BOOST_CHECK(table.insert("ndn:/", nameQ)); |
| 340 | BOOST_CHECK(! table.insert("ndn:/", "ndn:/strategy/Z")); |
| 341 | // not installed |
| 342 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), nameQ); |
| 343 | |
| 344 | BOOST_CHECK(table.insert("ndn:/", nameP1)); |
| 345 | BOOST_CHECK(table.insert("ndn:/", "ndn:/")); |
| 346 | // match one component longer only, { '/'=>4 } |
| 347 | BOOST_CHECK_EQUAL(table.findEffectiveStrategy("ndn:/").getName(), name4); |
| 348 | } |
| 349 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 350 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice |
| 351 | BOOST_AUTO_TEST_SUITE_END() // Table |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 352 | |
| 353 | } // namespace tests |
| 354 | } // namespace nfd |