RRClass::IN(), MasterLoader::MANY_ERRORS);
EXPECT_FALSE(loader_->loadedSucessfully());
+
+ // The following three should be set to 0 initially in case the loader
+ // is constructed from a file name.
EXPECT_EQ(0, loader_->getRRCount());
+ EXPECT_EQ(0, loader_->getSize());
+ EXPECT_EQ(0, loader_->getPosition());
+
loader_->load();
EXPECT_TRUE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
+
+ // Hardcode expected values taken from the test data file, assuming it
+ // won't change too often.
EXPECT_EQ(4, loader_->getRRCount());
+ EXPECT_EQ(549, loader_->getSize());
+ EXPECT_EQ(549, loader_->getPosition());
checkBasicRRs();
}
}
}
+TEST_F(MasterLoaderTest, includeAndIncremental) {
+ // Check getSize() and getPosition() are adjusted before and after
+ // $INCLUDE.
+ const string first_rr = "before.example.org. 0 A 192.0.2.1\n";
+ const string include_str = "$INCLUDE " TEST_DATA_SRCDIR "/example.org";
+ const string zone_data = first_rr + include_str + "\n" +
+ "www 3600 IN AAAA 2001:db8::1\n";
+ stringstream ss(zone_data);
+ setLoader(ss, Name("example.org."), RRClass::IN(), MasterLoader::DEFAULT);
+
+ // On construction, getSize() returns the size of the data (exclude the
+ // the file to be included); position is set to 0.
+ EXPECT_EQ(zone_data.size(), loader_->getSize());
+ EXPECT_EQ(0, loader_->getPosition());
+
+ // Read the first RR. getSize() doesn't change; position should be
+ // at the end of the first line.
+ loader_->loadIncremental(1);
+ EXPECT_EQ(zone_data.size(), loader_->getSize());
+ EXPECT_EQ(first_rr.size(), loader_->getPosition());
+
+ // Read next 4. It includes $INCLUDE processing. Magic number of 549
+ // is the size of the test zone file (see above); 506 is the position in
+ // the file at the end of 4th RR (due to extra comments it's smaller than
+ // the file size).
+ loader_->loadIncremental(4);
+ EXPECT_EQ(zone_data.size() + 549, loader_->getSize());
+ EXPECT_EQ(first_rr.size() + include_str.size() + 506,
+ loader_->getPosition());
+
+ // Read the last one. At this point getSize and getPosition return
+ // the same value, indicating progress of 100%.
+ loader_->loadIncremental(1);
+ EXPECT_EQ(zone_data.size() + 549, loader_->getSize());
+ EXPECT_EQ(zone_data.size() + 549, loader_->getPosition());
+
+ // we were not interested in checking RRs in this test. clear them to
+ // not confuse TearDown().
+ rrsets_.clear();
+}
+
// A commonly used helper to check callback message.
void
checkCallbackMessage(const string& actual_msg, const string& expected_msg,
// Check it works the same when created based on a stream, not filename
TEST_F(MasterLoaderTest, streamConstructor) {
- stringstream zone_stream(prepareZone("", true));
+ const string zone_data(prepareZone("", true));
+ stringstream zone_stream(zone_data);
setLoader(zone_stream, Name("example.org."), RRClass::IN(),
MasterLoader::MANY_ERRORS);
EXPECT_FALSE(loader_->loadedSucessfully());
+
+ // Unlike the basicLoad test, if we construct the loader from a stream
+ // getSize() returns the data size in the stream immediately after the
+ // construction.
+ EXPECT_EQ(0, loader_->getRRCount());
+ EXPECT_EQ(zone_data.size(), loader_->getSize());
+ EXPECT_EQ(0, loader_->getPosition());
+
loader_->load();
EXPECT_TRUE(loader_->loadedSucessfully());
checkRR("example.org", RRType::SOA(), "ns1.example.org. "
"admin.example.org. 1234 3600 1800 2419200 7200");
checkRR("correct.example.org", RRType::A(), "192.0.2.2");
+
+ // On completion of the load, both getSize() and getPosition() return the
+ // size of the data, and getRRCount() returns the number of loaded RRs,
+ // which is 2 in this case.
+ EXPECT_EQ(2, loader_->getRRCount());
+ EXPECT_EQ(zone_data.size(), loader_->getSize());
+ EXPECT_EQ(zone_data.size(), loader_->getPosition());
}
// Try loading data incrementally.
setLoader(TEST_DATA_SRCDIR "/example.org", Name("example.org."),
RRClass::IN(), MasterLoader::MANY_ERRORS);
+ EXPECT_EQ(0, loader_->getRRCount()); // initial count should be 2
EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_FALSE(loader_->loadIncremental(2));
+ EXPECT_EQ(2, loader_->getRRCount()); // number of loaded RR so far
EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
checkRR("www.example.org", RRType::A(), "192.0.2.1");
checkRR("www.example.org", RRType::AAAA(), "2001:db8::1");
+
+ EXPECT_EQ(4, loader_->getRRCount()); // on completion it's # of zone's RRs.
}
// Try loading from file that doesn't exist. There should be single error