Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [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. |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 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 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 30 | #include "../fw/dummy-strategy.hpp" |
| 31 | #include "../fw/install-strategy.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace tests { |
| 35 | |
| 36 | class TablesConfigSectionFixture : protected BaseFixture |
| 37 | { |
| 38 | public: |
| 39 | |
| 40 | TablesConfigSectionFixture() |
| 41 | : m_cs(m_forwarder.getCs()) |
| 42 | , m_pit(m_forwarder.getPit()) |
| 43 | , m_fib(m_forwarder.getFib()) |
| 44 | , m_strategyChoice(m_forwarder.getStrategyChoice()) |
| 45 | , m_measurements(m_forwarder.getMeasurements()) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 46 | , m_networkRegionTable(m_forwarder.getNetworkRegionTable()) |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 47 | , m_tablesConfig(m_forwarder) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 48 | { |
| 49 | m_tablesConfig.setConfigFile(m_config); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | runConfig(const std::string& CONFIG, bool isDryRun) |
| 54 | { |
| 55 | m_config.parse(CONFIG, isDryRun, "dummy-config"); |
| 56 | } |
| 57 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 58 | protected: |
| 59 | Forwarder m_forwarder; |
| 60 | |
| 61 | Cs& m_cs; |
| 62 | Pit& m_pit; |
| 63 | Fib& m_fib; |
| 64 | StrategyChoice& m_strategyChoice; |
| 65 | Measurements& m_measurements; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 66 | NetworkRegionTable& m_networkRegionTable; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 67 | |
| 68 | TablesConfigSection m_tablesConfig; |
| 69 | ConfigFile m_config; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 70 | }; |
| 71 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 72 | BOOST_FIXTURE_TEST_SUITE(Mgmt, TablesConfigSectionFixture) |
| 73 | BOOST_AUTO_TEST_SUITE(TestTablesConfigSection) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 74 | |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 75 | BOOST_AUTO_TEST_CASE(ConfigureTablesWithDefaults) |
| 76 | { |
| 77 | const size_t initialLimit = m_cs.getLimit(); |
| 78 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 79 | m_tablesConfig.ensureConfigured(); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 80 | BOOST_CHECK_NE(initialLimit, m_cs.getLimit()); |
| 81 | } |
| 82 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 83 | BOOST_AUTO_TEST_CASE(EmptyTablesSection) |
| 84 | { |
| 85 | const std::string CONFIG = |
| 86 | "tables\n" |
| 87 | "{\n" |
| 88 | "}\n"; |
| 89 | |
| 90 | const size_t nCsMaxPackets = m_cs.getLimit(); |
| 91 | |
| 92 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(m_cs.getLimit(), nCsMaxPackets); |
| 94 | |
| 95 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 96 | BOOST_CHECK_NE(m_cs.getLimit(), nCsMaxPackets); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 97 | |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 98 | const size_t defaultLimit = m_cs.getLimit(); |
| 99 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 100 | m_tablesConfig.ensureConfigured(); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(defaultLimit, m_cs.getLimit()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 102 | } |
| 103 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 104 | BOOST_AUTO_TEST_CASE(MissingTablesSection) |
| 105 | { |
| 106 | const std::string CONFIG = |
| 107 | "not_tables\n" |
| 108 | "{\n" |
| 109 | " some_other_field 0\n" |
| 110 | "}\n"; |
| 111 | |
| 112 | ConfigFile passiveConfig(&ConfigFile::ignoreUnknownSection); |
| 113 | |
| 114 | const size_t initialLimit = m_cs.getLimit(); |
| 115 | |
| 116 | passiveConfig.parse(CONFIG, true, "dummy-config"); |
| 117 | BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit()); |
| 118 | |
| 119 | passiveConfig.parse(CONFIG, false, "dummy-config"); |
| 120 | BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit()); |
| 121 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 122 | m_tablesConfig.ensureConfigured(); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 123 | BOOST_CHECK_NE(initialLimit, m_cs.getLimit()); |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_SUITE(Cs) |
| 127 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 128 | BOOST_AUTO_TEST_CASE(ValidCsMaxPackets) |
| 129 | { |
| 130 | const std::string CONFIG = |
| 131 | "tables\n" |
| 132 | "{\n" |
| 133 | " cs_max_packets 101\n" |
| 134 | "}\n"; |
| 135 | |
| 136 | BOOST_REQUIRE_NE(m_cs.getLimit(), 101); |
| 137 | |
| 138 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 139 | BOOST_CHECK_NE(m_cs.getLimit(), 101); |
| 140 | |
| 141 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 142 | BOOST_CHECK_EQUAL(m_cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 143 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 144 | m_tablesConfig.ensureConfigured(); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 145 | BOOST_CHECK_EQUAL(m_cs.getLimit(), 101); |
| 146 | } |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(MissingValueCsMaxPackets) |
| 149 | { |
| 150 | const std::string CONFIG = |
| 151 | "tables\n" |
| 152 | "{\n" |
| 153 | " cs_max_packets\n" |
| 154 | "}\n"; |
| 155 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 156 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 157 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | BOOST_AUTO_TEST_CASE(InvalidValueCsMaxPackets) |
| 161 | { |
| 162 | const std::string CONFIG = |
| 163 | "tables\n" |
| 164 | "{\n" |
| 165 | " cs_max_packets invalid\n" |
| 166 | "}\n"; |
| 167 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 168 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 169 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 170 | } |
| 171 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 172 | BOOST_AUTO_TEST_SUITE_END() // Cs |
| 173 | |
| 174 | BOOST_AUTO_TEST_SUITE(ConfigStrategy) |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 177 | { |
| 178 | const std::string CONFIG = |
| 179 | "tables\n" |
| 180 | "{\n" |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 181 | " strategy_choice\n" |
| 182 | " {\n" |
| 183 | " / /localhost/nfd/strategy/test-strategy-a\n" |
| 184 | " /a /localhost/nfd/strategy/test-strategy-b\n" |
| 185 | " }\n" |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 186 | "}\n"; |
| 187 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 188 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a"); |
| 189 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 190 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 191 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 192 | { |
| 193 | fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/"); |
| 194 | BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 195 | BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b"); |
| 196 | |
| 197 | fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a"); |
| 198 | BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b"); |
| 199 | BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 200 | } |
| 201 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 202 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 203 | { |
| 204 | fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/"); |
| 205 | BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 206 | |
| 207 | fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a"); |
| 208 | BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b"); |
| 209 | } |
| 210 | } |
| 211 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 212 | BOOST_AUTO_TEST_CASE(Versioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 213 | { |
| 214 | const std::string CONFIG = |
| 215 | "tables\n" |
| 216 | "{\n" |
| 217 | "strategy_choice\n" |
| 218 | "{\n" |
| 219 | " /test/latest /localhost/nfd/strategy/test-strategy-a\n" |
| 220 | " /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01\n" |
| 221 | "}\n" |
| 222 | "}\n"; |
| 223 | |
| 224 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 225 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01"); |
| 226 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02"); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 227 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 228 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 229 | { |
| 230 | fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest"); |
| 231 | BOOST_REQUIRE_NE(testLatestStrategy.getName(), |
| 232 | "/localhost/nfd/strategy/test-strategy-a/%FD%01"); |
| 233 | BOOST_REQUIRE_NE(testLatestStrategy.getName(), |
| 234 | "/localhost/nfd/strategy/test-strategy-a/%FD%02"); |
| 235 | |
| 236 | fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old"); |
| 237 | BOOST_REQUIRE_NE(testOldStrategy.getName(), |
| 238 | "/localhost/nfd/strategy/test-strategy-a/%FD%01"); |
| 239 | BOOST_REQUIRE_NE(testOldStrategy.getName(), |
| 240 | "/localhost/nfd/strategy/test-strategy-a/%FD%02"); |
| 241 | } |
| 242 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 243 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 244 | { |
| 245 | fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest"); |
| 246 | BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(), |
| 247 | "/localhost/nfd/strategy/test-strategy-a/%FD%02"); |
| 248 | |
| 249 | fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old"); |
| 250 | BOOST_REQUIRE_EQUAL(testOldStrategy.getName(), |
| 251 | "/localhost/nfd/strategy/test-strategy-a/%FD%01"); |
| 252 | } |
| 253 | } |
| 254 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 255 | BOOST_AUTO_TEST_CASE(NonExisting) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 256 | { |
| 257 | const std::string CONFIG = |
| 258 | "tables\n" |
| 259 | "{\n" |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 260 | " strategy_choice\n" |
| 261 | " {\n" |
| 262 | " / /localhost/nfd/strategy/test-doesnotexist\n" |
| 263 | " }\n" |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 264 | "}\n"; |
| 265 | |
| 266 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 267 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 268 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 271 | BOOST_AUTO_TEST_CASE(MissingPrefix) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 272 | { |
| 273 | const std::string CONFIG = |
| 274 | "tables\n" |
| 275 | "{\n" |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 276 | " strategy_choice\n" |
| 277 | " {\n" |
| 278 | " /localhost/nfd/strategy/test-strategy-a\n" |
| 279 | " }\n" |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 280 | "}\n"; |
| 281 | |
| 282 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 283 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a"); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 284 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 285 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 286 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 289 | BOOST_AUTO_TEST_CASE(Duplicate) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 290 | { |
| 291 | const std::string CONFIG = |
| 292 | "tables\n" |
| 293 | "{\n" |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 294 | " strategy_choice\n" |
| 295 | " {\n" |
| 296 | " / /localhost/nfd/strategy/test-strategy-a\n" |
| 297 | " /a /localhost/nfd/strategy/test-strategy-b\n" |
| 298 | " / /localhost/nfd/strategy/test-strategy-b\n" |
| 299 | " }\n" |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 300 | "}\n"; |
| 301 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 302 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a"); |
| 303 | install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 304 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 305 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 306 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 309 | BOOST_AUTO_TEST_SUITE_END() // StrategyChoice |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 310 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 311 | BOOST_AUTO_TEST_SUITE(NetworkRegion) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 312 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 313 | BOOST_AUTO_TEST_CASE(Basic) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 314 | { |
| 315 | const std::string CONFIG = |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 316 | "tables\n" |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 317 | "{\n" |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 318 | " network_region\n" |
| 319 | " {\n" |
| 320 | " /test/regionA\n" |
| 321 | " /test/regionB/component\n" |
| 322 | " }\n" |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 323 | "}\n"; |
| 324 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 325 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 326 | BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 0); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 327 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 328 | BOOST_CHECK(m_networkRegionTable.find("/test/regionA") == m_networkRegionTable.end()); |
| 329 | BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") == m_networkRegionTable.end()); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 330 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 331 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 332 | BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 2); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 333 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 334 | BOOST_CHECK(m_networkRegionTable.find("/test/regionA") != m_networkRegionTable.end()); |
| 335 | BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") != m_networkRegionTable.end()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 336 | } |
| 337 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 338 | BOOST_AUTO_TEST_CASE(Reload) |
| 339 | { |
| 340 | const std::string CONFIG1 = |
| 341 | "tables\n" |
| 342 | "{\n" |
| 343 | " network_region\n" |
| 344 | " {\n" |
| 345 | " /some/region\n" |
| 346 | " }\n" |
| 347 | "}\n"; |
| 348 | |
| 349 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true)); |
| 350 | BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end()); |
| 351 | |
| 352 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false)); |
| 353 | BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end()); |
| 354 | |
| 355 | const std::string CONFIG2 = |
| 356 | "tables\n" |
| 357 | "{\n" |
| 358 | " network_region\n" |
| 359 | " {\n" |
| 360 | " /different/region\n" |
| 361 | " }\n" |
| 362 | "}\n"; |
| 363 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true)); |
| 364 | BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end()); |
| 365 | BOOST_CHECK(m_networkRegionTable.find("/different/region") == m_networkRegionTable.end()); |
| 366 | |
| 367 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false)); |
| 368 | BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end()); |
| 369 | BOOST_CHECK(m_networkRegionTable.find("/different/region") != m_networkRegionTable.end()); |
| 370 | } |
| 371 | |
| 372 | BOOST_AUTO_TEST_SUITE_END() // NetworkRegion |
| 373 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 374 | BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 375 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 376 | |
| 377 | } // namespace tests |
| 378 | } // namespace nfd |