You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "system_wrappers/include/clock.h"
  11. #include "test/gtest.h"
  12. namespace webrtc {
  13. TEST(ClockTest, NtpTime) {
  14. Clock* clock = Clock::GetRealTimeClock();
  15. // To ensure the test runs correctly even on a heavily loaded system, do not
  16. // compare the seconds/fractions and millisecond values directly. Instead,
  17. // we check that the NTP time is between the "milliseconds" values returned
  18. // right before and right after the call.
  19. // The comparison includes 1 ms of margin to account for the rounding error in
  20. // the conversion.
  21. int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds();
  22. NtpTime ntp_time = clock->CurrentNtpTime();
  23. int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds();
  24. EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970);
  25. EXPECT_LE(milliseconds_lower_bound - 1, ntp_time.ToMs());
  26. EXPECT_GE(milliseconds_upper_bound + 1, ntp_time.ToMs());
  27. }
  28. } // namespace webrtc