| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 seq_nums_desc.insert(x); | 205 seq_nums_desc.insert(x); |
| 206 ASSERT_EQ(x, *seq_nums_asc.begin()); | 206 ASSERT_EQ(x, *seq_nums_asc.begin()); |
| 207 ASSERT_EQ(x, *seq_nums_desc.rbegin()); | 207 ASSERT_EQ(x, *seq_nums_desc.rbegin()); |
| 208 x = Add<D>(x, 1); | 208 x = Add<D>(x, 1); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 #if GTEST_HAS_DEATH_TEST | 212 #if GTEST_HAS_DEATH_TEST |
| 213 #if !defined(WEBRTC_ANDROID) | 213 #if !defined(WEBRTC_ANDROID) |
| 214 TEST(SeqNumUnwrapper, NoBackWardWrap) { | 214 TEST(SeqNumUnwrapper, NoBackWardWrap) { |
| 215 SeqNumUnwrapper<uint8_t> unwrapper; | 215 SeqNumUnwrapper<uint8_t> unwrapper(0); |
| 216 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | 216 EXPECT_EQ(0U, unwrapper.Unwrap(0)); |
| 217 | 217 |
| 218 // The unwrapped sequence is not allowed to wrap, if that happens the | 218 // The unwrapped sequence is not allowed to wrap, if that happens the |
| 219 // SeqNumUnwrapper should have been constructed with a higher start value. | 219 // SeqNumUnwrapper should have been constructed with a higher start value. |
| 220 EXPECT_DEATH(unwrapper.Unwrap(255), ""); | 220 EXPECT_DEATH(unwrapper.Unwrap(255), ""); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST(SeqNumUnwrapper, NoForwardWrap) { | 223 TEST(SeqNumUnwrapper, NoForwardWrap) { |
| 224 SeqNumUnwrapper<uint32_t> unwrapper(std::numeric_limits<uint64_t>::max()); | 224 SeqNumUnwrapper<uint32_t> unwrapper(std::numeric_limits<uint64_t>::max()); |
| 225 EXPECT_EQ(std::numeric_limits<uint64_t>::max(), unwrapper.Unwrap(0)); | 225 EXPECT_EQ(std::numeric_limits<uint64_t>::max(), unwrapper.Unwrap(0)); |
| 226 | 226 |
| 227 // The unwrapped sequence is not allowed to wrap, if that happens the | 227 // The unwrapped sequence is not allowed to wrap, if that happens the |
| 228 // SeqNumUnwrapper should have been constructed with a lower start value. | 228 // SeqNumUnwrapper should have been constructed with a lower start value. |
| 229 EXPECT_DEATH(unwrapper.Unwrap(1), ""); | 229 EXPECT_DEATH(unwrapper.Unwrap(1), ""); |
| 230 } | 230 } |
| 231 #endif | 231 #endif |
| 232 #endif | 232 #endif |
| 233 | 233 |
| 234 TEST(SeqNumUnwrapper, ForwardWrap) { | 234 TEST(SeqNumUnwrapper, ForwardWrap) { |
| 235 SeqNumUnwrapper<uint8_t> unwrapper; | 235 SeqNumUnwrapper<uint8_t> unwrapper(0); |
| 236 EXPECT_EQ(0U, unwrapper.Unwrap(255)); | 236 EXPECT_EQ(0U, unwrapper.Unwrap(255)); |
| 237 EXPECT_EQ(1U, unwrapper.Unwrap(0)); | 237 EXPECT_EQ(1U, unwrapper.Unwrap(0)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) { | 240 TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) { |
| 241 SeqNumUnwrapper<uint8_t, 33> unwrapper; | 241 SeqNumUnwrapper<uint8_t, 33> unwrapper(0); |
| 242 EXPECT_EQ(0U, unwrapper.Unwrap(30)); | 242 EXPECT_EQ(0U, unwrapper.Unwrap(30)); |
| 243 EXPECT_EQ(6U, unwrapper.Unwrap(3)); | 243 EXPECT_EQ(6U, unwrapper.Unwrap(3)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST(SeqNumUnwrapper, BackWardWrap) { | 246 TEST(SeqNumUnwrapper, BackWardWrap) { |
| 247 SeqNumUnwrapper<uint8_t> unwrapper(10); | 247 SeqNumUnwrapper<uint8_t> unwrapper(10); |
| 248 EXPECT_EQ(10U, unwrapper.Unwrap(0)); | 248 EXPECT_EQ(10U, unwrapper.Unwrap(0)); |
| 249 EXPECT_EQ(8U, unwrapper.Unwrap(254)); | 249 EXPECT_EQ(8U, unwrapper.Unwrap(254)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) { | 252 TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) { |
| 253 SeqNumUnwrapper<uint8_t, 33> unwrapper(10); | 253 SeqNumUnwrapper<uint8_t, 33> unwrapper(10); |
| 254 EXPECT_EQ(10U, unwrapper.Unwrap(0)); | 254 EXPECT_EQ(10U, unwrapper.Unwrap(0)); |
| 255 EXPECT_EQ(8U, unwrapper.Unwrap(31)); | 255 EXPECT_EQ(8U, unwrapper.Unwrap(31)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 TEST(SeqNumUnwrapper, Unwrap) { | 258 TEST(SeqNumUnwrapper, Unwrap) { |
| 259 SeqNumUnwrapper<uint16_t> unwrapper; | 259 SeqNumUnwrapper<uint16_t> unwrapper(0); |
| 260 const uint16_t kMax = std::numeric_limits<uint16_t>::max(); | 260 const uint16_t kMax = std::numeric_limits<uint16_t>::max(); |
| 261 const uint16_t kMaxDist = kMax / 2 + 1; | 261 const uint16_t kMaxDist = kMax / 2 + 1; |
| 262 | 262 |
| 263 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | 263 EXPECT_EQ(0U, unwrapper.Unwrap(0)); |
| 264 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); | 264 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); |
| 265 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | 265 EXPECT_EQ(0U, unwrapper.Unwrap(0)); |
| 266 | 266 |
| 267 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); | 267 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); |
| 268 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax)); | 268 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax)); |
| 269 EXPECT_EQ(kMax + 1U, unwrapper.Unwrap(0)); | 269 EXPECT_EQ(kMax + 1U, unwrapper.Unwrap(0)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 287 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | 287 EXPECT_EQ(0U, unwrapper.Unwrap(0)); |
| 288 } | 288 } |
| 289 | 289 |
| 290 TEST(SeqNumUnwrapper, ManyForwardWraps) { | 290 TEST(SeqNumUnwrapper, ManyForwardWraps) { |
| 291 const int kLargeNumber = 4711; | 291 const int kLargeNumber = 4711; |
| 292 const int kMaxStep = kLargeNumber / 2; | 292 const int kMaxStep = kLargeNumber / 2; |
| 293 const int kNumWraps = 100; | 293 const int kNumWraps = 100; |
| 294 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper; | 294 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper; |
| 295 | 295 |
| 296 uint16_t next_unwrap = 0; | 296 uint16_t next_unwrap = 0; |
| 297 uint64_t expected = 0; | 297 uint64_t expected = decltype(unwrapper)::kDefaultStartValue; |
| 298 for (int i = 0; i < kNumWraps * 2 + 1; ++i) { | 298 for (int i = 0; i < kNumWraps * 2 + 1; ++i) { |
| 299 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); | 299 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); |
| 300 expected += kMaxStep; | 300 expected += kMaxStep; |
| 301 next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber; | 301 next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 TEST(SeqNumUnwrapper, ManyBackwardWraps) { | 305 TEST(SeqNumUnwrapper, ManyBackwardWraps) { |
| 306 const int kLargeNumber = 4711; | 306 const int kLargeNumber = 4711; |
| 307 const int kMaxStep = kLargeNumber / 2; | 307 const int kMaxStep = kLargeNumber / 2; |
| 308 const int kNumWraps = 100; | 308 const int kNumWraps = 100; |
| 309 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps); | 309 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps); |
| 310 | 310 |
| 311 uint16_t next_unwrap = 0; | 311 uint16_t next_unwrap = 0; |
| 312 uint64_t expected = kLargeNumber * kNumWraps; | 312 uint64_t expected = kLargeNumber * kNumWraps; |
| 313 for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) { | 313 for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) { |
| 314 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); | 314 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); |
| 315 expected -= kMaxStep; | 315 expected -= kMaxStep; |
| 316 next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber; | 316 next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace webrtc | 320 } // namespace webrtc |
| OLD | NEW |