blob: 04389548ad3b48afaf4315bbc4e21a9943b81d80 [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 Pesavento8f0b8b62023-08-29 21:04:08 -04003 * Copyright (c) 2014-2023, 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 Pesavento8f0b8b62023-08-29 21:04:08 -040032#include <ndn-cxx/util/concepts.hpp>
33
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034namespace nfd::tests {
Junxiao Shibb5105f2014-03-03 12:06:45 -070035
Davide Pesavento8f0b8b62023-08-29 21:04:08 -040036NDN_CXX_ASSERT_FORWARD_ITERATOR(StrategyChoice::const_iterator);
37
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038class StrategyChoiceFixture : public GlobalIoFixture
Junxiao Shi18739c42016-12-22 08:03:00 +000039{
40protected:
41 StrategyChoiceFixture()
Junxiao Shi18739c42016-12-22 08:03:00 +000042 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000043 DummyStrategy::registerAs(strategyNameP);
44 DummyStrategy::registerAs(strategyNameQ);
Junxiao Shi18739c42016-12-22 08:03:00 +000045 }
46
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040047 /** \brief Insert StrategyChoice entry at \p prefix for \p instanceName.
Junxiao Shi91f6ee02016-12-29 21:44:44 +000048 * \return constructed instance name
49 */
Junxiao Shi18739c42016-12-22 08:03:00 +000050 Name
Junxiao Shi91f6ee02016-12-29 21:44:44 +000051 insertAndGet(const Name& prefix, const Name& instanceName)
Junxiao Shi18739c42016-12-22 08:03:00 +000052 {
Junxiao Shi91f6ee02016-12-29 21:44:44 +000053 BOOST_REQUIRE(sc.insert(prefix, instanceName));
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040054 auto [isFound, foundName] = sc.get(prefix);
Junxiao Shi18739c42016-12-22 08:03:00 +000055 BOOST_REQUIRE(isFound);
56 return foundName;
57 }
58
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040059 /** \brief Determine whether the effective strategy type at \p prefix is \p S.
Junxiao Shi91f6ee02016-12-29 21:44:44 +000060 * \tparam S expected strategy type
61 */
62 template<typename S>
63 bool
64 isStrategyType(const Name& prefix)
65 {
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040066 auto& effectiveStrategy = sc.findEffectiveStrategy(prefix);
Junxiao Shi91f6ee02016-12-29 21:44:44 +000067 return dynamic_cast<S*>(&effectiveStrategy) != nullptr;
68 }
69
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000070 template<typename Q>
71 Name
72 findInstanceName(const Q& query)
73 {
74 return sc.findEffectiveStrategy(query).getInstanceName();
75 }
76
Junxiao Shi18739c42016-12-22 08:03:00 +000077protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040078 FaceTable faceTable;
79 Forwarder forwarder{faceTable};
80 StrategyChoice& sc{forwarder.getStrategyChoice()};
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000081
Eric Newberry358414d2021-03-21 20:56:42 -070082 const Name strategyNameP = Name("/strategy-choice-P").appendVersion(0);
83 const Name strategyNameQ = Name("/strategy-choice-Q").appendVersion(0);
Junxiao Shi18739c42016-12-22 08:03:00 +000084};
85
Junxiao Shi4370fde2016-02-24 12:20:46 -070086BOOST_AUTO_TEST_SUITE(Table)
Junxiao Shi18739c42016-12-22 08:03:00 +000087BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture)
Junxiao Shibb5105f2014-03-03 12:06:45 -070088
Junxiao Shi7f566dd2016-12-27 02:28:31 +000089BOOST_AUTO_TEST_CASE(Versioning)
90{
Eric Newberry358414d2021-03-21 20:56:42 -070091 const auto strategyNameV = Name("/strategy-choice-V");
92 const auto strategyNameV0 = Name("/strategy-choice-V").appendVersion(0);
93 const auto strategyNameV1 = Name("/strategy-choice-V").appendVersion(1);
94 const auto strategyNameV2 = Name("/strategy-choice-V").appendVersion(2);
95 const auto strategyNameV3 = Name("/strategy-choice-V").appendVersion(3);
96 const auto strategyNameV4 = Name("/strategy-choice-V").appendVersion(4);
97 const auto strategyNameV5 = Name("/strategy-choice-V").appendVersion(5);
Junxiao Shi7f566dd2016-12-27 02:28:31 +000098
99 VersionedDummyStrategy<1>::registerAs(strategyNameV1);
100 VersionedDummyStrategy<3>::registerAs(strategyNameV3);
101 VersionedDummyStrategy<4>::registerAs(strategyNameV4);
102
103 // unversioned: choose latest version
104 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameV), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000105 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/A"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000106
107 // exact version: choose same version
108 BOOST_CHECK_EQUAL(this->insertAndGet("/B", strategyNameV1), strategyNameV1);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000109 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/B"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000110 BOOST_CHECK_EQUAL(this->insertAndGet("/C", strategyNameV3), strategyNameV3);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000111 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/C"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000112 BOOST_CHECK_EQUAL(this->insertAndGet("/D", strategyNameV4), strategyNameV4);
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000113 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/D"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000114
115 // lower version: choose next higher version
Junxiao Shi91f6ee02016-12-29 21:44:44 +0000116 BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV0);
117 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/E"));
118 BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV2);
119 BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/F"));
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000120
121 // higher version: failure
Junxiao Shi530cf002017-01-03 14:43:16 +0000122 StrategyChoice::InsertResult res5 = sc.insert("/G", strategyNameV5);
123 BOOST_CHECK(!res5);
124 BOOST_CHECK(!res5.isRegistered());
Junxiao Shi7f566dd2016-12-27 02:28:31 +0000125}
126
Junxiao Shi18739c42016-12-22 08:03:00 +0000127BOOST_AUTO_TEST_CASE(Parameters)
128{
Junxiao Shi18739c42016-12-22 08:03:00 +0000129 // no parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000130 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameP), strategyNameP);
Junxiao Shi18739c42016-12-22 08:03:00 +0000131
132 // one parameter
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000133 Name oneParamName = Name(strategyNameP).append("param");
Junxiao Shi18739c42016-12-22 08:03:00 +0000134 BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName);
135
136 // two parameters
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000137 Name twoParamName = Name(strategyNameP).append("x").append("y");
Junxiao Shi18739c42016-12-22 08:03:00 +0000138 BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName);
139
140 // parameter without version is disallowed
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000141 Name oneParamUnversioned = strategyNameP.getPrefix(-1).append("param");
Junxiao Shi530cf002017-01-03 14:43:16 +0000142 BOOST_CHECK(!sc.insert("/D", oneParamUnversioned));
Junxiao Shi18739c42016-12-22 08:03:00 +0000143}
144
Junxiao Shi4e837f82017-10-02 22:14:43 +0000145BOOST_AUTO_TEST_CASE(InsertLongName)
146{
147 Name n1;
148 while (n1.size() < NameTree::getMaxDepth()) {
149 n1.append("A");
150 }
151 Name n2 = n1;
152 while (n2.size() < NameTree::getMaxDepth() * 2) {
153 n2.append("B");
154 }
155
156 BOOST_CHECK(sc.insert(n1, strategyNameP));
157 BOOST_CHECK(!sc.insert(n2, strategyNameP));
158}
159
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600160BOOST_AUTO_TEST_CASE(Get)
161{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000162 BOOST_CHECK(sc.insert("/", strategyNameP));
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600163 // { '/'=>P }
164
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000165 auto getRoot = sc.get("/");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700166 BOOST_CHECK_EQUAL(getRoot.first, true);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000167 BOOST_CHECK_EQUAL(getRoot.second, strategyNameP);
Junxiao Shi838c4f12014-11-03 18:55:24 -0700168
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000169 auto getA = sc.get("/A");
Junxiao Shi838c4f12014-11-03 18:55:24 -0700170 BOOST_CHECK_EQUAL(getA.first, false);
Steve DiBenedetto77c87512014-10-06 14:18:22 -0600171}
172
Junxiao Shi4370fde2016-02-24 12:20:46 -0700173BOOST_AUTO_TEST_CASE(FindEffectiveStrategy)
Junxiao Shibb5105f2014-03-03 12:06:45 -0700174{
Eric Newberry358414d2021-03-21 20:56:42 -0700175 const auto strategyNameZ = Name("/strategy-choice-Z").appendVersion(0); // unregistered strategyName
Junxiao Shibb5105f2014-03-03 12:06:45 -0700176
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000177 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700178 // { '/'=>P }
179
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000180 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
181 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
182 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700183
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000184 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700185 // { '/'=>P, '/A/B'=>P }
186
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000187 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
188 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
189 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
190 // same entry, same instance
191 BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A"));
192 // different entries, distinct instances
193 BOOST_CHECK_NE(&sc.findEffectiveStrategy("/"), &sc.findEffectiveStrategy("/A/B"));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700194
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000195 sc.erase("/A"); // no effect
Junxiao Shibb5105f2014-03-03 12:06:45 -0700196 // { '/'=>P, '/A/B'=>P }
197
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000198 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
199 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
200 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700201
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000202 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700203 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
204
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000205 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
206 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
207 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700208
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000209 sc.erase("/A/B");
Junxiao Shibb5105f2014-03-03 12:06:45 -0700210 // { '/'=>P, '/A'=>Q }
211
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000212 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameP);
213 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameQ);
214 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700215
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000216 BOOST_CHECK(!sc.insert("/", strategyNameZ)); // non existent strategy
Junxiao Shibb5105f2014-03-03 12:06:45 -0700217
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000218 BOOST_CHECK(sc.insert("/", strategyNameQ));
219 BOOST_CHECK(sc.insert("/A", strategyNameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700220 // { '/'=>Q, '/A'=>P }
221
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000222 BOOST_CHECK_EQUAL(this->findInstanceName("/"), strategyNameQ);
223 BOOST_CHECK_EQUAL(this->findInstanceName("/A"), strategyNameP);
224 BOOST_CHECK_EQUAL(this->findInstanceName("/A/B"), strategyNameP);
225 BOOST_CHECK_EQUAL(this->findInstanceName("/D"), strategyNameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700226}
227
Junxiao Shi4370fde2016-02-24 12:20:46 -0700228BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry)
229{
Junxiao Shi4370fde2016-02-24 12:20:46 -0700230 shared_ptr<Data> dataABC = makeData("/A/B/C");
231 Name fullName = dataABC->getFullName();
232
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000233 BOOST_CHECK(sc.insert("/A", strategyNameP));
234 BOOST_CHECK(sc.insert(fullName, strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700235
236 Pit& pit = forwarder.getPit();
237 shared_ptr<Interest> interestAB = makeInterest("/A/B");
238 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
239 shared_ptr<Interest> interestFull = makeInterest(fullName);
240 shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first;
241
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000242 BOOST_CHECK_EQUAL(this->findInstanceName(*pitAB), strategyNameP);
243 BOOST_CHECK_EQUAL(this->findInstanceName(*pitFull), strategyNameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700244}
245
246BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry)
247{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000248 BOOST_CHECK(sc.insert("/A", strategyNameP));
249 BOOST_CHECK(sc.insert("/A/B/C", strategyNameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700250
251 Measurements& measurements = forwarder.getMeasurements();
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000252 measurements::Entry& mAB = measurements.get("/A/B");
253 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700254
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000255 BOOST_CHECK_EQUAL(this->findInstanceName(mAB), strategyNameP);
256 BOOST_CHECK_EQUAL(this->findInstanceName(mABCD), strategyNameQ);
257}
258
259BOOST_AUTO_TEST_CASE(Erase)
260{
261 NameTree& nameTree = forwarder.getNameTree();
262
263 sc.insert("/", strategyNameP);
264
265 size_t nNameTreeEntriesBefore = nameTree.size();
266
267 sc.insert("/A/B", strategyNameQ);
268 sc.erase("/A/B");
269 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700270}
271
Junxiao Shib5888d22014-05-26 07:35:22 -0700272BOOST_AUTO_TEST_CASE(Enumerate)
273{
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000274 sc.insert("/", strategyNameP);
275 sc.insert("/A/B", strategyNameQ);
276 sc.insert("/A/B/C", strategyNameP);
277 sc.insert("/D", strategyNameP);
278 sc.insert("/E", strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700279
Junxiao Shi18739c42016-12-22 08:03:00 +0000280 BOOST_CHECK_EQUAL(sc.size(), 5);
Junxiao Shib5888d22014-05-26 07:35:22 -0700281
282 std::map<Name, Name> map; // namespace=>strategyName
Junxiao Shi18739c42016-12-22 08:03:00 +0000283 for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) {
Junxiao Shi4cb74312016-12-25 20:48:47 +0000284 map[it->getPrefix()] = it->getStrategyInstanceName();
Junxiao Shib5888d22014-05-26 07:35:22 -0700285 }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000286
287 BOOST_CHECK_EQUAL(map.at("/"), strategyNameP);
288 BOOST_CHECK_EQUAL(map.at("/A/B"), strategyNameQ);
289 BOOST_CHECK_EQUAL(map.at("/A/B/C"), strategyNameP);
290 BOOST_CHECK_EQUAL(map.at("/D"), strategyNameP);
291 BOOST_CHECK_EQUAL(map.at("/E"), strategyNameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700292 BOOST_CHECK_EQUAL(map.size(), 5);
293}
294
Junxiao Shie349ea12014-03-12 01:32:42 -0700295class PStrategyInfo : public fw::StrategyInfo
296{
Junxiao Shi39ef2612014-11-29 20:35:19 -0700297public:
298 static constexpr int
299 getTypeId()
300 {
301 return 10;
302 }
Junxiao Shie349ea12014-03-12 01:32:42 -0700303};
304
305BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
306{
Junxiao Shie349ea12014-03-12 01:32:42 -0700307 Measurements& measurements = forwarder.getMeasurements();
308
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000309 BOOST_CHECK(sc.insert("/", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700310 // { '/'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000311 measurements.get("/").insertStrategyInfo<PStrategyInfo>();
312 measurements.get("/A").insertStrategyInfo<PStrategyInfo>();
313 measurements.get("/A/B").insertStrategyInfo<PStrategyInfo>();
314 measurements.get("/A/C").insertStrategyInfo<PStrategyInfo>();
Junxiao Shie349ea12014-03-12 01:32:42 -0700315
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000316 BOOST_CHECK(sc.insert("/A/B", strategyNameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700317 // { '/'=>P, '/A/B'=>P }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000318 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
319 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000320 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000321 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700322
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000323 BOOST_CHECK(sc.insert("/A", strategyNameQ));
Junxiao Shie349ea12014-03-12 01:32:42 -0700324 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000325 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
326 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shi55e21b92017-01-23 03:27:47 +0000327 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000328 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700329
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000330 sc.erase("/A/B");
Junxiao Shie349ea12014-03-12 01:32:42 -0700331 // { '/'=>P, '/A'=>Q }
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000332 BOOST_CHECK(measurements.get("/").getStrategyInfo<PStrategyInfo>() != nullptr);
333 BOOST_CHECK(measurements.get("/A").getStrategyInfo<PStrategyInfo>() == nullptr);
334 BOOST_CHECK(measurements.get("/A/B").getStrategyInfo<PStrategyInfo>() == nullptr);
335 BOOST_CHECK(measurements.get("/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700336}
337
Junxiao Shi4370fde2016-02-24 12:20:46 -0700338BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
339BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shibb5105f2014-03-03 12:06:45 -0700340
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400341} // namespace nfd::tests