Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: test/cctest/test-time.cc

Issue 23690003: Revert "Add Chromium-style TimeDelta, Time and TimeTicks classes, and a new ElapsedTimer class." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include <cstdlib>
29
30 #include "v8.h"
31
32 #include "cctest.h"
33 #if V8_OS_WIN
34 #include "win32-headers.h"
35 #endif
36
37 using namespace v8::internal;
38
39
40 TEST(TimeDeltaFromAndIn) {
41 CHECK(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
42 CHECK(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
43 CHECK(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
44 CHECK(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
45 CHECK(TimeDelta::FromMilliseconds(2) == TimeDelta::FromMicroseconds(2000));
46 CHECK_EQ(static_cast<int>(13), TimeDelta::FromDays(13).InDays());
47 CHECK_EQ(static_cast<int>(13), TimeDelta::FromHours(13).InHours());
48 CHECK_EQ(static_cast<int>(13), TimeDelta::FromMinutes(13).InMinutes());
49 CHECK_EQ(static_cast<int64_t>(13), TimeDelta::FromSeconds(13).InSeconds());
50 CHECK_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
51 CHECK_EQ(static_cast<int64_t>(13),
52 TimeDelta::FromMilliseconds(13).InMilliseconds());
53 CHECK_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
54 CHECK_EQ(static_cast<int64_t>(13),
55 TimeDelta::FromMicroseconds(13).InMicroseconds());
56 }
57
58
59 TEST(TimeJsTime) {
60 Time t = Time::FromJsTime(700000.3);
61 CHECK_EQ(700000.3, t.ToJsTime());
62 }
63
64
65 #if V8_OS_POSIX
66 TEST(TimeFromTimeVal) {
67 Time null;
68 CHECK(null.IsNull());
69 CHECK(null == Time::FromTimeval(null.ToTimeval()));
70 Time now = Time::Now();
71 CHECK(now == Time::FromTimeval(now.ToTimeval()));
72 Time now_sys = Time::NowFromSystemTime();
73 CHECK(now_sys == Time::FromTimeval(now_sys.ToTimeval()));
74 Time unix_epoch = Time::UnixEpoch();
75 CHECK(unix_epoch == Time::FromTimeval(unix_epoch.ToTimeval()));
76 Time max = Time::Max();
77 CHECK(max.IsMax());
78 CHECK(max == Time::FromTimeval(max.ToTimeval()));
79 }
80 #endif
81
82
83 #if V8_OS_WIN
84 TEST(TimeFromFiletime) {
85 Time null;
86 CHECK(null.IsNull());
87 CHECK(null == Time::FromFiletime(null.ToFiletime()));
88 Time now = Time::Now();
89 CHECK(now == Time::FromFiletime(now.ToFiletime()));
90 Time now_sys = Time::NowFromSystemTime();
91 CHECK(now_sys == Time::FromFiletime(now_sys.ToFiletime()));
92 Time unix_epoch = Time::UnixEpoch();
93 CHECK(unix_epoch == Time::FromFiletime(unix_epoch.ToFiletime()));
94 Time max = Time::Max();
95 CHECK(max.IsMax());
96 CHECK(max == Time::FromFiletime(max.ToFiletime()));
97 }
98 #endif
99
100
101 TEST(TimeTicksIsMonotonic) {
102 TimeTicks previous_normal_ticks;
103 TimeTicks previous_highres_ticks;
104 ElapsedTimer timer;
105 timer.Start();
106 while (!timer.HasExpired(TimeDelta::FromMilliseconds(100))) {
107 TimeTicks normal_ticks = TimeTicks::Now();
108 TimeTicks highres_ticks = TimeTicks::HighResNow();
109 CHECK_GE(normal_ticks, previous_normal_ticks);
110 CHECK_GE((normal_ticks - previous_normal_ticks).InMicroseconds(), 0);
111 CHECK_GE(highres_ticks, previous_highres_ticks);
112 CHECK_GE((highres_ticks - previous_highres_ticks).InMicroseconds(), 0);
113 previous_normal_ticks = normal_ticks;
114 previous_highres_ticks = highres_ticks;
115 }
116 }
OLDNEW
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698