| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/time.h" | 5 #include "base/time.h" |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 EXPECT_EQ(epoch, Time::UnixEpoch()); | 94 EXPECT_EQ(epoch, Time::UnixEpoch()); |
| 95 Time t = Time::FromJsTime(700000.3); | 95 Time t = Time::FromJsTime(700000.3); |
| 96 EXPECT_EQ(700.0003, t.ToDoubleT()); | 96 EXPECT_EQ(700.0003, t.ToDoubleT()); |
| 97 t = Time::FromDoubleT(800.73); | 97 t = Time::FromDoubleT(800.73); |
| 98 EXPECT_EQ(800730.0, t.ToJsTime()); | 98 EXPECT_EQ(800730.0, t.ToJsTime()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 #if defined(OS_POSIX) | 101 #if defined(OS_POSIX) |
| 102 TEST_F(TimeTest, FromTimeVal) { | 102 TEST_F(TimeTest, FromTimeVal) { |
| 103 Time now = Time::Now(); | 103 Time now = Time::Now(); |
| 104 Time also_now = Time::FromTimeVal(now.ToTimeVal()); | 104 timespec ts = now.ToTimeSpec(); |
| 105 timeval tv; |
| 106 tv.tv_sec = ts.tv_sec; |
| 107 tv.tv_usec = ts.tv_nsec / 1000; |
| 108 Time also_now = Time::FromTimeVal(tv); |
| 105 EXPECT_EQ(now, also_now); | 109 EXPECT_EQ(now, also_now); |
| 106 } | 110 } |
| 107 #endif // OS_POSIX | 111 #endif // OS_POSIX |
| 108 | 112 |
| 109 TEST_F(TimeTest, FromExplodedWithMilliseconds) { | 113 TEST_F(TimeTest, FromExplodedWithMilliseconds) { |
| 110 // Some platform implementations of FromExploded are liable to drop | 114 // Some platform implementations of FromExploded are liable to drop |
| 111 // milliseconds if we aren't careful. | 115 // milliseconds if we aren't careful. |
| 112 Time now = Time::NowFromSystemTime(); | 116 Time now = Time::NowFromSystemTime(); |
| 113 Time::Exploded exploded1 = {0}; | 117 Time::Exploded exploded1 = {0}; |
| 114 now.UTCExplode(&exploded1); | 118 now.UTCExplode(&exploded1); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 501 |
| 498 t = Time::FromJsTime(std::numeric_limits<double>::max()); | 502 t = Time::FromJsTime(std::numeric_limits<double>::max()); |
| 499 EXPECT_TRUE(t.is_max()); | 503 EXPECT_TRUE(t.is_max()); |
| 500 EXPECT_EQ(std::numeric_limits<double>::max(), t.ToJsTime()); | 504 EXPECT_EQ(std::numeric_limits<double>::max(), t.ToJsTime()); |
| 501 | 505 |
| 502 t = Time::FromTimeT(std::numeric_limits<time_t>::max()); | 506 t = Time::FromTimeT(std::numeric_limits<time_t>::max()); |
| 503 EXPECT_TRUE(t.is_max()); | 507 EXPECT_TRUE(t.is_max()); |
| 504 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT()); | 508 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT()); |
| 505 | 509 |
| 506 #if defined(OS_POSIX) | 510 #if defined(OS_POSIX) |
| 507 struct timeval tval; | 511 timeval tval; |
| 508 tval.tv_sec = std::numeric_limits<time_t>::max(); | 512 tval.tv_sec = std::numeric_limits<time_t>::max(); |
| 509 tval.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 513 tval.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 510 t = Time::FromTimeVal(tval); | 514 t = Time::FromTimeVal(tval); |
| 511 EXPECT_TRUE(t.is_max()); | 515 EXPECT_TRUE(t.is_max()); |
| 512 tval = t.ToTimeVal(); | 516 timespec tspec = t.ToTimeSpec(); |
| 513 EXPECT_EQ(std::numeric_limits<time_t>::max(), tval.tv_sec); | 517 EXPECT_EQ(std::numeric_limits<time_t>::max(), tspec.tv_sec); |
| 514 EXPECT_EQ(static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1, | 518 EXPECT_EQ(static_cast<long>(Time::kNanosecondsPerSecond) - 1, |
| 515 tval.tv_usec); | 519 tspec.tv_nsec); |
| 516 #endif | 520 #endif |
| 517 | 521 |
| 518 #if defined(OS_MACOSX) | 522 #if defined(OS_MACOSX) |
| 519 t = Time::FromCFAbsoluteTime(std::numeric_limits<CFAbsoluteTime>::max()); | 523 t = Time::FromCFAbsoluteTime(std::numeric_limits<CFAbsoluteTime>::max()); |
| 520 EXPECT_TRUE(t.is_max()); | 524 EXPECT_TRUE(t.is_max()); |
| 521 EXPECT_EQ(std::numeric_limits<CFAbsoluteTime>::max(), t.ToCFAbsoluteTime()); | 525 EXPECT_EQ(std::numeric_limits<CFAbsoluteTime>::max(), t.ToCFAbsoluteTime()); |
| 522 #endif | 526 #endif |
| 523 | 527 |
| 524 #if defined(OS_WIN) | 528 #if defined(OS_WIN) |
| 525 FILETIME ftime; | 529 FILETIME ftime; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 exploded.minute = 0; | 671 exploded.minute = 0; |
| 668 exploded.second = 0; | 672 exploded.second = 0; |
| 669 exploded.millisecond = 0; | 673 exploded.millisecond = 0; |
| 670 Time t = Time::FromUTCExploded(exploded); | 674 Time t = Time::FromUTCExploded(exploded); |
| 671 // Unix 1970 epoch. | 675 // Unix 1970 epoch. |
| 672 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); | 676 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); |
| 673 | 677 |
| 674 // We can't test 1601 epoch, since the system time functions on Linux | 678 // We can't test 1601 epoch, since the system time functions on Linux |
| 675 // only compute years starting from 1900. | 679 // only compute years starting from 1900. |
| 676 } | 680 } |
| OLD | NEW |