]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2522] more and better SSHFP unit tests
authorPaul Selkirk <pselkirk@isc.org>
Fri, 17 May 2013 18:05:22 +0000 (14:05 -0400)
committerPaul Selkirk <pselkirk@isc.org>
Fri, 17 May 2013 18:05:22 +0000 (14:05 -0400)
src/lib/dns/rdata/generic/sshfp_44.cc
src/lib/dns/tests/rdata_sshfp_unittest.cc

index 2843f10d0b836a7488ad3a3d2a0d090410687587..e398e3f6696cc3b4351c847a8d54f3ffbc6fa80d 100644 (file)
@@ -221,9 +221,6 @@ int
 SSHFP::compare(const Rdata& other) const {
     const SSHFP& other_sshfp = dynamic_cast<const SSHFP&>(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_) {
index 0b32dedb1c6e0dc691feab5534ee5a1559c42d6b..cb1630cc26259b72e48bf87557fab11c22c0ed66 100644 (file)
@@ -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
 
 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<generic::SSHFP, isc::Exception, isc::Exception>(
+            rdata_str, rdata_sshfp, false, false);
+    }
+
+    void checkFromText_LexerError(const string& rdata_str) {
+        checkFromText
+            <generic::SSHFP, InvalidRdataText, MasterLexer::LexerError>(
+                rdata_str, rdata_sshfp, true, true);
+    }
+
+    void checkFromText_BadValue(const string& rdata_str) {
+        checkFromText<generic::SSHFP, InvalidRdataText, BadValue>(
+            rdata_str, rdata_sshfp, true, true);
+    }
+
+    void checkFromText_BadString(const string& rdata_str) {
+        checkFromText
+            <generic::SSHFP, InvalidRdataText, isc::Exception>(
+                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()));