blob: ff6b754aa940a8a65ea04e49aa095f53056ac4d2 [file] [log] [blame]
Junxiao Shibb5105f2014-03-03 12:06:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi4e837f82017-10-02 22:14:43 +00002/*
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shiee5a4442014-07-27 17:13:43 -070024 */
Junxiao Shibb5105f2014-03-03 12:06:45 -070025
26#include "table/strategy-choice.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070027
28#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/daemon/global-io-fixture.hpp"
30#include "tests/daemon/fw/dummy-strategy.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070031
32namespace nfd {
33namespace tests {
34
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040035class StrategyChoiceFixture : public GlobalIoFixture
Junxiao Shi18739c42016-12-22 08:03:00 +000036{
37protected:
38 StrategyChoiceFixture()
Junxiao Shi18739c42016-12-22 08:03:00 +000039 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000040 DummyStrategy::registerAs(strategyNameP);
41 DummyStrategy::registerAs(strategyNameQ);
Junxiao Shi18739c42016-12-22 08:03:00 +000042 }
43
Junxiao Shi91f6ee02016-12-29 21:44:44 +000044 /** \brief insert StrategyChoice entry at \p prefix for \p instanceName
45 * \return constructed instance name
46 */
Junxiao Shi18739c42016-12-22 08:03:00 +000047 Name
Junxiao Shi91f6ee02016-12-29 21:44:44 +000048 insertAndGet(const Name& prefix, const Name& instanceName)
Junxiao Shi18739c42016-12-22 08:03:00 +000049 {
Junxiao Shi91f6ee02016-12-29 21:44:44 +000050 BOOST_REQUIRE(sc.insert(prefix, instanceName));
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040051 auto [isFound, foundName] = sc.get(prefix);
Junxiao Shi18739c42016-12-22 08:03:00 +000052 BOOST_REQUIRE(isFound);
53 return foundName;
54 }
55
Junxiao Shi91f6ee02016-12-29 21:44:44 +000056 /** \brief determine whether the effective strategy type at \p prefix is \p S
57 * \tparam S expected strategy type
58 */
59 template<typename S>
60 bool
61 isStrategyType(const Name& prefix)
62 {
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040063 auto& effectiveStrategy = sc.findEffectiveStrategy(prefix);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000064 return dynamic_cast<S*>(&effectiveStrategy) != nullptr;
65 }
66
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000067 template<typename Q>
68 Name
69 findInstanceName(const Q& query)
70 {
71 return sc.findEffectiveStrategy(query).getInstanceName();
72 }
73
Junxiao Shi18739c42016-12-22 08:03:00 +000074protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040075 FaceTable faceTable;
76 Forwarder forwarder{faceTable};
77 StrategyChoice& sc{forwarder.getStrategyChoice()};
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000078
Eric Newberry358414d2021-03-21 20:56:42 -070079 const Name strategyNameP = Name("/strategy-choice-P").appendVersion(0);
80 const Name strategyNameQ = Name("/strategy-choice-Q").appendVersion(0);
Junxiao Shi18739c42016-12-22 08:03:00 +000081};
82
Junxiao Shi4370fde2016-02-24 12:20:46 -070083BOOST_AUTO_TEST_SUITE(Table)
Junxiao Shi18739c42016-12-22 08:03:00 +000084BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture)
Junxiao Shibb5105f2014-03-03 12:06:45 -070085
Junxiao Shi7f566dd2016-12-27 02:28:31 +000086BOOST_AUTO_TEST_CASE(Versioning)
87{
Eric Newberry358414d2021-03-21 20:56:42 -070088 const auto strategyNameV = Name("/strategy-choice-V");
89 const auto strategyNameV0 = Name("/strategy-choice-V").appendVersion(0);
90 const auto strategyNameV1 = Name("/strategy-choice-V").appendVersion(1);
91 const auto strategyNameV2 = Name("/strategy-choice-V").appendVersion(2);
92 const auto strategyNameV3 = Name("/strategy-choice-V").appendVersion(3);
93 const auto strategyNameV4 = Name("/strategy-choice-V").appendVersion(4);
94 const auto strategyNameV5 = Name("/strategy-choice-V").appendVersion(5);
Junxiao Shi7f566dd2016-12-27 02:28:31 +000095
96 VersionedDummyStrategy<1>::registerAs(strategyNameV1);
97 VersionedDummyStrategy<3>::registerAs(strategyNameV3);
98 VersionedDummyStrategy<4>::registerAs(strategyNameV4);
99
100 // unversioned: choose latest version
101 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameV), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000102 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/A"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000103
104 // exact version: choose same version
105 BOOST_CHECK_EQUAL(this->insertAndGet("/B", strategyNameV1), strategyNameV1);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000106 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/B"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000107 BOOST_CHECK_EQUAL(this->insertAndGet("/C", strategyNameV3), strategyNameV3);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000108 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/C"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000109 BOOST_CHECK_EQUAL(this->insertAndGet("/D", strategyNameV4), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000110 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/D"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000111
112 // lower version: choose next higher version
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000113 BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV0);
114 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/E"));
115 BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV2);
116 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/F"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000117
118 // higher version: failure
Junxiao Shi530cf002017-01-03 14:43:16 +0000119 StrategyChoice::InsertResult res5 = sc.insert("/G", strategyNameV5);
120 BOOST_CHECK(!res5);
121 BOOST_CHECK(!res5.isRegistered());
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000122}
123
Junxiao Shi18739c42016-12-22 08:03:00 +0000124BOOST_AUTO_TEST_CASE(Parameters)
125{
Junxiao Shi18739c42016-12-22 08:03:00 +0000126 // no parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000127 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameP), strategyNameP);
Junxiao Shi18739c42016-12-22 08:03:00 +0000128
129 // one parameter
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000130 Name oneParamName = Name(strategyNameP).append("param");
Junxiao Shi18739c42016-12-22 08:03:00 +0000131 BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName);
132
133 // two parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000134 Name twoParamName = Name(strategyNameP).append("x").append("y");
Junxiao Shi18739c42016-12-22 08:03:00 +0000135 BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName);
136
137 // parameter without version is disallowed
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000138 Name oneParamUnversioned = strategyNameP.getPrefix(-1).append("param");
Junxiao Shi530cf002017-01-03 14:43:16 +0000139 BOOST_CHECK(!sc.insert("/D", oneParamUnversioned));
Junxiao Shi18739c42016-12-22 08:03:00 +0000140}
141
Junxiao Shi4e837f82017-10-02 22:14:43 +0000142BOOST_AUTO_TEST_CASE(InsertLongName)
143{
144 Name n1;
145 while (n1.size() < NameTree::getMaxDepth()) {
146 n1.append("A");
147 }
148 Name n2 = n1;
149 while (n2.size() < NameTree::getMaxDepth() * 2) {
150 n2.append("B");
151 }
152
153 BOOST_CHECK(sc.insert(n1, strategyNameP));
154 BOOST_CHECK(!sc.insert(n2, strategyNameP));
155}
156
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600157BOOST_AUTO_TEST_CASE(Get)
158{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000159 BOOST_CHECK(sc.insert("/", strategyNameP));
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600160 // { '/'=>P }
161
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000162 auto getRoot = sc.get("/");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700163 BOOST_CHECK_EQUAL(getRoot.first, true);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000164 BOOST_CHECK_EQUAL(getRoot.second, strategyNameP);
Junxiao Shi838c4f12014-11-03 18:55:24 -0700165
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000166 auto getA = sc.get("/A");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700167 BOOST_CHECK_EQUAL(getA.first, false);
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600168}
169
Junxiao Shi4370fde2016-02-24 12:20:46 -0700170BOOST_AUTO_TEST_CASE(FindEffectiveStrategy)
Junxiao Shibb5105f2014-03-03 12:06:45 -0700171{
Eric Newberry358414d2021-03-21 20:56:42 -0700172 const auto strategyNameZ = Name("/strategy-choice-Z").appendVersion(0); // unregistered strategyName
Junxiao Shibb5105f2014-03-03 12:06:45 -0700173
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000174 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700175 // { '/'=>P }
176
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000177 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
178 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
179 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700180
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000181 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700182 // { '/'=>P, '/A/B'=>P }
183
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000184 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
185 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
186 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
187 // same entry, same instance
188 BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A"));
189 // different entries, distinct instances
190 BOOST_CHECK_NE(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A/B"));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700191
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000192 sc.erase("/A"); // no effect
Junxiao Shibb5105f2014-03-03 12:06:45 -0700193 // { '/'=>P, '/A/B'=>P }
194
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000195 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
196 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
197 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700198
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000199 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700200 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
201
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000202 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
203 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
204 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700205
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000206 sc.erase("/A/B");
Junxiao Shibb5105f2014-03-03 12:06:45 -0700207 // { '/'=>P, '/A'=>Q }
208
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000209 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
210 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
211 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700212
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000213 BOOST_CHECK(!sc.insert("/", strategyNameZ)); // non existent strategy
Junxiao Shibb5105f2014-03-03 12:06:45 -0700214
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000215 BOOST_CHECK(sc.insert("/", strategyNameQ));
216 BOOST_CHECK(sc.insert("/A", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700217 // { '/'=>Q, '/A'=>P }
218
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000219 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameQ);
220 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
221 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
222 BOOST_CHECK_EQUAL(this->findInstanceName("/D"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700223}
224
Junxiao Shi4370fde2016-02-24 12:20:46 -0700225BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry)
226{
Junxiao Shi4370fde2016-02-24 12:20:46 -0700227 shared_ptr<Data> dataABC = makeData("/A/B/C");
228 Name fullName = dataABC->getFullName();
229
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000230 BOOST_CHECK(sc.insert("/A", strategyNameP));
231 BOOST_CHECK(sc.insert(fullName, strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700232
233 Pit& pit = forwarder.getPit();
234 shared_ptr<Interest> interestAB = makeInterest("/A/B");
235 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
236 shared_ptr<Interest> interestFull = makeInterest(fullName);
237 shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first;
238
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000239 BOOST_CHECK_EQUAL(this->findInstanceName(*pitAB), strategyNameP);
240 BOOST_CHECK_EQUAL(this->findInstanceName(*pitFull), strategyNameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700241}
242
243BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry)
244{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000245 BOOST_CHECK(sc.insert("/A", strategyNameP));
246 BOOST_CHECK(sc.insert("/A/B/C", strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700247
248 Measurements& measurements = forwarder.getMeasurements();
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000249 measurements::Entry& mAB = measurements.get("/A/B");
250 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700251
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000252 BOOST_CHECK_EQUAL(this->findInstanceName(mAB), strategyNameP);
253 BOOST_CHECK_EQUAL(this->findInstanceName(mABCD), strategyNameQ);
254}
255
256BOOST_AUTO_TEST_CASE(Erase)
257{
258 NameTree& nameTree = forwarder.getNameTree();
259
260 sc.insert("/", strategyNameP);
261
262 size_t nNameTreeEntriesBefore = nameTree.size();
263
264 sc.insert("/A/B", strategyNameQ);
265 sc.erase("/A/B");
266 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700267}
268
Junxiao Shib5888d22014-05-26 07:35:22 -0700269BOOST_AUTO_TEST_CASE(Enumerate)
270{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000271 sc.insert("/", strategyNameP);
272 sc.insert("/A/B", strategyNameQ);
273 sc.insert("/A/B/C", strategyNameP);
274 sc.insert("/D", strategyNameP);
275 sc.insert("/E", strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700276
Junxiao Shi18739c42016-12-22 08:03:00 +0000277 BOOST_CHECK_EQUAL(sc.size(), 5);
Junxiao Shib5888d22014-05-26 07:35:22 -0700278
279 std::map<Name, Name> map; // namespace=>strategyName
Junxiao Shi18739c42016-12-22 08:03:00 +0000280 for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) {
Junxiao Shi4cb74312016-12-25 20:48:47 +0000281 map[it->getPrefix()] = it->getStrategyInstanceName();
Junxiao Shib5888d22014-05-26 07:35:22 -0700282 }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000283
284 BOOST_CHECK_EQUAL(map.at("/"), strategyNameP);
285 BOOST_CHECK_EQUAL(map.at("/A/B"), strategyNameQ);
286 BOOST_CHECK_EQUAL(map.at("/A/B/C"), strategyNameP);
287 BOOST_CHECK_EQUAL(map.at("/D"), strategyNameP);
288 BOOST_CHECK_EQUAL(map.at("/E"), strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700289 BOOST_CHECK_EQUAL(map.size(), 5);
290}
291
Junxiao Shie349ea12014-03-12 01:32:42 -0700292class PStrategyInfo : public fw::StrategyInfo
293{
Junxiao Shi39ef2612014-11-29 20:35:19 -0700294public:
295 static constexpr int
296 getTypeId()
297 {
298 return 10;
299 }
Junxiao Shie349ea12014-03-12 01:32:42 -0700300};
301
302BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
303{
Junxiao Shie349ea12014-03-12 01:32:42 -0700304 Measurements& measurements = forwarder.getMeasurements();
305
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000306 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700307 // { '/'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000308 measurements.get("/").insertStrategyInfo<PStrategyInfo>();
309 measurements.get("/A").insertStrategyInfo<PStrategyInfo>();
310 measurements.get("/A/B").insertStrategyInfo<PStrategyInfo>();
311 measurements.get("/A/C").insertStrategyInfo<PStrategyInfo>();
Junxiao Shie349ea12014-03-12 01:32:42 -0700312
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000313 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700314 // { '/'=>P, '/A/B'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000315 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
316 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000317 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000318 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700319
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000320 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shie349ea12014-03-12 01:32:42 -0700321 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000322 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
323 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000324 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000325 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700326
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000327 sc.erase("/A/B");
Junxiao Shie349ea12014-03-12 01:32:42 -0700328 // { '/'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000329 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
330 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
331 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() == nullptr);
332 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700333}
334
Junxiao Shi4370fde2016-02-24 12:20:46 -0700335BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
336BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shibb5105f2014-03-03 12:06:45 -0700337
338} // namespace tests
339} // namespace nfd