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.
///
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
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
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