Commit 79532966 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac736] more tests

parent cd4ffa34
......@@ -34,8 +34,10 @@ ConstElementPtr findListOrMapSubSpec(ConstElementPtr spec_part) {
(spec_part->contains("list_item_spec") ||
spec_part->contains("map_item_spec"))) {
if (spec_part->contains("list_item_spec")) {
std::cout << "[XX] yup, list" << std::endl;
spec_part = spec_part->get("list_item_spec");
} else {
std::cout << "[XX] yup, map" << std::endl;
spec_part = spec_part->get("map_item_spec");
}
}
......@@ -54,6 +56,7 @@ ConstElementPtr findItemInSpecList(ConstElementPtr spec_part,
const std::string& id_full)
{
bool found = false;
std::cout << "[XX] find item in list: " << spec_part->str() << std::endl;
BOOST_FOREACH(ConstElementPtr list_el, spec_part->listValue()) {
if (list_el->getType() == Element::map &&
list_el->contains("item_name") &&
......@@ -98,6 +101,7 @@ find_spec_part(ConstElementPtr spec, const std::string& identifier) {
size_t sep = id.find('/');
while(sep != std::string::npos) {
std::string part = id.substr(0, sep);
std::cout << "[XX] NEXT IS: " << part << std::endl;
if (spec_part->getType() == Element::list) {
spec_part = findItemInSpecList(spec_part, part, identifier);
......@@ -105,6 +109,7 @@ find_spec_part(ConstElementPtr spec, const std::string& identifier) {
isc_throw(DataNotFoundError,
"Not a list of spec items: " + spec_part->str());
}
std::cout << "[XX] FOUND: " << part << std::endl;
id = id.substr(sep + 1);
sep = id.find("/");
......@@ -112,9 +117,11 @@ find_spec_part(ConstElementPtr spec, const std::string& identifier) {
// by the identifier, we want to automatically traverse list
// and map specifications
if (id != "" && id != "/") {
std::cout << "[XX] try sublist " << id << std::endl;
spec_part = findListOrMapSubSpec(spec_part);
}
}
std::cout << "[XX] LAST: " << id << std::endl;
if (id != "" && id != "/") {
if (spec_part->getType() == Element::list) {
spec_part = findItemInSpecList(spec_part, id, identifier);
......@@ -124,9 +131,12 @@ find_spec_part(ConstElementPtr spec, const std::string& identifier) {
spec_part->get("map_item_spec"),
id, identifier);
} else {
isc_throw(DataNotFoundError, "Element above " + id +
" in " + identifier +
" is not a map: " + spec_part->str());
if (!spec_part->contains("item_name") ||
spec_part->get("item_name")->stringValue() != id) {
isc_throw(DataNotFoundError, "Element above " + id +
" in " + identifier +
" is not a map: " + spec_part->str());
}
}
}
}
......
......@@ -64,6 +64,7 @@ TEST(ConfigData, getValue) {
EXPECT_EQ("{ }", cd.getValue(is_default, "value6/")->str());
EXPECT_TRUE(is_default);
EXPECT_EQ("[ ]", cd.getValue("value8")->str());
EXPECT_EQ("[ ]", cd.getDefaultValue("value8")->str());
EXPECT_EQ("empty", cd.getValue("value8/a")->stringValue());
EXPECT_THROW(cd.getValue("")->str(), DataNotFoundError);
......@@ -78,6 +79,20 @@ TEST(ConfigData, getValue) {
EXPECT_THROW(cd1.getValue("anything")->str(), DataNotFoundError);
}
TEST(ConfigData, getDefaultValue) {
ModuleSpec spec31 = moduleSpecFromFile(std::string(TEST_DATA_PATH) + "/spec31.spec");
ConfigData cd = ConfigData(spec31);
EXPECT_EQ("[ ]", cd.getDefaultValue("first_list_items")->str());
EXPECT_EQ("\"foo\"", cd.getDefaultValue("first_list_items/foo")->str());
EXPECT_EQ("{ }", cd.getDefaultValue("first_list_items/second_list_items/map_element")->str());
EXPECT_EQ("[ ]", cd.getDefaultValue("first_list_items/second_list_items/map_element/list1")->str());
EXPECT_EQ("1", cd.getDefaultValue("first_list_items/second_list_items/map_element/list1/number")->str());
EXPECT_THROW(cd.getDefaultValue("doesnotexist")->str(), DataNotFoundError);
EXPECT_THROW(cd.getDefaultValue("first_list_items/second_list_items/map_element/list1/doesnotexist")->str(), DataNotFoundError);
}
TEST(ConfigData, setLocalConfig) {
ModuleSpec spec2 = moduleSpecFromFile(std::string(TEST_DATA_PATH) + "/spec2.spec");
ConfigData cd = ConfigData(spec2);
......
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