From: JINMEI Tatuya Date: Thu, 9 Feb 2012 03:33:19 +0000 (-0800) Subject: [1641] test refactoring: use TYPED_TEST to share the same test code for NSEC[3]. X-Git-Tag: trac2351_base~97^2~37^2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a3853394c09ef698795c3b7fe98661e752e0426;p=thirdparty%2Fkea.git [1641] test refactoring: use TYPED_TEST to share the same test code for NSEC[3]. --- diff --git a/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc b/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc index 8a908781ea..7c46f86473 100644 --- a/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc +++ b/src/lib/dns/tests/rdata_nsecbitmap_unittest.cc @@ -22,10 +22,51 @@ #include +#include + +using namespace std; using namespace isc::dns; using namespace isc::dns::rdata; namespace { + +// Template for shared tests for NSEC and NSEC3 bitmaps +template +class NSECBitmapTest : public RdataTest { +protected: + // These depend on the specific RR type. We use specialized methods + // for them. + static RRType getType(); // return either RRType::NSEC() or NSEC3() + static string getWireFilePrefix(); +}; + +typedef ::testing::Types TestRdataTypes; +TYPED_TEST_CASE(NSECBitmapTest, TestRdataTypes); + +template <> +string +NSECBitmapTest::getWireFilePrefix() { + return ("rdata_nsec_"); +} + +template <> +RRType +NSECBitmapTest::getType() { + return (RRType::NSEC()); +} + +template <> +string +NSECBitmapTest::getWireFilePrefix() { + return ("rdata_nsec3_"); +} + +template <> +RRType +NSECBitmapTest::getType() { + return (RRType::NSEC3()); +} + class Rdata_NSECBITMAP_Test : public RdataTest { // there's nothing to specialize }; @@ -34,70 +75,55 @@ class Rdata_NSECBITMAP_Test : public RdataTest { // The syntax and semantics are common for both RR types, and our // implementation of that part is shared, so in theory it should be sufficient // to test for only one RR type. But we check for both just in case. -TEST_F(Rdata_NSECBITMAP_Test, createFromWire_NSEC) { +TYPED_TEST(NSECBitmapTest, createFromWire) { // A malformed NSEC bitmap length field that could cause overflow. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire4.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire4.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire4.wire").c_str()), DNSMessageFORMERR); // The bitmap field is incomplete (only the first byte is included) - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire5.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire5.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire5.wire").c_str()), DNSMessageFORMERR); // Bitmap length is 0, which is invalid. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire6.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire6.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire6.wire").c_str()), DNSMessageFORMERR); // Too large bitmap length with a short buffer. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire3"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire3"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire3").c_str()), DNSMessageFORMERR); // A boundary case: longest possible bitmaps (32 maps). This should be // accepted. - EXPECT_NO_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire7.wire")); - EXPECT_NO_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire7.wire")); + EXPECT_NO_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire7.wire").c_str())); // Another boundary condition: 33 bitmaps, which should be rejected. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire8.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire8.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire8.wire").c_str()), DNSMessageFORMERR); // Disordered bitmap window blocks. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire9.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire9.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire9.wire").c_str()), DNSMessageFORMERR); // Bitmap ending with all-zero bytes. Not necessarily harmful except // the additional overhead of parsing, but invalid according to the // spec anyway. - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC(), RRClass::IN(), - "rdata_nsec_fromWire10.wire"), - DNSMessageFORMERR); - EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), - "rdata_nsec3_fromWire10.wire"), + EXPECT_THROW(this->rdataFactoryFromFile(this->getType(), RRClass::IN(), + (this->getWireFilePrefix() + + "fromWire10.wire").c_str()), DNSMessageFORMERR); } }