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

Unified Diff: webrtc/base/timeutils_unittest.cc

Issue 1779773002: Make rtc::TimestampWrapAroundHandler handle backwards wrapping (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added unit test for "no negative start" Created 4 years, 9 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
« no previous file with comments | « webrtc/base/timeutils.cc ('k') | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/timeutils_unittest.cc
diff --git a/webrtc/base/timeutils_unittest.cc b/webrtc/base/timeutils_unittest.cc
index 688658b32f71356b11570a14a2fe5a7b635b50c2..7e342d00fa14f766ec3da0a390b30415d85ff59a 100644
--- a/webrtc/base/timeutils_unittest.cc
+++ b/webrtc/base/timeutils_unittest.cc
@@ -153,18 +153,48 @@ class TimestampWrapAroundHandlerTest : public testing::Test {
};
TEST_F(TimestampWrapAroundHandlerTest, Unwrap) {
- uint32_t ts = 0xfffffff2;
- int64_t unwrapped_ts = ts;
- EXPECT_EQ(ts, wraparound_handler_.Unwrap(ts));
+ // Start value.
+ int64_t ts = 2;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+
+ // Wrap backwards.
+ ts = -2;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+
+ // Forward to 2 again.
ts = 2;
- unwrapped_ts += 0x10;
- EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
- ts = 0xfffffff2;
- unwrapped_ts += 0xfffffff0;
- EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
- ts = 0;
- unwrapped_ts += 0xe;
- EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts));
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+
+ // Max positive skip ahead, until max value (0xffffffff).
+ for (uint32_t i = 0; i <= 0xf; ++i) {
+ ts = (i << 28) + 0x0fffffff;
+ EXPECT_EQ(
+ ts, wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+ }
+
+ // Wrap around.
+ ts += 2;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+
+ // Max wrap backward...
+ ts -= 0x0fffffff;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+
+ // ...and back again.
+ ts += 0x0fffffff;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
+}
+
+TEST_F(TimestampWrapAroundHandlerTest, NoNegativeStart) {
+ int64_t ts = 0xfffffff0;
+ EXPECT_EQ(ts,
+ wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff)));
}
class TmToSeconds : public testing::Test {
« no previous file with comments | « webrtc/base/timeutils.cc ('k') | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698