OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 class TimestampWrapAroundHandlerTest : public testing::Test { | 147 class TimestampWrapAroundHandlerTest : public testing::Test { |
148 public: | 148 public: |
149 TimestampWrapAroundHandlerTest() {} | 149 TimestampWrapAroundHandlerTest() {} |
150 | 150 |
151 protected: | 151 protected: |
152 TimestampWrapAroundHandler wraparound_handler_; | 152 TimestampWrapAroundHandler wraparound_handler_; |
153 }; | 153 }; |
154 | 154 |
155 TEST_F(TimestampWrapAroundHandlerTest, Unwrap) { | 155 TEST_F(TimestampWrapAroundHandlerTest, Unwrap) { |
156 uint32_t ts = 0xfffffff2; | 156 // Start value. |
157 int64_t unwrapped_ts = ts; | 157 int64_t ts = 2; |
158 EXPECT_EQ(ts, wraparound_handler_.Unwrap(ts)); | 158 EXPECT_EQ(ts, |
| 159 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 160 |
| 161 // Wrap backwards. |
| 162 ts = -2; |
| 163 EXPECT_EQ(ts, |
| 164 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 165 |
| 166 // Forward to 2 again. |
159 ts = 2; | 167 ts = 2; |
160 unwrapped_ts += 0x10; | 168 EXPECT_EQ(ts, |
161 EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts)); | 169 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
162 ts = 0xfffffff2; | 170 |
163 unwrapped_ts += 0xfffffff0; | 171 // Max positive skip ahead, until max value (0xffffffff). |
164 EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts)); | 172 for (uint32_t i = 0; i <= 0xf; ++i) { |
165 ts = 0; | 173 ts = (i << 28) + 0x0fffffff; |
166 unwrapped_ts += 0xe; | 174 EXPECT_EQ( |
167 EXPECT_EQ(unwrapped_ts, wraparound_handler_.Unwrap(ts)); | 175 ts, wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 176 } |
| 177 |
| 178 // Wrap around. |
| 179 ts += 2; |
| 180 EXPECT_EQ(ts, |
| 181 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 182 |
| 183 // Max wrap backward... |
| 184 ts -= 0x0fffffff; |
| 185 EXPECT_EQ(ts, |
| 186 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 187 |
| 188 // ...and back again. |
| 189 ts += 0x0fffffff; |
| 190 EXPECT_EQ(ts, |
| 191 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
| 192 } |
| 193 |
| 194 TEST_F(TimestampWrapAroundHandlerTest, NoNegativeStart) { |
| 195 int64_t ts = 0xfffffff0; |
| 196 EXPECT_EQ(ts, |
| 197 wraparound_handler_.Unwrap(static_cast<uint32_t>(ts & 0xffffffff))); |
168 } | 198 } |
169 | 199 |
170 class TmToSeconds : public testing::Test { | 200 class TmToSeconds : public testing::Test { |
171 public: | 201 public: |
172 TmToSeconds() { | 202 TmToSeconds() { |
173 // Set use of the test RNG to get deterministic expiration timestamp. | 203 // Set use of the test RNG to get deterministic expiration timestamp. |
174 rtc::SetRandomTestMode(true); | 204 rtc::SetRandomTestMode(true); |
175 } | 205 } |
176 ~TmToSeconds() { | 206 ~TmToSeconds() { |
177 // Put it back for the next test. | 207 // Put it back for the next test. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 #endif | 286 #endif |
257 } | 287 } |
258 } | 288 } |
259 }; | 289 }; |
260 | 290 |
261 TEST_F(TmToSeconds, TestTmToSeconds) { | 291 TEST_F(TmToSeconds, TestTmToSeconds) { |
262 TestTmToSeconds(100000); | 292 TestTmToSeconds(100000); |
263 } | 293 } |
264 | 294 |
265 } // namespace rtc | 295 } // namespace rtc |
OLD | NEW |