OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/simple_test_tick_clock.h" |
| 6 #include "media/cast/cast_defines.h" |
| 7 #include "media/cast/cast_ntp_tick_clock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace media { |
| 11 namespace cast { |
| 12 |
| 13 class PeerCastNtpTickClock : public CastNtpTickClock { |
| 14 public: |
| 15 explicit PeerCastNtpTickClock() {} |
| 16 |
| 17 using CastNtpTickClock::SetTickClock; |
| 18 }; |
| 19 |
| 20 class CastNtpTickClockTest : public ::testing::Test { |
| 21 protected: |
| 22 CastNtpTickClockTest() {} |
| 23 virtual ~CastNtpTickClockTest() {} |
| 24 }; |
| 25 |
| 26 // Note: This test will fail if the system clock is not between the years 2010 |
| 27 // and 2030. |
| 28 TEST_F(CastNtpTickClockTest, Basic) { |
| 29 const int64 kSecondsbetweenYear1900and2010 = GG_INT64_C(40176 * 24 * 60 * 60); |
| 30 const int64 kSecondsbetweenYear1900and2030 = GG_INT64_C(47481 * 24 * 60 * 60); |
| 31 |
| 32 CastNtpTickClock ntp_clock; |
| 33 base::TimeTicks now_ticks = ntp_clock.NowTicks(); |
| 34 base::TimeTicks year_2010_in_ticks; |
| 35 base::TimeTicks year_2030_in_ticks; |
| 36 year_2010_in_ticks += base::TimeDelta::FromSeconds( |
| 37 kSecondsbetweenYear1900and2010); |
| 38 year_2030_in_ticks += base::TimeDelta::FromSeconds( |
| 39 kSecondsbetweenYear1900and2030); |
| 40 |
| 41 EXPECT_GT(now_ticks, year_2010_in_ticks); |
| 42 EXPECT_LT(now_ticks, year_2030_in_ticks); |
| 43 } |
| 44 |
| 45 TEST_F(CastNtpTickClockTest, Advance) { |
| 46 const int64 kAdvanceTime = 123; |
| 47 PeerCastNtpTickClock ntp_clock; |
| 48 base::SimpleTestTickClock testing_clock; |
| 49 ntp_clock.SetTickClock(&testing_clock); |
| 50 base::TimeTicks start_ticks = ntp_clock.NowTicks(); |
| 51 base::TimeDelta advance_time = base::TimeDelta::FromSeconds(kAdvanceTime); |
| 52 testing_clock.Advance(advance_time); |
| 53 |
| 54 EXPECT_EQ(ntp_clock.NowTicks(), start_ticks + advance_time); |
| 55 } |
| 56 |
| 57 } // namespace cast |
| 58 } // namespace media |
| 59 |
OLD | NEW |