|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
};
|