blob: f7b0ed7a47fce4bf14645f1a7dd8c6c970d25f18 [file] [log] [blame]
stefan@webrtc.orgb8e7f4c2013-04-12 11:56:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "system_wrappers/include/clock.h"
stefan@webrtc.orgb8e7f4c2013-04-12 11:56:23 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "test/gtest.h"
stefan@webrtc.orgb8e7f4c2013-04-12 11:56:23 +000014
15namespace webrtc {
16
17TEST(ClockTest, NtpTime) {
18 Clock* clock = Clock::GetRealTimeClock();
skvladde3f8442016-10-05 01:55:04 -070019
20 // To ensure the test runs correctly even on a heavily loaded system, do not
21 // compare the seconds/fractions and millisecond values directly. Instead,
22 // we check that the NTP time is between the "milliseconds" values returned
23 // right before and right after the call.
24 // The comparison includes 1 ms of margin to account for the rounding error in
25 // the conversion.
26 int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds();
danilchap42287842017-02-20 06:40:18 -080027 NtpTime ntp_time = clock->CurrentNtpTime();
skvladde3f8442016-10-05 01:55:04 -070028 int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds();
29 EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970);
danilchap42287842017-02-20 06:40:18 -080030 EXPECT_LE(milliseconds_lower_bound - 1, ntp_time.ToMs());
31 EXPECT_GE(milliseconds_upper_bound + 1, ntp_time.ToMs());
stefan@webrtc.orgb8e7f4c2013-04-12 11:56:23 +000032}
andrew@webrtc.orga37bf2c2015-01-05 19:08:58 +000033
stefan@webrtc.orgb8e7f4c2013-04-12 11:56:23 +000034} // namespace webrtc