mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 22:45:18 +00:00
[2206] Add a ZoneTableSegment::destroy() method
Also update doc comments asking callers to use the destroy() method.
This commit is contained in:
@@ -28,6 +28,11 @@ ZoneTableSegment::create(const isc::data::Element&) {
|
|||||||
return (new ZoneTableSegmentLocal);
|
return (new ZoneTableSegmentLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ZoneTableSegment::destroy(ZoneTableSegment *segment) {
|
||||||
|
delete segment;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace memory
|
} // namespace memory
|
||||||
} // namespace datasrc
|
} // namespace datasrc
|
||||||
} // namespace isc
|
} // namespace isc
|
||||||
|
@@ -74,17 +74,29 @@ public:
|
|||||||
/// \return Returns the ZoneTableHeader for this zone table segment.
|
/// \return Returns the ZoneTableHeader for this zone table segment.
|
||||||
virtual isc::util::MemorySegment& getMemorySegment() = 0;
|
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
|
/// 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
|
/// \param config The configuration based on which a derived object
|
||||||
/// is returned.
|
/// is returned.
|
||||||
/// \return Returns a ZoneTableSegment object
|
/// \return Returns a ZoneTableSegment object
|
||||||
static ZoneTableSegment* create(const isc::data::Element& config);
|
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
|
} // namespace memory
|
||||||
|
@@ -24,17 +24,17 @@ namespace {
|
|||||||
|
|
||||||
TEST(ZoneTableSegment, create) {
|
TEST(ZoneTableSegment, create) {
|
||||||
const ElementPtr config = Element::fromJSON("{}");
|
const ElementPtr config = Element::fromJSON("{}");
|
||||||
auto_ptr<ZoneTableSegment>
|
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||||
seg(ZoneTableSegment::create((*config.get())));
|
|
||||||
|
|
||||||
// By default, a local zone table segment is created.
|
// By default, a local zone table segment is created.
|
||||||
EXPECT_NE(static_cast<void*>(NULL), seg.get());
|
EXPECT_NE(static_cast<void*>(NULL), seg);
|
||||||
|
|
||||||
|
ZoneTableSegment::destroy(seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ZoneTableSegment, getHeader) {
|
TEST(ZoneTableSegment, getHeader) {
|
||||||
const ElementPtr config = Element::fromJSON("{}");
|
const ElementPtr config = Element::fromJSON("{}");
|
||||||
auto_ptr<ZoneTableSegment>
|
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||||
seg(ZoneTableSegment::create((*config.get())));
|
|
||||||
|
|
||||||
// getHeader() should never return NULL.
|
// getHeader() should never return NULL.
|
||||||
ZoneTableHeader* header = seg->getHeader();
|
ZoneTableHeader* header = seg->getHeader();
|
||||||
@@ -43,16 +43,19 @@ TEST(ZoneTableSegment, getHeader) {
|
|||||||
// The zone table is unset.
|
// The zone table is unset.
|
||||||
ZoneTable* table = header->getTable();
|
ZoneTable* table = header->getTable();
|
||||||
EXPECT_EQ(static_cast<void*>(NULL), table);
|
EXPECT_EQ(static_cast<void*>(NULL), table);
|
||||||
|
|
||||||
|
ZoneTableSegment::destroy(seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ZoneTableSegment, getMemorySegment) {
|
TEST(ZoneTableSegment, getMemorySegment) {
|
||||||
// This doesn't do anything fun except test the API.
|
// This doesn't do anything fun except test the API.
|
||||||
const ElementPtr config = Element::fromJSON("{}");
|
const ElementPtr config = Element::fromJSON("{}");
|
||||||
auto_ptr<ZoneTableSegment>
|
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||||
seg(ZoneTableSegment::create((*config.get())));
|
|
||||||
|
|
||||||
MemorySegment& mem_sgmt = seg->getMemorySegment();
|
MemorySegment& mem_sgmt = seg->getMemorySegment();
|
||||||
EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
|
EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
|
||||||
|
|
||||||
|
ZoneTableSegment::destroy(seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
Reference in New Issue
Block a user