| Index: net/dns/dns_response_unittest.cc
|
| diff --git a/net/dns/dns_response_unittest.cc b/net/dns/dns_response_unittest.cc
|
| index 41f3a7296929c94add82acd33486d3be91fe4e1f..afdd9104ca198d769090f14c8d599ebdb15530d8 100644
|
| --- a/net/dns/dns_response_unittest.cc
|
| +++ b/net/dns/dns_response_unittest.cc
|
| @@ -4,9 +4,14 @@
|
|
|
| #include "net/dns/dns_response.h"
|
|
|
| +#include "base/time.h"
|
| +#include "net/base/address_list.h"
|
| #include "net/base/io_buffer.h"
|
| +#include "net/base/net_util.h"
|
| +#include "net/base/sys_addrinfo.h"
|
| #include "net/dns/dns_protocol.h"
|
| #include "net/dns/dns_query.h"
|
| +#include "net/dns/dns_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace net {
|
| @@ -241,6 +246,83 @@ TEST(DnsResponseTest, InitParse) {
|
| EXPECT_FALSE(parser.ParseRecord(&record));
|
| }
|
|
|
| +void VerifyAddressList(const std::vector<const char*>& ip_addresses,
|
| + const AddressList& addrlist) {
|
| + ASSERT_GT(ip_addresses.size(), 0u);
|
| + ASSERT_NE(static_cast<addrinfo*>(NULL), addrlist.head());
|
| +
|
| + IPAddressNumber ip_number;
|
| + const struct addrinfo* ainfo = addrlist.head();
|
| + for (std::vector<const char*>::const_iterator i = ip_addresses.begin();
|
| + i != ip_addresses.end(); ++i, ainfo = ainfo->ai_next) {
|
| + ASSERT_NE(static_cast<addrinfo*>(NULL), ainfo);
|
| + EXPECT_EQ(sizeof(struct sockaddr_in),
|
| + static_cast<size_t>(ainfo->ai_addrlen));
|
| +
|
| + const struct sockaddr* sa = ainfo->ai_addr;
|
| + EXPECT_STREQ(*i, NetAddressToString(sa, ainfo->ai_addrlen).c_str());
|
| + }
|
| + ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo);
|
| +}
|
| +
|
| +TEST(DnsResponseTest, ParseAddressList) {
|
| + const struct TestCase {
|
| + const uint8* query_data;
|
| + size_t query_size;
|
| + const uint8* response_data;
|
| + size_t response_size;
|
| + const char* const* expected_addresses;
|
| + size_t num_expected_addresses;
|
| + const char* expected_cname;
|
| + int expected_ttl_sec;
|
| + } cases[] = {
|
| + {
|
| + kT0QueryDatagram, arraysize(kT0QueryDatagram),
|
| + kT0ResponseDatagram, arraysize(kT0ResponseDatagram),
|
| + kT0IpAddresses, arraysize(kT0IpAddresses),
|
| + kT0CanonName,
|
| + kT0TTL,
|
| + },
|
| + {
|
| + kT1QueryDatagram, arraysize(kT1QueryDatagram),
|
| + kT1ResponseDatagram, arraysize(kT1ResponseDatagram),
|
| + kT1IpAddresses, arraysize(kT1IpAddresses),
|
| + kT1CanonName,
|
| + kT1TTL,
|
| + },
|
| + {
|
| + kT2QueryDatagram, arraysize(kT2QueryDatagram),
|
| + kT2ResponseDatagram, arraysize(kT2ResponseDatagram),
|
| + kT2IpAddresses, arraysize(kT2IpAddresses),
|
| + kT2CanonName,
|
| + kT2TTL,
|
| + },
|
| + {
|
| + kT3QueryDatagram, arraysize(kT3QueryDatagram),
|
| + kT3ResponseDatagram, arraysize(kT3ResponseDatagram),
|
| + kT3IpAddresses, arraysize(kT3IpAddresses),
|
| + kT3CanonName,
|
| + kT3TTL,
|
| + },
|
| + };
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
|
| + const TestCase& t = cases[i];
|
| + DnsResponse response(t.response_data, t.response_size, t.query_size);
|
| + AddressList addr_list;
|
| + base::TimeDelta ttl;
|
| + EXPECT_TRUE(response.ParseAddressList(&addr_list, &ttl));
|
| + std::vector<const char*> expected_addresses(
|
| + t.expected_addresses,
|
| + t.expected_addresses + t.num_expected_addresses);
|
| + VerifyAddressList(expected_addresses, addr_list);
|
| + std::string cname;
|
| + ASSERT_TRUE(addr_list.GetCanonicalName(&cname));
|
| + EXPECT_EQ(t.expected_cname, cname);
|
| + EXPECT_EQ(base::TimeDelta::FromSeconds(t.expected_ttl_sec), ttl);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace net
|
|
|