]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2209] Writer for the test segment
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Fri, 26 Oct 2012 18:11:40 +0000 (20:11 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Fri, 26 Oct 2012 18:11:40 +0000 (20:11 +0200)
src/lib/datasrc/tests/memory/zone_table_segment_test.h

index ab1334ee3f7b5a15718c8b610d1c1b2267d425ba..2078036376770438f74aeef8bd09176fb30c18ba 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <datasrc/memory/zone_table_segment.h>
 #include <datasrc/memory/zone_table.h>
+#include <datasrc/memory/zone_data.h>
 #include <datasrc/memory/zone_writer_local.h>
 
 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