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

Side by Side Diff: base/time_unittest.cc

Issue 4092: Change to Hi Res timers on Windows.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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 | « base/time_posix.cc ('k') | base/time_unittest_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium 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 <time.h> 5 #include <time.h>
6 6
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 TEST(Time, LocalMidnight) { 79 TEST(Time, LocalMidnight) {
80 Time::Exploded exploded; 80 Time::Exploded exploded;
81 Time::Now().LocalMidnight().LocalExplode(&exploded); 81 Time::Now().LocalMidnight().LocalExplode(&exploded);
82 EXPECT_EQ(0, exploded.hour); 82 EXPECT_EQ(0, exploded.hour);
83 EXPECT_EQ(0, exploded.minute); 83 EXPECT_EQ(0, exploded.minute);
84 EXPECT_EQ(0, exploded.second); 84 EXPECT_EQ(0, exploded.second);
85 EXPECT_EQ(0, exploded.millisecond); 85 EXPECT_EQ(0, exploded.millisecond);
86 } 86 }
87 87
88 TEST(TimeTicks, Deltas) { 88 TEST(TimeTicks, Deltas) {
89 TimeTicks ticks_start = TimeTicks::Now(); 89 for (int index = 0; index < 500; index++) {
90 PlatformThread::Sleep(10); 90 TimeTicks ticks_start = TimeTicks::Now();
91 TimeTicks ticks_stop = TimeTicks::Now(); 91 PlatformThread::Sleep(10);
92 TimeDelta delta = ticks_stop - ticks_start; 92 TimeTicks ticks_stop = TimeTicks::Now();
93 EXPECT_GE(delta.InMilliseconds(), 10); 93 TimeDelta delta = ticks_stop - ticks_start;
94 EXPECT_GE(delta.InMicroseconds(), 10000); 94 // Note: Although we asked for a 10ms sleep, if the
95 EXPECT_EQ(delta.InSeconds(), 0); 95 // time clock has a finer granularity than the Sleep()
96 // clock, it is quite possible to wakeup early. Here
97 // is how that works:
98 // Time(ms timer) Time(us timer)
99 // 5 5010
100 // 6 6010
101 // 7 7010
102 // 8 8010
103 // 9 9000
104 // Elapsed 4ms 3990us
105 //
106 // Unfortunately, our InMilliseconds() function truncates
107 // rather than rounds. We should consider fixing this
108 // so that our averages come out better.
109 EXPECT_GE(delta.InMilliseconds(), 9);
110 EXPECT_GE(delta.InMicroseconds(), 9000);
111 EXPECT_EQ(delta.InSeconds(), 0);
112 }
96 } 113 }
97 114
98 TEST(TimeTicks, UnreliableHighResNow) { 115 TEST(TimeTicks, HighResNow) {
99 TimeTicks ticks_start = TimeTicks::UnreliableHighResNow(); 116 TimeTicks ticks_start = TimeTicks::HighResNow();
100 PlatformThread::Sleep(10); 117 PlatformThread::Sleep(10);
101 TimeTicks ticks_stop = TimeTicks::UnreliableHighResNow(); 118 TimeTicks ticks_stop = TimeTicks::HighResNow();
102 TimeDelta delta = ticks_stop - ticks_start; 119 TimeDelta delta = ticks_stop - ticks_start;
103 EXPECT_GE(delta.InMilliseconds(), 10); 120 EXPECT_GE(delta.InMicroseconds(), 9000);
104 } 121 }
105 122
106 TEST(TimeDelta, FromAndIn) { 123 TEST(TimeDelta, FromAndIn) {
107 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48)); 124 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
108 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180)); 125 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
109 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120)); 126 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
110 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000)); 127 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
111 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) == 128 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) ==
112 TimeDelta::FromMicroseconds(2000)); 129 TimeDelta::FromMicroseconds(2000));
113 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); 130 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays());
114 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); 131 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours());
115 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); 132 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes());
116 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds()); 133 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds());
117 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); 134 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
118 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds()); 135 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds());
119 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); 136 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
120 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds()); 137 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
121 } 138 }
OLDNEW
« no previous file with comments | « base/time_posix.cc ('k') | base/time_unittest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698