blob: 2cf27ccd46461a2565e2adea15d54ce98f459a16 [file] [log] [blame]
Yingdi Yu92672512015-03-24 13:59:33 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yu92672512015-03-24 13:59:33 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yu92672512015-03-24 13:59:33 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yu92672512015-03-24 13:59:33 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yu92672512015-03-24 13:59:33 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu92672512015-03-24 13:59:33 -070020 */
21
22#include "conf/config-file.hpp"
23
24#include <boost/filesystem.hpp>
25#include <fstream>
26
27#include "boost-test.hpp"
28
29namespace nsl {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(TestConfig)
33
34BOOST_AUTO_TEST_CASE(Basic)
35{
36 const std::string CONFIG =
37 "logger-name /test/logger \n"
38 "db-dir /test/db \n"
39 "policy \n"
40 "{ \n"
41 " policy-key policy-value \n"
42 "} \n"
43 "validator \n"
44 "{ \n"
45 " validator-key validator-value \n"
46 "} \n";
47
48 namespace fs = boost::filesystem;
49
50 fs::create_directory(fs::path(TEST_LOGGER_PATH));
51
52 fs::path configPath = fs::path(TEST_LOGGER_PATH) / "logger-test.conf";
53 std::ofstream os(configPath.c_str());
54 os << CONFIG;
55 os.close();
56
57 conf::ConfigFile config(configPath.string());
58
59 BOOST_CHECK_NO_THROW(config.parse());
60
61 BOOST_CHECK_EQUAL(config.getConfFileName(), configPath.string());
62 BOOST_CHECK_EQUAL(config.getLoggerName(), Name("/test/logger"));
63 BOOST_CHECK_EQUAL(config.getDbDir(), "/test/db");
64 BOOST_CHECK_EQUAL(config.getPolicy().begin()->first, "policy-key");
65 BOOST_CHECK_EQUAL(config.getPolicy().begin()->second.data(), "policy-value");
66 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->first, "validator-key");
67 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->second.data(), "validator-value");
68
69 fs::remove_all(fs::path(TEST_LOGGER_PATH));
70}
71
72BOOST_AUTO_TEST_CASE(Basic2)
73{
74 const std::string CONFIG =
75 "logger-name /test/logger \n"
76 "policy \n"
77 "{ \n"
78 " policy-key policy-value \n"
79 "} \n"
80 "validator \n"
81 "{ \n"
82 " validator-key validator-value \n"
83 "} \n";
84
85 namespace fs = boost::filesystem;
86
87 fs::create_directory(fs::path(TEST_LOGGER_PATH));
88
89 fs::path configPath = fs::path(TEST_LOGGER_PATH) / "logger-test.conf";
90 std::ofstream os(configPath.c_str());
91 os << CONFIG;
92 os.close();
93
94 conf::ConfigFile config(configPath.string());
95
96 BOOST_CHECK_NO_THROW(config.parse());
97
98 BOOST_CHECK_EQUAL(config.getConfFileName(), configPath.string());
99 BOOST_CHECK_EQUAL(config.getLoggerName(), Name("/test/logger"));
100 BOOST_CHECK_EQUAL(config.getDbDir(), fs::path(TEST_LOGGER_PATH).string());
101 BOOST_CHECK_EQUAL(config.getPolicy().begin()->first, "policy-key");
102 BOOST_CHECK_EQUAL(config.getPolicy().begin()->second.data(), "policy-value");
103 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->first, "validator-key");
104 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->second.data(), "validator-value");
105
106 fs::remove_all(fs::path(TEST_LOGGER_PATH));
107}
108
109BOOST_AUTO_TEST_SUITE_END()
110
111} // namespace tests
112} // namespace nsl