core: Extend ConfigFile to support passing a parsed ConfigSection

Change-Id: I955220c08d8e6ed07c77d82149f6ff3ae48b2b12
Refs: #2495
This commit is contained in:
Alexander Afanasyev
2015-01-06 13:05:50 -08:00
parent a788e25e70
commit c0273e3505
3 changed files with 31 additions and 2 deletions
+7
View File
@@ -108,6 +108,13 @@ ConfigFile::parse(std::istream& input, bool isDryRun, const std::string& filenam
process(isDryRun, filename);
}
void
ConfigFile::parse(const ConfigSection& config, bool isDryRun, const std::string& filename)
{
m_global = config;
process(isDryRun, filename);
}
void
ConfigFile::process(bool isDryRun, const std::string& filename)
{
+11 -2
View File
@@ -91,7 +91,7 @@ public:
/**
* \param input configuration (as a string) to parse
* \param isDryRun true if performing a dry run of configuration, false otherwise
* \param filename optional convenience argument to provide more detailed error messages
* \param filename logical filename of the config file, can appear in error messages
* \throws ConfigFile::Error if file not found
* \throws ConfigFile::Error if parse error
*/
@@ -101,12 +101,21 @@ public:
/**
* \param input stream to parse
* \param isDryRun true if performing a dry run of configuration, false otherwise
* \param filename optional convenience argument to provide more detailed error messages
* \param filename logical filename of the config file, can appear in error messages
* \throws ConfigFile::Error if parse error
*/
void
parse(std::istream& input, bool isDryRun, const std::string& filename);
/**
* \param config ConfigSection that needs to be processed
* \param isDryRun true if performing a dry run of configuration, false otherwise
* \param filename logical filename of the config file, can appear in error messages
* \throws ConfigFile::Error if parse error
*/
void
parse(const ConfigSection& config, bool isDryRun, const std::string& filename);
private:
void
+13
View File
@@ -27,6 +27,7 @@
#include "tests/test-common.hpp"
#include <fstream>
#include <boost/property_tree/info_parser.hpp>
namespace nfd {
namespace tests {
@@ -236,6 +237,18 @@ BOOST_AUTO_TEST_CASE(OnConfigStreamEmptyStream)
BOOST_CHECK(sub.noCallbacksFired());
}
BOOST_AUTO_TEST_CASE(OnConfigSection)
{
ConfigFile file;
DummyAllSubscriber sub(file);
std::istringstream input(CONFIG);
ConfigSection section;
boost::property_tree::read_info(input, section);
file.parse(section, false, "dummy-config");
BOOST_CHECK(sub.allCallbacksFired());
}
BOOST_AUTO_TEST_CASE(OnConfigString)
{