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

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

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Delinted. Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/dns_response.cc ('k') | net/dns/dns_session.h » ('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) 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_response.h" 5 #include "net/dns/dns_response.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 "net/dns/dns_query.h" 9 #include "net/dns/dns_query.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 0x00, 0x04, // RDLENGTH is 4 bytes. 198 0x00, 0x04, // RDLENGTH is 4 bytes.
199 0x4a, 0x7d, // RDATA is the IP: 74.125.95.121 199 0x4a, 0x7d, // RDATA is the IP: 74.125.95.121
200 0x5f, 0x79, 200 0x5f, 0x79,
201 }; 201 };
202 202
203 DnsResponse resp; 203 DnsResponse resp;
204 memcpy(resp.io_buffer()->data(), response_data, sizeof(response_data)); 204 memcpy(resp.io_buffer()->data(), response_data, sizeof(response_data));
205 205
206 // Reject too short. 206 // Reject too short.
207 EXPECT_FALSE(resp.InitParse(query->io_buffer()->size() - 1, *query)); 207 EXPECT_FALSE(resp.InitParse(query->io_buffer()->size() - 1, *query));
208 EXPECT_FALSE(resp.IsValid());
208 209
209 // Reject wrong id. 210 // Reject wrong id.
210 scoped_ptr<DnsQuery> other_query(query->CloneWithNewId(0xbeef)); 211 scoped_ptr<DnsQuery> other_query(query->CloneWithNewId(0xbeef));
211 EXPECT_FALSE(resp.InitParse(sizeof(response_data), *other_query)); 212 EXPECT_FALSE(resp.InitParse(sizeof(response_data), *other_query));
213 EXPECT_FALSE(resp.IsValid());
212 214
213 // Reject wrong question. 215 // Reject wrong question.
214 scoped_ptr<DnsQuery> wrong_query( 216 scoped_ptr<DnsQuery> wrong_query(
215 new DnsQuery(0xcafe, qname, dns_protocol::kTypeCNAME)); 217 new DnsQuery(0xcafe, qname, dns_protocol::kTypeCNAME));
216 EXPECT_FALSE(resp.InitParse(sizeof(response_data), *wrong_query)); 218 EXPECT_FALSE(resp.InitParse(sizeof(response_data), *wrong_query));
219 EXPECT_FALSE(resp.IsValid());
217 220
218 // Accept matching question. 221 // Accept matching question.
219 EXPECT_TRUE(resp.InitParse(sizeof(response_data), *query)); 222 EXPECT_TRUE(resp.InitParse(sizeof(response_data), *query));
223 EXPECT_TRUE(resp.IsValid());
220 224
221 // Check header access. 225 // Check header access.
222 EXPECT_EQ(0x81, resp.flags0()); 226 EXPECT_EQ(0x8180, resp.flags());
223 EXPECT_EQ(0x80, resp.flags1());
224 EXPECT_EQ(0x0, resp.rcode()); 227 EXPECT_EQ(0x0, resp.rcode());
225 EXPECT_EQ(2, resp.answer_count()); 228 EXPECT_EQ(2, resp.answer_count());
226 229
230 // Check question access.
231 EXPECT_EQ(query->qname(), resp.qname());
232 EXPECT_EQ(query->qtype(), resp.qtype());
233 EXPECT_EQ("codereview.chromium.org", resp.GetDottedName());
234
227 DnsResourceRecord record; 235 DnsResourceRecord record;
228 DnsRecordParser parser = resp.Parser(); 236 DnsRecordParser parser = resp.Parser();
229 EXPECT_TRUE(parser.ParseRecord(&record)); 237 EXPECT_TRUE(parser.ParseRecord(&record));
238 EXPECT_FALSE(parser.AtEnd());
230 EXPECT_TRUE(parser.ParseRecord(&record)); 239 EXPECT_TRUE(parser.ParseRecord(&record));
240 EXPECT_TRUE(parser.AtEnd());
231 EXPECT_FALSE(parser.ParseRecord(&record)); 241 EXPECT_FALSE(parser.ParseRecord(&record));
232 } 242 }
233 243
234 } // namespace 244 } // namespace
235 245
236 } // namespace net 246 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_response.cc ('k') | net/dns/dns_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698