OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project 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 "src/base/atomicops.h" | 5 #include "src/base/atomicops.h" |
6 #include "src/base/platform/platform.h" | 6 #include "src/base/platform/platform.h" |
7 #include "src/cancelable-task.h" | 7 #include "src/cancelable-task.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 | 110 |
111 TEST(CancelableTask, SequentialMultipleTasks) { | 111 TEST(CancelableTask, SequentialMultipleTasks) { |
112 CancelableTaskManager manager; | 112 CancelableTaskManager manager; |
113 ResultType result1 = 0; | 113 ResultType result1 = 0; |
114 ResultType result2 = 0; | 114 ResultType result2 = 0; |
115 TestTask* task1 = new TestTask(&manager, &result1); | 115 TestTask* task1 = new TestTask(&manager, &result1); |
116 TestTask* task2 = new TestTask(&manager, &result2); | 116 TestTask* task2 = new TestTask(&manager, &result2); |
117 SequentialRunner runner1(task1); | 117 SequentialRunner runner1(task1); |
118 SequentialRunner runner2(task2); | 118 SequentialRunner runner2(task2); |
119 EXPECT_EQ(task1->id(), 1); | 119 EXPECT_EQ(task1->id(), 1u); |
120 EXPECT_EQ(task2->id(), 2); | 120 EXPECT_EQ(task2->id(), 2u); |
121 | 121 |
122 EXPECT_EQ(GetValue(&result1), 0); | 122 EXPECT_EQ(GetValue(&result1), 0); |
123 runner1.Run(); // Don't touch task1 after running it. | 123 runner1.Run(); // Don't touch task1 after running it. |
124 EXPECT_EQ(GetValue(&result1), 1); | 124 EXPECT_EQ(GetValue(&result1), 1); |
125 | 125 |
126 EXPECT_EQ(GetValue(&result2), 0); | 126 EXPECT_EQ(GetValue(&result2), 0); |
127 runner2.Run(); // Don't touch task2 after running it. | 127 runner2.Run(); // Don't touch task2 after running it. |
128 EXPECT_EQ(GetValue(&result2), 2); | 128 EXPECT_EQ(GetValue(&result2), 2); |
129 | 129 |
130 manager.CancelAndWait(); | 130 manager.CancelAndWait(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 EXPECT_EQ(GetValue(&result2), 0); | 174 EXPECT_EQ(GetValue(&result2), 0); |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 TEST(CancelableTask, RemoveBeforeCancelAndWait) { | 178 TEST(CancelableTask, RemoveBeforeCancelAndWait) { |
179 CancelableTaskManager manager; | 179 CancelableTaskManager manager; |
180 ResultType result1 = 0; | 180 ResultType result1 = 0; |
181 TestTask* task1 = new TestTask(&manager, &result1, TestTask::kCheckNotRun); | 181 TestTask* task1 = new TestTask(&manager, &result1, TestTask::kCheckNotRun); |
182 ThreadedRunner runner1(task1); | 182 ThreadedRunner runner1(task1); |
183 uint32_t id = task1->id(); | 183 uint32_t id = task1->id(); |
184 EXPECT_EQ(id, 1); | 184 EXPECT_EQ(id, 1u); |
185 EXPECT_TRUE(manager.TryAbort(id)); | 185 EXPECT_TRUE(manager.TryAbort(id)); |
186 runner1.Start(); | 186 runner1.Start(); |
187 runner1.Join(); | 187 runner1.Join(); |
188 manager.CancelAndWait(); | 188 manager.CancelAndWait(); |
189 EXPECT_EQ(GetValue(&result1), 0); | 189 EXPECT_EQ(GetValue(&result1), 0); |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 TEST(CancelableTask, RemoveAfterCancelAndWait) { | 193 TEST(CancelableTask, RemoveAfterCancelAndWait) { |
194 CancelableTaskManager manager; | 194 CancelableTaskManager manager; |
195 ResultType result1 = 0; | 195 ResultType result1 = 0; |
196 TestTask* task1 = new TestTask(&manager, &result1); | 196 TestTask* task1 = new TestTask(&manager, &result1); |
197 ThreadedRunner runner1(task1); | 197 ThreadedRunner runner1(task1); |
198 uint32_t id = task1->id(); | 198 uint32_t id = task1->id(); |
199 EXPECT_EQ(id, 1); | 199 EXPECT_EQ(id, 1u); |
200 runner1.Start(); | 200 runner1.Start(); |
201 runner1.Join(); | 201 runner1.Join(); |
202 manager.CancelAndWait(); | 202 manager.CancelAndWait(); |
203 EXPECT_FALSE(manager.TryAbort(id)); | 203 EXPECT_FALSE(manager.TryAbort(id)); |
204 EXPECT_EQ(GetValue(&result1), 1); | 204 EXPECT_EQ(GetValue(&result1), 1); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 TEST(CancelableTask, RemoveUnmanagedId) { | 208 TEST(CancelableTask, RemoveUnmanagedId) { |
209 CancelableTaskManager manager; | 209 CancelableTaskManager manager; |
210 EXPECT_FALSE(manager.TryAbort(1)); | 210 EXPECT_FALSE(manager.TryAbort(1)); |
211 EXPECT_FALSE(manager.TryAbort(2)); | 211 EXPECT_FALSE(manager.TryAbort(2)); |
212 manager.CancelAndWait(); | 212 manager.CancelAndWait(); |
213 EXPECT_FALSE(manager.TryAbort(1)); | 213 EXPECT_FALSE(manager.TryAbort(1)); |
214 EXPECT_FALSE(manager.TryAbort(3)); | 214 EXPECT_FALSE(manager.TryAbort(3)); |
215 } | 215 } |
216 | 216 |
217 } // namespace internal | 217 } // namespace internal |
218 } // namespace v8 | 218 } // namespace v8 |
OLD | NEW |