39 using namespace v8::internal;
43 CHECK(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
44 CHECK(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
45 CHECK(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
46 CHECK(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
47 CHECK(TimeDelta::FromMilliseconds(2) == TimeDelta::FromMicroseconds(2000));
48 CHECK_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays());
49 CHECK_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours());
50 CHECK_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes());
51 CHECK_EQ(static_cast<int64_t>(13), TimeDelta::FromSeconds(13).InSeconds());
52 CHECK_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
54 TimeDelta::FromMilliseconds(13).InMilliseconds());
55 CHECK_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
57 TimeDelta::FromMicroseconds(13).InMicroseconds());
62 TEST(TimeDeltaFromMachTimespec) {
63 TimeDelta null = TimeDelta();
64 CHECK(null == TimeDelta::FromMachTimespec(null.ToMachTimespec()));
65 TimeDelta delta1 = TimeDelta::FromMilliseconds(42);
66 CHECK(delta1 == TimeDelta::FromMachTimespec(delta1.ToMachTimespec()));
67 TimeDelta delta2 = TimeDelta::FromDays(42);
68 CHECK(delta2 == TimeDelta::FromMachTimespec(delta2.ToMachTimespec()));
74 Time t = Time::FromJsTime(700000.3);
80 TEST(TimeFromTimespec) {
83 CHECK(null == Time::FromTimespec(null.ToTimespec()));
84 Time now = Time::Now();
85 CHECK(now == Time::FromTimespec(now.ToTimespec()));
86 Time now_sys = Time::NowFromSystemTime();
87 CHECK(now_sys == Time::FromTimespec(now_sys.ToTimespec()));
88 Time unix_epoch = Time::UnixEpoch();
89 CHECK(unix_epoch == Time::FromTimespec(unix_epoch.ToTimespec()));
90 Time max = Time::Max();
92 CHECK(max == Time::FromTimespec(max.ToTimespec()));
96 TEST(TimeFromTimeval) {
99 CHECK(null == Time::FromTimeval(null.ToTimeval()));
100 Time now = Time::Now();
101 CHECK(now == Time::FromTimeval(now.ToTimeval()));
102 Time now_sys = Time::NowFromSystemTime();
103 CHECK(now_sys == Time::FromTimeval(now_sys.ToTimeval()));
104 Time unix_epoch = Time::UnixEpoch();
105 CHECK(unix_epoch == Time::FromTimeval(unix_epoch.ToTimeval()));
106 Time max = Time::Max();
108 CHECK(max == Time::FromTimeval(max.ToTimeval()));
114 TEST(TimeFromFiletime) {
116 CHECK(null.IsNull());
117 CHECK(null == Time::FromFiletime(null.ToFiletime()));
118 Time now = Time::Now();
119 CHECK(now == Time::FromFiletime(now.ToFiletime()));
120 Time now_sys = Time::NowFromSystemTime();
121 CHECK(now_sys == Time::FromFiletime(now_sys.ToFiletime()));
122 Time unix_epoch = Time::UnixEpoch();
123 CHECK(unix_epoch == Time::FromFiletime(unix_epoch.ToFiletime()));
124 Time max = Time::Max();
126 CHECK(max == Time::FromFiletime(max.ToFiletime()));
132 TimeTicks previous_normal_ticks;
133 TimeTicks previous_highres_ticks;
136 while (!timer.HasExpired(TimeDelta::FromMilliseconds(100))) {
137 TimeTicks normal_ticks = TimeTicks::Now();
138 TimeTicks highres_ticks = TimeTicks::HighResolutionNow();
139 CHECK_GE(normal_ticks, previous_normal_ticks);
140 CHECK_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0);
141 CHECK_GE(highres_ticks, previous_highres_ticks);
142 CHECK_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0);
143 previous_normal_ticks = normal_ticks;
144 previous_highres_ticks = highres_ticks;
149 template <
typename T>
150 static void ResolutionTest(
T (*Now)(), TimeDelta target_granularity) {
157 static const TimeDelta kExpirationTimeout = TimeDelta::FromSeconds(1);
170 }
while (now <= start);
171 CHECK_NE(static_cast<int64_t>(0), delta.InMicroseconds());
172 }
while (delta > target_granularity && !timer.HasExpired(kExpirationTimeout));
173 CHECK_LE(delta, target_granularity);
179 static const TimeDelta kTargetGranularity = TimeDelta::FromMilliseconds(16);
180 ResolutionTest<Time>(&Time::Now, kTargetGranularity);
186 static const TimeDelta kTargetGranularity = TimeDelta::FromMilliseconds(16);
187 ResolutionTest<TimeTicks>(&TimeTicks::Now, kTargetGranularity);
191 TEST(TimeTicksHighResolutionNowResolution) {
192 if (!TimeTicks::IsHighResolutionClockWorking())
return;
195 static const TimeDelta kTargetGranularity = TimeDelta::FromMilliseconds(1);
196 ResolutionTest<TimeTicks>(&TimeTicks::HighResolutionNow, kTargetGranularity);
#define CHECK_EQ(expected, value)
#define CHECK_NE(unexpected, value)
#define T(name, string, precedence)