[svn] commit: r2510 - in /trunk/src/lib/datasrc/tests: ./ testdata/
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jul 15 22:55:29 UTC 2010
Author: jinmei
Date: Thu Jul 15 22:55:29 2010
New Revision: 2510
Log:
minor cleanups for tests:
- generate queries in the code instead of using wire-format data.
it doesn't make much sense to use wire-format test data for valid
messages in terms of readability and maintainability.
- don't use a public name in tests. we should use reserved domains
for doc/tests.
I'm directly committing this to trunk. The changes may not be super trivial,
but they are basically straightforward translation (+ minor change of a
test domain name). so I think it's not worth wasting time of other developers.
the tests pass with these changes, of course.
Removed:
trunk/src/lib/datasrc/tests/testdata/q_cname
trunk/src/lib/datasrc/tests/testdata/q_cname_ext
trunk/src/lib/datasrc/tests/testdata/q_cname_int
trunk/src/lib/datasrc/tests/testdata/q_dname
trunk/src/lib/datasrc/tests/testdata/q_example_dnskey
trunk/src/lib/datasrc/tests/testdata/q_example_ns
trunk/src/lib/datasrc/tests/testdata/q_example_ptr
trunk/src/lib/datasrc/tests/testdata/q_glork
trunk/src/lib/datasrc/tests/testdata/q_spork
trunk/src/lib/datasrc/tests/testdata/q_sql1
trunk/src/lib/datasrc/tests/testdata/q_subzone
trunk/src/lib/datasrc/tests/testdata/q_subzone_any
trunk/src/lib/datasrc/tests/testdata/q_subzone_dname
trunk/src/lib/datasrc/tests/testdata/q_subzone_ds
trunk/src/lib/datasrc/tests/testdata/q_subzone_ns
trunk/src/lib/datasrc/tests/testdata/q_subzone_nsec
trunk/src/lib/datasrc/tests/testdata/q_wild2_a
trunk/src/lib/datasrc/tests/testdata/q_wild2_aaaa
trunk/src/lib/datasrc/tests/testdata/q_wild3_a
trunk/src/lib/datasrc/tests/testdata/q_wild_a
trunk/src/lib/datasrc/tests/testdata/q_wild_aaaa
Modified:
trunk/src/lib/datasrc/tests/datasrc_unittest.cc
trunk/src/lib/datasrc/tests/query_unittest.cc
Modified: trunk/src/lib/datasrc/tests/datasrc_unittest.cc
==============================================================================
--- trunk/src/lib/datasrc/tests/datasrc_unittest.cc (original)
+++ trunk/src/lib/datasrc/tests/datasrc_unittest.cc Thu Jul 15 22:55:29 2010
@@ -193,8 +193,8 @@
}
TEST_F(DataSrcTest, NSQuery) {
- readAndProcessQuery("q_example_ns");
-
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::NS());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -216,7 +216,8 @@
// Make sure two successive queries have the same result
TEST_F(DataSrcTest, DuplicateQuery) {
- readAndProcessQuery("q_example_ns");
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::NS());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -236,7 +237,8 @@
EXPECT_TRUE(it->isLast());
msg.clear(Message::PARSE);
- readAndProcessQuery("q_example_ns");
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::NS());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 0, 6);
rit = msg.beginSection(Section::ANSWER());
@@ -257,7 +259,8 @@
}
TEST_F(DataSrcTest, DNSKEYQuery) {
- readAndProcessQuery("q_example_dnskey");
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::DNSKEY());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -271,7 +274,8 @@
// We query for a record at a zone cut to ensure the REFERRAL flag doesn't
// cause incorrect behavior.
TEST_F(DataSrcTest, DNSKEYDuplicateQuery) {
- readAndProcessQuery("q_example_dnskey");
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::DNSKEY());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -281,9 +285,8 @@
EXPECT_EQ(RRClass::IN(), rrset->getClass());
msg.clear(Message::PARSE);
- readAndProcessQuery("q_example_dnskey");
- headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
-
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::DNSKEY());
rit = msg.beginSection(Section::ANSWER());
rrset = *rit;
EXPECT_EQ(Name("example.com"), rrset->getName());
@@ -292,7 +295,8 @@
}
TEST_F(DataSrcTest, NxRRset) {
- readAndProcessQuery("q_example_ptr");
+ createAndProcessQuery(Name("example.com"), RRClass::IN(),
+ RRType::PTR());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 4, 0);
@@ -303,7 +307,8 @@
}
TEST_F(DataSrcTest, Nxdomain) {
- readAndProcessQuery("q_glork");
+ createAndProcessQuery(Name("glork.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NXDOMAIN(), true, true, true, 0, 6, 0);
@@ -316,7 +321,8 @@
}
TEST_F(DataSrcTest, NxZone) {
- readAndProcessQuery("q_spork");
+ createAndProcessQuery(Name("spork.example"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::REFUSED(), true, false, true, 0, 0, 0);
@@ -327,7 +333,8 @@
}
TEST_F(DataSrcTest, Wildcard) {
- readAndProcessQuery("q_wild_a");
+ createAndProcessQuery(Name("www.wild.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 6, 6);
@@ -380,17 +387,18 @@
}
TEST_F(DataSrcTest, WildcardNodata) {
-
// Check that a query for a data type not covered by the wildcard
// returns NOERROR
- readAndProcessQuery("q_wild_aaaa");
+ createAndProcessQuery(Name("www.wild.example.com"), RRClass::IN(),
+ RRType::AAAA());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 2, 0);
}
TEST_F(DataSrcTest, WildcardCname) {
// Check that wildcard answers containing CNAMES are followed
// correctly
- readAndProcessQuery("q_wild2_a");
+ createAndProcessQuery(Name("www.wild2.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 6, 6);
@@ -458,7 +466,8 @@
TEST_F(DataSrcTest, WildcardCnameNodata) {
// A wildcard containing a CNAME whose target does not include
// data of this type.
- readAndProcessQuery("q_wild2_aaaa");
+ createAndProcessQuery(Name("www.wild2.example.com"), RRClass::IN(),
+ RRType::AAAA());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 0);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -489,7 +498,8 @@
TEST_F(DataSrcTest, WildcardCnameNxdomain) {
// A wildcard containing a CNAME whose target does not exist
- readAndProcessQuery("q_wild3_a");
+ createAndProcessQuery(Name("www.wild3.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 6, 0);
RRsetIterator rit = msg.beginSection(Section::ANSWER());
@@ -525,7 +535,8 @@
EXPECT_EQ(RRClass::IN(), rrset->getClass());
}
TEST_F(DataSrcTest, AuthDelegation) {
- readAndProcessQuery("q_sql1");
+ createAndProcessQuery(Name("www.sql1.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 6);
@@ -571,7 +582,8 @@
}
TEST_F(DataSrcTest, Dname) {
- readAndProcessQuery("q_dname");
+ createAndProcessQuery(Name("www.dname.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 5, 4, 6);
@@ -628,7 +640,8 @@
}
TEST_F(DataSrcTest, Cname) {
- readAndProcessQuery("q_cname");
+ createAndProcessQuery(Name("foo.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 0, 0);
@@ -646,7 +659,8 @@
}
TEST_F(DataSrcTest, CnameInt) {
- readAndProcessQuery("q_cname_int");
+ createAndProcessQuery(Name("cname-int.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
@@ -672,7 +686,8 @@
}
TEST_F(DataSrcTest, CnameExt) {
- readAndProcessQuery("q_cname_ext");
+ createAndProcessQuery(Name("cname-ext.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 4, 4, 6);
@@ -696,7 +711,8 @@
}
TEST_F(DataSrcTest, Delegation) {
- readAndProcessQuery("q_subzone");
+ createAndProcessQuery(Name("www.subzone.example.com"), RRClass::IN(),
+ RRType::A());
headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
@@ -726,7 +742,8 @@
}
TEST_F(DataSrcTest, NSDelegation) {
- readAndProcessQuery("q_subzone_ns");
+ createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+ RRType::NS());
headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
@@ -758,12 +775,13 @@
TEST_F(DataSrcTest, ANYZonecut) {
// An ANY query at a zone cut should behave the same as any other
// delegation
- readAndProcessQuery("q_subzone_any");
-
+ createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+ RRType::ANY());
}
TEST_F(DataSrcTest, NSECZonecut) {
- readAndProcessQuery("q_subzone_nsec");
+ createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+ RRType::NSEC());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 2, 4, 6);
@@ -791,7 +809,8 @@
}
TEST_F(DataSrcTest, DNAMEZonecut) {
- readAndProcessQuery("q_subzone_dname");
+ createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+ RRType::DNAME());
headerCheck(msg, Rcode::NOERROR(), true, false, true, 0, 5, 2);
RRsetIterator rit = msg.beginSection(Section::AUTHORITY());
@@ -820,7 +839,8 @@
}
TEST_F(DataSrcTest, DS) {
- readAndProcessQuery("q_subzone_ds");
+ createAndProcessQuery(Name("subzone.example.com"), RRClass::IN(),
+ RRType::DS());
headerCheck(msg, Rcode::NOERROR(), true, true, true, 3, 4, 6);
Modified: trunk/src/lib/datasrc/tests/query_unittest.cc
==============================================================================
--- trunk/src/lib/datasrc/tests/query_unittest.cc (original)
+++ trunk/src/lib/datasrc/tests/query_unittest.cc Thu Jul 15 22:55:29 2010
@@ -32,20 +32,13 @@
namespace {
-class QueryTest : public ::testing::Test {
-protected:
- void readQuery(Message& m, const char* datafile);
-
- HotCache cache;
-};
-
void
-QueryTest::readQuery(Message& m, const char* datafile) {
- std::vector<unsigned char> data;
- UnitTestUtil::readWireData(datafile, data);
-
- InputBuffer buffer(&data[0], data.size());
- m.fromWire(buffer);
+createQuery(Message& m, const Name& qname, const RRClass& qclass,
+ const RRType& qtype)
+{
+ m.setOpcode(Opcode::QUERY());
+ m.setHeaderFlag(MessageFlag::RD());
+ m.addQuestion(Question(qname, qclass, qtype));
}
QueryTaskPtr
@@ -58,15 +51,18 @@
// Check the QueryTask created using a temporary RRType object will remain
// valid.
-TEST_F(QueryTest, constructWithTemporary) {
- Message m1(Message::PARSE);
- readQuery(m1, "q_wild_a");
+TEST(QueryTest, constructWithTemporary) {
+ HotCache cache;
+
+ Message m1(Message::RENDER);
+ createQuery(m1, Name("www.wild.example.com"), RRClass::IN(), RRType::A());
QueryTaskPtr task_a = createTask(m1, Name("www.wild.example.com"),
RRType::A(), cache);
EXPECT_EQ(RRType::A(), task_a->qtype);
- Message m2(Message::PARSE);
- readQuery(m2, "q_wild_aaaa");
+ Message m2(Message::RENDER);
+ createQuery(m2, Name("www.wild.example.com"), RRClass::IN(),
+ RRType::AAAA());
QueryTaskPtr task_aaaa = createTask(m2, Name("www.wild.example.com"),
RRType::AAAA(), cache);
EXPECT_EQ(RRType::AAAA(), task_aaaa->qtype);
More information about the bind10-changes
mailing list