Commit 3ccbc934 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

introduced a string version of rrsetsCheck() and used it in query_unittest.

parent 36b738c0
......@@ -205,9 +205,6 @@ protected:
Message response;
const qid_t qid;
const uint16_t query_code;
stringstream expected_answer;
stringstream expected_authority;
stringstream expected_additional;
};
TEST_F(QueryTest, noZone) {
......@@ -226,18 +223,15 @@ TEST_F(QueryTest, exactMatch) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 1, 3, 3);
expected_answer << www_a_txt;
rrsetsCheck(expected_answer,
rrsetsCheck(www_a_txt,
response.beginSection(Message::SECTION_ANSWER),
response.endSection(Message::SECTION_ANSWER));
expected_authority << zone_ns_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(zone_ns_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY));
expected_additional << ns_addrs_txt;
rrsetsCheck(expected_additional,
rrsetsCheck(ns_addrs_txt,
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -251,20 +245,16 @@ TEST_F(QueryTest, exactAddrMatch) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 1, 3, 2);
expected_answer << "noglue.example.com. 3600 IN A 192.0.2.53\n";
rrsetsCheck(expected_answer,
rrsetsCheck("noglue.example.com. 3600 IN A 192.0.2.53\n",
response.beginSection(Message::SECTION_ANSWER),
response.endSection(Message::SECTION_ANSWER));
expected_authority << zone_ns_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(zone_ns_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY));
expected_additional <<
"glue.delegation.example.com. 3600 IN A 192.0.2.153\n"
"glue.delegation.example.com. 3600 IN AAAA 2001:db8::53\n";
rrsetsCheck(expected_additional,
rrsetsCheck("glue.delegation.example.com. 3600 IN A 192.0.2.153\n"
"glue.delegation.example.com. 3600 IN AAAA 2001:db8::53\n",
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -278,13 +268,11 @@ TEST_F(QueryTest, apexNSMatch) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 3, 0, 3);
expected_answer << zone_ns_txt;
rrsetsCheck(expected_answer,
rrsetsCheck(zone_ns_txt,
response.beginSection(Message::SECTION_ANSWER),
response.endSection(Message::SECTION_ANSWER));
expected_additional << ns_addrs_txt;
rrsetsCheck(expected_additional,
rrsetsCheck(ns_addrs_txt,
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -298,20 +286,16 @@ TEST_F(QueryTest, exactAnyMatch) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 1, 3, 2);
expected_answer << "noglue.example.com. 3600 IN A 192.0.2.53\n";
rrsetsCheck(expected_answer,
rrsetsCheck("noglue.example.com. 3600 IN A 192.0.2.53\n",
response.beginSection(Message::SECTION_ANSWER),
response.endSection(Message::SECTION_ANSWER));
expected_authority << zone_ns_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(zone_ns_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY));
expected_additional <<
"glue.delegation.example.com. 3600 IN A 192.0.2.153\n"
"glue.delegation.example.com. 3600 IN AAAA 2001:db8::53\n";
rrsetsCheck(expected_additional,
rrsetsCheck("glue.delegation.example.com. 3600 IN A 192.0.2.153\n"
"glue.delegation.example.com. 3600 IN AAAA 2001:db8::53\n",
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -335,13 +319,11 @@ TEST_F(QueryTest, delegation) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
0, 0, 0, 4, 3);
expected_authority << delegation_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(delegation_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY));
expected_additional << ns_addrs_txt;
rrsetsCheck(expected_additional,
rrsetsCheck(ns_addrs_txt,
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -351,8 +333,7 @@ TEST_F(QueryTest, nxdomain) {
response).process());
headerCheck(response, qid, Rcode::NXDOMAIN(), query_code,
AA_FLAG, 0, 0, 1, 0);
expected_authority << soa_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(soa_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY),
Name("example.com"));
......@@ -364,8 +345,7 @@ TEST_F(QueryTest, nxrrset) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 0, 1, 0);
expected_authority << soa_txt;
rrsetsCheck(expected_authority,
rrsetsCheck(soa_txt,
response.beginSection(Message::SECTION_AUTHORITY),
response.endSection(Message::SECTION_AUTHORITY),
Name("example.com"));
......@@ -409,14 +389,11 @@ TEST_F(QueryTest, MX) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 3, 3, 4);
expected_answer << mx_txt;
rrsetsCheck(expected_answer,
rrsetsCheck(mx_txt,
response.beginSection(Message::SECTION_ANSWER),
response.endSection(Message::SECTION_ANSWER));
expected_additional << ns_addrs_txt;
expected_additional << www_a_txt;
rrsetsCheck(expected_additional,
rrsetsCheck(string(ns_addrs_txt) + string(www_a_txt),
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......@@ -435,8 +412,7 @@ TEST_F(QueryTest, MXAlias) {
headerCheck(response, qid, Rcode::NOERROR(), query_code,
AA_FLAG, 0, 1, 3, 3);
expected_additional << ns_addrs_txt;
rrsetsCheck(expected_additional,
rrsetsCheck(ns_addrs_txt,
response.beginSection(Message::SECTION_ADDITIONAL),
response.endSection(Message::SECTION_ADDITIONAL));
}
......
......@@ -211,6 +211,38 @@ rrsetsCheck(std::istream& expected_stream,
detail::RRsetInserter(expected));
rrsetsCheck(expected.begin(), expected.end(), actual_begin, actual_end);
}
/// Set of unit tests to check if two sets of RRsets are identical using
/// expected data as string.
///
/// This function is a wrapper for the input stream version:
/// \c rrsetsCheck(std::istream&, ACTUAL_ITERATOR, ACTUAL_ITERATOR, const isc::dns::Name&, const isc::dns::RRClass&)(),
/// and takes a string object instead of a stream.
/// While the stream version is more generic, this version would be more
/// convenient for tests using hardcoded expected data. Using this version,
/// the example test case shown for the stream version would look as follows:
/// \code
/// rrsetsCheck("foo.example.com. 3600 IN A 192.0.2.1\n"
/// "foo.example.com. 3600 IN A 192.0.2.2\n"
/// "foo.example.com. 7200 IN AAAA 2001:db8::1\n",
/// message.beginSection(Message::SECTION_ADDITIONAL),
/// message.endSection(Message::SECTION_ADDITIONAL));
/// \endcode
///
/// The semantics of parameters is the same as that of the stream version
/// except that \c expected is a string of expected sets of RRsets.
template<typename ACTUAL_ITERATOR>
void
rrsetsCheck(const std::string& expected,
ACTUAL_ITERATOR actual_begin, ACTUAL_ITERATOR actual_end,
const isc::dns::Name& origin = isc::dns::Name::ROOT_NAME(),
const isc::dns::RRClass& rrclass = isc::dns::RRClass::IN())
{
std::stringstream expected_stream(expected);
rrsetsCheck(expected_stream, actual_begin, actual_end, origin,
rrclass);
}
} // end of namespace testutils
} // end of namespace isc
......
Markdown is supported
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