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

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: Windows. :( 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
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());
488 }
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 EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeVal().tv_sec);
Mark Mentovai 2012/09/06 16:10:49 Don’t call ToTimeVal twice.
Mike West 2012/09/06 19:51:16 Done.
513 EXPECT_EQ(static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1,
514 t.ToTimeVal().tv_usec);
515 #endif
516
517 #if defined(OS_MACOSX)
518 t = Time::FromCFAbsoluteTime(std::numeric_limits<CFAbsoluteTime>::max());
519 EXPECT_TRUE(t.is_max());
520 EXPECT_EQ(std::numeric_limits<CFAbsoluteTime>::max(), t.ToCFAbsoluteTime());
521 #endif
522
523 #if defined(OS_WIN)
524 FILETIME ftime;
525 ftime.dwHighDateTime = std::numeric_limits<int>::max();
526 ftime.dwLowDateTime = std::numeric_limits<int>::max();
527 t = Time::FromFileTime(ftime);
528 EXPECT_TRUE(t.is_max());
529 EXPECT_EQ(std::numeric_limits<int>::max(), t.ToFileTime().dwHighDateTime);
Mark Mentovai 2012/09/06 16:10:49 And don’t call ToFileTime twice.
Mike West 2012/09/06 19:51:16 Done.
530 EXPECT_EQ(std::numeric_limits<int>::max(), t.ToFileTime().dwLowDateTime);
531 #endif
486 } 532 }
487 533
488 TEST(TimeTicks, Deltas) { 534 TEST(TimeTicks, Deltas) {
489 for (int index = 0; index < 50; index++) { 535 for (int index = 0; index < 50; index++) {
490 TimeTicks ticks_start = TimeTicks::Now(); 536 TimeTicks ticks_start = TimeTicks::Now();
491 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 537 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
492 TimeTicks ticks_stop = TimeTicks::Now(); 538 TimeTicks ticks_stop = TimeTicks::Now();
493 TimeDelta delta = ticks_stop - ticks_start; 539 TimeDelta delta = ticks_stop - ticks_start;
494 // Note: Although we asked for a 10ms sleep, if the 540 // Note: Although we asked for a 10ms sleep, if the
495 // time clock has a finer granularity than the Sleep() 541 // time clock has a finer granularity than the Sleep()
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 exploded.minute = 0; 657 exploded.minute = 0;
612 exploded.second = 0; 658 exploded.second = 0;
613 exploded.millisecond = 0; 659 exploded.millisecond = 0;
614 Time t = Time::FromUTCExploded(exploded); 660 Time t = Time::FromUTCExploded(exploded);
615 // Unix 1970 epoch. 661 // Unix 1970 epoch.
616 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 662 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
617 663
618 // We can't test 1601 epoch, since the system time functions on Linux 664 // We can't test 1601 epoch, since the system time functions on Linux
619 // only compute years starting from 1900. 665 // only compute years starting from 1900.
620 } 666 }
OLDNEW
« base/time.cc ('K') | « base/time_posix.cc ('k') | base/time_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698