BIND 10 trac2108_3, updated. 94670cafdbca56d6bf2708e83fa9aa07295f579c [2108] Use the test memory segment in InMemoryClient unittests

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Sep 6 00:50:10 UTC 2012


The branch, trac2108_3 has been updated
       via  94670cafdbca56d6bf2708e83fa9aa07295f579c (commit)
      from  4da836d3f6d756fe91ae42fd5cb83ec282f3dc33 (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 94670cafdbca56d6bf2708e83fa9aa07295f579c
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Sep 6 06:19:20 2012 +0530

    [2108] Use the test memory segment in InMemoryClient unittests
    
    This has the setThrowCount() which we can use to check leaks during
    allocation problems.

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

Summary of changes:
 .../datasrc/memory/tests/memory_client_unittest.cc |   23 +++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/tests/memory_client_unittest.cc b/src/lib/datasrc/memory/tests/memory_client_unittest.cc
index 88e47b6..048d7be 100644
--- a/src/lib/datasrc/memory/tests/memory_client_unittest.cc
+++ b/src/lib/datasrc/memory/tests/memory_client_unittest.cc
@@ -41,6 +41,27 @@ using namespace isc::datasrc;
 using namespace isc::datasrc::memory;
 
 namespace {
+// Memory segment specified for tests.  It normally behaves like a "local"
+// memory segment.  If "throw count" is set to non 0 via setThrowCount(),
+// it continues the normal behavior up to the specified number of calls to
+// allocate(), and throws an exception at the next call.
+class TestMemorySegment : public isc::util::MemorySegmentLocal {
+public:
+    TestMemorySegment() : throw_count_(0) {}
+    virtual void* allocate(size_t size) {
+        if (throw_count_ > 0) {
+            if (--throw_count_ == 0) {
+                throw std::bad_alloc();
+            }
+        }
+        return (isc::util::MemorySegmentLocal::allocate(size));
+    }
+    void setThrowCount(size_t count) { throw_count_ = count; }
+
+private:
+    size_t throw_count_;
+};
+
 class MemoryClientTest : public ::testing::Test {
 protected:
     MemoryClientTest() : zclass_(RRClass::IN()),
@@ -61,7 +82,7 @@ protected:
     }
     const RRClass zclass_;
     const Name zname1, zname2, zname3;
-    isc::util::MemorySegmentLocal mem_sgmt_;
+    TestMemorySegment mem_sgmt_;
     InMemoryClient* client_;
     memory::ZoneTable* zone_table;
 };



More information about the bind10-changes mailing list