BIND 10 trac2223, updated. efded5c3713a67a6eaa0284a322195b2f5075a27 [2223] completely pull out sigs and check entire set

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Oct 15 12:57:22 UTC 2012


The branch, trac2223 has been updated
       via  efded5c3713a67a6eaa0284a322195b2f5075a27 (commit)
      from  a6c74caf3dc0aef52b89c78ebbcd02fcc5e47609 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit efded5c3713a67a6eaa0284a322195b2f5075a27
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Oct 15 14:57:05 2012 +0200

    [2223] completely pull out sigs and check entire set

-----------------------------------------------------------------------

Summary of changes:
 src/lib/testutils/dnsmessage_test.h |  130 ++++++++++++++++-------------------
 1 file changed, 59 insertions(+), 71 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/testutils/dnsmessage_test.h b/src/lib/testutils/dnsmessage_test.h
index bdf2223..1d83b82 100644
--- a/src/lib/testutils/dnsmessage_test.h
+++ b/src/lib/testutils/dnsmessage_test.h
@@ -160,47 +160,7 @@ public:
 private:
     std::vector<isc::dns::ConstRRsetPtr>& rrsets_;
 };
-
-class RRsetDumper {
-public:
-    RRsetDumper(std::string& output) :
-        output_(output)
-    {}
-    void operator()(isc::dns::ConstRRsetPtr rrset) {
-        output_ += "  " + rrset->toText();
-
-        if (rrset->getRRsig()) {
-            output_ += "  " + rrset->getRRsig()->toText();
-        }
-    }
-private:
-    std::string& output_;
-};
-}
-
-namespace {
-/// \brief Specialized counter for both RRsets and signatures
-///
-/// \param begin start of iterator (of any RRset type)
-/// \param begin end of iterator (of any RRset type)
-///
-/// \return the number of RRsets in the given iterator, plus
-/// the number of signature RRsets (each RRset with signatures
-/// is counted as 2 'rrsets', as if the signatures over an RRset
-/// are a separate RRset in the original iterator)
-template<typename ITERATOR_TYPE>
-size_t
-countRRsetsAndSigs(ITERATOR_TYPE begin, ITERATOR_TYPE end) {
-    size_t count = 0;
-    for (ITERATOR_TYPE it = begin; it != end; ++it) {
-        if ((*it)->getRRsig()) {
-            ++count;
-        }
-        ++count;
-    }
-    return count;
 }
-} // end anonymous namespace
 
 /// \brief A converter from a string to RRset.
 ///
@@ -225,6 +185,36 @@ isc::dns::RRsetPtr textToRRset(const std::string& text_rrset,
                                const isc::dns::Name& origin =
                                isc::dns::Name::ROOT_NAME());
 
+/// \brief Pull out signatures and convert to text
+///
+/// This is a helper function for rrsetsCheck.
+///
+/// It adds all the rrsets to the given vector. It also adds the
+/// signatures of those rrsets as separate rrsets into the vector
+/// (but does not modify the original rrset; i.e. technically the
+/// signatures are in the resulting vector twice).
+///
+/// Additionally, it adds the string representation of all rrsets
+/// and their signatures to the given string (for use in scoped_trace).
+///
+/// \param rrsets A vector to add the rrsets and signatures to
+/// \param text A string to add the rrsets string representations to
+/// \param begin The beginning of the rrsets iterator
+/// \param end The end of the rrsets iterator
+template <typename ITERATOR>
+void
+pullSigs(std::vector<isc::dns::ConstRRsetPtr>& rrsets,
+         std::string& text, ITERATOR begin, ITERATOR end) {
+    for (ITERATOR it = begin; it != end; ++it) {
+        rrsets.push_back(*it);
+        text += (*it)->toText();
+        if ((*it)->getRRsig()) {
+            rrsets.push_back((*it)->getRRsig());
+            text += (*it)->getRRsig()->toText();
+        }
+    }
+}
+
 /// Set of unit tests to check if two sets of RRsets are identical.
 ///
 /// This templated function takes two sets of sequences, each defined by
@@ -260,14 +250,31 @@ void
 rrsetsCheck(EXPECTED_ITERATOR expected_begin, EXPECTED_ITERATOR expected_end,
             ACTUAL_ITERATOR actual_begin, ACTUAL_ITERATOR actual_end)
 {
-    std::vector<isc::dns::ConstRRsetPtr> checked_rrsets; // for duplicate check
+    // Iterators can have their RRsig sets as separate RRsets,
+    // or they can have them attached to the RRset they cover.
+    // For ease of use of this method, we first flatten out both
+    // iterators, and pull out the signature sets, and add them as
+    // separate RRsets (checkRRset() later does not check signatures
+    // attached to rrsets)
+    std::vector<isc::dns::ConstRRsetPtr> actual_rrsets, expected_rrsets;
     std::string expected_text, actual_text;
-    std::for_each(expected_begin, expected_end,
-                  detail::RRsetDumper(expected_text));
-    std::for_each(actual_begin, actual_end, detail::RRsetDumper(actual_text));
-    unsigned int rrset_matched = 0;
-    ACTUAL_ITERATOR it;
-    for (it = actual_begin; it != actual_end; ++it) {
+
+    pullSigs(expected_rrsets, expected_text, expected_begin, expected_end);
+    pullSigs(actual_rrsets, actual_text, actual_begin, actual_end);
+
+    SCOPED_TRACE(std::string("Comparing two RRset lists:\n") +
+                 "Actual:\n" + actual_text +
+                 "Expected:\n" + expected_text);
+
+    // The vectors should have the same number of sets
+    ASSERT_EQ(expected_rrsets.size(), actual_rrsets.size());
+
+    // Now we check if all RRsets from the actual_rrsets are in
+    // expected_rrsets, and that actual_rrsets has no duplicates.
+    std::vector<isc::dns::ConstRRsetPtr> checked_rrsets; // for duplicate check
+
+    std::vector<isc::dns::ConstRRsetPtr>::const_iterator it;
+    for (it = actual_rrsets.begin(); it != actual_rrsets.end(); ++it) {
         // Make sure there's no duplicate RRset in actual (using a naive
         // search).  Since the actual set is guaranteed to be unique, we can
         // detect it if the expected data has a duplicate by the match/size
@@ -278,34 +285,15 @@ rrsetsCheck(EXPECTED_ITERATOR expected_begin, EXPECTED_ITERATOR expected_end,
                                  detail::RRsetMatch(*it)));
         checked_rrsets.push_back(*it);
 
-        EXPECTED_ITERATOR found_rrset_it =
-            std::find_if(expected_begin, expected_end,
+        std::vector<isc::dns::ConstRRsetPtr>::const_iterator found_rrset_it =
+            std::find_if(expected_rrsets.begin(), expected_rrsets.end(),
                          detail::RRsetMatch(*it));
-        if (found_rrset_it != expected_end) {
+        if (found_rrset_it != expected_rrsets.end()) {
             rrsetCheck(*found_rrset_it, *it);
-            ++rrset_matched;
-            rrset_matched += (*it)->getRRsigDataCount();
+        } else {
+            FAIL() << (*it)->toText() << " not found in expected rrsets";
         }
     }
-
-    {
-        SCOPED_TRACE(std::string("Comparing two RRsets:\n") +
-                     "Actual:\n" + actual_text +
-                     "Expected:\n" + expected_text);
-        // make sure all expected RRsets are in actual sets
-        EXPECT_EQ(std::distance(expected_begin, expected_end), rrset_matched);
-
-        // make sure rrsets only contains expected RRsets
-        //
-        // Any rrset in actual has been found in expected by the code above,
-        // so to determine whether there are no other rrsets present, we
-        // simply need to compare their sizes. However, signatures can be
-        // in-lined (as part of an RRset), or added as separate RRsets.
-        // So we count the number of rrsets + the number of rrsets that
-        // have signatures.
-        EXPECT_EQ(countRRsetsAndSigs(expected_begin, expected_end),
-                  countRRsetsAndSigs(actual_begin, actual_end));
-    }
 }
 
 /// Set of unit tests to check if two sets of RRsets are identical using



More information about the bind10-changes mailing list