OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
6 | 6 |
7 #if V8_OS_MACOSX | 7 #if V8_OS_MACOSX |
8 #include <mach/mach_time.h> | 8 #include <mach/mach_time.h> |
9 #endif | 9 #endif |
10 #if V8_OS_POSIX | 10 #if V8_OS_POSIX |
(...skipping 13 matching lines...) Expand all Loading... |
24 TEST(TimeDelta, FromAndIn) { | 24 TEST(TimeDelta, FromAndIn) { |
25 EXPECT_EQ(TimeDelta::FromDays(2), TimeDelta::FromHours(48)); | 25 EXPECT_EQ(TimeDelta::FromDays(2), TimeDelta::FromHours(48)); |
26 EXPECT_EQ(TimeDelta::FromHours(3), TimeDelta::FromMinutes(180)); | 26 EXPECT_EQ(TimeDelta::FromHours(3), TimeDelta::FromMinutes(180)); |
27 EXPECT_EQ(TimeDelta::FromMinutes(2), TimeDelta::FromSeconds(120)); | 27 EXPECT_EQ(TimeDelta::FromMinutes(2), TimeDelta::FromSeconds(120)); |
28 EXPECT_EQ(TimeDelta::FromSeconds(2), TimeDelta::FromMilliseconds(2000)); | 28 EXPECT_EQ(TimeDelta::FromSeconds(2), TimeDelta::FromMilliseconds(2000)); |
29 EXPECT_EQ(TimeDelta::FromMilliseconds(2), TimeDelta::FromMicroseconds(2000)); | 29 EXPECT_EQ(TimeDelta::FromMilliseconds(2), TimeDelta::FromMicroseconds(2000)); |
30 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays()); | 30 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays()); |
31 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours()); | 31 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours()); |
32 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes()); | 32 EXPECT_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes()); |
33 EXPECT_EQ(static_cast<int64_t>(13), TimeDelta::FromSeconds(13).InSeconds()); | 33 EXPECT_EQ(static_cast<int64_t>(13), TimeDelta::FromSeconds(13).InSeconds()); |
34 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); | 34 EXPECT_DOUBLE_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); |
35 EXPECT_EQ(static_cast<int64_t>(13), | 35 EXPECT_EQ(static_cast<int64_t>(13), |
36 TimeDelta::FromMilliseconds(13).InMilliseconds()); | 36 TimeDelta::FromMilliseconds(13).InMilliseconds()); |
37 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); | 37 EXPECT_DOUBLE_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); |
38 EXPECT_EQ(static_cast<int64_t>(13), | 38 EXPECT_EQ(static_cast<int64_t>(13), |
39 TimeDelta::FromMicroseconds(13).InMicroseconds()); | 39 TimeDelta::FromMicroseconds(13).InMicroseconds()); |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 #if V8_OS_MACOSX | 43 #if V8_OS_MACOSX |
44 TEST(TimeDelta, MachTimespec) { | 44 TEST(TimeDelta, MachTimespec) { |
45 TimeDelta null = TimeDelta(); | 45 TimeDelta null = TimeDelta(); |
46 EXPECT_EQ(null, TimeDelta::FromMachTimespec(null.ToMachTimespec())); | 46 EXPECT_EQ(null, TimeDelta::FromMachTimespec(null.ToMachTimespec())); |
47 TimeDelta delta1 = TimeDelta::FromMilliseconds(42); | 47 TimeDelta delta1 = TimeDelta::FromMilliseconds(42); |
48 EXPECT_EQ(delta1, TimeDelta::FromMachTimespec(delta1.ToMachTimespec())); | 48 EXPECT_EQ(delta1, TimeDelta::FromMachTimespec(delta1.ToMachTimespec())); |
49 TimeDelta delta2 = TimeDelta::FromDays(42); | 49 TimeDelta delta2 = TimeDelta::FromDays(42); |
50 EXPECT_EQ(delta2, TimeDelta::FromMachTimespec(delta2.ToMachTimespec())); | 50 EXPECT_EQ(delta2, TimeDelta::FromMachTimespec(delta2.ToMachTimespec())); |
51 } | 51 } |
52 #endif | 52 #endif |
53 | 53 |
54 | 54 |
55 TEST(Time, JsTime) { | 55 TEST(Time, JsTime) { |
56 Time t = Time::FromJsTime(700000.3); | 56 Time t = Time::FromJsTime(700000.3); |
57 EXPECT_EQ(700000.3, t.ToJsTime()); | 57 EXPECT_DOUBLE_EQ(700000.3, t.ToJsTime()); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 #if V8_OS_POSIX | 61 #if V8_OS_POSIX |
62 TEST(Time, Timespec) { | 62 TEST(Time, Timespec) { |
63 Time null; | 63 Time null; |
64 EXPECT_TRUE(null.IsNull()); | 64 EXPECT_TRUE(null.IsNull()); |
65 EXPECT_EQ(null, Time::FromTimespec(null.ToTimespec())); | 65 EXPECT_EQ(null, Time::FromTimespec(null.ToTimespec())); |
66 Time now = Time::Now(); | 66 Time now = Time::Now(); |
67 EXPECT_EQ(now, Time::FromTimespec(now.ToTimespec())); | 67 EXPECT_EQ(now, Time::FromTimespec(now.ToTimespec())); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0); | 177 EXPECT_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0); |
178 EXPECT_GE(highres_ticks, previous_highres_ticks); | 178 EXPECT_GE(highres_ticks, previous_highres_ticks); |
179 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0); | 179 EXPECT_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0); |
180 previous_normal_ticks = normal_ticks; | 180 previous_normal_ticks = normal_ticks; |
181 previous_highres_ticks = highres_ticks; | 181 previous_highres_ticks = highres_ticks; |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 } // namespace base | 185 } // namespace base |
186 } // namespace v8 | 186 } // namespace v8 |
OLD | NEW |