Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: media/cast/cast_ntp_tick_clock_unittest.cc

Issue 34623008: Change to calculate the real NTP in TimeTicks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a707494519a427a4481f0f82679ef403fad80cad
--- /dev/null
+++ b/media/cast/cast_ntp_tick_clock_unittest.cc
@@ -0,0 +1,59 @@
+// 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/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 advance_time = base::TimeDelta::FromSeconds(kAdvanceTime);
+ testing_clock.Advance(advance_time);
+
+ EXPECT_EQ(ntp_clock.NowTicks(), start_ticks + advance_time);
+}
+
+} // namespace cast
+} // namespace media
+

Powered by Google App Engine
This is Rietveld 408576698