Browse Source

Throw an excpetion if the NameserverEntry pointer is NULL
in NameserverAddress' constructor


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac356@3547 e5f2f494-b856-4b98-b285-d166d9295462

Haidong Wang 14 years ago
parent
commit
c5eac373c6

+ 13 - 3
src/lib/nsas/nameserver_address.h

@@ -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 @@ public:
     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 @@ public:
     /// \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

+ 2 - 4
src/lib/nsas/tests/nameserver_address_unittest.cc

@@ -94,10 +94,8 @@ TEST_F(NameserverAddressTest, Address) {
     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