blob: 574317d5d736207506cc57b2a7c09e91303dda9d [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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::tests {
Junxiao Shibb5105f2014-03-03 12:06:45 -070033
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040034class StrategyChoiceFixture : public GlobalIoFixture
Junxiao Shi18739c42016-12-22 08:03:00 +000035{
36protected:
37 StrategyChoiceFixture()
Junxiao Shi18739c42016-12-22 08:03:00 +000038 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000039 DummyStrategy::registerAs(strategyNameP);
40 DummyStrategy::registerAs(strategyNameQ);
Junxiao Shi18739c42016-12-22 08:03:00 +000041 }
42
Junxiao Shi91f6ee02016-12-29 21:44:44 +000043 /** \brief insert StrategyChoice entry at \p prefix for \p instanceName
44 * \return constructed instance name
45 */
Junxiao Shi18739c42016-12-22 08:03:00 +000046 Name
Junxiao Shi91f6ee02016-12-29 21:44:44 +000047 insertAndGet(const Name& prefix, const Name& instanceName)
Junxiao Shi18739c42016-12-22 08:03:00 +000048 {
Junxiao Shi91f6ee02016-12-29 21:44:44 +000049 BOOST_REQUIRE(sc.insert(prefix, instanceName));
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040050 auto [isFound, foundName] = sc.get(prefix);
Junxiao Shi18739c42016-12-22 08:03:00 +000051 BOOST_REQUIRE(isFound);
52 return foundName;
53 }
54
Junxiao Shi91f6ee02016-12-29 21:44:44 +000055 /** \brief determine whether the effective strategy type at \p prefix is \p S
56 * \tparam S expected strategy type
57 */
58 template<typename S>
59 bool
60 isStrategyType(const Name& prefix)
61 {
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040062 auto& effectiveStrategy = sc.findEffectiveStrategy(prefix);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000063 return dynamic_cast<S*>(&effectiveStrategy) != nullptr;
64 }
65
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000066 template<typename Q>
67 Name
68 findInstanceName(const Q& query)
69 {
70 return sc.findEffectiveStrategy(query).getInstanceName();
71 }
72
Junxiao Shi18739c42016-12-22 08:03:00 +000073protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040074 FaceTable faceTable;
75 Forwarder forwarder{faceTable};
76 StrategyChoice& sc{forwarder.getStrategyChoice()};
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000077
Eric Newberry358414d2021-03-21 20:56:42 -070078 const Name strategyNameP = Name("/strategy-choice-P").appendVersion(0);
79 const Name strategyNameQ = Name("/strategy-choice-Q").appendVersion(0);
Junxiao Shi18739c42016-12-22 08:03:00 +000080};
81
Junxiao Shi4370fde2016-02-24 12:20:46 -070082BOOST_AUTO_TEST_SUITE(Table)
Junxiao Shi18739c42016-12-22 08:03:00 +000083BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture)
Junxiao Shibb5105f2014-03-03 12:06:45 -070084
Junxiao Shi7f566dd2016-12-27 02:28:31 +000085BOOST_AUTO_TEST_CASE(Versioning)
86{
Eric Newberry358414d2021-03-21 20:56:42 -070087 const auto strategyNameV = Name("/strategy-choice-V");
88 const auto strategyNameV0 = Name("/strategy-choice-V").appendVersion(0);
89 const auto strategyNameV1 = Name("/strategy-choice-V").appendVersion(1);
90 const auto strategyNameV2 = Name("/strategy-choice-V").appendVersion(2);
91 const auto strategyNameV3 = Name("/strategy-choice-V").appendVersion(3);
92 const auto strategyNameV4 = Name("/strategy-choice-V").appendVersion(4);
93 const auto strategyNameV5 = Name("/strategy-choice-V").appendVersion(5);
Junxiao Shi7f566dd2016-12-27 02:28:31 +000094
95 VersionedDummyStrategy<1>::registerAs(strategyNameV1);
96 VersionedDummyStrategy<3>::registerAs(strategyNameV3);
97 VersionedDummyStrategy<4>::registerAs(strategyNameV4);
98
99 // unversioned: choose latest version
100 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameV), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000101 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/A"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000102
103 // exact version: choose same version
104 BOOST_CHECK_EQUAL(this->insertAndGet("/B", strategyNameV1), strategyNameV1);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000105 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/B"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000106 BOOST_CHECK_EQUAL(this->insertAndGet("/C", strategyNameV3), strategyNameV3);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000107 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/C"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000108 BOOST_CHECK_EQUAL(this->insertAndGet("/D", strategyNameV4), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000109 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/D"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000110
111 // lower version: choose next higher version
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000112 BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV0);
113 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/E"));
114 BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV2);
115 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/F"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000116
117 // higher version: failure
Junxiao Shi530cf002017-01-03 14:43:16 +0000118 StrategyChoice::InsertResult res5 = sc.insert("/G", strategyNameV5);
119 BOOST_CHECK(!res5);
120 BOOST_CHECK(!res5.isRegistered());
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000121}
122
Junxiao Shi18739c42016-12-22 08:03:00 +0000123BOOST_AUTO_TEST_CASE(Parameters)
124{
Junxiao Shi18739c42016-12-22 08:03:00 +0000125 // no parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000126 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameP), strategyNameP);
Junxiao Shi18739c42016-12-22 08:03:00 +0000127
128 // one parameter
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000129 Name oneParamName = Name(strategyNameP).append("param");
Junxiao Shi18739c42016-12-22 08:03:00 +0000130 BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName);
131
132 // two parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000133 Name twoParamName = Name(strategyNameP).append("x").append("y");
Junxiao Shi18739c42016-12-22 08:03:00 +0000134 BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName);
135
136 // parameter without version is disallowed
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000137 Name oneParamUnversioned = strategyNameP.getPrefix(-1).append("param");
Junxiao Shi530cf002017-01-03 14:43:16 +0000138 BOOST_CHECK(!sc.insert("/D", oneParamUnversioned));
Junxiao Shi18739c42016-12-22 08:03:00 +0000139}
140
Junxiao Shi4e837f82017-10-02 22:14:43 +0000141BOOST_AUTO_TEST_CASE(InsertLongName)
142{
143 Name n1;
144 while (n1.size() < NameTree::getMaxDepth()) {
145 n1.append("A");
146 }
147 Name n2 = n1;
148 while (n2.size() < NameTree::getMaxDepth() * 2) {
149 n2.append("B");
150 }
151
152 BOOST_CHECK(sc.insert(n1, strategyNameP));
153 BOOST_CHECK(!sc.insert(n2, strategyNameP));
154}
155
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600156BOOST_AUTO_TEST_CASE(Get)
157{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000158 BOOST_CHECK(sc.insert("/", strategyNameP));
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600159 // { '/'=>P }
160
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000161 auto getRoot = sc.get("/");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700162 BOOST_CHECK_EQUAL(getRoot.first, true);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000163 BOOST_CHECK_EQUAL(getRoot.second, strategyNameP);
Junxiao Shi838c4f12014-11-03 18:55:24 -0700164
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000165 auto getA = sc.get("/A");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700166 BOOST_CHECK_EQUAL(getA.first, false);
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600167}
168
Junxiao Shi4370fde2016-02-24 12:20:46 -0700169BOOST_AUTO_TEST_CASE(FindEffectiveStrategy)
Junxiao Shibb5105f2014-03-03 12:06:45 -0700170{
Eric Newberry358414d2021-03-21 20:56:42 -0700171 const auto strategyNameZ = Name("/strategy-choice-Z").appendVersion(0); // unregistered strategyName
Junxiao Shibb5105f2014-03-03 12:06:45 -0700172
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000173 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700174 // { '/'=>P }
175
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000176 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
177 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
178 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700179
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000180 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700181 // { '/'=>P, '/A/B'=>P }
182
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000183 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
184 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
185 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
186 // same entry, same instance
187 BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A"));
188 // different entries, distinct instances
189 BOOST_CHECK_NE(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A/B"));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700190
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000191 sc.erase("/A"); // no effect
Junxiao Shibb5105f2014-03-03 12:06:45 -0700192 // { '/'=>P, '/A/B'=>P }
193
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000194 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
195 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
196 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700197
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000198 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700199 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
200
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000201 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
202 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
203 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700204
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000205 sc.erase("/A/B");
Junxiao Shibb5105f2014-03-03 12:06:45 -0700206 // { '/'=>P, '/A'=>Q }
207
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000208 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
209 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
210 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700211
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000212 BOOST_CHECK(!sc.insert("/", strategyNameZ)); // non existent strategy
Junxiao Shibb5105f2014-03-03 12:06:45 -0700213
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000214 BOOST_CHECK(sc.insert("/", strategyNameQ));
215 BOOST_CHECK(sc.insert("/A", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700216 // { '/'=>Q, '/A'=>P }
217
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000218 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameQ);
219 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
220 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
221 BOOST_CHECK_EQUAL(this->findInstanceName("/D"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700222}
223
Junxiao Shi4370fde2016-02-24 12:20:46 -0700224BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry)
225{
Junxiao Shi4370fde2016-02-24 12:20:46 -0700226 shared_ptr<Data> dataABC = makeData("/A/B/C");
227 Name fullName = dataABC->getFullName();
228
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000229 BOOST_CHECK(sc.insert("/A", strategyNameP));
230 BOOST_CHECK(sc.insert(fullName, strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700231
232 Pit& pit = forwarder.getPit();
233 shared_ptr<Interest> interestAB = makeInterest("/A/B");
234 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
235 shared_ptr<Interest> interestFull = makeInterest(fullName);
236 shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first;
237
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000238 BOOST_CHECK_EQUAL(this->findInstanceName(*pitAB), strategyNameP);
239 BOOST_CHECK_EQUAL(this->findInstanceName(*pitFull), strategyNameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700240}
241
242BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry)
243{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000244 BOOST_CHECK(sc.insert("/A", strategyNameP));
245 BOOST_CHECK(sc.insert("/A/B/C", strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700246
247 Measurements& measurements = forwarder.getMeasurements();
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000248 measurements::Entry& mAB = measurements.get("/A/B");
249 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700250
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000251 BOOST_CHECK_EQUAL(this->findInstanceName(mAB), strategyNameP);
252 BOOST_CHECK_EQUAL(this->findInstanceName(mABCD), strategyNameQ);
253}
254
255BOOST_AUTO_TEST_CASE(Erase)
256{
257 NameTree& nameTree = forwarder.getNameTree();
258
259 sc.insert("/", strategyNameP);
260
261 size_t nNameTreeEntriesBefore = nameTree.size();
262
263 sc.insert("/A/B", strategyNameQ);
264 sc.erase("/A/B");
265 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700266}
267
Junxiao Shib5888d22014-05-26 07:35:22 -0700268BOOST_AUTO_TEST_CASE(Enumerate)
269{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000270 sc.insert("/", strategyNameP);
271 sc.insert("/A/B", strategyNameQ);
272 sc.insert("/A/B/C", strategyNameP);
273 sc.insert("/D", strategyNameP);
274 sc.insert("/E", strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700275
Junxiao Shi18739c42016-12-22 08:03:00 +0000276 BOOST_CHECK_EQUAL(sc.size(), 5);
Junxiao Shib5888d22014-05-26 07:35:22 -0700277
278 std::map<Name, Name> map; // namespace=>strategyName
Junxiao Shi18739c42016-12-22 08:03:00 +0000279 for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) {
Junxiao Shi4cb74312016-12-25 20:48:47 +0000280 map[it->getPrefix()] = it->getStrategyInstanceName();
Junxiao Shib5888d22014-05-26 07:35:22 -0700281 }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000282
283 BOOST_CHECK_EQUAL(map.at("/"), strategyNameP);
284 BOOST_CHECK_EQUAL(map.at("/A/B"), strategyNameQ);
285 BOOST_CHECK_EQUAL(map.at("/A/B/C"), strategyNameP);
286 BOOST_CHECK_EQUAL(map.at("/D"), strategyNameP);
287 BOOST_CHECK_EQUAL(map.at("/E"), strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700288 BOOST_CHECK_EQUAL(map.size(), 5);
289}
290
Junxiao Shie349ea12014-03-12 01:32:42 -0700291class PStrategyInfo : public fw::StrategyInfo
292{
Junxiao Shi39ef2612014-11-29 20:35:19 -0700293public:
294 static constexpr int
295 getTypeId()
296 {
297 return 10;
298 }
Junxiao Shie349ea12014-03-12 01:32:42 -0700299};
300
301BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
302{
Junxiao Shie349ea12014-03-12 01:32:42 -0700303 Measurements& measurements = forwarder.getMeasurements();
304
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000305 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700306 // { '/'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000307 measurements.get("/").insertStrategyInfo<PStrategyInfo>();
308 measurements.get("/A").insertStrategyInfo<PStrategyInfo>();
309 measurements.get("/A/B").insertStrategyInfo<PStrategyInfo>();
310 measurements.get("/A/C").insertStrategyInfo<PStrategyInfo>();
Junxiao Shie349ea12014-03-12 01:32:42 -0700311
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000312 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700313 // { '/'=>P, '/A/B'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000314 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
315 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000316 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000317 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700318
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000319 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shie349ea12014-03-12 01:32:42 -0700320 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000321 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
322 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000323 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000324 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700325
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000326 sc.erase("/A/B");
Junxiao Shie349ea12014-03-12 01:32:42 -0700327 // { '/'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000328 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
329 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
330 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() == nullptr);
331 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700332}
333
Junxiao Shi4370fde2016-02-24 12:20:46 -0700334BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
335BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shibb5105f2014-03-03 12:06:45 -0700336
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400337} // namespace nfd::tests