Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California, |
| 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 | |
| 26 | #include "mgmt/tables-config-section.hpp" |
| 27 | #include "fw/forwarder.hpp" |
| 28 | |
| 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
| 35 | class TablesConfigSectionFixture : protected BaseFixture |
| 36 | { |
| 37 | public: |
| 38 | |
| 39 | TablesConfigSectionFixture() |
| 40 | : m_cs(m_forwarder.getCs()) |
| 41 | , m_pit(m_forwarder.getPit()) |
| 42 | , m_fib(m_forwarder.getFib()) |
| 43 | , m_strategyChoice(m_forwarder.getStrategyChoice()) |
| 44 | , m_measurements(m_forwarder.getMeasurements()) |
| 45 | , m_tablesConfig(m_cs, m_pit, m_fib, m_strategyChoice, m_measurements) |
| 46 | { |
| 47 | m_tablesConfig.setConfigFile(m_config); |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | runConfig(const std::string& CONFIG, bool isDryRun) |
| 52 | { |
| 53 | m_config.parse(CONFIG, isDryRun, "dummy-config"); |
| 54 | } |
| 55 | |
| 56 | bool |
| 57 | validateException(const ConfigFile::Error& exception, const std::string& expectedMsg) |
| 58 | { |
| 59 | return exception.what() == expectedMsg; |
| 60 | } |
| 61 | |
| 62 | protected: |
| 63 | Forwarder m_forwarder; |
| 64 | |
| 65 | Cs& m_cs; |
| 66 | Pit& m_pit; |
| 67 | Fib& m_fib; |
| 68 | StrategyChoice& m_strategyChoice; |
| 69 | Measurements& m_measurements; |
| 70 | |
| 71 | TablesConfigSection m_tablesConfig; |
| 72 | ConfigFile m_config; |
| 73 | |
| 74 | }; |
| 75 | |
| 76 | BOOST_FIXTURE_TEST_SUITE(TestTableConfigSection, TablesConfigSectionFixture) |
| 77 | |
| 78 | BOOST_AUTO_TEST_CASE(EmptyTablesSection) |
| 79 | { |
| 80 | const std::string CONFIG = |
| 81 | "tables\n" |
| 82 | "{\n" |
| 83 | "}\n"; |
| 84 | |
| 85 | const size_t nCsMaxPackets = m_cs.getLimit(); |
| 86 | |
| 87 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 88 | |
| 89 | BOOST_CHECK_EQUAL(m_cs.getLimit(), nCsMaxPackets); |
| 90 | |
| 91 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 92 | |
| 93 | BOOST_CHECK_EQUAL(m_cs.getLimit(), nCsMaxPackets); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(ValidCsMaxPackets) |
| 97 | { |
| 98 | const std::string CONFIG = |
| 99 | "tables\n" |
| 100 | "{\n" |
| 101 | " cs_max_packets 101\n" |
| 102 | "}\n"; |
| 103 | |
| 104 | BOOST_REQUIRE_NE(m_cs.getLimit(), 101); |
| 105 | |
| 106 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 107 | |
| 108 | BOOST_CHECK_NE(m_cs.getLimit(), 101); |
| 109 | |
| 110 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 111 | |
| 112 | BOOST_CHECK_EQUAL(m_cs.getLimit(), 101); |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE(MissingValueCsMaxPackets) |
| 116 | { |
| 117 | const std::string CONFIG = |
| 118 | "tables\n" |
| 119 | "{\n" |
| 120 | " cs_max_packets\n" |
| 121 | "}\n"; |
| 122 | |
| 123 | const std::string expectedMsg = |
| 124 | "Invalid value for option \"cs_max_packets\" in \"tables\" section"; |
| 125 | |
| 126 | BOOST_CHECK_EXCEPTION(runConfig(CONFIG, true), |
| 127 | ConfigFile::Error, |
| 128 | bind(&TablesConfigSectionFixture::validateException, |
| 129 | this, _1, expectedMsg)); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(InvalidValueCsMaxPackets) |
| 133 | { |
| 134 | const std::string CONFIG = |
| 135 | "tables\n" |
| 136 | "{\n" |
| 137 | " cs_max_packets invalid\n" |
| 138 | "}\n"; |
| 139 | |
| 140 | const std::string expectedMsg = |
| 141 | "Invalid value for option \"cs_max_packets\" in \"tables\" section"; |
| 142 | |
| 143 | BOOST_CHECK_EXCEPTION(runConfig(CONFIG, true), |
| 144 | ConfigFile::Error, |
| 145 | bind(&TablesConfigSectionFixture::validateException, |
| 146 | this, _1, expectedMsg)); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_SUITE_END() |
| 150 | |
| 151 | } // namespace tests |
| 152 | } // namespace nfd |