"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/ares-test-parse-txt.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-txt.cc  (c-ares-1.17.1):ares-test-parse-txt.cc  (c-ares-1.17.2)
skipping to change at line 16 skipping to change at line 16
namespace ares { namespace ares {
namespace test { namespace test {
TEST_F(LibraryTest, ParseTxtReplyOK) { TEST_F(LibraryTest, ParseTxtReplyOK) {
DNSPacket pkt; DNSPacket pkt;
std::string expected1 = "txt1.example.com"; std::string expected1 = "txt1.example.com";
std::string expected2a = "txt2a"; std::string expected2a = "txt2a";
std::string expected2b("ABC\0ABC", 7); std::string expected2b("ABC\0ABC", 7);
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) .add_answer(new DNSTxtRR("example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); .add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_txt_reply* txt = nullptr; struct ares_txt_reply* txt = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_txt_reply(data.data(), data.size(), &txt)); EXPECT_EQ(ARES_SUCCESS, ares_parse_txt_reply(data.data(), data.size(), &txt));
ASSERT_NE(nullptr, txt); ASSERT_NE(nullptr, txt);
EXPECT_EQ(std::vector<byte>(expected1.data(), expected1.data() + expected1.siz e()), EXPECT_EQ(std::vector<byte>(expected1.data(), expected1.data() + expected1.siz e()),
std::vector<byte>(txt->txt, txt->txt + txt->length)); std::vector<byte>(txt->txt, txt->txt + txt->length));
skipping to change at line 47 skipping to change at line 47
ares_free_data(txt); ares_free_data(txt);
} }
TEST_F(LibraryTest, ParseTxtExtReplyOK) { TEST_F(LibraryTest, ParseTxtExtReplyOK) {
DNSPacket pkt; DNSPacket pkt;
std::string expected1 = "txt1.example.com"; std::string expected1 = "txt1.example.com";
std::string expected2a = "txt2a"; std::string expected2a = "txt2a";
std::string expected2b("ABC\0ABC", 7); std::string expected2b("ABC\0ABC", 7);
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) .add_answer(new DNSTxtRR("example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); .add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_txt_ext* txt = nullptr; struct ares_txt_ext* txt = nullptr;
EXPECT_EQ(ARES_SUCCESS, ares_parse_txt_reply_ext(data.data(), data.size(), &tx t)); EXPECT_EQ(ARES_SUCCESS, ares_parse_txt_reply_ext(data.data(), data.size(), &tx t));
ASSERT_NE(nullptr, txt); ASSERT_NE(nullptr, txt);
EXPECT_EQ(std::vector<byte>(expected1.data(), expected1.data() + expected1.siz e()), EXPECT_EQ(std::vector<byte>(expected1.data(), expected1.data() + expected1.siz e()),
std::vector<byte>(txt->txt, txt->txt + txt->length)); std::vector<byte>(txt->txt, txt->txt + txt->length));
EXPECT_EQ(1, txt->record_start); EXPECT_EQ(1, txt->record_start);
skipping to change at line 193 skipping to change at line 193
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ;
ASSERT_EQ(nullptr, txt); ASSERT_EQ(nullptr, txt);
} }
TEST_F(LibraryTest, ParseTxtReplyErrors) { TEST_F(LibraryTest, ParseTxtReplyErrors) {
DNSPacket pkt; DNSPacket pkt;
std::string expected1 = "txt1.example.com"; std::string expected1 = "txt1.example.com";
std::string expected2a = "txt2a"; std::string expected2a = "txt2a";
std::string expected2b = "txt2b"; std::string expected2b = "txt2b";
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) .add_answer(new DNSTxtRR("example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("example.com", 100, {expected1})) .add_answer(new DNSTxtRR("example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b})); .add_answer(new DNSTxtRR("example.com", 100, {expected2a, expected2b}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_txt_reply* txt = nullptr; struct ares_txt_reply* txt = nullptr;
// No question. // No question.
pkt.questions_.clear(); pkt.questions_.clear();
data = pkt.data(); data = pkt.data();
txt = nullptr; txt = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ;
EXPECT_EQ(nullptr, txt); EXPECT_EQ(nullptr, txt);
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
#ifdef DISABLED #ifdef DISABLED
// Question != answer // Question != answer
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("Axample.com", ns_t_txt)); pkt.add_question(new DNSQuestion("Axample.com", T_TXT));
data = pkt.data(); data = pkt.data();
EXPECT_EQ(ARES_ENODATA, ares_parse_txt_reply(data.data(), data.size(), &txt)); EXPECT_EQ(ARES_ENODATA, ares_parse_txt_reply(data.data(), data.size(), &txt));
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_txt)); pkt.add_question(new DNSQuestion("example.com", T_TXT));
#endif #endif
// Two questions. // Two questions.
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
data = pkt.data(); data = pkt.data();
txt = nullptr; txt = nullptr;
EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ; EXPECT_EQ(ARES_EBADRESP, ares_parse_txt_reply(data.data(), data.size(), &txt)) ;
EXPECT_EQ(nullptr, txt); EXPECT_EQ(nullptr, txt);
pkt.questions_.clear(); pkt.questions_.clear();
pkt.add_question(new DNSQuestion("example.com", ns_t_mx)); pkt.add_question(new DNSQuestion("example.com", T_MX));
// No answer. // No answer.
pkt.answers_.clear(); pkt.answers_.clear();
data = pkt.data(); data = pkt.data();
txt = nullptr; txt = nullptr;
EXPECT_EQ(ARES_ENODATA, ares_parse_txt_reply(data.data(), data.size(), &txt)); EXPECT_EQ(ARES_ENODATA, ares_parse_txt_reply(data.data(), data.size(), &txt));
EXPECT_EQ(nullptr, txt); EXPECT_EQ(nullptr, txt);
pkt.add_answer(new DNSTxtRR("example.com", 100, {expected1})); pkt.add_answer(new DNSTxtRR("example.com", 100, {expected1}));
// Truncated packets. // Truncated packets.
skipping to change at line 249 skipping to change at line 249
EXPECT_EQ(nullptr, txt); EXPECT_EQ(nullptr, txt);
} }
} }
TEST_F(LibraryTest, ParseTxtReplyAllocFail) { TEST_F(LibraryTest, ParseTxtReplyAllocFail) {
DNSPacket pkt; DNSPacket pkt;
std::string expected1 = "txt1.example.com"; std::string expected1 = "txt1.example.com";
std::string expected2a = "txt2a"; std::string expected2a = "txt2a";
std::string expected2b = "txt2b"; std::string expected2b = "txt2b";
pkt.set_qid(0x1234).set_response().set_aa() pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_mx)) .add_question(new DNSQuestion("example.com", T_MX))
.add_answer(new DNSCnameRR("example.com", 300, "c.example.com")) .add_answer(new DNSCnameRR("example.com", 300, "c.example.com"))
.add_answer(new DNSTxtRR("c.example.com", 100, {expected1})) .add_answer(new DNSTxtRR("c.example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("c.example.com", 100, {expected1})) .add_answer(new DNSTxtRR("c.example.com", 100, {expected1}))
.add_answer(new DNSTxtRR("c.example.com", 100, {expected2a, expected2b})); .add_answer(new DNSTxtRR("c.example.com", 100, {expected2a, expected2b}));
std::vector<byte> data = pkt.data(); std::vector<byte> data = pkt.data();
struct ares_txt_reply* txt = nullptr; struct ares_txt_reply* txt = nullptr;
for (int ii = 1; ii <= 13; ii++) { for (int ii = 1; ii <= 13; ii++) {
ClearFails(); ClearFails();
SetAllocFail(ii); SetAllocFail(ii);
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

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