blob: 12cca26b485d7b3ca506e3354de5187a911bb89e [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
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070029namespace ndn {
30namespace delorean {
Yingdi Yu92672512015-03-24 13:59:33 -070031namespace tests {
32
33BOOST_AUTO_TEST_SUITE(TestConfig)
34
35BOOST_AUTO_TEST_CASE(Basic)
36{
37 const std::string CONFIG =
38 "logger-name /test/logger \n"
39 "db-dir /test/db \n"
40 "policy \n"
41 "{ \n"
42 " policy-key policy-value \n"
43 "} \n"
44 "validator \n"
45 "{ \n"
46 " validator-key validator-value \n"
47 "} \n";
48
49 namespace fs = boost::filesystem;
50
51 fs::create_directory(fs::path(TEST_LOGGER_PATH));
52
53 fs::path configPath = fs::path(TEST_LOGGER_PATH) / "logger-test.conf";
54 std::ofstream os(configPath.c_str());
55 os << CONFIG;
56 os.close();
57
58 conf::ConfigFile config(configPath.string());
59
60 BOOST_CHECK_NO_THROW(config.parse());
61
62 BOOST_CHECK_EQUAL(config.getConfFileName(), configPath.string());
63 BOOST_CHECK_EQUAL(config.getLoggerName(), Name("/test/logger"));
64 BOOST_CHECK_EQUAL(config.getDbDir(), "/test/db");
65 BOOST_CHECK_EQUAL(config.getPolicy().begin()->first, "policy-key");
66 BOOST_CHECK_EQUAL(config.getPolicy().begin()->second.data(), "policy-value");
67 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->first, "validator-key");
68 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->second.data(), "validator-value");
69
70 fs::remove_all(fs::path(TEST_LOGGER_PATH));
71}
72
73BOOST_AUTO_TEST_CASE(Basic2)
74{
75 const std::string CONFIG =
76 "logger-name /test/logger \n"
77 "policy \n"
78 "{ \n"
79 " policy-key policy-value \n"
80 "} \n"
81 "validator \n"
82 "{ \n"
83 " validator-key validator-value \n"
84 "} \n";
85
86 namespace fs = boost::filesystem;
87
88 fs::create_directory(fs::path(TEST_LOGGER_PATH));
89
90 fs::path configPath = fs::path(TEST_LOGGER_PATH) / "logger-test.conf";
91 std::ofstream os(configPath.c_str());
92 os << CONFIG;
93 os.close();
94
95 conf::ConfigFile config(configPath.string());
96
97 BOOST_CHECK_NO_THROW(config.parse());
98
99 BOOST_CHECK_EQUAL(config.getConfFileName(), configPath.string());
100 BOOST_CHECK_EQUAL(config.getLoggerName(), Name("/test/logger"));
101 BOOST_CHECK_EQUAL(config.getDbDir(), fs::path(TEST_LOGGER_PATH).string());
102 BOOST_CHECK_EQUAL(config.getPolicy().begin()->first, "policy-key");
103 BOOST_CHECK_EQUAL(config.getPolicy().begin()->second.data(), "policy-value");
104 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->first, "validator-key");
105 BOOST_CHECK_EQUAL(config.getValidatorRule().begin()->second.data(), "validator-value");
106
107 fs::remove_all(fs::path(TEST_LOGGER_PATH));
108}
109
110BOOST_AUTO_TEST_SUITE_END()
111
112} // namespace tests
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -0700113} // namespace delorean
114} // namespace ndn