Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
| 24 | |
| 25 | #include "mgmt/general-config-section.hpp" |
| 26 | |
| 27 | #include "tests/test-common.hpp" |
| 28 | |
| 29 | namespace nfd { |
| 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(GeneralSectionConfig) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(TestConfig) |
| 35 | { |
| 36 | const std::string CONFIG = |
| 37 | "general\n" |
| 38 | "{\n" |
| 39 | " user nobody\n" |
| 40 | " group nogroup\n" |
| 41 | "}\n"; |
| 42 | |
| 43 | ConfigFile configFile; |
| 44 | |
| 45 | general::setConfigFile(configFile); |
| 46 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | BOOST_AUTO_TEST_CASE(TestDefaultConfig) |
| 51 | { |
| 52 | const std::string CONFIG = |
| 53 | "general\n" |
| 54 | "{\n" |
| 55 | "}\n"; |
| 56 | |
| 57 | ConfigFile configFile; |
| 58 | |
| 59 | general::setConfigFile(configFile); |
| 60 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(TestNoUserConfig) |
| 64 | { |
| 65 | const std::string CONFIG = |
| 66 | "general\n" |
| 67 | "{\n" |
| 68 | " group nogroup\n" |
| 69 | "}\n"; |
| 70 | |
| 71 | ConfigFile configFile; |
| 72 | |
| 73 | general::setConfigFile(configFile); |
| 74 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(TestNoGroupConfig) |
| 78 | { |
| 79 | const std::string CONFIG = |
| 80 | "general\n" |
| 81 | "{\n" |
| 82 | " user nobody\n" |
| 83 | "}\n"; |
| 84 | |
| 85 | ConfigFile configFile; |
| 86 | |
| 87 | general::setConfigFile(configFile); |
| 88 | BOOST_CHECK_NO_THROW(configFile.parse(CONFIG, true, "test-general-config-section")); |
| 89 | } |
| 90 | |
| 91 | static bool |
| 92 | checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected) |
| 93 | { |
| 94 | return error.what() == expected; |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(TestInvalidUserConfig) |
| 98 | { |
| 99 | const std::string CONFIG = |
| 100 | "general\n" |
| 101 | "{\n" |
| 102 | " user\n" |
| 103 | "}\n"; |
| 104 | |
| 105 | ConfigFile configFile; |
| 106 | general::setConfigFile(configFile); |
| 107 | |
| 108 | const std::string expected = "Invalid value for \"user\" in \"general\" section"; |
| 109 | BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"), |
| 110 | ConfigFile::Error, |
| 111 | bind(&checkExceptionMessage, _1, expected)); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(TestInvalidGroupConfig) |
| 115 | { |
| 116 | const std::string CONFIG = |
| 117 | "general\n" |
| 118 | "{\n" |
| 119 | " group\n" |
| 120 | "}\n"; |
| 121 | |
| 122 | ConfigFile configFile; |
| 123 | general::setConfigFile(configFile); |
| 124 | |
| 125 | const std::string expected = "Invalid value for \"group\" in \"general\" section"; |
| 126 | BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"), |
| 127 | ConfigFile::Error, |
| 128 | bind(&checkExceptionMessage, _1, expected)); |
| 129 | } |
| 130 | |
| 131 | BOOST_AUTO_TEST_SUITE_END() |
| 132 | |
| 133 | } // namespace tests |
| 134 | |
| 135 | } // namespace nfd |