BIND 10 master, updated. 932edbb0ec8a4dbb820c6cccf4a0becd9df533c2 Merge branch 'master' into trac2302
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Oct 14 15:15:28 UTC 2012
The branch, master has been updated
via 932edbb0ec8a4dbb820c6cccf4a0becd9df533c2 (commit)
via 55178c917f014922f8213921a44f0443b3dc40f8 (commit)
via 7bb6309fbc34c32a0e37ea2b2175738b6110bcf7 (commit)
via fd45bcdb5182e09d33b92e222772b54c6e744d01 (commit)
via 2975fbae44dbaacdff7b9039a395b00c4375f01b (commit)
via 593b348cbb8207fca3e9d01620794cfe118455b2 (commit)
from f97ecbe97b6b3e098ebde2c984041dd24ce2dbbe (commit)
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 932edbb0ec8a4dbb820c6cccf4a0becd9df533c2
Merge: 55178c9 f97ecbe
Author: Mukund Sivaraman <muks at isc.org>
Date: Sun Oct 14 20:13:42 2012 +0530
Merge branch 'master' into trac2302
-----------------------------------------------------------------------
Summary of changes:
src/lib/cc/data.cc | 16 +--
src/lib/cc/data.h | 44 +++----
src/lib/cc/tests/data_unittests.cc | 249 ++++++++++++++++++++++++++++--------
3 files changed, 227 insertions(+), 82 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc
index 47b1eb1..8d9b87d 100644
--- a/src/lib/cc/data.cc
+++ b/src/lib/cc/data.cc
@@ -57,32 +57,32 @@ Element::toWire(std::ostream& ss) const {
}
bool
-Element::getValue(long int&) {
+Element::getValue(long int&) const {
return (false);
}
bool
-Element::getValue(double&) {
+Element::getValue(double&) const {
return (false);
}
bool
-Element::getValue(bool&) {
+Element::getValue(bool&) const {
return (false);
}
bool
-Element::getValue(std::string&) {
+Element::getValue(std::string&) const {
return (false);
}
bool
-Element::getValue(std::vector<ConstElementPtr>&) {
+Element::getValue(std::vector<ConstElementPtr>&) const {
return (false);
}
bool
-Element::getValue(std::map<std::string, ConstElementPtr>&) {
+Element::getValue(std::map<std::string, ConstElementPtr>&) const {
return (false);
}
@@ -167,7 +167,7 @@ Element::find(const std::string&) const {
}
bool
-Element::find(const std::string&, ConstElementPtr) const {
+Element::find(const std::string&, ConstElementPtr&) const {
return (false);
}
@@ -812,7 +812,7 @@ MapElement::set(const std::string& key, ConstElementPtr value) {
}
bool
-MapElement::find(const std::string& id, ConstElementPtr t) const {
+MapElement::find(const std::string& id, ConstElementPtr& t) const {
try {
ConstElementPtr p = find(id);
if (p) {
diff --git a/src/lib/cc/data.h b/src/lib/cc/data.h
index 5c731e6..c1147a2 100644
--- a/src/lib/cc/data.h
+++ b/src/lib/cc/data.h
@@ -71,7 +71,7 @@ public:
/// the type in question.
///
class Element {
-
+
private:
// technically the type could be omitted; is it useful?
// should we remove it or replace it with a pure virtual
@@ -112,7 +112,7 @@ public:
/// \returns true if the other ElementPtr has the same type and
/// value
virtual bool equals(const Element& other) const = 0;
-
+
/// Converts the Element to JSON format and appends it to
/// the given stringstream.
virtual void toJSON(std::ostream& ss) const = 0;
@@ -152,12 +152,12 @@ public:
/// data to the given reference and returning true
///
//@{
- virtual bool getValue(long int& t);
- virtual bool getValue(double& t);
- virtual bool getValue(bool& t);
- virtual bool getValue(std::string& t);
- virtual bool getValue(std::vector<ConstElementPtr>& t);
- virtual bool getValue(std::map<std::string, ConstElementPtr>& t);
+ virtual bool getValue(long int& t) const;
+ virtual bool getValue(double& t) const;
+ virtual bool getValue(bool& t) const;
+ virtual bool getValue(std::string& t) const;
+ virtual bool getValue(std::vector<ConstElementPtr>& t) const;
+ virtual bool getValue(std::map<std::string, ConstElementPtr>& t) const;
//@}
///
@@ -209,7 +209,7 @@ public:
virtual size_t size() const;
//@}
-
+
/// \name MapElement functions
///
/// \brief If the Element on which these functions are called are not
@@ -253,12 +253,12 @@ public:
/// \param identifier The identifier of the element to find
/// \param t Reference to store the resulting ElementPtr, if found.
/// \return true if the element was found, false if not.
- virtual bool find(const std::string& identifier, ConstElementPtr t) const;
+ virtual bool find(const std::string& identifier, ConstElementPtr& t) const;
//@}
/// \name Factory functions
-
+
// TODO: should we move all factory functions to a different class
// so as not to burden the Element base with too many functions?
// and/or perhaps even to a separate header?
@@ -349,7 +349,7 @@ public:
/// These function pparse the wireformat at the given stringstream
/// (of the given length). If there is a parse error an exception
/// of the type isc::cc::DecodeError is raised.
-
+
//@{
/// Creates an Element from the wire format in the given
/// stringstream of the given length.
@@ -378,7 +378,7 @@ public:
IntElement(long int v) : Element(integer), i(v) { }
long int intValue() const { return (i); }
using Element::getValue;
- bool getValue(long int& t) { t = i; return (true); }
+ bool getValue(long int& t) const { t = i; return (true); }
using Element::setValue;
bool setValue(const long int v) { i = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -392,7 +392,7 @@ public:
DoubleElement(double v) : Element(real), d(v) {};
double doubleValue() const { return (d); }
using Element::getValue;
- bool getValue(double& t) { t = d; return (true); }
+ bool getValue(double& t) const { t = d; return (true); }
using Element::setValue;
bool setValue(const double v) { d = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -406,7 +406,7 @@ public:
BoolElement(const bool v) : Element(boolean), b(v) {};
bool boolValue() const { return (b); }
using Element::getValue;
- bool getValue(bool& t) { t = b; return (true); }
+ bool getValue(bool& t) const { t = b; return (true); }
using Element::setValue;
bool setValue(const bool v) { b = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -427,7 +427,7 @@ public:
StringElement(std::string v) : Element(string), s(v) {};
std::string stringValue() const { return (s); }
using Element::getValue;
- bool getValue(std::string& t) { t = s; return (true); }
+ bool getValue(std::string& t) const { t = s; return (true); }
using Element::setValue;
bool setValue(const std::string& v) { s = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -441,7 +441,7 @@ public:
ListElement() : Element(list) {}
const std::vector<ConstElementPtr>& listValue() const { return (l); }
using Element::getValue;
- bool getValue(std::vector<ConstElementPtr>& t) {
+ bool getValue(std::vector<ConstElementPtr>& t) const {
t = l;
return (true);
}
@@ -474,7 +474,7 @@ public:
return (m);
}
using Element::getValue;
- bool getValue(std::map<std::string, ConstElementPtr>& t) {
+ bool getValue(std::map<std::string, ConstElementPtr>& t) const {
t = m;
return (true);
}
@@ -495,7 +495,7 @@ public:
return (m.find(s) != m.end());
}
void toJSON(std::ostream& ss) const;
-
+
// we should name the two finds better...
// find the element at id; raises TypeError if one of the
// elements at path except the one we're looking for is not a
@@ -507,7 +507,7 @@ public:
// returns true if found, or false if not found (either because
// it doesnt exist or one of the elements in the path is not
// a MapElement)
- bool find(const std::string& id, ConstElementPtr t) const;
+ bool find(const std::string& id, ConstElementPtr& t) const;
bool equals(const Element& other) const;
};
@@ -569,6 +569,6 @@ bool operator!=(const Element& a, const Element& b);
} }
#endif // _ISC_DATA_H
-// Local Variables:
+// Local Variables:
// mode: c++
-// End:
+// End:
diff --git a/src/lib/cc/tests/data_unittests.cc b/src/lib/cc/tests/data_unittests.cc
index 87d92f6..1565418 100644
--- a/src/lib/cc/tests/data_unittests.cc
+++ b/src/lib/cc/tests/data_unittests.cc
@@ -112,7 +112,7 @@ TEST(Element, from_and_to_json) {
std::string s = std::string(pe.what());
EXPECT_EQ("String expected in <string>:1:3", s);
}
-
+
sv.clear();
sv.push_back("{1}");
//ElementPtr ep = Element::fromJSON("\"aaa\nbbb\"err");
@@ -172,14 +172,14 @@ TEST(Element, from_and_to_json) {
}
-TEST(Element, create_and_value_throws) {
- // this test checks whether elements throw exceptions if the
- // incorrect type is requested
- ElementPtr el;
+template <typename T>
+void
+testGetValueInt() {
+ T el;
long int i;
double d;
bool b;
- std::string s("asdf");
+ std::string s;
std::vector<ConstElementPtr> v;
std::map<std::string, ConstElementPtr> m;
@@ -196,27 +196,19 @@ TEST(Element, create_and_value_throws) {
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
- EXPECT_EQ(i, 1);
- i = 2;
- EXPECT_TRUE(el->setValue(i));
- EXPECT_EQ(2, el->intValue());
- EXPECT_FALSE(el->setValue(d));
- EXPECT_FALSE(el->setValue(b));
- EXPECT_FALSE(el->setValue(s));
- EXPECT_FALSE(el->setValue(v));
- EXPECT_FALSE(el->setValue(m));
- EXPECT_THROW(el->get(1), TypeError);
- EXPECT_THROW(el->set(1, el), TypeError);
- EXPECT_THROW(el->add(el), TypeError);
- EXPECT_THROW(el->remove(1), TypeError);
- EXPECT_THROW(el->size(), TypeError);
- EXPECT_THROW(el->get("foo"), TypeError);
- EXPECT_THROW(el->set("foo", el), TypeError);
- EXPECT_THROW(el->remove("foo"), TypeError);
- EXPECT_THROW(el->contains("foo"), TypeError);
- ConstElementPtr tmp;
- EXPECT_FALSE(el->find("foo", tmp));
-
+ EXPECT_EQ(1, i);
+}
+
+template <typename T>
+void
+testGetValueDouble() {
+ T el;
+ long int i;
+ double d;
+ bool b;
+ std::string s;
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
el = Element::create(1.1);
EXPECT_THROW(el->intValue(), TypeError);
@@ -231,15 +223,19 @@ TEST(Element, create_and_value_throws) {
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
- EXPECT_EQ(d, 1.1);
- d = 2.2;
- EXPECT_TRUE(el->setValue(d));
- EXPECT_EQ(2.2, el->doubleValue());
- EXPECT_FALSE(el->setValue(i));
- EXPECT_FALSE(el->setValue(b));
- EXPECT_FALSE(el->setValue(s));
- EXPECT_FALSE(el->setValue(v));
- EXPECT_FALSE(el->setValue(m));
+ EXPECT_EQ(1.1, d);
+}
+
+template <typename T>
+void
+testGetValueBool() {
+ T el;
+ long int i;
+ double d;
+ bool b;
+ std::string s;
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
el = Element::create(true);
EXPECT_THROW(el->intValue(), TypeError);
@@ -254,10 +250,19 @@ TEST(Element, create_and_value_throws) {
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
- EXPECT_EQ(b, true);
- b = false;
- EXPECT_TRUE(el->setValue(b));
- EXPECT_FALSE(el->boolValue());
+ EXPECT_EQ(true, b);
+}
+
+template <typename T>
+void
+testGetValueString() {
+ T el;
+ long int i;
+ double d;
+ bool b;
+ std::string s;
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
el = Element::create("foo");
EXPECT_THROW(el->intValue(), TypeError);
@@ -272,10 +277,19 @@ TEST(Element, create_and_value_throws) {
EXPECT_TRUE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
- EXPECT_EQ(s, "foo");
- s = "bar";
- EXPECT_TRUE(el->setValue(s));
- EXPECT_EQ("bar", el->stringValue());
+ EXPECT_EQ("foo", s);
+}
+
+template <typename T>
+void
+testGetValueList() {
+ T el;
+ long int i;
+ double d;
+ bool b;
+ std::string s;
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
el = Element::createList();
EXPECT_THROW(el->intValue(), TypeError);
@@ -291,9 +305,18 @@ TEST(Element, create_and_value_throws) {
EXPECT_TRUE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
EXPECT_EQ("[ ]", el->str());
- v.push_back(Element::create(1));
- EXPECT_TRUE(el->setValue(v));
- EXPECT_EQ("[ 1 ]", el->str());
+}
+
+template <typename T>
+void
+testGetValueMap() {
+ T el;
+ long int i;
+ double d;
+ bool b;
+ std::string s;
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
el = Element::createMap();
EXPECT_THROW(el->intValue(), TypeError);
@@ -308,7 +331,128 @@ TEST(Element, create_and_value_throws) {
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_TRUE(el->getValue(m));
+ EXPECT_EQ("{ }", el->str());
+}
+
+TEST(Element, create_and_value_throws) {
+ // this test checks whether elements throw exceptions if the
+ // incorrect type is requested
+ ElementPtr el;
+ ConstElementPtr cel;
+ long int i = 0;
+ double d = 0.0;
+ bool b = false;
+ std::string s("asdf");
+ std::vector<ConstElementPtr> v;
+ std::map<std::string, ConstElementPtr> m;
+ ConstElementPtr tmp;
+
+ testGetValueInt<ElementPtr>();
+ testGetValueInt<ConstElementPtr>();
+
+ el = Element::create(1);
+ i = 2;
+ EXPECT_TRUE(el->setValue(i));
+ EXPECT_EQ(2, el->intValue());
+ EXPECT_FALSE(el->setValue(d));
+ EXPECT_FALSE(el->setValue(b));
+ EXPECT_FALSE(el->setValue(s));
+ EXPECT_FALSE(el->setValue(v));
+ EXPECT_FALSE(el->setValue(m));
+ EXPECT_THROW(el->get(1), TypeError);
+ EXPECT_THROW(el->set(1, el), TypeError);
+ EXPECT_THROW(el->add(el), TypeError);
+ EXPECT_THROW(el->remove(1), TypeError);
+ EXPECT_THROW(el->size(), TypeError);
+ EXPECT_THROW(el->get("foo"), TypeError);
+ EXPECT_THROW(el->set("foo", el), TypeError);
+ EXPECT_THROW(el->remove("foo"), TypeError);
+ EXPECT_THROW(el->contains("foo"), TypeError);
+ EXPECT_FALSE(el->find("foo", tmp));
+
+ testGetValueDouble<ElementPtr>();
+ testGetValueDouble<ConstElementPtr>();
+
+ el = Element::create(1.1);
+ d = 2.2;
+ EXPECT_TRUE(el->setValue(d));
+ EXPECT_EQ(2.2, el->doubleValue());
+ EXPECT_FALSE(el->setValue(i));
+ EXPECT_FALSE(el->setValue(b));
+ EXPECT_FALSE(el->setValue(s));
+ EXPECT_FALSE(el->setValue(v));
+ EXPECT_FALSE(el->setValue(m));
+ EXPECT_THROW(el->get(1), TypeError);
+ EXPECT_THROW(el->set(1, el), TypeError);
+ EXPECT_THROW(el->add(el), TypeError);
+ EXPECT_THROW(el->remove(1), TypeError);
+ EXPECT_THROW(el->size(), TypeError);
+ EXPECT_THROW(el->get("foo"), TypeError);
+ EXPECT_THROW(el->set("foo", el), TypeError);
+ EXPECT_THROW(el->remove("foo"), TypeError);
+ EXPECT_THROW(el->contains("foo"), TypeError);
+ EXPECT_FALSE(el->find("foo", tmp));
+
+ testGetValueBool<ElementPtr>();
+ testGetValueBool<ConstElementPtr>();
+ el = Element::create(true);
+ b = false;
+ EXPECT_TRUE(el->setValue(b));
+ EXPECT_FALSE(el->boolValue());
+ EXPECT_FALSE(el->setValue(i));
+ EXPECT_FALSE(el->setValue(d));
+ EXPECT_FALSE(el->setValue(s));
+ EXPECT_FALSE(el->setValue(v));
+ EXPECT_FALSE(el->setValue(m));
+ EXPECT_THROW(el->get(1), TypeError);
+ EXPECT_THROW(el->set(1, el), TypeError);
+ EXPECT_THROW(el->add(el), TypeError);
+ EXPECT_THROW(el->remove(1), TypeError);
+ EXPECT_THROW(el->size(), TypeError);
+ EXPECT_THROW(el->get("foo"), TypeError);
+ EXPECT_THROW(el->set("foo", el), TypeError);
+ EXPECT_THROW(el->remove("foo"), TypeError);
+ EXPECT_THROW(el->contains("foo"), TypeError);
+ EXPECT_FALSE(el->find("foo", tmp));
+
+ testGetValueString<ElementPtr>();
+ testGetValueString<ConstElementPtr>();
+
+ el = Element::create("foo");
+ s = "bar";
+ EXPECT_TRUE(el->setValue(s));
+ EXPECT_EQ("bar", el->stringValue());
+ EXPECT_FALSE(el->setValue(i));
+ EXPECT_FALSE(el->setValue(b));
+ EXPECT_FALSE(el->setValue(d));
+ EXPECT_FALSE(el->setValue(v));
+ EXPECT_FALSE(el->setValue(m));
+ EXPECT_THROW(el->get(1), TypeError);
+ EXPECT_THROW(el->set(1, el), TypeError);
+ EXPECT_THROW(el->add(el), TypeError);
+ EXPECT_THROW(el->remove(1), TypeError);
+ EXPECT_THROW(el->size(), TypeError);
+ EXPECT_THROW(el->get("foo"), TypeError);
+ EXPECT_THROW(el->set("foo", el), TypeError);
+ EXPECT_THROW(el->remove("foo"), TypeError);
+ EXPECT_THROW(el->contains("foo"), TypeError);
+ EXPECT_FALSE(el->find("foo", tmp));
+
+ testGetValueList<ElementPtr>();
+ testGetValueList<ConstElementPtr>();
+
+ el = Element::createList();
+ v.push_back(Element::create(1));
+ EXPECT_TRUE(el->setValue(v));
+ EXPECT_EQ("[ 1 ]", el->str());
+
+ testGetValueMap<ElementPtr>();
+ testGetValueMap<ConstElementPtr>();
+
+ el = Element::createMap();
+ EXPECT_NO_THROW(el->set("foo", Element::create("bar")));
+ EXPECT_EQ("{ \"foo\": \"bar\" }", el->str());
}
// Helper for escape check; it puts the given string in a StringElement,
@@ -382,7 +526,7 @@ TEST(Element, MapElement) {
// this function checks the specific functions for ListElements
ElementPtr el = Element::fromJSON("{ \"name\": \"foo\", \"value1\": \"bar\", \"value2\": { \"number\": 42 } }");
ConstElementPtr el2;
-
+
EXPECT_EQ(el->get("name")->stringValue(), "foo");
EXPECT_EQ(el->get("value2")->getType(), Element::map);
@@ -396,11 +540,12 @@ TEST(Element, MapElement) {
EXPECT_EQ(el->find("value2/number")->intValue(), 42);
EXPECT_TRUE(isNull(el->find("value2/nothing/")));
-
+
EXPECT_EQ(el->find("value1")->stringValue(), "bar");
EXPECT_EQ(el->find("value1/")->stringValue(), "bar");
-
+
EXPECT_TRUE(el->find("value1", el2));
+ EXPECT_EQ("bar", el2->stringValue());
EXPECT_FALSE(el->find("name/error", el2));
// A map element whose (only) element has the maximum length of tag.
@@ -410,7 +555,7 @@ TEST(Element, MapElement) {
"9123456789abcdefa123456789abcdefb123456789abcdef"
"c123456789abcdefd123456789abcdefe123456789abcdef"
"f123456789abcde");
-
+
EXPECT_EQ(255, long_maptag.length()); // check prerequisite
el = Element::fromJSON("{ \"" + long_maptag + "\": \"bar\"}");
EXPECT_EQ("bar", el->find(long_maptag)->stringValue());
@@ -689,7 +834,7 @@ TEST(Element, merge) {
c = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }");
merge(b, a);
EXPECT_EQ(*b, *c);
-
+
// And some tests with multiple values
a = Element::fromJSON("{ \"a\": 1, \"b\": true, \"c\": null }");
b = Element::fromJSON("{ \"a\": 1, \"b\": null, \"c\": \"a string\" }");
More information about the bind10-changes
mailing list