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 { |
11 namespace tools { | 11 namespace tools { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 TEST(QuicEpollClockTest, ApproximateNowInUsec) { | 14 TEST(QuicEpollClockTest, ApproximateNowInUsec) { |
15 MockEpollServer epoll_server; | 15 MockEpollServer epoll_server; |
16 QuicEpollClock clock(&epoll_server); | 16 QuicEpollClock clock(&epoll_server); |
17 | 17 |
18 epoll_server.set_now_in_usec(1000000); | 18 epoll_server.set_now_in_usec(1000000); |
19 EXPECT_EQ(1000000, | 19 EXPECT_EQ(1000000, |
20 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); | 20 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); |
| 21 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); |
| 22 EXPECT_EQ(1000000u, clock.WallNow().ToUNIXMicroseconds()); |
21 | 23 |
22 epoll_server.AdvanceBy(5); | 24 epoll_server.AdvanceBy(5); |
23 EXPECT_EQ(1000005, | 25 EXPECT_EQ(1000005, |
24 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); | 26 clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds()); |
| 27 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); |
| 28 EXPECT_EQ(1000005u, clock.WallNow().ToUNIXMicroseconds()); |
| 29 |
| 30 epoll_server.AdvanceBy(10 * 1000000); |
| 31 EXPECT_EQ(11u, clock.WallNow().ToUNIXSeconds()); |
| 32 EXPECT_EQ(11000005u, clock.WallNow().ToUNIXMicroseconds()); |
25 } | 33 } |
26 | 34 |
27 TEST(QuicEpollClockTest, NowInUsec) { | 35 TEST(QuicEpollClockTest, NowInUsec) { |
28 MockEpollServer epoll_server; | 36 MockEpollServer epoll_server; |
29 QuicEpollClock clock(&epoll_server); | 37 QuicEpollClock clock(&epoll_server); |
30 | 38 |
31 epoll_server.set_now_in_usec(1000000); | 39 epoll_server.set_now_in_usec(1000000); |
32 EXPECT_EQ(1000000, | 40 EXPECT_EQ(1000000, |
33 clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); | 41 clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds()); |
34 | 42 |
(...skipping 13 matching lines...) Expand all Loading... |
48 // If end > start, then we can check now is between start and end. | 56 // If end > start, then we can check now is between start and end. |
49 if (end > start) { | 57 if (end > start) { |
50 EXPECT_LE(static_cast<uint64>(start.ToTimeT()), now.ToUNIXSeconds()); | 58 EXPECT_LE(static_cast<uint64>(start.ToTimeT()), now.ToUNIXSeconds()); |
51 EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64>(end.ToTimeT())); | 59 EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64>(end.ToTimeT())); |
52 } | 60 } |
53 } | 61 } |
54 | 62 |
55 } // namespace test | 63 } // namespace test |
56 } // namespace tools | 64 } // namespace tools |
57 } // namespace net | 65 } // namespace net |
OLD | NEW |