blob: 658018b7043acce739bb2a3540aa07da5cb783b0 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060020 */
21
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060022#include "util/config-file.hpp"
Davide Pesaventoeee3e822016-11-26 19:19:34 +010023#include "../test-home-env-saver.hpp"
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060024
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
26
Davide Pesaventoeee3e822016-11-26 19:19:34 +010027#include <cstdlib>
28
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060029namespace ndn {
Yingdi Yuf56c68f2014-04-24 21:50:13 -070030namespace tests {
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060031
Davide Pesaventoeee3e822016-11-26 19:19:34 +010032BOOST_AUTO_TEST_SUITE(Util)
33BOOST_FIXTURE_TEST_SUITE(TestConfigFile, TestHomeEnvSaver)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060034
Davide Pesaventoeee3e822016-11-26 19:19:34 +010035BOOST_AUTO_TEST_CASE(Parse)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060036{
Davide Pesaventoeee3e822016-11-26 19:19:34 +010037 namespace fs = boost::filesystem;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060038
Davide Pesavento74daf742018-11-23 18:14:13 -050039 setenv("TEST_HOME", "tests/unit/util/config-file-home", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060040
Davide Pesaventoeee3e822016-11-26 19:19:34 +010041 fs::path homePath(fs::absolute(std::getenv("TEST_HOME")));
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060042 homePath /= ".ndn/client.conf";
43
Davide Pesaventoeee3e822016-11-26 19:19:34 +010044 ConfigFile config;
45 BOOST_REQUIRE_EQUAL(config.getPath(), homePath);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060046
Davide Pesaventoeee3e822016-11-26 19:19:34 +010047 const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
48 BOOST_CHECK_EQUAL(parsed.get<std::string>("a"), "/path/to/nowhere");
49 BOOST_CHECK_EQUAL(parsed.get<std::string>("b"), "some-othervalue.01");
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060050}
51
Davide Pesaventoeee3e822016-11-26 19:19:34 +010052BOOST_AUTO_TEST_CASE(ParseEmptyPath)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060053{
Davide Pesavento74daf742018-11-23 18:14:13 -050054 setenv("TEST_HOME", "tests/unit/util/does/not/exist", 1);
Davide Pesaventoeee3e822016-11-26 19:19:34 +010055
56 BOOST_CHECK_NO_THROW(ConfigFile config);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060057}
58
Davide Pesaventoeee3e822016-11-26 19:19:34 +010059BOOST_AUTO_TEST_CASE(ParseMalformed)
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060060{
Davide Pesavento74daf742018-11-23 18:14:13 -050061 setenv("TEST_HOME", "tests/unit/util/config-file-malformed-home", 1);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060062
Davide Pesaventoeee3e822016-11-26 19:19:34 +010063 BOOST_CHECK_THROW(ConfigFile config, ConfigFile::Error);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060064}
65
Davide Pesaventoeee3e822016-11-26 19:19:34 +010066BOOST_AUTO_TEST_SUITE_END() // TestConfigFile
67BOOST_AUTO_TEST_SUITE_END() // Util
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060068
Yingdi Yuf56c68f2014-04-24 21:50:13 -070069} // namespace tests
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060070} // namespace ndn