OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 }; | 523 }; |
524 | 524 |
525 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) | 525 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) |
526 EXPECT_EQ(cases[i].expected, GetByteDisplayUnits(cases[i].bytes)); | 526 EXPECT_EQ(cases[i].expected, GetByteDisplayUnits(cases[i].bytes)); |
527 } | 527 } |
528 | 528 |
529 TEST(StringUtilTest, FormatBytes) { | 529 TEST(StringUtilTest, FormatBytes) { |
530 static const struct { | 530 static const struct { |
531 int64 bytes; | 531 int64 bytes; |
532 DataUnits units; | 532 DataUnits units; |
533 const wchar_t* expected; | 533 const char* expected; |
534 const wchar_t* expected_with_units; | 534 const char* expected_with_units; |
535 } cases[] = { | 535 } cases[] = { |
536 // Expected behavior: we show one post-decimal digit when we have | 536 // Expected behavior: we show one post-decimal digit when we have |
537 // under two pre-decimal digits, except in cases where it makes no | 537 // under two pre-decimal digits, except in cases where it makes no |
538 // sense (zero or bytes). | 538 // sense (zero or bytes). |
539 // Since we switch units once we cross the 1000 mark, this keeps | 539 // Since we switch units once we cross the 1000 mark, this keeps |
540 // the display of file sizes or bytes consistently around three | 540 // the display of file sizes or bytes consistently around three |
541 // digits. | 541 // digits. |
542 {0, DATA_UNITS_BYTE, L"0", L"0 B"}, | 542 {0, DATA_UNITS_BYTE, "0", "0 B"}, |
543 {512, DATA_UNITS_BYTE, L"512", L"512 B"}, | 543 {512, DATA_UNITS_BYTE, "512", "512 B"}, |
544 {512, DATA_UNITS_KIBIBYTE, L"0.5", L"0.5 kB"}, | 544 {512, DATA_UNITS_KIBIBYTE, "0.5", "0.5 kB"}, |
545 {1024*1024, DATA_UNITS_KIBIBYTE, L"1024", L"1024 kB"}, | 545 {1024*1024, DATA_UNITS_KIBIBYTE, "1024", "1024 kB"}, |
546 {1024*1024, DATA_UNITS_MEBIBYTE, L"1.0", L"1.0 MB"}, | 546 {1024*1024, DATA_UNITS_MEBIBYTE, "1.0", "1.0 MB"}, |
547 {1024*1024*1024, DATA_UNITS_GIBIBYTE, L"1.0", L"1.0 GB"}, | 547 {1024*1024*1024, DATA_UNITS_GIBIBYTE, "1.0", "1.0 GB"}, |
548 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"10.0", L"10.0 GB"}, | 548 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, |
549 {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"99.0", L"99.0 GB"}, | 549 {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "99.0", "99.0 GB"}, |
550 {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"105", L"105 GB"}, | 550 {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "105", "105 GB"}, |
551 {105LL*1024*1024*1024 + 500LL*1024*1024, DATA_UNITS_GIBIBYTE, | 551 {105LL*1024*1024*1024 + 500LL*1024*1024, DATA_UNITS_GIBIBYTE, |
552 L"105", L"105 GB"}, | 552 "105", "105 GB"}, |
553 {~(1LL<<63), DATA_UNITS_GIBIBYTE, L"8589934592", L"8589934592 GB"}, | 553 {~(1LL<<63), DATA_UNITS_GIBIBYTE, "8589934592", "8589934592 GB"}, |
554 | 554 |
555 {99*1024 + 103, DATA_UNITS_KIBIBYTE, L"99.1", L"99.1 kB"}, | 555 {99*1024 + 103, DATA_UNITS_KIBIBYTE, "99.1", "99.1 kB"}, |
556 {1024*1024 + 103, DATA_UNITS_KIBIBYTE, L"1024", L"1024 kB"}, | 556 {1024*1024 + 103, DATA_UNITS_KIBIBYTE, "1024", "1024 kB"}, |
557 {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, L"1.2", L"1.2 MB"}, | 557 {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, "1.2", "1.2 MB"}, |
558 {1024*1024*1024 + (927 * 1024*1024), DATA_UNITS_GIBIBYTE, | 558 {1024*1024*1024 + (927 * 1024*1024), DATA_UNITS_GIBIBYTE, |
559 L"1.9", L"1.9 GB"}, | 559 "1.9", "1.9 GB"}, |
560 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"10.0", L"10.0 GB"}, | 560 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, |
561 {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"100", L"100 GB"}, | 561 {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "100", "100 GB"}, |
562 #ifdef NDEBUG | 562 #ifdef NDEBUG |
563 {-1, DATA_UNITS_BYTE, L"", L""}, | 563 {-1, DATA_UNITS_BYTE, "", ""}, |
564 #endif | 564 #endif |
565 }; | 565 }; |
566 | 566 |
567 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 567 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
568 EXPECT_EQ(cases[i].expected, | 568 EXPECT_EQ(ASCIIToUTF16(cases[i].expected), |
569 FormatBytes(cases[i].bytes, cases[i].units, false)); | 569 FormatBytes(cases[i].bytes, cases[i].units, false)); |
570 EXPECT_EQ(cases[i].expected_with_units, | 570 EXPECT_EQ(ASCIIToUTF16(cases[i].expected_with_units), |
571 FormatBytes(cases[i].bytes, cases[i].units, true)); | 571 FormatBytes(cases[i].bytes, cases[i].units, true)); |
572 } | 572 } |
573 } | 573 } |
574 | 574 |
575 TEST(StringUtilTest, ReplaceSubstringsAfterOffset) { | 575 TEST(StringUtilTest, ReplaceSubstringsAfterOffset) { |
576 static const struct { | 576 static const struct { |
577 const char* str; | 577 const char* str; |
578 string16::size_type start_offset; | 578 string16::size_type start_offset; |
579 const char* find_this; | 579 const char* find_this; |
580 const char* replace_with; | 580 const char* replace_with; |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 SplitStringUsingSubstr( | 1251 SplitStringUsingSubstr( |
1252 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER", | 1252 "unDELIMITERdeuxDELIMITERtroisDELIMITERquatreDELIMITERDELIMITERDELIMITER", |
1253 "DELIMITER", | 1253 "DELIMITER", |
1254 &results); | 1254 &results); |
1255 ASSERT_EQ(7u, results.size()); | 1255 ASSERT_EQ(7u, results.size()); |
1256 EXPECT_THAT( | 1256 EXPECT_THAT( |
1257 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); | 1257 results, ElementsAre("un", "deux", "trois", "quatre", "", "", "")); |
1258 } | 1258 } |
1259 | 1259 |
1260 } // namespace base | 1260 } // namespace base |
OLD | NEW |