[svn] commit: r387 - in /branches/parkinglot: Makefile.am src/lib/cc/cpp/Makefile.am src/lib/cc/cpp/data.cc src/lib/cc/cpp/data.h src/lib/cc/cpp/data_unittests.cc src/lib/cc/cpp/run_unittests.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 18 17:41:23 UTC 2009
Author: jelte
Date: Fri Dec 18 17:41:23 2009
New Revision: 387
Log:
some unit tests for Elements, and fixed a few bugs while i was writing them
also added a is_null(ElementPtr) function
added a test target to the main makefile (which will execute any executable binary in the tree that ends with "unittests")
Added:
branches/parkinglot/src/lib/cc/cpp/data_unittests.cc
branches/parkinglot/src/lib/cc/cpp/run_unittests.cc
Modified:
branches/parkinglot/Makefile.am
branches/parkinglot/src/lib/cc/cpp/Makefile.am
branches/parkinglot/src/lib/cc/cpp/data.cc
branches/parkinglot/src/lib/cc/cpp/data.h
Modified: branches/parkinglot/Makefile.am
==============================================================================
--- branches/parkinglot/Makefile.am (original)
+++ branches/parkinglot/Makefile.am Fri Dec 18 17:41:23 2009
@@ -1,1 +1,5 @@
SUBDIRS = src
+
+# is there a better way to automate this?
+test: all
+ find . -name \*unittests -type f -executable -exec {} \;
Modified: branches/parkinglot/src/lib/cc/cpp/Makefile.am
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/Makefile.am (original)
+++ branches/parkinglot/src/lib/cc/cpp/Makefile.am Fri Dec 18 17:41:23 2009
@@ -2,3 +2,14 @@
lib_LIBRARIES = libcc.a
libcc_a_SOURCES = data.cc data.h session.cc session.h
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = data_unittests.cc run_unittests.cc
+run_unittests_CPPFLAGS = $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(GTEST_LDFLAGS)
+run_unittests_LDADD = libcc.a $(GTEST_LDADD)
+endif
+
+noinst_PROGRAMS = $(TESTS)
Modified: branches/parkinglot/src/lib/cc/cpp/data.cc
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data.cc (original)
+++ branches/parkinglot/src/lib/cc/cpp/data.cc Fri Dec 18 17:41:23 2009
@@ -69,7 +69,6 @@
Element::create(const bool b)
{
try {
- cout << "creating boolelement" << endl;
return ElementPtr(new BoolElement(b));
} catch (std::bad_alloc) {
return ElementPtr();
@@ -513,7 +512,12 @@
} else {
ElementPtr ce = get(id.substr(0, sep));
if (ce) {
- return ce->find(id.substr(sep+1));
+ // ignore trailing slash
+ if (sep+1 != id.size()) {
+ return ce->find(id.substr(sep+1));
+ } else {
+ return ce;
+ }
} else {
return ElementPtr();
}
@@ -894,3 +898,10 @@
}
return false;
}
+
+bool
+ISC::Data::is_null(ElementPtr p)
+{
+ return !p;
+}
+
Modified: branches/parkinglot/src/lib/cc/cpp/data.h
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data.h (original)
+++ branches/parkinglot/src/lib/cc/cpp/data.h Fri Dec 18 17:41:23 2009
@@ -87,7 +87,7 @@
virtual ElementPtr get(const int i) { throw TypeError(); };
virtual void set(const int i, ElementPtr element) { throw TypeError(); };
virtual void add(ElementPtr element) { throw TypeError(); };
- virtual void remove(ElementPtr element) { throw TypeError(); };
+ virtual void remove(const int i) { throw TypeError(); };
// for maps
virtual ElementPtr get(const std::string& name) { throw TypeError(); } ;
@@ -215,9 +215,10 @@
const std::vector<ElementPtr>& list_value() { return l; }
bool get_value(std::vector<ElementPtr>& t) { t = l; return true; };
bool set_value(const std::vector<ElementPtr>& v) { l = v; return true; };
- ElementPtr get(int i) { return l[i]; };
+ ElementPtr get(int i) { return l.at(i); };
void set(int i, ElementPtr e) { l[i] = e; };
void add(ElementPtr e) { l.push_back(e); };
+ void remove(int i) { l.erase(l.begin() + i); };
std::string str();
std::string str_xml(size_t prefix = 0);
std::string to_wire(int omit_length = 1);
@@ -257,6 +258,7 @@
bool find(const std::string& id, ElementPtr& t);
};
+ bool is_null(ElementPtr p);
} }
// add a << operator for output streams so we can do
More information about the bind10-changes
mailing list