[svn] commit: r474 - in /trunk: ./ src/lib/dns/cpp/ src/lib/dns/cpp/testdata/

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Jan 19 00:16:02 UTC 2010


Author: jinmei
Date: Tue Jan 19 00:16:02 2010
New Revision: 474

Log:
merged RRType/Class/TTL classes

Added:
    trunk/src/lib/dns/cpp/rrclass.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrclass.cc
    trunk/src/lib/dns/cpp/rrclass.h
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrclass.h
    trunk/src/lib/dns/cpp/rrclass_unittest.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrclass_unittest.cc
    trunk/src/lib/dns/cpp/rrparamregistry.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrparamregistry.cc
    trunk/src/lib/dns/cpp/rrparamregistry.h
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrparamregistry.h
    trunk/src/lib/dns/cpp/rrparamregistry_unittest.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrparamregistry_unittest.cc
    trunk/src/lib/dns/cpp/rrttl.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrttl.cc
    trunk/src/lib/dns/cpp/rrttl.h
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrttl.h
    trunk/src/lib/dns/cpp/rrttl_unittest.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrttl_unittest.cc
    trunk/src/lib/dns/cpp/rrtype.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrtype.cc
    trunk/src/lib/dns/cpp/rrtype.h
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrtype.h
    trunk/src/lib/dns/cpp/rrtype_unittest.cc
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/rrtype_unittest.cc
    trunk/src/lib/dns/cpp/testdata/rrcode16_fromWire1
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/testdata/rrcode16_fromWire1
    trunk/src/lib/dns/cpp/testdata/rrcode16_fromWire2
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/testdata/rrcode16_fromWire2
    trunk/src/lib/dns/cpp/testdata/rrcode32_fromWire1
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/testdata/rrcode32_fromWire1
    trunk/src/lib/dns/cpp/testdata/rrcode32_fromWire2
      - copied unchanged from r473, branches/jinmei-dnsrrparams/src/lib/dns/cpp/testdata/rrcode32_fromWire2
Modified:
    trunk/   (props changed)
    trunk/configure.ac
    trunk/src/lib/dns/cpp/Makefile.am
    trunk/src/lib/dns/cpp/buffer_unittest.cc
    trunk/src/lib/dns/cpp/exceptions_unittest.cc
    trunk/src/lib/dns/cpp/messagerenderer.cc
    trunk/src/lib/dns/cpp/messagerenderer.h
    trunk/src/lib/dns/cpp/messagerenderer_unittest.cc
    trunk/src/lib/dns/cpp/name.cc
    trunk/src/lib/dns/cpp/name.h

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Tue Jan 19 00:16:02 2010
@@ -33,7 +33,20 @@
    CXXFLAGS="$CXXFLAGS -fPIC"
 fi
 
-AC_SUBST(CXXFLAGS)
+#
+# Check availablity of boost: 
+#
+AC_ARG_WITH(boost,
+[  --with-boost=PATH       specify a path to the boost if it's not automatically found],
+    boost_path="$withval", boost_path="no")
+if test "$boost_path" != "no"
+then
+	BOOST_INCLUDES="-I$boost_path/include"
+else
+	BOOST_INCLUDES=
+fi
+
+AC_SUBST(BOOST_INCLUDES)
 
 #
 # Check availablity of gtest, which will be used for unit tests.
@@ -64,6 +77,42 @@
 AC_SUBST(GTEST_LDFLAGS)
 AC_SUBST(GTEST_LDADD)
 
+AC_ARG_WITH(lcov,
+[  --with-lcov[=PROGRAM]     enable gtest and coverage target using the specified lcov], lcov="$withval", lcov="no")
+
+USE_LCOV="no"
+if test "$lcov" != "no"; then
+	# force gtest if not set
+	if test "$gtest_path" = "no"; then
+		gtest_path="yes"
+	fi
+	if test "$lcov" != "yes"; then
+		LCOV_PATHS=$lcov
+	else
+		LCOV_PATHS="/usr/bin/lcov /usr/local/bin/lcov"
+	fi
+	for f in $LCOV_PATHS; do
+		if test -x "$f"; then
+			USE_LCOV="yes"
+			LCOV=$f
+		fi
+	done
+	if test $USE_LCOV != "yes"; then
+		AC_MSG_ERROR([Cannot find lcov in: $LCOV_PATHS])
+	fi
+	# is genhtml always in the same directory?
+	GENHTML=`echo "$LCOV" | sed s/lcov$/genhtml/`
+	if test ! -x $GENHTML; then
+		AC_MSG_ERROR([genhtml not found, needed for lcov])
+	fi
+	# GCC specific?
+	CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
+	LIBS=" $LIBS -lgcov"
+fi
+
+AC_SUBST(CXXFLAGS)
+AC_SUBST(LIBS)
+
 # Checks for library functions.
 
 AC_CONFIG_FILES([Makefile

Modified: trunk/src/lib/dns/cpp/Makefile.am
==============================================================================
--- trunk/src/lib/dns/cpp/Makefile.am (original)
+++ trunk/src/lib/dns/cpp/Makefile.am Tue Jan 19 00:16:02 2010
@@ -1,5 +1,11 @@
+AM_CPPFLAGS = $(BOOST_INCLUDES)
+
+CLEANFILES = *.gcno *.gcda
+
 lib_LTLIBRARIES = libdns.la
 libdns_la_SOURCES = buffer.h name.cc name.h messagerenderer.h messagerenderer.cc
+libdns_la_SOURCES += rrparamregistry.h rrparamregistry.cc
+libdns_la_SOURCES += rrclass.h rrclass.cc rrtype.h rrtype.cc rrttl.h rrttl.cc
 libdns_la_SOURCES += exceptions.h exceptions.cc
 
 TESTS =
@@ -8,6 +14,9 @@
 run_unittests_SOURCES = unittest_util.h unittest_util.cc
 run_unittests_SOURCES += buffer_unittest.cc name_unittest.cc
 run_unittests_SOURCES += messagerenderer_unittest.cc exceptions_unittest.cc
+run_unittests_SOURCES += rrclass_unittest.cc rrtype_unittest.cc
+run_unittests_SOURCES += rrttl_unittest.cc
+run_unittests_SOURCES += rrparamregistry_unittest.cc
 run_unittests_SOURCES += run_unittests.cc
 run_unittests_CPPFLAGS = $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(GTEST_LDFLAGS)

Modified: trunk/src/lib/dns/cpp/buffer_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/buffer_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/buffer_unittest.cc Tue Jan 19 00:16:02 2010
@@ -43,7 +43,7 @@
 
 const uint8_t BufferTest::testdata[5] = {1, 2, 3, 4, 5};
 
-TEST_F(BufferTest, input_buffer_read)
+TEST_F(BufferTest, inputBufferRead)
 {
     EXPECT_EQ(5, ibuffer.getLength());
     EXPECT_EQ(1, ibuffer.readUint8());
@@ -61,7 +61,7 @@
     EXPECT_EQ(0, memcmp(vdata, testdata, sizeof(testdata)));
 }
 
-TEST_F(BufferTest, input_buffer_exception)
+TEST_F(BufferTest, inputBufferException)
 {
     EXPECT_THROW(ibuffer.setPosition(6), isc::dns::InvalidBufferPosition);
 
@@ -79,7 +79,7 @@
                  isc::dns::InvalidBufferPosition);
 }
 
-TEST_F(BufferTest, output_buffer_extend)
+TEST_F(BufferTest, outputBufferExtend)
 {
     EXPECT_EQ(0, obuffer.getCapacity());
     EXPECT_EQ(0, obuffer.getLength());
@@ -88,7 +88,7 @@
     EXPECT_EQ(1, obuffer.getLength());
 }
 
-TEST_F(BufferTest, output_buffer_write)
+TEST_F(BufferTest, outputBufferWrite)
 {
     const uint8_t* cp;
 
@@ -121,7 +121,7 @@
     EXPECT_EQ(0, memcmp(cp + 7, testdata, sizeof(testdata)));
 }
 
-TEST_F(BufferTest, output_buffer_writeat)
+TEST_F(BufferTest, outputBufferWriteat)
 {
     obuffer.writeUint32(data32);
     expected_size += sizeof(data32);
@@ -140,7 +140,7 @@
                  isc::dns::InvalidBufferPosition);
 }
 
-TEST_F(BufferTest, output_buffer_skip)
+TEST_F(BufferTest, outputBufferSkip)
 {
     obuffer.skip(4);
     EXPECT_EQ(4, obuffer.getLength());
@@ -149,7 +149,7 @@
     EXPECT_EQ(6, obuffer.getLength());
 }
 
-TEST_F(BufferTest, output_buffer_readat)
+TEST_F(BufferTest, outputBufferReadat)
 {
     obuffer.writeData(testdata, sizeof(testdata));
     for (int i = 0; i < sizeof(testdata); i ++) {
@@ -158,7 +158,7 @@
     EXPECT_THROW(obuffer[sizeof(testdata)], isc::dns::InvalidBufferPosition);
 }
 
-TEST_F(BufferTest, output_buffer_clear)
+TEST_F(BufferTest, outputBufferClear)
 {
     obuffer.writeData(testdata, sizeof(testdata));
     obuffer.clear();

Modified: trunk/src/lib/dns/cpp/exceptions_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/exceptions_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/exceptions_unittest.cc Tue Jan 19 00:16:02 2010
@@ -31,7 +31,7 @@
     const char* teststring;
 };
 
-TEST_F(ExceptionTest, BasicMethods) {
+TEST_F(ExceptionTest, basicMethods) {
     try {
         dns_throw(Exception, teststring);
     } catch (Exception& ex) {
@@ -42,7 +42,7 @@
 }
 
 // Test to see if it works as a proper derived class of std::exception.
-TEST_F(ExceptionTest, StdInheritance) {
+TEST_F(ExceptionTest, stdInheritance) {
     try {
         dns_throw(Exception, teststring);
     } catch (std::exception& ex) {

Modified: trunk/src/lib/dns/cpp/messagerenderer.cc
==============================================================================
--- trunk/src/lib/dns/cpp/messagerenderer.cc (original)
+++ trunk/src/lib/dns/cpp/messagerenderer.cc Tue Jan 19 00:16:02 2010
@@ -127,7 +127,7 @@
 /// \c MessageRenderer.
 ///
 /// The implementation is hidden from applications.  We can refer to specific
-/// members of this class only within this file.
+/// members of this class only within the implementation source file.
 ///
 struct MessageRendererImpl {
     /// \brief Constructor from an output buffer.
@@ -157,6 +157,30 @@
 }
 
 void
+MessageRenderer::writeUint16(uint16_t data)
+{
+    impl_->buffer_.writeUint16(data);
+}
+
+void
+MessageRenderer::writeUint32(uint32_t data)
+{
+    impl_->buffer_.writeUint32(data);
+}
+
+const void*
+MessageRenderer::getData() const
+{
+    return (impl_->buffer_.getData());
+}
+
+size_t
+MessageRenderer::getLength() const
+{
+    return (impl_->buffer_.getLength());
+}
+
+void
 MessageRenderer::writeName(const Name& name, bool compress)
 {
     impl_->nbuffer_.clear();

Modified: trunk/src/lib/dns/cpp/messagerenderer.h
==============================================================================
--- trunk/src/lib/dns/cpp/messagerenderer.h (original)
+++ trunk/src/lib/dns/cpp/messagerenderer.h Tue Jan 19 00:16:02 2010
@@ -88,6 +88,36 @@
     //@}
 
     ///
+    /// \name Getter Methods
+    ///
+    //@{
+    /// \brief Return a pointer to the head of the data stored in the internal
+    /// buffer.
+    ///
+    /// This method works exactly same as the same method of the \c OutputBuffer
+    /// class; all notes for \c OutputBuffer apply.
+    const void* getData() const;
+    /// \brief Return the length of data written in the internal buffer.
+    size_t getLength() const;
+    //@}
+
+    ///
+    /// \name Methods for writing data into the internal buffer.
+    ///
+    //@{
+    /// \brief Write an unsigned 16-bit integer in host byte order into the
+    /// internal buffer in network byte order.
+    ///
+    /// \param data The 16-bit integer to be written into the buffer.
+    void writeUint16(uint16_t data);
+    /// \brief Write an unsigned 32-bit integer in host byte order into the
+    /// internal buffer in network byte order.
+    ///
+    /// \param data The 32-bit integer to be written into the buffer.
+    void writeUint32(uint32_t data);
+    //@}
+
+    ///
     /// \name Rendering Methods
     ///
     //@{

Modified: trunk/src/lib/dns/cpp/messagerenderer_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/messagerenderer_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/messagerenderer_unittest.cc Tue Jan 19 00:16:02 2010
@@ -32,13 +32,33 @@
 namespace {
 class MessageRendererTest : public ::testing::Test {
 protected:
-    MessageRendererTest() : buffer(0), renderer(buffer) {}
+    MessageRendererTest() : expected_size(0), buffer(0), renderer(buffer)
+    {
+        data16 = (2 << 8) | 3;
+        data32 = (4 << 24) | (5 << 16) | (6 << 8) | 7;
+    }
+    size_t expected_size;
+    uint16_t data16;
+    uint32_t data32;
     OutputBuffer buffer;
     MessageRenderer renderer;
     std::vector<unsigned char> data;
+    static const uint8_t testdata[5];
 };
 
-TEST_F(MessageRendererTest, toWire)
+const uint8_t MessageRendererTest::testdata[5] = {1, 2, 3, 4, 5};
+
+// The test cases are borrowed from those for the OutputBuffer class.
+TEST_F(MessageRendererTest, writeIntger)
+{
+    renderer.writeUint16(data16);
+    expected_size += sizeof(data16);
+
+    EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, renderer.getData(),
+                        renderer.getLength(), &testdata[1], sizeof(data16));
+}
+
+TEST_F(MessageRendererTest, writeName)
 {
     UnitTestUtil::readWireData("testdata/name_toWire1", data);
     renderer.writeName(Name("a.example.com."));
@@ -48,7 +68,7 @@
                         buffer.getLength(), &data[0], data.size());
 }
 
-TEST_F(MessageRendererTest, toWireInLargeBuffer)
+TEST_F(MessageRendererTest, writeNameInLargeBuffer)
 {
     size_t offset = 0x3fff;
     buffer.skip(offset);
@@ -63,7 +83,7 @@
                         &data[0], data.size());
 }
 
-TEST_F(MessageRendererTest, toWireWithUncompressed)
+TEST_F(MessageRendererTest, writeNameWithUncompressed)
 {
     UnitTestUtil::readWireData("testdata/name_toWire3", data);
     renderer.writeName(Name("a.example.com."));
@@ -73,7 +93,7 @@
                         buffer.getLength(), &data[0], data.size());
 }
 
-TEST_F(MessageRendererTest, toWirePointerChain)
+TEST_F(MessageRendererTest, writeNamePointerChain)
 {
     UnitTestUtil::readWireData("testdata/name_toWire4", data);
     renderer.writeName(Name("a.example.com."));
@@ -83,7 +103,7 @@
                         buffer.getLength(), &data[0], data.size());
 }
 
-TEST_F(MessageRendererTest, toWireCaseCompress)
+TEST_F(MessageRendererTest, writeNameCaseCompress)
 {
     UnitTestUtil::readWireData("testdata/name_toWire1", data);
     renderer.writeName(Name("a.example.com."));

Modified: trunk/src/lib/dns/cpp/name.cc
==============================================================================
--- trunk/src/lib/dns/cpp/name.cc (original)
+++ trunk/src/lib/dns/cpp/name.cc Tue Jan 19 00:16:02 2010
@@ -25,6 +25,7 @@
 #include "name.h"
 #include "messagerenderer.h"
 
+using namespace std;
 using isc::dns::NameComparisonResult;
 using isc::dns::MessageRenderer;
 
@@ -566,19 +567,6 @@
     return (length_ >= 2 && ndata_[0] == 1 && ndata_[1] == '*'); 
 }
 
-namespace {                     // hide the local class
-///
-/// A helper functor class to add an additional offset to an offset vector.
-///
-struct OffsetAdjuster : public std::binary_function<unsigned char,
-                                                    int, unsigned char> {
-    unsigned char operator()(unsigned char ch, int offset) const
-    {
-        return (ch + offset);
-    }
-};
-}
-
 Name
 Name::concatenate(const Name& suffix) const
 {
@@ -610,7 +598,7 @@
                             &this->offsets_[0] + this->labelcount_ - 1);
     transform(suffix.offsets_.begin(), suffix.offsets_.end(),
               back_inserter(retname.offsets_),
-              bind2nd(OffsetAdjuster(), this->length_ - 1));
+              bind2nd(plus<char>(), this->length_ - 1));
     assert(retname.offsets_.size() == labels);
     retname.labelcount_ = labels;
 
@@ -636,7 +624,7 @@
     retname.offsets_.reserve(newlabels);
     transform(offsets_.begin() + first, offsets_.begin() + first + newlabels,
               back_inserter(retname.offsets_),
-              bind2nd(OffsetAdjuster(), -offsets_[first]));
+              bind2nd(plus<char>(), -offsets_[first]));
 
     //
     // Set up the new name.  At this point the tail of the new offsets specifies

Modified: trunk/src/lib/dns/cpp/name.h
==============================================================================
--- trunk/src/lib/dns/cpp/name.h (original)
+++ trunk/src/lib/dns/cpp/name.h Tue Jan 19 00:16:02 2010
@@ -330,6 +330,7 @@
     /// <code>buffer.getCapacity() - buffer.getLength() >= Name::MAX_WIRE</code>
     /// then this method should not throw an exception.
     ///
+    /// \param buffer An output buffer to store the wire data.
     void toWire(OutputBuffer& buffer) const;
     //@}
 
@@ -368,17 +369,17 @@
     bool equals(const Name& other) const;
 
     /// Same as equals()
-    bool operator==(const Name& other) const { return (this->equals(other)); }
+    bool operator==(const Name& other) const { return (equals(other)); }
 
     /// \brief Return true iff two names are not equal.
     ///
     /// This method simply negates the result of \c equal() method, and in that
     /// sense it's redundant.  The separate method is provided just for
     /// convenience.
-    bool nequals(const Name& other) const { return !(this->equals(other)); }
+    bool nequals(const Name& other) const { return !(equals(other)); }
 
     /// Same as nequals()
-    bool operator!=(const Name& other) const { return (this->nequals(other)); }
+    bool operator!=(const Name& other) const { return (nequals(other)); }
 
     /// \brief Less-than or equal comparison for Name against <code>other</code>
     ///




More information about the bind10-changes mailing list