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

Unified Diff: webrtc/modules/video_coding/sequence_number_util_unittest.cc

Issue 2977603002: Implemented a new sequence number unwrapper in sequence_number_util.h. (Closed)
Patch Set: Feedback Created 3 years, 5 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/modules/video_coding/sequence_number_util.h ('k') | webrtc/rtc_base/mod_ops.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/video_coding/sequence_number_util_unittest.cc
diff --git a/webrtc/modules/video_coding/sequence_number_util_unittest.cc b/webrtc/modules/video_coding/sequence_number_util_unittest.cc
index 1ed78b95b8772f99a56dc53c5884e83d5e9d66f9..12cc911e414ce96217d731c371aa7fb2da413bba 100644
--- a/webrtc/modules/video_coding/sequence_number_util_unittest.cc
+++ b/webrtc/modules/video_coding/sequence_number_util_unittest.cc
@@ -209,4 +209,108 @@ TEST_F(TestSeqNumUtil, SeqNumComparatorWithDivisor) {
}
}
+TEST(SeqNumUnwrapper, NoBackWardWrap) {
+ SeqNumUnwrapper<uint8_t> unwrapper;
+ EXPECT_EQ(0U, unwrapper.Unwrap(0));
+
+ // The unwrapped sequence is not allowed to wrap, if that happens the
+ // SeqNumUnwrapper should have been constructed with a higher start value.
+ ASSERT_DEATH_IF_SUPPORTED(unwrapper.Unwrap(255), "");
+}
+
+TEST(SeqNumUnwrapper, NoForwardWrap) {
+ SeqNumUnwrapper<uint32_t> unwrapper(std::numeric_limits<uint64_t>::max());
+ EXPECT_EQ(std::numeric_limits<uint64_t>::max(), unwrapper.Unwrap(0));
+
+ // The unwrapped sequence is not allowed to wrap, if that happens the
+ // SeqNumUnwrapper should have been constructed with a lower start value.
+ ASSERT_DEATH_IF_SUPPORTED(unwrapper.Unwrap(1), "");
+}
+
+TEST(SeqNumUnwrapper, ForwardWrap) {
+ SeqNumUnwrapper<uint8_t> unwrapper;
+ EXPECT_EQ(0U, unwrapper.Unwrap(255));
+ EXPECT_EQ(1U, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) {
+ SeqNumUnwrapper<uint8_t, 33> unwrapper;
+ EXPECT_EQ(0U, unwrapper.Unwrap(30));
+ EXPECT_EQ(6U, unwrapper.Unwrap(3));
+}
+
+TEST(SeqNumUnwrapper, BackWardWrap) {
+ SeqNumUnwrapper<uint8_t> unwrapper(10);
+ EXPECT_EQ(10U, unwrapper.Unwrap(0));
+ EXPECT_EQ(8U, unwrapper.Unwrap(254));
+}
+
+TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) {
+ SeqNumUnwrapper<uint8_t, 33> unwrapper(10);
+ EXPECT_EQ(10U, unwrapper.Unwrap(0));
+ EXPECT_EQ(8U, unwrapper.Unwrap(31));
+}
+
+TEST(SeqNumUnwrapper, Unwrap) {
+ SeqNumUnwrapper<uint16_t> unwrapper;
+ const uint16_t kMax = std::numeric_limits<uint16_t>::max();
+ const uint16_t kMaxDist = kMax / 2 + 1;
+
+ EXPECT_EQ(0U, unwrapper.Unwrap(0));
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(0U, unwrapper.Unwrap(0));
+
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
+ EXPECT_EQ(kMax + 1U, unwrapper.Unwrap(0));
+ EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(0U, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, UnwrapOddDivisor) {
+ SeqNumUnwrapper<uint8_t, 11> unwrapper(10);
+
+ EXPECT_EQ(10U, unwrapper.Unwrap(10));
+ EXPECT_EQ(11U, unwrapper.Unwrap(0));
+ EXPECT_EQ(16U, unwrapper.Unwrap(5));
+ EXPECT_EQ(21U, unwrapper.Unwrap(10));
+ EXPECT_EQ(22U, unwrapper.Unwrap(0));
+ EXPECT_EQ(17U, unwrapper.Unwrap(6));
+ EXPECT_EQ(12U, unwrapper.Unwrap(1));
+ EXPECT_EQ(7U, unwrapper.Unwrap(7));
+ EXPECT_EQ(2U, unwrapper.Unwrap(2));
+ EXPECT_EQ(0U, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, ManyForwardWraps) {
+ const int kLargeNumber = 4711;
+ const int kMaxStep = kLargeNumber / 2;
+ const int kNumWraps = 100;
+ SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
+
+ uint16_t next_unwrap = 0;
+ uint64_t expected = 0;
+ for (int i = 0; i < kNumWraps * 2 + 1; ++i) {
+ EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
+ expected += kMaxStep;
+ next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber;
+ }
+}
+
+TEST(SeqNumUnwrapper, ManyBackwardWraps) {
+ const int kLargeNumber = 4711;
+ const int kMaxStep = kLargeNumber / 2;
+ const int kNumWraps = 100;
+ SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps);
+
+ uint16_t next_unwrap = 0;
+ uint64_t expected = kLargeNumber * kNumWraps;
+ for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) {
+ EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
+ expected -= kMaxStep;
+ next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber;
+ }
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/video_coding/sequence_number_util.h ('k') | webrtc/rtc_base/mod_ops.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698