EXPECT_EQ("////", result->stringValue());
}
+/// @brief Load a file into a JSON element.
+///
+/// @param fname The name of the file to load.
+/// @param list The JSON element list to add the parsing result to.
+void loadFile(const string& fname, ElementPtr list) {
+ ParserContext ctx;
+ ElementPtr json;
+ EXPECT_NO_THROW(json = ctx.parseFile(fname, ParserContext::PARSER_AGENT));
+ ASSERT_TRUE(json);
+ list->add(json);
+}
+
// This test checks that all map entries are in the sample file.
TEST(ParserTest, mapEntries) {
// Type of keyword set.
}
syntax_file.close();
- // Get keywords from the sample file
- string sample_fname(CFG_EXAMPLES);
- sample_fname += "/simple.json";
- ParserContext ctx;
- ElementPtr sample_json;
- EXPECT_NO_THROW(sample_json =
- ctx.parseFile(sample_fname, ParserContext::PARSER_AGENT));
- ASSERT_TRUE(sample_json);
+ // Get keywords from the sample files
+ string sample_dir(CFG_EXAMPLES);
+ sample_dir += "/";
+ ElementPtr sample_json = Element::createList();
+ loadFile(sample_dir + "simple.json", sample_json);
KeywordSet sample_keys;
// Recursively extract keywords.
static void (*extract)(ConstElementPtr, KeywordSet&) =
// Handle maps.
for (auto elem : json->mapValue()) {
// Skip entries with free content.
- if ((elem.first != "user-context") &&
- (elem.first != "parameters")) {
+ if ((elem.first == "user-context") ||
+ (elem.first == "parameters")) {
continue;
}
EXPECT_EQ("////", result->stringValue());
}
+/// @brief Load a file into a JSON element.
+///
+/// @param fname The name of the file to load.
+/// @param list The JSON element list to add the parsing result to.
+void loadFile(const string& fname, ElementPtr list) {
+ D2ParserContext ctx;
+ ElementPtr json;
+ EXPECT_NO_THROW(json = ctx.parseFile(fname, D2ParserContext::PARSER_DHCPDDNS));
+ ASSERT_TRUE(json);
+ list->add(json);
+}
+
// This test checks that all map entries are in the sample file.
TEST(ParserTest, mapEntries) {
+ // Type of keyword set.
+ typedef set<string> KeywordSet;
+
// Get keywords from the syntax file (d2_parser.yy).
ifstream syntax_file(SYNTAX_FILE);
EXPECT_TRUE(syntax_file.is_open());
syntax_file.close();
// Get keywords from the sample file
- string sample_fname(D2_TEST_DATA_DIR);
- sample_fname += "/get_config.json";
- D2ParserContext ctx;
- ElementPtr sample_json;
- EXPECT_NO_THROW(sample_json =
- ctx.parseFile(sample_fname, D2ParserContext::PARSER_DHCPDDNS));
- ASSERT_TRUE(sample_json);
+ string sample_dir(D2_TEST_DATA_DIR);
+ sample_dir += "/";
+ ElementPtr sample_json = Element::createList();
+ loadFile(sample_dir + "get_config.json", sample_json);
KeywordSet sample_keys;
// Recursively extract keywords.
static void (*extract)(ConstElementPtr, KeywordSet&) =
// Handle maps.
for (auto elem : json->mapValue()) {
// Skip entries with free content.
- if ((elem.first != "user-context") &&
- (elem.first != "parameters")) {
+ if ((elem.first == "user-context") ||
+ (elem.first == "parameters")) {
continue;
}
return (ctx.parseString(in, isc::d2::D2ParserContext::PARSER_JSON));
}
-/// @brief Type of keyword set
-typedef std::set<std::string> KeywordSet;
-
}
}
}
EXPECT_EQ("////", result->stringValue());
}
+/// @brief Load a file into a JSON element.
+///
+/// @param fname The name of the file to load.
+/// @param list The JSON element list to add the parsing result to.
+void loadFile(const string& fname, ElementPtr list) {
+ Parser4Context ctx;
+ ElementPtr json;
+ EXPECT_NO_THROW(json = ctx.parseFile(fname, Parser4Context::PARSER_DHCP4));
+ ASSERT_TRUE(json);
+ list->add(json);
+}
+
// This test checks that all map entries are in the all-keys file.
TEST(ParserTest, mapEntries) {
// Type of keyword set.
}
syntax_file.close();
- // Get keywords from the all keys file
- string sample_fname(CFG_EXAMPLES);
- sample_fname += "/all-keys.json";
- Parser4Context ctx;
- ElementPtr sample_json;
- EXPECT_NO_THROW(sample_json =
- ctx.parseFile(sample_fname, Parser4Context::PARSER_DHCP4));
- ASSERT_TRUE(sample_json);
+ // Get keywords from the all-keys and reservations file
+ string sample_dir(CFG_EXAMPLES);
+ sample_dir += "/";
+ ElementPtr sample_json = Element::createList();
+ loadFile(sample_dir + "all-keys.json", sample_json);
+ loadFile(sample_dir + "reservations.json", sample_json);
KeywordSet sample_keys = {
- "hw-address", "duid", "client-id", "flex-id",
"hosts-database"
};
// Recursively extract keywords.
// Handle maps.
for (auto elem : json->mapValue()) {
// Skip entries with free content.
- if ((elem.first != "user-context") &&
- (elem.first != "parameters")) {
+ if ((elem.first == "user-context") ||
+ (elem.first == "parameters")) {
continue;
}
EXPECT_EQ("////", result->stringValue());
}
+/// @brief Load a file into a JSON element.
+///
+/// @param fname The name of the file to load.
+/// @param list The JSON element list to add the parsing result to.
+void loadFile(const string& fname, ElementPtr list) {
+ Parser6Context ctx;
+ ElementPtr json;
+ EXPECT_NO_THROW(json = ctx.parseFile(fname, Parser6Context::PARSER_DHCP6));
+ ASSERT_TRUE(json);
+ list->add(json);
+}
+
// This test checks that all map entries are in the all-keys file.
TEST(ParserTest, mapEntries) {
// Type of keyword set.
}
syntax_file.close();
- // Get keywords from the all keys file.
- string sample_fname(CFG_EXAMPLES);
- sample_fname += "/all-keys.json";
- Parser6Context ctx;
- ElementPtr sample_json;
- EXPECT_NO_THROW(sample_json =
- ctx.parseFile(sample_fname, Parser6Context::PARSER_DHCP6));
- ASSERT_TRUE(sample_json);
+ // Get keywords from the example files.
+ string sample_dir(CFG_EXAMPLES);
+ sample_dir += "/";
+ ElementPtr sample_json = Element::createList();
+ loadFile(sample_dir + "advanced.json", sample_json);
+ loadFile(sample_dir + "all-keys.json", sample_json);
+ loadFile(sample_dir + "duid.json", sample_json);
+ loadFile(sample_dir + "reservations.json", sample_json);
KeywordSet sample_keys = {
- "hw-address", "flex-id",
"hosts-database",
- "htype", "ip-address", "time"
};
// Recursively extract keywords.
static void (*extract)(ConstElementPtr, KeywordSet&) =
// Handle maps.
for (auto elem : json->mapValue()) {
// Skip entries with free content.
- if ((elem.first != "user-context") &&
- (elem.first != "parameters")) {
+ if ((elem.first == "user-context") ||
+ (elem.first == "parameters")) {
continue;
}
EXPECT_EQ("////", result->stringValue());
}
+/// @brief Load a file into a JSON element.
+///
+/// @param fname The name of the file to load.
+/// @param list The JSON element list to add the parsing result to.
+void loadFile(const string& fname, ElementPtr list) {
+ ParserContext ctx;
+ ElementPtr json;
+ EXPECT_NO_THROW(json = ctx.parseFile(fname, ParserContext::PARSER_NETCONF));
+ ASSERT_TRUE(json);
+ list->add(json);
+}
+
// This test checks that all map entries are in the sample file.
TEST(ParserTest, mapEntries) {
// Type of keyword set.
syntax_file.close();
// Get keywords from the sample file
- string sample_fname(CFG_EXAMPLES);
- sample_fname += "/simple-dhcp4.json";
- ParserContext ctx;
- ElementPtr sample_json;
- EXPECT_NO_THROW(sample_json =
- ctx.parseFile(sample_fname, ParserContext::PARSER_NETCONF));
- ASSERT_TRUE(sample_json);
+ string sample_dir(CFG_EXAMPLES);
+ sample_dir += "/";
+ ElementPtr sample_json = Element::createList();
+ loadFile(sample_dir + "simple-dhcp4.json", sample_json);
+ loadFile(sample_dir + "simple-dhcp6.json", sample_json);
KeywordSet sample_keys = {
- "ca", "d2", "dhcp6",
+ "ca", "d2",
"hooks-libraries", "library", "parameters",
"socket-url"
};
// Handle maps.
for (auto elem : json->mapValue()) {
// Skip entries with free content.
- if ((elem.first != "user-context") &&
- (elem.first != "parameters")) {
+ if ((elem.first == "user-context") ||
+ (elem.first == "parameters")) {
continue;
}