OLD | NEW |
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/threading/thread.h" | 5 #include "base/threading/thread.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 TEST_F(ThreadTest, TwoTasks) { | 170 TEST_F(ThreadTest, TwoTasks) { |
171 bool was_invoked = false; | 171 bool was_invoked = false; |
172 { | 172 { |
173 Thread a("TwoTasks"); | 173 Thread a("TwoTasks"); |
174 EXPECT_TRUE(a.Start()); | 174 EXPECT_TRUE(a.Start()); |
175 EXPECT_TRUE(a.message_loop()); | 175 EXPECT_TRUE(a.message_loop()); |
176 | 176 |
177 // Test that all events are dispatched before the Thread object is | 177 // Test that all events are dispatched before the Thread object is |
178 // destroyed. We do this by dispatching a sleep event before the | 178 // destroyed. We do this by dispatching a sleep event before the |
179 // event that will toggle our sentinel value. | 179 // event that will toggle our sentinel value. |
180 a.message_loop()->PostTask(FROM_HERE, | 180 a.message_loop()->PostTask( |
181 base::Bind(&base::PlatformThread::Sleep, 20)); | 181 FROM_HERE, |
| 182 base::Bind(static_cast<void (*)(int)>(&base::PlatformThread::Sleep), |
| 183 20)); |
182 a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue, | 184 a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue, |
183 &was_invoked)); | 185 &was_invoked)); |
184 } | 186 } |
185 EXPECT_TRUE(was_invoked); | 187 EXPECT_TRUE(was_invoked); |
186 } | 188 } |
187 | 189 |
188 TEST_F(ThreadTest, StopSoon) { | 190 TEST_F(ThreadTest, StopSoon) { |
189 Thread a("StopSoon"); | 191 Thread a("StopSoon"); |
190 EXPECT_TRUE(a.Start()); | 192 EXPECT_TRUE(a.Start()); |
191 EXPECT_TRUE(a.message_loop()); | 193 EXPECT_TRUE(a.message_loop()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 237 |
236 // Upon leaving this scope, the thread is deleted. | 238 // Upon leaving this scope, the thread is deleted. |
237 } | 239 } |
238 | 240 |
239 // Check the order of events during shutdown. | 241 // Check the order of events during shutdown. |
240 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); | 242 ASSERT_EQ(static_cast<size_t>(THREAD_NUM_EVENTS), captured_events.size()); |
241 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); | 243 EXPECT_EQ(THREAD_EVENT_INIT, captured_events[0]); |
242 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); | 244 EXPECT_EQ(THREAD_EVENT_CLEANUP, captured_events[1]); |
243 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); | 245 EXPECT_EQ(THREAD_EVENT_MESSAGE_LOOP_DESTROYED, captured_events[2]); |
244 } | 246 } |
OLD | NEW |