core: Extend ConfigFile to support passing a parsed ConfigSection

Change-Id: I955220c08d8e6ed07c77d82149f6ff3ae48b2b12
Refs: #2495
diff --git a/core/config-file.cpp b/core/config-file.cpp
index 5887c2b..1079666 100644
--- a/core/config-file.cpp
+++ b/core/config-file.cpp
@@ -109,6 +109,13 @@
 }
 
 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)
 {
   BOOST_ASSERT(!filename.empty());
diff --git a/core/config-file.hpp b/core/config-file.hpp
index b7dd886..9991484 100644
--- a/core/config-file.hpp
+++ b/core/config-file.hpp
@@ -91,7 +91,7 @@
   /**
    * \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 @@
   /**
    * \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
diff --git a/tests/core/config-file.cpp b/tests/core/config-file.cpp
index 29689dd..7d3ddde 100644
--- a/tests/core/config-file.cpp
+++ b/tests/core/config-file.cpp
@@ -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_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)
 {