|
@@ -76,8 +76,8 @@ public:
|
|
|
void initAccessor(const std::string& filename, const RRClass& rrclass) {
|
|
|
db.reset(new SQLite3Database(filename, rrclass));
|
|
|
}
|
|
|
- // The tested dbection
|
|
|
- boost::scoped_ptr<SQLite3Database> db;
|
|
|
+ // The tested db
|
|
|
+ boost::shared_ptr<SQLite3Database> db;
|
|
|
};
|
|
|
|
|
|
// This zone exists in the data, so it should be found
|
|
@@ -103,6 +103,47 @@ TEST_F(SQLite3Access, noClass) {
|
|
|
EXPECT_FALSE(db->getZone(Name("example.com")).first);
|
|
|
}
|
|
|
|
|
|
+// This tests the iterator context
|
|
|
+TEST_F(SQLite3Access, iterator) {
|
|
|
+ // Our test zone is conveniently small, but not empty
|
|
|
+ initAccessor(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
|
|
|
+
|
|
|
+ // Get the iterator context
|
|
|
+ DatabaseAccessor::IteratorContextPtr
|
|
|
+ context(db->getAllRecords(Name("example2.com"), 1));
|
|
|
+ ASSERT_NE(DatabaseAccessor::IteratorContextPtr(),
|
|
|
+ context);
|
|
|
+
|
|
|
+ const size_t size(5);
|
|
|
+ std::string data[size];
|
|
|
+ // Get and check the first and only record
|
|
|
+ EXPECT_TRUE(context->getNext(data, size));
|
|
|
+ EXPECT_EQ("example2.com.", data[4]);
|
|
|
+ EXPECT_EQ("SOA", data[0]);
|
|
|
+ EXPECT_EQ("master.example2.com. admin.example2.com. "
|
|
|
+ "1234 3600 1800 2419200 7200", data[3]);
|
|
|
+ EXPECT_EQ("3600", data[1]);
|
|
|
+ // Check there's no other
|
|
|
+ EXPECT_FALSE(context->getNext(data, size));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SQLite3Access, iteratorColumnCount) {
|
|
|
+ // Our test zone is conveniently small, but not empty
|
|
|
+ initAccessor(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
|
|
|
+
|
|
|
+ // Get the iterator context
|
|
|
+ DatabaseAccessor::IteratorContextPtr
|
|
|
+ context(db->getAllRecords(Name("example2.com"), 1));
|
|
|
+ ASSERT_NE(DatabaseAccessor::IteratorContextPtr(),
|
|
|
+ context);
|
|
|
+
|
|
|
+ EXPECT_THROW(context->getNext(NULL, 0), DataSourceError);
|
|
|
+ std::string data[6];
|
|
|
+ EXPECT_THROW(context->getNext(data, 4), DataSourceError);
|
|
|
+ EXPECT_THROW(context->getNext(data, 6), DataSourceError);
|
|
|
+ EXPECT_NO_THROW(context->getNext(data, 5));
|
|
|
+}
|
|
|
+
|
|
|
TEST(SQLite3Open, getDBNameExample2) {
|
|
|
SQLite3Database db(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
|
|
|
EXPECT_EQ(SQLITE_DBNAME_EXAMPLE2, db.getDBName());
|
|
@@ -120,12 +161,14 @@ checkRecordRow(const std::string columns[],
|
|
|
const std::string& field0,
|
|
|
const std::string& field1,
|
|
|
const std::string& field2,
|
|
|
- const std::string& field3)
|
|
|
+ const std::string& field3,
|
|
|
+ const std::string& field4)
|
|
|
{
|
|
|
EXPECT_EQ(field0, columns[0]);
|
|
|
EXPECT_EQ(field1, columns[1]);
|
|
|
EXPECT_EQ(field2, columns[2]);
|
|
|
EXPECT_EQ(field3, columns[3]);
|
|
|
+ EXPECT_EQ(field4, columns[4]);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Access, getRecords) {
|
|
@@ -140,83 +183,89 @@ TEST_F(SQLite3Access, getRecords) {
|
|
|
|
|
|
// without search, getNext() should return false
|
|
|
EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "", "", "", "");
|
|
|
+ checkRecordRow(columns, "", "", "", "", "");
|
|
|
|
|
|
db->searchForRecords(zone_id, "foo.bar.");
|
|
|
EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "", "", "", "");
|
|
|
+ checkRecordRow(columns, "", "", "", "", "");
|
|
|
|
|
|
db->searchForRecords(zone_id, "");
|
|
|
EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "", "", "", "");
|
|
|
+ checkRecordRow(columns, "", "", "", "", "");
|
|
|
|
|
|
// Should error on a bad number of columns
|
|
|
- EXPECT_THROW(db->getNextRecord(columns, 3), DataSourceError);
|
|
|
- EXPECT_THROW(db->getNextRecord(columns, 5), DataSourceError);
|
|
|
+ EXPECT_THROW(db->getNextRecord(columns, 4), DataSourceError);
|
|
|
+ EXPECT_THROW(db->getNextRecord(columns, 6), DataSourceError);
|
|
|
|
|
|
// now try some real searches
|
|
|
db->searchForRecords(zone_id, "foo.example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "CNAME", "3600", "",
|
|
|
- "cnametest.example.org.");
|
|
|
+ "cnametest.example.org.", "foo.example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "CNAME",
|
|
|
"CNAME 5 3 3600 20100322084538 20100220084538 33495 "
|
|
|
- "example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "example.com. FAKEFAKEFAKEFAKE", "foo.example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NSEC", "7200", "",
|
|
|
- "mail.example.com. CNAME RRSIG NSEC");
|
|
|
+ "mail.example.com. CNAME RRSIG NSEC", "foo.example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 3 7200 20100322084538 20100220084538 33495 "
|
|
|
- "example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "example.com. FAKEFAKEFAKEFAKE", "foo.example.com.");
|
|
|
EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
// with no more records, the array should not have been modified
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 3 7200 20100322084538 20100220084538 33495 "
|
|
|
- "example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "example.com. FAKEFAKEFAKEFAKE", "foo.example.com.");
|
|
|
|
|
|
db->searchForRecords(zone_id, "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "SOA", "3600", "",
|
|
|
"master.example.com. admin.example.com. "
|
|
|
- "1234 3600 1800 2419200 7200");
|
|
|
+ "1234 3600 1800 2419200 7200", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "SOA",
|
|
|
"SOA 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "NS", "1200", "", "dns01.example.com.");
|
|
|
+ checkRecordRow(columns, "NS", "1200", "", "dns01.example.com.",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "NS", "3600", "", "dns02.example.com.");
|
|
|
+ checkRecordRow(columns, "NS", "3600", "", "dns02.example.com.",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "NS", "1800", "", "dns03.example.com.");
|
|
|
+ checkRecordRow(columns, "NS", "1800", "", "dns03.example.com.",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "NS",
|
|
|
"NS 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
- checkRecordRow(columns, "MX", "3600", "", "10 mail.example.com.");
|
|
|
+ checkRecordRow(columns, "MX", "3600", "", "10 mail.example.com.",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "MX", "3600", "",
|
|
|
- "20 mail.subzone.example.com.");
|
|
|
+ "20 mail.subzone.example.com.", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "MX",
|
|
|
"MX 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NSEC", "7200", "",
|
|
|
- "cname-ext.example.com. NS SOA MX RRSIG NSEC DNSKEY");
|
|
|
+ "cname-ext.example.com. NS SOA MX RRSIG NSEC DNSKEY",
|
|
|
+ "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 2 7200 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "DNSKEY", "3600", "",
|
|
|
"256 3 5 AwEAAcOUBllYc1hf7ND9uDy+Yz1BF3sI0m4q NGV7W"
|
|
|
"cTD0WEiuV7IjXgHE36fCmS9QsUxSSOV o1I/FMxI2PJVqTYHkX"
|
|
|
"FBS7AzLGsQYMU7UjBZ SotBJ6Imt5pXMu+lEDNy8TOUzG3xm7g"
|
|
|
- "0qcbW YF6qCEfvZoBtAqi5Rk7Mlrqs8agxYyMx");
|
|
|
+ "0qcbW YF6qCEfvZoBtAqi5Rk7Mlrqs8agxYyMx", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "DNSKEY", "3600", "",
|
|
|
"257 3 5 AwEAAe5WFbxdCPq2jZrZhlMj7oJdff3W7syJ tbvzg"
|
|
@@ -226,20 +275,20 @@ TEST_F(SQLite3Access, getRecords) {
|
|
|
"qiODyNZYQ+ZrLmF0KIJ2yPN3iO6Zq 23TaOrVTjB7d1a/h31OD"
|
|
|
"fiHAxFHrkY3t3D5J R9Nsl/7fdRmSznwtcSDgLXBoFEYmw6p86"
|
|
|
"Acv RyoYNcL1SXjaKVLG5jyU3UR+LcGZT5t/0xGf oIK/aKwEN"
|
|
|
- "rsjcKZZj660b1M=");
|
|
|
+ "rsjcKZZj660b1M=", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "4456 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "4456 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
// getnextrecord returning false should mean array is not altered
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
|
- "33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
+ "33495 example.com. FAKEFAKEFAKEFAKE", "example.com.");
|
|
|
}
|
|
|
|
|
|
} // end anonymous namespace
|