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

Side by Side Diff: webrtc/base/task_unittest.cc

Issue 1345433002: Add RTC_ prefix to contructormagic macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Formatting fix. Created 5 years, 3 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/base/stream.h ('k') | webrtc/base/taskparent.h » ('j') | 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 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/common.h" 23 #include "webrtc/base/common.h"
24 #include "webrtc/base/gunit.h" 24 #include "webrtc/base/gunit.h"
25 #include "webrtc/base/logging.h" 25 #include "webrtc/base/logging.h"
26 #include "webrtc/base/task.h" 26 #include "webrtc/base/task.h"
27 #include "webrtc/base/taskrunner.h" 27 #include "webrtc/base/taskrunner.h"
28 #include "webrtc/base/thread.h" 28 #include "webrtc/base/thread.h"
29 #include "webrtc/base/timeutils.h" 29 #include "webrtc/base/timeutils.h"
30 #include "webrtc/test/testsupport/gtest_disable.h" 30 #include "webrtc/test/testsupport/gtest_disable.h"
31 31
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // make sure none of our happy tasks timed out 263 // make sure none of our happy tasks timed out
264 for (int i = 0; i < HAPPY_TASK_COUNT; ++i) { 264 for (int i = 0; i < HAPPY_TASK_COUNT; ++i) {
265 EXPECT_FALSE(happy_[i].timed_out_); 265 EXPECT_FALSE(happy_[i].timed_out_);
266 } 266 }
267 267
268 // make sure all of our stuck tasks timed out 268 // make sure all of our stuck tasks timed out
269 for (int i = 0; i < STUCK_TASK_COUNT; ++i) { 269 for (int i = 0; i < STUCK_TASK_COUNT; ++i) {
270 EXPECT_TRUE(stuck_[i].timed_out_); 270 EXPECT_TRUE(stuck_[i].timed_out_);
271 if (!stuck_[i].timed_out_) { 271 if (!stuck_[i].timed_out_) {
272 std::cout << "Stuck task #" << i << " timeout is at " 272 std::cout << "Stuck task #" << i << " timeout is at "
273 << stuck_[i].task_->timeout_time() << std::endl; 273 << stuck_[i].task_->timeout_time() << std::endl;
274 } 274 }
275 } 275 }
276 276
277 std::cout.flush(); 277 std::cout.flush();
278 } 278 }
279 279
280 private: 280 private:
281 struct TaskInfo { 281 struct TaskInfo {
282 IdTimeoutTask *task_; 282 IdTimeoutTask *task_;
283 bool timed_out_; 283 bool timed_out_;
(...skipping 17 matching lines...) Expand all
301 public: 301 public:
302 explicit AbortTask(TaskParent *parent) : Task(parent) { 302 explicit AbortTask(TaskParent *parent) : Task(parent) {
303 set_timeout_seconds(1); 303 set_timeout_seconds(1);
304 } 304 }
305 305
306 virtual int ProcessStart() { 306 virtual int ProcessStart() {
307 Abort(); 307 Abort();
308 return STATE_NEXT; 308 return STATE_NEXT;
309 } 309 }
310 private: 310 private:
311 DISALLOW_COPY_AND_ASSIGN(AbortTask); 311 RTC_DISALLOW_COPY_AND_ASSIGN(AbortTask);
312 }; 312 };
313 313
314 class TaskAbortTest : public sigslot::has_slots<> { 314 class TaskAbortTest : public sigslot::has_slots<> {
315 public: 315 public:
316 TaskAbortTest() {} 316 TaskAbortTest() {}
317 317
318 // no need to delete any tasks; the task runner owns them 318 // no need to delete any tasks; the task runner owns them
319 ~TaskAbortTest() {} 319 ~TaskAbortTest() {}
320 320
321 void Start() { 321 void Start() {
322 Task *abort_task = new AbortTask(&task_runner_); 322 Task *abort_task = new AbortTask(&task_runner_);
323 abort_task->SignalTimeout.connect(this, &TaskAbortTest::OnTimeout); 323 abort_task->SignalTimeout.connect(this, &TaskAbortTest::OnTimeout);
324 abort_task->Start(); 324 abort_task->Start();
325 325
326 // run the task 326 // run the task
327 task_runner_.RunTasks(); 327 task_runner_.RunTasks();
328 } 328 }
329 329
330 private: 330 private:
331 void OnTimeout() { 331 void OnTimeout() {
332 FAIL() << "Task timed out instead of aborting."; 332 FAIL() << "Task timed out instead of aborting.";
333 } 333 }
334 334
335 MyTaskRunner task_runner_; 335 MyTaskRunner task_runner_;
336 DISALLOW_COPY_AND_ASSIGN(TaskAbortTest); 336 RTC_DISALLOW_COPY_AND_ASSIGN(TaskAbortTest);
337 }; 337 };
338 338
339 TEST(start_task_test, Abort) { 339 TEST(start_task_test, Abort) {
340 TaskAbortTest abort_test; 340 TaskAbortTest abort_test;
341 abort_test.Start(); 341 abort_test.Start();
342 } 342 }
343 343
344 // Test for aborting a task to verify that it does the Wake operation 344 // Test for aborting a task to verify that it does the Wake operation
345 // which gets it deleted. 345 // which gets it deleted.
346 346
347 class SetBoolOnDeleteTask : public Task { 347 class SetBoolOnDeleteTask : public Task {
348 public: 348 public:
349 SetBoolOnDeleteTask(TaskParent *parent, bool *set_when_deleted) 349 SetBoolOnDeleteTask(TaskParent *parent, bool *set_when_deleted)
350 : Task(parent), 350 : Task(parent),
351 set_when_deleted_(set_when_deleted) { 351 set_when_deleted_(set_when_deleted) {
352 EXPECT_TRUE(NULL != set_when_deleted); 352 EXPECT_TRUE(NULL != set_when_deleted);
353 EXPECT_FALSE(*set_when_deleted); 353 EXPECT_FALSE(*set_when_deleted);
354 } 354 }
355 355
356 virtual ~SetBoolOnDeleteTask() { 356 virtual ~SetBoolOnDeleteTask() {
357 *set_when_deleted_ = true; 357 *set_when_deleted_ = true;
358 } 358 }
359 359
360 virtual int ProcessStart() { 360 virtual int ProcessStart() {
361 return STATE_BLOCKED; 361 return STATE_BLOCKED;
362 } 362 }
363 363
364 private: 364 private:
365 bool* set_when_deleted_; 365 bool* set_when_deleted_;
366 DISALLOW_COPY_AND_ASSIGN(SetBoolOnDeleteTask); 366 RTC_DISALLOW_COPY_AND_ASSIGN(SetBoolOnDeleteTask);
367 }; 367 };
368 368
369 class AbortShouldWakeTest : public sigslot::has_slots<> { 369 class AbortShouldWakeTest : public sigslot::has_slots<> {
370 public: 370 public:
371 AbortShouldWakeTest() {} 371 AbortShouldWakeTest() {}
372 372
373 // no need to delete any tasks; the task runner owns them 373 // no need to delete any tasks; the task runner owns them
374 ~AbortShouldWakeTest() {} 374 ~AbortShouldWakeTest() {}
375 375
376 void Start() { 376 void Start() {
(...skipping 12 matching lines...) Expand all
389 task_runner_.RunTasks(); 389 task_runner_.RunTasks();
390 } 390 }
391 } 391 }
392 392
393 private: 393 private:
394 void OnTimeout() { 394 void OnTimeout() {
395 FAIL() << "Task timed out instead of aborting."; 395 FAIL() << "Task timed out instead of aborting.";
396 } 396 }
397 397
398 MyTaskRunner task_runner_; 398 MyTaskRunner task_runner_;
399 DISALLOW_COPY_AND_ASSIGN(AbortShouldWakeTest); 399 RTC_DISALLOW_COPY_AND_ASSIGN(AbortShouldWakeTest);
400 }; 400 };
401 401
402 TEST(start_task_test, AbortShouldWake) { 402 TEST(start_task_test, AbortShouldWake) {
403 AbortShouldWakeTest abort_should_wake_test; 403 AbortShouldWakeTest abort_should_wake_test;
404 abort_should_wake_test.Start(); 404 abort_should_wake_test.Start();
405 } 405 }
406 406
407 // Validate that TaskRunner's OnTimeoutChange gets called appropriately 407 // Validate that TaskRunner's OnTimeoutChange gets called appropriately
408 // * When a task calls UpdateTaskTimeout 408 // * When a task calls UpdateTaskTimeout
409 // * When the next timeout task time, times out 409 // * When the next timeout task time, times out
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 task_count_--; 470 task_count_--;
471 stuck_tasks_[i] = NULL; 471 stuck_tasks_[i] = NULL;
472 break; 472 break;
473 } 473 }
474 } 474 }
475 } 475 }
476 476
477 MyTaskRunner task_runner_; 477 MyTaskRunner task_runner_;
478 StuckTask* (stuck_tasks_[3]); 478 StuckTask* (stuck_tasks_[3]);
479 int task_count_; 479 int task_count_;
480 DISALLOW_COPY_AND_ASSIGN(TimeoutChangeTest); 480 RTC_DISALLOW_COPY_AND_ASSIGN(TimeoutChangeTest);
481 }; 481 };
482 482
483 TEST(start_task_test, TimeoutChange) { 483 TEST(start_task_test, TimeoutChange) {
484 TimeoutChangeTest timeout_change_test; 484 TimeoutChangeTest timeout_change_test;
485 timeout_change_test.Start(); 485 timeout_change_test.Start();
486 } 486 }
487 487
488 class DeleteTestTaskRunner : public TaskRunner { 488 class DeleteTestTaskRunner : public TaskRunner {
489 public: 489 public:
490 DeleteTestTaskRunner() { 490 DeleteTestTaskRunner() {
491 } 491 }
492 virtual void WakeTasks() { } 492 virtual void WakeTasks() { }
493 virtual int64 CurrentTime() { 493 virtual int64 CurrentTime() {
494 return GetCurrentTime(); 494 return GetCurrentTime();
495 } 495 }
496 private: 496 private:
497 DISALLOW_COPY_AND_ASSIGN(DeleteTestTaskRunner); 497 RTC_DISALLOW_COPY_AND_ASSIGN(DeleteTestTaskRunner);
498 }; 498 };
499 499
500 TEST(unstarted_task_test, DeleteTask) { 500 TEST(unstarted_task_test, DeleteTask) {
501 // This test ensures that we don't 501 // This test ensures that we don't
502 // crash if a task is deleted without running it. 502 // crash if a task is deleted without running it.
503 DeleteTestTaskRunner task_runner; 503 DeleteTestTaskRunner task_runner;
504 HappyTask* happy_task = new HappyTask(&task_runner); 504 HappyTask* happy_task = new HappyTask(&task_runner);
505 happy_task->Start(); 505 happy_task->Start();
506 506
507 // try deleting the task directly 507 // try deleting the task directly
(...skipping 29 matching lines...) Expand all
537 // Do not start the task. 537 // Do not start the task.
538 // Note: this leaks memory, so don't do this. 538 // Note: this leaks memory, so don't do this.
539 // Instead, always run your tasks or delete them. 539 // Instead, always run your tasks or delete them.
540 new HappyTask(happy_task); 540 new HappyTask(happy_task);
541 541
542 // run the unblocked tasks 542 // run the unblocked tasks
543 task_runner.RunTasks(); 543 task_runner.RunTasks();
544 } 544 }
545 545
546 } // namespace rtc 546 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/stream.h ('k') | webrtc/base/taskparent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698