diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-19 09:16:49 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-19 09:16:49 +0000 |
commit | 9f25130b2cf85b8eae02576967201ac0cbe14846 (patch) | |
tree | a89790892da949c1085ba8da8da03969eef97515 /base/time_unittest.cc | |
parent | 8a2b93feeacc95ee609fabfb5815fdd88e1b3a86 (diff) | |
download | chromium_src-9f25130b2cf85b8eae02576967201ac0cbe14846.zip chromium_src-9f25130b2cf85b8eae02576967201ac0cbe14846.tar.gz chromium_src-9f25130b2cf85b8eae02576967201ac0cbe14846.tar.bz2 |
Add tests for From / In converions and LocalMidnight. Add InMinutes().
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_unittest.cc')
-rw-r--r-- | base/time_unittest.cc | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/base/time_unittest.cc b/base/time_unittest.cc index 829c579..b02451e 100644 --- a/base/time_unittest.cc +++ b/base/time_unittest.cc @@ -70,14 +70,19 @@ TEST(Time, TimeT) { time_t now_t_2 = our_time_2.ToTimeT(); EXPECT_EQ(now_t_1, now_t_2); + EXPECT_EQ(10, Time().FromTimeT(10).ToTimeT()); + EXPECT_EQ(10.0, Time().FromTimeT(10).ToDoubleT()); + // Conversions of 0 should stay 0. EXPECT_EQ(0, Time().ToTimeT()); EXPECT_EQ(0, Time::FromTimeT(0).ToInternalValue()); } TEST(Time, ZeroIsSymmetric) { - Time zeroTime(Time::FromTimeT(0)); - EXPECT_EQ(0, zeroTime.ToTimeT()); + Time zero_time(Time::FromTimeT(0)); + EXPECT_EQ(0, zero_time.ToTimeT()); + + EXPECT_EQ(0.0, zero_time.ToDoubleT()); } TEST(Time, LocalExplode) { @@ -101,6 +106,15 @@ TEST(Time, UTCExplode) { EXPECT_TRUE((a - b) < TimeDelta::FromMilliseconds(1)); } +TEST(Time, LocalMidnight) { + Time::Exploded exploded; + Time::Now().LocalMidnight().LocalExplode(&exploded); + EXPECT_EQ(0, exploded.hour); + EXPECT_EQ(0, exploded.minute); + EXPECT_EQ(0, exploded.second); + EXPECT_EQ(0, exploded.millisecond); +} + TEST(TimeTicks, Deltas) { TimeTicks ticks_start = TimeTicks::Now(); PlatformThread::Sleep(10); @@ -111,6 +125,23 @@ TEST(TimeTicks, Deltas) { EXPECT_EQ(delta.InSeconds(), 0); } +TEST(TimeDelta, FromAndIn) { + EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48)); + EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180)); + EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120)); + EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000)); + EXPECT_TRUE(TimeDelta::FromMilliseconds(2) == + TimeDelta::FromMicroseconds(2000)); + EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); + EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); + EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); + EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds()); + EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); + EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds()); + EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); + EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds()); +} + #if defined(OS_WIN) // TODO(pinkerton): Need to find a way to mock this for non-windows. |