BIND 10 trac510, updated. 1468dd9e7bc1e0a045cdab88d1db815cc7e2bd52 [trac510] throw exceptions instead of assertion for parameter check
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Aug 22 09:19:17 UTC 2011
The branch, trac510 has been updated
via 1468dd9e7bc1e0a045cdab88d1db815cc7e2bd52 (commit)
from 3582ccf1eb2093d34e944bcda5ea2069158349dc (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 1468dd9e7bc1e0a045cdab88d1db815cc7e2bd52
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Mon Aug 22 18:11:59 2011 +0900
[trac510] throw exceptions instead of assertion for parameter check
-----------------------------------------------------------------------
Summary of changes:
src/lib/statistics/counter.cc | 13 +++++++++----
src/lib/statistics/counter.h | 14 ++++++++------
src/lib/statistics/counter_dict.cc | 7 +++++--
src/lib/statistics/counter_dict.h | 5 ++---
src/lib/statistics/tests/counter_dict_unittest.cc | 10 ++++++----
src/lib/statistics/tests/counter_unittest.cc | 13 +++++++++----
6 files changed, 39 insertions(+), 23 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/statistics/counter.cc b/src/lib/statistics/counter.cc
index 119c939..9cb1a6f 100644
--- a/src/lib/statistics/counter.cc
+++ b/src/lib/statistics/counter.cc
@@ -1,5 +1,4 @@
#include <vector>
-#include <cassert>
#include <boost/noncopyable.hpp>
@@ -25,21 +24,27 @@ class CounterImpl : boost::noncopyable {
CounterImpl::CounterImpl(const size_t items) :
counters_(items, InitialValue)
{
- assert(items != 0);
+ if (items == 0) {
+ isc_throw(isc::InvalidParameter, "Items must not be 0");
+ }
}
CounterImpl::~CounterImpl() {}
void
CounterImpl::inc(const Counter::Type& type) {
- assert(type < counters_.size());
+ if(type >= counters_.size()) {
+ isc_throw(isc::OutOfRange, "Counter type is out of range");
+ }
++counters_.at(type);
return;
}
const Counter::Value&
CounterImpl::get(const Counter::Type& type) const {
- assert(type < counters_.size());
+ if(type >= counters_.size()) {
+ isc_throw(isc::OutOfRange, "Counter type is out of range");
+ }
return (counters_.at(type));
}
diff --git a/src/lib/statistics/counter.h b/src/lib/statistics/counter.h
index 0c16c3b..2af0bc4 100644
--- a/src/lib/statistics/counter.h
+++ b/src/lib/statistics/counter.h
@@ -4,6 +4,8 @@
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
+#include <exceptions/exceptions.h>
+
namespace isc {
namespace statistics {
@@ -21,11 +23,10 @@ class Counter : boost::noncopyable {
///
/// This constructor is mostly exception free. But it may still throw
/// a standard exception if memory allocation fails inside the method.
- ///
- /// Note: \a items must be greater than 0. Otherwise this constructor
- /// causes an assertion failure.
///
/// \param items A number of counter items to hold (greater than 0)
+ ///
+ /// \throw isc::InvalidParameter \a items is 0
Counter(const size_t items);
/// The destructor.
@@ -34,16 +35,17 @@ class Counter : boost::noncopyable {
~Counter();
/// \brief Increment a counter item specified with \a type.
- ///
- /// Note: \a type must be valid counter type. Otherwise this method
- /// causes an assertion failure.
///
/// \param type %Counter item to increment
+ ///
+ /// \throw isc::OutOfRange \a type is invalid
void inc(const Type& type);
/// \brief Get the value of a counter item specified with \a type.
///
/// \param type %Counter item to get the value of
+ ///
+ /// \throw isc::OutOfRange \a type is invalid
const Value& get(const Type& type) const;
};
diff --git a/src/lib/statistics/counter_dict.cc b/src/lib/statistics/counter_dict.cc
index 3ffe09f..8314b46 100644
--- a/src/lib/statistics/counter_dict.cc
+++ b/src/lib/statistics/counter_dict.cc
@@ -41,8 +41,10 @@ class CounterDictionaryImpl : boost::noncopyable {
CounterDictionaryImpl::CounterDictionaryImpl(const size_t items) :
items_(items)
{
- // The number of the items must not be 0.
- assert(items != 0);
+ // The number of items must not be 0
+ if (items == 0) {
+ isc_throw(isc::InvalidParameter, "Items must not be 0");
+ }
}
// Destructor
@@ -55,6 +57,7 @@ CounterDictionaryImpl::addElement(const std::string& name) {
isc_throw(isc::InvalidParameter,
"Element " << name << " already exists");
}
+ assert(items_ != 0);
// Create a new Counter and add to the map
dictionary_.insert(
DictionaryMap::value_type(name, CounterPtr(new Counter(items_))));
diff --git a/src/lib/statistics/counter_dict.h b/src/lib/statistics/counter_dict.h
index 8039306..be455b6 100644
--- a/src/lib/statistics/counter_dict.h
+++ b/src/lib/statistics/counter_dict.h
@@ -27,11 +27,10 @@ class CounterDictionary : boost::noncopyable {
/// The constructor.
/// This constructor is mostly exception free. But it may still throw
/// a standard exception if memory allocation fails inside the method.
- ///
- /// Note: \a items must be greater than 0; otherwise this constructor
- /// causes assertion failure.
///
/// \param items A number of counter items to hold (greater than 0)
+ ///
+ /// \throw isc::InvalidParameter \a items is 0
CounterDictionary(const size_t items);
/// The destructor.
diff --git a/src/lib/statistics/tests/counter_dict_unittest.cc b/src/lib/statistics/tests/counter_dict_unittest.cc
index 3790216..2e635be 100644
--- a/src/lib/statistics/tests/counter_dict_unittest.cc
+++ b/src/lib/statistics/tests/counter_dict_unittest.cc
@@ -100,8 +100,9 @@ TEST_F(CounterDictionaryTest, deleteElement) {
}
TEST_F(CounterDictionaryTest, invalidCounterSize) {
- // Creating counter with 0 elements will cause assertion failure
- EXPECT_DEATH(CounterDictionary counters(0), "Assertion.+failed");
+ // Creating counter with 0 elements will cause an isc::InvalidParameter
+ // exception
+ EXPECT_THROW(CounterDictionary counters(0), isc::InvalidParameter);
}
TEST_F(CounterDictionaryTest, invalidCounterItem) {
@@ -109,8 +110,9 @@ TEST_F(CounterDictionaryTest, invalidCounterItem) {
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
- // Incrementing out-of-bound counter will cause assertion failure
- EXPECT_DEATH(counters["test"].inc(NUMBER_OF_ITEMS), "Assertion.+failed");
+ // Incrementing out-of-bound counter will cause an isc::OutOfRange
+ // exception
+ EXPECT_THROW(counters["test"].inc(NUMBER_OF_ITEMS), isc::OutOfRange);
}
TEST_F(CounterDictionaryTest, uniqueCheck) {
diff --git a/src/lib/statistics/tests/counter_unittest.cc b/src/lib/statistics/tests/counter_unittest.cc
index b43487b..8293376 100644
--- a/src/lib/statistics/tests/counter_unittest.cc
+++ b/src/lib/statistics/tests/counter_unittest.cc
@@ -61,13 +61,18 @@ TEST_F(CounterTest, incrementCounterItem) {
}
TEST_F(CounterTest, invalidCounterSize) {
- // Creating counter with 0 elements will cause assertion failure
- EXPECT_DEATH(Counter counter(0), "Assertion.+failed");
+ // Creating counter with 0 elements will cause an isc::InvalidParameter
+ // exception
+ EXPECT_THROW(Counter counter(0), isc::InvalidParameter);
}
TEST_F(CounterTest, invalidCounterItem) {
// Create counter
Counter counter(NUMBER_OF_ITEMS);
- // Incrementing out-of-bound counter will cause assertion failure
- EXPECT_DEATH(counter.inc(NUMBER_OF_ITEMS), "Assertion.+failed");
+ // Incrementing out-of-bound counter will cause an isc::OutOfRange
+ // exception
+ EXPECT_THROW(counter.inc(NUMBER_OF_ITEMS), isc::OutOfRange);
+ // Trying to get out-of-bound counter will cause an isc::OutOfRange
+ // exception
+ EXPECT_THROW(counter.get(NUMBER_OF_ITEMS), isc::OutOfRange);
}
More information about the bind10-changes
mailing list