blob: ff6605a5b503c70183d22f0c1e856c0c2575660c [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi1f481fa2017-01-26 15:14:43 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * 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.
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/>.
24 */
25
Junxiao Shi331ade72016-08-19 14:07:19 +000026#include "nfdc/strategy-choice-module.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi5d3e4812017-04-05 16:52:59 +000028#include "execute-command-fixture.hpp"
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030
31namespace nfd {
32namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000033namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000034namespace tests {
35
Junxiao Shi331ade72016-08-19 14:07:19 +000036BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi5d3e4812017-04-05 16:52:59 +000037BOOST_AUTO_TEST_SUITE(TestStrategyChoiceModule)
38
39class StrategyListFixture : public ExecuteCommandFixture
40{
41protected:
42 bool
43 respondStrategyChoiceDataset(const Interest& interest)
44 {
45 if (!Name("/localhost/nfd/strategy-choice/list").isPrefixOf(interest.getName())) {
46 return false;
47 }
48
49 StrategyChoice entry1;
50 entry1.setName("/");
51 entry1.setStrategy("/strategyP/%FD%01");
52
53 StrategyChoice entry2;
54 entry2.setName("/52VRvpL9/Yqfut4TNHv");
55 entry2.setStrategy("/strategyQ/%FD%02");
56
57 this->sendDataset(interest.getName(), entry1, entry2);
58 return true;
59 }
60};
61
62BOOST_FIXTURE_TEST_SUITE(ListCommand, StrategyListFixture)
63
64BOOST_AUTO_TEST_CASE(Normal)
65{
66 this->processInterest = [this] (const Interest& interest) {
67 BOOST_CHECK(this->respondStrategyChoiceDataset(interest));
68 };
69
70 this->execute("strategy list");
71 BOOST_CHECK_EQUAL(exitCode, 0);
72 BOOST_CHECK(out.is_equal("prefix=/ strategy=/strategyP/%FD%01\n"
73 "prefix=/52VRvpL9/Yqfut4TNHv strategy=/strategyQ/%FD%02\n"));
74 BOOST_CHECK(err.is_empty());
75}
76
77BOOST_AUTO_TEST_CASE(ErrorDataset)
78{
79 this->processInterest = nullptr; // no response to dataset or command
80
81 this->execute("strategy list");
82 BOOST_CHECK_EQUAL(exitCode, 1);
83 BOOST_CHECK(out.is_empty());
84 BOOST_CHECK(err.is_equal("Error 10060 when fetching strategy choice dataset: Timeout\n"));
85}
86
87BOOST_AUTO_TEST_SUITE_END() // ListCommand
88
89BOOST_FIXTURE_TEST_SUITE(ShowCommand, StrategyListFixture)
90
91BOOST_AUTO_TEST_CASE(NormalDefaultStrategy)
92{
93 this->processInterest = [this] (const Interest& interest) {
94 BOOST_CHECK(this->respondStrategyChoiceDataset(interest));
95 };
96
97 this->execute("strategy show /I1Ixgg0X");
98 BOOST_CHECK_EQUAL(exitCode, 0);
99 BOOST_CHECK(out.is_equal(" prefix=/\n"
100 "strategy=/strategyP/%FD%01\n"));
101 BOOST_CHECK(err.is_empty());
102}
103
104BOOST_AUTO_TEST_CASE(NormalNonDefaultStrategy)
105{
106 this->processInterest = [this] (const Interest& interest) {
107 BOOST_CHECK(this->respondStrategyChoiceDataset(interest));
108 };
109
110 this->execute("strategy show /52VRvpL9/Yqfut4TNHv/Y5gY7gom");
111 BOOST_CHECK_EQUAL(exitCode, 0);
112 BOOST_CHECK(out.is_equal(" prefix=/52VRvpL9/Yqfut4TNHv\n"
113 "strategy=/strategyQ/%FD%02\n"));
114 BOOST_CHECK(err.is_empty());
115}
116
117BOOST_AUTO_TEST_CASE(ErrorDataset)
118{
119 this->processInterest = nullptr; // no response to dataset or command
120
121 this->execute("strategy show /xVoIhNsJ");
122 BOOST_CHECK_EQUAL(exitCode, 1);
123 BOOST_CHECK(out.is_empty());
124 BOOST_CHECK(err.is_equal("Error 10060 when fetching strategy choice dataset: Timeout\n"));
125}
126
127BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000128
129const std::string STATUS_XML = stripXmlSpaces(R"XML(
130 <strategyChoices>
131 <strategyChoice>
132 <namespace>/</namespace>
133 <strategy>
134 <name>/localhost/nfd/strategy/best-route/%FD%04</name>
135 </strategy>
136 </strategyChoice>
137 <strategyChoice>
138 <namespace>/localhost</namespace>
139 <strategy>
140 <name>/localhost/nfd/strategy/multicast/%FD%01</name>
141 </strategy>
142 </strategyChoice>
143 </strategyChoices>
144)XML");
145
146const std::string STATUS_TEXT = std::string(R"TEXT(
147Strategy choices:
Junxiao Shi5d3e4812017-04-05 16:52:59 +0000148 prefix=/ strategy=/localhost/nfd/strategy/best-route/%FD%04
149 prefix=/localhost strategy=/localhost/nfd/strategy/multicast/%FD%01
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000150)TEXT").substr(1);
151
Junxiao Shi5d3e4812017-04-05 16:52:59 +0000152BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<StrategyChoiceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000153{
154 this->fetchStatus();
155 StrategyChoice payload1;
156 payload1.setName("/")
157 .setStrategy("/localhost/nfd/strategy/best-route/%FD%04");
158 StrategyChoice payload2;
159 payload2.setName("/localhost")
160 .setStrategy("/localhost/nfd/strategy/multicast/%FD%01");
161 this->sendDataset("/localhost/nfd/strategy-choice/list", payload1, payload2);
162 this->prepareStatusOutput();
163
164 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
165 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
166}
167
168BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoiceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000169BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000170
171} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000172} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000173} // namespace tools
174} // namespace nfd