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

Side by Side Diff: url/scheme_host_port_unittest.cc

Issue 1542703002: Switch to standard integer types in url/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « url/scheme_host_port.cc ('k') | url/url_canon_icu.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h>
6 #include <stdint.h>
7
8 #include "base/macros.h"
5 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
6 #include "url/gurl.h" 10 #include "url/gurl.h"
7 #include "url/scheme_host_port.h" 11 #include "url/scheme_host_port.h"
8 12
9 namespace { 13 namespace {
10 14
11 TEST(SchemeHostPortTest, Invalid) { 15 TEST(SchemeHostPortTest, Invalid) {
12 url::SchemeHostPort invalid; 16 url::SchemeHostPort invalid;
13 EXPECT_EQ("", invalid.scheme()); 17 EXPECT_EQ("", invalid.scheme());
14 EXPECT_EQ("", invalid.host()); 18 EXPECT_EQ("", invalid.host());
(...skipping 18 matching lines...) Expand all
33 EXPECT_TRUE(tuple.Equals(tuple)); 37 EXPECT_TRUE(tuple.Equals(tuple));
34 EXPECT_TRUE(tuple.Equals(invalid)); 38 EXPECT_TRUE(tuple.Equals(invalid));
35 EXPECT_TRUE(invalid.Equals(tuple)); 39 EXPECT_TRUE(invalid.Equals(tuple));
36 } 40 }
37 } 41 }
38 42
39 TEST(SchemeHostPortTest, ExplicitConstruction) { 43 TEST(SchemeHostPortTest, ExplicitConstruction) {
40 struct TestCases { 44 struct TestCases {
41 const char* scheme; 45 const char* scheme;
42 const char* host; 46 const char* host;
43 uint16 port; 47 uint16_t port;
44 } cases[] = { 48 } cases[] = {
45 {"http", "example.com", 80}, 49 {"http", "example.com", 80},
46 {"http", "example.com", 123}, 50 {"http", "example.com", 123},
47 {"https", "example.com", 443}, 51 {"https", "example.com", 443},
48 {"https", "example.com", 123}, 52 {"https", "example.com", 123},
49 {"file", "", 0}, 53 {"file", "", 0},
50 {"file", "example.com", 0}, 54 {"file", "example.com", 0},
51 }; 55 };
52 56
53 for (const auto& test : cases) { 57 for (const auto& test : cases) {
54 SCOPED_TRACE(testing::Message() << test.scheme << "://" << test.host << ":" 58 SCOPED_TRACE(testing::Message() << test.scheme << "://" << test.host << ":"
55 << test.port); 59 << test.port);
56 url::SchemeHostPort tuple(test.scheme, test.host, test.port); 60 url::SchemeHostPort tuple(test.scheme, test.host, test.port);
57 EXPECT_EQ(test.scheme, tuple.scheme()); 61 EXPECT_EQ(test.scheme, tuple.scheme());
58 EXPECT_EQ(test.host, tuple.host()); 62 EXPECT_EQ(test.host, tuple.host());
59 EXPECT_EQ(test.port, tuple.port()); 63 EXPECT_EQ(test.port, tuple.port());
60 EXPECT_FALSE(tuple.IsInvalid()); 64 EXPECT_FALSE(tuple.IsInvalid());
61 EXPECT_TRUE(tuple.Equals(tuple)); 65 EXPECT_TRUE(tuple.Equals(tuple));
62 } 66 }
63 } 67 }
64 68
65 TEST(SchemeHostPortTest, InvalidConstruction) { 69 TEST(SchemeHostPortTest, InvalidConstruction) {
66 struct TestCases { 70 struct TestCases {
67 const char* scheme; 71 const char* scheme;
68 const char* host; 72 const char* host;
69 uint16 port; 73 uint16_t port;
70 } cases[] = {{"", "", 0}, 74 } cases[] = {{"", "", 0},
71 {"data", "", 0}, 75 {"data", "", 0},
72 {"blob", "", 0}, 76 {"blob", "", 0},
73 {"filesystem", "", 0}, 77 {"filesystem", "", 0},
74 {"http", "", 80}, 78 {"http", "", 80},
75 {"data", "example.com", 80}, 79 {"data", "example.com", 80},
76 {"http", "☃.net", 80}, 80 {"http", "☃.net", 80},
77 {"http\nmore", "example.com", 80}, 81 {"http\nmore", "example.com", 80},
78 {"http\rmore", "example.com", 80}, 82 {"http\rmore", "example.com", 80},
79 {"http\n", "example.com", 80}, 83 {"http\n", "example.com", 80},
(...skipping 16 matching lines...) Expand all
96 EXPECT_TRUE(tuple.Equals(tuple)); 100 EXPECT_TRUE(tuple.Equals(tuple));
97 } 101 }
98 } 102 }
99 103
100 TEST(SchemeHostPortTest, InvalidConstructionWithEmbeddedNulls) { 104 TEST(SchemeHostPortTest, InvalidConstructionWithEmbeddedNulls) {
101 struct TestCases { 105 struct TestCases {
102 const char* scheme; 106 const char* scheme;
103 size_t scheme_length; 107 size_t scheme_length;
104 const char* host; 108 const char* host;
105 size_t host_length; 109 size_t host_length;
106 uint16 port; 110 uint16_t port;
107 } cases[] = {{"http\0more", 9, "example.com", 11, 80}, 111 } cases[] = {{"http\0more", 9, "example.com", 11, 80},
108 {"http\0", 5, "example.com", 11, 80}, 112 {"http\0", 5, "example.com", 11, 80},
109 {"\0http", 5, "example.com", 11, 80}, 113 {"\0http", 5, "example.com", 11, 80},
110 {"http", 4, "example.com\0not-example.com", 27, 80}, 114 {"http", 4, "example.com\0not-example.com", 27, 80},
111 {"http", 4, "example.com\0", 12, 80}, 115 {"http", 4, "example.com\0", 12, 80},
112 {"http", 4, "\0example.com", 12, 80}}; 116 {"http", 4, "\0example.com", 12, 80}};
113 117
114 for (const auto& test : cases) { 118 for (const auto& test : cases) {
115 SCOPED_TRACE(testing::Message() << test.scheme << "://" << test.host << ":" 119 SCOPED_TRACE(testing::Message() << test.scheme << "://" << test.host << ":"
116 << test.port); 120 << test.port);
117 url::SchemeHostPort tuple(std::string(test.scheme, test.scheme_length), 121 url::SchemeHostPort tuple(std::string(test.scheme, test.scheme_length),
118 std::string(test.host, test.host_length), 122 std::string(test.host, test.host_length),
119 test.port); 123 test.port);
120 EXPECT_EQ("", tuple.scheme()); 124 EXPECT_EQ("", tuple.scheme());
121 EXPECT_EQ("", tuple.host()); 125 EXPECT_EQ("", tuple.host());
122 EXPECT_EQ(0, tuple.port()); 126 EXPECT_EQ(0, tuple.port());
123 EXPECT_TRUE(tuple.IsInvalid()); 127 EXPECT_TRUE(tuple.IsInvalid());
124 } 128 }
125 } 129 }
126 130
127 TEST(SchemeHostPortTest, GURLConstruction) { 131 TEST(SchemeHostPortTest, GURLConstruction) {
128 struct TestCases { 132 struct TestCases {
129 const char* url; 133 const char* url;
130 const char* scheme; 134 const char* scheme;
131 const char* host; 135 const char* host;
132 uint16 port; 136 uint16_t port;
133 } cases[] = { 137 } cases[] = {
134 {"http://192.168.9.1/", "http", "192.168.9.1", 80}, 138 {"http://192.168.9.1/", "http", "192.168.9.1", 80},
135 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80}, 139 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80},
136 {"http://☃.net/", "http", "xn--n3h.net", 80}, 140 {"http://☃.net/", "http", "xn--n3h.net", 80},
137 {"http://example.com/", "http", "example.com", 80}, 141 {"http://example.com/", "http", "example.com", 80},
138 {"http://example.com:123/", "http", "example.com", 123}, 142 {"http://example.com:123/", "http", "example.com", 123},
139 {"https://example.com/", "https", "example.com", 443}, 143 {"https://example.com/", "https", "example.com", 443},
140 {"https://example.com:123/", "https", "example.com", 123}, 144 {"https://example.com:123/", "https", "example.com", 123},
141 {"file:///etc/passwd", "file", "", 0}, 145 {"file:///etc/passwd", "file", "", 0},
142 {"file://example.com/etc/passwd", "file", "example.com", 0}, 146 {"file://example.com/etc/passwd", "file", "example.com", 0},
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 url::SchemeHostPort tuple(url); 185 url::SchemeHostPort tuple(url);
182 EXPECT_EQ(test.expected, tuple.Serialize()); 186 EXPECT_EQ(test.expected, tuple.Serialize());
183 } 187 }
184 } 188 }
185 189
186 TEST(SchemeHostPortTest, Comparison) { 190 TEST(SchemeHostPortTest, Comparison) {
187 // These tuples are arranged in increasing order: 191 // These tuples are arranged in increasing order:
188 struct SchemeHostPorts { 192 struct SchemeHostPorts {
189 const char* scheme; 193 const char* scheme;
190 const char* host; 194 const char* host;
191 uint16 port; 195 uint16_t port;
192 } tuples[] = { 196 } tuples[] = {
193 {"http", "a", 80}, 197 {"http", "a", 80},
194 {"http", "b", 80}, 198 {"http", "b", 80},
195 {"https", "a", 80}, 199 {"https", "a", 80},
196 {"https", "b", 80}, 200 {"https", "b", 80},
197 {"http", "a", 81}, 201 {"http", "a", 81},
198 {"http", "b", 81}, 202 {"http", "b", 81},
199 {"https", "a", 81}, 203 {"https", "a", 81},
200 {"https", "b", 81}, 204 {"https", "b", 81},
201 }; 205 };
202 206
203 for (size_t i = 0; i < arraysize(tuples); i++) { 207 for (size_t i = 0; i < arraysize(tuples); i++) {
204 url::SchemeHostPort current(tuples[i].scheme, tuples[i].host, 208 url::SchemeHostPort current(tuples[i].scheme, tuples[i].host,
205 tuples[i].port); 209 tuples[i].port);
206 for (size_t j = i; j < arraysize(tuples); j++) { 210 for (size_t j = i; j < arraysize(tuples); j++) {
207 url::SchemeHostPort to_compare(tuples[j].scheme, tuples[j].host, 211 url::SchemeHostPort to_compare(tuples[j].scheme, tuples[j].host,
208 tuples[j].port); 212 tuples[j].port);
209 EXPECT_EQ(i < j, current < to_compare) << i << " < " << j; 213 EXPECT_EQ(i < j, current < to_compare) << i << " < " << j;
210 EXPECT_EQ(j < i, to_compare < current) << j << " < " << i; 214 EXPECT_EQ(j < i, to_compare < current) << j << " < " << i;
211 } 215 }
212 } 216 }
213 } 217 }
214 218
215 } // namespace url 219 } // namespace url
OLDNEW
« no previous file with comments | « url/scheme_host_port.cc ('k') | url/url_canon_icu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698