[svn] commit: r708 - in /branches/parkinglot: ./ src/lib/config/cpp/ src/lib/config/python/isc/config/ src/lib/config/testdata/
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Feb 3 12:08:20 UTC 2010
Author: jelte
Date: Wed Feb 3 12:08:19 2010
New Revision: 708
Log:
tests for data_def.cc
Added:
branches/parkinglot/src/lib/config/cpp/data_def_unittests.cc
branches/parkinglot/src/lib/config/cpp/data_def_unittests_config.h.in
branches/parkinglot/src/lib/config/cpp/run_unittests.cc
branches/parkinglot/src/lib/config/testdata/
branches/parkinglot/src/lib/config/testdata/spec1.spec
branches/parkinglot/src/lib/config/testdata/spec2.spec
branches/parkinglot/src/lib/config/testdata/spec3.spec
branches/parkinglot/src/lib/config/testdata/spec4.spec
branches/parkinglot/src/lib/config/testdata/spec5.spec
branches/parkinglot/src/lib/config/testdata/spec6.spec
branches/parkinglot/src/lib/config/testdata/spec7.spec
branches/parkinglot/src/lib/config/testdata/spec8.spec
Modified:
branches/parkinglot/configure.ac
branches/parkinglot/src/lib/config/cpp/Makefile.am
branches/parkinglot/src/lib/config/cpp/data_def.cc
branches/parkinglot/src/lib/config/cpp/data_def.h
branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py
Modified: branches/parkinglot/configure.ac
==============================================================================
--- branches/parkinglot/configure.ac (original)
+++ branches/parkinglot/configure.ac Wed Feb 3 12:08:19 2010
@@ -184,6 +184,7 @@
src/bin/msgq/run_msgq.sh
src/bin/auth/config.h
src/bin/parkinglot/config.h
+ src/lib/config/cpp/data_def_unittests_config.h
src/lib/dns/cpp/gen-rdatacode.py
], [
chmod +x src/bin/cfgmgr/run_b10-cfgmgr.sh
Modified: branches/parkinglot/src/lib/config/cpp/Makefile.am
==============================================================================
--- branches/parkinglot/src/lib/config/cpp/Makefile.am (original)
+++ branches/parkinglot/src/lib/config/cpp/Makefile.am Wed Feb 3 12:08:19 2010
@@ -1,7 +1,19 @@
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/ext -Wall -Werror
-lib_LIBRARIES = libclient.a
-libclient_a_SOURCES = data_def.h data_def.cc ccsession.cc ccsession.h
+lib_LIBRARIES = libcfgclient.a
+libcfgclient_a_SOURCES = data_def.h data_def.cc ccsession.cc ccsession.h
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = data_def_unittests.cc run_unittests.cc
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+run_unittests_LDADD = libcfgclient.a $(GTEST_LDADD)
+run_unittests_LDADD += $(top_builddir)/src/lib/dns/cpp/libdns.la
+run_unittests_LDADD += $(top_builddir)/src/lib/cc/cpp/libcc.a
+endif
+
+noinst_PROGRAMS = $(TESTS)
-
Modified: branches/parkinglot/src/lib/config/cpp/data_def.cc
==============================================================================
--- branches/parkinglot/src/lib/config/cpp/data_def.cc (original)
+++ branches/parkinglot/src/lib/config/cpp/data_def.cc Wed Feb 3 12:08:19 2010
@@ -3,6 +3,8 @@
#include <sstream>
#include <iostream>
+#include <fstream>
+#include <cerrno>
#include <boost/foreach.hpp>
@@ -88,13 +90,14 @@
// todo: add stuff for type map
if (getType_value(spec->get("item_type")->stringValue()) == Element::map) {
check_leaf_item(spec, "map_item_spec", Element::list, true);
- check_config_item_list(spec);
+ check_config_item_list(spec->get("map_item_spec"));
}
}
static void
check_config_item_list(const ElementPtr& spec) {
if (spec->getType() != Element::list) {
+ std::cout << "[XX] ERROR IN: " << spec << std::endl;
throw DataDefinitionError("config_data is not a list of elements");
}
BOOST_FOREACH(ElementPtr item, spec->listValue()) {
@@ -141,6 +144,24 @@
throw DataDefinitionError("Data specification does not contain data_specification element");
} else {
check_data_specification(def->get("data_specification"));
+ }
+}
+
+DataDefinition::DataDefinition(const std::string& file_name,
+ const bool check)
+ throw(ParseError, DataDefinitionError) {
+ std::ifstream file;
+
+ file.open(file_name.c_str());
+ if (!file) {
+ std::stringstream errs;
+ errs << "Error opening " << file_name << ": " << strerror(errno);
+ throw DataDefinitionError(errs.str());
+ }
+
+ definition = Element::createFromString(file, file_name);
+ if (check) {
+ check_definition(definition);
}
}
Modified: branches/parkinglot/src/lib/config/cpp/data_def.h
==============================================================================
--- branches/parkinglot/src/lib/config/cpp/data_def.h (original)
+++ branches/parkinglot/src/lib/config/cpp/data_def.h Wed Feb 3 12:08:19 2010
@@ -39,9 +39,22 @@
/// the specification
/// \param e The Element containing the data specification
explicit DataDefinition(ElementPtr e) : definition(e) {};
+
+ /// Creates a \c DataDefinition instance from the contents
+ /// of the file given by file_name.
+ /// If check is true, and the definition is not of the correct
+ /// form, a DataDefinitionError is thrown. If the file could
+ /// not be parse, a ParseError is thrown.
+ /// \param file_name The file to be opened and parsed
+ /// \param check If true, the data definition in the file is
+ /// checked to be of the correct form
+ DataDefinition(const std::string& file_name, const bool check = true)
+ throw(ParseError, DataDefinitionError);
+
// todo: make check default false, or leave out option completely and always check?
- /// Creates a \c DataDefinition instance from the given .spec
- /// file stream. If check is true, and the definition is not of
+ /// Creates a \c DataDefinition instance from the given input
+ /// stream that contains the contents of a .spec file.
+ /// If check is true, and the definition is not of
/// the correct form, a DataDefinitionError is thrown. If the
/// file could not be parsed, a ParseError is thrown.
/// \param in The std::istream containing the .spec file data
Modified: branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py
==============================================================================
--- branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py (original)
+++ branches/parkinglot/src/lib/config/python/isc/config/datadefinition.py Wed Feb 3 12:08:19 2010
@@ -65,6 +65,11 @@
return self._data_spec["data_specification"]["module_name"]
def _check(data_spec):
+ """Checks the full specification. This is a dict that contains the
+ element "data_specification", which is in itself a dict that
+ must contain at least a "module_name" (string) and optionally
+ a "config_data" and a "commands" element, both of which are lists
+ of dicts. Raises a DataDefinitionError if there is a problem."""
if type(data_spec) != dict:
raise DataDefinitionError("data specification not a dict")
if "data_specification" not in data_spec:
@@ -81,12 +86,17 @@
# config data is a list of items represented by dicts that contain
# things like "item_name", depending on the type they can have
# specific subitems
+ """Checks a list that contains the configuration part of the
+ specification. Raises a DataDefinitionError if there is a
+ problem."""
if type(config_data) != list:
raise DataDefinitionError("config_data is not a list of items")
for config_item in config_data:
_checkItemSpec(config_item)
def _checkCommandSpec(commands):
+ """Checks the list that contains a set of commands. Raises a
+ DataDefinitionError is there is an error"""
if type(commands) != list:
raise DataDefinitionError("commands is not a list of commands")
for command in commands:
@@ -110,8 +120,9 @@
pass
def _checkItemSpec(config_item):
- # checks the dict that defines one config item
- # (i.e. containing "item_name", "item_type", etc
+ """Checks the dict that defines one config item
+ (i.e. containing "item_name", "item_type", etc.
+ Raises a DataDefinitionError if there is an error"""
if type(config_item) != dict:
raise DataDefinitionError("item spec not a dict")
if "item_name" not in config_item:
More information about the bind10-changes
mailing list