blob: a9042a98f4f559412f5fcdc4814469c1bdef5fce [file] [log] [blame]
Junxiao Shibb5105f2014-03-03 12:06:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi4370fde2016-02-24 12:20:46 -07003 * Copyright (c) 2014-2016, 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"
Junxiao Shia49a1ab2016-07-15 18:24:36 +000029#include "../fw/dummy-strategy.hpp"
30#include "../fw/install-strategy.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070031
32namespace nfd {
33namespace tests {
34
Junxiao Shi18739c42016-12-22 08:03:00 +000035class StrategyChoiceFixture : public BaseFixture
36{
37protected:
38 StrategyChoiceFixture()
39 : sc(forwarder.getStrategyChoice())
40 {
41 }
42
43 Name
44 insertAndGet(const Name& prefix, const Name& strategyName)
45 {
46 BOOST_REQUIRE(sc.insert(prefix, strategyName));
47 bool isFound;
48 Name foundName;
49 std::tie(isFound, foundName) = sc.get(prefix);
50 BOOST_REQUIRE(isFound);
51 return foundName;
52 }
53
54protected:
55 Forwarder forwarder;
56 StrategyChoice& sc;
57};
58
Junxiao Shi4370fde2016-02-24 12:20:46 -070059BOOST_AUTO_TEST_SUITE(Table)
Junxiao Shi18739c42016-12-22 08:03:00 +000060BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture)
Junxiao Shibb5105f2014-03-03 12:06:45 -070061
62using fw::Strategy;
63
Junxiao Shi18739c42016-12-22 08:03:00 +000064BOOST_AUTO_TEST_CASE(Parameters)
65{
66 const Name strategyName("/strategy-choice-test-parameters/%FD%01");
67 DummyStrategy::registerAs(strategyName);
68
69 // no parameters
70 BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyName), strategyName);
71
72 // one parameter
73 Name oneParamName = Name(strategyName).append("param");
74 BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName);
75
76 // two parameters
77 Name twoParamName = Name(strategyName).append("x").append("y");
78 BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName);
79
80 // parameter without version is disallowed
81 Name oneParamUnversioned = strategyName.getPrefix(-1).append("param");
82 BOOST_CHECK_EQUAL(sc.insert("/D", oneParamUnversioned), false);
83}
84
Steve DiBenedetto77c87512014-10-06 14:18:22 -060085BOOST_AUTO_TEST_CASE(Get)
86{
Steve DiBenedetto77c87512014-10-06 14:18:22 -060087 Name nameP("ndn:/strategy/P");
Junxiao Shia49a1ab2016-07-15 18:24:36 +000088 install<DummyStrategy>(forwarder, nameP);
Steve DiBenedetto77c87512014-10-06 14:18:22 -060089
Junxiao Shi18739c42016-12-22 08:03:00 +000090 BOOST_CHECK(sc.insert("ndn:/", nameP));
Steve DiBenedetto77c87512014-10-06 14:18:22 -060091 // { '/'=>P }
92
Junxiao Shi18739c42016-12-22 08:03:00 +000093 auto getRoot = sc.get("ndn:/");
Junxiao Shi838c4f12014-11-03 18:55:24 -070094 BOOST_CHECK_EQUAL(getRoot.first, true);
95 BOOST_CHECK_EQUAL(getRoot.second, nameP);
96
Junxiao Shi18739c42016-12-22 08:03:00 +000097 auto getA = sc.get("ndn:/A");
Junxiao Shi838c4f12014-11-03 18:55:24 -070098 BOOST_CHECK_EQUAL(getA.first, false);
Steve DiBenedetto77c87512014-10-06 14:18:22 -060099}
100
Junxiao Shi4370fde2016-02-24 12:20:46 -0700101BOOST_AUTO_TEST_CASE(FindEffectiveStrategy)
Junxiao Shibb5105f2014-03-03 12:06:45 -0700102{
Junxiao Shibb5105f2014-03-03 12:06:45 -0700103 Name nameP("ndn:/strategy/P");
104 Name nameQ("ndn:/strategy/Q");
105 Name nameZ("ndn:/strategy/Z");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000106 install<DummyStrategy>(forwarder, nameP);
107 install<DummyStrategy>(forwarder, nameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700108
Junxiao Shi18739c42016-12-22 08:03:00 +0000109 BOOST_CHECK(sc.insert("ndn:/", nameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700110 // { '/'=>P }
111
Junxiao Shi18739c42016-12-22 08:03:00 +0000112 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP);
113 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP);
114 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700115
Junxiao Shi18739c42016-12-22 08:03:00 +0000116 BOOST_CHECK(sc.insert("ndn:/A/B", nameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700117 // { '/'=>P, '/A/B'=>P }
118
Junxiao Shi18739c42016-12-22 08:03:00 +0000119 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP);
120 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP);
121 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700122 // same instance
Junxiao Shi18739c42016-12-22 08:03:00 +0000123 BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("ndn:/"),
124 &sc.findEffectiveStrategy("ndn:/A/B"));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700125
Junxiao Shi18739c42016-12-22 08:03:00 +0000126 sc.erase("ndn:/A"); // no effect
Junxiao Shibb5105f2014-03-03 12:06:45 -0700127 // { '/'=>P, '/A/B'=>P }
128
Junxiao Shi18739c42016-12-22 08:03:00 +0000129 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP);
130 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP);
131 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700132
Junxiao Shi18739c42016-12-22 08:03:00 +0000133 BOOST_CHECK(sc.insert("ndn:/A", nameQ));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700134 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
135
Junxiao Shi18739c42016-12-22 08:03:00 +0000136 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP);
137 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameQ);
138 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700139
Junxiao Shi18739c42016-12-22 08:03:00 +0000140 sc.erase("ndn:/A/B");
Junxiao Shibb5105f2014-03-03 12:06:45 -0700141 // { '/'=>P, '/A'=>Q }
142
Junxiao Shi18739c42016-12-22 08:03:00 +0000143 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP);
144 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameQ);
145 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700146
Junxiao Shi18739c42016-12-22 08:03:00 +0000147 BOOST_CHECK(!sc.insert("ndn:/", nameZ)); // non existent strategy
Junxiao Shibb5105f2014-03-03 12:06:45 -0700148
Junxiao Shi18739c42016-12-22 08:03:00 +0000149 BOOST_CHECK(sc.insert("ndn:/", nameQ));
150 BOOST_CHECK(sc.insert("ndn:/A", nameP));
Junxiao Shibb5105f2014-03-03 12:06:45 -0700151 // { '/'=>Q, '/A'=>P }
152
Junxiao Shi18739c42016-12-22 08:03:00 +0000153 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameQ);
154 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP);
155 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP);
156 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/D") .getName(), nameQ);
Junxiao Shibb5105f2014-03-03 12:06:45 -0700157}
158
Junxiao Shi4370fde2016-02-24 12:20:46 -0700159BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry)
160{
Junxiao Shi4370fde2016-02-24 12:20:46 -0700161 Name nameP("ndn:/strategy/P");
162 Name nameQ("ndn:/strategy/Q");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000163 install<DummyStrategy>(forwarder, nameP);
164 install<DummyStrategy>(forwarder, nameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700165
166 shared_ptr<Data> dataABC = makeData("/A/B/C");
167 Name fullName = dataABC->getFullName();
168
Junxiao Shi18739c42016-12-22 08:03:00 +0000169 BOOST_CHECK(sc.insert("/A", nameP));
170 BOOST_CHECK(sc.insert(fullName, nameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700171
172 Pit& pit = forwarder.getPit();
173 shared_ptr<Interest> interestAB = makeInterest("/A/B");
174 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
175 shared_ptr<Interest> interestFull = makeInterest(fullName);
176 shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first;
177
Junxiao Shi18739c42016-12-22 08:03:00 +0000178 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(*pitAB).getName(), nameP);
179 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(*pitFull).getName(), nameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700180}
181
182BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry)
183{
Junxiao Shi4370fde2016-02-24 12:20:46 -0700184 Name nameP("ndn:/strategy/P");
185 Name nameQ("ndn:/strategy/Q");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000186 install<DummyStrategy>(forwarder, nameP);
187 install<DummyStrategy>(forwarder, nameQ);
188
Junxiao Shi18739c42016-12-22 08:03:00 +0000189 BOOST_CHECK(sc.insert("/A", nameP));
190 BOOST_CHECK(sc.insert("/A/B/C", nameQ));
Junxiao Shi4370fde2016-02-24 12:20:46 -0700191
192 Measurements& measurements = forwarder.getMeasurements();
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000193 measurements::Entry& mAB = measurements.get("/A/B");
194 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700195
Junxiao Shi18739c42016-12-22 08:03:00 +0000196 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(mAB).getName(), nameP);
197 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(mABCD).getName(), nameQ);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700198}
199
Junxiao Shib5888d22014-05-26 07:35:22 -0700200//XXX BOOST_CONCEPT_ASSERT((ForwardIterator<std::vector<int>::iterator>))
201// is also failing. There might be a problem with ForwardIterator concept checking.
202//BOOST_CONCEPT_ASSERT((ForwardIterator<StrategyChoice::const_iterator>));
203
204BOOST_AUTO_TEST_CASE(Enumerate)
205{
Junxiao Shib5888d22014-05-26 07:35:22 -0700206 Name nameP("ndn:/strategy/P");
207 Name nameQ("ndn:/strategy/Q");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000208 install<DummyStrategy>(forwarder, nameP);
209 install<DummyStrategy>(forwarder, nameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700210
Junxiao Shi18739c42016-12-22 08:03:00 +0000211 sc.insert("ndn:/", nameP);
212 sc.insert("ndn:/A/B", nameQ);
213 sc.insert("ndn:/A/B/C", nameP);
214 sc.insert("ndn:/D", nameP);
215 sc.insert("ndn:/E", nameQ);
Junxiao Shib5888d22014-05-26 07:35:22 -0700216
Junxiao Shi18739c42016-12-22 08:03:00 +0000217 BOOST_CHECK_EQUAL(sc.size(), 5);
Junxiao Shib5888d22014-05-26 07:35:22 -0700218
219 std::map<Name, Name> map; // namespace=>strategyName
Junxiao Shi18739c42016-12-22 08:03:00 +0000220 for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) {
Junxiao Shib5888d22014-05-26 07:35:22 -0700221 map[it->getPrefix()] = it->getStrategyName();
222 }
223 BOOST_CHECK_EQUAL(map.size(), 5);
224 BOOST_CHECK_EQUAL(map["ndn:/"], nameP);
225 BOOST_CHECK_EQUAL(map["ndn:/A/B"], nameQ);
226 BOOST_CHECK_EQUAL(map["ndn:/A/B/C"], nameP);
227 BOOST_CHECK_EQUAL(map["ndn:/D"], nameP);
228 BOOST_CHECK_EQUAL(map["ndn:/E"], nameQ);
229 BOOST_CHECK_EQUAL(map.size(), 5);
230}
231
Junxiao Shie349ea12014-03-12 01:32:42 -0700232class PStrategyInfo : public fw::StrategyInfo
233{
Junxiao Shi39ef2612014-11-29 20:35:19 -0700234public:
235 static constexpr int
236 getTypeId()
237 {
238 return 10;
239 }
Junxiao Shie349ea12014-03-12 01:32:42 -0700240};
241
242BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
243{
Junxiao Shie349ea12014-03-12 01:32:42 -0700244 Name nameP("ndn:/strategy/P");
245 Name nameQ("ndn:/strategy/Q");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000246 install<DummyStrategy>(forwarder, nameP);
247 install<DummyStrategy>(forwarder, nameQ);
Junxiao Shie349ea12014-03-12 01:32:42 -0700248
Junxiao Shie349ea12014-03-12 01:32:42 -0700249 Measurements& measurements = forwarder.getMeasurements();
250
Junxiao Shi18739c42016-12-22 08:03:00 +0000251 BOOST_CHECK(sc.insert("ndn:/", nameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700252 // { '/'=>P }
Junxiao Shi5b3feb62016-08-19 01:51:41 +0000253 measurements.get("ndn:/").insertStrategyInfo<PStrategyInfo>();
254 measurements.get("ndn:/A").insertStrategyInfo<PStrategyInfo>();
255 measurements.get("ndn:/A/B").insertStrategyInfo<PStrategyInfo>();
256 measurements.get("ndn:/A/C").insertStrategyInfo<PStrategyInfo>();
Junxiao Shie349ea12014-03-12 01:32:42 -0700257
Junxiao Shi18739c42016-12-22 08:03:00 +0000258 BOOST_CHECK(sc.insert("ndn:/A/B", nameP));
Junxiao Shie349ea12014-03-12 01:32:42 -0700259 // { '/'=>P, '/A/B'=>P }
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000260 BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
261 BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() != nullptr);
262 BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
263 BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() != nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700264
Junxiao Shi18739c42016-12-22 08:03:00 +0000265 BOOST_CHECK(sc.insert("ndn:/A", nameQ));
Junxiao Shie349ea12014-03-12 01:32:42 -0700266 // { '/'=>P, '/A/B'=>P, '/A'=>Q }
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000267 BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
268 BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr);
269 BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr);
270 BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700271
Junxiao Shi18739c42016-12-22 08:03:00 +0000272 sc.erase("ndn:/A/B");
Junxiao Shie349ea12014-03-12 01:32:42 -0700273 // { '/'=>P, '/A'=>Q }
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000274 BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr);
275 BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr);
276 BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() == nullptr);
277 BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr);
Junxiao Shie349ea12014-03-12 01:32:42 -0700278}
279
Junxiao Shiee5a4442014-07-27 17:13:43 -0700280BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
281{
Junxiao Shiee5a4442014-07-27 17:13:43 -0700282 Name nameP("ndn:/strategy/P");
283 Name nameQ("ndn:/strategy/Q");
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000284 install<DummyStrategy>(forwarder, nameP);
285 install<DummyStrategy>(forwarder, nameQ);
286
287 NameTree& nameTree = forwarder.getNameTree();
Junxiao Shiee5a4442014-07-27 17:13:43 -0700288
Junxiao Shi18739c42016-12-22 08:03:00 +0000289 sc.insert("ndn:/", nameP);
Junxiao Shiee5a4442014-07-27 17:13:43 -0700290
291 size_t nNameTreeEntriesBefore = nameTree.size();
292
Junxiao Shi18739c42016-12-22 08:03:00 +0000293 sc.insert("ndn:/A/B", nameQ);
294 sc.erase("ndn:/A/B");
Junxiao Shiee5a4442014-07-27 17:13:43 -0700295 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
296}
297
Junxiao Shie93d6a32014-09-07 16:13:22 -0700298BOOST_AUTO_TEST_CASE(Versioning)
299{
300 Forwarder forwarder;
301 Name nameP("ndn:/strategy/P");
302 Name nameP1("ndn:/strategy/P/%FD%01");
303 Name nameP2("ndn:/strategy/P/%FD%02");
304 Name name3("ndn:/%FD%03");
305 Name name4("ndn:/%FD%04");
306 Name nameQ("ndn:/strategy/Q");
307 Name nameQ5("ndn:/strategy/Q/%FD%05");
Junxiao Shie93d6a32014-09-07 16:13:22 -0700308
Junxiao Shie93d6a32014-09-07 16:13:22 -0700309 // install
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000310 auto strategyP1 = make_unique<DummyStrategy>(ref(forwarder), nameP1);
311 Strategy* instanceP1 = strategyP1.get();
312 auto strategyP1b = make_unique<DummyStrategy>(ref(forwarder), nameP1);
313 auto strategyP2 = make_unique<DummyStrategy>(ref(forwarder), nameP2);
314 auto strategy3 = make_unique<DummyStrategy>(ref(forwarder), name3);
315 auto strategy4 = make_unique<DummyStrategy>(ref(forwarder), name4);
316 auto strategyQ = make_unique<DummyStrategy>(ref(forwarder), nameQ);
317 auto strategyQ5 = make_unique<DummyStrategy>(ref(forwarder), nameQ5);
318
319 bool isInstalled = false;
320 Strategy* installed = nullptr;
321
Junxiao Shi18739c42016-12-22 08:03:00 +0000322 std::tie(isInstalled, installed) = sc.install(std::move(strategyP1));
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000323 BOOST_CHECK_EQUAL(isInstalled, true);
324 BOOST_CHECK_EQUAL(installed, instanceP1);
Junxiao Shi18739c42016-12-22 08:03:00 +0000325 std::tie(isInstalled, installed) = sc.install(std::move(strategyP1b));
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000326 BOOST_CHECK_EQUAL(isInstalled, false);
327 BOOST_CHECK_EQUAL(installed, instanceP1);
328
Junxiao Shi18739c42016-12-22 08:03:00 +0000329 BOOST_CHECK_EQUAL(sc.hasStrategy(nameP, false), true);
330 BOOST_CHECK_EQUAL(sc.hasStrategy(nameP, true), false);
331 BOOST_CHECK_EQUAL(sc.hasStrategy(nameP1, true), true);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700332
Junxiao Shi18739c42016-12-22 08:03:00 +0000333 BOOST_CHECK_EQUAL(sc.install(std::move(strategyP2)).first, true);
334 BOOST_CHECK_EQUAL(sc.install(std::move(strategy3)).first, true);
335 BOOST_CHECK_EQUAL(sc.install(std::move(strategy4)).first, true);
336 BOOST_CHECK_EQUAL(sc.install(std::move(strategyQ)).first, true);
337 BOOST_CHECK_EQUAL(sc.install(std::move(strategyQ5)).first, true);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700338
Junxiao Shi18739c42016-12-22 08:03:00 +0000339 BOOST_CHECK(sc.insert("ndn:/", nameQ));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700340 // exact match, { '/'=>Q }
Junxiao Shi18739c42016-12-22 08:03:00 +0000341 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700342
Junxiao Shi18739c42016-12-22 08:03:00 +0000343 BOOST_CHECK(sc.insert("ndn:/", nameQ));
344 BOOST_CHECK(sc.insert("ndn:/", nameP));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700345 // { '/'=>P2 }
Junxiao Shi18739c42016-12-22 08:03:00 +0000346 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP2);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700347
Junxiao Shi18739c42016-12-22 08:03:00 +0000348 BOOST_CHECK(sc.insert("ndn:/", nameQ));
349 BOOST_CHECK(sc.insert("ndn:/", nameP1));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700350 // { '/'=>P1 }
Junxiao Shi18739c42016-12-22 08:03:00 +0000351 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP1);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700352
Junxiao Shi18739c42016-12-22 08:03:00 +0000353 BOOST_CHECK(sc.insert("ndn:/", nameQ));
354 BOOST_CHECK(sc.insert("ndn:/", nameP2));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700355 // { '/'=>P2 }
Junxiao Shi18739c42016-12-22 08:03:00 +0000356 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP2);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700357
Junxiao Shi18739c42016-12-22 08:03:00 +0000358 BOOST_CHECK(sc.insert("ndn:/", nameQ));
359 BOOST_CHECK(! sc.insert("ndn:/", "ndn:/strategy/A"));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700360 // not installed
Junxiao Shi18739c42016-12-22 08:03:00 +0000361 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700362
Junxiao Shi18739c42016-12-22 08:03:00 +0000363 BOOST_CHECK(sc.insert("ndn:/", nameQ));
364 BOOST_CHECK(! sc.insert("ndn:/", "ndn:/strategy/Z"));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700365 // not installed
Junxiao Shi18739c42016-12-22 08:03:00 +0000366 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700367
Junxiao Shi18739c42016-12-22 08:03:00 +0000368 BOOST_CHECK(sc.insert("ndn:/", nameP1));
369 BOOST_CHECK(sc.insert("ndn:/", "ndn:/"));
Junxiao Shie93d6a32014-09-07 16:13:22 -0700370 // match one component longer only, { '/'=>4 }
Junxiao Shi18739c42016-12-22 08:03:00 +0000371 BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), name4);
Junxiao Shie93d6a32014-09-07 16:13:22 -0700372}
373
Junxiao Shi4370fde2016-02-24 12:20:46 -0700374BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice
375BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shibb5105f2014-03-03 12:06:45 -0700376
377} // namespace tests
378} // namespace nfd