From: Paul Selkirk Date: Fri, 17 May 2013 18:05:22 +0000 (-0400) Subject: [2522] more and better SSHFP unit tests X-Git-Tag: bind10-1.2.0beta1-release~430^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=592db047a5a82c5af9e837dc2fc9a9df102af8ed;p=thirdparty%2Fkea.git [2522] more and better SSHFP unit tests --- diff --git a/src/lib/dns/rdata/generic/sshfp_44.cc b/src/lib/dns/rdata/generic/sshfp_44.cc index 2843f10d0b..e398e3f669 100644 --- a/src/lib/dns/rdata/generic/sshfp_44.cc +++ b/src/lib/dns/rdata/generic/sshfp_44.cc @@ -221,9 +221,6 @@ int SSHFP::compare(const Rdata& other) const { const SSHFP& other_sshfp = dynamic_cast(other); - /* This doesn't really make any sort of sense, but in the name of - consistency... */ - if (impl_->algorithm_ < other_sshfp.impl_->algorithm_) { return (-1); } else if (impl_->algorithm_ > other_sshfp.impl_->algorithm_) { diff --git a/src/lib/dns/tests/rdata_sshfp_unittest.cc b/src/lib/dns/tests/rdata_sshfp_unittest.cc index 0b32dedb1c..cb1630cc26 100644 --- a/src/lib/dns/tests/rdata_sshfp_unittest.cc +++ b/src/lib/dns/tests/rdata_sshfp_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -30,17 +30,45 @@ using isc::UnitTestUtil; using namespace std; +using namespace isc; using namespace isc::dns; using namespace isc::util; using namespace isc::dns::rdata; namespace { class Rdata_SSHFP_Test : public RdataTest { - // there's nothing to specialize +protected: + Rdata_SSHFP_Test() : + sshfp_txt("2 1 123456789abcdef67890123456789abcdef67890"), + rdata_sshfp(sshfp_txt) + {} + + void checkFromText_None(const string& rdata_str) { + checkFromText( + rdata_str, rdata_sshfp, false, false); + } + + void checkFromText_LexerError(const string& rdata_str) { + checkFromText + ( + rdata_str, rdata_sshfp, true, true); + } + + void checkFromText_BadValue(const string& rdata_str) { + checkFromText( + rdata_str, rdata_sshfp, true, true); + } + + void checkFromText_BadString(const string& rdata_str) { + checkFromText + ( + rdata_str, rdata_sshfp, true, false); + } + + const string sshfp_txt; + const generic::SSHFP rdata_sshfp; }; -const string sshfp_txt("2 1 123456789abcdef67890123456789abcdef67890"); -const generic::SSHFP rdata_sshfp(2, 1, "123456789abcdef67890123456789abcdef67890"); const uint8_t rdata_sshfp_wiredata[] = { // algorithm 0x02, @@ -56,22 +84,13 @@ const uint8_t rdata_sshfp_wiredata[] = { TEST_F(Rdata_SSHFP_Test, createFromText) { // Basic test - const generic::SSHFP rdata_sshfp2(sshfp_txt); - EXPECT_EQ(0, rdata_sshfp2.compare(rdata_sshfp)); + checkFromText_None(sshfp_txt); // With different spacing - const generic::SSHFP rdata_sshfp3("2 1 123456789abcdef67890123456789abcdef67890"); - EXPECT_EQ(0, rdata_sshfp3.compare(rdata_sshfp)); + checkFromText_None("2 1 123456789abcdef67890123456789abcdef67890"); // Combination of lowercase and uppercase - const generic::SSHFP rdata_sshfp4("2 1 123456789ABCDEF67890123456789abcdef67890"); - EXPECT_EQ(0, rdata_sshfp4.compare(rdata_sshfp)); -} - -TEST_F(Rdata_SSHFP_Test, createFromLexer) { - EXPECT_EQ(0, rdata_sshfp.compare( - *test::createRdataUsingLexer(RRType::SSHFP(), RRClass::IN(), - sshfp_txt))); + checkFromText_None("2 1 123456789ABCDEF67890123456789abcdef67890"); } TEST_F(Rdata_SSHFP_Test, algorithmTypes) { @@ -101,10 +120,11 @@ TEST_F(Rdata_SSHFP_Test, algorithmTypes) { } TEST_F(Rdata_SSHFP_Test, badText) { - EXPECT_THROW(const generic::SSHFP rdata_sshfp("1"), InvalidRdataText); - EXPECT_THROW(const generic::SSHFP rdata_sshfp("BUCKLE MY SHOES"), InvalidRdataText); - EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo"), InvalidRdataText); - EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 12ab bar"), InvalidRdataText); + checkFromText_LexerError("1"); + checkFromText_LexerError("ONE 2 123456789abcdef67890123456789abcdef67890"); + checkFromText_LexerError("1 TWO 123456789abcdef67890123456789abcdef67890"); + checkFromText_BadValue("1 2 BUCKLEMYSHOES"); + checkFromText_BadString(sshfp_txt + " extra text"); } TEST_F(Rdata_SSHFP_Test, copy) { @@ -161,6 +181,16 @@ TEST_F(Rdata_SSHFP_Test, createFromWire) { InvalidBufferPosition); } +TEST_F(Rdata_SSHFP_Test, createFromComponents) { + const generic::SSHFP rdata_sshfp2(2, 1, "123456789abcdef67890123456789abcdef67890"); + EXPECT_EQ(0, rdata_sshfp2.compare(rdata_sshfp)); +} + +TEST_F(Rdata_SSHFP_Test, createByCopy) { + const generic::SSHFP rdata_sshfp2(rdata_sshfp); + EXPECT_EQ(0, rdata_sshfp2.compare(rdata_sshfp)); +} + TEST_F(Rdata_SSHFP_Test, toText) { EXPECT_TRUE(boost::iequals(sshfp_txt, rdata_sshfp.toText()));