OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/threading/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" |
11 | 11 |
12 using base::Time; | 12 using base::Time; |
13 using base::TimeDelta; | 13 using base::TimeDelta; |
14 using base::TimeTicks; | 14 using base::TimeTicks; |
15 | 15 |
16 // Test conversions to/from time_t and exploding/unexploding. | 16 // Test conversions to/from time_t and exploding/unexploding. |
17 TEST(Time, TimeT) { | 17 TEST(Time, TimeT) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 Time::Now().LocalMidnight().LocalExplode(&exploded); | 99 Time::Now().LocalMidnight().LocalExplode(&exploded); |
100 EXPECT_EQ(0, exploded.hour); | 100 EXPECT_EQ(0, exploded.hour); |
101 EXPECT_EQ(0, exploded.minute); | 101 EXPECT_EQ(0, exploded.minute); |
102 EXPECT_EQ(0, exploded.second); | 102 EXPECT_EQ(0, exploded.second); |
103 EXPECT_EQ(0, exploded.millisecond); | 103 EXPECT_EQ(0, exploded.millisecond); |
104 } | 104 } |
105 | 105 |
106 TEST(TimeTicks, Deltas) { | 106 TEST(TimeTicks, Deltas) { |
107 for (int index = 0; index < 50; index++) { | 107 for (int index = 0; index < 50; index++) { |
108 TimeTicks ticks_start = TimeTicks::Now(); | 108 TimeTicks ticks_start = TimeTicks::Now(); |
109 PlatformThread::Sleep(10); | 109 base::PlatformThread::Sleep(10); |
110 TimeTicks ticks_stop = TimeTicks::Now(); | 110 TimeTicks ticks_stop = TimeTicks::Now(); |
111 TimeDelta delta = ticks_stop - ticks_start; | 111 TimeDelta delta = ticks_stop - ticks_start; |
112 // Note: Although we asked for a 10ms sleep, if the | 112 // Note: Although we asked for a 10ms sleep, if the |
113 // time clock has a finer granularity than the Sleep() | 113 // time clock has a finer granularity than the Sleep() |
114 // clock, it is quite possible to wakeup early. Here | 114 // clock, it is quite possible to wakeup early. Here |
115 // is how that works: | 115 // is how that works: |
116 // Time(ms timer) Time(us timer) | 116 // Time(ms timer) Time(us timer) |
117 // 5 5010 | 117 // 5 5010 |
118 // 6 6010 | 118 // 6 6010 |
119 // 7 7010 | 119 // 7 7010 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 exploded.minute = 0; | 220 exploded.minute = 0; |
221 exploded.second = 0; | 221 exploded.second = 0; |
222 exploded.millisecond = 0; | 222 exploded.millisecond = 0; |
223 Time t = Time::FromUTCExploded(exploded); | 223 Time t = Time::FromUTCExploded(exploded); |
224 // Unix 1970 epoch. | 224 // Unix 1970 epoch. |
225 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); | 225 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); |
226 | 226 |
227 // We can't test 1601 epoch, since the system time functions on Linux | 227 // We can't test 1601 epoch, since the system time functions on Linux |
228 // only compute years starting from 1900. | 228 // only compute years starting from 1900. |
229 } | 229 } |
OLD | NEW |