Commit 25e56e5d authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] Merge branch 'trac1068'

with fixing conflicts in src/lib/datasrc/tests/database_unittest.cc
parents 87d2a876 64ac0166
......@@ -65,3 +65,4 @@ EXTRA_DIST += testdata/sql1.example.com.signed
EXTRA_DIST += testdata/sql2.example.com.signed
EXTRA_DIST += testdata/test-root.sqlite3
EXTRA_DIST += testdata/test.sqlite3
EXTRA_DIST += testdata/rwtest.sqlite3
......@@ -25,6 +25,7 @@
#include <datasrc/zone.h>
#include <datasrc/data_source.h>
#include <datasrc/iterator.h>
#include <datasrc/sqlite3_accessor.h>
#include <testutils/dnsmessage_test.h>
......@@ -41,6 +42,135 @@ namespace {
const int READONLY_ZONE_ID = 42;
const int WRITABLE_ZONE_ID = 4200;
// Commonly used test data
const char* const TEST_RECORDS[][5] = {
// some plain data
{"www.example.org.", "A", "3600", "", "192.0.2.1"},
{"www.example.org.", "AAAA", "3600", "", "2001:db8::1"},
{"www.example.org.", "AAAA", "3600", "", "2001:db8::2"},
{"www2.example.org.", "A", "3600", "", "192.0.2.1"},
{"www2.example.org.","AAAA", "3600", "", "2001:db8::1"},
{"www2.example.org.", "A", "3600", "", "192.0.2.2"},
{"cname.example.org.", "CNAME", "3600", "", "www.example.org."},
// some DNSSEC-'signed' data
{"signed1.example.org.", "A", "3600", "", "192.0.2.1"},
{"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
{"signed1.example.org.", "AAAA", "3600", "", "2001:db8::1"},
{"signed1.example.org.", "AAAA", "3600", "", "2001:db8::2"},
{"signed1.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"signedcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
{"signedcname1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
// special case might fail; sig is for cname, which isn't there (should be ignored)
// (ignoring of 'normal' other type is done above by www.)
{"acnamesig1.example.org.", "A", "3600", "", "192.0.2.1"},
{"acnamesig1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"acnamesig1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
// let's pretend we have a database that is not careful
// about the order in which it returns data
{"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"signed2.example.org.", "AAAA", "3600", "", "2001:db8::2"},
{"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
{"signed2.example.org.", "A", "3600", "", "192.0.2.1"},
{"signed2.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"signed2.example.org.", "AAAA", "3600", "", "2001:db8::1"},
{"signedcname2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"signedcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
{"acnamesig2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"acnamesig2.example.org.", "A", "3600", "", "192.0.2.1"},
{"acnamesig2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"acnamesig3.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"acnamesig3.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"acnamesig3.example.org.", "A", "3600", "", "192.0.2.1"},
{"ttldiff1.example.org.", "A", "3600", "", "192.0.2.1"},
{"ttldiff1.example.org.", "A", "360", "", "192.0.2.2"},
{"ttldiff2.example.org.", "A", "360", "", "192.0.2.1"},
{"ttldiff2.example.org.", "A", "3600", "", "192.0.2.2"},
// also add some intentionally bad data
{"badcname1.example.org.", "A", "3600", "", "192.0.2.1"},
{"badcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
{"badcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
{"badcname2.example.org.", "A", "3600", "", "192.0.2.1"},
{"badcname3.example.org.", "CNAME", "3600", "", "www.example.org."},
{"badcname3.example.org.", "CNAME", "3600", "", "www.example2.org."},
{"badrdata.example.org.", "A", "3600", "", "bad"},
{"badtype.example.org.", "BAD_TYPE", "3600", "", "192.0.2.1"},
{"badttl.example.org.", "A", "badttl", "", "192.0.2.1"},
{"badsig.example.org.", "A", "badttl", "", "192.0.2.1"},
{"badsig.example.org.", "RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"badsigtype.example.org.", "A", "3600", "", "192.0.2.1"},
{"badsigtype.example.org.", "RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
// Data for testing delegation (with NS and DNAME)
{"delegation.example.org.", "NS", "3600", "", "ns.example.com."},
{"delegation.example.org.", "NS", "3600", "",
"ns.delegation.example.org."},
{"delegation.example.org.", "RRSIG", "3600", "", "NS 5 3 3600 "
"20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"ns.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
{"deep.below.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
{"dname.example.org.", "A", "3600", "", "192.0.2.1"},
{"dname.example.org.", "DNAME", "3600", "", "dname.example.com."},
{"dname.example.org.", "RRSIG", "3600", "",
"DNAME 5 3 3600 20000101000000 20000201000000 12345 "
"example.org. FAKEFAKEFAKE"},
{"below.dname.example.org.", "A", "3600", "", "192.0.2.1"},
// Broken NS
{"brokenns1.example.org.", "A", "3600", "", "192.0.2.1"},
{"brokenns1.example.org.", "NS", "3600", "", "ns.example.com."},
{"brokenns2.example.org.", "NS", "3600", "", "ns.example.com."},
{"brokenns2.example.org.", "A", "3600", "", "192.0.2.1"},
// Now double DNAME, to test failure mode
{"baddname.example.org.", "DNAME", "3600", "", "dname1.example.com."},
{"baddname.example.org.", "DNAME", "3600", "", "dname2.example.com."},
// Put some data into apex (including NS) so we can check our NS
// doesn't break anything
{"example.org.", "NS", "3600", "", "ns.example.com."},
{"example.org.", "A", "3600", "", "192.0.2.1"},
{"example.org.", "RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
"20000201000000 12345 example.org. FAKEFAKEFAKE"},
// This is because of empty domain test
{"a.b.example.org.", "A", "3600", "", "192.0.2.1"},
// Something for wildcards
{"*.wild.example.org.", "A", "3600", "", "192.0.2.5"},
{"*.wild.example.org.", "RRSIG", "3600", "A", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
{"cancel.here.wild.example.org.", "AAAA", "3600", "", "2001:db8::5"},
{"delegatedwild.example.org.", "NS", "3600", "", "ns.example.com."},
{"*.delegatedwild.example.org.", "A", "3600", "", "192.0.2.5"},
{"wild.*.foo.example.org.", "A", "3600", "", "192.0.2.5"},
{"wild.*.foo.*.bar.example.org.", "A", "3600", "", "192.0.2.5"},
{NULL, NULL, NULL, NULL, NULL},
};
/*
* An accessor with minimum implementation, keeping the original
* "NotImplemented" methods.
......@@ -481,156 +611,17 @@ private:
// might not come in 'normal' order)
// It shall immediately fail if you try to add the same name twice.
void fillData() {
// some plain data
addRecord("A", "3600", "", "192.0.2.1");
addRecord("AAAA", "3600", "", "2001:db8::1");
addRecord("AAAA", "3600", "", "2001:db8::2");
addCurName("www.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("AAAA", "3600", "", "2001:db8::1");
addRecord("A", "3600", "", "192.0.2.2");
addCurName("www2.example.org.");
addRecord("CNAME", "3600", "", "www.example.org.");
addCurName("cname.example.org.");
// some DNSSEC-'signed' data
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
addRecord("AAAA", "3600", "", "2001:db8::1");
addRecord("AAAA", "3600", "", "2001:db8::2");
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("signed1.example.org.");
addRecord("CNAME", "3600", "", "www.example.org.");
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("signedcname1.example.org.");
// special case might fail; sig is for cname, which isn't there (should be ignored)
// (ignoring of 'normal' other type is done above by www.)
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("acnamesig1.example.org.");
// let's pretend we have a database that is not careful
// about the order in which it returns data
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("AAAA", "3600", "", "2001:db8::2");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("AAAA", "3600", "", "2001:db8::1");
addCurName("signed2.example.org.");
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("CNAME", "3600", "", "www.example.org.");
addCurName("signedcname2.example.org.");
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("acnamesig2.example.org.");
addRecord("RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("acnamesig3.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("A", "360", "", "192.0.2.2");
addCurName("ttldiff1.example.org.");
addRecord("A", "360", "", "192.0.2.1");
addRecord("A", "3600", "", "192.0.2.2");
addCurName("ttldiff2.example.org.");
// also add some intentionally bad data
addRecord("A", "3600", "", "192.0.2.1");
addRecord("CNAME", "3600", "", "www.example.org.");
addCurName("badcname1.example.org.");
addRecord("CNAME", "3600", "", "www.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("badcname2.example.org.");
addRecord("CNAME", "3600", "", "www.example.org.");
addRecord("CNAME", "3600", "", "www.example2.org.");
addCurName("badcname3.example.org.");
addRecord("A", "3600", "", "bad");
addCurName("badrdata.example.org.");
addRecord("BAD_TYPE", "3600", "", "192.0.2.1");
addCurName("badtype.example.org.");
addRecord("A", "badttl", "", "192.0.2.1");
addCurName("badttl.example.org.");
addRecord("A", "badttl", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("badsig.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("badsigtype.example.org.");
// Data for testing delegation (with NS and DNAME)
addRecord("NS", "3600", "", "ns.example.com.");
addRecord("NS", "3600", "", "ns.delegation.example.org.");
addRecord("RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
"20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("delegation.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("ns.delegation.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("deep.below.delegation.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("DNAME", "3600", "", "dname.example.com.");
addRecord("RRSIG", "3600", "", "DNAME 5 3 3600 20000101000000 "
"20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("dname.example.org.");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("below.dname.example.org.");
// Broken NS
addRecord("A", "3600", "", "192.0.2.1");
addRecord("NS", "3600", "", "ns.example.com.");
addCurName("brokenns1.example.org.");
addRecord("NS", "3600", "", "ns.example.com.");
addRecord("A", "3600", "", "192.0.2.1");
addCurName("brokenns2.example.org.");
// Now double DNAME, to test failure mode
addRecord("DNAME", "3600", "", "dname1.example.com.");
addRecord("DNAME", "3600", "", "dname2.example.com.");
addCurName("baddname.example.org.");
// Put some data into apex (including NS) so we can check our NS
// doesn't break anything
addRecord("NS", "3600", "", "ns.example.com.");
addRecord("A", "3600", "", "192.0.2.1");
addRecord("RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
"20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("example.org.");
// This is because of empty domain test
addRecord("A", "3600", "", "192.0.2.1");
addCurName("a.b.example.org.");
// Something for wildcards
addRecord("A", "3600", "", "192.0.2.5");
addRecord("RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
addCurName("*.wild.example.org.");
addRecord("AAAA", "3600", "", "2001:db8::5");
addCurName("cancel.here.wild.example.org.");
addRecord("NS", "3600", "", "ns.example.com.");
addCurName("delegatedwild.example.org.");
addRecord("A", "3600", "", "192.0.2.5");
addCurName("*.delegatedwild.example.org.");
addRecord("A", "3600", "", "192.0.2.5");
addCurName("wild.*.foo.example.org.");
addRecord("A", "3600", "", "192.0.2.5");
addCurName("wild.*.foo.*.bar.example.org.");
const char* prev_name = NULL;
for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
if (prev_name != NULL &&
strcmp(prev_name, TEST_RECORDS[i][0]) != 0) {
addCurName(prev_name);
}
prev_name = TEST_RECORDS[i][0];
addRecord(TEST_RECORDS[i][1], TEST_RECORDS[i][2],
TEST_RECORDS[i][3], TEST_RECORDS[i][4]);
}
addCurName(prev_name);
}
};
......@@ -647,6 +638,10 @@ TEST(DatabaseConnectionTest, getAllRecords) {
isc::NotImplemented);
}
// This test fixture is templated so that we can share (most of) the test
// cases with different types of data sources. Note that in test cases
// we need to use 'this' to refer to member variables of the test class.
template <typename ACCESSOR_TYPE>
class DatabaseClientTest : public ::testing::Test {
public:
DatabaseClientTest() : zname_("example.org"), qname_("www.example.org"),
......@@ -682,9 +677,10 @@ public:
* times per test.
*/
void createClient() {
current_accessor_ = new MockAccessor();
current_accessor_ = new ACCESSOR_TYPE();
is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_) != NULL);
client_.reset(new DatabaseClient(qclass_,
shared_ptr<DatabaseAccessor>(
shared_ptr<ACCESSOR_TYPE>(
current_accessor_)));
}
......@@ -698,7 +694,9 @@ public:
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
"Wrong type of finder";
if (is_mock_) {
EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
}
EXPECT_EQ(current_accessor_, &finder->getAccessor());
}
......@@ -707,29 +705,49 @@ public:
EXPECT_EQ(result::SUCCESS, zone.code);
shared_ptr<DatabaseClient::Finder> finder(
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
if (is_mock_) {
EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
}
return (finder);
}
// Helper methods for update tests
bool isRollbacked() const {
return (update_accessor_->isRollbacked());
bool isRollbacked(bool expected = false) const {
if (is_mock_) {
const MockAccessor& mock_accessor =
dynamic_cast<const MockAccessor&>(*update_accessor_);
return (mock_accessor.isRollbacked());
} else {
return (expected);
}
}
void checkLastAdded(const char* const expected[]) const {
if (is_mock_) {
const MockAccessor* mock_accessor =
dynamic_cast<const MockAccessor*>(current_accessor_);
for (int i = 0; i < DatabaseAccessor::ADD_COLUMN_COUNT; ++i) {
EXPECT_EQ(expected[i],
current_accessor_->getLatestClone()->getLastAdded()[i]);
mock_accessor->getLatestClone()->getLastAdded()[i]);
}
}
}
void setUpdateAccessor() {
update_accessor_ = current_accessor_->getLatestClone();
if (is_mock_) {
const MockAccessor* mock_accessor =
dynamic_cast<const MockAccessor*>(current_accessor_);
update_accessor_ = mock_accessor->getLatestClone();
}
}
// Some tests only work for MockAccessor. We remember whether our accessor
// is of that type.
bool is_mock_;
// Will be deleted by client_, just keep the current value for comparison.
MockAccessor* current_accessor_;
ACCESSOR_TYPE* current_accessor_;
shared_ptr<DatabaseClient> client_;
const std::string database_name_;
......@@ -747,7 +765,7 @@ public:
// update related objects to be tested
ZoneUpdaterPtr updater_;
shared_ptr<const MockAccessor> update_accessor_;
shared_ptr<const DatabaseAccessor> update_accessor_;
// placeholders
const std::vector<std::string> empty_rdatas_; // for NXRRSET/NXDOMAIN
......@@ -755,25 +773,60 @@ public:
std::vector<std::string> expected_sig_rdatas_;
};
TEST_F(DatabaseClientTest, zoneNotFound) {
DataSourceClient::FindResult zone(client_->findZone(Name("example.com")));
class TestSQLite3Accessor : public SQLite3Accessor {
public:
TestSQLite3Accessor() : SQLite3Accessor(
TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied",
RRClass::IN())
{
startUpdateZone("example.org.", true);
string columns[ADD_COLUMN_COUNT];
for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
columns[ADD_NAME] = TEST_RECORDS[i][0];
columns[ADD_REV_NAME] = Name(columns[ADD_NAME]).reverse().toText();
columns[ADD_TYPE] = TEST_RECORDS[i][1];
columns[ADD_TTL] = TEST_RECORDS[i][2];
columns[ADD_SIGTYPE] = TEST_RECORDS[i][3];
columns[ADD_RDATA] = TEST_RECORDS[i][4];
addRecordToZone(columns);
}
commitUpdateZone();
}
};
// The following two lines instantiate test cases with concrete accessor
// classes to be tested.
typedef ::testing::Types<MockAccessor, TestSQLite3Accessor> TestAccessorTypes;
TYPED_TEST_CASE(DatabaseClientTest, TestAccessorTypes);
// In some cases the entire test fixture is for the mock accessor only.
// We use the usual TEST_F for them with the corresponding specialized class
// to make the code simpler.
typedef DatabaseClientTest<MockAccessor> MockDatabaseClientTest;
TYPED_TEST(DatabaseClientTest, zoneNotFound) {
DataSourceClient::FindResult zone(
this->client_->findZone(Name("example.com")));
EXPECT_EQ(result::NOTFOUND, zone.code);
}
TEST_F(DatabaseClientTest, exactZone) {
DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
TYPED_TEST(DatabaseClientTest, exactZone) {
DataSourceClient::FindResult zone(
this->client_->findZone(Name("example.org")));
EXPECT_EQ(result::SUCCESS, zone.code);
checkZoneFinder(zone);
this->checkZoneFinder(zone);
}
TEST_F(DatabaseClientTest, superZone) {
DataSourceClient::FindResult zone(client_->findZone(Name(
TYPED_TEST(DatabaseClientTest, superZone) {
DataSourceClient::FindResult zone(this->client_->findZone(Name(
"sub.example.org")));
EXPECT_EQ(result::PARTIALMATCH, zone.code);
checkZoneFinder(zone);
this->checkZoneFinder(zone);
}
TEST_F(DatabaseClientTest, noAccessorException) {
// This test doesn't depend on derived accessor class, so we use TEST().
TEST(GenericDatabaseClientTest, noAccessorException) {
// We need a dummy variable here; some compiler would regard it a mere
// declaration instead of an instantiation and make the test fail.
EXPECT_THROW(DatabaseClient dummy(RRClass::IN(),
......@@ -782,13 +835,14 @@ TEST_F(DatabaseClientTest, noAccessorException) {
}
// If the zone doesn't exist, exception is thrown
TEST_F(DatabaseClientTest, noZoneIterator) {
EXPECT_THROW(client_->getIterator(Name("example.com")), DataSourceError);
TYPED_TEST(DatabaseClientTest, noZoneIterator) {
EXPECT_THROW(this->client_->getIterator(Name("example.com")),
DataSourceError);
}
// If the zone doesn't exist and iteration is not implemented, it still throws
// the exception it doesn't exist
TEST_F(DatabaseClientTest, noZoneNotImplementedIterator) {
TEST(GenericDatabaseClientTest, noZoneNotImplementedIterator) {
EXPECT_THROW(DatabaseClient(RRClass::IN(),
boost::shared_ptr<DatabaseAccessor>(
new NopAccessor())).getIterator(
......@@ -796,32 +850,39 @@ TEST_F(DatabaseClientTest, noZoneNotImplementedIterator) {
DataSourceError);
}
TEST_F(DatabaseClientTest, notImplementedIterator) {
TEST(GenericDatabaseClientTest, notImplementedIterator) {
EXPECT_THROW(DatabaseClient(RRClass::IN(), shared_ptr<DatabaseAccessor>(
new NopAccessor())).getIterator(Name("example.org")),
isc::NotImplemented);
}
// Pretend a bug in the connection and pass NULL as the context
// Should not crash, but gracefully throw
TEST_F(DatabaseClientTest, nullIteratorContext) {
EXPECT_THROW(client_->getIterator(Name("null.example.org")),
// Should not crash, but gracefully throw. Works for the mock accessor only.
TEST_F(MockDatabaseClientTest, nullIteratorContext) {
EXPECT_THROW(this->client_->getIterator(Name("null.example.org")),
isc::Unexpected);
}
// It doesn't crash or anything if the zone is completely empty
TEST_F(DatabaseClientTest, emptyIterator) {
ZoneIteratorPtr it(client_->getIterator(Name("empty.example.org")));
// It doesn't crash or anything if the zone is completely empty.
// Works for the mock accessor only.
TEST_F(MockDatabaseClientTest, emptyIterator) {
ZoneIteratorPtr it(this->client_->getIterator(Name("empty.example.org")));
EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
// This is past the end, it should throw
EXPECT_THROW(it->getNextRRset(), isc::Unexpected);
}
// Iterate trough a zone
TEST_F(DatabaseClientTest, iterator) {
ZoneIteratorPtr it(client_->getIterator(Name("example.org")));
// Iterate through a zone
TYPED_TEST(DatabaseClientTest, iterator) {
ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
ConstRRsetPtr rrset(it->getNextRRset());
ASSERT_NE(ConstRRsetPtr(), rrset);
// The rest of the checks work only for the mock accessor.
if (!this->is_mock_) {
return;
}
EXPECT_EQ(Name("example.org"), rrset->getName());
EXPECT_EQ(RRClass::IN(), rrset->getClass());
EXPECT_EQ(RRType::SOA(), rrset->getType());
......@@ -864,10 +925,10 @@ TEST_F(DatabaseClientTest, iterator) {
}
// This has inconsistent TTL in the set (the rest, like nonsense in
// the data is handled in rdata itself).
TEST_F(DatabaseClientTest, badIterator) {
// the data is handled in rdata itself). Works for the mock accessor only.
TEST_F(MockDatabaseClientTest, badIterator) {
// It should not throw, but get the lowest one of them
ZoneIteratorPtr it(client_->getIterator(Name("bad.example.org")));
ZoneIteratorPtr it(this->client_->getIterator(Name("bad.example.org")));
EXPECT_EQ(it->getNextRRset()->getTTL(), isc::dns::RRTTL(300));
}
......@@ -924,551 +985,520 @@ doFindTest(ZoneFinder& finder,
}
}
TEST_F(DatabaseClientTest, find) {
shared_ptr<DatabaseClient::Finder> finder(getFinder());
TYPED_TEST(DatabaseClientTest, find) {
shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
expected_rdatas_.clear();
expected_sig_rdatas_.clear();
expected_rdatas_.push_back("192.0.2.1");
this->expected_rdatas_.clear();
this->expected_sig_rdatas_.clear();
this->expected_rdatas_.push_back("192.0.2.1");
doFindTest(*finder, isc::dns::Name("www.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
ZoneFinder::SUCCESS,
expected_rdatas_, expected_sig_rdatas_);
this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
this->expected_rdatas_, this->expected_sig_rdatas_);
expected_rdatas_.clear();
expected_sig_rdatas_.clear();
expected_rdatas_.push_back("192.0.2.1");
expected_rdatas_.push_back("192.0.2.2");
this->expected_rdatas_.clear();
this->expected_sig_rdatas_.clear();
this->expected_rdatas_.push_back("192.0.2.1");
this->expected