blob: 29e5e7a07c2a96aec7c0e0c78a5c739978568366 [file] [log] [blame]
Steve DiBenedetto24b9a642014-04-07 15:45:39 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettob4336c22014-10-06 12:14:06 -06003 * 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 DiBenedetto24b9a642014-04-07 15:45:39 -060010 *
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 DiBenedettob4336c22014-10-06 12:14:06 -060024 */
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060025
26#include "mgmt/general-config-section.hpp"
27
28#include "tests/test-common.hpp"
29
30namespace nfd {
31namespace tests {
32
Steve DiBenedettob4336c22014-10-06 12:14:06 -060033BOOST_FIXTURE_TEST_SUITE(MgmtGeneralConfigSection, BaseFixture)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060034
Steve DiBenedettob4336c22014-10-06 12:14:06 -060035BOOST_AUTO_TEST_CASE(UserAndGroupConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060036{
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 DiBenedettob4336c22014-10-06 12:14:06 -060051BOOST_AUTO_TEST_CASE(DefaultConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060052{
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 DiBenedettob4336c22014-10-06 12:14:06 -060064BOOST_AUTO_TEST_CASE(NoUserConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060065{
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 DiBenedettob4336c22014-10-06 12:14:06 -060078BOOST_AUTO_TEST_CASE(NoGroupConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060079{
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
92static bool
93checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected)
94{
95 return error.what() == expected;
96}
97
Steve DiBenedettob4336c22014-10-06 12:14:06 -060098BOOST_AUTO_TEST_CASE(InvalidUserConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -060099{
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 DiBenedettob4336c22014-10-06 12:14:06 -0600115BOOST_AUTO_TEST_CASE(InvalidGroupConfig)
Steve DiBenedetto24b9a642014-04-07 15:45:39 -0600116{
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
132BOOST_AUTO_TEST_SUITE_END()
133
134} // namespace tests
135
136} // namespace nfd