Commit 231849d9 authored by Jelte Jansen's avatar Jelte Jansen

change method names according to right camelcasing

parent f8d17c60
...@@ -255,7 +255,7 @@ ModuleCCSession::handleConfigUpdate(ConstElementPtr new_config) { ...@@ -255,7 +255,7 @@ ModuleCCSession::handleConfigUpdate(ConstElementPtr new_config) {
ElementPtr errors = Element::createList(); ElementPtr errors = Element::createList();
if (!config_handler_) { if (!config_handler_) {
answer = createAnswer(1, module_name_ + " does not have a config handler"); answer = createAnswer(1, module_name_ + " does not have a config handler");
} else if (!module_specification_.validate_config(new_config, false, } else if (!module_specification_.validateConfig(new_config, false,
errors)) { errors)) {
std::stringstream ss; std::stringstream ss;
ss << "Error in config validation: "; ss << "Error in config validation: ";
...@@ -305,7 +305,7 @@ ModuleCCSession::checkModuleCommand(const std::string& cmd_str, ...@@ -305,7 +305,7 @@ ModuleCCSession::checkModuleCommand(const std::string& cmd_str,
if (target_module == module_name_) { if (target_module == module_name_) {
if (command_handler_) { if (command_handler_) {
ElementPtr errors = Element::createList(); ElementPtr errors = Element::createList();
if (module_specification_.validate_command(cmd_str, if (module_specification_.validateCommand(cmd_str,
arg, arg,
errors)) { errors)) {
return command_handler_(cmd_str, arg); return command_handler_(cmd_str, arg);
......
...@@ -177,24 +177,23 @@ ModuleSpec::getModuleDescription() const { ...@@ -177,24 +177,23 @@ ModuleSpec::getModuleDescription() const {
} }
bool bool
ModuleSpec::validate_config(ConstElementPtr data, const bool full) const { ModuleSpec::validateConfig(ConstElementPtr data, const bool full) const {
ConstElementPtr spec = module_specification->find("config_data"); ConstElementPtr spec = module_specification->find("config_data");
return (validate_spec_list(spec, data, full, ElementPtr())); return (validateSpecList(spec, data, full, ElementPtr()));
} }
bool bool
ModuleSpec::validate_command(const std::string& command, ModuleSpec::validateCommand(const std::string& command,
ConstElementPtr args, ConstElementPtr args,
ElementPtr errors) const ElementPtr errors) const
{ {
ConstElementPtr commands_spec = module_specification->find("commands");
if (args->getType() != Element::map) { if (args->getType() != Element::map) {
errors->add(Element::create("args for command " + errors->add(Element::create("args for command " +
command + " is not a map")); command + " is not a map"));
return (false); return (false);
} }
ConstElementPtr commands_spec = module_specification->find("commands");
if (!commands_spec) { if (!commands_spec) {
// there are no commands according to the spec. // there are no commands according to the spec.
errors->add(Element::create("The given module has no commands")); errors->add(Element::create("The given module has no commands"));
...@@ -203,7 +202,7 @@ ModuleSpec::validate_command(const std::string& command, ...@@ -203,7 +202,7 @@ ModuleSpec::validate_command(const std::string& command,
BOOST_FOREACH(ConstElementPtr cur_command, commands_spec->listValue()) { BOOST_FOREACH(ConstElementPtr cur_command, commands_spec->listValue()) {
if (cur_command->get("command_name")->stringValue() == command) { if (cur_command->get("command_name")->stringValue() == command) {
return (validate_spec_list(cur_command->get("command_args"), return (validateSpecList(cur_command->get("command_args"),
args, true, errors)); args, true, errors));
} }
} }
...@@ -214,11 +213,11 @@ ModuleSpec::validate_command(const std::string& command, ...@@ -214,11 +213,11 @@ ModuleSpec::validate_command(const std::string& command,
} }
bool bool
ModuleSpec::validate_config(ConstElementPtr data, const bool full, ModuleSpec::validateConfig(ConstElementPtr data, const bool full,
ElementPtr errors) const ElementPtr errors) const
{ {
ConstElementPtr spec = module_specification->find("config_data"); ConstElementPtr spec = module_specification->find("config_data");
return (validate_spec_list(spec, data, full, errors)); return (validateSpecList(spec, data, full, errors));
} }
ModuleSpec ModuleSpec
...@@ -295,7 +294,7 @@ check_type(ConstElementPtr spec, ConstElementPtr element) { ...@@ -295,7 +294,7 @@ check_type(ConstElementPtr spec, ConstElementPtr element) {
} }
bool bool
ModuleSpec::validate_item(ConstElementPtr spec, ConstElementPtr data, ModuleSpec::validateItem(ConstElementPtr spec, ConstElementPtr data,
const bool full, ElementPtr errors) const const bool full, ElementPtr errors) const
{ {
if (!check_type(spec, data)) { if (!check_type(spec, data)) {
...@@ -317,14 +316,14 @@ ModuleSpec::validate_item(ConstElementPtr spec, ConstElementPtr data, ...@@ -317,14 +316,14 @@ ModuleSpec::validate_item(ConstElementPtr spec, ConstElementPtr data,
return (false); return (false);
} }
if (list_spec->get("item_type")->stringValue() == "map") { if (list_spec->get("item_type")->stringValue() == "map") {
if (!validate_item(list_spec, list_el, full, errors)) { if (!validateItem(list_spec, list_el, full, errors)) {
return (false); return (false);
} }
} }
} }
} }
if (data->getType() == Element::map) { if (data->getType() == Element::map) {
if (!validate_spec_list(spec->get("map_item_spec"), data, full, errors)) { if (!validateSpecList(spec->get("map_item_spec"), data, full, errors)) {
return (false); return (false);
} }
} }
...@@ -333,7 +332,7 @@ ModuleSpec::validate_item(ConstElementPtr spec, ConstElementPtr data, ...@@ -333,7 +332,7 @@ ModuleSpec::validate_item(ConstElementPtr spec, ConstElementPtr data,
// spec is a map with item_name etc, data is a map // spec is a map with item_name etc, data is a map
bool bool
ModuleSpec::validate_spec(ConstElementPtr spec, ConstElementPtr data, ModuleSpec::validateSpec(ConstElementPtr spec, ConstElementPtr data,
const bool full, ElementPtr errors) const const bool full, ElementPtr errors) const
{ {
std::string item_name = spec->get("item_name")->stringValue(); std::string item_name = spec->get("item_name")->stringValue();
...@@ -342,7 +341,7 @@ ModuleSpec::validate_spec(ConstElementPtr spec, ConstElementPtr data, ...@@ -342,7 +341,7 @@ ModuleSpec::validate_spec(ConstElementPtr spec, ConstElementPtr data,
data_el = data->get(item_name); data_el = data->get(item_name);
if (data_el) { if (data_el) {
if (!validate_item(spec, data_el, full, errors)) { if (!validateItem(spec, data_el, full, errors)) {
return (false); return (false);
} }
} else { } else {
...@@ -358,13 +357,13 @@ ModuleSpec::validate_spec(ConstElementPtr spec, ConstElementPtr data, ...@@ -358,13 +357,13 @@ ModuleSpec::validate_spec(ConstElementPtr spec, ConstElementPtr data,
// spec is a list of maps, data is a map // spec is a list of maps, data is a map
bool bool
ModuleSpec::validate_spec_list(ConstElementPtr spec, ConstElementPtr data, ModuleSpec::validateSpecList(ConstElementPtr spec, ConstElementPtr data,
const bool full, ElementPtr errors) const const bool full, ElementPtr errors) const
{ {
bool validated = true; bool validated = true;
std::string cur_item_name; std::string cur_item_name;
BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) { BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
if (!validate_spec(cur_spec_el, data, full, errors)) { if (!validateSpec(cur_spec_el, data, full, errors)) {
validated = false; validated = false;
} }
} }
......
...@@ -88,7 +88,7 @@ namespace isc { namespace config { ...@@ -88,7 +88,7 @@ namespace isc { namespace config {
/// \param data The base \c Element of the data to check /// \param data The base \c Element of the data to check
/// \return true if the data conforms to the specification, /// \return true if the data conforms to the specification,
/// false otherwise. /// false otherwise.
bool validate_config(isc::data::ConstElementPtr data, bool validateConfig(isc::data::ConstElementPtr data,
const bool full = false) const; const bool full = false) const;
/// Validates the arguments for the given command /// Validates the arguments for the given command
...@@ -100,25 +100,25 @@ namespace isc { namespace config { ...@@ -100,25 +100,25 @@ namespace isc { namespace config {
/// StringElements to this list /// StringElements to this list
/// \return true if the command is known and the parameters are correct /// \return true if the command is known and the parameters are correct
/// false otherwise /// false otherwise
bool validate_command(const std::string& command, bool validateCommand(const std::string& command,
isc::data::ConstElementPtr args, isc::data::ConstElementPtr args,
isc::data::ElementPtr errors) const; isc::data::ElementPtr errors) const;
/// errors must be of type ListElement /// errors must be of type ListElement
bool validate_config(isc::data::ConstElementPtr data, const bool full, bool validateConfig(isc::data::ConstElementPtr data, const bool full,
isc::data::ElementPtr errors) const; isc::data::ElementPtr errors) const;
private: private:
bool validate_item(isc::data::ConstElementPtr spec, bool validateItem(isc::data::ConstElementPtr spec,
isc::data::ConstElementPtr data,
const bool full,
isc::data::ElementPtr errors) const;
bool validateSpec(isc::data::ConstElementPtr spec,
isc::data::ConstElementPtr data, isc::data::ConstElementPtr data,
const bool full, const bool full,
isc::data::ElementPtr errors) const; isc::data::ElementPtr errors) const;
bool validate_spec(isc::data::ConstElementPtr spec, bool validateSpecList(isc::data::ConstElementPtr spec,
isc::data::ConstElementPtr data,
const bool full,
isc::data::ElementPtr errors) const;
bool validate_spec_list(isc::data::ConstElementPtr spec,
isc::data::ConstElementPtr data, isc::data::ConstElementPtr data,
const bool full, const bool full,
isc::data::ElementPtr errors) const; isc::data::ElementPtr errors) const;
......
...@@ -30,7 +30,7 @@ std::string specfile(const std::string name) { ...@@ -30,7 +30,7 @@ std::string specfile(const std::string name) {
} }
void void
module_spec_error(const std::string& file, moduleSpecError(const std::string& file,
const std::string& error1, const std::string& error1,
const std::string& error2 = "", const std::string& error2 = "",
const std::string& error3 = "") const std::string& error3 = "")
...@@ -52,7 +52,7 @@ TEST(ModuleSpec, ReadingSpecfiles) { ...@@ -52,7 +52,7 @@ TEST(ModuleSpec, ReadingSpecfiles) {
->stringValue(), "Spec1"); ->stringValue(), "Spec1");
dd = moduleSpecFromFile(specfile("spec2.spec")); dd = moduleSpecFromFile(specfile("spec2.spec"));
EXPECT_EQ(dd.getFullSpec()->get("config_data")->size(), 6); EXPECT_EQ(dd.getFullSpec()->get("config_data")->size(), 6);
module_spec_error("doesnotexist", moduleSpecError("doesnotexist",
"Error opening ", "Error opening ",
specfile("doesnotexist"), specfile("doesnotexist"),
": No such file or directory"); ": No such file or directory");
...@@ -81,69 +81,65 @@ TEST(ModuleSpec, ReadingSpecfiles) { ...@@ -81,69 +81,65 @@ TEST(ModuleSpec, ReadingSpecfiles) {
} }
TEST(ModuleSpec, SpecfileItems) { TEST(ModuleSpec, SpecfileItems) {
module_spec_error("spec3.spec", moduleSpecError("spec3.spec",
"item_name missing in { \"item_default\": 1, \"item_optional\": false, \"item_type\": \"integer\" }"); "item_name missing in { \"item_default\": 1, \"item_optional\": false, \"item_type\": \"integer\" }");
module_spec_error("spec4.spec", moduleSpecError("spec4.spec",
"item_type missing in { \"item_default\": 1, \"item_name\": \"item1\", \"item_optional\": false }"); "item_type missing in { \"item_default\": 1, \"item_name\": \"item1\", \"item_optional\": false }");
module_spec_error("spec5.spec", moduleSpecError("spec5.spec",
"item_optional missing in { \"item_default\": 1, \"item_name\": \"item1\", \"item_type\": \"integer\" }"); "item_optional missing in { \"item_default\": 1, \"item_name\": \"item1\", \"item_type\": \"integer\" }");
module_spec_error("spec6.spec", moduleSpecError("spec6.spec",
"item_default missing in { \"item_name\": \"item1\", \"item_optional\": false, \"item_type\": \"integer\" }"); "item_default missing in { \"item_name\": \"item1\", \"item_optional\": false, \"item_type\": \"integer\" }");
module_spec_error("spec9.spec", moduleSpecError("spec9.spec",
"item_default not of type integer"); "item_default not of type integer");
module_spec_error("spec10.spec", moduleSpecError("spec10.spec",
"item_default not of type real"); "item_default not of type real");
module_spec_error("spec11.spec", moduleSpecError("spec11.spec",
"item_default not of type boolean"); "item_default not of type boolean");
module_spec_error("spec12.spec", moduleSpecError("spec12.spec",
"item_default not of type string"); "item_default not of type string");
module_spec_error("spec13.spec", moduleSpecError("spec13.spec",
"item_default not of type list"); "item_default not of type list");
module_spec_error("spec14.spec", moduleSpecError("spec14.spec",
"item_default not of type map"); "item_default not of type map");
module_spec_error("spec15.spec", moduleSpecError("spec15.spec",
"badname is not a valid type name"); "badname is not a valid type name");
} }
TEST(ModuleSpec, SpecfileConfigData) { TEST(ModuleSpec, SpecfileConfigData) {
module_spec_error("spec7.spec", moduleSpecError("spec7.spec",
"module_name missing in { }"); "module_name missing in { }");
module_spec_error("spec8.spec", moduleSpecError("spec8.spec",
"No module_spec in specification"); "No module_spec in specification");
module_spec_error("spec16.spec", moduleSpecError("spec16.spec",
"config_data is not a list of elements"); "config_data is not a list of elements");
module_spec_error("spec21.spec", moduleSpecError("spec21.spec",
"commands is not a list of elements"); "commands is not a list of elements");
} }
TEST(ModuleSpec, SpecfileCommands) { TEST(ModuleSpec, SpecfileCommands) {
module_spec_error("spec17.spec", moduleSpecError("spec17.spec",
"command_name missing in { \"command_args\": [ { \"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": false, \"item_type\": \"string\" } ], \"command_description\": \"Print the given message to stdout\" }"); "command_name missing in { \"command_args\": [ { \"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": false, \"item_type\": \"string\" } ], \"command_description\": \"Print the given message to stdout\" }");
module_spec_error("spec18.spec", moduleSpecError("spec18.spec",
"command_args missing in { \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\" }"); "command_args missing in { \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\" }");
module_spec_error("spec19.spec", moduleSpecError("spec19.spec",
"command_args not of type list"); "command_args not of type list");
module_spec_error("spec20.spec", moduleSpecError("spec20.spec",
"somethingbad is not a valid type name"); "somethingbad is not a valid type name");
/*
module_spec_error("spec22.spec",
"");
*/
} }
bool bool
data_test(const ModuleSpec& dd, const std::string& data_file_name) { dataTest(const ModuleSpec& dd, const std::string& data_file_name) {
std::ifstream data_file; std::ifstream data_file;
data_file.open(specfile(data_file_name).c_str()); data_file.open(specfile(data_file_name).c_str());
ConstElementPtr data = Element::fromJSON(data_file, data_file_name); ConstElementPtr data = Element::fromJSON(data_file, data_file_name);
data_file.close(); data_file.close();
return (dd.validate_config(data)); return (dd.validateConfig(data));
} }
bool bool
data_test_with_errors(const ModuleSpec& dd, const std::string& data_file_name, dataTestWithErrors(const ModuleSpec& dd, const std::string& data_file_name,
ElementPtr errors) ElementPtr errors)
{ {
std::ifstream data_file; std::ifstream data_file;
...@@ -152,28 +148,28 @@ data_test_with_errors(const ModuleSpec& dd, const std::string& data_file_name, ...@@ -152,28 +148,28 @@ data_test_with_errors(const ModuleSpec& dd, const std::string& data_file_name,
ConstElementPtr data = Element::fromJSON(data_file, data_file_name); ConstElementPtr data = Element::fromJSON(data_file, data_file_name);
data_file.close(); data_file.close();
return (dd.validate_config(data, true, errors)); return (dd.validateConfig(data, true, errors));
} }
TEST(ModuleSpec, DataValidation) { TEST(ModuleSpec, DataValidation) {
ModuleSpec dd = moduleSpecFromFile(specfile("spec22.spec")); ModuleSpec dd = moduleSpecFromFile(specfile("spec22.spec"));
EXPECT_TRUE(data_test(dd, "data22_1.data")); EXPECT_TRUE(dataTest(dd, "data22_1.data"));
EXPECT_FALSE(data_test(dd, "data22_2.data")); EXPECT_FALSE(dataTest(dd, "data22_2.data"));
EXPECT_FALSE(data_test(dd, "data22_3.data")); EXPECT_FALSE(dataTest(dd, "data22_3.data"));
EXPECT_FALSE(data_test(dd, "data22_4.data")); EXPECT_FALSE(dataTest(dd, "data22_4.data"));
EXPECT_FALSE(data_test(dd, "data22_5.data")); EXPECT_FALSE(dataTest(dd, "data22_5.data"));
EXPECT_TRUE(data_test(dd, "data22_6.data")); EXPECT_TRUE(dataTest(dd, "data22_6.data"));
EXPECT_TRUE(data_test(dd, "data22_7.data")); EXPECT_TRUE(dataTest(dd, "data22_7.data"));
EXPECT_FALSE(data_test(dd, "data22_8.data")); EXPECT_FALSE(dataTest(dd, "data22_8.data"));
EXPECT_FALSE(data_test(dd, "data22_9.data")); EXPECT_FALSE(dataTest(dd, "data22_9.data"));
ElementPtr errors = Element::createList(); ElementPtr errors = Element::createList();
EXPECT_FALSE(data_test_with_errors(dd, "data22_8.data", errors)); EXPECT_FALSE(dataTestWithErrors(dd, "data22_8.data", errors));
EXPECT_EQ("[ \"Type mismatch\" ]", errors->str()); EXPECT_EQ("[ \"Type mismatch\" ]", errors->str());
errors = Element::createList(); errors = Element::createList();
EXPECT_FALSE(data_test_with_errors(dd, "data22_9.data", errors)); EXPECT_FALSE(dataTestWithErrors(dd, "data22_9.data", errors));
EXPECT_EQ("[ \"Unknown item value_does_not_exist\" ]", errors->str()); EXPECT_EQ("[ \"Unknown item value_does_not_exist\" ]", errors->str());
} }
...@@ -182,33 +178,33 @@ TEST(ModuleSpec, CommandValidation) { ...@@ -182,33 +178,33 @@ TEST(ModuleSpec, CommandValidation) {
ConstElementPtr arg = Element::fromJSON("{}"); ConstElementPtr arg = Element::fromJSON("{}");
ElementPtr errors = Element::createList(); ElementPtr errors = Element::createList();
EXPECT_TRUE(dd.validate_command("shutdown", arg, errors)); EXPECT_TRUE(dd.validateCommand("shutdown", arg, errors));
EXPECT_EQ(errors->size(), 0); EXPECT_EQ(errors->size(), 0);
errors = Element::createList(); errors = Element::createList();
EXPECT_FALSE(dd.validate_command("unknowncommand", arg, errors)); EXPECT_FALSE(dd.validateCommand("unknowncommand", arg, errors));
EXPECT_EQ(errors->size(), 1); EXPECT_EQ(errors->size(), 1);
EXPECT_EQ(errors->get(0)->stringValue(), "Unknown command unknowncommand"); EXPECT_EQ(errors->get(0)->stringValue(), "Unknown command unknowncommand");
errors = Element::createList(); errors = Element::createList();
EXPECT_FALSE(dd.validate_command("print_message", arg, errors)); EXPECT_FALSE(dd.validateCommand("print_message", arg, errors));
EXPECT_EQ(errors->size(), 1); EXPECT_EQ(errors->size(), 1);
EXPECT_EQ(errors->get(0)->stringValue(), "Non-optional value missing"); EXPECT_EQ(errors->get(0)->stringValue(), "Non-optional value missing");
errors = Element::createList(); errors = Element::createList();
arg = Element::fromJSON("{ \"message\": \"Hello\" }"); arg = Element::fromJSON("{ \"message\": \"Hello\" }");
EXPECT_TRUE(dd.validate_command("print_message", arg, errors)); EXPECT_TRUE(dd.validateCommand("print_message", arg, errors));
EXPECT_EQ(errors->size(), 0); EXPECT_EQ(errors->size(), 0);
errors = Element::createList(); errors = Element::createList();
arg = Element::fromJSON("{ \"message\": \"Hello\", \"unknown_second_arg\": 1 }"); arg = Element::fromJSON("{ \"message\": \"Hello\", \"unknown_second_arg\": 1 }");
EXPECT_FALSE(dd.validate_command("print_message", arg, errors)); EXPECT_FALSE(dd.validateCommand("print_message", arg, errors));
EXPECT_EQ(errors->size(), 1); EXPECT_EQ(errors->size(), 1);
EXPECT_EQ(errors->get(0)->stringValue(), "Unknown item unknown_second_arg"); EXPECT_EQ(errors->get(0)->stringValue(), "Unknown item unknown_second_arg");
errors = Element::createList(); errors = Element::createList();
arg = Element::fromJSON("{ \"message\": 1 }"); arg = Element::fromJSON("{ \"message\": 1 }");
EXPECT_FALSE(dd.validate_command("print_message", arg, errors)); EXPECT_FALSE(dd.validateCommand("print_message", arg, errors));
EXPECT_EQ(errors->size(), 1); EXPECT_EQ(errors->size(), 1);
EXPECT_EQ(errors->get(0)->stringValue(), "Type mismatch"); EXPECT_EQ(errors->get(0)->stringValue(), "Type mismatch");
......
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