| 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/dns/dns_query.h" | 5 #include "net/dns/dns_query.h" |
| 6 | 6 |
| 7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 #include "net/dns/dns_protocol.h" | 8 #include "net/dns/dns_protocol.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 TEST(DnsQueryTest, Constructor) { | 15 TEST(DnsQueryTest, Constructor) { |
| 16 // This includes \0 at the end. | 16 // This includes \0 at the end. |
| 17 const char qname_data[] = "\x03""www""\x07""example""\x03""com"; | 17 const char qname_data[] = "\x03""www""\x07""example""\x03""com"; |
| 18 const uint8 query_data[] = { | 18 const uint8_t query_data[] = { |
| 19 // Header | 19 // Header |
| 20 0xbe, 0xef, | 20 0xbe, 0xef, 0x01, 0x00, // Flags -- set RD (recursion desired) bit. |
| 21 0x01, 0x00, // Flags -- set RD (recursion desired) bit. | 21 0x00, 0x01, // Set QDCOUNT (question count) to 1, all the |
| 22 0x00, 0x01, // Set QDCOUNT (question count) to 1, all the | 22 // rest are 0 for a query. |
| 23 // rest are 0 for a query. | 23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 24 0x00, 0x00, | |
| 25 0x00, 0x00, | |
| 26 0x00, 0x00, | |
| 27 | 24 |
| 28 // Question | 25 // Question |
| 29 0x03, 'w', 'w', 'w', // QNAME: www.example.com in DNS format. | 26 0x03, 'w', 'w', 'w', // QNAME: www.example.com in DNS format. |
| 30 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e', | 27 0x07, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0x03, 'c', 'o', 'm', 0x00, |
| 31 0x03, 'c', 'o', 'm', | |
| 32 0x00, | |
| 33 | 28 |
| 34 0x00, 0x01, // QTYPE: A query. | 29 0x00, 0x01, // QTYPE: A query. |
| 35 0x00, 0x01, // QCLASS: IN class. | 30 0x00, 0x01, // QCLASS: IN class. |
| 36 }; | 31 }; |
| 37 | 32 |
| 38 base::StringPiece qname(qname_data, sizeof(qname_data)); | 33 base::StringPiece qname(qname_data, sizeof(qname_data)); |
| 39 DnsQuery q1(0xbeef, qname, dns_protocol::kTypeA); | 34 DnsQuery q1(0xbeef, qname, dns_protocol::kTypeA); |
| 40 EXPECT_EQ(dns_protocol::kTypeA, q1.qtype()); | 35 EXPECT_EQ(dns_protocol::kTypeA, q1.qtype()); |
| 41 | 36 |
| 42 ASSERT_EQ(static_cast<int>(sizeof(query_data)), q1.io_buffer()->size()); | 37 ASSERT_EQ(static_cast<int>(sizeof(query_data)), q1.io_buffer()->size()); |
| 43 EXPECT_EQ(0, memcmp(q1.io_buffer()->data(), query_data, sizeof(query_data))); | 38 EXPECT_EQ(0, memcmp(q1.io_buffer()->data(), query_data, sizeof(query_data))); |
| 44 EXPECT_EQ(qname, q1.qname()); | 39 EXPECT_EQ(qname, q1.qname()); |
| 45 | 40 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 scoped_ptr<DnsQuery> q2 = q1.CloneWithNewId(42); | 53 scoped_ptr<DnsQuery> q2 = q1.CloneWithNewId(42); |
| 59 EXPECT_EQ(42, q2->id()); | 54 EXPECT_EQ(42, q2->id()); |
| 60 EXPECT_EQ(q1.io_buffer()->size(), q2->io_buffer()->size()); | 55 EXPECT_EQ(q1.io_buffer()->size(), q2->io_buffer()->size()); |
| 61 EXPECT_EQ(q1.qtype(), q2->qtype()); | 56 EXPECT_EQ(q1.qtype(), q2->qtype()); |
| 62 EXPECT_EQ(q1.question(), q2->question()); | 57 EXPECT_EQ(q1.question(), q2->question()); |
| 63 } | 58 } |
| 64 | 59 |
| 65 } // namespace | 60 } // namespace |
| 66 | 61 |
| 67 } // namespace net | 62 } // namespace net |
| OLD | NEW |