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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 EXPECT_EQ(TimeDelta::FromMilliseconds(2000), | 296 EXPECT_EQ(TimeDelta::FromMilliseconds(2000), |
297 2 * TimeDelta::FromMilliseconds(1000)); | 297 2 * TimeDelta::FromMilliseconds(1000)); |
298 } | 298 } |
299 | 299 |
300 // Test that all the time functions exposed by TimeUtils get time from the | 300 // Test that all the time functions exposed by TimeUtils get time from the |
301 // fake clock when it's set. | 301 // fake clock when it's set. |
302 TEST(FakeClock, TimeFunctionsUseFakeClock) { | 302 TEST(FakeClock, TimeFunctionsUseFakeClock) { |
303 FakeClock clock; | 303 FakeClock clock; |
304 SetClockForTesting(&clock); | 304 SetClockForTesting(&clock); |
305 | 305 |
306 clock.SetTimeNanos(987654321u); | 306 clock.SetTimeNanos(987654321); |
307 EXPECT_EQ(987u, Time32()); | 307 EXPECT_EQ(987u, Time32()); |
308 EXPECT_EQ(987, TimeMillis()); | 308 EXPECT_EQ(987, TimeMillis()); |
309 EXPECT_EQ(987654u, TimeMicros()); | 309 EXPECT_EQ(987654, TimeMicros()); |
310 EXPECT_EQ(987654321u, TimeNanos()); | 310 EXPECT_EQ(987654321, TimeNanos()); |
311 EXPECT_EQ(1000u, TimeAfter(13)); | 311 EXPECT_EQ(1000u, TimeAfter(13)); |
312 | 312 |
313 SetClockForTesting(nullptr); | 313 SetClockForTesting(nullptr); |
314 // After it's unset, we should get a normal time. | 314 // After it's unset, we should get a normal time. |
315 EXPECT_NE(987, TimeMillis()); | 315 EXPECT_NE(987, TimeMillis()); |
316 } | 316 } |
317 | 317 |
318 TEST(FakeClock, InitialTime) { | 318 TEST(FakeClock, InitialTime) { |
319 FakeClock clock; | 319 FakeClock clock; |
320 EXPECT_EQ(0u, clock.TimeNanos()); | 320 EXPECT_EQ(0, clock.TimeNanos()); |
321 } | 321 } |
322 | 322 |
323 TEST(FakeClock, SetTimeNanos) { | 323 TEST(FakeClock, SetTimeNanos) { |
324 FakeClock clock; | 324 FakeClock clock; |
325 clock.SetTimeNanos(123u); | 325 clock.SetTimeNanos(123); |
326 EXPECT_EQ(123u, clock.TimeNanos()); | 326 EXPECT_EQ(123, clock.TimeNanos()); |
327 clock.SetTimeNanos(456u); | 327 clock.SetTimeNanos(456); |
328 EXPECT_EQ(456u, clock.TimeNanos()); | 328 EXPECT_EQ(456, clock.TimeNanos()); |
329 } | 329 } |
330 | 330 |
331 TEST(FakeClock, AdvanceTime) { | 331 TEST(FakeClock, AdvanceTime) { |
332 FakeClock clock; | 332 FakeClock clock; |
333 clock.AdvanceTime(TimeDelta::FromNanoseconds(1111u)); | 333 clock.AdvanceTime(TimeDelta::FromNanoseconds(1111u)); |
334 EXPECT_EQ(1111u, clock.TimeNanos()); | 334 EXPECT_EQ(1111, clock.TimeNanos()); |
335 clock.AdvanceTime(TimeDelta::FromMicroseconds(2222u)); | 335 clock.AdvanceTime(TimeDelta::FromMicroseconds(2222u)); |
336 EXPECT_EQ(2223111u, clock.TimeNanos()); | 336 EXPECT_EQ(2223111, clock.TimeNanos()); |
337 clock.AdvanceTime(TimeDelta::FromMilliseconds(3333u)); | 337 clock.AdvanceTime(TimeDelta::FromMilliseconds(3333u)); |
338 EXPECT_EQ(3335223111u, clock.TimeNanos()); | 338 EXPECT_EQ(3335223111, clock.TimeNanos()); |
339 clock.AdvanceTime(TimeDelta::FromSeconds(4444u)); | 339 clock.AdvanceTime(TimeDelta::FromSeconds(4444u)); |
340 EXPECT_EQ(4447335223111u, clock.TimeNanos()); | 340 EXPECT_EQ(4447335223111, clock.TimeNanos()); |
341 } | 341 } |
342 | 342 |
343 // When the clock is advanced, threads that are waiting in a socket select | 343 // When the clock is advanced, threads that are waiting in a socket select |
344 // should wake up and look at the new time. This allows tests using the | 344 // should wake up and look at the new time. This allows tests using the |
345 // fake clock to run much faster, if the test is bound by time constraints | 345 // fake clock to run much faster, if the test is bound by time constraints |
346 // (such as a test for a STUN ping timeout). | 346 // (such as a test for a STUN ping timeout). |
347 TEST(FakeClock, SettingTimeWakesThreads) { | 347 TEST(FakeClock, SettingTimeWakesThreads) { |
348 int64_t real_start_time_ms = TimeMillis(); | 348 int64_t real_start_time_ms = TimeMillis(); |
349 | 349 |
350 FakeClock clock; | 350 FakeClock clock; |
(...skipping 23 matching lines...) Expand all Loading... |
374 | 374 |
375 SetClockForTesting(nullptr); | 375 SetClockForTesting(nullptr); |
376 | 376 |
377 // The message should have been dispatched long before the 60 seconds fully | 377 // The message should have been dispatched long before the 60 seconds fully |
378 // elapsed (just a sanity check). | 378 // elapsed (just a sanity check). |
379 int64_t real_end_time_ms = TimeMillis(); | 379 int64_t real_end_time_ms = TimeMillis(); |
380 EXPECT_LT(real_end_time_ms - real_start_time_ms, 10000); | 380 EXPECT_LT(real_end_time_ms - real_start_time_ms, 10000); |
381 } | 381 } |
382 | 382 |
383 } // namespace rtc | 383 } // namespace rtc |
OLD | NEW |