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 #include "net/tools/quic/quic_epoll_clock.h" | 5 #include "net/tools/quic/quic_epoll_clock.h" |
6 | 6 |
7 #include "net/tools/quic/test_tools/mock_epoll_server.h" | 7 #include "net/tools/quic/test_tools/mock_epoll_server.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 11 matching lines...) Expand all Loading... |
22 epoll_server.AdvanceBy(5); | 22 epoll_server.AdvanceBy(5); |
23 EXPECT_EQ(1000005, | 23 EXPECT_EQ(1000005, |
24 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); | 24 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); |
25 } | 25 } |
26 | 26 |
27 TEST(QuicEpollClockTest, NowInUsec) { | 27 TEST(QuicEpollClockTest, NowInUsec) { |
28 MockEpollServer epoll_server; | 28 MockEpollServer epoll_server; |
29 QuicEpollClock clock(&epoll_server); | 29 QuicEpollClock clock(&epoll_server); |
30 | 30 |
31 epoll_server.set_now_in_usec(1000000); | 31 epoll_server.set_now_in_usec(1000000); |
32 EXPECT_EQ(1000000, | 32 EXPECT_EQ(1000000, clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); |
33 clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); | |
34 | 33 |
35 epoll_server.AdvanceBy(5); | 34 epoll_server.AdvanceBy(5); |
36 EXPECT_EQ(1000005, | 35 EXPECT_EQ(1000005, clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); |
37 clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); | |
38 } | 36 } |
39 | 37 |
40 TEST(QuicEpollClockTest, WallNow) { | 38 TEST(QuicEpollClockTest, WallNow) { |
41 MockEpollServer epoll_server; | 39 MockEpollServer epoll_server; |
42 QuicEpollClock clock(&epoll_server); | 40 QuicEpollClock clock(&epoll_server); |
43 | 41 |
44 base::Time start = base::Time::Now(); | 42 base::Time start = base::Time::Now(); |
45 QuicWallTime now = clock.WallNow(); | 43 QuicWallTime now = clock.WallNow(); |
46 base::Time end = base::Time::Now(); | 44 base::Time end = base::Time::Now(); |
47 | 45 |
48 // If end > start, then we can check now is between start and end. | 46 // If end > start, then we can check now is between start and end. |
49 if (end > start) { | 47 if (end > start) { |
50 EXPECT_LE(static_cast<uint64>(start.ToTimeT()), now.ToUNIXSeconds()); | 48 EXPECT_LE(static_cast<uint64>(start.ToTimeT()), now.ToUNIXSeconds()); |
51 EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64>(end.ToTimeT())); | 49 EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64>(end.ToTimeT())); |
52 } | 50 } |
53 } | 51 } |
54 | 52 |
55 } // namespace test | 53 } // namespace test |
56 } // namespace tools | 54 } // namespace tools |
57 } // namespace net | 55 } // namespace net |
OLD | NEW |