1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #include "system_wrappers/include/clock.h" 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h" 14*d9f75844SAndroid Build Coastguard Worker 15*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 16*d9f75844SAndroid Build Coastguard Worker TEST(ClockTest,NtpTime)17*d9f75844SAndroid Build Coastguard WorkerTEST(ClockTest, NtpTime) { 18*d9f75844SAndroid Build Coastguard Worker Clock* clock = Clock::GetRealTimeClock(); 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker // To ensure the test runs correctly even on a heavily loaded system, do not 21*d9f75844SAndroid Build Coastguard Worker // compare the seconds/fractions and millisecond values directly. Instead, 22*d9f75844SAndroid Build Coastguard Worker // we check that the NTP time is between the "milliseconds" values returned 23*d9f75844SAndroid Build Coastguard Worker // right before and right after the call. 24*d9f75844SAndroid Build Coastguard Worker // The comparison includes 1 ms of margin to account for the rounding error in 25*d9f75844SAndroid Build Coastguard Worker // the conversion. 26*d9f75844SAndroid Build Coastguard Worker int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds(); 27*d9f75844SAndroid Build Coastguard Worker NtpTime ntp_time = clock->CurrentNtpTime(); 28*d9f75844SAndroid Build Coastguard Worker int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds(); 29*d9f75844SAndroid Build Coastguard Worker EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970); 30*d9f75844SAndroid Build Coastguard Worker EXPECT_LE(milliseconds_lower_bound - 1, ntp_time.ToMs()); 31*d9f75844SAndroid Build Coastguard Worker EXPECT_GE(milliseconds_upper_bound + 1, ntp_time.ToMs()); 32*d9f75844SAndroid Build Coastguard Worker } 33*d9f75844SAndroid Build Coastguard Worker 34*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 35