Commit 1cc1a42e authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2107] added get/set NSEC3Data

parent a68e9042
......@@ -203,4 +203,33 @@ TEST_F(ZoneDataTest, addRdataSets) {
// TearDown() will confirm there's no leak on destroy
}
TEST_F(ZoneDataTest, getSetNSEC3Data) {
// Initially there's no NSEC3 data
EXPECT_EQ(static_cast<NSEC3Data*>(NULL), zone_data_->getNSEC3Data());
// Set a new one. The set method should return NULL. The get method
// should return the new one.
NSEC3Data* nsec3_data = NSEC3Data::create(mem_sgmt_, param_rdata_);
NSEC3Data* old_nsec3_data = zone_data_->setNSEC3Data(nsec3_data);
EXPECT_EQ(static_cast<NSEC3Data*>(NULL), old_nsec3_data);
EXPECT_EQ(nsec3_data, zone_data_->getNSEC3Data());
// Replace an existing one with a yet another one.
// We're responsible for destroying the old one.
NSEC3Data* nsec3_data2 = NSEC3Data::create(mem_sgmt_, nsec3_rdata_);
old_nsec3_data = zone_data_->setNSEC3Data(nsec3_data2);
EXPECT_EQ(nsec3_data, old_nsec3_data);
EXPECT_EQ(nsec3_data2, zone_data_->getNSEC3Data());
NSEC3Data::destroy(mem_sgmt_, old_nsec3_data, RRClass::IN());
// Setting NULL clears any existing one.
old_nsec3_data = zone_data_->setNSEC3Data(NULL);
EXPECT_EQ(nsec3_data2, old_nsec3_data);
EXPECT_EQ(static_cast<NSEC3Data*>(NULL), zone_data_->getNSEC3Data());
// Then set it again. The zone data should destroy it on its own
// destruction.
zone_data_->setNSEC3Data(old_nsec3_data);
}
}
......@@ -145,6 +145,9 @@ ZoneData::destroy(util::MemorySegment& mem_sgmt, RRClass zone_class,
ZoneTree::destroy(mem_sgmt, zone_data->zone_tree_.get(),
boost::bind(rdataSetDeleter, zone_class, &mem_sgmt,
_1));
if (zone_data->nsec3_data_) {
NSEC3Data::destroy(mem_sgmt, zone_data->nsec3_data_.get(), zone_class);
}
mem_sgmt.deallocate(zone_data, sizeof(ZoneData));
}
......
......@@ -112,9 +112,18 @@ public:
const ZoneTree* getZoneTree() const { return (zone_tree_.get()); }
const NSEC3Data* getNSEC3Data() const { return (nsec3_data_.get()); }
NSEC3Data* getNSEC3Data() { return (nsec3_data_.get()); }
NSEC3Data* setNSEC3Data(NSEC3Data* nsec3_data) {
NSEC3Data* old = nsec3_data_.get();
nsec3_data_ = nsec3_data;
return (old);
}
private:
const boost::interprocess::offset_ptr<ZoneTree> zone_tree_;
const boost::interprocess::offset_ptr<ZoneNode> origin_node_;
boost::interprocess::offset_ptr<NSEC3Data> nsec3_data_;
};
} // 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