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

Side by Side Diff: webrtc/modules/module_common_types_unittest.cc

Issue 2813593003: Add TimestampUnwrapper and generalize the code (Closed)
Patch Set: Remove ctor Created 3 years, 8 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/include/module_common_types.h ('k') | no next file » | 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 EXPECT_EQ(0x0000FFFFu, LatestTimestamp(0xFFFF0000, 0x0000FFFF)); 112 EXPECT_EQ(0x0000FFFFu, LatestTimestamp(0xFFFF0000, 0x0000FFFF));
113 } 113 }
114 114
115 115
116 TEST(SequenceNumberUnwrapper, Limits) { 116 TEST(SequenceNumberUnwrapper, Limits) {
117 SequenceNumberUnwrapper unwrapper; 117 SequenceNumberUnwrapper unwrapper;
118 118
119 EXPECT_EQ(0, unwrapper.Unwrap(0)); 119 EXPECT_EQ(0, unwrapper.Unwrap(0));
120 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000)); 120 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
121 // Delta is exactly 0x8000 but current is lower than input, wrap backwards. 121 // Delta is exactly 0x8000 but current is lower than input, wrap backwards.
122 EXPECT_EQ(0x0, unwrapper.Unwrap(0x0000)); 122 EXPECT_EQ(0, unwrapper.Unwrap(0));
123 123
124 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000)); 124 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
125 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF)); 125 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
126 EXPECT_EQ(0x10000, unwrapper.Unwrap(0x0000)); 126 EXPECT_EQ(0x10000, unwrapper.Unwrap(0));
127 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF)); 127 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
128 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000)); 128 EXPECT_EQ(0x8000, unwrapper.Unwrap(0x8000));
129 EXPECT_EQ(0, unwrapper.Unwrap(0)); 129 EXPECT_EQ(0, unwrapper.Unwrap(0));
130 130
131 // Don't allow negative values. 131 // Don't allow negative values.
132 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF)); 132 EXPECT_EQ(0xFFFF, unwrapper.Unwrap(0xFFFF));
133 } 133 }
134 134
135 TEST(SequenceNumberUnwrapper, ForwardWraps) { 135 TEST(SequenceNumberUnwrapper, ForwardWraps) {
136 int64_t seq = 0; 136 int64_t seq = 0;
(...skipping 28 matching lines...) Expand all
165 } 165 }
166 166
167 seq = kNumWraps * 0xFFFF; 167 seq = kNumWraps * 0xFFFF;
168 unwrapper.UpdateLast(seq); 168 unwrapper.UpdateLast(seq);
169 for (; seq >= 0; --seq) { 169 for (; seq >= 0; --seq) {
170 int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF)); 170 int64_t unwrapped = unwrapper.Unwrap(static_cast<uint16_t>(seq & 0xFFFF));
171 EXPECT_EQ(seq, unwrapped); 171 EXPECT_EQ(seq, unwrapped);
172 } 172 }
173 } 173 }
174 174
175 TEST(TimestampUnwrapper, Limits) {
176 TimestampUnwrapper unwrapper;
177
178 EXPECT_EQ(0, unwrapper.Unwrap(0));
179 EXPECT_EQ(0x80000000, unwrapper.Unwrap(0x80000000));
180 // Delta is exactly 0x80000000 but current is lower than input, wrap
181 // backwards.
182 EXPECT_EQ(0, unwrapper.Unwrap(0));
183
184 EXPECT_EQ(0x80000000, unwrapper.Unwrap(0x80000000));
185 EXPECT_EQ(0xFFFFFFFF, unwrapper.Unwrap(0xFFFFFFFF));
186 EXPECT_EQ(0x100000000, unwrapper.Unwrap(0x00000000));
187 EXPECT_EQ(0xFFFFFFFF, unwrapper.Unwrap(0xFFFFFFFF));
188 EXPECT_EQ(0x80000000, unwrapper.Unwrap(0x80000000));
189 EXPECT_EQ(0, unwrapper.Unwrap(0));
190
191 // Don't allow negative values.
192 EXPECT_EQ(0xFFFFFFFF, unwrapper.Unwrap(0xFFFFFFFF));
193 }
194
195 TEST(TimestampUnwrapper, ForwardWraps) {
196 int64_t ts = 0;
197 TimestampUnwrapper unwrapper;
198
199 const int64_t kMaxIncrease = 0x80000000 - 1;
200 const int kNumWraps = 4;
201 for (int i = 0; i < kNumWraps * 2; ++i) {
202 int64_t unwrapped =
203 unwrapper.Unwrap(static_cast<uint32_t>(ts & 0xFFFFFFFF));
204 EXPECT_EQ(ts, unwrapped);
205 ts += kMaxIncrease;
206 }
207 }
208
209 TEST(TimestampUnwrapper, BackwardWraps) {
210 TimestampUnwrapper unwrapper;
211
212 const int64_t kMaxDecrease = 0x80000000 - 1;
213 const int kNumWraps = 4;
214 int64_t ts = kNumWraps * 2 * kMaxDecrease;
215 unwrapper.UpdateLast(ts);
216 for (int i = 0; i <= kNumWraps * 2; ++i) {
217 int64_t unwrapped =
218 unwrapper.Unwrap(static_cast<uint32_t>(ts & 0xFFFFFFFF));
219 EXPECT_EQ(ts, unwrapped);
220 ts -= kMaxDecrease;
221 }
222 }
223
175 } // namespace webrtc 224 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/include/module_common_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698