| Index: base/time/time_unittest.cc
|
| diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc
|
| index a96787cf207dd750cfca5d1fe024e40ffceb034c..6c12423d790f2544dca864b85790c480819b2393 100644
|
| --- a/base/time/time_unittest.cc
|
| +++ b/base/time/time_unittest.cc
|
| @@ -942,6 +942,77 @@ TEST(TimeDelta, NumericOperators) {
|
| 2 * TimeDelta::FromMilliseconds(1000));
|
| }
|
|
|
| +bool IsMin(TimeDelta delta) {
|
| + return (-delta).is_max();
|
| +}
|
| +
|
| +TEST(TimeDelta, Overflows) {
|
| + // Some sanity checks.
|
| + EXPECT_TRUE(TimeDelta::Max().is_max());
|
| + EXPECT_TRUE(IsMin(-TimeDelta::Max()));
|
| + EXPECT_GT(TimeDelta(), -TimeDelta::Max());
|
| +
|
| + TimeDelta large_delta = TimeDelta::Max() - TimeDelta::FromMilliseconds(1);
|
| + TimeDelta large_negative = -large_delta;
|
| + EXPECT_GT(TimeDelta(), large_negative);
|
| + EXPECT_FALSE(large_delta.is_max());
|
| + EXPECT_FALSE(IsMin(-large_negative));
|
| + TimeDelta one_second = TimeDelta::FromSeconds(1);
|
| +
|
| + // Test +, -, * and / operators.
|
| + EXPECT_TRUE((large_delta + one_second).is_max());
|
| + EXPECT_TRUE(IsMin(large_negative + (-one_second)));
|
| + EXPECT_TRUE(IsMin(large_negative - one_second));
|
| + EXPECT_TRUE((large_delta - (-one_second)).is_max());
|
| + EXPECT_TRUE((large_delta * 2).is_max());
|
| + EXPECT_TRUE(IsMin(large_delta * -2));
|
| + EXPECT_TRUE((large_delta / 0.5).is_max());
|
| + EXPECT_TRUE(IsMin(large_delta / -0.5));
|
| +
|
| + // Test +=, -=, *= and /= operators.
|
| + TimeDelta delta = large_delta;
|
| + delta += one_second;
|
| + EXPECT_TRUE(delta.is_max());
|
| + delta = large_negative;
|
| + delta += -one_second;
|
| + EXPECT_TRUE(IsMin(delta));
|
| +
|
| + delta = large_negative;
|
| + delta -= one_second;
|
| + EXPECT_TRUE(IsMin(delta));
|
| + delta = large_delta;
|
| + delta -= -one_second;
|
| + EXPECT_TRUE(delta.is_max());
|
| +
|
| + delta = large_delta;
|
| + delta *= 2;
|
| + EXPECT_TRUE(delta.is_max());
|
| + delta = large_negative;
|
| + delta *= 1.5;
|
| + EXPECT_TRUE(IsMin(delta));
|
| +
|
| + delta = large_delta;
|
| + delta /= 0.5;
|
| + EXPECT_TRUE(delta.is_max());
|
| + delta = large_negative;
|
| + delta /= 0.5;
|
| + EXPECT_TRUE(IsMin(delta));
|
| +
|
| + // Test operations with Time and TimeTicks.
|
| + EXPECT_TRUE((large_delta + Time::Now()).is_max());
|
| + EXPECT_TRUE((large_delta + TimeTicks::Now()).is_max());
|
| + EXPECT_TRUE((Time::Now() + large_delta).is_max());
|
| + EXPECT_TRUE((TimeTicks::Now() + large_delta).is_max());
|
| +
|
| + Time time_now = Time::Now();
|
| + EXPECT_EQ(one_second, (time_now + one_second) - time_now);
|
| + EXPECT_EQ(-one_second, (time_now - one_second) - time_now);
|
| +
|
| + TimeTicks ticks_now = TimeTicks::Now();
|
| + EXPECT_EQ(-one_second, (ticks_now - one_second) - ticks_now);
|
| + EXPECT_EQ(one_second, (ticks_now + one_second) - ticks_now);
|
| +}
|
| +
|
| TEST(TimeDeltaLogging, DCheckEqCompiles) {
|
| DCHECK_EQ(TimeDelta(), TimeDelta());
|
| }
|
|
|