Commit ea17ff0d authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2107] make sure zone data is created with the origin name.

added getOrigiNode() to get access to the origin node.
parent 3128629c
......@@ -16,30 +16,36 @@
#include <util/memory_segment_local.h>
#include <dns/name.h>
#include <dns/labelsequence.h>
#include <datasrc/memory/rdata_encoder.h>
#include <datasrc/memory/rdataset.h>
#include <datasrc/memory/zone_data.h>
#include <gtest/gtest.h>
using namespace isc::dns;
using namespace isc::datasrc::memory;
namespace {
class ZoneDataTest : public ::testing::Test {
protected:
ZoneDataTest() {}
ZoneDataTest() : zname_("example.com") {}
void TearDown() {
// detect any memory leak in the test memory segment
EXPECT_TRUE(mem_sgmt_.allMemoryDeallocated());
}
const Name zname_;
isc::util::MemorySegmentLocal mem_sgmt_;
RdataEncoder encoder_;
};
TEST_F(ZoneDataTest, create) {
ZoneData* zone_data = ZoneData::create(mem_sgmt_);
ZoneData* zone_data = ZoneData::create(mem_sgmt_, zname_);
EXPECT_EQ(LabelSequence(zname_), zone_data->getOriginNode()->getLabels());
ZoneData::destroy(mem_sgmt_, zone_data);
}
}
......@@ -14,34 +14,40 @@
#include <util/memory_segment.h>
#include <dns/name.h>
#include "rdataset.h"
#include "rdata_encoder.h"
#include "zone_data.h"
#include <cassert>
#include <new> // for the placement new
using namespace isc::dns;
namespace isc {
namespace datasrc {
namespace memory {
ZoneData*
ZoneData::create(util::MemorySegment& mem_sgmt) {
ZoneData::create(util::MemorySegment& mem_sgmt, const Name& zone_origin) {
ZoneTree* tree = ZoneTree::create(mem_sgmt, true);
ZoneNode* origin_node = NULL;
const ZoneTree::Result result =
tree->insert(mem_sgmt, zone_origin, &origin_node);
assert(result == ZoneTree::SUCCESS);
void* p = mem_sgmt.allocate(sizeof(ZoneData));
ZoneData* zone_data = new(p) ZoneData;
zone_data->zone_tree = tree;
ZoneData* zone_data = new(p) ZoneData(tree, origin_node);
return (zone_data);
}
void
ZoneData::destroy(util::MemorySegment& mem_sgmt, ZoneData* zone_data) {
ZoneTree::destroy(mem_sgmt, zone_data->zone_tree.get());
ZoneTree::destroy(mem_sgmt, zone_data->zone_tree_.get());
mem_sgmt.deallocate(zone_data, sizeof(ZoneData));
}
} // namespace memory
} // namespace datasrc
} // datasrc isc
......@@ -17,6 +17,8 @@
#include <util/memory_segment.h>
#include <dns/name.h>
#include <datasrc/memory/domaintree.h>
#include <datasrc/memory/rdataset.h>
......@@ -36,12 +38,23 @@ class ZoneData : boost::noncopyable {
{}
};
typedef DomainTree<RdataSet, RdataSetDeleter> ZoneTree;
typedef DomainTreeNode<RdataSet, RdataSetDeleter> ZoneNode;
ZoneData(ZoneTree* zone_tree, ZoneNode* origin_node) :
zone_tree_(zone_tree), origin_node_(origin_node)
{}
public:
static ZoneData* create(util::MemorySegment& mem_sgmt);
static ZoneData* create(util::MemorySegment& mem_sgmt,
const dns::Name& zone_name);
static void destroy(util::MemorySegment& mem_sgmt, ZoneData* zone_data);
const ZoneNode* getOriginNode() const {
return (origin_node_.get());
}
boost::interprocess::offset_ptr<ZoneTree> zone_tree;
private:
const boost::interprocess::offset_ptr<ZoneTree> zone_tree_;
const boost::interprocess::offset_ptr<ZoneNode> origin_node_;
};
} // namespace memory
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment