| 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/platform/impl/quic_epoll_clock.h" | 5 #include "net/tools/quic/platform/impl/quic_epoll_clock.h" |
| 6 | 6 |
| 7 #include "net/quic/platform/api/quic_test.h" |
| 7 #include "net/tools/quic/test_tools/mock_epoll_server.h" | 8 #include "net/tools/quic/test_tools/mock_epoll_server.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 namespace test { | 11 namespace test { |
| 12 | 12 |
| 13 TEST(QuicEpollClockTest, ApproximateNowInUsec) { | 13 class QuicEpollClockTest : public QuicTest {}; |
| 14 |
| 15 TEST_F(QuicEpollClockTest, ApproximateNowInUsec) { |
| 14 MockEpollServer epoll_server; | 16 MockEpollServer epoll_server; |
| 15 QuicEpollClock clock(&epoll_server); | 17 QuicEpollClock clock(&epoll_server); |
| 16 | 18 |
| 17 epoll_server.set_now_in_usec(1000000); | 19 epoll_server.set_now_in_usec(1000000); |
| 18 EXPECT_EQ(1000000, | 20 EXPECT_EQ(1000000, |
| 19 (clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds()); | 21 (clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds()); |
| 20 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); | 22 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); |
| 21 EXPECT_EQ(1000000u, clock.WallNow().ToUNIXMicroseconds()); | 23 EXPECT_EQ(1000000u, clock.WallNow().ToUNIXMicroseconds()); |
| 22 | 24 |
| 23 epoll_server.AdvanceBy(5); | 25 epoll_server.AdvanceBy(5); |
| 24 EXPECT_EQ(1000005, | 26 EXPECT_EQ(1000005, |
| 25 (clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds()); | 27 (clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds()); |
| 26 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); | 28 EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds()); |
| 27 EXPECT_EQ(1000005u, clock.WallNow().ToUNIXMicroseconds()); | 29 EXPECT_EQ(1000005u, clock.WallNow().ToUNIXMicroseconds()); |
| 28 | 30 |
| 29 epoll_server.AdvanceBy(10 * 1000000); | 31 epoll_server.AdvanceBy(10 * 1000000); |
| 30 EXPECT_EQ(11u, clock.WallNow().ToUNIXSeconds()); | 32 EXPECT_EQ(11u, clock.WallNow().ToUNIXSeconds()); |
| 31 EXPECT_EQ(11000005u, clock.WallNow().ToUNIXMicroseconds()); | 33 EXPECT_EQ(11000005u, clock.WallNow().ToUNIXMicroseconds()); |
| 32 } | 34 } |
| 33 | 35 |
| 34 TEST(QuicEpollClockTest, NowInUsec) { | 36 TEST_F(QuicEpollClockTest, NowInUsec) { |
| 35 MockEpollServer epoll_server; | 37 MockEpollServer epoll_server; |
| 36 QuicEpollClock clock(&epoll_server); | 38 QuicEpollClock clock(&epoll_server); |
| 37 | 39 |
| 38 epoll_server.set_now_in_usec(1000000); | 40 epoll_server.set_now_in_usec(1000000); |
| 39 EXPECT_EQ(1000000, (clock.Now() - QuicTime::Zero()).ToMicroseconds()); | 41 EXPECT_EQ(1000000, (clock.Now() - QuicTime::Zero()).ToMicroseconds()); |
| 40 | 42 |
| 41 epoll_server.AdvanceBy(5); | 43 epoll_server.AdvanceBy(5); |
| 42 EXPECT_EQ(1000005, (clock.Now() - QuicTime::Zero()).ToMicroseconds()); | 44 EXPECT_EQ(1000005, (clock.Now() - QuicTime::Zero()).ToMicroseconds()); |
| 43 } | 45 } |
| 44 | 46 |
| 45 } // namespace test | 47 } // namespace test |
| 46 } // namespace net | 48 } // namespace net |
| OLD | NEW |