From: Yoshitaka Aharen Date: Wed, 26 Dec 2012 11:10:42 +0000 (+0900) Subject: [2157] throw an exception instead of assert for invalid parameter X-Git-Tag: bind10-1.1.0beta1-release~85^2~5^2~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=76759ae07db6edb36cc063ef1f89e247d910275a;p=thirdparty%2Fkea.git [2157] throw an exception instead of assert for invalid parameter --- diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h index 312fe03418..2b294f2bbb 100644 --- a/src/bin/auth/statistics.h +++ b/src/bin/auth/statistics.h @@ -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; } diff --git a/src/bin/auth/tests/statistics_unittest.cc.pre b/src/bin/auth/tests/statistics_unittest.cc.pre index 39515a6e02..ac37de1c99 100644 --- a/src/bin/auth/tests/statistics_unittest.cc.pre +++ b/src/bin/auth/tests/statistics_unittest.cc.pre @@ -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) {