BIND 10 trac2986test, updated. 58b258501da3c477fe07149bd48eb1174da046de [2986test] Automatic type conversion among intElement, uint64Element and doubleElement
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 20 06:28:56 UTC 2013
The branch, trac2986test has been updated
via 58b258501da3c477fe07149bd48eb1174da046de (commit)
from 3cbf908f8e18d61510752315edbcf990a6686e11 (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 58b258501da3c477fe07149bd48eb1174da046de
Author: Kazunori Fujiwara <fujiwara at wide.ad.jp>
Date: Thu Jun 20 15:28:12 2013 +0900
[2986test] Automatic type conversion among intElement, uint64Element and doubleElement
-----------------------------------------------------------------------
Summary of changes:
src/lib/cc/data.h | 52 ++++++++++++++++++++++++++++++++++++
src/lib/cc/tests/data_unittests.cc | 10 ++++---
2 files changed, 58 insertions(+), 4 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/cc/data.h b/src/lib/cc/data.h
index 26a9e0a..6c85f52 100644
--- a/src/lib/cc/data.h
+++ b/src/lib/cc/data.h
@@ -391,8 +391,20 @@ public:
isc_throw(TypeError, "uint64Value() called on negative integer Element");
}
};
+ double doubleValue() const {
+ return (i);
+ }
using Element::getValue;
bool getValue(int64_t& t) const { t = i; return (true); }
+ bool getValue(uint64_t& t) const {
+ if (i >= 0) {
+ t = i;
+ return (true);
+ } else {
+ isc_throw(TypeError, "uint64Value() called on negative integer Element");
+ }
+ }
+ bool getValue(double& t) const { t = i; return (true); }
using Element::setValue;
bool setValue(const int64_t v) { i = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -412,8 +424,20 @@ public:
isc_throw(TypeError, "intValue() called on uint64 Element");
}
};
+ double doubleValue() const {
+ return (i);
+ }
using Element::getValue;
bool getValue(uint64_t& t) const { t = i; return (true); }
+ bool getValue(int64_t& t) const {
+ if (i <= LLONG_MAX) {
+ t = i;
+ return (true);
+ } else {
+ isc_throw(TypeError, "getValue(int64_t&) called on uint64 Element");
+ }
+ }
+ bool getValue(double& t) const { t = i; return (true); }
using Element::setValue;
bool setValue(const uint64_t v) { i = v; return (true); }
void toJSON(std::ostream& ss) const;
@@ -426,8 +450,36 @@ class DoubleElement : public Element {
public:
DoubleElement(double v) : Element(real), d(v) {};
double doubleValue() const { return (d); }
+ int64_t intValue() const {
+ if (d <= LLONG_MAX && d >= LLONG_MIN) {
+ return d;
+ }
+ isc_throw(TypeError, "intValue() called on double Element");
+ }
+ uint64_t uint64Value() const {
+ if (d <= ULLONG_MAX && d >= 0) {
+ return d;
+ }
+ isc_throw(TypeError, "uint64Value() called on double Element");
+ }
using Element::getValue;
bool getValue(double& t) const { t = d; return (true); }
+ bool getValue(int64_t& t) const {
+ if (d <= LLONG_MAX) {
+ t = d;
+ return (true);
+ } else {
+ isc_throw(TypeError, "getValue(int64_t&) called on double Element");
+ }
+ }
+ bool getValue(uint64_t& t) const {
+ if (d >= 0) {
+ t = d;
+ return (true);
+ } else {
+ isc_throw(TypeError, "uint64Value() called on negative double Element");
+ }
+ }
using Element::setValue;
bool setValue(const double v) { d = v; return (true); }
void toJSON(std::ostream& ss) const;
diff --git a/src/lib/cc/tests/data_unittests.cc b/src/lib/cc/tests/data_unittests.cc
index 3f9d5d4..a69c849 100644
--- a/src/lib/cc/tests/data_unittests.cc
+++ b/src/lib/cc/tests/data_unittests.cc
@@ -201,18 +201,19 @@ testGetValueInt() {
el = Element::create(1);
EXPECT_NO_THROW(el->intValue());
- EXPECT_THROW(el->doubleValue(), TypeError);
+ // EXPECT_THROW(el->doubleValue(), TypeError);
EXPECT_THROW(el->boolValue(), TypeError);
EXPECT_THROW(el->stringValue(), TypeError);
EXPECT_THROW(el->listValue(), TypeError);
EXPECT_THROW(el->mapValue(), TypeError);
EXPECT_TRUE(el->getValue(i));
- EXPECT_FALSE(el->getValue(d));
+ EXPECT_TRUE(el->getValue(d));
EXPECT_FALSE(el->getValue(b));
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
EXPECT_EQ(1, i);
+ EXPECT_EQ(1, d);
}
template <typename T>
@@ -227,19 +228,20 @@ testGetValueDouble() {
std::map<std::string, ConstElementPtr> m;
el = Element::create(1.1);
- EXPECT_THROW(el->intValue(), TypeError);
+ // EXPECT_THROW(el->intValue(), TypeError);
EXPECT_NO_THROW(el->doubleValue());
EXPECT_THROW(el->boolValue(), TypeError);
EXPECT_THROW(el->stringValue(), TypeError);
EXPECT_THROW(el->listValue(), TypeError);
EXPECT_THROW(el->mapValue(), TypeError);
- EXPECT_FALSE(el->getValue(i));
+ EXPECT_TRUE(el->getValue(i));
EXPECT_TRUE(el->getValue(d));
EXPECT_FALSE(el->getValue(b));
EXPECT_FALSE(el->getValue(s));
EXPECT_FALSE(el->getValue(v));
EXPECT_FALSE(el->getValue(m));
EXPECT_EQ(1.1, d);
+ EXPECT_EQ(1, i);
}
template <typename T>
More information about the bind10-changes
mailing list