| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/dns_response.h" |
| 6 |
| 7 #include "base/bind.h" |
| 5 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 6 #include "net/base/dns_response.h" | |
| 7 #include "net/base/dns_util.h" | 9 #include "net/base/dns_util.h" |
| 8 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace net { | 13 namespace net { |
| 12 | 14 |
| 13 // DNS response consists of a header followed by a question followed by | 15 // DNS response consists of a header followed by a question followed by |
| 14 // answer. Header format, question format and response format are | 16 // answer. Header format, question format and response format are |
| 15 // described below. For the meaning of specific fields, please see RFC | 17 // described below. For the meaning of specific fields, please see RFC |
| 16 // 1035. | 18 // 1035. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 65 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 64 // | RDLENGTH | | 66 // | RDLENGTH | |
| 65 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| | 67 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| |
| 66 // / RDATA / | 68 // / RDATA / |
| 67 // / / | 69 // / / |
| 68 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 70 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 69 | 71 |
| 70 // TODO(agayev): add more thorough tests. | 72 // TODO(agayev): add more thorough tests. |
| 71 TEST(DnsResponseTest, ResponseWithCnameA) { | 73 TEST(DnsResponseTest, ResponseWithCnameA) { |
| 72 const std::string kHostnameDns("\012codereview\010chromium\003org", 25); | 74 const std::string kHostnameDns("\012codereview\010chromium\003org", 25); |
| 75 RandIntCallback rand_int_cb = base::Bind(&base::RandInt); |
| 73 | 76 |
| 74 DnsQuery q1(kHostnameDns, kDNS_A, base::RandUint64); | 77 DnsQuery q1(kHostnameDns, kDNS_A, rand_int_cb); |
| 75 uint8 id_hi = q1.id() >> 8, id_lo = q1.id() & 0xff; | 78 uint8 id_hi = q1.id() >> 8, id_lo = q1.id() & 0xff; |
| 76 | 79 |
| 77 uint8 ip[] = { // codereview.chromium.org resolves to | 80 uint8 ip[] = { // codereview.chromium.org resolves to |
| 78 0x4a, 0x7d, 0x5f, 0x79 // 74.125.95.121 | 81 0x4a, 0x7d, 0x5f, 0x79 // 74.125.95.121 |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 std::vector<IPAddressNumber> expected_ips; | 84 std::vector<IPAddressNumber> expected_ips; |
| 82 expected_ips.push_back(IPAddressNumber(ip, ip + arraysize(ip))); | 85 expected_ips.push_back(IPAddressNumber(ip, ip + arraysize(ip))); |
| 83 | 86 |
| 84 uint8 response_data[] = { | 87 uint8 response_data[] = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 r1.io_buffer()->size()); | 133 r1.io_buffer()->size()); |
| 131 | 134 |
| 132 // Verify resolved IPs. | 135 // Verify resolved IPs. |
| 133 int response_size = arraysize(response_data); | 136 int response_size = arraysize(response_data); |
| 134 std::vector<IPAddressNumber> actual_ips; | 137 std::vector<IPAddressNumber> actual_ips; |
| 135 EXPECT_EQ(OK, r1.Parse(response_size, &actual_ips)); | 138 EXPECT_EQ(OK, r1.Parse(response_size, &actual_ips)); |
| 136 EXPECT_EQ(expected_ips, actual_ips); | 139 EXPECT_EQ(expected_ips, actual_ips); |
| 137 } | 140 } |
| 138 | 141 |
| 139 } // namespace net | 142 } // namespace net |
| OLD | NEW |