Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 4 | * 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 Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 26 | #include "nfdc/strategy-choice-module.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 27 | |
Junxiao Shi | 5d3e481 | 2017-04-05 16:52:59 +0000 | [diff] [blame] | 28 | #include "execute-command-fixture.hpp" |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 29 | #include "status-fixture.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 33 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Nfdc) |
Junxiao Shi | 5d3e481 | 2017-04-05 16:52:59 +0000 | [diff] [blame] | 37 | BOOST_AUTO_TEST_SUITE(TestStrategyChoiceModule) |
| 38 | |
| 39 | class StrategyListFixture : public ExecuteCommandFixture |
| 40 | { |
| 41 | protected: |
| 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 | |
| 62 | BOOST_FIXTURE_TEST_SUITE(ListCommand, StrategyListFixture) |
| 63 | |
| 64 | BOOST_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 | |
| 77 | BOOST_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 | |
| 87 | BOOST_AUTO_TEST_SUITE_END() // ListCommand |
| 88 | |
| 89 | BOOST_FIXTURE_TEST_SUITE(ShowCommand, StrategyListFixture) |
| 90 | |
| 91 | BOOST_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 | |
| 104 | BOOST_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 | |
| 117 | BOOST_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 | |
| 127 | BOOST_AUTO_TEST_SUITE_END() // ShowCommand |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 128 | |
| 129 | const 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 | |
| 146 | const std::string STATUS_TEXT = std::string(R"TEXT( |
| 147 | Strategy choices: |
Junxiao Shi | 5d3e481 | 2017-04-05 16:52:59 +0000 | [diff] [blame] | 148 | prefix=/ strategy=/localhost/nfd/strategy/best-route/%FD%04 |
| 149 | prefix=/localhost strategy=/localhost/nfd/strategy/multicast/%FD%01 |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 150 | )TEXT").substr(1); |
| 151 | |
Junxiao Shi | 5d3e481 | 2017-04-05 16:52:59 +0000 | [diff] [blame] | 152 | BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<StrategyChoiceModule>) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 153 | { |
| 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 | |
| 168 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoiceModule |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 169 | BOOST_AUTO_TEST_SUITE_END() // Nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 170 | |
| 171 | } // namespace tests |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 172 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 173 | } // namespace tools |
| 174 | } // namespace nfd |