BIND 10 trac929, updated. 9ab3a2e5c02edc14f22562dc7a4d7e9087bca735 [trac929] add unit tests of the methods using some dummy spec files with the dummy data of statistics specification - getStatisticsSpec() - validateStatistics() - validateStatistics() - check_format()
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jul 22 11:03:55 UTC 2011
The branch, trac929 has been updated
discards 2bbe9d72f0f2a8652873a2600a510cc23cc3990e (commit)
discards 4089a03170200a230f71555885adf6beb4121a72 (commit)
discards ac74183b3cef60df0b9a83724ce4e0335305c86a (commit)
discards 144588b693f243388fedb35636706c1ce7f26fb3 (commit)
discards 610e2676a76e03d36d7fe8ea68b5afeffb79f45e (commit)
discards bf2bb0534e3b0914820469799d9d2491f0ba1694 (commit)
discards 2af93ce75f5c24ce2cab601a4aa102dedad69626 (commit)
discards a385d63aa6e6c32eaeb7253f9fa2a8ac76eaabdd (commit)
via 9ab3a2e5c02edc14f22562dc7a4d7e9087bca735 (commit)
via 456de3a5647fa836547b6238169aebbec933f852 (commit)
via 343ee47dcdf0d1d48eba525189db5c0cc789d4f3 (commit)
via 2d74f6935838788ac864de5f647734dd4aff085c (commit)
via 9162b03e7e66c7f3763e854ef6d7c56dd576aae6 (commit)
via 406019a4e371e1de2412bd206e299601eba545d9 (commit)
via 1d22cafef31ee83ab4ed646e67f9cd57ab1d30ce (commit)
via 2fc3572cc76548463f8342cd2f0d9b92b14bb732 (commit)
via 39901e5b831ba424c8aa17d06ecba87d53fdce4c (commit)
via 42042bbaeaa7bc1523bb23e3e6cb9f3a84a1638a (commit)
via 26100f264a9c48aa80748256db1e94c6091ba729 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (2bbe9d72f0f2a8652873a2600a510cc23cc3990e)
\
N -- N -- N (9ab3a2e5c02edc14f22562dc7a4d7e9087bca735)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9ab3a2e5c02edc14f22562dc7a4d7e9087bca735
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Jul 19 21:02:12 2011 +0900
[trac929]
add unit tests of the methods using some dummy spec files with the dummy data of statistics specification
- getStatisticsSpec()
- validateStatistics()
- validateStatistics()
- check_format()
add include of boost_foreach
update the year of copyright
commit 456de3a5647fa836547b6238169aebbec933f852
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Jul 19 20:57:32 2011 +0900
[trac929]
add some methods for statistics specification
- getStatisticsSpec()
- validateStatistics()
- validateStatistics()
update the year of copyright
commit 343ee47dcdf0d1d48eba525189db5c0cc789d4f3
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Jul 19 20:55:39 2011 +0900
[trac929]
addition and modification as a variant of the statistics part of module_spec.py
- add check_format which checks whether the given element is a valid statistics specification
- modify check_data_specification to add check of statistics specification
- add getStatisticsSpec() which returns statistics specification
- add two of validateStatistics which check whether specified data is valid for statistics specification
- modify validateItem to add check of item_format in specification
update the year of copyright
commit 2d74f6935838788ac864de5f647734dd4aff085c
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:47:09 2011 +0900
[trac929] add unittest of "get_statistics_spec"
commit 9162b03e7e66c7f3763e854ef6d7c56dd576aae6
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:46:57 2011 +0900
[trac929] add unittests for the functions:
- validate_format
- check_format
- validate_format
commit 406019a4e371e1de2412bd206e299601eba545d9
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:46:46 2011 +0900
[trac929] add "validate_statistics" which validates statistics specification in the spec file
It checks data types and data format of statistics specification
commit 1d22cafef31ee83ab4ed646e67f9cd57ab1d30ce
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:46:27 2011 +0900
[trac929] add "get_statistics_spec" into cfgmgr.py
it pushes contents in statistics category of each spec file.
commit 2fc3572cc76548463f8342cd2f0d9b92b14bb732
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:45:28 2011 +0900
[trac929] add COMMAND_GET_STATISTICS_SPEC for "get_statistics_spec"
commit 39901e5b831ba424c8aa17d06ecba87d53fdce4c
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:45:15 2011 +0900
[trac929] add a statistics category into "spec2.spec"
and modify message string to be compared with in EXPECT_EQ
commit 42042bbaeaa7bc1523bb23e3e6cb9f3a84a1638a
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Fri Jul 8 15:44:40 2011 +0900
[trac929] add some spec files for unittest of statistics category
-----------------------------------------------------------------------
Summary of changes:
src/bin/cfgmgr/plugins/logging.spec | 3 +-
src/bin/cfgmgr/plugins/tsig_keys.spec | 3 +-
src/bin/cmdctl/cmdctl.spec.pre.in | 3 +-
src/bin/dhcp6/dhcp6.spec | 3 +-
src/bin/resolver/resolver.spec.pre.in | 3 +-
src/bin/stats/stats-httpd.spec | 3 +-
src/bin/stats/stats-schema.spec | 3 +-
src/bin/stats/tests/testdata/stats_test.spec | 3 +-
src/bin/xfrin/xfrin.spec | 3 +-
src/bin/xfrout/xfrout.spec.pre.in | 3 +-
src/bin/zonemgr/zonemgr.spec.pre.in | 3 +-
src/lib/config/module_spec.cc | 84 +++++++++++-
src/lib/config/module_spec.h | 23 +++-
src/lib/config/tests/module_spec_unittests.cc | 145 +++++++++++++++++++-
.../python/isc/config/tests/module_spec_test.py | 3 +
15 files changed, 263 insertions(+), 25 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/cfgmgr/plugins/logging.spec b/src/bin/cfgmgr/plugins/logging.spec
index 37dab21..e377b0e 100644
--- a/src/bin/cfgmgr/plugins/logging.spec
+++ b/src/bin/cfgmgr/plugins/logging.spec
@@ -76,7 +76,6 @@
}
}
],
- "commands": [],
- "statistics": []
+ "commands": []
}
}
diff --git a/src/bin/cfgmgr/plugins/tsig_keys.spec b/src/bin/cfgmgr/plugins/tsig_keys.spec
index f404af0..e558dd2 100644
--- a/src/bin/cfgmgr/plugins/tsig_keys.spec
+++ b/src/bin/cfgmgr/plugins/tsig_keys.spec
@@ -16,7 +16,6 @@
}
}
],
- "commands": [],
- "statistics": []
+ "commands": []
}
}
diff --git a/src/bin/cmdctl/cmdctl.spec.pre.in b/src/bin/cmdctl/cmdctl.spec.pre.in
index 8651a70..537b678 100644
--- a/src/bin/cmdctl/cmdctl.spec.pre.in
+++ b/src/bin/cmdctl/cmdctl.spec.pre.in
@@ -33,8 +33,7 @@
"command_description": "shutdown cmdctl",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/dhcp6/dhcp6.spec b/src/bin/dhcp6/dhcp6.spec
index 9afc798..0e7e852 100644
--- a/src/bin/dhcp6/dhcp6.spec
+++ b/src/bin/dhcp6/dhcp6.spec
@@ -9,7 +9,6 @@
"item_default": "eth0"
}
],
- "commands": [],
- "statistics": []
+ "commands": []
}
}
diff --git a/src/bin/resolver/resolver.spec.pre.in b/src/bin/resolver/resolver.spec.pre.in
index f0ce600..076ef85 100644
--- a/src/bin/resolver/resolver.spec.pre.in
+++ b/src/bin/resolver/resolver.spec.pre.in
@@ -156,8 +156,7 @@
"command_description": "Shut down recursive DNS server",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/stats/stats-httpd.spec b/src/bin/stats/stats-httpd.spec
index 05b5ee9..6307135 100644
--- a/src/bin/stats/stats-httpd.spec
+++ b/src/bin/stats/stats-httpd.spec
@@ -49,7 +49,6 @@
"command_description": "Shut down the stats httpd",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/stats/stats-schema.spec b/src/bin/stats/stats-schema.spec
index abb035e..37e9c1a 100644
--- a/src/bin/stats/stats-schema.spec
+++ b/src/bin/stats/stats-schema.spec
@@ -82,7 +82,6 @@
"item_description": "A number of total query counts which all auth servers receive over UDP since they started initially"
}
],
- "commands": [],
- "statistics": []
+ "commands": []
}
}
diff --git a/src/bin/stats/tests/testdata/stats_test.spec b/src/bin/stats/tests/testdata/stats_test.spec
index fb7be2b..8136756 100644
--- a/src/bin/stats/tests/testdata/stats_test.spec
+++ b/src/bin/stats/tests/testdata/stats_test.spec
@@ -14,7 +14,6 @@
"command_description": "this is for testing",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/xfrin/xfrin.spec b/src/bin/xfrin/xfrin.spec
index 4380dec..a3e62ce 100644
--- a/src/bin/xfrin/xfrin.spec
+++ b/src/bin/xfrin/xfrin.spec
@@ -83,7 +83,6 @@
"command_description": "Shut down xfrin module",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/xfrout/xfrout.spec.pre.in b/src/bin/xfrout/xfrout.spec.pre.in
index d1f3a9b..2efa3d7 100644
--- a/src/bin/xfrout/xfrout.spec.pre.in
+++ b/src/bin/xfrout/xfrout.spec.pre.in
@@ -57,8 +57,7 @@
"command_description": "Shut down Xfrout",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/bin/zonemgr/zonemgr.spec.pre.in b/src/bin/zonemgr/zonemgr.spec.pre.in
index 99610df..36f02df 100644
--- a/src/bin/zonemgr/zonemgr.spec.pre.in
+++ b/src/bin/zonemgr/zonemgr.spec.pre.in
@@ -65,8 +65,7 @@
"command_description": "Shut down Zonemgr",
"command_args": []
}
- ],
- "statistics": []
+ ]
}
}
diff --git a/src/lib/config/module_spec.cc b/src/lib/config/module_spec.cc
index 1621fe3..b5644a8 100644
--- a/src/lib/config/module_spec.cc
+++ b/src/lib/config/module_spec.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 Internet Systems Consortium.
+// Copyright (C) 2010, 2011 Internet Systems Consortium.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -84,6 +84,54 @@ check_config_item_list(ConstElementPtr spec) {
}
}
+// checks whether the given element is a valid statistics specification
+// returns false if the specification is bad
+bool
+check_format(ConstElementPtr value, ConstElementPtr format_name) {
+ typedef std::map<std::string, std::string> format_types;
+ format_types time_formats;
+ // TODO: should be added other format types if necessary
+ time_formats.insert(
+ format_types::value_type("date-time", "%Y-%m-%dT%H:%M:%SZ") );
+ time_formats.insert(
+ format_types::value_type("date", "%Y-%m-%d") );
+ time_formats.insert(
+ format_types::value_type("time", "%H:%M:%S") );
+ BOOST_FOREACH (const format_types::value_type& f, time_formats) {
+ if (format_name->stringValue() == f.first) {
+ struct tm tm;
+ return (strptime(value->stringValue().c_str(),
+ f.second.c_str(), &tm) != NULL);
+ }
+ }
+ return (false);
+}
+
+void check_statistics_item_list(ConstElementPtr spec);
+
+void
+check_statistics_item_list(ConstElementPtr spec) {
+ if (spec->getType() != Element::list) {
+ throw ModuleSpecError("statistics is not a list of elements");
+ }
+ BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
+ check_config_item(item);
+ // additional checks for statistics
+ check_leaf_item(item, "item_title", Element::string, true);
+ check_leaf_item(item, "item_description", Element::string, true);
+ check_leaf_item(item, "item_format", Element::string, false);
+ // checks name of item_format and validation of item_default
+ if (item->contains("item_format")
+ && item->contains("item_default")) {
+ if(!check_format(item->get("item_default"),
+ item->get("item_format"))) {
+ throw ModuleSpecError(
+ "item_default not valid type of item_format");
+ }
+ }
+ }
+}
+
void
check_command(ConstElementPtr spec) {
check_leaf_item(spec, "command_name", Element::string, true);
@@ -113,6 +161,9 @@ check_data_specification(ConstElementPtr spec) {
if (spec->contains("commands")) {
check_command_list(spec->get("commands"));
}
+ if (spec->contains("statistics")) {
+ check_statistics_item_list(spec->get("statistics"));
+ }
}
// checks whether the given element is a valid module specification
@@ -162,6 +213,15 @@ ModuleSpec::getConfigSpec() const {
}
}
+ConstElementPtr
+ModuleSpec::getStatisticsSpec() const {
+ if (module_specification->contains("statistics")) {
+ return (module_specification->get("statistics"));
+ } else {
+ return (ElementPtr());
+ }
+}
+
const std::string
ModuleSpec::getModuleName() const {
return (module_specification->get("module_name")->stringValue());
@@ -183,6 +243,12 @@ ModuleSpec::validateConfig(ConstElementPtr data, const bool full) const {
}
bool
+ModuleSpec::validateStatistics(ConstElementPtr data, const bool full) const {
+ ConstElementPtr spec = module_specification->find("statistics");
+ return (validateSpecList(spec, data, full, ElementPtr()));
+}
+
+bool
ModuleSpec::validateCommand(const std::string& command,
ConstElementPtr args,
ElementPtr errors) const
@@ -220,6 +286,14 @@ ModuleSpec::validateConfig(ConstElementPtr data, const bool full,
return (validateSpecList(spec, data, full, errors));
}
+bool
+ModuleSpec::validateStatistics(ConstElementPtr data, const bool full,
+ ElementPtr errors) const
+{
+ ConstElementPtr spec = module_specification->find("statistics");
+ return (validateSpecList(spec, data, full, errors));
+}
+
ModuleSpec
moduleSpecFromFile(const std::string& file_name, const bool check)
throw(JSONError, ModuleSpecError)
@@ -327,6 +401,14 @@ ModuleSpec::validateItem(ConstElementPtr spec, ConstElementPtr data,
return (false);
}
}
+ if (spec->contains("item_format")) {
+ if (!check_format(data, spec->get("item_format"))) {
+ if (errors) {
+ errors->add(Element::create("Format mismatch"));
+ }
+ return (false);
+ }
+ }
return (true);
}
diff --git a/src/lib/config/module_spec.h b/src/lib/config/module_spec.h
index ab6e273..ce3762f 100644
--- a/src/lib/config/module_spec.h
+++ b/src/lib/config/module_spec.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 Internet Systems Consortium.
+// Copyright (C) 2010, 2011 Internet Systems Consortium.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -71,6 +71,12 @@ namespace isc { namespace config {
/// part of the specification
isc::data::ConstElementPtr getConfigSpec() const;
+ /// Returns the statistics part of the specification as an
+ /// ElementPtr
+ /// \return ElementPtr Shared pointer to the statistics
+ /// part of the specification
+ isc::data::ConstElementPtr getStatisticsSpec() const;
+
/// Returns the full module specification as an ElementPtr
/// \return ElementPtr Shared pointer to the specification
isc::data::ConstElementPtr getFullSpec() const {
@@ -95,6 +101,17 @@ namespace isc { namespace config {
bool validateConfig(isc::data::ConstElementPtr data,
const bool full = false) const;
+ // returns true if the given element conforms to this data
+ // statistics specification
+ /// Validates the given statistics data for this specification.
+ /// \param data The base \c Element of the data to check
+ /// \param full If true, all non-optional statistics parameters
+ /// must be specified.
+ /// \return true if the data conforms to the specification,
+ /// false otherwise.
+ bool validateStatistics(isc::data::ConstElementPtr data,
+ const bool full = false) const;
+
/// Validates the arguments for the given command
///
/// This checks the command and argument against the
@@ -142,6 +159,10 @@ namespace isc { namespace config {
bool validateConfig(isc::data::ConstElementPtr data, const bool full,
isc::data::ElementPtr errors) const;
+ /// errors must be of type ListElement
+ bool validateStatistics(isc::data::ConstElementPtr data, const bool full,
+ isc::data::ElementPtr errors) const;
+
private:
bool validateItem(isc::data::ConstElementPtr spec,
isc::data::ConstElementPtr data,
diff --git a/src/lib/config/tests/module_spec_unittests.cc b/src/lib/config/tests/module_spec_unittests.cc
index 1b43350..a33ba1e 100644
--- a/src/lib/config/tests/module_spec_unittests.cc
+++ b/src/lib/config/tests/module_spec_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009, 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@@ -18,6 +18,8 @@
#include <fstream>
+#include <boost/foreach.hpp>
+
#include <config/tests/data_def_unittests_config.h>
using namespace isc::data;
@@ -57,6 +59,7 @@ TEST(ModuleSpec, ReadingSpecfiles) {
dd = moduleSpecFromFile(specfile("spec2.spec"));
EXPECT_EQ("[ { \"command_args\": [ { \"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": false, \"item_type\": \"string\" } ], \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\" }, { \"command_args\": [ ], \"command_description\": \"Shut down BIND 10\", \"command_name\": \"shutdown\" } ]", dd.getCommandsSpec()->str());
+ EXPECT_EQ("[ { \"item_default\": \"1970-01-01T00:00:00Z\", \"item_description\": \"A dummy date time\", \"item_format\": \"date-time\", \"item_name\": \"dummy_time\", \"item_optional\": false, \"item_title\": \"Dummy Time\", \"item_type\": \"string\" } ]", dd.getStatisticsSpec()->str());
EXPECT_EQ("Spec2", dd.getModuleName());
EXPECT_EQ("", dd.getModuleDescription());
@@ -64,6 +67,11 @@ TEST(ModuleSpec, ReadingSpecfiles) {
EXPECT_EQ("Spec25", dd.getModuleName());
EXPECT_EQ("Just an empty module", dd.getModuleDescription());
EXPECT_THROW(moduleSpecFromFile(specfile("spec26.spec")), ModuleSpecError);
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec33.spec")), ModuleSpecError);
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec34.spec")), ModuleSpecError);
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec35.spec")), ModuleSpecError);
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec36.spec")), ModuleSpecError);
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec37.spec")), ModuleSpecError);
std::ifstream file;
file.open(specfile("spec1.spec").c_str());
@@ -71,6 +79,7 @@ TEST(ModuleSpec, ReadingSpecfiles) {
EXPECT_EQ(dd.getFullSpec()->get("module_name")
->stringValue(), "Spec1");
EXPECT_TRUE(isNull(dd.getCommandsSpec()));
+ EXPECT_TRUE(isNull(dd.getStatisticsSpec()));
std::ifstream file2;
file2.open(specfile("spec8.spec").c_str());
@@ -114,6 +123,12 @@ TEST(ModuleSpec, SpecfileConfigData) {
"commands is not a list of elements");
}
+TEST(ModuleSpec, SpecfileStatistics) {
+ moduleSpecError("spec35.spec", "item_default not valid type of item_format");
+ moduleSpecError("spec36.spec", "statistics is not a list of elements");
+ moduleSpecError("spec37.spec", "item_default not valid type of item_format");
+}
+
TEST(ModuleSpec, SpecfileCommands) {
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\" }");
@@ -137,6 +152,17 @@ dataTest(const ModuleSpec& dd, const std::string& data_file_name) {
}
bool
+statisticsTest(const ModuleSpec& dd, const std::string& data_file_name) {
+ std::ifstream data_file;
+
+ data_file.open(specfile(data_file_name).c_str());
+ ConstElementPtr data = Element::fromJSON(data_file, data_file_name);
+ data_file.close();
+
+ return (dd.validateStatistics(data));
+}
+
+bool
dataTestWithErrors(const ModuleSpec& dd, const std::string& data_file_name,
ElementPtr errors)
{
@@ -149,6 +175,19 @@ dataTestWithErrors(const ModuleSpec& dd, const std::string& data_file_name,
return (dd.validateConfig(data, true, errors));
}
+bool
+statisticsTestWithErrors(const ModuleSpec& dd, const std::string& data_file_name,
+ ElementPtr errors)
+{
+ std::ifstream data_file;
+
+ data_file.open(specfile(data_file_name).c_str());
+ ConstElementPtr data = Element::fromJSON(data_file, data_file_name);
+ data_file.close();
+
+ return (dd.validateStatistics(data, true, errors));
+}
+
TEST(ModuleSpec, DataValidation) {
ModuleSpec dd = moduleSpecFromFile(specfile("spec22.spec"));
@@ -175,6 +214,17 @@ TEST(ModuleSpec, DataValidation) {
EXPECT_EQ("[ \"Unknown item value_does_not_exist\" ]", errors->str());
}
+TEST(ModuleSpec, StatisticsValidation) {
+ ModuleSpec dd = moduleSpecFromFile(specfile("spec32.spec"));
+
+ EXPECT_TRUE(statisticsTest(dd, "data32_1.data"));
+ EXPECT_FALSE(statisticsTest(dd, "data32_2.data"));
+
+ ElementPtr errors = Element::createList();
+ EXPECT_FALSE(statisticsTestWithErrors(dd, "data32_2.data", errors));
+ EXPECT_EQ("[ \"Format mismatch\", \"Format mismatch\", \"Format mismatch\" ]", errors->str());
+}
+
TEST(ModuleSpec, CommandValidation) {
ModuleSpec dd = moduleSpecFromFile(specfile("spec2.spec"));
ConstElementPtr arg = Element::fromJSON("{}");
@@ -211,3 +261,96 @@ TEST(ModuleSpec, CommandValidation) {
EXPECT_EQ(errors->get(0)->stringValue(), "Type mismatch");
}
+
+TEST(ModuleSpec, CheckFormat) {
+
+ const std::string json_begin = "{ \"module_spec\": { \"module_name\": \"Foo\", \"statistics\": [ { \"item_name\": \"dummy_time\", \"item_type\": \"string\", \"item_optional\": true, \"item_title\": \"Dummy Time\", \"item_description\": \"A dummy date time\"";
+ const std::string json_end = " } ] } }";
+ std::string item_default;
+ std::string item_format;
+ std::vector<std::string> specs;
+ ConstElementPtr el;
+
+ specs.clear();
+ item_default = "\"item_default\": \"2011-05-27T19:42:57Z\",";
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"2011-05-27\",";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"19:42:57Z\",";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_default + item_format);
+
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_format);
+ item_default = "";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_format);
+ item_default = "";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_format);
+
+ item_default = "\"item_default\": \"a\"";
+ specs.push_back("," + item_default);
+ item_default = "\"item_default\": \"b\"";
+ specs.push_back("," + item_default);
+ item_default = "\"item_default\": \"c\"";
+ specs.push_back("," + item_default);
+
+ item_format = "\"item_format\": \"dummy\"";
+ specs.push_back("," + item_format);
+
+ specs.push_back("");
+
+ BOOST_FOREACH(std::string s, specs) {
+ el = Element::fromJSON(json_begin + s + json_end)->get("module_spec");
+ EXPECT_NO_THROW(ModuleSpec(el, true));
+ }
+
+ specs.clear();
+ item_default = "\"item_default\": \"2011-05-27T19:42:57Z\",";
+ item_format = "\"item_format\": \"dummy\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"2011-05-27\",";
+ item_format = "\"item_format\": \"dummy\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"19:42:57Z\",";
+ item_format = "\"item_format\": \"dummy\"";
+ specs.push_back("," + item_default + item_format);
+
+ item_default = "\"item_default\": \"2011-13-99T99:99:99Z\",";
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"2011-13-99\",";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"99:99:99Z\",";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_default + item_format);
+
+ item_default = "\"item_default\": \"1\",";
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"1\",";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"1\",";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_default + item_format);
+
+ item_default = "\"item_default\": \"\",";
+ item_format = "\"item_format\": \"date-time\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"\",";
+ item_format = "\"item_format\": \"date\"";
+ specs.push_back("," + item_default + item_format);
+ item_default = "\"item_default\": \"\",";
+ item_format = "\"item_format\": \"time\"";
+ specs.push_back("," + item_default + item_format);
+
+ BOOST_FOREACH(std::string s, specs) {
+ el = Element::fromJSON(json_begin + s + json_end)->get("module_spec");
+ EXPECT_THROW(ModuleSpec(el, true), ModuleSpecError);
+ }
+}
diff --git a/src/lib/python/isc/config/tests/module_spec_test.py b/src/lib/python/isc/config/tests/module_spec_test.py
index 953a049..6ff9868 100644
--- a/src/lib/python/isc/config/tests/module_spec_test.py
+++ b/src/lib/python/isc/config/tests/module_spec_test.py
@@ -343,6 +343,9 @@ class TestModuleSpec(unittest.TestCase):
self.assertFalse(isc.config.module_spec._check_format('2011-05-27T19:42:57Z', 'dummy'))
self.assertFalse(isc.config.module_spec._check_format('2011-05-27', 'dummy'))
self.assertFalse(isc.config.module_spec._check_format('19:42:57', 'dummy'))
+ self.assertFalse(isc.config.module_spec._check_format('2011-13-99T99:99:99Z', 'date-time'))
+ self.assertFalse(isc.config.module_spec._check_format('2011-13-99', 'date'))
+ self.assertFalse(isc.config.module_spec._check_format('99:99:99', 'time'))
self.assertFalse(isc.config.module_spec._check_format('', 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, 'date-time'))
self.assertFalse(isc.config.module_spec._check_format(None, None))
More information about the bind10-changes
mailing list