 Chromium Code Reviews
 Chromium Code Reviews Issue 7276014:
  DnsQuery: changed raw function pointer to callback.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 7276014:
  DnsQuery: changed raw function pointer to callback.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 "base/bind.h" | |
| 5 #include "base/rand_util.h" | 6 #include "base/rand_util.h" | 
| 6 #include "net/base/dns_response.h" | 7 #include "net/base/dns_response.h" | 
| 
willchan no longer on Chromium
2011/06/28 09:58:23
This header should go first.
 
agayev
2011/06/28 14:37:24
Done.
 | |
| 7 #include "net/base/dns_util.h" | 8 #include "net/base/dns_util.h" | 
| 8 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" | 
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" | 
| 10 | 11 | 
| 11 namespace net { | 12 namespace net { | 
| 12 | 13 | 
| 13 // DNS response consists of a header followed by a question followed by | 14 // DNS response consists of a header followed by a question followed by | 
| 14 // answer. Header format, question format and response format are | 15 // answer. Header format, question format and response format are | 
| 15 // described below. For the meaning of specific fields, please see RFC | 16 // described below. For the meaning of specific fields, please see RFC | 
| 16 // 1035. | 17 // 1035. | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 64 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 
| 64 // | RDLENGTH | | 65 // | RDLENGTH | | 
| 65 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| | 66 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| | 
| 66 // / RDATA / | 67 // / RDATA / | 
| 67 // / / | 68 // / / | 
| 68 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 69 // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | 
| 69 | 70 | 
| 70 // TODO(agayev): add more thorough tests. | 71 // TODO(agayev): add more thorough tests. | 
| 71 TEST(DnsResponseTest, ResponseWithCnameA) { | 72 TEST(DnsResponseTest, ResponseWithCnameA) { | 
| 72 const std::string kHostnameDns("\012codereview\010chromium\003org", 25); | 73 const std::string kHostnameDns("\012codereview\010chromium\003org", 25); | 
| 74 base::RandIntCallback rand_int_cb = base::Bind(&base::RandInt); | |
| 73 | 75 | 
| 74 DnsQuery q1(kHostnameDns, kDNS_A, base::RandUint64); | 76 DnsQuery q1(kHostnameDns, kDNS_A, rand_int_cb); | 
| 75 uint8 id_hi = q1.id() >> 8, id_lo = q1.id() & 0xff; | 77 uint8 id_hi = q1.id() >> 8, id_lo = q1.id() & 0xff; | 
| 76 | 78 | 
| 77 uint8 ip[] = { // codereview.chromium.org resolves to | 79 uint8 ip[] = { // codereview.chromium.org resolves to | 
| 78 0x4a, 0x7d, 0x5f, 0x79 // 74.125.95.121 | 80 0x4a, 0x7d, 0x5f, 0x79 // 74.125.95.121 | 
| 79 }; | 81 }; | 
| 80 | 82 | 
| 81 std::vector<IPAddressNumber> expected_ips; | 83 std::vector<IPAddressNumber> expected_ips; | 
| 82 expected_ips.push_back(IPAddressNumber(ip, ip + arraysize(ip))); | 84 expected_ips.push_back(IPAddressNumber(ip, ip + arraysize(ip))); | 
| 83 | 85 | 
| 84 uint8 response_data[] = { | 86 uint8 response_data[] = { | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 r1.io_buffer()->size()); | 132 r1.io_buffer()->size()); | 
| 131 | 133 | 
| 132 // Verify resolved IPs. | 134 // Verify resolved IPs. | 
| 133 int response_size = arraysize(response_data); | 135 int response_size = arraysize(response_data); | 
| 134 std::vector<IPAddressNumber> actual_ips; | 136 std::vector<IPAddressNumber> actual_ips; | 
| 135 EXPECT_EQ(OK, r1.Parse(response_size, &actual_ips)); | 137 EXPECT_EQ(OK, r1.Parse(response_size, &actual_ips)); | 
| 136 EXPECT_EQ(expected_ips, actual_ips); | 138 EXPECT_EQ(expected_ips, actual_ips); | 
| 137 } | 139 } | 
| 138 | 140 | 
| 139 } // namespace net | 141 } // namespace net | 
| OLD | NEW |