| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string16.h" |
| 8 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/time_format.h" | 11 #include "chrome/common/time_format.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 using base::Time; | 14 using base::Time; |
| 13 using base::TimeDelta; | 15 using base::TimeDelta; |
| 14 | 16 |
| 15 TEST(TimeFormat, RelativeDate) { | 17 TEST(TimeFormat, RelativeDate) { |
| 16 Time now = Time::Now(); | 18 Time now = Time::Now(); |
| 17 std::wstring today_str = TimeFormat::RelativeDate(now, NULL); | 19 string16 today_str = TimeFormat::RelativeDate(now, NULL); |
| 18 EXPECT_EQ(L"Today", today_str); | 20 EXPECT_EQ(ASCIIToUTF16("Today"), today_str); |
| 19 | 21 |
| 20 Time yesterday = now - TimeDelta::FromDays(1); | 22 Time yesterday = now - TimeDelta::FromDays(1); |
| 21 std::wstring yesterday_str = TimeFormat::RelativeDate(yesterday, NULL); | 23 string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL); |
| 22 EXPECT_EQ(L"Yesterday", yesterday_str); | 24 EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str); |
| 23 | 25 |
| 24 Time two_days_ago = now - TimeDelta::FromDays(2); | 26 Time two_days_ago = now - TimeDelta::FromDays(2); |
| 25 std::wstring two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL); | 27 string16 two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL); |
| 26 EXPECT_TRUE(two_days_ago_str.empty()); | 28 EXPECT_TRUE(two_days_ago_str.empty()); |
| 27 | 29 |
| 28 Time a_week_ago = now - TimeDelta::FromDays(7); | 30 Time a_week_ago = now - TimeDelta::FromDays(7); |
| 29 std::wstring a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); | 31 string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); |
| 30 EXPECT_TRUE(a_week_ago_str.empty()); | 32 EXPECT_TRUE(a_week_ago_str.empty()); |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 void TestTimeFormats(const TimeDelta delta, const std::wstring& expected) { | 36 void TestTimeFormats(const TimeDelta delta, const char* expected_ascii) { |
| 35 std::wstring expected_left = expected + L" left"; | 37 string16 expected = ASCIIToUTF16(expected_ascii); |
| 36 std::wstring expected_ago = expected + L" ago"; | 38 string16 expected_left = expected + ASCIIToUTF16(" left"); |
| 39 string16 expected_ago = expected + ASCIIToUTF16(" ago"); |
| 37 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); | 40 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); |
| 38 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta)); | 41 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta)); |
| 39 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); | 42 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); |
| 40 } | 43 } |
| 41 | 44 |
| 42 } // namespace | 45 } // namespace |
| 43 | 46 |
| 44 TEST(TimeFormat, FormatTime) { | 47 TEST(TimeFormat, FormatTime) { |
| 45 const TimeDelta one_day = TimeDelta::FromDays(1); | 48 const TimeDelta one_day = TimeDelta::FromDays(1); |
| 46 const TimeDelta three_days = TimeDelta::FromDays(3); | 49 const TimeDelta three_days = TimeDelta::FromDays(3); |
| 47 const TimeDelta one_hour = TimeDelta::FromHours(1); | 50 const TimeDelta one_hour = TimeDelta::FromHours(1); |
| 48 const TimeDelta four_hours = TimeDelta::FromHours(4); | 51 const TimeDelta four_hours = TimeDelta::FromHours(4); |
| 49 const TimeDelta one_min = TimeDelta::FromMinutes(1); | 52 const TimeDelta one_min = TimeDelta::FromMinutes(1); |
| 50 const TimeDelta three_mins = TimeDelta::FromMinutes(3); | 53 const TimeDelta three_mins = TimeDelta::FromMinutes(3); |
| 51 const TimeDelta one_sec = TimeDelta::FromSeconds(1); | 54 const TimeDelta one_sec = TimeDelta::FromSeconds(1); |
| 52 const TimeDelta five_secs = TimeDelta::FromSeconds(5); | 55 const TimeDelta five_secs = TimeDelta::FromSeconds(5); |
| 53 const TimeDelta twohundred_millisecs = TimeDelta::FromMilliseconds(200); | 56 const TimeDelta twohundred_millisecs = TimeDelta::FromMilliseconds(200); |
| 54 | 57 |
| 55 // TODO(jungshik) : These test only pass when the OS locale is 'en'. | 58 // TODO(jungshik) : These test only pass when the OS locale is 'en'. |
| 56 // We need to add SetUp() and TearDown() to set the locale to 'en'. | 59 // We need to add SetUp() and TearDown() to set the locale to 'en'. |
| 57 TestTimeFormats(twohundred_millisecs, L"0 secs"); | 60 TestTimeFormats(twohundred_millisecs, "0 secs"); |
| 58 TestTimeFormats(one_sec - twohundred_millisecs, L"0 secs"); | 61 TestTimeFormats(one_sec - twohundred_millisecs, "0 secs"); |
| 59 TestTimeFormats(one_sec + twohundred_millisecs, L"1 sec"); | 62 TestTimeFormats(one_sec + twohundred_millisecs, "1 sec"); |
| 60 TestTimeFormats(five_secs + twohundred_millisecs, L"5 secs"); | 63 TestTimeFormats(five_secs + twohundred_millisecs, "5 secs"); |
| 61 TestTimeFormats(one_min + five_secs, L"1 min"); | 64 TestTimeFormats(one_min + five_secs, "1 min"); |
| 62 TestTimeFormats(three_mins + twohundred_millisecs, L"3 mins"); | 65 TestTimeFormats(three_mins + twohundred_millisecs, "3 mins"); |
| 63 TestTimeFormats(one_hour + five_secs, L"1 hour"); | 66 TestTimeFormats(one_hour + five_secs, "1 hour"); |
| 64 TestTimeFormats(four_hours + five_secs, L"4 hours"); | 67 TestTimeFormats(four_hours + five_secs, "4 hours"); |
| 65 TestTimeFormats(one_day + five_secs, L"1 day"); | 68 TestTimeFormats(one_day + five_secs, "1 day"); |
| 66 TestTimeFormats(three_days, L"3 days"); | 69 TestTimeFormats(three_days, "3 days"); |
| 67 TestTimeFormats(three_days + four_hours, L"3 days"); | 70 TestTimeFormats(three_days + four_hours, "3 days"); |
| 68 } | 71 } |
| OLD | NEW |