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

Side by Side Diff: base/task_unittest.cc

Issue 7062013: Move media library AutoTaskRunner to base and rename ScopedTaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments and add unit test. Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/task.h" 6 #include "base/task.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 TEST(TaskTest, TestCancelInDestructor) { 43 TEST(TaskTest, TestCancelInDestructor) {
44 // Intentionally not using a scoped_refptr for cancel_in_destructor. 44 // Intentionally not using a scoped_refptr for cancel_in_destructor.
45 CancelInDestructor* cancel_in_destructor = new CancelInDestructor(); 45 CancelInDestructor* cancel_in_destructor = new CancelInDestructor();
46 cancel_in_destructor->Start(); 46 cancel_in_destructor->Start();
47 CancelableTask* cancelable_task = cancel_in_destructor->cancelable_task(); 47 CancelableTask* cancelable_task = cancel_in_destructor->cancelable_task();
48 ASSERT_TRUE(cancelable_task); 48 ASSERT_TRUE(cancelable_task);
49 delete cancelable_task; 49 delete cancelable_task;
50 } 50 }
51 51
52 class DoneTask : public Task {
53 public:
54 DoneTask(int* run_count, bool* was_deleted)
55 : run_count_(run_count), was_deleted_(was_deleted) {}
awong 2011/05/26 19:01:01 Since you had to break for the initializer list, t
Wez 2011/05/26 20:53:46 Done.
56 ~DoneTask() {
awong 2011/05/26 19:01:01 virtual
Wez 2011/05/26 20:53:46 Done.
57 *was_deleted_ = true;
58 }
59
60 virtual void Run() {
61 ++(*run_count_);
62 }
63
64 int* run_count_;
65 bool* was_deleted_;
66 };
67
68 TEST(TaskTest, TestScopedTaskRunnerExitScope) {
69 int run_count = 0;
70 bool was_deleted = false;
71 {
72 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
73 }
74 ASSERT_EQ(1, run_count);
awong 2011/05/26 19:01:01 Use EXPECT_* not ASSERT_* here and in the other ne
Wez 2011/05/26 20:53:46 Done.
75 ASSERT_EQ(true, was_deleted);
awong 2011/05/26 19:01:01 _TRUE, not _EQ
Wez 2011/05/26 20:53:46 Done.
76 }
77
78 TEST(TaskTest, TestScopedTaskRunnerRelease) {
79 int run_count = 0;
80 bool was_deleted = false;
81 {
82 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
83 delete runner.Release();
84 ASSERT_EQ(true, was_deleted);
awong 2011/05/26 19:01:01 ASSERT_TRUE
Wez 2011/05/26 20:53:46 Done.
85 }
86 ASSERT_EQ(0, run_count);
87 }
88
89 TEST(TaskTest, TestScopedTaskRunnerManualRun) {
90 int run_count = 0;
91 Task* done_task = NULL;
92 bool was_deleted = false;
93 {
94 base::ScopedTaskRunner runner(new DoneTask(&run_count, &was_deleted));
95 done_task = runner.Release();
96 ASSERT_TRUE(NULL != done_task);
awong 2011/05/26 19:01:01 ASSERT_EQ?
Wez 2011/05/26 20:53:46 Would need to be ASSERT_NE(), which gets confused
97 ASSERT_EQ(false, was_deleted);
98 done_task->Run();
99 ASSERT_EQ(false, was_deleted);
100 }
101 ASSERT_EQ(1, run_count);
102 delete done_task;
103 ASSERT_EQ(true, was_deleted);
104 }
105
52 } // namespace 106 } // namespace
OLDNEW
« base/task.h ('K') | « base/task.cc ('k') | media/base/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698