]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2157] throw an exception instead of assert for invalid parameter
authorYoshitaka Aharen <aharen@jprs.co.jp>
Wed, 26 Dec 2012 11:10:42 +0000 (20:10 +0900)
committerYoshitaka Aharen <aharen@jprs.co.jp>
Wed, 26 Dec 2012 11:10:42 +0000 (20:10 +0900)
src/bin/auth/statistics.h
src/bin/auth/tests/statistics_unittest.cc.pre

index 312fe0341880ccd48080180be8c80a9648c3ac9b..2b294f2bbb153686bf82a6689b445224d4b91431 100644 (file)
@@ -103,9 +103,11 @@ public:
 
     /// \brief Set IP version carrying the request.
     /// \param ip_version IP version carrying the request
-    /// \throw None
+    /// \throw isc::InvalidParameter ip_version is invalid
     void setRequestIPVersion(const IPVersionType ip_version) {
-        assert(ip_version != IP_VERSION_UNSPEC);
+        if (ip_version == IP_VERSION_UNSPEC) {
+            isc_throw(isc::InvalidParameter, "Invalid IP version");
+        }
         req_ip_version_ = ip_version;
     }
 
@@ -118,11 +120,13 @@ public:
 
     /// \brief Set transport protocol carrying the request.
     /// \param transport_protocol Transport protocol carrying the request
-    /// \throw None
+    /// \throw isc::InvalidParameter transport_protocol is invalid
     void setRequestTransportProtocol(
         const TransportProtocolType transport_protocol)
     {
-        assert(transport_protocol != TRANSPORT_UNSPEC);
+        if (transport_protocol == TRANSPORT_UNSPEC) {
+            isc_throw(isc::InvalidParameter, "Invalid transport protocol");
+        }
         req_transport_protocol_ = transport_protocol;
     }
 
index 39515a6e029ce71c54fe5c87c6cc34959257065b..ac37de1c99d059581eca37d89a297e4462787c48 100644 (file)
@@ -112,16 +112,15 @@ buildSkeletonMessage(MessageAttributes& msgattrs) {
 TEST_F(CountersTest, invalidParameter) {
     MessageAttributes msgattrs;
 
-    // Passing *_UNSPEC should trigger an assertion failure.
-    // Note that we just check that it dies - we don't check what message is
-    // output.
-    EXPECT_DEATH_IF_SUPPORTED(
+    // Passing *_UNSPEC should trigger throwing an exception
+    // isc::InvalidParameter.
+    EXPECT_THROW(
         msgattrs.setRequestIPVersion(MessageAttributes::IP_VERSION_UNSPEC),
-        ".*");
-    EXPECT_DEATH_IF_SUPPORTED(
+        isc::InvalidParameter);
+    EXPECT_THROW(
         msgattrs.setRequestTransportProtocol(
             MessageAttributes::TRANSPORT_UNSPEC),
-        ".*");
+        isc::InvalidParameter);
 }
 
 TEST_F(CountersTest, invalidOperationForGetRequestOpCode) {