Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 4e837f8 | 2017-10-02 22:14:43 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/daemon/global-io-fixture.hpp" |
| 30 | #include "tests/daemon/fw/dummy-strategy.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 35 | class StrategyChoiceFixture : public GlobalIoFixture |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 36 | { |
| 37 | protected: |
| 38 | StrategyChoiceFixture() |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 39 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 40 | DummyStrategy::registerAs(strategyNameP); |
| 41 | DummyStrategy::registerAs(strategyNameQ); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 44 | /** \brief insert StrategyChoice entry at \p prefix for \p instanceName |
| 45 | * \return constructed instance name |
| 46 | */ |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 47 | Name |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 48 | insertAndGet(const Name& prefix, const Name& instanceName) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 49 | { |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 50 | BOOST_REQUIRE(sc.insert(prefix, instanceName)); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 51 | bool isFound; |
| 52 | Name foundName; |
| 53 | std::tie(isFound, foundName) = sc.get(prefix); |
| 54 | BOOST_REQUIRE(isFound); |
| 55 | return foundName; |
| 56 | } |
| 57 | |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 58 | /** \brief determine whether the effective strategy type at \p prefix is \p S |
| 59 | * \tparam S expected strategy type |
| 60 | */ |
| 61 | template<typename S> |
| 62 | bool |
| 63 | isStrategyType(const Name& prefix) |
| 64 | { |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 65 | auto& effectiveStrategy = sc.findEffectiveStrategy(prefix); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 66 | return dynamic_cast<S*>(&effectiveStrategy) != nullptr; |
| 67 | } |
| 68 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 69 | template<typename Q> |
| 70 | Name |
| 71 | findInstanceName(const Q& query) |
| 72 | { |
| 73 | return sc.findEffectiveStrategy(query).getInstanceName(); |
| 74 | } |
| 75 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 76 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame^] | 77 | FaceTable faceTable; |
| 78 | Forwarder forwarder{faceTable}; |
| 79 | StrategyChoice& sc{forwarder.getStrategyChoice()}; |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 80 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame^] | 81 | const Name strategyNameP = "/strategy-choice-P/%FD%00"; |
| 82 | const Name strategyNameQ = "/strategy-choice-Q/%FD%00"; |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 85 | BOOST_AUTO_TEST_SUITE(Table) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 86 | BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 87 | |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 88 | BOOST_AUTO_TEST_CASE(Versioning) |
| 89 | { |
| 90 | const Name strategyNameV("/strategy-choice-V"); |
| 91 | const Name strategyNameV0("/strategy-choice-V/%FD%00"); |
| 92 | const Name strategyNameV1("/strategy-choice-V/%FD%01"); |
| 93 | const Name strategyNameV2("/strategy-choice-V/%FD%02"); |
| 94 | const Name strategyNameV3("/strategy-choice-V/%FD%03"); |
| 95 | const Name strategyNameV4("/strategy-choice-V/%FD%04"); |
| 96 | const Name strategyNameV5("/strategy-choice-V/%FD%05"); |
| 97 | |
| 98 | VersionedDummyStrategy<1>::registerAs(strategyNameV1); |
| 99 | VersionedDummyStrategy<3>::registerAs(strategyNameV3); |
| 100 | VersionedDummyStrategy<4>::registerAs(strategyNameV4); |
| 101 | |
| 102 | // unversioned: choose latest version |
| 103 | BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameV), strategyNameV4); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 104 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/A")); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 105 | |
| 106 | // exact version: choose same version |
| 107 | BOOST_CHECK_EQUAL(this->insertAndGet("/B", strategyNameV1), strategyNameV1); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 108 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/B")); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 109 | BOOST_CHECK_EQUAL(this->insertAndGet("/C", strategyNameV3), strategyNameV3); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 110 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/C")); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(this->insertAndGet("/D", strategyNameV4), strategyNameV4); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 112 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/D")); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 113 | |
| 114 | // lower version: choose next higher version |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 115 | BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV0); |
| 116 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/E")); |
| 117 | BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV2); |
| 118 | BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/F")); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 119 | |
| 120 | // higher version: failure |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 121 | StrategyChoice::InsertResult res5 = sc.insert("/G", strategyNameV5); |
| 122 | BOOST_CHECK(!res5); |
| 123 | BOOST_CHECK(!res5.isRegistered()); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 126 | BOOST_AUTO_TEST_CASE(Parameters) |
| 127 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 128 | // no parameters |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameP), strategyNameP); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 130 | |
| 131 | // one parameter |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 132 | Name oneParamName = Name(strategyNameP).append("param"); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 133 | BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName); |
| 134 | |
| 135 | // two parameters |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 136 | Name twoParamName = Name(strategyNameP).append("x").append("y"); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName); |
| 138 | |
| 139 | // parameter without version is disallowed |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 140 | Name oneParamUnversioned = strategyNameP.getPrefix(-1).append("param"); |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 141 | BOOST_CHECK(!sc.insert("/D", oneParamUnversioned)); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Junxiao Shi | 4e837f8 | 2017-10-02 22:14:43 +0000 | [diff] [blame] | 144 | BOOST_AUTO_TEST_CASE(InsertLongName) |
| 145 | { |
| 146 | Name n1; |
| 147 | while (n1.size() < NameTree::getMaxDepth()) { |
| 148 | n1.append("A"); |
| 149 | } |
| 150 | Name n2 = n1; |
| 151 | while (n2.size() < NameTree::getMaxDepth() * 2) { |
| 152 | n2.append("B"); |
| 153 | } |
| 154 | |
| 155 | BOOST_CHECK(sc.insert(n1, strategyNameP)); |
| 156 | BOOST_CHECK(!sc.insert(n2, strategyNameP)); |
| 157 | } |
| 158 | |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 159 | BOOST_AUTO_TEST_CASE(Get) |
| 160 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 161 | BOOST_CHECK(sc.insert("/", strategyNameP)); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 162 | // { '/'=>P } |
| 163 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 164 | auto getRoot = sc.get("/"); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 165 | BOOST_CHECK_EQUAL(getRoot.first, true); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 166 | BOOST_CHECK_EQUAL(getRoot.second, strategyNameP); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 167 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 168 | auto getA = sc.get("/A"); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(getA.first, false); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 170 | } |
| 171 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 172 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 173 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 174 | const Name strategyNameZ("/strategy-choice-Z/%FD%00"); // unregistered strategyName |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 175 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 176 | BOOST_CHECK(sc.insert("/", strategyNameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 177 | // { '/'=>P } |
| 178 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP); |
| 180 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP); |
| 181 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 182 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 183 | BOOST_CHECK(sc.insert("/A/B", strategyNameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 184 | // { '/'=>P, '/A/B'=>P } |
| 185 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP); |
| 187 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP); |
| 188 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP); |
| 189 | // same entry, same instance |
| 190 | BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A")); |
| 191 | // different entries, distinct instances |
| 192 | BOOST_CHECK_NE(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A/B")); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 193 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 194 | sc.erase("/A"); // no effect |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 195 | // { '/'=>P, '/A/B'=>P } |
| 196 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP); |
| 198 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP); |
| 199 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 200 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 201 | BOOST_CHECK(sc.insert("/A", strategyNameQ)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 202 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
| 203 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP); |
| 205 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ); |
| 206 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 207 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 208 | sc.erase("/A/B"); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 209 | // { '/'=>P, '/A'=>Q } |
| 210 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP); |
| 212 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ); |
| 213 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 214 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 215 | BOOST_CHECK(!sc.insert("/", strategyNameZ)); // non existent strategy |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 216 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 217 | BOOST_CHECK(sc.insert("/", strategyNameQ)); |
| 218 | BOOST_CHECK(sc.insert("/A", strategyNameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 219 | // { '/'=>Q, '/A'=>P } |
| 220 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 221 | BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameQ); |
| 222 | BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP); |
| 223 | BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP); |
| 224 | BOOST_CHECK_EQUAL(this->findInstanceName("/D"), strategyNameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry) |
| 228 | { |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 229 | shared_ptr<Data> dataABC = makeData("/A/B/C"); |
| 230 | Name fullName = dataABC->getFullName(); |
| 231 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 232 | BOOST_CHECK(sc.insert("/A", strategyNameP)); |
| 233 | BOOST_CHECK(sc.insert(fullName, strategyNameQ)); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 234 | |
| 235 | Pit& pit = forwarder.getPit(); |
| 236 | shared_ptr<Interest> interestAB = makeInterest("/A/B"); |
| 237 | shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first; |
| 238 | shared_ptr<Interest> interestFull = makeInterest(fullName); |
| 239 | shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first; |
| 240 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 241 | BOOST_CHECK_EQUAL(this->findInstanceName(*pitAB), strategyNameP); |
| 242 | BOOST_CHECK_EQUAL(this->findInstanceName(*pitFull), strategyNameQ); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry) |
| 246 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 247 | BOOST_CHECK(sc.insert("/A", strategyNameP)); |
| 248 | BOOST_CHECK(sc.insert("/A/B/C", strategyNameQ)); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 249 | |
| 250 | Measurements& measurements = forwarder.getMeasurements(); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 251 | measurements::Entry& mAB = measurements.get("/A/B"); |
| 252 | measurements::Entry& mABCD = measurements.get("/A/B/C/D"); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 253 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 254 | BOOST_CHECK_EQUAL(this->findInstanceName(mAB), strategyNameP); |
| 255 | BOOST_CHECK_EQUAL(this->findInstanceName(mABCD), strategyNameQ); |
| 256 | } |
| 257 | |
| 258 | BOOST_AUTO_TEST_CASE(Erase) |
| 259 | { |
| 260 | NameTree& nameTree = forwarder.getNameTree(); |
| 261 | |
| 262 | sc.insert("/", strategyNameP); |
| 263 | |
| 264 | size_t nNameTreeEntriesBefore = nameTree.size(); |
| 265 | |
| 266 | sc.insert("/A/B", strategyNameQ); |
| 267 | sc.erase("/A/B"); |
| 268 | BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(Enumerate) |
| 272 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 273 | sc.insert("/", strategyNameP); |
| 274 | sc.insert("/A/B", strategyNameQ); |
| 275 | sc.insert("/A/B/C", strategyNameP); |
| 276 | sc.insert("/D", strategyNameP); |
| 277 | sc.insert("/E", strategyNameQ); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 278 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL(sc.size(), 5); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 280 | |
| 281 | std::map<Name, Name> map; // namespace=>strategyName |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 282 | for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) { |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 283 | map[it->getPrefix()] = it->getStrategyInstanceName(); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 284 | } |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 285 | |
| 286 | BOOST_CHECK_EQUAL(map.at("/"), strategyNameP); |
| 287 | BOOST_CHECK_EQUAL(map.at("/A/B"), strategyNameQ); |
| 288 | BOOST_CHECK_EQUAL(map.at("/A/B/C"), strategyNameP); |
| 289 | BOOST_CHECK_EQUAL(map.at("/D"), strategyNameP); |
| 290 | BOOST_CHECK_EQUAL(map.at("/E"), strategyNameQ); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(map.size(), 5); |
| 292 | } |
| 293 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 294 | class PStrategyInfo : public fw::StrategyInfo |
| 295 | { |
Junxiao Shi | 39ef261 | 2014-11-29 20:35:19 -0700 | [diff] [blame] | 296 | public: |
| 297 | static constexpr int |
| 298 | getTypeId() |
| 299 | { |
| 300 | return 10; |
| 301 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | BOOST_AUTO_TEST_CASE(ClearStrategyInfo) |
| 305 | { |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 306 | Measurements& measurements = forwarder.getMeasurements(); |
| 307 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 308 | BOOST_CHECK(sc.insert("/", strategyNameP)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 309 | // { '/'=>P } |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 310 | measurements.get("/").insertStrategyInfo<PStrategyInfo>(); |
| 311 | measurements.get("/A").insertStrategyInfo<PStrategyInfo>(); |
| 312 | measurements.get("/A/B").insertStrategyInfo<PStrategyInfo>(); |
| 313 | measurements.get("/A/C").insertStrategyInfo<PStrategyInfo>(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 314 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 315 | BOOST_CHECK(sc.insert("/A/B", strategyNameP)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 316 | // { '/'=>P, '/A/B'=>P } |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 317 | BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 318 | BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 319 | BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 320 | BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 321 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 322 | BOOST_CHECK(sc.insert("/A", strategyNameQ)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 323 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 324 | BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 325 | BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 326 | BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 327 | BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 328 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 329 | sc.erase("/A/B"); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 330 | // { '/'=>P, '/A'=>Q } |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 331 | BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 332 | BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr); |
| 333 | BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() == nullptr); |
| 334 | BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 337 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice |
| 338 | BOOST_AUTO_TEST_SUITE_END() // Table |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 339 | |
| 340 | } // namespace tests |
| 341 | } // namespace nfd |