Yingdi Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California |
Yingdi Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 5 | * 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 Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 8 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 9 | * 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 Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 13 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 14 | * 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 Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 17 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 18 | * 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 Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "conf/config-file.hpp" |
| 23 | |
| 24 | #include <boost/filesystem.hpp> |
| 25 | #include <fstream> |
| 26 | |
| 27 | #include "boost-test.hpp" |
| 28 | |
| 29 | namespace nsl { |
| 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(TestConfig) |
| 33 | |
| 34 | BOOST_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 | |
| 72 | BOOST_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 | |
| 109 | BOOST_AUTO_TEST_SUITE_END() |
| 110 | |
| 111 | } // namespace tests |
| 112 | } // namespace nsl |