xref: /aosp_15_r20/external/cronet/net/quic/platform/impl/quic_chromium_clock_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/quic/platform/impl/quic_chromium_clock.h"
6 
7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace quic::test {
11 
TEST(QuicChromiumClockTest,Now)12 TEST(QuicChromiumClockTest, Now) {
13   QuicChromiumClock clock;
14 
15   QuicTime start = clock.Now();
16   QuicTime now = clock.ApproximateNow();
17   QuicTime end = clock.Now();
18 
19   EXPECT_LE(start, now);
20   EXPECT_LE(now, end);
21 }
22 
TEST(QuicChromiumClockTest,WallNow)23 TEST(QuicChromiumClockTest, WallNow) {
24   QuicChromiumClock clock;
25 
26   base::Time start = base::Time::Now();
27   QuicWallTime now = clock.WallNow();
28   base::Time end = base::Time::Now();
29 
30   // If end > start, then we can check now is between start and end.
31   if (end > start) {
32     EXPECT_LE(static_cast<uint64_t>(start.ToTimeT()), now.ToUNIXSeconds());
33     EXPECT_LE(now.ToUNIXSeconds(), static_cast<uint64_t>(end.ToTimeT()));
34   }
35 }
36 
37 }  // namespace quic::test
38