Commit e559a237 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5014] Unit-test loading example config files implemented.

parent d774e032
......@@ -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();
......
......@@ -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
......
......@@ -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);
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment