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

Side by Side 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, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 x = 200; 202 x = 200;
203 for (int i = 0; i < D / 2; ++i) { 203 for (int i = 0; i < D / 2; ++i) {
204 seq_nums_asc.insert(x); 204 seq_nums_asc.insert(x);
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 TEST(SeqNumUnwrapper, NoBackWardWrap) {
213 SeqNumUnwrapper<uint8_t> unwrapper;
214 EXPECT_EQ(0U, unwrapper.Unwrap(0));
215
216 // The unwrapped sequence is not allowed to wrap, if that happens the
217 // SeqNumUnwrapper should have been constructed with a higher start value.
218 ASSERT_DEATH_IF_SUPPORTED(unwrapper.Unwrap(255), "");
219 }
220
221 TEST(SeqNumUnwrapper, NoForwardWrap) {
222 SeqNumUnwrapper<uint32_t> unwrapper(std::numeric_limits<uint64_t>::max());
223 EXPECT_EQ(std::numeric_limits<uint64_t>::max(), unwrapper.Unwrap(0));
224
225 // The unwrapped sequence is not allowed to wrap, if that happens the
226 // SeqNumUnwrapper should have been constructed with a lower start value.
227 ASSERT_DEATH_IF_SUPPORTED(unwrapper.Unwrap(1), "");
228 }
229
230 TEST(SeqNumUnwrapper, ForwardWrap) {
231 SeqNumUnwrapper<uint8_t> unwrapper;
232 EXPECT_EQ(0U, unwrapper.Unwrap(255));
233 EXPECT_EQ(1U, unwrapper.Unwrap(0));
234 }
235
236 TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) {
237 SeqNumUnwrapper<uint8_t, 33> unwrapper;
238 EXPECT_EQ(0U, unwrapper.Unwrap(30));
239 EXPECT_EQ(6U, unwrapper.Unwrap(3));
240 }
241
242 TEST(SeqNumUnwrapper, BackWardWrap) {
243 SeqNumUnwrapper<uint8_t> unwrapper(10);
244 EXPECT_EQ(10U, unwrapper.Unwrap(0));
245 EXPECT_EQ(8U, unwrapper.Unwrap(254));
246 }
247
248 TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) {
249 SeqNumUnwrapper<uint8_t, 33> unwrapper(10);
250 EXPECT_EQ(10U, unwrapper.Unwrap(0));
251 EXPECT_EQ(8U, unwrapper.Unwrap(31));
252 }
253
254 TEST(SeqNumUnwrapper, Unwrap) {
255 SeqNumUnwrapper<uint16_t> unwrapper;
256 const uint16_t kMax = std::numeric_limits<uint16_t>::max();
257 const uint16_t kMaxDist = kMax / 2 + 1;
258
259 EXPECT_EQ(0U, unwrapper.Unwrap(0));
260 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
261 EXPECT_EQ(0U, unwrapper.Unwrap(0));
262
263 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
264 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
265 EXPECT_EQ(kMax + 1U, unwrapper.Unwrap(0));
266 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
267 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
268 EXPECT_EQ(0U, unwrapper.Unwrap(0));
269 }
270
271 TEST(SeqNumUnwrapper, UnwrapOddDivisor) {
272 SeqNumUnwrapper<uint8_t, 11> unwrapper(10);
273
274 EXPECT_EQ(10U, unwrapper.Unwrap(10));
275 EXPECT_EQ(11U, unwrapper.Unwrap(0));
276 EXPECT_EQ(16U, unwrapper.Unwrap(5));
277 EXPECT_EQ(21U, unwrapper.Unwrap(10));
278 EXPECT_EQ(22U, unwrapper.Unwrap(0));
279 EXPECT_EQ(17U, unwrapper.Unwrap(6));
280 EXPECT_EQ(12U, unwrapper.Unwrap(1));
281 EXPECT_EQ(7U, unwrapper.Unwrap(7));
282 EXPECT_EQ(2U, unwrapper.Unwrap(2));
283 EXPECT_EQ(0U, unwrapper.Unwrap(0));
284 }
285
286 TEST(SeqNumUnwrapper, ManyForwardWraps) {
287 const int kLargeNumber = 4711;
288 const int kMaxStep = kLargeNumber / 2;
289 const int kNumWraps = 100;
290 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
291
292 uint16_t next_unwrap = 0;
293 uint64_t expected = 0;
294 for (int i = 0; i < kNumWraps * 2 + 1; ++i) {
295 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
296 expected += kMaxStep;
297 next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber;
298 }
299 }
300
301 TEST(SeqNumUnwrapper, ManyBackwardWraps) {
302 const int kLargeNumber = 4711;
303 const int kMaxStep = kLargeNumber / 2;
304 const int kNumWraps = 100;
305 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps);
306
307 uint16_t next_unwrap = 0;
308 uint64_t expected = kLargeNumber * kNumWraps;
309 for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) {
310 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
311 expected -= kMaxStep;
312 next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber;
313 }
314 }
315
212 } // namespace webrtc 316 } // namespace webrtc
OLDNEW
« 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