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

Side by Side Diff: base/time/time_unittest.cc

Issue 163413004: Add base::TimeDelta::Max(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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/time.cc ('k') | cc/debug/rasterize_and_record_benchmark.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/time.h" 5 #include "base/time/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/logging.h" 10 #include "base/logging.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // Should be 1970-01-01 00:00:01 1 millisecond. 474 // Should be 1970-01-01 00:00:01 1 millisecond.
475 EXPECT_EQ(kUnixEpochYear, exploded.year); 475 EXPECT_EQ(kUnixEpochYear, exploded.year);
476 EXPECT_EQ(1, exploded.month); 476 EXPECT_EQ(1, exploded.month);
477 EXPECT_EQ(1, exploded.day_of_month); 477 EXPECT_EQ(1, exploded.day_of_month);
478 EXPECT_EQ(0, exploded.hour); 478 EXPECT_EQ(0, exploded.hour);
479 EXPECT_EQ(0, exploded.minute); 479 EXPECT_EQ(0, exploded.minute);
480 EXPECT_EQ(1, exploded.second); 480 EXPECT_EQ(1, exploded.second);
481 EXPECT_EQ(1, exploded.millisecond); 481 EXPECT_EQ(1, exploded.millisecond);
482 } 482 }
483 483
484 TEST_F(TimeTest, TimeDeltaMax) {
485 TimeDelta max = TimeDelta::Max();
486 EXPECT_TRUE(max.is_max());
487 EXPECT_EQ(max, TimeDelta::Max());
488 EXPECT_GT(max, TimeDelta::FromDays(100 * 365));
489 EXPECT_GT(max, TimeDelta());
490 }
491
492 TEST_F(TimeTest, TimeDeltaMaxConversions) {
493 TimeDelta t = TimeDelta::Max();
494 EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue());
495
496 EXPECT_EQ(std::numeric_limits<int>::max(), t.InDays());
497 EXPECT_EQ(std::numeric_limits<int>::max(), t.InHours());
498 EXPECT_EQ(std::numeric_limits<int>::max(), t.InMinutes());
499 EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InSecondsF());
500 EXPECT_EQ(std::numeric_limits<int64>::max(), t.InSeconds());
501 EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InMillisecondsF());
502 EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMilliseconds());
503 EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMillisecondsRoundedUp());
504
505 t = TimeDelta::FromDays(std::numeric_limits<int>::max());
506 EXPECT_TRUE(t.is_max());
507
508 t = TimeDelta::FromHours(std::numeric_limits<int>::max());
509 EXPECT_TRUE(t.is_max());
510
511 t = TimeDelta::FromMinutes(std::numeric_limits<int>::max());
512 EXPECT_TRUE(t.is_max());
513
514 t = TimeDelta::FromSeconds(std::numeric_limits<int64>::max());
515 EXPECT_TRUE(t.is_max());
516
517 t = TimeDelta::FromMilliseconds(std::numeric_limits<int64>::max());
518 EXPECT_TRUE(t.is_max());
519
520 t = TimeDelta::FromMicroseconds(std::numeric_limits<int64>::max());
521 EXPECT_TRUE(t.is_max());
522 }
523
484 TEST_F(TimeTest, Max) { 524 TEST_F(TimeTest, Max) {
485 Time max = Time::Max(); 525 Time max = Time::Max();
486 EXPECT_TRUE(max.is_max()); 526 EXPECT_TRUE(max.is_max());
487 EXPECT_EQ(max, Time::Max()); 527 EXPECT_EQ(max, Time::Max());
488 EXPECT_GT(max, Time::Now()); 528 EXPECT_GT(max, Time::Now());
489 EXPECT_GT(max, Time()); 529 EXPECT_GT(max, Time());
490 } 530 }
491 531
492 TEST_F(TimeTest, MaxConversions) { 532 TEST_F(TimeTest, MaxConversions) {
493 Time t = Time::Max(); 533 Time t = Time::Max();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 exploded.minute = 0; 751 exploded.minute = 0;
712 exploded.second = 0; 752 exploded.second = 0;
713 exploded.millisecond = 0; 753 exploded.millisecond = 0;
714 Time t = Time::FromUTCExploded(exploded); 754 Time t = Time::FromUTCExploded(exploded);
715 // Unix 1970 epoch. 755 // Unix 1970 epoch.
716 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue()); 756 EXPECT_EQ(GG_INT64_C(11644473600000000), t.ToInternalValue());
717 757
718 // We can't test 1601 epoch, since the system time functions on Linux 758 // We can't test 1601 epoch, since the system time functions on Linux
719 // only compute years starting from 1900. 759 // only compute years starting from 1900.
720 } 760 }
OLDNEW
« no previous file with comments | « base/time/time.cc ('k') | cc/debug/rasterize_and_record_benchmark.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698