"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-aaaa.cc" between
c-ares-1.17.1.tar.gz and c-ares-1.17.2.tar.gz

About: c-ares is a C library for asynchronous DNS requests (including name resolves).

ares-test-parse-aaaa.cc  (c-ares-1.17.1):ares-test-parse-aaaa.cc  (c-ares-1.17.2)
skipping to change at line 13 skipping to change at line 13
#include <sstream> #include <sstream>
#include <vector> #include <vector>
namespace ares { namespace ares {
namespace test { namespace test {
TEST_F(LibraryTest, ParseAaaaReplyOK) { TEST_F(LibraryTest, ParseAaaaReplyOK) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSAaaaRR("example.com", 100, .add_answer(new DNSAaaaRR("example.com", 100,
{0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, {0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04}))
.add_answer(new DNSARR("example.com", 0x01020304, {2,3,4,5})); .add_answer(new DNSARR("example.com", 0x01020304, {2,3,4,5}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addr6ttl info[5]; struct ares_addr6ttl info[5];
int count = 5; int count = 5;
EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
skipping to change at line 43 skipping to change at line 43
// Repeat without providing places to put the results // Repeat without providing places to put the results
count = 0; count = 0;
EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(),
nullptr, info, &count)); nullptr, info, &count));
} }
TEST_F(LibraryTest, ParseAaaaReplyCname) { TEST_F(LibraryTest, ParseAaaaReplyCname) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSCnameRR("example.com", 50, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 50, "c.example.com"))
.add_answer(new DNSAaaaRR("c.example.com", 100, .add_answer(new DNSAaaaRR("c.example.com", 100,
{0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, {0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ; 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addr6ttl info[5]; struct ares_addr6ttl info[5];
int count = 5; int count = 5;
EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_SUCCESS, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
skipping to change at line 78 skipping to change at line 78
nullptr, info, &count)); nullptr, info, &count));
EXPECT_EQ(1, count); EXPECT_EQ(1, count);
EXPECT_EQ(50, info[0].ttl); EXPECT_EQ(50, info[0].ttl);
EXPECT_EQ(0x01, info[0].ip6addr._S6_un._S6_u8[0]); EXPECT_EQ(0x01, info[0].ip6addr._S6_un._S6_u8[0]);
EXPECT_EQ(0x02, info[0].ip6addr._S6_un._S6_u8[4]); EXPECT_EQ(0x02, info[0].ip6addr._S6_un._S6_u8[4]);
} }
TEST_F(LibraryTest, ParseAaaaReplyNoData) { TEST_F(LibraryTest, ParseAaaaReplyNoData) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)); .add_question(new DNSQuestion("example.com", T_AAAA));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addr6ttl info[2]; struct ares_addr6ttl info[2];
int count = 2; int count = 2;
EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(0, count); EXPECT_EQ(0, count);
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
// Again but with a CNAME. // Again but with a CNAME.
pkt.add_answer(new DNSCnameRR("example.com", 200, "c.example.com")); pkt.add_answer(new DNSCnameRR("example.com", 200, "c.example.com"));
EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(0, count); EXPECT_EQ(0, count);
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
} }
TEST_F(LibraryTest, ParseAaaaReplyErrors) { TEST_F(LibraryTest, ParseAaaaReplyErrors) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSAaaaRR("example.com", 100, .add_answer(new DNSAaaaRR("example.com", 100,
{0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, {0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ; 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ;
std::vector<byte> data; std::vector<byte> data;
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addr6ttl info[2]; struct ares_addr6ttl info[2];
int count = 2; int count = 2;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.add_question(new DNSQuestion("example.com", ns_t_aaaa)); pkt.add_question(new DNSQuestion("example.com", T_AAAA));
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_aaaa)); pkt.add_question(new DNSQuestion("Axample.com", T_AAAA));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_aaaa)); pkt.add_question(new DNSQuestion("example.com", T_AAAA));
// Two questions. // Two questions.
pkt.add_question(new DNSQuestion("example.com", ns_t_aaaa)); pkt.add_question(new DNSQuestion("example.com", T_AAAA));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_aaaa)); pkt.add_question(new DNSQuestion("example.com", T_AAAA));
// Wrong sort of answer. // Wrong sort of answer.
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com")); pkt.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com"));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(), EXPECT_EQ(ARES_ENODATA, ares_parse_aaaa_reply(data.data(), data.size(),
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
pkt.answers_.clear(); pkt.answers_.clear();
pkt.add_answer(new DNSAaaaRR("example.com", 100, pkt.add_answer(new DNSAaaaRR("example.com", 100,
skipping to change at line 172 skipping to change at line 172
&host, info, &count)); &host, info, &count));
EXPECT_EQ(nullptr, host); EXPECT_EQ(nullptr, host);
EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), len, EXPECT_EQ(ARES_EBADRESP, ares_parse_aaaa_reply(data.data(), len,
nullptr, info, &count)); nullptr, info, &count));
} }
} }
TEST_F(LibraryTest, ParseAaaaReplyAllocFail) { TEST_F(LibraryTest, ParseAaaaReplyAllocFail) {
DNSPacket pkt; DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa)) .add_question(new DNSQuestion("example.com", T_AAAA))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSAaaaRR("c.example.com", 100, .add_answer(new DNSAaaaRR("c.example.com", 100,
{0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, {0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ; 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04})) ;
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct hostent *host = nullptr; struct hostent *host = nullptr;
struct ares_addr6ttl info[2]; struct ares_addr6ttl info[2];
int count = 2; int count = 2;
for (int ii = 1; ii <= 8; ii++) { for (int ii = 1; ii <= 8; ii++) {
 End of changes. 10 change blocks. 
10 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)