mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +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);
|
||||
}
|
||||
|
||||
void
|
||||
ZoneTableSegment::destroy(ZoneTableSegment *segment) {
|
||||
delete segment;
|
||||
}
|
||||
|
||||
} // namespace memory
|
||||
} // namespace datasrc
|
||||
} // namespace isc
|
||||
|
@@ -74,17 +74,29 @@ public:
|
||||
/// \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
|
||||
|
@@ -24,17 +24,17 @@ namespace {
|
||||
|
||||
TEST(ZoneTableSegment, create) {
|
||||
const ElementPtr config = Element::fromJSON("{}");
|
||||
auto_ptr<ZoneTableSegment>
|
||||
seg(ZoneTableSegment::create((*config.get())));
|
||||
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||
|
||||
// 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) {
|
||||
const ElementPtr config = Element::fromJSON("{}");
|
||||
auto_ptr<ZoneTableSegment>
|
||||
seg(ZoneTableSegment::create((*config.get())));
|
||||
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||
|
||||
// getHeader() should never return NULL.
|
||||
ZoneTableHeader* header = seg->getHeader();
|
||||
@@ -43,16 +43,19 @@ TEST(ZoneTableSegment, getHeader) {
|
||||
// The zone table is unset.
|
||||
ZoneTable* table = header->getTable();
|
||||
EXPECT_EQ(static_cast<void*>(NULL), table);
|
||||
|
||||
ZoneTableSegment::destroy(seg);
|
||||
}
|
||||
|
||||
TEST(ZoneTableSegment, getMemorySegment) {
|
||||
// This doesn't do anything fun except test the API.
|
||||
const ElementPtr config = Element::fromJSON("{}");
|
||||
auto_ptr<ZoneTableSegment>
|
||||
seg(ZoneTableSegment::create((*config.get())));
|
||||
ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
|
||||
|
||||
MemorySegment& mem_sgmt = seg->getMemorySegment();
|
||||
EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
|
||||
|
||||
ZoneTableSegment::destroy(seg);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
Reference in New Issue
Block a user