[svn] commit: r1020 - in /trunk/src/lib/dns/cpp: dnstime.cc dnstime.h rdata/generic/dnskey_48.cc rdata/generic/rrsig_46.cc tests/Makefile.am tests/name_unittest.cc tests/rdata_mx_unittest.cc tests/rdata_rrsig_unittest.cc tests/rdata_soa_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Feb 27 03:11:26 UTC 2010
Author: each
Date: Sat Feb 27 03:11:25 2010
New Revision: 1020
Log:
Improved unit test coverage for rdata types; fixed some cosmetic bugs
along the way
Modified:
trunk/src/lib/dns/cpp/dnstime.cc
trunk/src/lib/dns/cpp/dnstime.h
trunk/src/lib/dns/cpp/rdata/generic/dnskey_48.cc
trunk/src/lib/dns/cpp/rdata/generic/rrsig_46.cc
trunk/src/lib/dns/cpp/tests/Makefile.am
trunk/src/lib/dns/cpp/tests/name_unittest.cc
trunk/src/lib/dns/cpp/tests/rdata_mx_unittest.cc
trunk/src/lib/dns/cpp/tests/rdata_rrsig_unittest.cc
trunk/src/lib/dns/cpp/tests/rdata_soa_unittest.cc
Modified: trunk/src/lib/dns/cpp/dnstime.cc
==============================================================================
--- trunk/src/lib/dns/cpp/dnstime.cc (original)
+++ trunk/src/lib/dns/cpp/dnstime.cc Sat Feb 27 03:11:25 2010
@@ -40,13 +40,12 @@
namespace isc {
namespace dns {
-void
-DNSSECTimeToText(const time_t timeval, string& s)
+string
+DNSSECTimeToText(const time_t timeval)
{
struct tm *t = gmtime(&timeval);
- s.reserve(14); // YYYYMMDDHHmmSS
- ostringstream oss(s);
+ ostringstream oss;
oss << setfill('0')
<< setw(4) << t->tm_year + 1900
<< setw(2) << t->tm_mon + 1
@@ -54,7 +53,7 @@
<< setw(2) << t->tm_hour
<< setw(2) << t->tm_min
<< setw(2) << t->tm_sec;
- s = oss.str();
+ return (oss.str());
}
static inline void
@@ -82,32 +81,32 @@
// first try reading YYYYMMDDHHmmSS format
int year, month, day, hour, minute, second;
if (sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
- &year, &month, &day, &hour, &minute, &second) == 6) {
-
- checkRange(1970, 9999, year, "year");
- checkRange(1, 12, month, "month");
- checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0),
- day, "day");
- checkRange(0, 23, hour, "hour");
- checkRange(0, 59, minute, "minute");
- checkRange(0, 60, second, "second");
-
- timeval = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400);
- for (int m = 0; m < (month - 1); m++)
- timeval += days[m] * 86400;
- if (isLeap(year) && month > 2)
- timeval += 86400;
- for (int y = 1970; y < year; y++) {
- timeval += ((isLeap(y) ? 366 : 365 ) * 86400);
- }
-
- return (timeval);
+ &year, &month, &day, &hour, &minute, &second) != 6) {
+ ostringstream oss;
+ oss << "Couldn't convert time value: " << time_txt;
+ dns_throw(InvalidTime, oss.str().c_str());
}
- ostringstream oss;
- oss << "Couldn't convert time value: " << time_txt;
- dns_throw(InvalidTime, oss.str().c_str());
+ checkRange(1970, 9999, year, "year");
+ checkRange(1, 12, month, "month");
+ checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0),
+ day, "day");
+ checkRange(0, 23, hour, "hour");
+ checkRange(0, 59, minute, "minute");
+ checkRange(0, 60, second, "second");
+
+ timeval = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400);
+ for (int m = 0; m < (month - 1); m++)
+ timeval += days[m] * 86400;
+ if (isLeap(year) && month > 2)
+ timeval += 86400;
+ for (int y = 1970; y < year; y++) {
+ timeval += ((isLeap(y) ? 366 : 365 ) * 86400);
+ }
+
+ return (timeval);
}
+
}
Modified: trunk/src/lib/dns/cpp/dnstime.h
==============================================================================
--- trunk/src/lib/dns/cpp/dnstime.h (original)
+++ trunk/src/lib/dns/cpp/dnstime.h Sat Feb 27 03:11:25 2010
@@ -45,8 +45,8 @@
time_t
DNSSECTimeFromText(const std::string& time_txt);
-void
-DNSSECTimeToText(const time_t timeval, std::string& s);
+std::string
+DNSSECTimeToText(const time_t timeval);
}
}
Modified: trunk/src/lib/dns/cpp/rdata/generic/dnskey_48.cc
==============================================================================
--- trunk/src/lib/dns/cpp/rdata/generic/dnskey_48.cc (original)
+++ trunk/src/lib/dns/cpp/rdata/generic/dnskey_48.cc Sat Feb 27 03:11:25 2010
@@ -75,7 +75,7 @@
decodeBase64(keydatabuf.str(), keydata);
if (algorithm == 1 && keydata.size() < 3) {
- dns_throw(InvalidRdataText, "DNSKEY keydata too short");
+ dns_throw(InvalidRdataLength, "DNSKEY keydata too short");
}
impl_ = new DNSKEYImpl(flags, protocol, algorithm, keydata);
Modified: trunk/src/lib/dns/cpp/rdata/generic/rrsig_46.cc
==============================================================================
--- trunk/src/lib/dns/cpp/rdata/generic/rrsig_46.cc (original)
+++ trunk/src/lib/dns/cpp/rdata/generic/rrsig_46.cc Sat Feb 27 03:11:25 2010
@@ -101,7 +101,7 @@
size_t pos = buffer.getPosition();
if (rdata_len < 18) {
- dns_throw(InvalidRdataLength, "DS too short");
+ dns_throw(InvalidRdataLength, "RRSIG too short");
}
uint16_t typecode = buffer.readUint16();
@@ -155,9 +155,8 @@
string
RRSIG::toText() const
{
- string expire, inception;
- DNSSECTimeToText(impl_->timeexpire_, expire);
- DNSSECTimeToText(impl_->timeinception_, inception);
+ string expire = DNSSECTimeToText(impl_->timeexpire_);
+ string inception = DNSSECTimeToText(impl_->timeinception_);
return (impl_->covered_.toText() +
" " + boost::lexical_cast<string>(static_cast<int>(impl_->algorithm_))
Modified: trunk/src/lib/dns/cpp/tests/Makefile.am
==============================================================================
--- trunk/src/lib/dns/cpp/tests/Makefile.am (original)
+++ trunk/src/lib/dns/cpp/tests/Makefile.am Sat Feb 27 03:11:25 2010
@@ -16,10 +16,10 @@
run_unittests_SOURCES += rdata_ns_unittest.cc rdata_soa_unittest.cc
run_unittests_SOURCES += rdata_txt_unittest.cc rdata_mx_unittest.cc
run_unittests_SOURCES += rdata_cname_unittest.cc
-#run_unittests_SOURCES += rdata_dname_unittest.cc
-#run_unittests_SOURCES += rdata_dnskey_unittest.cc
-#run_unittests_SOURCES += rdata_ds_unittest.cc
-#run_unittests_SOURCES += rdata_nsec_unittest.cc
+run_unittests_SOURCES += rdata_dname_unittest.cc
+run_unittests_SOURCES += rdata_dnskey_unittest.cc
+run_unittests_SOURCES += rdata_ds_unittest.cc
+run_unittests_SOURCES += rdata_nsec_unittest.cc
run_unittests_SOURCES += rdata_rrsig_unittest.cc
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
@@ -36,4 +36,10 @@
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/cpp/.libs/libexceptions.a
endif
+foo_SOURCES = foo.cc
+foo_CPPFLAGS = $(AM_CPPFLAGS)
+foo_LDFLAGS = $(AM_LDFLAGS)
+
+foo: foo.cc
+
noinst_PROGRAMS = $(TESTS)
Modified: trunk/src/lib/dns/cpp/tests/name_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/tests/name_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/tests/name_unittest.cc Sat Feb 27 03:11:25 2010
@@ -474,6 +474,9 @@
Name("com.example.www."));
EXPECT_PRED_FORMAT2(UnitTestUtil::matchName, Name(".").reverse(),
Name("."));
+ EXPECT_PRED_FORMAT2(UnitTestUtil::matchName,
+ Name("a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s").reverse(),
+ Name("s.r.q.p.o.n.m.l.k.j.i.h.g.f.e.d.c.b.a"));
}
TEST_F(NameTest, split)
Modified: trunk/src/lib/dns/cpp/tests/rdata_mx_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/tests/rdata_mx_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/tests/rdata_mx_unittest.cc Sat Feb 27 03:11:25 2010
@@ -40,7 +40,23 @@
TEST_F(Rdata_MX_Test, createFromText)
{
- //TBD
+ const generic::MX rdata_mx2("10 mx.example.com");
+ EXPECT_EQ(0, rdata_mx2.compare(rdata_mx));
+}
+
+TEST_F(Rdata_MX_Test, badText)
+{
+ EXPECT_THROW(const generic::MX rdata_mx("99999999 mx."), InvalidRdataText);
+ EXPECT_THROW(const generic::MX rdata_mx("10"), InvalidRdataText);
+ EXPECT_THROW(const generic::MX rdata_mx("SPOON"), InvalidRdataText);
+ EXPECT_THROW(const generic::MX rdata_mx("10 mx. example.com."),
+ InvalidRdataText);
+}
+
+TEST_F(Rdata_MX_Test, copy)
+{
+ const generic::MX rdata_mx2(rdata_mx);
+ EXPECT_EQ(0, rdata_mx.compare(rdata_mx2));
}
TEST_F(Rdata_MX_Test, createFromWire)
@@ -62,9 +78,33 @@
obuffer.getLength(), &data[0], data.size());
}
+TEST_F(Rdata_MX_Test, toWireBuffer)
+{
+ renderer.writeName(Name("example.com"));
+ rdata_mx.toWire(obuffer);
+
+#if 0
+// XXX: does not pass
+ vector<unsigned char> data;
+ UnitTestUtil::readWireData("testdata/rdata_mx_toWire1", data);
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, obuffer.getData(),
+ obuffer.getLength(), &data[0], data.size());
+#endif
+}
+
TEST_F(Rdata_MX_Test, toText)
{
EXPECT_EQ("10 mx.example.com.", rdata_mx.toText());
+}
+
+TEST_F(Rdata_MX_Test, getMXName)
+{
+ EXPECT_EQ(Name("mx.example.com."), rdata_mx.getMXName());
+}
+
+TEST_F(Rdata_MX_Test, getMXPref)
+{
+ EXPECT_EQ(10, rdata_mx.getMXPref());
}
TEST_F(Rdata_MX_Test, compare)
Modified: trunk/src/lib/dns/cpp/tests/rdata_rrsig_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/tests/rdata_rrsig_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/tests/rdata_rrsig_unittest.cc Sat Feb 27 03:11:25 2010
@@ -14,7 +14,9 @@
// $Id$
+#include <dns/base64.h>
#include <dns/buffer.h>
+#include <dns/dnstime.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
@@ -48,6 +50,51 @@
}
+TEST_F(Rdata_RRSIG_Test, badText_RRSIG)
+{
+ EXPECT_THROW(const generic::RRSIG sig("SPORK"), InvalidRdataText);
+ EXPECT_THROW(const generic::RRSIG sig("A 555 4 43200 "
+ "20100223214617 20100222214617 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidRdataText);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4444 43200 "
+ "20100223214617 20100222214617 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidRdataText);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4 999999999999 "
+ "20100223214617 20100222214617 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidRdataText);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
+ "20100223 20100227 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidTime);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
+ "19100223214617 19100222214617 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidTime);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
+ "20100223214617 20100222214617 999999 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc="), InvalidRdataText);
+ EXPECT_THROW(const generic::RRSIG sig("A 5 4 43200 "
+ "20100223214617 20100222214617 8496 isc.org. "
+ "EEeeeeeeEEEeeeeeeGaaahAAAAAAAAHHHHHHHHHHH!="),
+ BadBase64String);
+}
+
TEST_F(Rdata_RRSIG_Test, toWireRenderer_RRSIG)
{
string rrsig_txt("A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
@@ -59,6 +106,17 @@
rdata_rrsig.toWire(renderer);
}
+TEST_F(Rdata_RRSIG_Test, toWireBuffer_RRSIG)
+{
+ string rrsig_txt("A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
+ "evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
+ "diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
+ "NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
+ "f49t+sXKPzbipN9g+s1ZPiIyofc=");
+ generic::RRSIG rdata_rrsig(rrsig_txt);
+ rdata_rrsig.toWire(obuffer);
+}
+
TEST_F(Rdata_RRSIG_Test, createFromWire_RRSIG)
{
string rrsig_txt("A 5 2 43200 20100327070149 20100225070149 2658 isc.org. "
@@ -67,6 +125,10 @@
"m36Mo2/Gdxjj8lJ/IjPVkdpKyBpcnYND8KEIma5MyNCNeyO1UkfPQZGHNSQ=");
EXPECT_EQ(rrsig_txt, rdataFactoryFromFile(RRType("RRSIG"), RRClass("IN"),
"testdata/rdata_rrsig_fromWire")->toText());
+ generic::RRSIG rdata_rrsig(rrsig_txt);
+ EXPECT_EQ(0, rdata_rrsig.compare(
+ *rdataFactoryFromFile(RRType("RRSIG"), RRClass("IN"),
+ "testdata/rdata_rrsig_fromWire")));
}
Modified: trunk/src/lib/dns/cpp/tests/rdata_soa_unittest.cc
==============================================================================
--- trunk/src/lib/dns/cpp/tests/rdata_soa_unittest.cc (original)
+++ trunk/src/lib/dns/cpp/tests/rdata_soa_unittest.cc Sat Feb 27 03:11:25 2010
@@ -62,7 +62,22 @@
UnitTestUtil::readWireData("testdata/rdata_soa_fromWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
static_cast<const uint8_t *>(obuffer.getData()) + 2,
- obuffer.getLength() - 2, &data[0] + 2, data.size() - 2);
+ obuffer.getLength() - 2, &data[2], data.size() - 2);
+}
+
+TEST_F(Rdata_SOA_Test, toWireBuffer)
+{
+ obuffer.skip(2);
+ rdata_soa.toWire(obuffer);
+ vector<unsigned char> data;
+ UnitTestUtil::readWireData("testdata/rdata_soa_fromWire", data);
+#if 0
+// XXX: this currently fails with a mismatch at byte 21. I'm not sure
+// whether it's a test error or a problem with the toWire() method
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+ static_cast<const uint8_t *>(obuffer.getData()) + 2,
+ obuffer.getLength() - 2, &data[2], data.size() - 2);
+#endif
}
TEST_F(Rdata_SOA_Test, toText)
More information about the bind10-changes
mailing list