OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 EXPECT_FALSE( | 454 EXPECT_FALSE( |
455 IsStringASCII(wchar_ascii.substr(0, len))); | 455 IsStringASCII(wchar_ascii.substr(0, len))); |
456 wchar_ascii[char_pos] &= ~0x10000; | 456 wchar_ascii[char_pos] &= ~0x10000; |
457 #endif // WCHAR_T_IS_UTF32 | 457 #endif // WCHAR_T_IS_UTF32 |
458 } | 458 } |
459 } | 459 } |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 TEST(StringUtilTest, ConvertASCII) { | 463 TEST(StringUtilTest, ConvertASCII) { |
464 static const char* char_cases[] = { | 464 static const char* const char_cases[] = { |
465 "Google Video", | 465 "Google Video", |
466 "Hello, world\n", | 466 "Hello, world\n", |
467 "0123ABCDwxyz \a\b\t\r\n!+,.~" | 467 "0123ABCDwxyz \a\b\t\r\n!+,.~" |
468 }; | 468 }; |
469 | 469 |
470 static const wchar_t* const wchar_cases[] = { | 470 static const wchar_t* const wchar_cases[] = { |
471 L"Google Video", | 471 L"Google Video", |
472 L"Hello, world\n", | 472 L"Hello, world\n", |
473 L"0123ABCDwxyz \a\b\t\r\n!+,.~" | 473 L"0123ABCDwxyz \a\b\t\r\n!+,.~" |
474 }; | 474 }; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 // the display of file sizes or bytes consistently around three | 559 // the display of file sizes or bytes consistently around three |
560 // digits. | 560 // digits. |
561 {0, "0 B"}, | 561 {0, "0 B"}, |
562 {512, "512 B"}, | 562 {512, "512 B"}, |
563 {1024*1024, "1.0 MB"}, | 563 {1024*1024, "1.0 MB"}, |
564 {1024*1024*1024, "1.0 GB"}, | 564 {1024*1024*1024, "1.0 GB"}, |
565 {10LL*1024*1024*1024, "10.0 GB"}, | 565 {10LL*1024*1024*1024, "10.0 GB"}, |
566 {99LL*1024*1024*1024, "99.0 GB"}, | 566 {99LL*1024*1024*1024, "99.0 GB"}, |
567 {105LL*1024*1024*1024, "105 GB"}, | 567 {105LL*1024*1024*1024, "105 GB"}, |
568 {105LL*1024*1024*1024 + 500LL*1024*1024, "105 GB"}, | 568 {105LL*1024*1024*1024 + 500LL*1024*1024, "105 GB"}, |
569 {~(1LL<<63), "8192 PB"}, | 569 {~(1LL << 63), "8192 PB"}, |
570 | 570 |
571 {99*1024 + 103, "99.1 kB"}, | 571 {99*1024 + 103, "99.1 kB"}, |
572 {1024*1024 + 103, "1.0 MB"}, | 572 {1024*1024 + 103, "1.0 MB"}, |
573 {1024*1024 + 205 * 1024, "1.2 MB"}, | 573 {1024*1024 + 205 * 1024, "1.2 MB"}, |
574 {1024*1024*1024 + (927 * 1024*1024), "1.9 GB"}, | 574 {1024*1024*1024 + (927 * 1024*1024), "1.9 GB"}, |
575 {10LL*1024*1024*1024, "10.0 GB"}, | 575 {10LL*1024*1024*1024, "10.0 GB"}, |
576 {100LL*1024*1024*1024, "100 GB"}, | 576 {100LL*1024*1024*1024, "100 GB"}, |
577 }; | 577 }; |
578 | 578 |
579 for (size_t i = 0; i < arraysize(cases); ++i) { | 579 for (size_t i = 0; i < arraysize(cases); ++i) { |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 { L"%f %d %o %u", true }, | 1146 { L"%f %d %o %u", true }, |
1147 { L"%-8d (%02.1f%)", true }, | 1147 { L"%-8d (%02.1f%)", true }, |
1148 { L"% 10s", false }, | 1148 { L"% 10s", false }, |
1149 { L"% 10ls", true } | 1149 { L"% 10ls", true } |
1150 }; | 1150 }; |
1151 for (size_t i = 0; i < arraysize(cases); ++i) | 1151 for (size_t i = 0; i < arraysize(cases); ++i) |
1152 EXPECT_EQ(cases[i].portable, base::IsWprintfFormatPortable(cases[i].input)); | 1152 EXPECT_EQ(cases[i].portable, base::IsWprintfFormatPortable(cases[i].input)); |
1153 } | 1153 } |
1154 | 1154 |
1155 TEST(StringUtilTest, RemoveChars) { | 1155 TEST(StringUtilTest, RemoveChars) { |
1156 const char* kRemoveChars = "-/+*"; | 1156 const char kRemoveChars[] = "-/+*"; |
1157 std::string input = "A-+bc/d!*"; | 1157 std::string input = "A-+bc/d!*"; |
1158 EXPECT_TRUE(RemoveChars(input, kRemoveChars, &input)); | 1158 EXPECT_TRUE(RemoveChars(input, kRemoveChars, &input)); |
1159 EXPECT_EQ("Abcd!", input); | 1159 EXPECT_EQ("Abcd!", input); |
1160 | 1160 |
1161 // No characters match kRemoveChars. | 1161 // No characters match kRemoveChars. |
1162 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input)); | 1162 EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input)); |
1163 EXPECT_EQ("Abcd!", input); | 1163 EXPECT_EQ("Abcd!", input); |
1164 | 1164 |
1165 // Empty string. | 1165 // Empty string. |
1166 input.clear(); | 1166 input.clear(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 const std::string live = kLive; | 1259 const std::string live = kLive; |
1260 std::string dead = live; | 1260 std::string dead = live; |
1261 strncpy(WriteInto(&dead, 5), kDead, 4); | 1261 strncpy(WriteInto(&dead, 5), kDead, 4); |
1262 EXPECT_EQ(kDead, dead); | 1262 EXPECT_EQ(kDead, dead); |
1263 EXPECT_EQ(4u, dead.size()); | 1263 EXPECT_EQ(4u, dead.size()); |
1264 EXPECT_EQ(kLive, live); | 1264 EXPECT_EQ(kLive, live); |
1265 EXPECT_EQ(4u, live.size()); | 1265 EXPECT_EQ(4u, live.size()); |
1266 } | 1266 } |
1267 | 1267 |
1268 } // namespace base | 1268 } // namespace base |
OLD | NEW |