summaryrefslogtreecommitdiff
path: root/chromium/net/tools/quic/quic_epoll_clock_test.cc
blob: c774d0adba2bf58a6326b045da4d342405d62efa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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/tools/quic/quic_epoll_clock.h"

#include "net/tools/quic/test_tools/mock_epoll_server.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace net {
namespace tools {
namespace test {

TEST(QuicEpollClockTest, ApproximateNowInUsec) {
  MockEpollServer epoll_server;
  QuicEpollClock clock(&epoll_server);

  epoll_server.set_now_in_usec(1000000);
  EXPECT_EQ(1000000,
            clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds());

  epoll_server.AdvanceBy(5);
  EXPECT_EQ(1000005,
            clock.ApproximateNow().Subtract(QuicTime::Zero()).ToMicroseconds());
}

TEST(QuicEpollClockTest, NowInUsec) {
  MockEpollServer epoll_server;
  QuicEpollClock clock(&epoll_server);

  epoll_server.set_now_in_usec(1000000);
  EXPECT_EQ(1000000,
            clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds());

  epoll_server.AdvanceBy(5);
  EXPECT_EQ(1000005,
            clock.Now().Subtract(QuicTime::Zero()).ToMicroseconds());
}

TEST(QuicClockTest, WallNow) {
  MockEpollServer epoll_server;
  QuicEpollClock clock(&epoll_server);

  base::Time start = base::Time::Now();
  QuicWallTime now = clock.WallNow();
  base::Time end = base::Time::Now();

  // If end > start, then we can check now is between start and end.
  if (end > start) {
    EXPECT_LE(static_cast<uint64>(start.ToTimeT()), now.ToUNIXSeconds());
    EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64>(end.ToTimeT()));
  }
}

}  // namespace test
}  // namespace tools
}  // namespace net