10 TEST_F(LibraryTest, ParseSoaReplyOK) {
12 pkt.set_qid(0x1234).set_response().set_aa()
13 .add_question(new DNSQuestion("example.com", T_SOA))
14 .add_answer(new DNSSoaRR("example.com", 100,
15 "soa1.example.com", "fred.example.com",
17 std::vector<byte> data = pkt.data();
19 struct ares_soa_reply* soa = nullptr;
20 EXPECT_EQ(ARES_SUCCESS, ares_parse_soa_reply(data.data(), data.size(), &soa));
21 ASSERT_NE(nullptr, soa);
22 EXPECT_EQ("soa1.example.com", std::string(soa->nsname));
23 EXPECT_EQ("fred.example.com", std::string(soa->hostmaster));
24 EXPECT_EQ(1, soa->serial);
25 EXPECT_EQ(2, soa->refresh);
26 EXPECT_EQ(3, soa->retry);
27 EXPECT_EQ(4, soa->expire);
28 EXPECT_EQ(5, soa->minttl);
32 TEST_F(LibraryTest, ParseSoaReplyErrors) {
34 pkt.set_qid(0x1234).set_response().set_aa()
35 .add_question(new DNSQuestion("example.com", T_SOA))
36 .add_answer(new DNSSoaRR("example.com", 100,
37 "soa1.example.com", "fred.example.com",
39 std::vector<byte> data;
40 struct ares_soa_reply* soa = nullptr;
43 pkt.questions_.clear();
45 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa));
46 pkt.add_question(new DNSQuestion("example.com", T_SOA));
50 pkt.questions_.clear();
51 pkt.add_question(new DNSQuestion("Axample.com", T_SOA));
53 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa));
54 pkt.questions_.clear();
55 pkt.add_question(new DNSQuestion("example.com", T_SOA));
59 pkt.add_question(new DNSQuestion("example.com", T_SOA));
61 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa));
62 pkt.questions_.clear();
63 pkt.add_question(new DNSQuestion("example.com", T_SOA));
65 // Wrong sort of answer.
67 pkt.add_answer(new DNSMxRR("example.com", 100, 100, "mx1.example.com"));
69 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa));
71 pkt.add_answer(new DNSSoaRR("example.com", 100,
72 "soa1.example.com", "fred.example.com",
78 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), data.size(), &soa));
79 pkt.add_answer(new DNSSoaRR("example.com", 100,
80 "soa1.example.com", "fred.example.com",
85 for (size_t len = 1; len < data.size(); len++) {
86 EXPECT_EQ(ARES_EBADRESP, ares_parse_soa_reply(data.data(), len, &soa));
90 TEST_F(LibraryTest, ParseSoaReplyAllocFail) {
92 pkt.set_qid(0x1234).set_response().set_aa()
93 .add_question(new DNSQuestion("example.com", T_SOA))
94 .add_answer(new DNSSoaRR("example.com", 100,
95 "soa1.example.com", "fred.example.com",
97 std::vector<byte> data = pkt.data();
98 struct ares_soa_reply* soa = nullptr;
100 for (int ii = 1; ii <= 5; ii++) {
103 EXPECT_EQ(ARES_ENOMEM, ares_parse_soa_reply(data.data(), data.size(), &soa)) << ii;