1 /* 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 11 #include "system_wrappers/include/clock.h" 12 13 #include "test/gtest.h" 14 15 namespace webrtc { 16 TEST(ClockTest,NtpTime)17TEST(ClockTest, NtpTime) { 18 Clock* clock = Clock::GetRealTimeClock(); 19 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(); 27 NtpTime ntp_time = clock->CurrentNtpTime(); 28 int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds(); 29 EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970); 30 EXPECT_LE(milliseconds_lower_bound - 1, ntp_time.ToMs()); 31 EXPECT_GE(milliseconds_upper_bound + 1, ntp_time.ToMs()); 32 } 33 34 } // namespace webrtc 35