From: Michal 'vorner' Vaner Date: Fri, 26 Oct 2012 18:11:40 +0000 (+0200) Subject: [2209] Writer for the test segment X-Git-Tag: trac2487_base~21^2~8^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9afd797dee6f7ede5c387466547ac5a06277ecd;p=thirdparty%2Fkea.git [2209] Writer for the test segment --- diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_test.h b/src/lib/datasrc/tests/memory/zone_table_segment_test.h index ab1334ee3f..2078036376 100644 --- a/src/lib/datasrc/tests/memory/zone_table_segment_test.h +++ b/src/lib/datasrc/tests/memory/zone_table_segment_test.h @@ -17,6 +17,7 @@ #include #include +#include #include namespace isc { @@ -52,15 +53,55 @@ public: return (mem_sgmt_); } - virtual ZoneWriter* getZoneWriter(const LoadAction&, const dns::Name&, - const dns::RRClass&) + virtual ZoneWriter* getZoneWriter(const LoadAction& load_action, + const dns::Name& name, + const dns::RRClass& rrclass) { - isc_throw(isc::NotImplemented, "Not implemented"); + return (new Writer(this, load_action, name, rrclass)); } private: isc::util::MemorySegment& mem_sgmt_; ZoneTableHeader header_; + + // A writer for this segment. The implementation is similar + // to ZoneWriterLocal, but all the error handling is stripped + // for simplicity. Also, we do everything inside the + // install(), for the same reason. We just need something + // inside the tests, not a full-blown implementation + // for background loading. + class Writer : public ZoneWriter { + public: + Writer(ZoneTableSegmentTest* segment, const LoadAction& load_action, + const dns::Name& name, const dns::RRClass& rrclass) : + segment_(segment), + load_action_(load_action), + name_(name), + rrclass_(rrclass) + {} + + void load() {} + + void install() { + ZoneTable* table(segment_->getHeader().getTable()); + const ZoneTable::AddResult + result(table->addZone(segment_->getMemorySegment(), rrclass_, + name_, + load_action_(segment_-> + getMemorySegment()))); + if (result.zone_data != NULL) { + ZoneData::destroy(segment_->getMemorySegment(), + result.zone_data, rrclass_); + } + } + + virtual void cleanup() {} + private: + ZoneTableSegmentTest* segment_; + LoadAction load_action_; + dns::Name name_; + dns::RRClass rrclass_; + }; }; } // namespace test