Browse Source

[2209] Writer for the test segment

Michal 'vorner' Vaner 12 years ago
parent
commit
b9afd797de
1 changed files with 44 additions and 3 deletions
  1. 44 3
      src/lib/datasrc/tests/memory/zone_table_segment_test.h

+ 44 - 3
src/lib/datasrc/tests/memory/zone_table_segment_test.h

@@ -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