Chromium Code Reviews| Index: media/cast/cast_ntp_tick_clock_unittest.cc |
| diff --git a/media/cast/cast_ntp_tick_clock_unittest.cc b/media/cast/cast_ntp_tick_clock_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58e1f52b8bb717bf646ba319943c0f1ff24e910e |
| --- /dev/null |
| +++ b/media/cast/cast_ntp_tick_clock_unittest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/threading/platform_thread.h" |
| +#include "base/test/simple_test_tick_clock.h" |
| +#include "media/cast/cast_defines.h" |
| +#include "media/cast/cast_ntp_tick_clock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace media { |
| +namespace cast { |
| + |
| +class PeerCastNtpTickClock : public CastNtpTickClock { |
| + public: |
| + explicit PeerCastNtpTickClock() {} |
| + |
| + using CastNtpTickClock::SetTickClock; |
| +}; |
| + |
| +class CastNtpTickClockTest : public ::testing::Test { |
| + protected: |
| + CastNtpTickClockTest() {} |
| + virtual ~CastNtpTickClockTest() {} |
| +}; |
| + |
| +// Note: This test will fail if the system clock is not between the years 2010 |
| +// and 2030. |
| +TEST_F(CastNtpTickClockTest, Basic) { |
| + const int64 kSecondsbetweenYear1900and2010 = GG_INT64_C(40176 * 24 * 60 * 60); |
| + const int64 kSecondsbetweenYear1900and2030 = GG_INT64_C(47481 * 24 * 60 * 60); |
| + |
| + CastNtpTickClock ntp_clock; |
| + base::TimeTicks now_ticks = ntp_clock.NowTicks(); |
| + base::TimeTicks year_2010_in_ticks; |
| + base::TimeTicks year_2030_in_ticks; |
| + year_2010_in_ticks += base::TimeDelta::FromSeconds( |
| + kSecondsbetweenYear1900and2010); |
| + year_2030_in_ticks += base::TimeDelta::FromSeconds( |
| + kSecondsbetweenYear1900and2030); |
| + |
| + EXPECT_GT(now_ticks, year_2010_in_ticks); |
| + EXPECT_LT(now_ticks, year_2030_in_ticks); |
| +} |
| + |
| +TEST_F(CastNtpTickClockTest, Advance) { |
| + const int64 kAdvanceTime = 123; |
| + PeerCastNtpTickClock ntp_clock; |
| + base::SimpleTestTickClock testing_clock; |
| + ntp_clock.SetTickClock(&testing_clock); |
| + base::TimeTicks start_ticks = ntp_clock.NowTicks(); |
| + base::TimeDelta advence_time = base::TimeDelta::FromSeconds(kAdvanceTime); |
|
miu
2013/10/23 18:24:02
typo: s/advence/advance/
pwestin
2013/10/23 21:07:49
Done.
pwestin
2013/10/23 21:07:49
Done.
|
| + testing_clock.Advance(advence_time); |
| + |
| + EXPECT_EQ(ntp_clock.NowTicks(), start_ticks + advence_time); |
| +} |
| + |
| +} // namespace cast |
| +} // namespace media |
| + |