initialized_(false),
ok_(true),
many_errors_((options & MANY_ERRORS) != 0),
- complete_(false)
+ complete_(false),
+ seen_error_(false)
{}
void reportError(const std::string& filename, size_t line,
const std::string& reason)
{
+ seen_error_ = true;
callbacks_.error(filename, line, reason);
if (!many_errors_) {
// In case we don't have the lenient mode, every error is fatal
const std::string master_file_;
std::string string_token_;
bool initialized_;
- bool ok_;
- const bool many_errors_;
+ bool ok_; // Is it OK to continue loading?
+ const bool many_errors_; // Are many errors allowed (or should we abort
+ // on the first)
public:
- bool complete_;
+ bool complete_; // All work done.
+ bool seen_error_; // Was there at least one error during the
+ // load?
};
bool
// Good, we loaded another one
++count;
- } else if (!many_errors_) {
- ok_ = false;
- complete_ = true;
- // We don't have the exact error here, but it was reported
- // by the error callback.
- isc_throw(MasterLoaderError, "Invalid RR data");
+ } else {
+ seen_error_ = true;
+ if (!many_errors_) {
+ ok_ = false;
+ complete_ = true;
+ // We don't have the exact error here, but it was reported
+ // by the error callback.
+ isc_throw(MasterLoaderError, "Invalid RR data");
+ }
}
} catch (const MasterLoaderError&) {
// This is a hack. We exclude the MasterLoaderError from the
return (result);
}
+bool
+MasterLoader::loadedSucessfully() const {
+ return (impl_->complete_ && !impl_->seen_error_);
+}
+
} // end namespace dns
} // end namespace isc
setLoader(TEST_DATA_SRCDIR "/example.org", Name("example.org."),
RRClass::IN(), MasterLoader::MANY_ERRORS);
+ EXPECT_FALSE(loader_->loadedSucessfully());
loader_->load();
+ EXPECT_TRUE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
setLoader(zone_stream, Name("example.org."), RRClass::IN(),
MasterLoader::MANY_ERRORS);
+ EXPECT_FALSE(loader_->loadedSucessfully());
loader_->load();
+ EXPECT_TRUE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
setLoader(TEST_DATA_SRCDIR "/example.org", Name("example.org."),
RRClass::IN(), MasterLoader::MANY_ERRORS);
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_FALSE(loader_->loadIncremental(2));
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
// Load the rest.
EXPECT_TRUE(loader_->loadIncremental(20));
+ EXPECT_TRUE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
stringstream zone_stream(zone);
setLoader(zone_stream, Name("example.org."), RRClass::IN(),
MasterLoader::DEFAULT);
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_THROW(loader_->load(), MasterLoaderError);
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_EQ(1, errors_.size()) << errors_[0];
EXPECT_TRUE(warnings_.empty());
stringstream zone_stream(zone);
setLoader(zone_stream, Name("example.org."), RRClass::IN(),
MasterLoader::MANY_ERRORS);
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_NO_THROW(loader_->load());
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_EQ(1, errors_.size());
EXPECT_TRUE(warnings_.empty());
checkRR("example.org", RRType::SOA(), "ns1.example.org. "
stringstream zone_stream(zoneEOF);
setLoader(zone_stream, Name("example.org."), RRClass::IN(),
MasterLoader::MANY_ERRORS);
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_NO_THROW(loader_->load());
+ EXPECT_FALSE(loader_->loadedSucessfully());
EXPECT_EQ(1, errors_.size());
// FIXME: The invalid rdata generates a warning.
// And we may want to generate warning ourself here too.