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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « base/time/time.cc ('k') | base/trace_event/memory_dump_manager.h » ('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 <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 TimeDelta difference = delta - delta_thread; 708 TimeDelta difference = delta - delta_thread;
709 EXPECT_GE(difference.InMicroseconds(), 9000); 709 EXPECT_GE(difference.InMicroseconds(), 9000);
710 } 710 }
711 } 711 }
712 712
713 TEST(TimeTicks, NowFromSystemTraceTime) { 713 TEST(TimeTicks, NowFromSystemTraceTime) {
714 // Re-use HighRes test for now since clock properties are identical. 714 // Re-use HighRes test for now since clock properties are identical.
715 HighResClockTest(&TimeTicks::NowFromSystemTraceTime); 715 HighResClockTest(&TimeTicks::NowFromSystemTraceTime);
716 } 716 }
717 717
718 TEST(TimeTicks, SnappedToNextTickBasic) {
719 base::TimeTicks phase = base::TimeTicks::FromInternalValue(4000);
720 base::TimeDelta interval = base::TimeDelta::FromInternalValue(1000);
721 base::TimeTicks timestamp;
722
723 // Timestamp in previous interval.
724 timestamp = base::TimeTicks::FromInternalValue(3500);
725 EXPECT_EQ(4000,
726 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
727
728 // Timestamp in next interval.
729 timestamp = base::TimeTicks::FromInternalValue(4500);
730 EXPECT_EQ(5000,
731 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
732
733 // Timestamp multiple intervals before.
734 timestamp = base::TimeTicks::FromInternalValue(2500);
735 EXPECT_EQ(3000,
736 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
737
738 // Timestamp multiple intervals after.
739 timestamp = base::TimeTicks::FromInternalValue(6500);
740 EXPECT_EQ(7000,
741 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
742
743 // Timestamp on previous interval.
744 timestamp = base::TimeTicks::FromInternalValue(3000);
745 EXPECT_EQ(3000,
746 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
747
748 // Timestamp on next interval.
749 timestamp = base::TimeTicks::FromInternalValue(5000);
750 EXPECT_EQ(5000,
751 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
752
753 // Timestamp equal to phase.
754 timestamp = base::TimeTicks::FromInternalValue(4000);
755 EXPECT_EQ(4000,
756 timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
757 }
758
759 TEST(TimeTicks, SnappedToNextTickOverflow) {
760 // int(big_timestamp / interval) < 0, so this causes a crash if the number of
761 // intervals elapsed is attempted to be stored in an int.
762 base::TimeTicks phase = base::TimeTicks::FromInternalValue(0);
763 base::TimeDelta interval = base::TimeDelta::FromInternalValue(4000);
764 base::TimeTicks big_timestamp =
765 base::TimeTicks::FromInternalValue(8635916564000);
766
767 EXPECT_EQ(8635916564000,
768 big_timestamp.SnappedToNextTick(phase, interval).ToInternalValue());
769 EXPECT_EQ(8635916564000,
770 big_timestamp.SnappedToNextTick(big_timestamp, interval)
771 .ToInternalValue());
772 }
773
718 TEST(TimeDelta, FromAndIn) { 774 TEST(TimeDelta, FromAndIn) {
719 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48)); 775 EXPECT_TRUE(TimeDelta::FromDays(2) == TimeDelta::FromHours(48));
720 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180)); 776 EXPECT_TRUE(TimeDelta::FromHours(3) == TimeDelta::FromMinutes(180));
721 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120)); 777 EXPECT_TRUE(TimeDelta::FromMinutes(2) == TimeDelta::FromSeconds(120));
722 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000)); 778 EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
723 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) == 779 EXPECT_TRUE(TimeDelta::FromMilliseconds(2) ==
724 TimeDelta::FromMicroseconds(2000)); 780 TimeDelta::FromMicroseconds(2000));
725 EXPECT_TRUE(TimeDelta::FromSecondsD(2.3) == 781 EXPECT_TRUE(TimeDelta::FromSecondsD(2.3) ==
726 TimeDelta::FromMilliseconds(2300)); 782 TimeDelta::FromMilliseconds(2300));
727 EXPECT_TRUE(TimeDelta::FromMillisecondsD(2.5) == 783 EXPECT_TRUE(TimeDelta::FromMillisecondsD(2.5) ==
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 947
892 TEST(TimeTicksLogging, DoesNotMakeStreamBad) { 948 TEST(TimeTicksLogging, DoesNotMakeStreamBad) {
893 std::ostringstream oss; 949 std::ostringstream oss;
894 oss << TimeTicks(); 950 oss << TimeTicks();
895 EXPECT_TRUE(oss.good()); 951 EXPECT_TRUE(oss.good());
896 } 952 }
897 953
898 } // namespace 954 } // namespace
899 955
900 } // namespace base 956 } // namespace base
OLDNEW
« no previous file with comments | « base/time/time.cc ('k') | base/trace_event/memory_dump_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698