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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Wrapping backward from 0 is not allowed, if that happens the | |
217 // SeqNumUnwrapper should have been constructed with a higher start value. | |
218 // unwrapper.Unwrap(255); | |
terelius
2017/07/24 13:35:39
Should this really be commented? Did you intend to
philipel
2017/07/24 14:46:43
TIL, death tests :)
| |
219 } | |
220 | |
221 TEST(SeqNumUnwrapper, ForwardWrap) { | |
222 SeqNumUnwrapper<uint8_t> unwrapper; | |
223 EXPECT_EQ(0U, unwrapper.Unwrap(255)); | |
224 EXPECT_EQ(1U, unwrapper.Unwrap(0)); | |
225 } | |
226 | |
227 TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) { | |
228 SeqNumUnwrapper<uint8_t, 33> unwrapper; | |
229 EXPECT_EQ(0U, unwrapper.Unwrap(30)); | |
230 EXPECT_EQ(6U, unwrapper.Unwrap(3)); | |
231 } | |
232 | |
233 TEST(SeqNumUnwrapper, BackWardWrap) { | |
234 SeqNumUnwrapper<uint8_t> unwrapper(10); | |
235 EXPECT_EQ(10U, unwrapper.Unwrap(0)); | |
236 EXPECT_EQ(8U, unwrapper.Unwrap(254)); | |
237 } | |
238 | |
239 TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) { | |
240 SeqNumUnwrapper<uint8_t, 33> unwrapper(10); | |
241 EXPECT_EQ(10U, unwrapper.Unwrap(0)); | |
242 EXPECT_EQ(8U, unwrapper.Unwrap(31)); | |
243 } | |
244 | |
245 TEST(SeqNumUnwrapper, Unwrap) { | |
246 SeqNumUnwrapper<uint16_t> unwrapper; | |
247 const uint16_t kMax = std::numeric_limits<uint16_t>::max(); | |
248 const uint16_t kMaxDist = kMax / 2 + 1; | |
249 | |
250 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | |
251 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); | |
252 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | |
253 | |
254 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); | |
255 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax)); | |
256 EXPECT_EQ(kMax + 1U, unwrapper.Unwrap(0)); | |
257 EXPECT_EQ(kMax, unwrapper.Unwrap(kMax)); | |
258 EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist)); | |
259 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | |
260 } | |
261 | |
262 TEST(SeqNumUnwrapper, UnwrapOddDivisor) { | |
263 SeqNumUnwrapper<uint8_t, 11> unwrapper(10); | |
264 | |
265 EXPECT_EQ(10U, unwrapper.Unwrap(10)); | |
266 EXPECT_EQ(11U, unwrapper.Unwrap(0)); | |
267 EXPECT_EQ(16U, unwrapper.Unwrap(5)); | |
268 EXPECT_EQ(21U, unwrapper.Unwrap(10)); | |
269 EXPECT_EQ(22U, unwrapper.Unwrap(0)); | |
270 EXPECT_EQ(17U, unwrapper.Unwrap(6)); | |
271 EXPECT_EQ(12U, unwrapper.Unwrap(1)); | |
272 EXPECT_EQ(7U, unwrapper.Unwrap(7)); | |
273 EXPECT_EQ(2U, unwrapper.Unwrap(2)); | |
274 EXPECT_EQ(0U, unwrapper.Unwrap(0)); | |
275 } | |
276 | |
277 TEST(SeqNumUnwrapper, ManyForwardWraps) { | |
278 const int kLargeNumber = 4711; | |
279 const int kMaxStep = kLargeNumber / 2; | |
280 const int kNumWraps = 100; | |
281 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper; | |
282 | |
283 uint16_t next_unwrap = 0; | |
284 uint64_t expected = 0; | |
285 for (int i = 0; i < kNumWraps * 2 + 1; ++i) { | |
286 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); | |
287 expected += kMaxStep; | |
288 next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber; | |
289 } | |
290 } | |
291 | |
292 TEST(SeqNumUnwrapper, ManyBackwardWraps) { | |
293 const int kLargeNumber = 4711; | |
294 const int kMaxStep = kLargeNumber / 2; | |
295 const int kNumWraps = 100; | |
296 SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper(kLargeNumber * kNumWraps); | |
297 | |
298 uint16_t next_unwrap = 0; | |
299 uint64_t expected = kLargeNumber * kNumWraps; | |
300 for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) { | |
301 EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap)); | |
302 expected -= kMaxStep; | |
303 next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber; | |
304 } | |
305 } | |
306 | |
212 } // namespace webrtc | 307 } // namespace webrtc |
OLD | NEW |