Browse Source

[2267] added a test that checks if load() with separate_rr iterator fails.

to catch any later regression.
JINMEI Tatuya 12 years ago
parent
commit
4a78f86fff
1 changed files with 27 additions and 4 deletions
  1. 27 4
      src/lib/datasrc/memory/tests/memory_client_unittest.cc

+ 27 - 4
src/lib/datasrc/memory/tests/memory_client_unittest.cc

@@ -51,7 +51,23 @@ namespace {
 const char* rrset_data[] = {
     "example.org. 3600 IN SOA ns1.example.org. bugs.x.w.example.org. "
     "68 3600 300 3600000 3600",
+    "a.example.org. 3600 IN A 192.168.0.1\n" // RRset containing 2 RRs
+    "a.example.org. 3600 IN A 192.168.0.2",
+// This will trigger a bug in the implementation
+//     "a.example.org. 3600 IN RRSIG A 5 3 3600 20150420235959 20051021000000 "
+//     "40430 example.org. FAKEFAKE",
+    "a.example.org. 3600 IN MX 10 mail.example.org.",
+    "a.example.org. 3600 IN RRSIG MX 5 3 3600 20150420235959 20051021000000 "
+    "40430 example.org. FAKEFAKEFAKE",
+    NULL
+};
+
+// Similar to the previous, but RRs of the same RRset are separated.
+const char* rrset_data_separated[] = {
+    "example.org. 3600 IN SOA ns1.example.org. bugs.x.w.example.org. "
+    "68 3600 300 3600000 3600",
     "a.example.org. 3600 IN A 192.168.0.1",
+    "a.example.org. 3600 IN A 192.168.0.2",
 // This will trigger a bug in the implementation
 //     "a.example.org. 3600 IN RRSIG A 5 3 3600 20150420235959 20051021000000 "
 //     "40430 example.org. FAKEFAKE",
@@ -63,8 +79,8 @@ const char* rrset_data[] = {
 
 class MockIterator : public ZoneIterator {
 private:
-    MockIterator() :
-        rrset_data_ptr_(rrset_data)
+    MockIterator(bool separate_rrs) :
+        rrset_data_ptr_(separate_rrs ? rrset_data_separated : rrset_data)
     {
     }
 
@@ -87,8 +103,8 @@ public:
         isc_throw(isc::NotImplemented, "Not implemented");
     }
 
-    static ZoneIteratorPtr makeIterator(void) {
-        return (ZoneIteratorPtr(new MockIterator()));
+    static ZoneIteratorPtr makeIterator(bool separate_rrs = false) {
+        return (ZoneIteratorPtr(new MockIterator(separate_rrs)));
     }
 };
 
@@ -197,6 +213,13 @@ TEST_F(MemoryClientTest, loadFromIterator) {
 
     // Iterating past the end should result in an exception
     EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
+
+    // Loading the zone with an iterator separating RRs of the same RRset
+    // will fail because the resulting sequence doesn't meet assumptions of
+    // the (current) in-memory implementation.
+    EXPECT_THROW(client_->load(Name("example.org"),
+                               *MockIterator::makeIterator(true)),
+                 InMemoryClient::AddError);
 }
 
 TEST_F(MemoryClientTest, loadMemoryAllocationFailures) {