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* expected_ascii) { |
21 base::string16 expected = ASCIIToUTF16(expected_ascii); | 21 const base::string16 expected(ASCIIToUTF16(expected_ascii)); |
22 base::string16 expected_left = expected + ASCIIToUTF16(" left"); | 22 const base::string16 sec(ASCIIToUTF16("sec")); |
23 base::string16 expected_ago = expected + ASCIIToUTF16(" ago"); | 23 const base::string16 min(ASCIIToUTF16("min")); |
24 const base::string16 ond(ASCIIToUTF16("ond")); | |
bartfab (slow)
2014/01/31 12:58:23
Nit: No longer used.
Thiemo Nagel
2014/01/31 14:10:36
Done.
| |
25 const base::string16 ute(); | |
bartfab (slow)
2014/01/31 12:58:23
Nit: No longer used and actually completely wrong
Thiemo Nagel
2014/01/31 14:10:36
That's embarrassing. I forgot to remove ond and ut
| |
26 | |
27 base::string16 expected_long = expected; // sec, min --> second, minute | |
28 base::string16 expected_long_minute = expected; // min --> minute | |
29 | |
30 if (expected_long.find(sec) != base::string16::npos) | |
31 expected_long.insert(expected_long.find(sec) + sec.length(), | |
32 ASCIIToUTF16("ond")); | |
33 if (expected_long.find(min) != base::string16::npos) | |
34 expected_long.insert(expected_long.find(min) + min.length(), | |
35 ASCIIToUTF16("ute")); | |
36 if (expected_long_minute.find(min) != base::string16::npos) | |
bartfab (slow)
2014/01/31 12:58:23
Nit: Not sure whether it would make things cleaner
Thiemo Nagel
2014/01/31 14:10:36
Good idea! I have the impression that this makes t
| |
37 expected_long_minute.insert(expected_long_minute.find(min) + min.length(), | |
38 ASCIIToUTF16("ute")); | |
39 | |
40 EXPECT_EQ(expected + ASCIIToUTF16(" ago"), TimeFormat::TimeElapsed(delta)); | |
41 EXPECT_EQ(expected + ASCIIToUTF16(" left"), TimeFormat::TimeRemaining(delta)); | |
42 EXPECT_EQ(expected_long_minute + ASCIIToUTF16(" left"), | |
43 TimeFormat::TimeRemainingLong(delta)); | |
24 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); | 44 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); |
25 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta)); | 45 EXPECT_EQ(expected_long, TimeFormat::TimeDurationLong(delta)); |
bartfab (slow)
2014/01/31 12:58:23
Is there a reason that TimeDurationLong() expands
Thiemo Nagel
2014/01/31 14:10:36
I fully agree. However, this behaviour is documen
| |
26 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); | |
27 } | 46 } |
28 | 47 |
29 TEST(TimeFormat, FormatTime) { | 48 TEST(TimeFormat, FormatTime) { |
30 const TimeDelta one_day = TimeDelta::FromDays(1); | 49 const TimeDelta one_day = TimeDelta::FromDays(1); |
31 const TimeDelta three_days = TimeDelta::FromDays(3); | 50 const TimeDelta three_days = TimeDelta::FromDays(3); |
32 const TimeDelta one_hour = TimeDelta::FromHours(1); | 51 const TimeDelta one_hour = TimeDelta::FromHours(1); |
33 const TimeDelta four_hours = TimeDelta::FromHours(4); | 52 const TimeDelta four_hours = TimeDelta::FromHours(4); |
34 const TimeDelta one_min = TimeDelta::FromMinutes(1); | 53 const TimeDelta one_min = TimeDelta::FromMinutes(1); |
35 const TimeDelta three_mins = TimeDelta::FromMinutes(3); | 54 const TimeDelta three_mins = TimeDelta::FromMinutes(3); |
36 const TimeDelta one_sec = TimeDelta::FromSeconds(1); | 55 const TimeDelta one_sec = TimeDelta::FromSeconds(1); |
(...skipping 30 matching lines...) Expand all Loading... | |
67 TimeFormat::RelativeDate(two_days_ago, NULL); | 86 TimeFormat::RelativeDate(two_days_ago, NULL); |
68 EXPECT_TRUE(two_days_ago_str.empty()); | 87 EXPECT_TRUE(two_days_ago_str.empty()); |
69 | 88 |
70 base::Time a_week_ago = now - TimeDelta::FromDays(7); | 89 base::Time a_week_ago = now - TimeDelta::FromDays(7); |
71 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); | 90 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); |
72 EXPECT_TRUE(a_week_ago_str.empty()); | 91 EXPECT_TRUE(a_week_ago_str.empty()); |
73 } | 92 } |
74 | 93 |
75 } // namespace | 94 } // namespace |
76 } // namespace ui | 95 } // namespace ui |
OLD | NEW |