BIND 10 trac1144, updated. b6dd72042939ca62d9ceeb80385eedc7c5f0560d [1144] added simple assignment tests mainly only for covering the code.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Sep 23 21:56:16 UTC 2011


The branch, trac1144 has been updated
       via  b6dd72042939ca62d9ceeb80385eedc7c5f0560d (commit)
       via  31e010330189f489c624b7cdb812ef3f33f8e280 (commit)
      from  f8b10842465d60483e3bc9827e06115ea8081bfc (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 b6dd72042939ca62d9ceeb80385eedc7c5f0560d
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Fri Sep 23 14:55:49 2011 -0700

    [1144] added simple assignment tests mainly only for covering the code.

commit 31e010330189f489c624b7cdb812ef3f33f8e280
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Fri Sep 23 14:34:30 2011 -0700

    [1144] some suggested (mostly) editorial cleanups:
    - style guideline adjustment (position of opening braces, indentation, etc)
    - avoid 'using namespace' before including a header file and (as a result
      of it) in ds_like.h
    - move standard header files from dlv/ds implementation files to ds_link.h
      as much as possible
    - trivial documentation updates

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/rdata/generic/detail/ds_like.h  |   50 +++++++++++++++++---------
 src/lib/dns/rdata/generic/dlv_32769.cc      |   11 ++----
 src/lib/dns/rdata/generic/dlv_32769.h       |    8 +++--
 src/lib/dns/rdata/generic/ds_43.cc          |   11 ++----
 src/lib/dns/rdata/generic/ds_43.h           |   28 +++++++++++++--
 src/lib/dns/tests/rdata_ds_like_unittest.cc |   28 ++++++++++++---
 6 files changed, 90 insertions(+), 46 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/detail/ds_like.h b/src/lib/dns/rdata/generic/detail/ds_like.h
index 40157e6..da3ade4 100644
--- a/src/lib/dns/rdata/generic/detail/ds_like.h
+++ b/src/lib/dns/rdata/generic/detail/ds_like.h
@@ -17,19 +17,36 @@
 
 #include <stdint.h>
 
+#include <iostream>
+#include <sstream>
 #include <string>
 #include <vector>
 
+#include <boost/lexical_cast.hpp>
+
+#include <exceptions/exceptions.h>
+
+#include <dns/messagerenderer.h>
+#include <dns/name.h>
+#include <dns/rdata.h>
+#include <dns/rdataclass.h>
+
+namespace isc {
+namespace dns {
+namespace rdata {
+namespace generic {
+namespace detail {
+
 /// \brief \c rdata::DSLikeImpl class represents the DS-like RDATA for DS
 /// and DLV types.
 ///
 /// This class implements the basic interfaces inherited by the DS and DLV
 /// classes from the abstract \c rdata::Rdata class, and provides trivial
 /// accessors to DS-like RDATA.
-template<class Type, uint16_t typeCode>class DSLikeImpl {
+template <class Type, uint16_t typeCode> class DSLikeImpl {
     // Common sequence of toWire() operations used for the two versions of
     // toWire().
-    template<typename Output>
+    template <typename Output>
     void
     toWireCommon(Output& output) const {
         output.writeUint16(tag_);
@@ -45,10 +62,9 @@ public:
     ///
     /// \c InvalidRdataText is thrown if the method cannot process the
     /// parameter data for any of the number of reasons.
-    DSLikeImpl(const string& ds_str)
-    {
-        istringstream iss(ds_str);
-        stringbuf digestbuf;
+    DSLikeImpl(const std::string& ds_str) {
+        std::istringstream iss(ds_str);
+        std::stringbuf digestbuf;
         uint32_t tag, algorithm, digest_type;
 
         iss >> tag >> algorithm >> digest_type >> &digestbuf;
@@ -90,24 +106,19 @@ public:
             isc_throw(InvalidRdataLength, RRType(typeCode) << " too short");
         }
 
-        uint16_t tag = buffer.readUint16();
-        uint16_t algorithm = buffer.readUint8();
-        uint16_t digest_type = buffer.readUint8();
+        tag_ = buffer.readUint16();
+        algorithm_ = buffer.readUint8();
+        digest_type_ = buffer.readUint8();
 
         rdata_len -= 4;
         digest_.resize(rdata_len);
         buffer.readData(&digest_[0], rdata_len);
-
-        tag_ = tag;
-        algorithm_ = algorithm;
-        digest_type_ = digest_type;
     }
 
     /// \brief The copy constructor.
     ///
     /// Trivial for now, we could've used the default one.
-    DSLikeImpl(const DSLikeImpl& source)
-    {
+    DSLikeImpl(const DSLikeImpl& source) {
         digest_ = source.digest_;
         tag_ = source.tag_;
         algorithm_ = source.algorithm_;
@@ -117,7 +128,7 @@ public:
     /// \brief Convert the DS-like data to a string.
     ///
     /// \return A \c string object that represents the DS-like data.
-    string
+    std::string
     toText() const {
         using namespace boost;
         return (lexical_cast<string>(static_cast<int>(tag_)) +
@@ -189,9 +200,14 @@ private:
     uint16_t tag_;
     uint8_t algorithm_;
     uint8_t digest_type_;
-    vector<uint8_t> digest_;
+    std::vector<uint8_t> digest_;
 };
 
+}
+}
+}
+}
+}
 #endif //  __DS_LIKE_H
 
 // Local Variables: 
diff --git a/src/lib/dns/rdata/generic/dlv_32769.cc b/src/lib/dns/rdata/generic/dlv_32769.cc
index 84a0d16..4e2d780 100644
--- a/src/lib/dns/rdata/generic/dlv_32769.cc
+++ b/src/lib/dns/rdata/generic/dlv_32769.cc
@@ -12,33 +12,28 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <iostream>
 #include <string>
-#include <sstream>
-#include <vector>
-
-#include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
 #include <util/encode/hex.h>
 
 #include <dns/messagerenderer.h>
-#include <dns/name.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
 #include <stdio.h>
 #include <time.h>
 
+#include <dns/rdata/generic/detail/ds_like.h>
+
 using namespace std;
 using namespace isc::util;
 using namespace isc::util::encode;
+using namespace isc::dns::rdata::generic::detail;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE
 
-#include <dns/rdata/generic/detail/ds_like.h>
-
 /// \brief Constructor from string.
 ///
 /// A copy of the implementation object is allocated and constructed.
diff --git a/src/lib/dns/rdata/generic/dlv_32769.h b/src/lib/dns/rdata/generic/dlv_32769.h
index cdc22ec..30128fb 100644
--- a/src/lib/dns/rdata/generic/dlv_32769.h
+++ b/src/lib/dns/rdata/generic/dlv_32769.h
@@ -30,9 +30,11 @@
 
 // BEGIN_RDATA_NAMESPACE
 
-template<class Type, uint16_t typeCode> class DSLikeImpl;
+namespace detail {
+template <class Type, uint16_t typeCode> class DSLikeImpl;
+}
 
-/// \brief \c rdata::DLV class represents the DLV RDATA as defined %in
+/// \brief \c rdata::generic::DLV class represents the DLV RDATA as defined in
 /// RFC4431.
 ///
 /// This class implements the basic interfaces inherited from the abstract
@@ -62,7 +64,7 @@ public:
     /// This method never throws an exception.
     uint16_t getTag() const;
 private:
-    typedef DSLikeImpl<DLV, 32769> DLVImpl;
+    typedef detail::DSLikeImpl<DLV, 32769> DLVImpl;
     DLVImpl* impl_;
 };
 
diff --git a/src/lib/dns/rdata/generic/ds_43.cc b/src/lib/dns/rdata/generic/ds_43.cc
index 0883616..5535d9d 100644
--- a/src/lib/dns/rdata/generic/ds_43.cc
+++ b/src/lib/dns/rdata/generic/ds_43.cc
@@ -12,33 +12,28 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <iostream>
 #include <string>
-#include <sstream>
-#include <vector>
-
-#include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
 #include <util/encode/hex.h>
 
 #include <dns/messagerenderer.h>
-#include <dns/name.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 
+#include <dns/rdata/generic/detail/ds_like.h>
+
 #include <stdio.h>
 #include <time.h>
 
 using namespace std;
 using namespace isc::util;
 using namespace isc::util::encode;
+using namespace isc::dns::rdata::generic::detail;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE
 
-#include <dns/rdata/generic/detail/ds_like.h>
-
 DS::DS(const string& ds_str) :
     impl_(new DSImpl(ds_str))
 {}
diff --git a/src/lib/dns/rdata/generic/ds_43.h b/src/lib/dns/rdata/generic/ds_43.h
index ef441b6..52f2f0b 100644
--- a/src/lib/dns/rdata/generic/ds_43.h
+++ b/src/lib/dns/rdata/generic/ds_43.h
@@ -30,21 +30,41 @@
 
 // BEGIN_RDATA_NAMESPACE
 
-template<class Type, uint16_t typeCode> class DSLikeImpl;
+namespace detail {
+template <class Type, uint16_t typeCode> class DSLikeImpl;
+}
 
+/// \brief \c rdata::generic::DS class represents the DS RDATA as defined in
+/// RFC3658.
+///
+/// This class implements the basic interfaces inherited from the abstract
+/// \c rdata::Rdata class, and provides trivial accessors specific to the
+/// DS RDATA.
 class DS : public Rdata {
 public:
     // BEGIN_COMMON_MEMBERS
     // END_COMMON_MEMBERS
+
+    /// \brief Assignment operator.
+    ///
+    /// It internally allocates a resource, and if it fails a corresponding
+    /// standard exception will be thrown.
+    /// This operator never throws an exception otherwise.
+    ///
+    /// This operator provides the strong exception guarantee: When an
+    /// exception is thrown the content of the assignment target will be
+    /// intact.
     DS& operator=(const DS& source);
+
+    /// \brief The destructor.
     ~DS();
 
+    /// \brief Return the value of the Tag field.
     ///
-    /// Specialized methods
-    ///
+    /// This method never throws an exception.
     uint16_t getTag() const;
 private:
-    typedef DSLikeImpl<DS, 43> DSImpl;
+    typedef detail::DSLikeImpl<DS, 43> DSImpl;
     DSImpl* impl_;
 };
 
diff --git a/src/lib/dns/tests/rdata_ds_like_unittest.cc b/src/lib/dns/tests/rdata_ds_like_unittest.cc
index 62937df..daf0dd4 100644
--- a/src/lib/dns/tests/rdata_ds_like_unittest.cc
+++ b/src/lib/dns/tests/rdata_ds_like_unittest.cc
@@ -33,8 +33,9 @@ using namespace isc::dns;
 using namespace isc::util;
 using namespace isc::dns::rdata;
 
+namespace {
 // hacks to make templates work
-template<class T>
+template <class T>
 class RRTYPE : public RRType {
 public:
     RRTYPE();
@@ -43,7 +44,6 @@ public:
 template<> RRTYPE<generic::DS>::RRTYPE() : RRType(RRType::DS()) {}
 template<> RRTYPE<generic::DLV>::RRTYPE() : RRType(RRType::DLV()) {}
 
-namespace {
 template <class DS_LIKE>
 class Rdata_DS_LIKE_Test : public RdataTest {
 protected:
@@ -51,7 +51,7 @@ protected:
 };
 
 string ds_like_txt("12892 5 2 F1E184C0E1D615D20EB3C223ACED3B03C773DD952D"
-              "5F0EB5C777586DE18DA6B5");
+                   "5F0EB5C777586DE18DA6B5");
 
 template <class DS_LIKE>
 DS_LIKE const Rdata_DS_LIKE_Test<DS_LIKE>::rdata_ds_like(ds_like_txt);
@@ -91,6 +91,23 @@ TYPED_TEST(Rdata_DS_LIKE_Test, createFromWire_DS_LIKE) {
                                           "rdata_ds_fromWire")));
 }
 
+TYPED_TEST(Rdata_DS_LIKE_Test, assignment_DS_LIKE) {
+    TypeParam copy((string(ds_like_txt)));
+    copy = this->rdata_ds_like;
+    EXPECT_EQ(0, copy.compare(this->rdata_ds_like));
+
+    // Check if the copied data is valid even after the original is deleted
+    TypeParam* copy2 = new TypeParam(this->rdata_ds_like);
+    TypeParam copy3((string(ds_like_txt)));
+    copy3 = *copy2;
+    delete copy2;
+    EXPECT_EQ(0, copy3.compare(this->rdata_ds_like));
+
+    // Self assignment
+    copy = copy;
+    EXPECT_EQ(0, copy.compare(this->rdata_ds_like));
+}
+
 TYPED_TEST(Rdata_DS_LIKE_Test, getTag_DS_LIKE) {
     EXPECT_EQ(12892, Rdata_DS_LIKE_Test<TypeParam>::rdata_ds_like.getTag());
 }
@@ -103,7 +120,7 @@ TYPED_TEST(Rdata_DS_LIKE_Test, toWireRenderer) {
     vector<unsigned char> data;
     UnitTestUtil::readWireData("rdata_ds_fromWire", data);
     EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
-                        static_cast<const uint8_t *>
+                        static_cast<const uint8_t*>
                         (Rdata_DS_LIKE_Test<TypeParam>::obuffer.getData()) + 2,
                         Rdata_DS_LIKE_Test<TypeParam>::obuffer.getLength() - 2,
                         &data[2], data.size() - 2);
@@ -116,8 +133,7 @@ TYPED_TEST(Rdata_DS_LIKE_Test, toWireBuffer) {
 
 TYPED_TEST(Rdata_DS_LIKE_Test, compare) {
     // trivial case: self equivalence
-    EXPECT_EQ(0,
-              TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt)));
+    EXPECT_EQ(0, TypeParam(ds_like_txt).compare(TypeParam(ds_like_txt)));
 
     // TODO: need more tests
 }




More information about the bind10-changes mailing list