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

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
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/dns/record_rdata.h" 6 #include "net/dns/record_rdata.h"
7 #include "net/dns/dns_response.h" 7 #include "net/dns/dns_response.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 ASSERT_EQ("www.google.com", record1_obj->target()); 46 ASSERT_EQ("www.google.com", record1_obj->target());
47 47
48 record2_obj = SrvRecordRdata::Create(record2_strpiece, parser); 48 record2_obj = SrvRecordRdata::Create(record2_strpiece, parser);
49 ASSERT_TRUE(record2_obj != NULL); 49 ASSERT_TRUE(record2_obj != NULL);
50 ASSERT_EQ(257, record2_obj->priority()); 50 ASSERT_EQ(257, record2_obj->priority());
51 ASSERT_EQ(258, record2_obj->weight()); 51 ASSERT_EQ(258, record2_obj->weight());
52 ASSERT_EQ(259, record2_obj->port()); 52 ASSERT_EQ(259, record2_obj->port());
53 53
54 ASSERT_EQ("www2.google.com", record2_obj->target()); 54 ASSERT_EQ("www2.google.com", record2_obj->target());
55
56 ASSERT_TRUE(record1_obj->IsEqual(record1_obj.get()));
57 ASSERT_FALSE(record1_obj->IsEqual(record2_obj.get()));
55 } 58 }
56 59
57 TEST(RecordRdataTest, ParseARecord) { 60 TEST(RecordRdataTest, ParseARecord) {
58 scoped_ptr<ARecordRdata> record_obj; 61 scoped_ptr<ARecordRdata> record_obj;
59 62
60 // These are just the rdata portions of the DNS records, rather than complete 63 // These are just the rdata portions of the DNS records, rather than complete
61 // records, but it works well enough for this test. 64 // records, but it works well enough for this test.
62 65
63 const char record[] = { 66 const char record[] = {
64 0x7F, 0x00, 0x00, 0x01 // 127.0.0.1 67 0x7F, 0x00, 0x00, 0x01 // 127.0.0.1
65 }; 68 };
66 69
67 DnsRecordParser parser(record, sizeof(record), 0); 70 DnsRecordParser parser(record, sizeof(record), 0);
68 base::StringPiece record_strpiece(record, sizeof(record)); 71 base::StringPiece record_strpiece(record, sizeof(record));
69 72
70 record_obj = ARecordRdata::Create(record_strpiece, parser); 73 record_obj = ARecordRdata::Create(record_strpiece, parser);
71 ASSERT_TRUE(record_obj != NULL); 74 ASSERT_TRUE(record_obj != NULL);
72 75
73 ASSERT_EQ("127.0.0.1", IPAddressToString(record_obj->address())); 76 ASSERT_EQ("127.0.0.1", IPAddressToString(record_obj->address()));
77
78 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
79 }
80
81 TEST(RecordRdataTest, ParseAAAARecord) {
82 scoped_ptr<AAAARecordRdata> record_obj;
83
84 // These are just the rdata portions of the DNS records, rather than complete
85 // records, but it works well enough for this test.
86
87 const char record[] = {
88 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x01 // ::1
92 };
93
94 DnsRecordParser parser(record, sizeof(record), 0);
95 base::StringPiece record_strpiece(record, sizeof(record));
96
97 record_obj = AAAARecordRdata::Create(record_strpiece, parser);
98 ASSERT_TRUE(record_obj != NULL);
99
100 ASSERT_EQ("::1",
101 IPAddressToString(record_obj->address()));
102
103 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
74 } 104 }
75 105
76 TEST(RecordRdataTest, ParseCnameRecord) { 106 TEST(RecordRdataTest, ParseCnameRecord) {
77 scoped_ptr<CnameRecordRdata> record_obj; 107 scoped_ptr<CnameRecordRdata> record_obj;
78 108
79 // These are just the rdata portions of the DNS records, rather than complete 109 // These are just the rdata portions of the DNS records, rather than complete
80 // records, but it works well enough for this test. 110 // records, but it works well enough for this test.
81 111
82 const char record[] = { 112 const char record[] = {
83 0x03, 'w', 'w', 'w', 113 0x03, 'w', 'w', 'w',
84 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 114 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
85 0x03, 'c', 'o', 'm', 115 0x03, 'c', 'o', 'm',
86 0x00 116 0x00
87 }; 117 };
88 118
89 DnsRecordParser parser(record, sizeof(record), 0); 119 DnsRecordParser parser(record, sizeof(record), 0);
90 base::StringPiece record_strpiece(record, sizeof(record)); 120 base::StringPiece record_strpiece(record, sizeof(record));
91 121
92 record_obj = CnameRecordRdata::Create(record_strpiece, parser); 122 record_obj = CnameRecordRdata::Create(record_strpiece, parser);
93 ASSERT_TRUE(record_obj != NULL); 123 ASSERT_TRUE(record_obj != NULL);
94 124
95 ASSERT_EQ("www.google.com", record_obj->cname()); 125 ASSERT_EQ("www.google.com", record_obj->cname());
126
127 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
96 } 128 }
97 129
98 TEST(RecordRdataTest, ParsePtrRecord) { 130 TEST(RecordRdataTest, ParsePtrRecord) {
99 scoped_ptr<PtrRecordRdata> record_obj; 131 scoped_ptr<PtrRecordRdata> record_obj;
100 132
101 // These are just the rdata portions of the DNS records, rather than complete 133 // These are just the rdata portions of the DNS records, rather than complete
102 // records, but it works well enough for this test. 134 // records, but it works well enough for this test.
103 135
104 const char record[] = { 136 const char record[] = {
105 0x03, 'w', 'w', 'w', 137 0x03, 'w', 'w', 'w',
106 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 138 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
107 0x03, 'c', 'o', 'm', 139 0x03, 'c', 'o', 'm',
108 0x00 140 0x00
109 }; 141 };
110 142
111 DnsRecordParser parser(record, sizeof(record), 0); 143 DnsRecordParser parser(record, sizeof(record), 0);
112 base::StringPiece record_strpiece(record, sizeof(record)); 144 base::StringPiece record_strpiece(record, sizeof(record));
113 145
114 record_obj = PtrRecordRdata::Create(record_strpiece, parser); 146 record_obj = PtrRecordRdata::Create(record_strpiece, parser);
115 ASSERT_TRUE(record_obj != NULL); 147 ASSERT_TRUE(record_obj != NULL);
116 148
117 ASSERT_EQ("www.google.com", record_obj->ptrdomain()); 149 ASSERT_EQ("www.google.com", record_obj->ptrdomain());
150
151 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
118 } 152 }
119 153
120 TEST(RecordRdataTest, ParseTxtRecord) { 154 TEST(RecordRdataTest, ParseTxtRecord) {
121 scoped_ptr<TxtRecordRdata> record_obj; 155 scoped_ptr<TxtRecordRdata> record_obj;
122 156
123 // These are just the rdata portions of the DNS records, rather than complete 157 // These are just the rdata portions of the DNS records, rather than complete
124 // records, but it works well enough for this test. 158 // records, but it works well enough for this test.
125 159
126 const char record[] = { 160 const char record[] = {
127 0x03, 'w', 'w', 'w', 161 0x03, 'w', 'w', 'w',
128 0x06, 'g', 'o', 'o', 'g', 'l', 'e', 162 0x06, 'g', 'o', 'o', 'g', 'l', 'e',
129 0x03, 'c', 'o', 'm' 163 0x03, 'c', 'o', 'm'
130 }; 164 };
131 165
132 DnsRecordParser parser(record, sizeof(record), 0); 166 DnsRecordParser parser(record, sizeof(record), 0);
133 base::StringPiece record_strpiece(record, sizeof(record)); 167 base::StringPiece record_strpiece(record, sizeof(record));
134 168
135 record_obj = TxtRecordRdata::Create(record_strpiece, parser); 169 record_obj = TxtRecordRdata::Create(record_strpiece, parser);
136 ASSERT_TRUE(record_obj != NULL); 170 ASSERT_TRUE(record_obj != NULL);
137 171
138 std::vector<std::string> expected; 172 std::vector<std::string> expected;
139 expected.push_back("www"); 173 expected.push_back("www");
140 expected.push_back("google"); 174 expected.push_back("google");
141 expected.push_back("com"); 175 expected.push_back("com");
142 176
143 ASSERT_EQ(expected, record_obj->texts()); 177 ASSERT_EQ(expected, record_obj->texts());
178
179 ASSERT_TRUE(record_obj->IsEqual(record_obj.get()));
144 } 180 }
145 181
146 } // namespace net 182 } // namespace net
OLDNEW
« net/dns/record_rdata.cc ('K') | « net/dns/record_rdata.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698