Commit ec3e1e87 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1578] pre-work refactoring2: use testutils::rrsetCheck to compare RRsets.

this makes the test code shorter, and perfomrs more flexible than pointer
comparison.  this is not necessarily crucial for this branch, but will
eventually be necessary when we update the internal representation of in-memory
data.  at that point returned RRset by find() will be different from the one
installed by add() wrt pointer comprison.
parent e475cf69
...@@ -401,6 +401,8 @@ public: ...@@ -401,6 +401,8 @@ public:
* \param check_answer Should a check against equality of the answer be * \param check_answer Should a check against equality of the answer be
* done? * done?
* \param answer The expected rrset, if any should be returned. * \param answer The expected rrset, if any should be returned.
* \param expected_flags The expected result flags returned via find().
* These can be tested using isWildcard() etc.
* \param zone_finder Check different InMemoryZoneFinder object than * \param zone_finder Check different InMemoryZoneFinder object than
* zone_finder_ (if NULL, uses zone_finder_) * zone_finder_ (if NULL, uses zone_finder_)
* \param check_wild_answer Checks that the answer has the same RRs, type * \param check_wild_answer Checks that the answer has the same RRs, type
...@@ -425,8 +427,7 @@ public: ...@@ -425,8 +427,7 @@ public:
// we can't assign to FindResult // we can't assign to FindResult
EXPECT_NO_THROW({ EXPECT_NO_THROW({
ZoneFinder::FindResult find_result(zone_finder->find( ZoneFinder::FindResult find_result(zone_finder->find(
name, rrtype, name, rrtype, options));
options));
// Check it returns correct answers // Check it returns correct answers
EXPECT_EQ(result, find_result.code); EXPECT_EQ(result, find_result.code);
EXPECT_EQ((expected_flags & ZoneFinder::RESULT_WILDCARD) != 0, EXPECT_EQ((expected_flags & ZoneFinder::RESULT_WILDCARD) != 0,
...@@ -436,35 +437,28 @@ public: ...@@ -436,35 +437,28 @@ public:
EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC3_SIGNED) EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC3_SIGNED)
!= 0, find_result.isNSEC3Signed()); != 0, find_result.isNSEC3Signed());
if (check_answer) { if (check_answer) {
EXPECT_EQ(answer, find_result.rrset); if (!answer) {
ASSERT_FALSE(find_result.rrset);
} else {
ASSERT_TRUE(find_result.rrset);
rrsetCheck(answer, find_result.rrset);
}
} else if (check_wild_answer) { } else if (check_wild_answer) {
ASSERT_NE(ConstRRsetPtr(), answer) << ASSERT_NE(ConstRRsetPtr(), answer) <<
"Wrong test, don't check for wild names if you expect " "Wrong test, don't check for wild names if you expect "
"empty answer"; "empty answer";
ASSERT_NE(ConstRRsetPtr(), find_result.rrset) << ASSERT_NE(ConstRRsetPtr(), find_result.rrset) <<
"No answer found"; "No answer found";
// Build the expected answer using the given name and
// other parameter of the base wildcard RRset.
RRsetPtr wildanswer(new RRset(name, answer->getClass(),
answer->getType(),
answer->getTTL()));
RdataIteratorPtr expectedIt(answer->getRdataIterator()); RdataIteratorPtr expectedIt(answer->getRdataIterator());
RdataIteratorPtr actualIt( for (; !expectedIt->isLast(); expectedIt->next()) {
find_result.rrset->getRdataIterator()); wildanswer->addRdata(expectedIt->getCurrent());
while (!expectedIt->isLast() && !actualIt->isLast()) {
EXPECT_EQ(0, expectedIt->getCurrent().compare(
actualIt->getCurrent())) << "The RRs differ ('" <<
expectedIt->getCurrent().toText() << "', '" <<
actualIt->getCurrent().toText() << "')";
expectedIt->next();
actualIt->next();
} }
EXPECT_TRUE(expectedIt->isLast()) << rrsetCheck(wildanswer, find_result.rrset);
"Result has less RRs than expected";
EXPECT_TRUE(actualIt->isLast()) <<
"Result has more RRs than expected";
EXPECT_EQ(answer->getClass(),
find_result.rrset->getClass());
EXPECT_EQ(answer->getType(),
find_result.rrset->getType());
EXPECT_EQ(answer->getTTL(),
find_result.rrset->getTTL());
EXPECT_EQ(name, find_result.rrset->getName());
} }
}); });
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment