Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: net/dns/record_rdata_unittest.cc

Issue 14697022: Cache for mDNS records (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@record_parsed_klassbit
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/record_rdata.cc ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "net/base/net_util.h"
7 #include "net/dns/dns_response.h"
6 #include "net/dns/record_rdata.h" 8 #include "net/dns/record_rdata.h"
7 #include "net/dns/dns_response.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace net { 11 namespace net {
11 12
12 TEST(RecordRdataTest, ParseSrvRecord) { 13 TEST(RecordRdataTest, ParseSrvRecord) {
13 scoped_ptr<SrvRecordRdata> record1_obj; 14 scoped_ptr<SrvRecordRdata> record1_obj;
14 scoped_ptr<SrvRecordRdata> record2_obj; 15 scoped_ptr<SrvRecordRdata> record2_obj;
15 16
16 // These are just the rdata portions of the DNS records, rather than complete 17 // These are just the rdata portions of the DNS records, rather than complete
17 // records, but it works well enough for this test. 18 // records, but it works well enough for this test.
(...skipping 27 matching lines...) Expand all
45 46
46 ASSERT_EQ("www.google.com", record1_obj->target()); 47 ASSERT_EQ("www.google.com", record1_obj->target());
47 48
48 record2_obj = SrvRecordRdata::Create(record2_strpiece, parser); 49 record2_obj = SrvRecordRdata::Create(record2_strpiece, parser);
49 ASSERT_TRUE(record2_obj != NULL); 50 ASSERT_TRUE(record2_obj != NULL);
50 ASSERT_EQ(257, record2_obj->priority()); 51 ASSERT_EQ(257, record2_obj->priority());
51 ASSERT_EQ(258, record2_obj->weight()); 52 ASSERT_EQ(258, record2_obj->weight());
52 ASSERT_EQ(259, record2_obj->port()); 53 ASSERT_EQ(259, record2_obj->port());
53 54
54 ASSERT_EQ("www2.google.com", record2_obj->target()); 55 ASSERT_EQ("www2.google.com", record2_obj->target());
56
57 ASSERT_TRUE(record1_obj->IsEqual(record1_obj.get()));
58 ASSERT_FALSE(record1_obj->IsEqual(record2_obj.get()));
55 } 59 }
56 60
57 TEST(RecordRdataTest, ParseARecord) { 61 TEST(RecordRdataTest, ParseARecord) {
58 scoped_ptr<ARecordRdata> record_obj; 62 scoped_ptr<ARecordRdata> record_obj;
59 63
60 // These are just the rdata portions of the DNS records, rather than complete 64 // These are just the rdata portions of the DNS records, rather than complete
61 // records, but it works well enough for this test. 65 // records, but it works well enough for this test.
62 66
63 const char record[] = { 67 const char record[] = {
64 0x7F, 0x00, 0x00, 0x01 // 127.0.0.1 68 0x7F, 0x00, 0x00, 0x01 // 127.0.0.1
65 }; 69 };
66 70
67 DnsRecordParser parser(record, sizeof(record), 0); 71 DnsRecordParser parser(record, sizeof(record), 0);
68 base::StringPiece record_strpiece(record, sizeof(record)); 72 base::StringPiece record_strpiece(record, sizeof(record));
69 73
70 record_obj = ARecordRdata::Create(record_strpiece, parser); 74 record_obj = ARecordRdata::Create(record_strpiece, parser);
71 ASSERT_TRUE(record_obj != NULL); 75 ASSERT_TRUE(record_obj != NULL);
72 76
73 ASSERT_EQ("127.0.0.1", IPAddressToString(record_obj->address())); 77 ASSERT_EQ("127.0.0.1", IPAddressToString(record_obj->address()));
78
79 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
80 }
81
82 TEST(RecordRdataTest, ParseAAAARecord) {
83 scoped_ptr<AAAARecordRdata> record_obj;
84
85 // These are just the rdata portions of the DNS records, rather than complete
86 // records, but it works well enough for this test.
87
88 const char record[] = {
89 0x12, 0x34, 0x56, 0x78,
90 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x09 // 1234:5678::9A
93 };
94
95 DnsRecordParser parser(record, sizeof(record), 0);
96 base::StringPiece record_strpiece(record, sizeof(record));
97
98 record_obj = AAAARecordRdata::Create(record_strpiece, parser);
99 ASSERT_TRUE(record_obj != NULL);
100
101 ASSERT_EQ("1234:5678::9",
102 IPAddressToString(record_obj->address()));
103
104 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
74 } 105 }
75 106
76 TEST(RecordRdataTest, ParseCnameRecord) { 107 TEST(RecordRdataTest, ParseCnameRecord) {
77 scoped_ptr<CnameRecordRdata> record_obj; 108 scoped_ptr<CnameRecordRdata> record_obj;
78 109
79 // These are just the rdata portions of the DNS records, rather than complete 110 // These are just the rdata portions of the DNS records, rather than complete
80 // records, but it works well enough for this test. 111 // records, but it works well enough for this test.
81 112
82 const char record[] = { 113 const char record[] = {
83 0x03, 'w', 'w', 'w', 114 0x03, 'w', 'w', 'w',
84 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 115 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
85 0x03, 'c', 'o', 'm', 116 0x03, 'c', 'o', 'm',
86 0x00 117 0x00
87 }; 118 };
88 119
89 DnsRecordParser parser(record, sizeof(record), 0); 120 DnsRecordParser parser(record, sizeof(record), 0);
90 base::StringPiece record_strpiece(record, sizeof(record)); 121 base::StringPiece record_strpiece(record, sizeof(record));
91 122
92 record_obj = CnameRecordRdata::Create(record_strpiece, parser); 123 record_obj = CnameRecordRdata::Create(record_strpiece, parser);
93 ASSERT_TRUE(record_obj != NULL); 124 ASSERT_TRUE(record_obj != NULL);
94 125
95 ASSERT_EQ("www.google.com", record_obj->cname()); 126 ASSERT_EQ("www.google.com", record_obj->cname());
127
128 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
96 } 129 }
97 130
98 TEST(RecordRdataTest, ParsePtrRecord) { 131 TEST(RecordRdataTest, ParsePtrRecord) {
99 scoped_ptr<PtrRecordRdata> record_obj; 132 scoped_ptr<PtrRecordRdata> record_obj;
100 133
101 // These are just the rdata portions of the DNS records, rather than complete 134 // These are just the rdata portions of the DNS records, rather than complete
102 // records, but it works well enough for this test. 135 // records, but it works well enough for this test.
103 136
104 const char record[] = { 137 const char record[] = {
105 0x03, 'w', 'w', 'w', 138 0x03, 'w', 'w', 'w',
106 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 139 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
107 0x03, 'c', 'o', 'm', 140 0x03, 'c', 'o', 'm',
108 0x00 141 0x00
109 }; 142 };
110 143
111 DnsRecordParser parser(record, sizeof(record), 0); 144 DnsRecordParser parser(record, sizeof(record), 0);
112 base::StringPiece record_strpiece(record, sizeof(record)); 145 base::StringPiece record_strpiece(record, sizeof(record));
113 146
114 record_obj = PtrRecordRdata::Create(record_strpiece, parser); 147 record_obj = PtrRecordRdata::Create(record_strpiece, parser);
115 ASSERT_TRUE(record_obj != NULL); 148 ASSERT_TRUE(record_obj != NULL);
116 149
117 ASSERT_EQ("www.google.com", record_obj->ptrdomain()); 150 ASSERT_EQ("www.google.com", record_obj->ptrdomain());
151
152 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
118 } 153 }
119 154
120 TEST(RecordRdataTest, ParseTxtRecord) { 155 TEST(RecordRdataTest, ParseTxtRecord) {
121 scoped_ptr<TxtRecordRdata> record_obj; 156 scoped_ptr<TxtRecordRdata> record_obj;
122 157
123 // These are just the rdata portions of the DNS records, rather than complete 158 // These are just the rdata portions of the DNS records, rather than complete
124 // records, but it works well enough for this test. 159 // records, but it works well enough for this test.
125 160
126 const char record[] = { 161 const char record[] = {
127 0x03, 'w', 'w', 'w', 162 0x03, 'w', 'w', 'w',
128 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 163 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
129 0x03, 'c', 'o', 'm' 164 0x03, 'c', 'o', 'm'
130 }; 165 };
131 166
132 DnsRecordParser parser(record, sizeof(record), 0); 167 DnsRecordParser parser(record, sizeof(record), 0);
133 base::StringPiece record_strpiece(record, sizeof(record)); 168 base::StringPiece record_strpiece(record, sizeof(record));
134 169
135 record_obj = TxtRecordRdata::Create(record_strpiece, parser); 170 record_obj = TxtRecordRdata::Create(record_strpiece, parser);
136 ASSERT_TRUE(record_obj != NULL); 171 ASSERT_TRUE(record_obj != NULL);
137 172
138 std::vector<std::string> expected; 173 std::vector<std::string> expected;
139 expected.push_back("www"); 174 expected.push_back("www");
140 expected.push_back("google"); 175 expected.push_back("google");
141 expected.push_back("com"); 176 expected.push_back("com");
142 177
143 ASSERT_EQ(expected, record_obj->texts()); 178 ASSERT_EQ(expected, record_obj->texts());
179
180 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
144 } 181 }
145 182
146 } // namespace net 183 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/record_rdata.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698