BIND 10 trac2223, updated. f6616492db24a4831ca25258c4bc234e5bd148bb [2223] revert vector implementation, use a count function

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Oct 11 12:07:01 UTC 2012


The branch, trac2223 has been updated
       via  f6616492db24a4831ca25258c4bc234e5bd148bb (commit)
      from  e4f9ff3f23810d365e13ee2e204f70eac5ffdc8f (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 f6616492db24a4831ca25258c4bc234e5bd148bb
Author: Jelte Jansen <jelte at isc.org>
Date:   Thu Oct 11 14:06:19 2012 +0200

    [2223] revert vector implementation, use a count function

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

Summary of changes:
 src/lib/testutils/dnsmessage_test.h |   63 ++++++++++++-----------------------
 1 file changed, 21 insertions(+), 42 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/testutils/dnsmessage_test.h b/src/lib/testutils/dnsmessage_test.h
index dd1fc7b..ab0f823 100644
--- a/src/lib/testutils/dnsmessage_test.h
+++ b/src/lib/testutils/dnsmessage_test.h
@@ -179,38 +179,27 @@ private:
 }
 
 namespace {
-/// \brief Add the string representation of RRsets to a vector
+/// \brief Specialized counter for both RRsets and signatures
 ///
-/// This is a helper function for checkRRsets, to compare the
-/// contents of two sets of RRsets
+/// \param begin start of iterator (of any RRset type)
+/// \param begin end of iterator (of any RRset type)
 ///
-/// It adds the string representations of the RRsets in the given
-/// iterator to the given vector.
-///
-/// If an RRset has signatures, those are added to the
-/// vector as a separate string
+/// \return the number of RRsets in the given iterator, plus
+/// the number of Signature sets (each RRset with signatures
+/// is counted as 2 'rrsets')
 template<typename ITERATOR_TYPE>
-void
-addRRsetsToStringVector(std::vector<std::string>& strings,
-                        ITERATOR_TYPE begin,
-                        ITERATOR_TYPE end)
-{
+size_t
+countRRsetsAndSigs(ITERATOR_TYPE begin, ITERATOR_TYPE end) {
+    size_t count = 0;
     for (ITERATOR_TYPE it = begin; it != end; ++it) {
         if ((*it)->getRRsig()) {
-            // no 'sigless' toText(), but since we need to get both,
-            // it's easier to remove the sigs after toText than to
-            // reimplement toText here
-            std::string rrset_string = (*it)->toText();
-            std::string rrsig_string = (*it)->getRRsig()->toText();
-            strings.push_back(
-                rrset_string.substr(0, rrset_string.find(rrsig_string)));
-            strings.push_back(rrsig_string);
-        } else {
-            strings.push_back((*it)->toText());
+            ++count;
         }
+        ++count;
     }
+    return count;
 }
-}
+} // end anonymous namespace
 
 /// \brief A converter from a string to RRset.
 ///
@@ -307,24 +296,14 @@ rrsetsCheck(EXPECTED_ITERATOR expected_begin, EXPECTED_ITERATOR expected_end,
 
         // make sure rrsets only contains expected RRsets
         //
-        // In order to compare two lists of RRsets, we first convert
-        // them to vectors of strings, sort those vectors, and compare
-        // the result.
-        //
-        // Since some of the RRsets may have their signatures in-line,
-        // and some vectors has them as separate RRsets, we perform one
-        // additional step; If an RRset has signatures, those signatures
-        // are stripped from the original toText() result, and added
-        // as a separate RRset in the string vector.
-        std::vector<std::string> expected_strings;
-        addRRsetsToStringVector(expected_strings, expected_begin, expected_end);
-        std::sort(expected_strings.begin(), expected_strings.end());
-
-        std::vector<std::string> actual_strings;
-        addRRsetsToStringVector(actual_strings, actual_begin, actual_end);
-        std::sort(actual_strings.begin(), actual_strings.end());
-
-        EXPECT_EQ(expected_strings, actual_strings);
+        // 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));
     }
 }
 



More information about the bind10-changes mailing list