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 // Test of classes in tracked_time.cc | 5 // Test of classes in tracked_time.cc |
6 | 6 |
7 #include "base/profiler/tracked_time.h" | 7 #include "base/profiler/tracked_time.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 Duration::FromMilliseconds(kSomeMilliseconds); | 21 Duration::FromMilliseconds(kSomeMilliseconds); |
22 EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds()); | 22 EXPECT_EQ(kSomeMilliseconds, (some - TrackedTime()).InMilliseconds()); |
23 EXPECT_FALSE(some.is_null()); | 23 EXPECT_FALSE(some.is_null()); |
24 | 24 |
25 // Now create a big time, to check that it is wrapped modulo 2^32. | 25 // Now create a big time, to check that it is wrapped modulo 2^32. |
26 base::TimeTicks big = base::TimeTicks() + | 26 base::TimeTicks big = base::TimeTicks() + |
27 base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds); | 27 base::TimeDelta::FromMilliseconds(kReallyBigMilliseconds); |
28 EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds()); | 28 EXPECT_EQ(kReallyBigMilliseconds, (big - base::TimeTicks()).InMilliseconds()); |
29 | 29 |
30 TrackedTime wrapped_big(big); | 30 TrackedTime wrapped_big(big); |
31 #if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS) | |
32 // Expect wrapping at 32 bits. | 31 // Expect wrapping at 32 bits. |
33 EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds()); | 32 EXPECT_EQ(kSomeMilliseconds, (wrapped_big - TrackedTime()).InMilliseconds()); |
34 #else // !USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS) | |
35 // Expect no wrapping at 32 bits. | |
36 EXPECT_EQ(kReallyBigMilliseconds, | |
37 (wrapped_big - TrackedTime()).InMilliseconds()); | |
38 #endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS) | |
39 } | 33 } |
40 | 34 |
41 TEST(TrackedTimeTest, TrackedTimerDuration) { | 35 TEST(TrackedTimeTest, TrackedTimerDuration) { |
42 int kFirstMilliseconds = 793; | 36 int kFirstMilliseconds = 793; |
43 int kSecondMilliseconds = 14889; | 37 int kSecondMilliseconds = 14889; |
44 | 38 |
45 Duration first = Duration::FromMilliseconds(kFirstMilliseconds); | 39 Duration first = Duration::FromMilliseconds(kFirstMilliseconds); |
46 Duration second = Duration::FromMilliseconds(kSecondMilliseconds); | 40 Duration second = Duration::FromMilliseconds(kSecondMilliseconds); |
47 | 41 |
48 EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds()); | 42 EXPECT_EQ(kFirstMilliseconds, first.InMilliseconds()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 EXPECT_FALSE(ticks_after.is_null()); | 101 EXPECT_FALSE(ticks_after.is_null()); |
108 | 102 |
109 // Now make sure that we bracketed our tracked time nicely. | 103 // Now make sure that we bracketed our tracked time nicely. |
110 Duration before = now - TrackedTime(ticks_before); | 104 Duration before = now - TrackedTime(ticks_before); |
111 EXPECT_LE(0, before.InMilliseconds()); | 105 EXPECT_LE(0, before.InMilliseconds()); |
112 Duration after = now - TrackedTime(ticks_after); | 106 Duration after = now - TrackedTime(ticks_after); |
113 EXPECT_GE(0, after.InMilliseconds()); | 107 EXPECT_GE(0, after.InMilliseconds()); |
114 } | 108 } |
115 | 109 |
116 } // namespace tracked_objects | 110 } // namespace tracked_objects |
OLD | NEW |