BIND 10 trac2206, updated. a6748eee324ebb4cf4ba99aa225df51d71458c81 [2206] Use a fixture in tests

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Oct 3 04:52:06 UTC 2012


The branch, trac2206 has been updated
       via  a6748eee324ebb4cf4ba99aa225df51d71458c81 (commit)
       via  5acf0ff36e8503de33ce04fe16e279ec6ee871f1 (commit)
       via  14680316801f9274e5b4d099a4dfbf63d7cb110b (commit)
       via  d25bb8d27cf235603cb8a1d789066b2aa993eccd (commit)
       via  f2b62e24805e97f66aeac4f9ab3db2d9778c9314 (commit)
      from  1ab6aafab6660d60a5f2e7cf7125d59d5807f2e5 (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 a6748eee324ebb4cf4ba99aa225df51d71458c81
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Oct 3 10:21:17 2012 +0530

    [2206] Use a fixture in tests

commit 5acf0ff36e8503de33ce04fe16e279ec6ee871f1
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Oct 3 10:10:32 2012 +0530

    [2206] Add a ZoneTableSegment::destroy() method
    
    Also update doc comments asking callers to use the destroy() method.

commit 14680316801f9274e5b4d099a4dfbf63d7cb110b
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Oct 3 10:00:06 2012 +0530

    [2206] Add a doc comment that getHeader() should never return NULL

commit d25bb8d27cf235603cb8a1d789066b2aa993eccd
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Oct 3 09:58:04 2012 +0530

    [2206] Add ZoneTableHeader::getTable() method

commit f2b62e24805e97f66aeac4f9ab3db2d9778c9314
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Oct 3 09:33:54 2012 +0530

    [2206] Update doc comments to remove redundant bits
    
    Also correct comments where wrong, and add a code comment for
    ZoneTableSegment::create().

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

Summary of changes:
 src/lib/datasrc/memory/zone_table_segment.cc       |   11 +++-
 src/lib/datasrc/memory/zone_table_segment.h        |   56 +++++++++++++++-----
 src/lib/datasrc/memory/zone_table_segment_local.h  |   18 +++----
 .../tests/memory/zone_table_segment_unittest.cc    |   52 +++++++++++-------
 4 files changed, 94 insertions(+), 43 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_table_segment.cc b/src/lib/datasrc/memory/zone_table_segment.cc
index d818675..7a80e3c 100644
--- a/src/lib/datasrc/memory/zone_table_segment.cc
+++ b/src/lib/datasrc/memory/zone_table_segment.cc
@@ -21,7 +21,16 @@ namespace memory {
 
 ZoneTableSegment*
 ZoneTableSegment::create(const isc::data::Element&) {
-     return (new ZoneTableSegmentLocal);
+    /// FIXME: For now, we always return ZoneTableSegmentLocal. This
+    /// should be updated eventually to parse the passed Element
+    /// argument and construct a corresponding ZoneTableSegment
+    /// implementation.
+    return (new ZoneTableSegmentLocal);
+}
+
+void
+ZoneTableSegment::destroy(ZoneTableSegment *segment) {
+    delete segment;
 }
 
 } // namespace memory
diff --git a/src/lib/datasrc/memory/zone_table_segment.h b/src/lib/datasrc/memory/zone_table_segment.h
index db5f74a..8505019 100644
--- a/src/lib/datasrc/memory/zone_table_segment.h
+++ b/src/lib/datasrc/memory/zone_table_segment.h
@@ -27,48 +27,76 @@ namespace isc {
 namespace datasrc {
 namespace memory {
 
-/// \brief Zone Table Header Class
+/// \brief Memory-management independent entry point that contains a
+/// pointer to a zone table in memory.
+///
+/// An instance of this type lives inside a ZoneTableSegment
+/// implementation. It contains an offset pointer to the zone table (a
+/// map from domain names to zone locators) in memory.
 struct ZoneTableHeader {
+public:
+    /// \brief Returns a pointer to the underlying zone table.
+    ZoneTable* getTable() {
+        return (table.get());
+    }
+
+    /// \brief const version of getTable().
+    const ZoneTable* getTable() const {
+        return (getTable());
+    }
+
+private:
     boost::interprocess::offset_ptr<ZoneTable> table;
 };
 
-/// \brief Zone Table Segment Class
+/// \brief Manages a ZoneTableHeader, an entry point into a table of
+/// zones
 ///
 /// This class specifies an interface for derived implementations which
 /// return a pointer to an object of type ZoneTableHeader, an entry
-/// point of some memory image regardless of the underlying memory
-/// management implementation.
+/// point into a table of zones regardless of the underlying memory
+/// management implementation. Derived classes would implement the
+/// interface for specific memory-implementation behavior.
 class ZoneTableSegment {
 public:
     /// \brief Destructor
     virtual ~ZoneTableSegment() {}
 
-    /// \brief Return a ZoneTableHeader for the zone table segment.
+    /// \brief Return the ZoneTableHeader for the zone table segment.
     ///
-    /// Returns a ZoneTableHeader that contains a pointer to the zone
-    /// table data in memory.
+    /// NOTE: This method should never return \c NULL.
     ///
-    /// \return Returns a ZoneTableHeader for this zone table segment.
+    /// \return Returns the ZoneTableHeader for this zone table segment.
     virtual ZoneTableHeader* getHeader() = 0;
 
     /// \brief Return the MemorySegment for the zone table segment.
     ///
-    /// Returns the MemorySegment used in this zone table segment.
-    ///
-    /// \return Returns a ZoneTableHeader for this zone table segment.
+    /// \return Returns the ZoneTableHeader for this zone table segment.
     virtual isc::util::MemorySegment& getMemorySegment() = 0;
 
-    /// \brief Create a subclass depending on the memory segment model
+    /// \brief Create an instance depending on the memory segment model
     ///
     /// This is a factory method to create a derived ZoneTableSegment
-    /// object based on the \c config passed.
+    /// object based on the \c config passed. The method returns a
+    /// dynamically-allocated object. The caller is responsible for
+    /// destroying it with \c ZoneTableSegment::destroy().
     ///
-    /// FIXME: For now, we always return ZoneTableSegmentLocal.
+    /// FIXME: For now, we always return ZoneTableSegmentLocal
+    /// regardless of the passed \c config.
     ///
     /// \param config The configuration based on which a derived object
     ///               is returned.
     /// \return Returns a ZoneTableSegment object
     static ZoneTableSegment* create(const isc::data::Element& config);
+
+    /// \brief Destroy a ZoneTableSegment
+    ///
+    /// This method destroys the passed ZoneTableSegment. It must be
+    /// passed a segment previously created by \c
+    /// ZoneTableSegment::create().
+    ///
+    /// \param segment The segment to destroy.
+    static void destroy(ZoneTableSegment* segment);
 };
 
 } // namespace memory
diff --git a/src/lib/datasrc/memory/zone_table_segment_local.h b/src/lib/datasrc/memory/zone_table_segment_local.h
index 2d4d757..6d823a7 100644
--- a/src/lib/datasrc/memory/zone_table_segment_local.h
+++ b/src/lib/datasrc/memory/zone_table_segment_local.h
@@ -22,7 +22,7 @@ namespace isc {
 namespace datasrc {
 namespace memory {
 
-/// \brief MemorySegmentLocal based Zone Table Segment class
+/// \brief Local implementation of ZoneTableSegment class
 ///
 /// This class specifies a concrete implementation for a
 /// MemorySegmentLocal based ZoneTableSegment. Please see the
@@ -32,19 +32,17 @@ public:
     /// \brief Destructor
     virtual ~ZoneTableSegmentLocal() {}
 
-    /// \brief Return a ZoneTableHeader for the zone table segment.
+    /// \brief Return the ZoneTableHeader for the local zone table
+    /// segment implementation.
     ///
-    /// Returns a ZoneTableHeader that contains a pointer to the zone
-    /// table data in memory.
-    ///
-    /// \return Returns a ZoneTableHeader for this zone table segment.
+    /// \return Returns the ZoneTableHeader for this zone table segment.
     virtual ZoneTableHeader* getHeader();
 
-    /// \brief Return the MemorySegment for the zone table segment.
-    ///
-    /// Returns the MemorySegment used in this zone table segment.
+    /// \brief Return the MemorySegment for the local zone table segment
+    /// implementation.
     ///
-    /// \return Returns a ZoneTableHeader for this zone table segment.
+    /// \return Returns the MemorySegment for this zone table segment (a
+    /// MemorySegmentLocal instance).
     virtual isc::util::MemorySegment& getMemorySegment();
 
 private:
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
index 1dfe143..f023b6b 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
@@ -22,35 +22,51 @@ using namespace std;
 
 namespace {
 
-TEST(ZoneTableSegment, create) {
-    const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
+class ZoneTableSegmentTest : public ::testing::Test {
+protected:
+    ZoneTableSegmentTest() :
+        config_(Element::fromJSON("{}")),
+        segment_(ZoneTableSegment::create((*config_.get())))
+    {}
 
+    ~ZoneTableSegmentTest() {
+        if (segment_ != NULL) {
+            ZoneTableSegment::destroy(segment_);
+        }
+    }
+
+    void TearDown() {
+        // Catch any future leaks here.
+        const MemorySegment& mem_sgmt = segment_->getMemorySegment();
+        EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
+
+        ZoneTableSegment::destroy(segment_);
+        segment_ = NULL;
+    }
+
+    const ElementPtr config_;
+    ZoneTableSegment* segment_;
+};
+
+
+TEST_F(ZoneTableSegmentTest, create) {
     // By default, a local zone table segment is created.
-    EXPECT_NE(static_cast<void*>(NULL), seg.get());
+    EXPECT_NE(static_cast<void*>(NULL), segment_);
 }
 
-TEST(ZoneTableSegment, getHeader) {
-    const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
-
-    ZoneTableHeader* header = seg->getHeader();
+TEST_F(ZoneTableSegmentTest, getHeader) {
+    // getHeader() should never return NULL.
+    ZoneTableHeader* header = segment_->getHeader();
     EXPECT_NE(static_cast<void*>(NULL), header);
 
     // The zone table is unset.
-    ZoneTable* table = header->table.get();
+    ZoneTable* table = header->getTable();
     EXPECT_EQ(static_cast<void*>(NULL), table);
 }
 
-TEST(ZoneTableSegment, getMemorySegment) {
+TEST_F(ZoneTableSegmentTest, getMemorySegment) {
     // This doesn't do anything fun except test the API.
-    const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
-
-    MemorySegment& mem_sgmt = seg->getMemorySegment();
+    MemorySegment& mem_sgmt = segment_->getMemorySegment();
     EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
 }
 



More information about the bind10-changes mailing list