blob: 2b3465478cc448b5d670f1ada39a163c6d18ac47 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/third_party/quic/platform/impl/quic_epoll_clock.h"
#include "net/third_party/quic/platform/api/quic_test.h"
#include "net/third_party/quic/test_tools/fake_epoll_server.h"
namespace quic {
namespace test {
class QuicEpollClockTest : public QuicTest {};
TEST_F(QuicEpollClockTest, ApproximateNowInUsec) {
FakeEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
epoll_server.set_now_in_usec(1000000);
EXPECT_EQ(1000000,
(clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds());
EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds());
EXPECT_EQ(1000000u, clock.WallNow().ToUNIXMicroseconds());
epoll_server.AdvanceBy(5);
EXPECT_EQ(1000005,
(clock.ApproximateNow() - QuicTime::Zero()).ToMicroseconds());
EXPECT_EQ(1u, clock.WallNow().ToUNIXSeconds());
EXPECT_EQ(1000005u, clock.WallNow().ToUNIXMicroseconds());
epoll_server.AdvanceBy(10 * 1000000);
EXPECT_EQ(11u, clock.WallNow().ToUNIXSeconds());
EXPECT_EQ(11000005u, clock.WallNow().ToUNIXMicroseconds());
}
TEST_F(QuicEpollClockTest, NowInUsec) {
FakeEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
epoll_server.set_now_in_usec(1000000);
EXPECT_EQ(1000000, (clock.Now() - QuicTime::Zero()).ToMicroseconds());
epoll_server.AdvanceBy(5);
EXPECT_EQ(1000005, (clock.Now() - QuicTime::Zero()).ToMicroseconds());
}
} // namespace test
} // namespace quic