[svn] commit: r3547 - in /branches/trac356/src/lib/nsas: nameserver_address.h tests/nameserver_address_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Nov 17 07:32:52 UTC 2010
Author: ocean
Date: Wed Nov 17 07:32:52 2010
New Revision: 3547
Log:
Throw an excpetion if the NameserverEntry pointer is NULL
in NameserverAddress' constructor
Modified:
branches/trac356/src/lib/nsas/nameserver_address.h
branches/trac356/src/lib/nsas/tests/nameserver_address_unittest.cc
Modified: branches/trac356/src/lib/nsas/nameserver_address.h
==============================================================================
--- branches/trac356/src/lib/nsas/nameserver_address.h (original)
+++ branches/trac356/src/lib/nsas/nameserver_address.h Wed Nov 17 07:32:52 2010
@@ -25,6 +25,17 @@
namespace isc {
namespace nsas {
+/// \brief Empty \c NameserverEntry pointer exception
+///
+/// Thrown if the the \c NameservrEntry pointer in the \c boost::shared_ptr that passed
+/// into \c NameserverAddress' constructor is NULL
+class NullNameserverEntryPointer : public isc::Exception {
+public:
+ NullNameserverEntryPointer(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what)
+ {}
+};
+
/// \brief Nameserver Address
///
/// This class implements the object that returned from NSAS when the resolver
@@ -48,6 +59,7 @@
NameserverAddress(boost::shared_ptr<NameserverEntry>& nameserver, uint32_t index):
ns_(nameserver), index_(index)
{
+ if(!ns_.get()) isc_throw(NullNameserverEntryPointer, "NULL NameserverEntry pointer.");
}
/// \brief Destructor
@@ -59,9 +71,7 @@
/// \brief Return address
///
asiolink::IOAddress getAddress() const {
- NameserverEntry *ne = ns_.get();
- assert(ne != NULL);
- return ne->getAddressAtIndex(index_);
+ return ns_.get()->getAddressAtIndex(index_);
}
/// \brief Update Round-trip Time
Modified: branches/trac356/src/lib/nsas/tests/nameserver_address_unittest.cc
==============================================================================
--- branches/trac356/src/lib/nsas/tests/nameserver_address_unittest.cc (original)
+++ branches/trac356/src/lib/nsas/tests/nameserver_address_unittest.cc Wed Nov 17 07:32:52 2010
@@ -94,10 +94,8 @@
ASSERT_DEATH(invalid_ns_address_.getAddress(), "");
boost::shared_ptr<NameserverEntry> empty_ne((NameserverEntry*)NULL);
- NameserverAddress empty_ns_address(empty_ne, 0);
-
- // It will trigger an assert with the empty NameserverEntry shared pointer
- ASSERT_DEATH(empty_ns_address.getAddress(), "");
+ // It will throw an NullNameserverEntryPointer exception with the empty NameserverEntry shared pointer
+ ASSERT_THROW({NameserverAddress empty_ns_address(empty_ne, 0);}, NullNameserverEntryPointer);
}
// Test that the RTT is updated
More information about the bind10-changes
mailing list