Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 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 |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -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/>. |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 25 | |
| 26 | #include "mgmt/general-config-section.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace tests { |
| 32 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_SUITE(MgmtGeneralConfigSection, BaseFixture) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 34 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(UserAndGroupConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 36 | { |
| 37 | const std::string CONFIG = |
| 38 | "general\n" |
| 39 | "{\n" |
| 40 | " user nobody\n" |
| 41 | " group nogroup\n" |
| 42 | "}\n"; |
| 43 | |
| 44 | ConfigFile configFile; |
| 45 | |
| 46 | general::setConfigFile(configFile); |
| 47 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 48 | |
| 49 | } |
| 50 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(DefaultConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 52 | { |
| 53 | const std::string CONFIG = |
| 54 | "general\n" |
| 55 | "{\n" |
| 56 | "}\n"; |
| 57 | |
| 58 | ConfigFile configFile; |
| 59 | |
| 60 | general::setConfigFile(configFile); |
| 61 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 62 | } |
| 63 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 64 | BOOST_AUTO_TEST_CASE(NoUserConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 65 | { |
| 66 | const std::string CONFIG = |
| 67 | "general\n" |
| 68 | "{\n" |
| 69 | " group nogroup\n" |
| 70 | "}\n"; |
| 71 | |
| 72 | ConfigFile configFile; |
| 73 | |
| 74 | general::setConfigFile(configFile); |
| 75 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 76 | } |
| 77 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(NoGroupConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 79 | { |
| 80 | const std::string CONFIG = |
| 81 | "general\n" |
| 82 | "{\n" |
| 83 | " user nobody\n" |
| 84 | "}\n"; |
| 85 | |
| 86 | ConfigFile configFile; |
| 87 | |
| 88 | general::setConfigFile(configFile); |
| 89 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 90 | } |
| 91 | |
| 92 | static bool |
| 93 | checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected) |
| 94 | { |
| 95 | return error.what() == expected; |
| 96 | } |
| 97 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 98 | BOOST_AUTO_TEST_CASE(InvalidUserConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 99 | { |
| 100 | const std::string CONFIG = |
| 101 | "general\n" |
| 102 | "{\n" |
| 103 | " user\n" |
| 104 | "}\n"; |
| 105 | |
| 106 | ConfigFile configFile; |
| 107 | general::setConfigFile(configFile); |
| 108 | |
| 109 | const std::string expected = "Invalid value for \"user\" in \"general\" section"; |
| 110 | BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"), |
| 111 | ConfigFile::Error, |
| 112 | bind(&checkExceptionMessage, _1, expected)); |
| 113 | } |
| 114 | |
Steve DiBenedetto | b4336c2 | 2014-10-06 12:14:06 -0600 | [diff] [blame] | 115 | BOOST_AUTO_TEST_CASE(InvalidGroupConfig) |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 116 | { |
| 117 | const std::string CONFIG = |
| 118 | "general\n" |
| 119 | "{\n" |
| 120 | " group\n" |
| 121 | "}\n"; |
| 122 | |
| 123 | ConfigFile configFile; |
| 124 | general::setConfigFile(configFile); |
| 125 | |
| 126 | const std::string expected = "Invalid value for \"group\" in \"general\" section"; |
| 127 | BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"), |
| 128 | ConfigFile::Error, |
| 129 | bind(&checkExceptionMessage, _1, expected)); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_SUITE_END() |
| 133 | |
| 134 | } // namespace tests |
| 135 | |
| 136 | } // namespace nfd |