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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "net/dns/record_parsed.h" 5 #include "net/dns/record_parsed.h"
6 6
7 #include "net/dns/dns_protocol.h" 7 #include "net/dns/dns_protocol.h"
8 #include "net/dns/dns_response.h" 8 #include "net/dns/dns_response.h"
9 #include "net/dns/dns_test_util.h" 9 #include "net/dns/dns_test_util.h"
10 #include "net/dns/record_rdata.h" 10 #include "net/dns/record_rdata.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 static const uint8 kT1ResponseWithCacheFlushBit[] = { 15 static const uint8 kT1ResponseWithCacheFlushBit[] = {
16 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w', 16 0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i',
17 0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm', 17 'e', 'w', 0x08, 'c', 'h', 'r', 'o', 'm', 'i',
18 0x03, 'o', 'r', 'g', 18 'u', 'm', 0x03, 'o', 'r', 'g', 0x00, 0x00, 0x05, // TYPE is CNAME.
19 0x00, 19 0x80, 0x01, // CLASS is IN with cache flush bit set.
20 0x00, 0x05, // TYPE is CNAME. 20 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds.
21 0x80, 0x01, // CLASS is IN with cache flush bit set. 21 0x24, 0x74, 0x00, 0x12, // RDLENGTH is 18 bytes.
22 0x00, 0x01, // TTL (4 bytes) is 20 hours, 47 minutes, 48 seconds. 22 // ghs.l.google.com in DNS format.
23 0x24, 0x74, 23 0x03, 'g', 'h', 's', 0x01, 'l', 0x06, 'g', 'o',
24 0x00, 0x12, // RDLENGTH is 18 bytes. 24 'o', 'g', 'l', 'e', 0x03, 'c', 'o', 'm', 0x00};
25 // ghs.l.google.com in DNS format.
26 0x03, 'g', 'h', 's',
27 0x01, 'l',
28 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
29 0x03, 'c', 'o', 'm',
30 0x00
31 };
32 25
33 TEST(RecordParsedTest, ParseSingleRecord) { 26 TEST(RecordParsedTest, ParseSingleRecord) {
34 DnsRecordParser parser(kT1ResponseDatagram, sizeof(kT1ResponseDatagram), 27 DnsRecordParser parser(kT1ResponseDatagram,
28 sizeof(kT1ResponseDatagram),
35 sizeof(dns_protocol::Header)); 29 sizeof(dns_protocol::Header));
36 scoped_ptr<const RecordParsed> record; 30 scoped_ptr<const RecordParsed> record;
37 const CnameRecordRdata* rdata; 31 const CnameRecordRdata* rdata;
38 32
39 parser.SkipQuestion(); 33 parser.SkipQuestion();
40 record = RecordParsed::CreateFrom(&parser, base::Time()); 34 record = RecordParsed::CreateFrom(&parser, base::Time());
41 EXPECT_TRUE(record != NULL); 35 EXPECT_TRUE(record != NULL);
42 36
43 ASSERT_EQ("codereview.chromium.org", record->name()); 37 ASSERT_EQ("codereview.chromium.org", record->name());
44 ASSERT_EQ(dns_protocol::kTypeCNAME, record->type()); 38 ASSERT_EQ(dns_protocol::kTypeCNAME, record->type());
45 ASSERT_EQ(dns_protocol::kClassIN, record->klass()); 39 ASSERT_EQ(dns_protocol::kClassIN, record->klass());
46 40
47 rdata = record->rdata<CnameRecordRdata>(); 41 rdata = record->rdata<CnameRecordRdata>();
48 ASSERT_TRUE(rdata != NULL); 42 ASSERT_TRUE(rdata != NULL);
49 ASSERT_EQ(kT1CanonName, rdata->cname()); 43 ASSERT_EQ(kT1CanonName, rdata->cname());
50 44
51 ASSERT_FALSE(record->rdata<SrvRecordRdata>()); 45 ASSERT_FALSE(record->rdata<SrvRecordRdata>());
52 ASSERT_TRUE(record->IsEqual(record.get(), true)); 46 ASSERT_TRUE(record->IsEqual(record.get(), true));
53 } 47 }
54 48
55 TEST(RecordParsedTest, CacheFlushBitCompare) { 49 TEST(RecordParsedTest, CacheFlushBitCompare) {
56 DnsRecordParser parser1(kT1ResponseDatagram, sizeof(kT1ResponseDatagram), 50 DnsRecordParser parser1(kT1ResponseDatagram,
57 sizeof(dns_protocol::Header)); 51 sizeof(kT1ResponseDatagram),
52 sizeof(dns_protocol::Header));
58 parser1.SkipQuestion(); 53 parser1.SkipQuestion();
59 scoped_ptr<const RecordParsed> record1 = 54 scoped_ptr<const RecordParsed> record1 =
60 RecordParsed::CreateFrom(&parser1, base::Time()); 55 RecordParsed::CreateFrom(&parser1, base::Time());
61 56
62 DnsRecordParser parser2(kT1ResponseWithCacheFlushBit, 57 DnsRecordParser parser2(
63 sizeof(kT1ResponseWithCacheFlushBit), 58 kT1ResponseWithCacheFlushBit, sizeof(kT1ResponseWithCacheFlushBit), 0);
64 0);
65 59
66 scoped_ptr<const RecordParsed> record2 = 60 scoped_ptr<const RecordParsed> record2 =
67 RecordParsed::CreateFrom(&parser2, base::Time()); 61 RecordParsed::CreateFrom(&parser2, base::Time());
68 62
69 EXPECT_FALSE(record1->IsEqual(record2.get(), false)); 63 EXPECT_FALSE(record1->IsEqual(record2.get(), false));
70 EXPECT_TRUE(record1->IsEqual(record2.get(), true)); 64 EXPECT_TRUE(record1->IsEqual(record2.get(), true));
71 EXPECT_FALSE(record2->IsEqual(record1.get(), false)); 65 EXPECT_FALSE(record2->IsEqual(record1.get(), false));
72 EXPECT_TRUE(record2->IsEqual(record1.get(), true)); 66 EXPECT_TRUE(record2->IsEqual(record1.get(), true));
73 } 67 }
74 68
75 } //namespace net 69 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698