]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5014] Unit-test loading example config files implemented.
authorTomek Mrugalski <tomasz@isc.org>
Wed, 9 Nov 2016 21:28:38 +0000 (22:28 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 9 Nov 2016 21:28:38 +0000 (22:28 +0100)
src/bin/dhcp6/parser_context.cc
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tests/parser_unittest.cc

index e667a8e5e865776ed2b959e54fc3d51e58c74381..07fecd08b261ad3927faa72f9d2d35fc7ad84276 100644 (file)
@@ -60,7 +60,7 @@ Parser6Context::parseFile(const std::string& filename) {
     std::string line;
     while (!f.eof()) {
         std::getline(f, line);
-        string_ = string_ + line;
+        string_ = string_ + line + "\n";
     }
     f.close();
 
index 0fa0220f8d1d13257ed5876cd3bc41c2ce6f4a0c..9192f3dbca69b10bb1313d3b9f4e2dd6a6a92299 100644 (file)
@@ -24,6 +24,7 @@ AM_CPPFLAGS += -DTOP_BUILDDIR="\"$(top_builddir)\""
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/dhcp6/tests\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
+AM_CPPFLAGS += -DCFG_EXAMPLES=\"$(abs_top_srcdir)/doc/examples/kea6\"
 
 CLEANFILES  = $(builddir)/logger_lockfile
 CLEANFILES += $(builddir)/load_marker.txt $(builddir)/unload_marker.txt
index 188c906d43af7aba50739c8074b1bb50d2231c77..84b1be94b99e1d3f8cf5642422e924c534dc340c 100644 (file)
@@ -13,11 +13,13 @@ using namespace std;
 
 namespace {
 
-void compareJSON(ConstElementPtr a, ConstElementPtr b) {
+void compareJSON(ConstElementPtr a, ConstElementPtr b, bool print = true) {
     ASSERT_TRUE(a);
     ASSERT_TRUE(b);
-    std::cout << a->str() << std::endl;
-    std::cout << b->str() << std::endl;
+    if (print) {
+        std::cout << a->str() << std::endl;
+        std::cout << b->str() << std::endl;
+    }
     EXPECT_EQ(a->str(), b->str());
 }
 
@@ -164,23 +166,53 @@ TEST(ParserTest, multilineComments) {
     testParser2(txt);
 }
 
-TEST(ParserTest, file) {
 
+void testFile(const std::string& fname, bool print) {
     ElementPtr reference_json;
     ConstElementPtr test_json;
 
-    std::string fname = "test.json";
+    cout << "Attempting to load file " << fname << endl;
 
     EXPECT_NO_THROW(reference_json = Element::fromJSONFile(fname, true));
-    EXPECT_NO_THROW({
+
+    try {
         Parser6Context ctx;
         test_json = ctx.parseFile(fname);
-    });
+    } catch (const std::exception &x) {
+        cout << "EXCEPTION: " << x.what() << endl;
+    }
 
     ASSERT_TRUE(reference_json);
     ASSERT_TRUE(test_json);
 
-    compareJSON(reference_json, test_json);
+    compareJSON(reference_json, test_json, print);
+
+
+}
+
+// This test loads all available existing files. Each config is loaded
+// twice: first with the existing Element::fromJSONFile() and then
+// the second time with Parser6. Both JSON trees are then compared.
+TEST(ParserTest, file) {
+    vector<string> configs;
+    configs.push_back("advanced.json");
+    configs.push_back("backends.json");
+    configs.push_back("classify.json");
+    configs.push_back("dhcpv4-over-dhcpv6.json");
+    configs.push_back("duid.json");
+    configs.push_back("hooks.json");
+    configs.push_back("leases-expiration.json");
+    configs.push_back("multiple-options.json");
+    configs.push_back("mysql-reservations.json");
+    configs.push_back("pgsql-reservations.json");
+    configs.push_back("reservations.json");
+    configs.push_back("several-subnets.json");
+    configs.push_back("simple.json");
+    configs.push_back("stateless.json");
+
+    for (int i = 0; i<configs.size(); i++) {
+        testFile(string(CFG_EXAMPLES) + "/" + configs[i], false);
+    }
 }
 
 };