Commit 8545674c authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2377] Tests for actually loading something

parent 38149697
......@@ -37,7 +37,10 @@ public:
~MasterLoader();
bool loadIncremental(size_t count_limit);
//void load();
void load() {
while (!loadIncremental(1000)) {
}
}
private:
class MasterLoaderImpl;
......
......@@ -14,13 +14,21 @@
#include <dns/master_loader_callbacks.h>
#include <dns/master_loader.h>
#include <dns/rrtype.h>
#include <dns/rrset.h>
#include <gtest/gtest.h>
#include <boost/bind.hpp>
#include <boost/scoped_ptr.hpp>
#include <string>
#include <vector>
#include <list>
using namespace isc::dns;
using std::vector;
using std::string;
using std::list;
class MasterLoaderTest : public ::testing::Test {
public:
......@@ -33,42 +41,67 @@ public:
/// Concatenate file, line, and reason, and add it to either errors
/// or warnings
void
callback(bool error, const std::string& file, size_t line,
const std::string reason)
void callback(bool error, const std::string& file, size_t line,
const std::string reason)
{
std::stringstream ss;
ss << file << line << reason;
if (error) {
errors.push_back(ss.str());
errors_.push_back(ss.str());
} else {
warnings.push_back(ss.str());
warnings_.push_back(ss.str());
}
}
void addRRset(const RRsetPtr&) {
// TODO
void addRRset(const RRsetPtr& rrset) {
rrsets_.push_back(rrset);
}
void
setLoader(const char* file, const Name& origin, const RRClass rrclass,
const MasterLoader::Options options)
void setLoader(const char* file, const Name& origin, const RRClass rrclass,
const MasterLoader::Options options)
{
loader.reset(new MasterLoader(file, origin, rrclass, callbacks_,
boost::bind(&MasterLoaderTest::addRRset,
this, _1), options));
loader_.reset(new MasterLoader((string(TEST_DATA_SRCDIR) +
file).c_str(), origin, rrclass,
callbacks_,
boost::bind(&MasterLoaderTest::addRRset,
this, _1), options));
}
// Check the next RR in the ones produced by the loader
// Other than passed arguments are checked to be the default for the tests
void checkRR(const string& name, const RRType& type, const string& data) {
ASSERT_FALSE(rrsets_.empty());
RRsetPtr current = rrsets_.front();
rrsets_.pop_front();
EXPECT_EQ(Name(name), current->getName());
ASSERT_EQ(type, current->getType());
ASSERT_EQ(1, current->getRdataCount());
EXPECT_EQ(data, current->getRdataIterator()->getCurrent().toText());
}
MasterLoaderCallbacks callbacks_;
boost::scoped_ptr<MasterLoader> loader;
std::vector<std::string> errors;
std::vector<std::string> warnings;
boost::scoped_ptr<MasterLoader> loader_;
vector<string> errors_;
vector<string> warnings_;
list<RRsetPtr> rrsets_;
};
// Test simple loading. The zone file contains no tricky things, and nothing is
// omitted. No RRset contains more than one RR Also no errors or warnings.
TEST_F(MasterLoaderTest, basicLoad) {
setLoader("testdata/loader_test.txt",
Name("example.com."),
setLoader("example.org",
Name("example.org."),
RRClass::IN(),
MasterLoader::MANY_ERRORS);
ASSERT_FALSE(loader->loadIncremental(1));
loader_->load();
EXPECT_TRUE(errors_.empty());
EXPECT_TRUE(warnings_.empty());
checkRR("example.org", RRType::SOA(), "ns1.example.org. admin.example.org. "
"1234 3600 1800 2419200 7200");
checkRR("example.org", RRType::NS(), "ns1.example.org");
checkRR("www.example.org", RRType::A(), "192.0.2.1");
}
......@@ -170,6 +170,7 @@ EXTRA_DIST += tsig_verify1.spec tsig_verify2.spec tsig_verify3.spec
EXTRA_DIST += tsig_verify4.spec tsig_verify5.spec tsig_verify6.spec
EXTRA_DIST += tsig_verify7.spec tsig_verify8.spec tsig_verify9.spec
EXTRA_DIST += tsig_verify10.spec
EXTRA_DIST += example.org
.spec.wire:
$(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<
example.org. 3600 IN SOA ( ; The SOA, split across lines for testing
ns1.example.org.
admin.example.org.
1234
3600
1800
2419200
7200
)
example.org. 3600 IN NS ns1.example.org.
www.example.org. 3600 IN A 192.0.2.1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment