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

Unified Diff: media/cast/common/rtp_time_unittest.cc

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Speculative workaround fix for win8_chromium_ng compile error. Created 5 years 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
« no previous file with comments | « media/cast/common/rtp_time.cc ('k') | media/cast/logging/encoding_event_subscriber.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cast/common/rtp_time_unittest.cc
diff --git a/media/cast/common/rtp_time_unittest.cc b/media/cast/common/rtp_time_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cdbd10f9cef694cd8ce2a197b1096507c73e000e
--- /dev/null
+++ b/media/cast/common/rtp_time_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2015 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 "media/cast/common/rtp_time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+namespace cast {
+
+// Tests that conversions between base::TimeDelta and RtpTimeDelta are accurate.
+// Note that this implicitly tests the conversions to/from RtpTimeTicks as well
+// due to shared implementation.
+TEST(RtpTimeDeltaTest, ConversionToAndFromTimeDelta) {
+ const int kTimebase = 48000;
+
+ // Origin in both timelines is equivalent.
+ ASSERT_EQ(RtpTimeDelta(), RtpTimeDelta::FromTicks(0));
+ ASSERT_EQ(RtpTimeDelta(),
+ RtpTimeDelta::FromTimeDelta(base::TimeDelta(), kTimebase));
+ ASSERT_EQ(base::TimeDelta(),
+ RtpTimeDelta::FromTicks(0).ToTimeDelta(kTimebase));
+
+ // Conversions that are exact (i.e., do not require rounding).
+ ASSERT_EQ(RtpTimeDelta::FromTicks(480),
+ RtpTimeDelta::FromTimeDelta(base::TimeDelta::FromMilliseconds(10),
+ kTimebase));
+ ASSERT_EQ(
+ RtpTimeDelta::FromTicks(96000),
+ RtpTimeDelta::FromTimeDelta(base::TimeDelta::FromSeconds(2), kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromMilliseconds(10),
+ RtpTimeDelta::FromTicks(480).ToTimeDelta(kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromSeconds(2),
+ RtpTimeDelta::FromTicks(96000).ToTimeDelta(kTimebase));
+
+ // Conversions that are approximate (i.e., are rounded).
+ for (int error_us = -3; error_us <= +3; ++error_us) {
+ ASSERT_EQ(RtpTimeDelta::FromTicks(0),
+ RtpTimeDelta::FromTimeDelta(
+ base::TimeDelta::FromMicroseconds(0 + error_us), kTimebase));
+ ASSERT_EQ(RtpTimeDelta::FromTicks(1),
+ RtpTimeDelta::FromTimeDelta(
+ base::TimeDelta::FromMicroseconds(21 + error_us), kTimebase));
+ ASSERT_EQ(RtpTimeDelta::FromTicks(2),
+ RtpTimeDelta::FromTimeDelta(
+ base::TimeDelta::FromMicroseconds(42 + error_us), kTimebase));
+ ASSERT_EQ(RtpTimeDelta::FromTicks(3),
+ RtpTimeDelta::FromTimeDelta(
+ base::TimeDelta::FromMicroseconds(63 + error_us), kTimebase));
+ ASSERT_EQ(RtpTimeDelta::FromTicks(4),
+ RtpTimeDelta::FromTimeDelta(
+ base::TimeDelta::FromMicroseconds(83 + error_us), kTimebase));
+ ASSERT_EQ(
+ RtpTimeDelta::FromTicks(11200000000000),
+ RtpTimeDelta::FromTimeDelta(base::TimeDelta::FromMicroseconds(
+ INT64_C(233333333333333) + error_us),
+ kTimebase));
+ }
+ ASSERT_EQ(base::TimeDelta::FromMicroseconds(21),
+ RtpTimeDelta::FromTicks(1).ToTimeDelta(kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromMicroseconds(42),
+ RtpTimeDelta::FromTicks(2).ToTimeDelta(kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromMicroseconds(63),
+ RtpTimeDelta::FromTicks(3).ToTimeDelta(kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromMicroseconds(83),
+ RtpTimeDelta::FromTicks(4).ToTimeDelta(kTimebase));
+ ASSERT_EQ(base::TimeDelta::FromMicroseconds(INT64_C(233333333333333)),
+ RtpTimeDelta::FromTicks(11200000000000).ToTimeDelta(kTimebase));
+}
+
+} // namespace cast
+} // namespace media
« no previous file with comments | « media/cast/common/rtp_time.cc ('k') | media/cast/logging/encoding_event_subscriber.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698