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 |
11 TEST(BytesFormattingTest, GetByteDisplayUnits) { | 11 TEST(BytesFormattingTest, GetByteDisplayUnits) { |
12 static const struct { | 12 static const struct { |
13 int64 bytes; | 13 int64 bytes; |
14 DataUnits expected; | 14 DataUnits expected; |
15 } cases[] = { | 15 } cases[] = { |
16 {0, DATA_UNITS_BYTE}, | 16 {0, DATA_UNITS_BYTE}, |
17 {512, DATA_UNITS_BYTE}, | 17 {512, DATA_UNITS_BYTE}, |
18 {10*1024, DATA_UNITS_KIBIBYTE}, | 18 {10*1024, DATA_UNITS_KIBIBYTE}, |
19 {10*1024*1024, DATA_UNITS_MEBIBYTE}, | 19 {10*1024*1024, DATA_UNITS_MEBIBYTE}, |
20 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE}, | 20 {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE}, |
21 {10LL*1024*1024*1024*1024, DATA_UNITS_TEBIBYTE}, | 21 {10LL*1024*1024*1024*1024, DATA_UNITS_TEBIBYTE}, |
22 {~(1LL<<63), DATA_UNITS_PEBIBYTE}, | 22 {~(1LL<<63), DATA_UNITS_PEBIBYTE}, |
23 #ifdef NDEBUG | 23 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
24 {-1, DATA_UNITS_BYTE}, | 24 {-1, DATA_UNITS_BYTE}, |
25 #endif | 25 #endif |
26 }; | 26 }; |
27 | 27 |
28 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) | 28 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) |
29 EXPECT_EQ(cases[i].expected, GetByteDisplayUnits(cases[i].bytes)); | 29 EXPECT_EQ(cases[i].expected, GetByteDisplayUnits(cases[i].bytes)); |
30 } | 30 } |
31 | 31 |
32 TEST(BytesFormattingTest, FormatBytes) { | 32 TEST(BytesFormattingTest, FormatBytes) { |
33 static const struct { | 33 static const struct { |
(...skipping 22 matching lines...) Expand all Loading... |
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 #ifdef NDEBUG | 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 |