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 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 29 | namespace ndn { |
| 30 | namespace delorean { |
Yingdi Yu | 9267251 | 2015-03-24 13:59:33 -0700 | [diff] [blame] | 31 | namespace tests { |
| 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(TestConfig) |
| 34 | |
| 35 | BOOST_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 | |
| 73 | BOOST_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 | |
| 110 | BOOST_AUTO_TEST_SUITE_END() |
| 111 | |
| 112 | } // namespace tests |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 113 | } // namespace delorean |
| 114 | } // namespace ndn |