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