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 |
11 #if defined(WEBRTC_POSIX) | 11 #if defined(WEBRTC_POSIX) |
12 #include <sys/time.h> | 12 #include <sys/time.h> |
13 #endif // WEBRTC_POSIX | 13 #endif // WEBRTC_POSIX |
14 | 14 |
15 // TODO: Remove this once the cause of sporadic failures in these | 15 // TODO: Remove this once the cause of sporadic failures in these |
16 // tests is tracked down. | 16 // tests is tracked down. |
17 #include <iostream> | 17 #include <iostream> |
18 | 18 |
19 #if defined(WEBRTC_WIN) | 19 #if defined(WEBRTC_WIN) |
20 #include "webrtc/base/win32.h" | 20 #include "webrtc/base/win32.h" |
21 #endif // WEBRTC_WIN | 21 #endif // WEBRTC_WIN |
22 | 22 |
| 23 #include "webrtc/base/arraysize.h" |
23 #include "webrtc/base/common.h" | 24 #include "webrtc/base/common.h" |
24 #include "webrtc/base/gunit.h" | 25 #include "webrtc/base/gunit.h" |
25 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
26 #include "webrtc/base/task.h" | 27 #include "webrtc/base/task.h" |
27 #include "webrtc/base/taskrunner.h" | 28 #include "webrtc/base/taskrunner.h" |
28 #include "webrtc/base/thread.h" | 29 #include "webrtc/base/thread.h" |
29 #include "webrtc/base/timeutils.h" | 30 #include "webrtc/base/timeutils.h" |
30 #include "webrtc/test/testsupport/gtest_disable.h" | 31 #include "webrtc/test/testsupport/gtest_disable.h" |
31 | 32 |
32 namespace rtc { | 33 namespace rtc { |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 AbortShouldWakeTest abort_should_wake_test; | 402 AbortShouldWakeTest abort_should_wake_test; |
402 abort_should_wake_test.Start(); | 403 abort_should_wake_test.Start(); |
403 } | 404 } |
404 | 405 |
405 // Validate that TaskRunner's OnTimeoutChange gets called appropriately | 406 // Validate that TaskRunner's OnTimeoutChange gets called appropriately |
406 // * When a task calls UpdateTaskTimeout | 407 // * When a task calls UpdateTaskTimeout |
407 // * When the next timeout task time, times out | 408 // * When the next timeout task time, times out |
408 class TimeoutChangeTest : public sigslot::has_slots<> { | 409 class TimeoutChangeTest : public sigslot::has_slots<> { |
409 public: | 410 public: |
410 TimeoutChangeTest() | 411 TimeoutChangeTest() |
411 : task_count_(ARRAY_SIZE(stuck_tasks_)) {} | 412 : task_count_(arraysize(stuck_tasks_)) {} |
412 | 413 |
413 // no need to delete any tasks; the task runner owns them | 414 // no need to delete any tasks; the task runner owns them |
414 ~TimeoutChangeTest() {} | 415 ~TimeoutChangeTest() {} |
415 | 416 |
416 void Start() { | 417 void Start() { |
417 for (int i = 0; i < task_count_; ++i) { | 418 for (int i = 0; i < task_count_; ++i) { |
418 stuck_tasks_[i] = new StuckTask(&task_runner_); | 419 stuck_tasks_[i] = new StuckTask(&task_runner_); |
419 stuck_tasks_[i]->set_timeout_seconds(i + 2); | 420 stuck_tasks_[i]->set_timeout_seconds(i + 2); |
420 stuck_tasks_[i]->SignalTimeoutId.connect(this, | 421 stuck_tasks_[i]->SignalTimeoutId.connect(this, |
421 &TimeoutChangeTest::OnTimeoutId); | 422 &TimeoutChangeTest::OnTimeoutId); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // the smallest timeout is now in the past. | 457 // the smallest timeout is now in the past. |
457 EXPECT_TRUE(task_runner_.timeout_change()); | 458 EXPECT_TRUE(task_runner_.timeout_change()); |
458 task_runner_.clear_timeout_change(); | 459 task_runner_.clear_timeout_change(); |
459 } | 460 } |
460 Thread::Current()->socketserver()->Wait(500, false); | 461 Thread::Current()->socketserver()->Wait(500, false); |
461 } | 462 } |
462 } | 463 } |
463 | 464 |
464 private: | 465 private: |
465 void OnTimeoutId(const int id) { | 466 void OnTimeoutId(const int id) { |
466 for (int i = 0; i < ARRAY_SIZE(stuck_tasks_); ++i) { | 467 for (size_t i = 0; i < arraysize(stuck_tasks_); ++i) { |
467 if (stuck_tasks_[i] && stuck_tasks_[i]->unique_id() == id) { | 468 if (stuck_tasks_[i] && stuck_tasks_[i]->unique_id() == id) { |
468 task_count_--; | 469 task_count_--; |
469 stuck_tasks_[i] = NULL; | 470 stuck_tasks_[i] = NULL; |
470 break; | 471 break; |
471 } | 472 } |
472 } | 473 } |
473 } | 474 } |
474 | 475 |
475 MyTaskRunner task_runner_; | 476 MyTaskRunner task_runner_; |
476 StuckTask* (stuck_tasks_[3]); | 477 StuckTask* (stuck_tasks_[3]); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // Do not start the task. | 534 // Do not start the task. |
534 // Note: this leaks memory, so don't do this. | 535 // Note: this leaks memory, so don't do this. |
535 // Instead, always run your tasks or delete them. | 536 // Instead, always run your tasks or delete them. |
536 new HappyTask(happy_task); | 537 new HappyTask(happy_task); |
537 | 538 |
538 // run the unblocked tasks | 539 // run the unblocked tasks |
539 task_runner.RunTasks(); | 540 task_runner.RunTasks(); |
540 } | 541 } |
541 | 542 |
542 } // namespace rtc | 543 } // namespace rtc |
OLD | NEW |