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

Unified Diff: webrtc/modules/module_common_types_unittest.cc

Issue 1209623002: Add utility class for unwrapping 16 bit sequence numbers (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added comment Created 5 years, 3 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/interface/module_common_types.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/module_common_types_unittest.cc
diff --git a/webrtc/modules/module_common_types_unittest.cc b/webrtc/modules/module_common_types_unittest.cc
index 3e7f594166631fda651944638352170b813f1bff..bc0b7a1a5b2cb1517858afd2d25d8bb6211c5c12 100644
--- a/webrtc/modules/module_common_types_unittest.cc
+++ b/webrtc/modules/module_common_types_unittest.cc
@@ -122,4 +122,63 @@ TEST(ClampToInt16, TestCases) {
EXPECT_EQ(-0x8000, ClampToInt16(-0x7FFFFFFF));
}
+TEST(SequenceNumberUnwrapper, Limits) {
+ SequenceNumberUnwrapper unwrapper;
+
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+ EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
+ // Delta is exactly 0x8000 but current is lower than input, wrap backwards.
+ EXPECT_EQ(0x0, unwrapper.Unwrap(0x0000));
+
+ EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
+ EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
+ EXPECT_EQ(0x10000, unwrapper.Unwrap(0x0000));
+ EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
+ EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+
+ // Don't allow negative values.
+ EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
+}
+
+TEST(SequenceNumberUnwrapper, ForwardWraps) {
+ int64_t seq = 0;
+ SequenceNumberUnwrapper unwrapper;
+
+ const int kMaxIncrease = 0x8000 - 1;
+ const int kNumWraps = 4;
+ for (int i = 0; i < kNumWraps * 2; ++i) {
+ int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF));
+ EXPECT_EQ(seq, unwrapped);
+ seq += kMaxIncrease;
+ }
+
+ unwrapper.UpdateLast(0);
+ for (int seq = 0; seq < kNumWraps * 0xFFFF; ++seq) {
+ int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF));
+ EXPECT_EQ(seq, unwrapped);
+ }
+}
+
+TEST(SequenceNumberUnwrapper, BackwardWraps) {
+ SequenceNumberUnwrapper unwrapper;
+
+ const int kMaxDecrease = 0x8000 - 1;
+ const int kNumWraps = 4;
+ int64_t seq = kNumWraps * 2 * kMaxDecrease;
+ unwrapper.UpdateLast(seq);
+ for (int i = kNumWraps * 2; i >= 0; --i) {
+ int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF));
+ EXPECT_EQ(seq, unwrapped);
+ seq -= kMaxDecrease;
+ }
+
+ seq = kNumWraps * 0xFFFF;
+ unwrapper.UpdateLast(seq);
+ for (; seq >= 0; --seq) {
+ int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF));
+ EXPECT_EQ(seq, unwrapped);
+ }
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/interface/module_common_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698