1/* 2 * Copyright (c) 2014 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 "testing/gtest/include/gtest/gtest.h" 12 13#include "webrtc/system_wrappers/include/ntp_time.h" 14 15namespace webrtc { 16namespace { 17 18const uint32_t kNtpSec = 0x12345678; 19const uint32_t kNtpFrac = 0x23456789; 20 21TEST(NtpTimeTest, NoValueMeansInvalid) { 22 NtpTime ntp; 23 EXPECT_FALSE(ntp.Valid()); 24} 25 26TEST(NtpTimeTest, CanResetValue) { 27 NtpTime ntp(kNtpSec, kNtpFrac); 28 EXPECT_TRUE(ntp.Valid()); 29 ntp.Reset(); 30 EXPECT_FALSE(ntp.Valid()); 31} 32 33TEST(NtpTimeTest, CanGetWhatIsSet) { 34 NtpTime ntp; 35 ntp.Set(kNtpSec, kNtpFrac); 36 EXPECT_EQ(kNtpSec, ntp.seconds()); 37 EXPECT_EQ(kNtpFrac, ntp.fractions()); 38} 39 40TEST(NtpTimeTest, SetIsSameAs2ParameterConstructor) { 41 NtpTime ntp1(kNtpSec, kNtpFrac); 42 NtpTime ntp2; 43 EXPECT_NE(ntp1, ntp2); 44 45 ntp2.Set(kNtpSec, kNtpFrac); 46 EXPECT_EQ(ntp1, ntp2); 47} 48 49TEST(NtpTimeTest, SetCurrentIsSameAs1ParameterConstructor) { 50 SimulatedClock clock(0x0123456789abcdef); 51 52 NtpTime ntp1(clock); 53 NtpTime ntp2; 54 EXPECT_NE(ntp1, ntp2); 55 56 ntp2.SetCurrent(clock); 57 EXPECT_EQ(ntp1, ntp2); 58} 59 60TEST(NtpTimeTest, ToMsMeansToNtpMilliseconds) { 61 SimulatedClock clock(0x123456789abc); 62 63 NtpTime ntp(clock); 64 EXPECT_EQ(ntp.ToMs(), Clock::NtpToMs(ntp.seconds(), ntp.fractions())); 65 EXPECT_EQ(ntp.ToMs(), clock.CurrentNtpInMilliseconds()); 66} 67 68} // namespace 69} // namespace webrtc 70