danilchap | b1ac203 | 2015-11-26 09:01:10 -0800 | [diff] [blame] | 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 | |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 11 | #include "webrtc/test/gtest.h" |
danilchap | b1ac203 | 2015-11-26 09:01:10 -0800 | [diff] [blame] | 12 | |
| 13 | #include "webrtc/system_wrappers/include/ntp_time.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace { |
| 17 | |
| 18 | const uint32_t kNtpSec = 0x12345678; |
| 19 | const uint32_t kNtpFrac = 0x23456789; |
| 20 | |
| 21 | TEST(NtpTimeTest, NoValueMeansInvalid) { |
| 22 | NtpTime ntp; |
| 23 | EXPECT_FALSE(ntp.Valid()); |
| 24 | } |
| 25 | |
| 26 | TEST(NtpTimeTest, CanResetValue) { |
| 27 | NtpTime ntp(kNtpSec, kNtpFrac); |
| 28 | EXPECT_TRUE(ntp.Valid()); |
| 29 | ntp.Reset(); |
| 30 | EXPECT_FALSE(ntp.Valid()); |
| 31 | } |
| 32 | |
| 33 | TEST(NtpTimeTest, CanGetWhatIsSet) { |
| 34 | NtpTime ntp; |
| 35 | ntp.Set(kNtpSec, kNtpFrac); |
| 36 | EXPECT_EQ(kNtpSec, ntp.seconds()); |
| 37 | EXPECT_EQ(kNtpFrac, ntp.fractions()); |
| 38 | } |
| 39 | |
| 40 | TEST(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 | |
| 49 | TEST(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 | |
| 60 | TEST(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 |