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

Side by Side Diff: base/time_unittest.cc

Issue 10916089: Fixing Time::Max()'s behavior with Time::ToTimeT() and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DWORD. Created 8 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_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) 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ(kUnixEpochYear, exploded.year); 473 EXPECT_EQ(kUnixEpochYear, exploded.year);
474 EXPECT_EQ(1, exploded.month); 474 EXPECT_EQ(1, exploded.month);
475 EXPECT_EQ(1, exploded.day_of_month); 475 EXPECT_EQ(1, exploded.day_of_month);
476 EXPECT_EQ(0, exploded.hour); 476 EXPECT_EQ(0, exploded.hour);
477 EXPECT_EQ(0, exploded.minute); 477 EXPECT_EQ(0, exploded.minute);
478 EXPECT_EQ(1, exploded.second); 478 EXPECT_EQ(1, exploded.second);
479 EXPECT_EQ(1, exploded.millisecond); 479 EXPECT_EQ(1, exploded.millisecond);
480 } 480 }
481 481
482 TEST_F(TimeTest, Max) { 482 TEST_F(TimeTest, Max) {
483 EXPECT_EQ(base::Time::Max(), base::Time::Max()); 483 Time max = Time::Max();
484 EXPECT_GT(base::Time::Max(), base::Time::Now()); 484 EXPECT_TRUE(max.is_max());
485 EXPECT_GT(base::Time::Max(), base::Time()); 485 EXPECT_EQ(max, Time::Max());
486 EXPECT_GT(max, Time::Now());
487 EXPECT_GT(max, Time());
486 } 488 }
487 489
490 TEST_F(TimeTest, MaxConversions) {
491 Time t = Time::Max();
492 EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue());
493
494 t = Time::FromDoubleT(std::numeric_limits<double>::max());
495 EXPECT_TRUE(t.is_max());
496 EXPECT_EQ(std::numeric_limits<double>::max(), t.ToDoubleT());
497
498 t = Time::FromJsTime(std::numeric_limits<double>::max());
499 EXPECT_TRUE(t.is_max());
500 EXPECT_EQ(std::numeric_limits<double>::max(), t.ToJsTime());
501
502 t = Time::FromTimeT(std::numeric_limits<time_t>::max());
503 EXPECT_TRUE(t.is_max());
504 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT());
505
506 #if defined(OS_POSIX)
507 struct timeval tval;
508 tval.tv_sec = std::numeric_limits<time_t>::max();
509 tval.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1;
510 t = Time::FromTimeVal(tval);
511 EXPECT_TRUE(t.is_max());
512 tval = t.ToTimeVal();
513 EXPECT_EQ(std::numeric_limits<time_t>::max(), tval.tv_sec);
514 EXPECT_EQ(static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1,
515 tval.tv_usec);
516 #endif
517
518 #if defined(OS_MACOSX)
519 t = Time::FromCFAbsoluteTime(std::numeric_limits<CFAbsoluteTime>::max());
520 EXPECT_TRUE(t.is_max());
521 EXPECT_EQ(std::numeric_limits<CFAbsoluteTime>::max(), t.ToCFAbsoluteTime());
522 #endif
523
524 #if defined(OS_WIN)
525 FILETIME ftime;
526 ftime.dwHighDateTime = std::numeric_limits<DWORD>::max();
527 ftime.dwLowDateTime = std::numeric_limits<DWORD>::max();
528 t = Time::FromFileTime(ftime);
529 EXPECT_TRUE(t.is_max());
530 ftime = t.ToFileTime();
531 EXPECT_EQ(std::numeric_limits<DWORD>::max(), ftime.dwHighDateTime);
532 EXPECT_EQ(std::numeric_limits<DWORD>::max(), ftime.dwLowDateTime);
533 #endif
534 }
535
536 #if defined(OS_MACOSX)
537 TEST_F(TimeTest, TimeTOverflow) {
538 Time t = Time::FromInternalValue(std::numeric_limits<int64>::max() - 1);
539 EXPECT_FALSE(t.is_max());
540 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT());
541 }
542 #endif
543
488 TEST(TimeTicks, Deltas) { 544 TEST(TimeTicks, Deltas) {
489 for (int index = 0; index < 50; index++) { 545 for (int index = 0; index < 50; index++) {
490 TimeTicks ticks_start = TimeTicks::Now(); 546 TimeTicks ticks_start = TimeTicks::Now();
491 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 547 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
492 TimeTicks ticks_stop = TimeTicks::Now(); 548 TimeTicks ticks_stop = TimeTicks::Now();
493 TimeDelta delta = ticks_stop - ticks_start; 549 TimeDelta delta = ticks_stop - ticks_start;
494 // Note: Although we asked for a 10ms sleep, if the 550 // Note: Although we asked for a 10ms sleep, if the
495 // time clock has a finer granularity than the Sleep() 551 // time clock has a finer granularity than the Sleep()
496 // clock, it is quite possible to wakeup early. Here 552 // clock, it is quite possible to wakeup early. Here
497 // is how that works: 553 // is how that works:
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 exploded.minute = 0; 667 exploded.minute = 0;
612 exploded.second = 0; 668 exploded.second = 0;
613 exploded.millisecond = 0; 669 exploded.millisecond = 0;
614 Time t = Time::FromUTCExploded(exploded); 670 Time t = Time::FromUTCExploded(exploded);
615 // Unix 1970 epoch. 671 // Unix 1970 epoch.
616 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 672 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
617 673
618 // We can't test 1601 epoch, since the system time functions on Linux 674 // We can't test 1601 epoch, since the system time functions on Linux
619 // only compute years starting from 1900. 675 // only compute years starting from 1900.
620 } 676 }
OLDNEW
« no previous file with comments | « base/time_posix.cc ('k') | base/time_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698