OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/base/text/bytes_formatting.h" | 7 #include "ui/base/text/bytes_formatting.h" |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 const char* expected_with_units; | 37 const char* expected_with_units; |
38 } cases[] = { | 38 } cases[] = { |
39 // Expected behavior: we show one post-decimal digit when we have | 39 // Expected behavior: we show one post-decimal digit when we have |
40 // under two pre-decimal digits, except in cases where it makes no | 40 // under two pre-decimal digits, except in cases where it makes no |
41 // sense (zero or bytes). | 41 // sense (zero or bytes). |
42 // Since we switch units once we cross the 1000 mark, this keeps | 42 // Since we switch units once we cross the 1000 mark, this keeps |
43 // the display of file sizes or bytes consistently around three | 43 // the display of file sizes or bytes consistently around three |
44 // digits. | 44 // digits. |
45 {0, DATA_UNITS_BYTE, "0", "0 B"}, | 45 {0, DATA_UNITS_BYTE, "0", "0 B"}, |
46 {512, DATA_UNITS_BYTE, "512", "512 B"}, | 46 {512, DATA_UNITS_BYTE, "512", "512 B"}, |
47 {512, DATA_UNITS_KIBIBYTE, "0.5", "0.5 kB"}, | 47 {512, DATA_UNITS_KIBIBYTE, "0.5", "0.5 KB"}, |
48 {1024*1024, DATA_UNITS_KIBIBYTE, "1,024", "1,024 kB"}, | 48 {1024*1024, DATA_UNITS_KIBIBYTE, "1,024", "1,024 KB"}, |
49 {1024*1024, DATA_UNITS_MEBIBYTE, "1.0", "1.0 MB"}, | 49 {1024*1024, DATA_UNITS_MEBIBYTE, "1.0", "1.0 MB"}, |
50 {1024*1024*1024, DATA_UNITS_GIBIBYTE, "1.0", "1.0 GB"}, | 50 {1024*1024*1024, DATA_UNITS_GIBIBYTE, "1.0", "1.0 GB"}, |
51 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, | 51 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, |
52 {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "99.0", "99.0 GB"}, | 52 {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "99.0", "99.0 GB"}, |
53 {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "105", "105 GB"}, | 53 {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "105", "105 GB"}, |
54 {105LL*1024*1024*1024 + 500LL*1024*1024, DATA_UNITS_GIBIBYTE, | 54 {105LL*1024*1024*1024 + 500LL*1024*1024, DATA_UNITS_GIBIBYTE, |
55 "105", "105 GB"}, | 55 "105", "105 GB"}, |
56 {~(1LL<<63), DATA_UNITS_GIBIBYTE, "8,589,934,592", "8,589,934,592 GB"}, | 56 {~(1LL<<63), DATA_UNITS_GIBIBYTE, "8,589,934,592", "8,589,934,592 GB"}, |
57 {~(1LL<<63), DATA_UNITS_PEBIBYTE, "8,192", "8,192 PB"}, | 57 {~(1LL<<63), DATA_UNITS_PEBIBYTE, "8,192", "8,192 PB"}, |
58 | 58 |
59 {99*1024 + 103, DATA_UNITS_KIBIBYTE, "99.1", "99.1 kB"}, | 59 {99*1024 + 103, DATA_UNITS_KIBIBYTE, "99.1", "99.1 KB"}, |
60 {1024*1024 + 103, DATA_UNITS_KIBIBYTE, "1,024", "1,024 kB"}, | 60 {1024*1024 + 103, DATA_UNITS_KIBIBYTE, "1,024", "1,024 KB"}, |
61 {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, "1.2", "1.2 MB"}, | 61 {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, "1.2", "1.2 MB"}, |
62 {1024*1024*1024 + (927 * 1024*1024), DATA_UNITS_GIBIBYTE, | 62 {1024*1024*1024 + (927 * 1024*1024), DATA_UNITS_GIBIBYTE, |
63 "1.9", "1.9 GB"}, | 63 "1.9", "1.9 GB"}, |
64 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, | 64 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"}, |
65 {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "100", "100 GB"}, | 65 {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "100", "100 GB"}, |
66 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 66 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
67 {-1, DATA_UNITS_BYTE, "", ""}, | 67 {-1, DATA_UNITS_BYTE, "", ""}, |
68 #endif | 68 #endif |
69 }; | 69 }; |
70 | 70 |
71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
72 EXPECT_EQ(ASCIIToUTF16(cases[i].expected), | 72 EXPECT_EQ(ASCIIToUTF16(cases[i].expected), |
73 FormatBytesWithUnits(cases[i].bytes, cases[i].units, false)); | 73 FormatBytesWithUnits(cases[i].bytes, cases[i].units, false)); |
74 EXPECT_EQ(ASCIIToUTF16(cases[i].expected_with_units), | 74 EXPECT_EQ(ASCIIToUTF16(cases[i].expected_with_units), |
75 FormatBytesWithUnits(cases[i].bytes, cases[i].units, true)); | 75 FormatBytesWithUnits(cases[i].bytes, cases[i].units, true)); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 } // namespace ui | 79 } // namespace ui |
OLD | NEW |