| OLD | NEW |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); | 135 EXPECT_EQ(13, TimeDelta::FromDays(13).InDays()); |
| 136 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); | 136 EXPECT_EQ(13, TimeDelta::FromHours(13).InHours()); |
| 137 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); | 137 EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes()); |
| 138 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds()); | 138 EXPECT_EQ(13, TimeDelta::FromSeconds(13).InSeconds()); |
| 139 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); | 139 EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF()); |
| 140 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds()); | 140 EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds()); |
| 141 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); | 141 EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF()); |
| 142 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds()); | 142 EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 #if defined(OS_POSIX) |
| 146 TEST(TimeDelta, TimeSpecConversion) { |
| 147 struct timespec result = TimeDelta::FromSeconds(0).ToTimeSpec(); |
| 148 EXPECT_EQ(result.tv_sec, 0); |
| 149 EXPECT_EQ(result.tv_nsec, 0); |
| 150 |
| 151 result = TimeDelta::FromSeconds(1).ToTimeSpec(); |
| 152 EXPECT_EQ(result.tv_sec, 1); |
| 153 EXPECT_EQ(result.tv_nsec, 0); |
| 154 |
| 155 result = TimeDelta::FromMicroseconds(1).ToTimeSpec(); |
| 156 EXPECT_EQ(result.tv_sec, 0); |
| 157 EXPECT_EQ(result.tv_nsec, 1000); |
| 158 |
| 159 result = TimeDelta::FromMicroseconds( |
| 160 Time::kMicrosecondsPerSecond + 1).ToTimeSpec(); |
| 161 EXPECT_EQ(result.tv_sec, 1); |
| 162 EXPECT_EQ(result.tv_nsec, 1000); |
| 163 } |
| 164 #endif // OS_POSIX |
| 165 |
| 145 // Our internal time format is serialized in things like databases, so it's | 166 // Our internal time format is serialized in things like databases, so it's |
| 146 // important that it's consistent across all our platforms. We use the 1601 | 167 // important that it's consistent across all our platforms. We use the 1601 |
| 147 // Windows epoch as the internal format across all platforms. | 168 // Windows epoch as the internal format across all platforms. |
| 148 TEST(TimeDelta, WindowsEpoch) { | 169 TEST(TimeDelta, WindowsEpoch) { |
| 149 Time::Exploded exploded; | 170 Time::Exploded exploded; |
| 150 exploded.year = 1970; | 171 exploded.year = 1970; |
| 151 exploded.month = 1; | 172 exploded.month = 1; |
| 152 exploded.day_of_week = 0; // Should be unusued. | 173 exploded.day_of_week = 0; // Should be unusued. |
| 153 exploded.day_of_month = 1; | 174 exploded.day_of_month = 1; |
| 154 exploded.hour = 0; | 175 exploded.hour = 0; |
| 155 exploded.minute = 0; | 176 exploded.minute = 0; |
| 156 exploded.second = 0; | 177 exploded.second = 0; |
| 157 exploded.millisecond = 0; | 178 exploded.millisecond = 0; |
| 158 Time t = Time::FromUTCExploded(exploded); | 179 Time t = Time::FromUTCExploded(exploded); |
| 159 // Unix 1970 epoch. | 180 // Unix 1970 epoch. |
| 160 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); | 181 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); |
| 161 | 182 |
| 162 // We can't test 1601 epoch, since the system time functions on Linux | 183 // We can't test 1601 epoch, since the system time functions on Linux |
| 163 // only compute years starting from 1900. | 184 // only compute years starting from 1900. |
| 164 } | 185 } |
| OLD | NEW |