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 "ui/base/l10n/time_format.h" | 5 #include "ui/base/l10n/time_format.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 | 12 |
13 using base::ASCIIToUTF16; | 13 using base::ASCIIToUTF16; |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 namespace { | 16 namespace { |
17 | 17 |
18 using base::TimeDelta; | 18 using base::TimeDelta; |
19 | 19 |
20 void TestTimeFormats(const TimeDelta& delta, const char* expected_ascii) { | 20 void TestTimeFormats(const TimeDelta& delta, const char* expect_ascii) { |
21 base::string16 expected = ASCIIToUTF16(expected_ascii); | 21 const base::string16 expect(ASCIIToUTF16(expect_ascii)); |
bartfab (slow)
2014/01/29 15:46:16
Nit: s/expect/expected/
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
22 base::string16 expected_left = expected + ASCIIToUTF16(" left"); | 22 const base::string16 sec (ASCIIToUTF16("sec")); |
bartfab (slow)
2014/01/29 15:46:16
* Do not align with spaces.
* Please add one_ pre
Thiemo Nagel
2014/01/29 16:18:05
Done, except "one_" prefixes.
| |
23 base::string16 expected_ago = expected + ASCIIToUTF16(" ago"); | 23 const base::string16 min (ASCIIToUTF16("min")); |
24 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); | 24 const base::string16 ond (ASCIIToUTF16("ond")); |
bartfab (slow)
2014/01/29 15:46:16
"ond" and "ute" are not exactly self-explanatory.
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
25 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta)); | 25 const base::string16 ute (ASCIIToUTF16("ute")); |
26 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); | 26 const base::string16 _ago (ASCIIToUTF16(" ago")); |
bartfab (slow)
2014/01/29 15:46:16
Do not start variable names with _. I know it stan
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
27 const base::string16 _left (ASCIIToUTF16(" left")); | |
28 | |
29 base::string16 expect_long = expect; // sec, min --> second, minute | |
bartfab (slow)
2014/01/29 15:46:16
Do not align with spaces.
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
30 base::string16 expect_long_minute = expect; // min --> minute | |
31 | |
32 if (expect_long.find(sec) != base::string16::npos) { | |
33 expect_long.insert(expect_long.find(sec)+sec.length(), ond); | |
bartfab (slow)
2014/01/29 15:46:16
Here and further down: Spaces around the + are mis
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
34 } | |
35 if (expect_long.find(min) != base::string16::npos) { | |
36 expect_long.insert(expect_long.find(min)+min.length(), ute); | |
37 } | |
38 if (expect_long_minute.find(min) != base::string16::npos) { | |
39 expect_long_minute.insert(expect_long_minute.find(min)+min.length(), ute); | |
40 } | |
41 | |
42 const base::string16 expect_elapsed = expect + _ago; | |
bartfab (slow)
2014/01/29 15:46:16
Here and throughout the rest of the CL: Do not ali
Thiemo Nagel
2014/01/29 16:18:05
Done.
| |
43 const base::string16 expect_remaining = expect + _left; | |
44 const base::string16 expect_remaining_long = expect_long_minute + _left; | |
45 const base::string16 expect_remaining_short = expect; | |
46 const base::string16 expect_duration_long = expect_long; | |
47 | |
48 EXPECT_EQ(expect_elapsed, TimeFormat::TimeElapsed(delta)); | |
49 EXPECT_EQ(expect_remaining, TimeFormat::TimeRemaining(delta)); | |
50 EXPECT_EQ(expect_remaining_long, TimeFormat::TimeRemainingLong(delta)); | |
51 EXPECT_EQ(expect_remaining_short, TimeFormat::TimeRemainingShort(delta)); | |
52 EXPECT_EQ(expect_duration_long, TimeFormat::TimeDurationLong(delta)); | |
27 } | 53 } |
28 | 54 |
29 TEST(TimeFormat, FormatTime) { | 55 TEST(TimeFormat, FormatTime) { |
30 const TimeDelta one_day = TimeDelta::FromDays(1); | 56 const TimeDelta one_day = TimeDelta::FromDays(1); |
31 const TimeDelta three_days = TimeDelta::FromDays(3); | 57 const TimeDelta three_days = TimeDelta::FromDays(3); |
32 const TimeDelta one_hour = TimeDelta::FromHours(1); | 58 const TimeDelta one_hour = TimeDelta::FromHours(1); |
33 const TimeDelta four_hours = TimeDelta::FromHours(4); | 59 const TimeDelta four_hours = TimeDelta::FromHours(4); |
34 const TimeDelta one_min = TimeDelta::FromMinutes(1); | 60 const TimeDelta one_min = TimeDelta::FromMinutes(1); |
35 const TimeDelta three_mins = TimeDelta::FromMinutes(3); | 61 const TimeDelta three_mins = TimeDelta::FromMinutes(3); |
36 const TimeDelta one_sec = TimeDelta::FromSeconds(1); | 62 const TimeDelta one_sec = TimeDelta::FromSeconds(1); |
(...skipping 30 matching lines...) Expand all Loading... | |
67 TimeFormat::RelativeDate(two_days_ago, NULL); | 93 TimeFormat::RelativeDate(two_days_ago, NULL); |
68 EXPECT_TRUE(two_days_ago_str.empty()); | 94 EXPECT_TRUE(two_days_ago_str.empty()); |
69 | 95 |
70 base::Time a_week_ago = now - TimeDelta::FromDays(7); | 96 base::Time a_week_ago = now - TimeDelta::FromDays(7); |
71 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); | 97 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); |
72 EXPECT_TRUE(a_week_ago_str.empty()); | 98 EXPECT_TRUE(a_week_ago_str.empty()); |
73 } | 99 } |
74 | 100 |
75 } // namespace | 101 } // namespace |
76 } // namespace ui | 102 } // namespace ui |
OLD | NEW |