Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +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 | |
| 26 | #include "face/face-system.hpp" |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 27 | #include "face-system-fixture.hpp" |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 28 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace face { |
| 33 | namespace tests { |
| 34 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Face) |
| 36 | BOOST_FIXTURE_TEST_SUITE(TestFaceSystem, FaceSystemFixture) |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
| 39 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE(Normal) |
| 41 | { |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 42 | faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams()); |
| 43 | faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams()); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 44 | auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1")); |
| 45 | auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2")); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 46 | |
| 47 | const std::string CONFIG = R"CONFIG( |
| 48 | face_system |
| 49 | { |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 50 | general |
| 51 | { |
| 52 | enable_congestion_marking yes |
| 53 | } |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 54 | f1 |
| 55 | { |
| 56 | key v1 |
| 57 | } |
| 58 | f2 |
| 59 | { |
| 60 | key v2 |
| 61 | } |
| 62 | } |
| 63 | )CONFIG"; |
| 64 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 65 | parseConfig(CONFIG, true); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 66 | BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 1); |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 67 | BOOST_CHECK(f1->processConfigHistory.back().isDryRun); |
| 68 | BOOST_CHECK(f1->processConfigHistory.back().wantCongestionMarking); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(f1->processConfigHistory.back().configSection->get<std::string>("key"), "v1"); |
| 70 | BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 1); |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 71 | BOOST_CHECK(f2->processConfigHistory.back().isDryRun); |
| 72 | BOOST_CHECK(f2->processConfigHistory.back().wantCongestionMarking); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(f2->processConfigHistory.back().configSection->get<std::string>("key"), "v2"); |
| 74 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 75 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 76 | BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 2); |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 77 | BOOST_CHECK(!f1->processConfigHistory.back().isDryRun); |
| 78 | BOOST_CHECK(f1->processConfigHistory.back().wantCongestionMarking); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(f1->processConfigHistory.back().configSection->get<std::string>("key"), "v1"); |
| 80 | BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 2); |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 81 | BOOST_CHECK(!f2->processConfigHistory.back().isDryRun); |
| 82 | BOOST_CHECK(f2->processConfigHistory.back().wantCongestionMarking); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(f2->processConfigHistory.back().configSection->get<std::string>("key"), "v2"); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(OmittedSection) |
| 87 | { |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 88 | faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams()); |
| 89 | faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams()); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 90 | auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1")); |
| 91 | auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2")); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 92 | |
| 93 | const std::string CONFIG = R"CONFIG( |
| 94 | face_system |
| 95 | { |
| 96 | f1 |
| 97 | { |
| 98 | } |
| 99 | } |
| 100 | )CONFIG"; |
| 101 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 102 | parseConfig(CONFIG, true); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 103 | BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 1); |
| 104 | BOOST_CHECK_EQUAL(f1->processConfigHistory.back().isDryRun, true); |
| 105 | BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 1); |
| 106 | BOOST_CHECK_EQUAL(f2->processConfigHistory.back().isDryRun, true); |
| 107 | BOOST_CHECK(!f2->processConfigHistory.back().configSection); |
| 108 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 109 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 110 | BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 2); |
| 111 | BOOST_CHECK_EQUAL(f1->processConfigHistory.back().isDryRun, false); |
| 112 | BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 2); |
| 113 | BOOST_CHECK_EQUAL(f2->processConfigHistory.back().isDryRun, false); |
| 114 | BOOST_CHECK(!f2->processConfigHistory.back().configSection); |
| 115 | } |
| 116 | |
| 117 | BOOST_AUTO_TEST_CASE(UnknownSection) |
| 118 | { |
| 119 | const std::string CONFIG = R"CONFIG( |
| 120 | face_system |
| 121 | { |
| 122 | f0 |
| 123 | { |
| 124 | } |
| 125 | } |
| 126 | )CONFIG"; |
| 127 | |
| 128 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 129 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(ChangeProvidedSchemes) |
| 133 | { |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 134 | faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams()); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 135 | auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1")); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 136 | |
| 137 | const std::string CONFIG = R"CONFIG( |
| 138 | face_system |
| 139 | { |
| 140 | f1 |
| 141 | { |
| 142 | } |
| 143 | } |
| 144 | )CONFIG"; |
| 145 | |
| 146 | f1->newProvidedSchemes.insert("s1"); |
| 147 | f1->newProvidedSchemes.insert("s2"); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 148 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 149 | BOOST_CHECK(faceSystem.getFactoryByScheme("f1") == nullptr); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 150 | BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s1"), f1); |
| 151 | BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s2"), f1); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 152 | |
| 153 | f1->newProvidedSchemes.erase("s2"); |
| 154 | f1->newProvidedSchemes.insert("s3"); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 155 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 156 | BOOST_CHECK(faceSystem.getFactoryByScheme("f1") == nullptr); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 157 | BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s1"), f1); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 158 | BOOST_CHECK(faceSystem.getFactoryByScheme("s2") == nullptr); |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s3"), f1); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 163 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 164 | BOOST_AUTO_TEST_SUITE_END() // TestFaceSystem |
Junxiao Shi | eef49a9 | 2018-11-10 12:19:36 +0000 | [diff] [blame^] | 165 | BOOST_AUTO_TEST_SUITE_END() // Face |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 166 | |
| 167 | } // namespace tests |
| 168 | } // namespace face |
| 169 | } // namespace nfd |