SeqNumUnwrapper::Unwrap now returns int64_t instead of uint64_t.

Bug: webrtc:10263
Change-Id: Idaeae6be01bd4eba0691226c958d70e114161ffd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127295
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Johannes Kron <kron@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27129}
This commit is contained in:
philipel
2019-03-14 10:52:37 +01:00
committed by Commit Bot
parent e8efbbd61b
commit b0f968a761
9 changed files with 409 additions and 448 deletions

View File

@ -211,82 +211,65 @@ TEST_F(TestSeqNumUtil, SeqNumComparatorWithDivisor) {
}
}
#if GTEST_HAS_DEATH_TEST
#if !defined(WEBRTC_ANDROID)
TEST(SeqNumUnwrapper, NoBackWardWrap) {
SeqNumUnwrapper<uint8_t> unwrapper(0);
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.
EXPECT_DEATH(unwrapper.Unwrap(255), "");
TEST(SeqNumUnwrapper, PreserveStartValue) {
SeqNumUnwrapper<uint8_t> unwrapper;
EXPECT_EQ(123, unwrapper.Unwrap(123));
}
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.
EXPECT_DEATH(unwrapper.Unwrap(1), "");
}
#endif
#endif
TEST(SeqNumUnwrapper, ForwardWrap) {
SeqNumUnwrapper<uint8_t> unwrapper(0);
EXPECT_EQ(0U, unwrapper.Unwrap(255));
EXPECT_EQ(1U, unwrapper.Unwrap(0));
SeqNumUnwrapper<uint8_t> unwrapper;
EXPECT_EQ(255, unwrapper.Unwrap(255));
EXPECT_EQ(256, unwrapper.Unwrap(0));
}
TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) {
SeqNumUnwrapper<uint8_t, 33> unwrapper(0);
EXPECT_EQ(0U, unwrapper.Unwrap(30));
EXPECT_EQ(6U, unwrapper.Unwrap(3));
SeqNumUnwrapper<uint8_t, 33> unwrapper;
EXPECT_EQ(30, unwrapper.Unwrap(30));
EXPECT_EQ(36, unwrapper.Unwrap(3));
}
TEST(SeqNumUnwrapper, BackWardWrap) {
SeqNumUnwrapper<uint8_t> unwrapper(10);
EXPECT_EQ(10U, unwrapper.Unwrap(0));
EXPECT_EQ(8U, unwrapper.Unwrap(254));
SeqNumUnwrapper<uint8_t> unwrapper;
EXPECT_EQ(0, unwrapper.Unwrap(0));
EXPECT_EQ(-2, unwrapper.Unwrap(254));
}
TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) {
SeqNumUnwrapper<uint8_t, 33> unwrapper(10);
EXPECT_EQ(10U, unwrapper.Unwrap(0));
EXPECT_EQ(8U, unwrapper.Unwrap(31));
SeqNumUnwrapper<uint8_t, 33> unwrapper;
EXPECT_EQ(0, unwrapper.Unwrap(0));
EXPECT_EQ(-2, unwrapper.Unwrap(31));
}
TEST(SeqNumUnwrapper, Unwrap) {
SeqNumUnwrapper<uint16_t> unwrapper(0);
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(0, unwrapper.Unwrap(0));
EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
EXPECT_EQ(0U, unwrapper.Unwrap(0));
EXPECT_EQ(0, 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 + 1, unwrapper.Unwrap(0));
EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
EXPECT_EQ(0U, unwrapper.Unwrap(0));
EXPECT_EQ(0, unwrapper.Unwrap(0));
}
TEST(SeqNumUnwrapper, UnwrapOddDivisor) {
SeqNumUnwrapper<uint8_t, 11> unwrapper(10);
SeqNumUnwrapper<uint8_t, 11> unwrapper;
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));
EXPECT_EQ(10, unwrapper.Unwrap(10));
EXPECT_EQ(11, unwrapper.Unwrap(0));
EXPECT_EQ(16, unwrapper.Unwrap(5));
EXPECT_EQ(21, unwrapper.Unwrap(10));
EXPECT_EQ(22, unwrapper.Unwrap(0));
EXPECT_EQ(17, unwrapper.Unwrap(6));
EXPECT_EQ(12, unwrapper.Unwrap(1));
EXPECT_EQ(7, unwrapper.Unwrap(7));
EXPECT_EQ(2, unwrapper.Unwrap(2));
EXPECT_EQ(0, unwrapper.Unwrap(0));
}
TEST(SeqNumUnwrapper, ManyForwardWraps) {
@ -296,7 +279,7 @@ TEST(SeqNumUnwrapper, ManyForwardWraps) {
SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
uint16_t next_unwrap = 0;
uint64_t expected = decltype(unwrapper)::kDefaultStartValue;
int64_t expected = 0;
for (int i = 0; i < kNumWraps * 2 + 1; ++i) {
EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
expected += kMaxStep;
@ -308,10 +291,10 @@ TEST(SeqNumUnwrapper, ManyBackwardWraps) {
const int kLargeNumber = 4711;
const int kMaxStep = kLargeNumber / 2;
const int kNumWraps = 100;
SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps);
SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
uint16_t next_unwrap = 0;
uint64_t expected = kLargeNumber * kNumWraps;
int64_t expected = 0;
for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) {
EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
expected -= kMaxStep;