OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <math.h> | 5 #include <math.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 EXPECT_EQ(r[1], L"b\tcc"); | 1292 EXPECT_EQ(r[1], L"b\tcc"); |
1293 r.clear(); | 1293 r.clear(); |
1294 | 1294 |
1295 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); | 1295 SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r); |
1296 EXPECT_EQ(2U, r.size()); | 1296 EXPECT_EQ(2U, r.size()); |
1297 EXPECT_EQ(r[0], L"\ta\t"); | 1297 EXPECT_EQ(r[0], L"\ta\t"); |
1298 EXPECT_EQ(r[1], L"b\tcc"); | 1298 EXPECT_EQ(r[1], L"b\tcc"); |
1299 r.clear(); | 1299 r.clear(); |
1300 } | 1300 } |
1301 | 1301 |
| 1302 // Test for JoinString |
| 1303 TEST(StringUtilTest, JoinString) { |
| 1304 std::vector<std::string> in; |
| 1305 EXPECT_EQ("", JoinString(in, ',')); |
| 1306 |
| 1307 in.push_back("a"); |
| 1308 EXPECT_EQ("a", JoinString(in, ',')); |
| 1309 |
| 1310 in.push_back("b"); |
| 1311 in.push_back("c"); |
| 1312 EXPECT_EQ("a,b,c", JoinString(in, ',')); |
| 1313 |
| 1314 in.push_back(""); |
| 1315 EXPECT_EQ("a,b,c,", JoinString(in, ',')); |
| 1316 in.push_back(" "); |
| 1317 EXPECT_EQ("a|b|c|| ", JoinString(in, '|')); |
| 1318 } |
| 1319 |
1302 TEST(StringUtilTest, StartsWith) { | 1320 TEST(StringUtilTest, StartsWith) { |
1303 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true)); | 1321 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true)); |
1304 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true)); | 1322 EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true)); |
1305 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false)); | 1323 EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false)); |
1306 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false)); | 1324 EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false)); |
1307 EXPECT_FALSE(StartsWithASCII("java", "javascript", true)); | 1325 EXPECT_FALSE(StartsWithASCII("java", "javascript", true)); |
1308 EXPECT_FALSE(StartsWithASCII("java", "javascript", false)); | 1326 EXPECT_FALSE(StartsWithASCII("java", "javascript", false)); |
1309 EXPECT_FALSE(StartsWithASCII("", "javascript", false)); | 1327 EXPECT_FALSE(StartsWithASCII("", "javascript", false)); |
1310 EXPECT_FALSE(StartsWithASCII("", "javascript", true)); | 1328 EXPECT_FALSE(StartsWithASCII("", "javascript", true)); |
1311 EXPECT_TRUE(StartsWithASCII("java", "", false)); | 1329 EXPECT_TRUE(StartsWithASCII("java", "", false)); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 } | 1522 } |
1505 } | 1523 } |
1506 | 1524 |
1507 TEST(StringUtilTest, HexEncode) { | 1525 TEST(StringUtilTest, HexEncode) { |
1508 std::string hex(HexEncode(NULL, 0)); | 1526 std::string hex(HexEncode(NULL, 0)); |
1509 EXPECT_EQ(hex.length(), 0U); | 1527 EXPECT_EQ(hex.length(), 0U); |
1510 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; | 1528 unsigned char bytes[] = {0x01, 0xff, 0x02, 0xfe, 0x03, 0x80, 0x81}; |
1511 hex = HexEncode(bytes, sizeof(bytes)); | 1529 hex = HexEncode(bytes, sizeof(bytes)); |
1512 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); | 1530 EXPECT_EQ(hex.compare("01FF02FE038081"), 0); |
1513 } | 1531 } |
OLD | NEW |